Skip to content

Commit

Permalink
fix: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed May 15, 2021
1 parent 56a765a commit 0b5ad31
Show file tree
Hide file tree
Showing 119 changed files with 2,921 additions and 657 deletions.
14 changes: 12 additions & 2 deletions .eslintrc.js
@@ -1,7 +1,12 @@
module.exports = {
root: true,
reportUnusedDisableDirectives: true,
extends: ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended", "prettier"],
extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:prettier/recommended",
"prettier",
],
parserOptions: { ecmaVersion: 2018, sourceType: "script" },
plugins: ["node"],
settings: {
Expand Down Expand Up @@ -30,11 +35,16 @@ module.exports = {
},
},
files: ["**/*.ts"],
extends: ["plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
rules: {
"node/no-unsupported-features/es-syntax": "off",
"max-len": [0, 100],
},
},
],
Expand Down
10 changes: 8 additions & 2 deletions jest.config.js
@@ -1,7 +1,10 @@
const { cli } = require("webpack");

// Ignore core-flags test for webpack@4
const ignorePattern = typeof cli !== "undefined" ? ["<rootDir>/node_modules/"] : ["<rootDir>/node_modules/", "<rootDir>/test/build/core-flags"];
const ignorePattern =
typeof cli !== "undefined"
? ["<rootDir>/node_modules/"]
: ["<rootDir>/node_modules/", "<rootDir>/test/build/core-flags"];

module.exports = {
testPathIgnorePatterns: ignorePattern,
Expand All @@ -20,5 +23,8 @@ module.exports = {
setupFilesAfterEnv: ["<rootDir>/setupTest.js"],
globalTeardown: "<rootDir>/scripts/cleanupTest.js",
globalSetup: "<rootDir>/scripts/globalSetup.js",
modulePathIgnorePatterns: ["<rootDir>/test/loader/test-loader", "<rootDir>/test/plugin/test-plugin"],
modulePathIgnorePatterns: [
"<rootDir>/test/loader/test-loader",
"<rootDir>/test/plugin/test-plugin",
],
};
4 changes: 3 additions & 1 deletion packages/configtest/src/index.ts
Expand Up @@ -52,7 +52,9 @@ class ConfigTestCommand {
process.exit(2);
}

logger.success("There are no validation errors in the given webpack configuration.");
logger.success(
"There are no validation errors in the given webpack configuration.",
);
},
);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/generators/README.md
Expand Up @@ -19,7 +19,12 @@ To run the package programmatically, install it as a dependency. When using the
### Node

