Skip to content

Commit

Permalink
refactor: generators (#2328)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabh3112 authored Jan 9, 2021
1 parent b6884fa commit 7506f07
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/configtest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ConfigTestCommand {
throw new webpack.WebpackOptionsValidationError(error);
}
} catch (error) {
const isValidationError = (error) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isValidationError = (error: any): boolean => {
// https://github.com/webpack/webpack/blob/master/lib/index.js#L267
// https://github.com/webpack/webpack/blob/v4.44.2/lib/webpack.js#L90
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion packages/generators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
},
"files": [
"lib",
"templates"
"addon-template",
"init-template",
"loader-template",
"plugin-template"
],
"dependencies": {
"@webpack-cli/utils": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/src/addon-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const addonGenerator = (
}

public writing(): void {
const packageJsonTemplatePath = '../templates/addon-package.json.js';
const packageJsonTemplatePath = '../addon-template/package.json.js';
// eslint-disable-next-line @typescript-eslint/no-var-requires
this.fs.extendJSON(this.destinationPath('package.json'), require(packageJsonTemplatePath)(this.props.name));

Expand Down
12 changes: 6 additions & 6 deletions packages/generators/src/init-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ export default class InitGenerator extends CustomGenerator {
public writing(): void {
this.config.set('configuration', this.configuration);

const packageJsonTemplatePath = '../templates/package.json.js';
const packageJsonTemplatePath = '../init-template/package.json.js';
// eslint-disable-next-line @typescript-eslint/no-var-requires
this.fs.extendJSON(this.destinationPath('package.json'), require(packageJsonTemplatePath)(this.autoGenerateConfig));

const generateEntryFile = (entryPath: string, name: string): void => {
entryPath = entryPath.replace(/'/g, '');
this.fs.copyTpl(path.resolve(__dirname, '../templates/index.js'), this.destinationPath(entryPath), { name });
this.fs.copyTpl(path.resolve(__dirname, '../init-template/index.js'), this.destinationPath(entryPath), { name });
};

// Generate entry file/files
Expand All @@ -262,16 +262,16 @@ export default class InitGenerator extends CustomGenerator {
}

// Generate README
this.fs.copyTpl(path.resolve(__dirname, '../templates/README.md'), this.destinationPath('README.md'), {});
this.fs.copyTpl(path.resolve(__dirname, '../init-template/README.md'), this.destinationPath('README.md'), {});

// Generate HTML template file, copy the default service worker
this.fs.copyTpl(path.resolve(__dirname, '../templates/template.html'), this.destinationPath('index.html'), {});
this.fs.copyTpl(path.resolve(__dirname, '../init-template/template.html'), this.destinationPath('index.html'), {});

if (this.langType === LangType.ES6) {
this.fs.copyTpl(path.resolve(__dirname, '../templates/.babelrc'), this.destinationPath('.babelrc'), {});
this.fs.copyTpl(path.resolve(__dirname, '../init-template/.babelrc'), this.destinationPath('.babelrc'), {});
} else if (this.langType === LangType.Typescript) {
// Generate tsconfig
const tsConfigTemplatePath = '../templates/tsconfig.json.js';
const tsConfigTemplatePath = '../init-template/tsconfig.json.js';
// eslint-disable-next-line @typescript-eslint/no-var-requires
this.fs.extendJSON(this.destinationPath('tsconfig.json'), require(tsConfigTemplatePath));
}
Expand Down
1 change: 1 addition & 0 deletions packages/generators/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ export class CustomGenerator extends Generator {
};
public isProd: boolean;
public dependencies: string[];
public getTemplatePath: (template: string) => string;
}

0 comments on commit 7506f07

Please sign in to comment.