Skip to content

Commit 551253e

Browse files
author
罗学
committed
feat: 增加cli eslint
1 parent 04cccb7 commit 551253e

File tree

3 files changed

+42
-195
lines changed

3 files changed

+42
-195
lines changed

packages/eslint/lint.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ const renamedArgs = {
1717
config: 'configFile'
1818
}
1919

20-
module.exports = function lint ({ args = {}, api }) {
20+
module.exports = function lint ({ args = {} }) {
2121
const path = require('path')
22-
const cwd = api.resolve('.')
22+
const cwd = process.cwd()
2323
const { log, done, exit, chalk, loadModule } = require('@pkb/shared-utils')
2424
const { CLIEngine } = loadModule('eslint', cwd, true) || require('eslint')
25-
const extensions = require('./eslintOptions').extensions(api)
25+
const extensions = require('./eslintOptions').extensions()
2626
const argsConfig = normalizeConfig(args)
2727
const config = Object.assign({
2828
extensions,
@@ -65,9 +65,6 @@ module.exports = function lint ({ args = {}, api }) {
6565
: defaultFilesToLint
6666

6767
const processCwd = process.cwd
68-
if (!api.invoking) {
69-
process.cwd = () => cwd
70-
}
7168

7269
const report = engine.executeOnFiles(files)
7370
process.cwd = processCwd
@@ -111,8 +108,6 @@ module.exports = function lint ({ args = {}, api }) {
111108
}
112109
exit(1)
113110
}
114-
115-
console.log('--------end------')
116111
}
117112

118113
function normalizeConfig (args) {

packages/tools/util/hmr-utils.js

Lines changed: 0 additions & 186 deletions
This file was deleted.

packages/tools/util/utils.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
11
const execa = require('execa')
22
const path = require('path')
33
const fs = require('fs-extra')
4-
const execSync = require('child_process').execSync
4+
const net = require('net')
5+
const chalk = require('chalk')
6+
7+
8+
const { execSync } = require('child_process')
59
const { success } = require('../util/log')
610

11+
12+
const errLog = (msg) => console.log(`${chalk.red('[错误]')}${msg}`)
13+
const successLog = (msg) => console.log(`${chalk.green('[成功]')}${msg}`)
14+
const baseLog = (msg) => console.log(`${chalk.cyanBright(msg)}`)
15+
const warnLog = (msg) => console.log(`${chalk.yellow('[警告]')}${msg}`)
16+
const changeLog = (msg) => console.log(`${chalk.cyan('[变更]')}${msg}`)
17+
const compileLog = (msg) => console.log(`${chalk.grey('[编译]')}${msg}`)
18+
19+
async function portInUse(port) {
20+
return new Promise((resolve, reject) => {
21+
const server = net.createServer().listen(port)
22+
server.on('listening', function () {
23+
server.close()
24+
resolve(port)
25+
})
26+
server.on('error', function (err) {
27+
if (err.code === 'EADDRINUSE') {
28+
port++
29+
reject(err)
30+
}
31+
})
32+
})
33+
}
34+
35+
exports.tryUsePort = (port, _portAvailableCallback) => {
36+
portInUse(port).then((port) => {
37+
_portAvailableCallback(port)
38+
}).catch(() => {
39+
console.log(port + '被占用')
40+
port += 1
41+
tryUsePort(port, _portAvailableCallback)
42+
})
43+
}
44+
745
// 获取当前分支
846
exports.getCurBranch = () => {
947
return execSync('git rev-parse --abbrev-ref HEAD').toString().trim()

0 commit comments

Comments
 (0)