```js
const { addonGenerator, initGenerator, loaderGenerator, pluginGenerator } = require("@webpack-cli/generators");
const {
addonGenerator,
initGenerator,
loaderGenerator,
pluginGenerator,
} = require("@webpack-cli/generators");

// ... compose with yeoman env or add a generator to your own yeoman project
```
Expand Down
35 changes: 27 additions & 8 deletions packages/generators/src/addon-generator.ts
Expand Up @@ -57,9 +57,18 @@ const addonGenerator = (

public async prompting(): Promise<void> {
if (!this.supportedTemplates.includes(this.template)) {
this.utils.logger.warn(`⚠ ${this.template} is not a valid template, please select one from below`);

const { selectedTemplate } = await List(this, "selectedTemplate", "Select a valid template from below:", this.supportedTemplates, "default", false);
this.utils.logger.warn(
`⚠ ${this.template} is not a valid template, please select one from below`,
);

const { selectedTemplate } = await List(
this,
"selectedTemplate",
"Select a valid template from below:",
this.supportedTemplates,
"default",
false,
);

this.template = selectedTemplate;
}
Expand Down Expand Up @@ -90,8 +99,11 @@ const addonGenerator = (

public writing(): void {
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));
this.fs.extendJSON(
this.destinationPath("package.json"),
// eslint-disable-next-line @typescript-eslint/no-var-requires
require(packageJsonTemplatePath)(this.props.name),
);

let files = [];
try {
Expand All @@ -103,20 +115,27 @@ const addonGenerator = (
}

// Template file paths should be of the form `path/to/_file.js.tpl`
const copyTemplateFiles = files.filter((filePath) => path.basename(filePath).startsWith("_"));
const copyTemplateFiles = files.filter((filePath) =>
path.basename(filePath).startsWith("_"),
);

// File paths should be of the form `path/to/file.js.tpl`
const copyFiles = files.filter((filePath) => !copyTemplateFiles.includes(filePath));

copyFiles.forEach((filePath) => {
// `absolute-path/to/file.js.tpl` -> `destination-path/file.js`
const destFilePath = path.relative(this.resolvedTemplatePath, filePath).replace(".tpl", "");
const destFilePath = path
.relative(this.resolvedTemplatePath, filePath)
.replace(".tpl", "");
this.fs.copyTpl(filePath, this.destinationPath(destFilePath));
});

copyTemplateFiles.forEach((filePath) => {
// `absolute-path/to/_file.js.tpl` -> `destination-path/file.js`
const destFilePath = path.relative(this.resolvedTemplatePath, filePath).replace("_", "").replace(".tpl", "");
const destFilePath = path
.relative(this.resolvedTemplatePath, filePath)
.replace("_", "")
.replace(".tpl", "");
this.fs.copyTpl(filePath, this.destinationPath(destFilePath), templateFn(this));
});
}
Expand Down
105 changes: 90 additions & 15 deletions packages/generators/src/handlers/default.ts
Expand Up @@ -12,28 +12,55 @@ const resolveFile = (file: string): string => {
* @param Question Contains questions
*/

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function questions(self: CustomGenerator, Question: Record<string, any>): Promise<void> {
export async function questions(
self: CustomGenerator,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Question: Record<string, any>,
): Promise<void> {
// Handle JS language solutions
const { langType } = await Question.List(self, "langType", "Which of the following JS solutions do you want to use?", ["none", "ES6", "Typescript"], "none", self.force);
const { langType } = await Question.List(
self,
"langType",
"Which of the following JS solutions do you want to use?",
["none", "ES6", "Typescript"],
"none",
self.force,
);

switch (langType) {
case "ES6":
self.dependencies = [...self.dependencies, "babel-loader", "@babel/core", "@babel/preset-env"];
self.dependencies = [
...self.dependencies,
"babel-loader",
"@babel/core",
"@babel/preset-env",
];
break;
case "Typescript":
self.dependencies = [...self.dependencies, "typescript", "ts-loader"];
break;
}

// Configure devServer configuraion
const { devServer } = await Question.Confirm(self, "devServer", "Do you want to use webpack-dev-server?", true, self.force);
const { devServer } = await Question.Confirm(
self,
"devServer",
"Do you want to use webpack-dev-server?",
true,
self.force,
);
if (devServer) {
self.dependencies = [...self.dependencies, "webpack-dev-server"];
}

// Handle addition of html-webpack-plugin
const { htmlWebpackPlugin } = await Question.Confirm(self, "htmlWebpackPlugin", "Do you want to simplify the creation of HTML files for your bundle?", true, self.force);
const { htmlWebpackPlugin } = await Question.Confirm(
self,
"htmlWebpackPlugin",
"Do you want to simplify the creation of HTML files for your bundle?",
true,
self.force,
);
if (htmlWebpackPlugin) {
self.dependencies = [...self.dependencies, "html-webpack-plugin"];
}
Expand All @@ -42,18 +69,53 @@ export async function questions(self: CustomGenerator, Question: Record<string,
self.answers = { ...self.answers, langType, devServer, htmlWebpackPlugin };

// Handle CSS solutions
const { cssType } = await Question.List(self, "cssType", "Which of the following CSS solutions do you want to use?", ["none", "CSS only", "SASS", "LESS", "Stylus"], "none", self.force);
const { cssType } = await Question.List(
self,
"cssType",
"Which of the following CSS solutions do you want to use?",
["none", "CSS only", "SASS", "LESS", "Stylus"],
"none",
self.force,
);

if (cssType == "none") {
self.answers = { ...self.answers, cssType, isCSS: false, isPostCSS: false, extractPlugin: "No" };
self.answers = {
...self.answers,
cssType,
isCSS: false,
isPostCSS: false,
extractPlugin: "No",
};
return;
}

const { isCSS } = cssType != "CSS only" ? await Question.Confirm(self, "isCSS", `Will you be using CSS styles along with ${cssType} in your project?`, true, self.force) : { isCSS: true };

const { isPostCSS } = await Question.Confirm(self, "isPostCSS", "Will you be using PostCSS in your project?", cssType == "CSS only", self.force);
const { isCSS } =
cssType != "CSS only"
? await Question.Confirm(
self,
"isCSS",
`Will you be using CSS styles along with ${cssType} in your project?`,
true,
self.force,
)
: { isCSS: true };

const { isPostCSS } = await Question.Confirm(
self,
"isPostCSS",
"Will you be using PostCSS in your project?",
cssType == "CSS only",
self.force,
);

const { extractPlugin } = await Question.List(self, "extractPlugin", "Do you want to extract CSS for every file?", ["No", "Only for Production", "Yes"], "No", self.force);
const { extractPlugin } = await Question.List(
self,
"extractPlugin",
"Do you want to extract CSS for every file?",
["No", "Only for Production", "Yes"],
"No",
self.force,
);

switch (cssType) {
case "SASS":
Expand All @@ -79,7 +141,13 @@ export async function questions(self: CustomGenerator, Question: Record<string,
self.dependencies = [...self.dependencies, "mini-css-extract-plugin"];
}

self.answers = { ...self.answers, cssType, isCSS, isPostCSS, extractPlugin };
self.answers = {
...self.answers,
cssType,
isCSS,
isPostCSS,
extractPlugin,
};
}

/**
Expand Down Expand Up @@ -109,7 +177,11 @@ export function generate(self: CustomGenerator): void {
self.fs.copyTpl(resolveFile("template.html"), self.destinationPath("index.html"), {});

// Generate webpack configuration
self.fs.copyTpl(resolveFile("webpack.configjs.tpl"), self.destinationPath("webpack.config.js"), { ...self.answers, entry });
self.fs.copyTpl(
resolveFile("webpack.configjs.tpl"),
self.destinationPath("webpack.config.js"),
{ ...self.answers, entry },
);
self.configurationPath = self.destinationPath("webpack.config.js");

// Generate JS language essentials
Expand All @@ -124,6 +196,9 @@ export function generate(self: CustomGenerator): void {

// Generate postcss configuration
if (self.answers.isPostCSS) {
self.fs.copyTpl(resolveFile("postcss.config.js"), self.destinationPath("postcss.config.js"));
self.fs.copyTpl(
resolveFile("postcss.config.js"),
self.destinationPath("postcss.config.js"),
);
}
}
4 changes: 3 additions & 1 deletion packages/generators/src/index.ts
Expand Up @@ -43,7 +43,9 @@ class GeneratorsCommand {
async (generationPath, options) => {
options.generationPath = generationPath || ".";

const env = yeoman.createEnv([], { cwd: options.generationPath });
const env = yeoman.createEnv([], {
cwd: options.generationPath,
});
const generatorName = "webpack-init-generator";

env.registerStub(initGenerator, generatorName);
Expand Down

0 comments on commit 0b5ad31

Please sign in to comment.