From cc970b000a489f8f7db09ee843c599e72392755e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Tue, 1 Jan 2019 10:00:09 +0800 Subject: [PATCH] add lint prettier in Ci (#3262) * add lint prettier in Ci * .circleci use version =2 * remove jest in package * update package.json * add enzyme * fix appveyor error * use check-prettier script --- .circleci/config.yml | 9 +++++---- appveyor.yml | 4 ++-- jest-puppeteer.config.js | 2 +- package.json | 27 ++++++++++++++++++--------- scripts/getPrettierFiles.js | 21 +++++++++++++++++++++ scripts/prettier.js | 16 ++-------------- 6 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 scripts/getPrettierFiles.js diff --git a/.circleci/config.yml b/.circleci/config.yml index f889c7d7..e6c87e9a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,6 +6,7 @@ jobs: steps: - checkout - run: npm install + - run: npm run lint - run: npm run build test: docker: @@ -13,12 +14,12 @@ jobs: steps: - checkout - run: npm install - - run: - command : npm run test:all - no_output_timeout : 30m + - run: + command: npm run test:all + no_output_timeout: 30m workflows: version: 2 build_and_test: jobs: - build - - test \ No newline at end of file + - test diff --git a/appveyor.yml b/appveyor.yml index 22ae1886..f2ffbbd4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,10 +1,10 @@ # Test against the latest version of this Node.js version environment: - nodejs_version: "8" + nodejs_version: '10' # this is how to allow failing jobs in the matrix matrix: - fast_finish: true # set this flag to immediately finish build once one of the jobs fails. + fast_finish: true # set this flag to immediately finish build once one of the jobs fails. # Install scripts. (runs after repo cloning) install: diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js index 53fa1df1..d720fc2b 100644 --- a/jest-puppeteer.config.js +++ b/jest-puppeteer.config.js @@ -1,7 +1,7 @@ // ps https://github.com/GoogleChrome/puppeteer/issues/3120 module.exports = { launch: { - headless: false, + headless: true, args: [ '--disable-gpu', '--disable-dev-shm-usage', diff --git a/package.json b/package.json index 69b1a43f..773de2d7 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "site": "npm run presite && cross-env APP_TYPE=site npm run build && firebase deploy && npm run docker:push", "analyze": "cross-env ANALYZE=1 umi build", "lint:style": "stylelint \"src/**/*.less\" --syntax less", - "lint": "eslint --ext .js src mock tests && npm run lint:style", + "lint:prettier": "check-prettier lint", + "lint": "eslint --ext .js src mock tests && npm run lint:style && npm run lint:prettier", "lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style", "lint-staged": "lint-staged", "lint-staged:js": "eslint --ext .js", @@ -30,11 +31,12 @@ "docker:push": "npm run docker-hub:build && npm run docker:tag && docker push chenshuai2144/ant-design-pro" }, "dependencies": { - "@babel/runtime": "^7.1.5", - "antd": "^3.10.9", - "bizcharts": "^3.4.0", - "bizcharts-plugin-slider": "^2.1.1-beta.1", "@antv/data-set": "^0.10.0", + "@babel/runtime": "^7.2.0", + "antd": "^3.11.6", + "bizcharts": "^3.4.2", + "bizcharts-plugin-slider": "^2.1.1-beta.1", + "check-prettier": "^1.0.1", "classnames": "^2.2.6", "dva": "^2.4.0", "enquire-js": "^0.2.1", @@ -67,7 +69,7 @@ "babel-eslint": "^10.0.1", "cross-env": "^5.1.1", "cross-port-killer": "^1.0.1", - "enzyme": "^3.7.0", + "enzyme": "3.7.0", "eslint": "^5.4.0", "eslint-config-airbnb": "^17.0.0", "eslint-config-prettier": "^3.0.1", @@ -85,16 +87,16 @@ "mockjs": "^1.0.1-beta3", "prettier": "1.15.2", "pro-download": "^1.0.1", + "slash2": "^2.0.0", "stylelint": "^9.8.0", "stylelint-config-prettier": "^4.0.0", "stylelint-config-standard": "^18.0.0", "tslint": "^5.10.0", "tslint-config-prettier": "^1.10.0", "tslint-react": "^3.6.0", - "umi": "^2.2.7", + "umi": "^2.3.1", "umi-plugin-ga": "^1.1.3", - "umi-plugin-react": "^1.2.0", - "slash2": "^2.0.0" + "umi-plugin-react": "^1.2.0" }, "optionalDependencies": { "puppeteer": "^1.10.0" @@ -115,6 +117,13 @@ "last 2 versions", "not ie <= 10" ], + "checkFiles": [ + "src/**/*.js*", + "src/**/*.ts*", + "src/**/*.less", + "config/**/*.js*", + "scripts/**/*.js" + ], "husky": { "hooks": { "pre-commit": "npm run lint-staged" diff --git a/scripts/getPrettierFiles.js b/scripts/getPrettierFiles.js new file mode 100644 index 00000000..2b01a8ef --- /dev/null +++ b/scripts/getPrettierFiles.js @@ -0,0 +1,21 @@ +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/**'] }); + files = files.concat(jsFiles); + files = files.concat(tsFiles); + files = files.concat(configFiles); + files = files.concat(scriptFiles); + files = files.concat(lessFiles); + if (!files.length) { + return; + } + return files; +}; + +module.exports = getPrettierFiles; diff --git a/scripts/prettier.js b/scripts/prettier.js index 29cbe340..9ce7813a 100644 --- a/scripts/prettier.js +++ b/scripts/prettier.js @@ -9,24 +9,12 @@ const glob = require('glob'); const prettier = require('prettier'); const fs = require('fs'); +const getPrettierFiles = require('./getPrettierFiles'); const prettierConfigPath = require.resolve('../.prettierrc'); let didError = false; -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/**'] }); -files = files.concat(jsFiles); -files = files.concat(tsFiles); -files = files.concat(configFiles); -files = files.concat(scriptFiles); -files = files.concat(lessFiles); -if (!files.length) { - return; -} +const files = getPrettierFiles(); files.forEach(file => { const options = prettier.resolveConfig.sync(file, { -- GitLab