From be6f46dee1bfd731b7e07b5e8df6974bde314337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Tue, 8 Jan 2019 23:33:59 +0800 Subject: [PATCH] lint-prettier will direct write (#3318) --- package.json | 1 + scripts/lint-prettier.js | 16 +++++++--------- scripts/prettier.js | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 7b39ad7b..24e87d06 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "antd": "^3.11.6", "bizcharts": "^3.4.2", "bizcharts-plugin-slider": "^2.1.1-beta.1", + "chalk": "^2.4.2", "classnames": "^2.2.6", "dva": "^2.4.0", "enquire-js": "^0.2.1", diff --git a/scripts/lint-prettier.js b/scripts/lint-prettier.js index 24c4df40..677f793b 100644 --- a/scripts/lint-prettier.js +++ b/scripts/lint-prettier.js @@ -8,12 +8,12 @@ const prettier = require('prettier'); const fs = require('fs'); +const chalk = require('chalk'); const prettierConfigPath = require.resolve('../.prettierrc'); const files = process.argv.slice(2); let didError = false; -let didWarn = false; files.forEach(file => { Promise.all([ @@ -32,21 +32,19 @@ files.forEach(file => { ...options, parser: fileInfo.inferredParser, }; - const isPrettier = prettier.check(input, withParserOptions); - if (!isPrettier) { - console.log( - `\x1b[31m ${file} is no prettier, please use npm run prettier and git add !\x1b[0m` - ); - didWarn = true; + const output = prettier.format(input, withParserOptions); + if (output !== input) { + fs.writeFileSync(file, output, 'utf8'); + console.log(chalk.green(`${file} is prettier`)); } }) .catch(e => { didError = true; }) .finally(() => { - if (didWarn || didError) { + if (didError) { process.exit(1); } - console.log('\x1b[32m lint prettier success!\x1b[0m'); + console.log(chalk.hex('#1890FF')('prettier success!')); }); }); diff --git a/scripts/prettier.js b/scripts/prettier.js index 9ce7813a..17ded6c5 100644 --- a/scripts/prettier.js +++ b/scripts/prettier.js @@ -6,11 +6,11 @@ *----------*****-------------- */ -const glob = require('glob'); const prettier = require('prettier'); const fs = require('fs'); const getPrettierFiles = require('./getPrettierFiles'); const prettierConfigPath = require.resolve('../.prettierrc'); +const chalk = require('chalk'); let didError = false; @@ -33,7 +33,7 @@ files.forEach(file => { const output = prettier.format(input, withParserOptions); if (output !== input) { fs.writeFileSync(file, output, 'utf8'); - console.log(`\x1b[34m ${file} is prettier`); + console.log(chalk.green(`${file} is prettier`)); } } catch (e) { didError = true; @@ -43,4 +43,4 @@ files.forEach(file => { if (didError) { process.exit(1); } -console.log('\x1b[32m prettier success!'); +console.log(chalk.hex('#1890FF')('prettier success!')); -- GitLab