From 6639cbe45553d35ec8738599cb11ae0e2541cedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Tue, 7 May 2019 14:29:22 +0800 Subject: [PATCH] remove prettier.js --- package.json | 6 ++--- scripts/getPrettierFiles.js | 23 ----------------- scripts/lint-prettier.js | 50 ------------------------------------- scripts/prettier.js | 47 ---------------------------------- 4 files changed, 3 insertions(+), 123 deletions(-) delete mode 100644 scripts/getPrettierFiles.js delete mode 100644 scripts/lint-prettier.js delete mode 100644 scripts/prettier.js diff --git a/package.json b/package.json index 3d9dbf7e..a8b0af76 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "lint:prettier": "check-prettier lint", "lint:style": "stylelint --fix 'src/**/*.less' --syntax less", "lint:ts": "tslint -p . -c tslint.yml", - "prettier": "node ./scripts/prettier.js", + "prettier": " check-prettier write", "site": "umi build && npm run functions:build", "start": "cross-env ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION=site umi dev", "start:no-mock": "cross-env MOCK=none umi dev", @@ -42,8 +42,8 @@ "lint-staged": { "**/*.less": "stylelint --syntax less", "**/*.{js,jsx}": "npm run lint-staged:js", - "**/*.{js,ts,tsx,json,jsx,less}": [ - "node ./scripts/lint-prettier.js", + "**/*.{js,ts,tsx,md,json,jsx,less}": [ + "npm run prettier", "git add" ], "**/*.{ts,tsx}": "npm run lint-staged:ts" diff --git a/scripts/getPrettierFiles.js b/scripts/getPrettierFiles.js deleted file mode 100644 index 500ab092..00000000 --- a/scripts/getPrettierFiles.js +++ /dev/null @@ -1,23 +0,0 @@ -const glob = require('glob'); - -const getPrettierFiles = () => { - let files = []; - const jsFiles = glob.sync('src/**/*.js*', { ignore: ['**/node_modules/**', 'build/**'] }); - const tsFiles = glob.sync('src/**/*.ts*', { ignore: ['**/node_modules/**', 'build/**'] }); - const configFiles = glob.sync('config/**/*.js*', { ignore: ['**/node_modules/**', 'build/**'] }); - const scriptFiles = glob.sync('scripts/**/*.js'); - const lessFiles = glob.sync('src/**/*.less*', { ignore: ['**/node_modules/**', 'build/**'] }); - const mdFiles = glob.sync('src/**/*.md*', { ignore: ['**/node_modules/**', 'build/**'] }); - files = files.concat(jsFiles); - files = files.concat(tsFiles); - files = files.concat(configFiles); - files = files.concat(scriptFiles); - files = files.concat(lessFiles); - files = files.concat(mdFiles); - if (!files.length) { - return; - } - return files; -}; - -module.exports = getPrettierFiles; diff --git a/scripts/lint-prettier.js b/scripts/lint-prettier.js deleted file mode 100644 index 677f793b..00000000 --- a/scripts/lint-prettier.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * copy to https://github.com/facebook/react/blob/master/scripts/prettier/index.js - * prettier api doc https://prettier.io/docs/en/api.html - *----------*****-------------- - * lint file is prettier - *----------*****-------------- - */ - -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; - -files.forEach(file => { - Promise.all([ - prettier.resolveConfig(file, { - config: prettierConfigPath, - }), - prettier.getFileInfo(file), - ]) - .then(resolves => { - const [options, fileInfo] = resolves; - if (fileInfo.ignored) { - return; - } - const input = fs.readFileSync(file, 'utf8'); - const withParserOptions = { - ...options, - parser: fileInfo.inferredParser, - }; - 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 (didError) { - process.exit(1); - } - console.log(chalk.hex('#1890FF')('prettier success!')); - }); -}); diff --git a/scripts/prettier.js b/scripts/prettier.js deleted file mode 100644 index 22a6b2d4..00000000 --- a/scripts/prettier.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * copy to https://github.com/facebook/react/blob/master/scripts/prettier/index.js - * prettier api doc https://prettier.io/docs/en/api.html - *----------*****-------------- - * prettier all js and all ts. - *----------*****-------------- - */ - -const prettier = require('prettier'); -const fs = require('fs'); -const getPrettierFiles = require('./getPrettierFiles'); -const prettierConfigPath = require.resolve('../.prettierrc'); -const chalk = require('chalk'); - -let didError = false; - -const files = getPrettierFiles(); - -files.forEach(file => { - const options = prettier.resolveConfig.sync(file, { - config: prettierConfigPath, - }); - const fileInfo = prettier.getFileInfo.sync(file); - if (fileInfo.ignored) { - return; - } - try { - const input = fs.readFileSync(file, 'utf8'); - const withParserOptions = { - ...options, - parser: fileInfo.inferredParser, - }; - const output = prettier.format(input, withParserOptions); - if (output !== input) { - fs.writeFileSync(file, output, 'utf8'); - console.log(chalk.green(`${file} is prettier`)); - } - } catch (e) { - console.log(e); - didError = true; - } -}); - -if (didError) { - process.exit(1); -} -console.log(chalk.hex('#1890FF')('prettier success!')); -- GitLab