Skip to content

Commit

Permalink
fix: prettier error (#214)
Browse files Browse the repository at this point in the history
* fix: prettier error

* fix: show log once
  • Loading branch information
chenbin92 authored Apr 6, 2020
1 parent 7d4465a commit e3c49e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 11 additions & 2 deletions packages/plugin-core/src/generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -113,7 +113,8 @@ export default (api) => {
defaultData: {
runtimeModules,
buildConfig: JSON.stringify(buildConfig)
}
},
log
});

const pageGenerator = new PageGenerator({
Expand Down

0 comments on commit e3c49e9

Please sign in to comment.