陈帅 7 лет назад
Родитель
Сommit
ac86837d20
5 измененных файлов с 56 добавлено и 7 удалено
  1. 2 1
      .eslintignore
  2. 1 1
      package.json
  3. 48 0
      scripts/prettier.js
  4. 2 3
      src/components/DescriptionList/DescriptionList.js
  5. 3 2
      src/manifest.json

+ 2 - 1
.eslintignore

@@ -1 +1,2 @@
-/functions/mock/**
+/functions/mock/**
+/scripts

+ 1 - 1
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",

+ 48 - 0
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);
+}

+ 2 - 3
src/components/DescriptionList/DescriptionList.js

@@ -22,9 +22,8 @@ const DescriptionList = ({
     <div className={clsString} {...restProps}>
       {title ? <div className={styles.title}>{title}</div> : null}
       <Row gutter={gutter}>
-        {React.Children.map(
-          children,
-          child => (child ? React.cloneElement(child, { column }) : child)
+        {React.Children.map(children, child =>
+          child ? React.cloneElement(child, { column }) : child
         )}
       </Row>
     </div>

+ 3 - 2
src/manifest.json

@@ -9,9 +9,10 @@
     {
       "src": "icons/icon-192x192.png",
       "sizes": "192x192"
-    },{
+    },
+    {
       "src": "icons/icon-128x128.png",
       "sizes": "128x128"
     }
   ]
-}
+}