fix: prettier error (#214)

* fix: prettier error

* fix: show log once
This commit is contained in:
chenbin92 2020-04-06 18:23:28 +08:00 committed by GitHub
parent 87ffdc071e
commit d360264b34
2 changed files with 14 additions and 4 deletions

View File

@ -35,13 +35,19 @@ export default class Generator {
private projectRoot: string;
constructor({ projectRoot, targetDir, templateDir, defaultData }) {
private log: any;
private showPrettierError: boolean;
constructor({ projectRoot, targetDir, templateDir, defaultData, log }) {
this.projectRoot = projectRoot;
this.templateDir = templateDir;
this.targetDir = targetDir;
this.renderData = defaultData;
this.contentRegistration = {};
this.rerender = false;
this.log = log;
this.showPrettierError = true;
}
public addExport = (registerKey ,exportData: IExportData|IExportData[]) => {
@ -136,7 +142,10 @@ export default class Generator {
singleQuote: true
});
} catch (error) {
console.error(error);
if (this.showPrettierError) {
this.log.warn(`Prettier format error: ${error.message}`);
this.showPrettierError = false;
}
}
fse.ensureDirSync(path.dirname(targetPath));
fse.writeFileSync(targetPath, content, 'utf-8');

View File

@ -8,7 +8,7 @@ import getPages from './utils/getPages';
import formatPath from './utils/formatPath';
export default (api) => {
const { onHook, onGetWebpackConfig, registerMethod, registerUserConfig, context, getAllPlugin, setValue, modifyUserConfig } = api;
const { onHook, onGetWebpackConfig, registerMethod, registerUserConfig, context, getAllPlugin, setValue, modifyUserConfig, log } = api;
const { rootDir, command, userConfig } = context;
const iceTempPath = path.join(rootDir, '.ice');
@ -113,7 +113,8 @@ export default (api) => {
defaultData: {
runtimeModules,
buildConfig: JSON.stringify(buildConfig)
}
},
log
});
const pageGenerator = new PageGenerator({