mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
|
#!/usr/bin/env node
|
||
|
// usage: github-lint
|
||
|
//
|
||
|
// Run ESLint and Flow on project.
|
||
|
|
||
|
const childProcess = require('child_process')
|
||
|
const fs = require('fs')
|
||
|
const path = require('path')
|
||
|
|
||
|
function execFile(command, args) {
|
||
|
return new Promise(resolve => {
|
||
|
childProcess.execFile(command, args, (error, stdout, stderr) => {
|
||
|
resolve({code: error ? error.code : 0, stdout, stderr})
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
;(async function() {
|
||
|
let runs = 0
|
||
|
const codes = []
|
||
|
const commands = []
|
||
|
|
||
|
const packageJson = fs.existsSync('package.json') ? require(path.join(process.cwd(), 'package.json')) : {}
|
||
|
|
||
|
let eslintOptions = ['--report-unused-disable-directives', '.']
|
||
|
|
||
|
const isTypeScriptProject = fs.existsSync('tsconfig.json')
|
||
|
|
||
|
if (isTypeScriptProject) {
|
||
|
eslintOptions = eslintOptions.concat(['--ext', '.ts,.tsx'])
|
||
|
}
|
||
|
|
||
|
commands.push(['eslint', eslintOptions])
|
||
|
|
||
|
if (isTypeScriptProject) {
|
||
|
commands.push(['tsc', ['--noEmit']])
|
||
|
}
|
||
|
|
||
|
if (fs.existsSync('.flowconfig')) {
|
||
|
commands.push(['flow', ['check']])
|
||
|
}
|
||
|
|
||
|
if (packageJson && packageJson.flow && packageJson.flow.coverageThreshold) {
|
||
|
commands.push(['flow-coverage', []])
|
||
|
}
|
||
|
|
||
|
for (const [command, args] of commands) {
|
||
|
if (runs > 0) process.stderr.write('\n')
|
||
|
process.stderr.write(`> ${command} ${args.join(' ')}\n`)
|
||
|
|
||
|
const {code, stdout, stderr} = await execFile(command, args)
|
||
|
codes.push(code)
|
||
|
if (stderr) process.stderr.write(stderr)
|
||
|
if (stdout) process.stdout.write(stdout)
|
||
|
|
||
|
runs++
|
||
|
}
|
||
|
|
||
|
const nonzero = codes.find(code => code !== 0)
|
||
|
if (nonzero) {
|
||
|
process.stderr.write(`\nCommand failed: ${nonzero}\n`)
|
||
|
process.exit(nonzero)
|
||
|
}
|
||
|
})().catch(error => {
|
||
|
setTimeout(() => {
|
||
|
throw error
|
||
|
})
|
||
|
})
|