Skip to content

Commit

Permalink
feat: 增加cli eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
罗学 committed Apr 13, 2021
1 parent 04cccb7 commit 551253e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 195 deletions.
11 changes: 3 additions & 8 deletions packages/eslint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const renamedArgs = {
config: 'configFile'
}

module.exports = function lint ({ args = {}, api }) {
module.exports = function lint ({ args = {} }) {
const path = require('path')
const cwd = api.resolve('.')
const cwd = process.cwd()
const { log, done, exit, chalk, loadModule } = require('@pkb/shared-utils')
const { CLIEngine } = loadModule('eslint', cwd, true) || require('eslint')
const extensions = require('./eslintOptions').extensions(api)
const extensions = require('./eslintOptions').extensions()
const argsConfig = normalizeConfig(args)
const config = Object.assign({
extensions,
Expand Down Expand Up @@ -65,9 +65,6 @@ module.exports = function lint ({ args = {}, api }) {
: defaultFilesToLint

const processCwd = process.cwd
if (!api.invoking) {
process.cwd = () => cwd
}

const report = engine.executeOnFiles(files)
process.cwd = processCwd
Expand Down Expand Up @@ -111,8 +108,6 @@ module.exports = function lint ({ args = {}, api }) {
}
exit(1)
}

console.log('--------end------')
}

function normalizeConfig (args) {
Expand Down
186 changes: 0 additions & 186 deletions packages/tools/util/hmr-utils.js

This file was deleted.

40 changes: 39 additions & 1 deletion packages/tools/util/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
const execa = require('execa')
const path = require('path')
const fs = require('fs-extra')
const execSync = require('child_process').execSync
const net = require('net')
const chalk = require('chalk')


const { execSync } = require('child_process')
const { success } = require('../util/log')


const errLog = (msg) => console.log(`${chalk.red('[错误]')}${msg}`)
const successLog = (msg) => console.log(`${chalk.green('[成功]')}${msg}`)
const baseLog = (msg) => console.log(`${chalk.cyanBright(msg)}`)
const warnLog = (msg) => console.log(`${chalk.yellow('[警告]')}${msg}`)
const changeLog = (msg) => console.log(`${chalk.cyan('[变更]')}${msg}`)
const compileLog = (msg) => console.log(`${chalk.grey('[编译]')}${msg}`)

async function portInUse(port) {
return new Promise((resolve, reject) => {
const server = net.createServer().listen(port)
server.on('listening', function () {
server.close()
resolve(port)
})
server.on('error', function (err) {
if (err.code === 'EADDRINUSE') {
port++
reject(err)
}
})
})
}

exports.tryUsePort = (port, _portAvailableCallback) => {
portInUse(port).then((port) => {
_portAvailableCallback(port)
}).catch(() => {
console.log(port + '被占用')
port += 1
tryUsePort(port, _portAvailableCallback)
})
}

// 获取当前分支
exports.getCurBranch = () => {
return execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
Expand Down

0 comments on commit 551253e

Please sign in to comment.