diff --git a/.eslintignore b/.eslintignore index fa7856aeab5fd08d8d73b48a585bc3d4adb970bc..18275c1c1a871cac03e13ac7acab033d5b74937c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ -/functions/mock/** \ No newline at end of file +/functions/mock/** +/scripts \ No newline at end of file diff --git a/package.json b/package.json index f6314128841b4685da8b60513d882530aa8e9709..1363ec790f8df681c5f7d6394efecf4bb1fba1a4 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "test": "umi test", "test:component": "umi test ./src/components", "test:all": "node ./tests/run-tests.js", - "prettier": "prettier --write './src/**/*'", + "prettier": "node node ./scripts/prettier.js", "docker:dev": "docker-compose -f ./docker/docker-compose.dev.yml up", "docker:build": "docker-compose -f ./docker/docker-compose.dev.yml build", "docker-prod:dev": "docker-compose -f ./docker/docker-compose.yml up", diff --git a/scripts/prettier.js b/scripts/prettier.js new file mode 100644 index 0000000000000000000000000000000000000000..5cbe5c016c6487ce3a1d1b2232decfe83dfb5e3b --- /dev/null +++ b/scripts/prettier.js @@ -0,0 +1,48 @@ +/** + * 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 glob = require('glob'); +const prettier = require('prettier'); +const fs = require('fs'); +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/**'] }); +files = files.concat(jsFiles); +files = files.concat(tsFiles); +if (!files.length) { + return; +} + +files.forEach(async file => { + const options = prettier.resolveConfig.sync(file, { + config: prettierConfigPath, + }); + const fileInfo = await prettier.getFileInfo(file); + 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(`\x1b[34m ${file} is prettier`); + } + } catch (e) { + didError = true; + } +}); +console.log('\x1b[32m prettier success!'); +if (didError) { + process.exit(1); +} diff --git a/src/components/DescriptionList/DescriptionList.js b/src/components/DescriptionList/DescriptionList.js index 73bb5f5f92262c1e1f550d0e6e2a28811717b5da..84bdbd79d3dd52c62833c16783010825ecdbd0c1 100644 --- a/src/components/DescriptionList/DescriptionList.js +++ b/src/components/DescriptionList/DescriptionList.js @@ -22,9 +22,8 @@ const DescriptionList = ({