From ac86837d20494f082ab39b1a52eabea3bc2ac81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Sat, 1 Dec 2018 13:31:08 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#2953=EF=BC=8Cprettier=20support=20win?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 3 +- package.json | 2 +- scripts/prettier.js | 48 +++++++++++++++++++ .../DescriptionList/DescriptionList.js | 5 +- src/manifest.json | 5 +- 5 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 scripts/prettier.js diff --git a/.eslintignore b/.eslintignore index fa7856ae..18275c1c 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 f6314128..1363ec79 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 00000000..5cbe5c01 --- /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 73bb5f5f..84bdbd79 100644 --- a/src/components/DescriptionList/DescriptionList.js +++ b/src/components/DescriptionList/DescriptionList.js @@ -22,9 +22,8 @@ const DescriptionList = ({
{title ?
{title}
: null} - {React.Children.map( - children, - child => (child ? React.cloneElement(child, { column }) : child) + {React.Children.map(children, child => + child ? React.cloneElement(child, { column }) : child )}
diff --git a/src/manifest.json b/src/manifest.json index 69bce982..42db46a1 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -9,9 +9,10 @@ { "src": "icons/icon-192x192.png", "sizes": "192x192" - },{ + }, + { "src": "icons/icon-128x128.png", "sizes": "128x128" } ] -} \ No newline at end of file +} -- GitLab