Fix formetter script (#3885)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-10-25 14:42:04 +07:00 committed by GitHub
parent 10d5993d02
commit 035a7fd097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,7 +45,7 @@ function calcHash(source, msg) {
for( const v of process.argv.slice(2)) { for( const v of process.argv.slice(2)) {
if( existsSync(v) ) { if( existsSync(v) ) {
console.log('checking:', join( process.cwd(), v) ) console.info('checking:', join( process.cwd(), v) )
calcHash(join(process.cwd(), v), 'changed') calcHash(join(process.cwd(), v), 'changed')
} }
} }
@ -55,30 +55,44 @@ if( process.argv.includes('-f')) {
} }
if( filesToCheck.length > 0 ) { if( filesToCheck.length > 0 ) {
console.log(`running prettier ${filesToCheck.length}`) console.info(`running prettier ${filesToCheck.length}`)
// Changes detected. // Changes detected.
const prettier = spawnSync(join(process.cwd(), 'node_modules/.bin/prettier'), ["--color", "--plugin-search-dir=.", "--write", ...filesToCheck],) const prettier = spawnSync(join(process.cwd(), 'node_modules/.bin/prettier'), ["--color", "--plugin-search-dir=.", "--write", ...filesToCheck],)
if( prettier.stdout != null) { if( prettier.stdout != null) {
writeFileSync('.format/prettier.log', prettier.stdout) writeFileSync('.format/prettier.log', prettier.stdout)
console.log(prettier.stdout.toString()) if( prettier.status === null || prettier.status === 0) {
console.info(prettier.stdout.toString())
} else {
console.error(prettier.stdout.toString())
}
} }
if( prettier.stderr != null) { if( prettier.stderr != null) {
writeFileSync('.format/prettier.err', prettier.stderr) writeFileSync('.format/prettier.err', prettier.stderr)
console.error(prettier.stderr.toString()) const data = prettier.stderr.toString()
if( data.length > 0) {
console.error(data)
}
} }
console.log(`running eslint ${filesToCheck.length}`) console.log(`running eslint ${filesToCheck.length}`)
const eslint = spawnSync(join(process.cwd(), 'node_modules/.bin/eslint'), ["--color", "--fix", ...filesToCheck]) const eslint = spawnSync(join(process.cwd(), 'node_modules/.bin/eslint'), ["--color", "--fix", ...filesToCheck])
if(eslint.stdout != null) { if(eslint.stdout != null) {
writeFileSync('.format/eslint.log', eslint.stdout) writeFileSync('.format/eslint.log', eslint.stdout)
console.log(eslint.stdout.toString()) if( prettier.status === null || prettier.status === 0) {
console.info(eslint.stdout.toString())
} else {
console.error(eslint.stdout.toString())
}
} }
if( eslint.stderr != null) { if( eslint.stderr != null) {
writeFileSync('.format/eslint.err', eslint.stderr) writeFileSync('.format/eslint.err', eslint.stderr)
console.error(eslint.stderr.toString()) const data = eslint.stderr.toString()
if( data.length > 0) {
console.error(data)
}
} }
if( prettier.status || eslint.status) { if( prettier.status || eslint.status) {
console.log('prettier and eslint failed', prettier.status, eslint.status) console.info('prettier and eslint failed', prettier.status, eslint.status)
process.exit(1) process.exit(1)
} }
@ -90,7 +104,7 @@ if( filesToCheck.length > 0 ) {
} }
writeFileSync('.format/format.json', JSON.stringify(newHash, undefined, 2)) writeFileSync('.format/format.json', JSON.stringify(newHash, undefined, 2))
} else { } else {
console.log('No changes detected.') console.info('No changes detected.')
} }
process.exit(0) process.exit(0)