Browse Source

fix #2953,prettier support win

pull/3036/head
陈帅 7 years ago
parent
commit
ac86837d20
  1. 3
      .eslintignore
  2. 2
      package.json
  3. 48
      scripts/prettier.js
  4. 5
      src/components/DescriptionList/DescriptionList.js
  5. 5
      src/manifest.json

3
.eslintignore

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

2
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
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);
}

5
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>

5
src/manifest.json

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

Loading…
Cancel
Save