Skip to content

Commit

Permalink
Merge branch 'master' of github.com:webpack/webpack-cli into cli-blan…
Browse files Browse the repository at this point in the history
…k-fix
  • Loading branch information
pranshuchittora committed May 31, 2019
2 parents 7d31321 + ce8f6e1 commit 3d67892
Show file tree
Hide file tree
Showing 64 changed files with 971 additions and 845 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Expand Up @@ -9,4 +9,5 @@ test/**/null.js
test/**/main.js
test/**/cliEntry.js
test/**/foo.js
test/binCases/config-location/webpack-babel-config/bin/es6.js
test/binCases/config-location/webpack-babel-config/bin/es6.js
packages/utils/validate-identifier.ts
49 changes: 24 additions & 25 deletions INIT.md
@@ -1,6 +1,6 @@
# webpack-cli init

`webpack-cli init` is used to initialize `webpack` projects quickly by scaffolding configuration and installing modules required for the project as per user preferences.
`webpack-cli init` is used to initialize `webpack` projects quickly by scaffolding configuration and creating a runnable project with all the dependencies based on the user preferences.

## Initial Setup

Expand All @@ -10,38 +10,38 @@ These are the steps necessary to setup `webpack-cli init` locally:

1. Create `package.json` through npm

```shell
npm init
```
```shell
npm init
```

2. Install `webpack` and `webpack-cli` as devDependencies

```shell
```shell
npm install --save-dev webpack webpack-cli
```

3. Install `@webpack-cli/init` package to add the init scaffold

```shell
```shell
npm install --save-dev @webpack-cli/init
```

### b. Global Setup

These are the steps necessary to setup `webpack-cli init` globally:

1. Install `webpack` and `webpack-cli` globally

```shell
npm install -g webpack webpack-cli
```
```shell
npm install -g webpack webpack-cli
```

2. Install `@webpack-cli/init` package to add the init scaffold

```shell
npm install -g @webpack-cli/init
```
```shell
npm install -g @webpack-cli/init
```

## Usage

### a. Running locally
Expand All @@ -60,36 +60,35 @@ webpack-cli init

1. `Will your application have multiple bundles? (y/N)`

> *Property/key resolved: [entry](https://webpack.js.org/configuration/entry-context/#entry)*
> _Property/key resolved: [entry](https://webpack.js.org/configuration/entry-context/#entry)_
This is used to determine if your app will have multiple [entry points](https://webpack.js.org/configuration/entry-context/#entry).
If you want to have multiple entry points, answer yes. If you want to have only one, answer no.

2. `Which will be your application entry point? (src/index)`

> *Property/key resolved: [entry](https://webpack.js.org/configuration/entry-context/#entry)*
> _Property/key resolved: [entry](https://webpack.js.org/configuration/entry-context/#entry)_
This tells webpack from which file to start bundling your application. The default answer `src/index` will tell webpack to look for a file called `index` inside a folder named `src`.
This tells webpack from which file to start bundling your application. The default answer `src/index` will tell webpack to look for a file called `index` inside a folder named `src`.

3. `In which folder do you want to store your generated bundles? (dist)`

> *Property/key resolved: [output.path](https://webpack.js.org/configuration/output/#output-path)*
> _Property/key resolved: [output.path](https://webpack.js.org/configuration/output/#output-path)_
The output directory is where your bundled application will be. Your `index.html` will read the generated files from this folder, that is usually named `dist`.

4. `Will you be using ES2015? (Y/n)`

> *Property/key resolved: [module.rules](https://webpack.js.org/configuration/module/#module-rules) (for .js files)*
> _Property/key resolved: [module.rules](https://webpack.js.org/configuration/module/#module-rules) (for .js files)_
This enables webpack to parse [`ES2015`](https://babeljs.io/learn-es2015/) code. Answer `Yes` if you want to use modern JavaScript in your project.
This enables webpack to parse [`ES2015`](https://babeljs.io/learn-es2015/) code. Answer `Yes` if you want to use modern JavaScript in your project.

5. `Will you use one of the below CSS solutions?`

> *Property/key resolved: [module.rules](https://webpack.js.org/configuration/module/#module-rules) (for .scss,.less,.css,.postCSS files)*
> _Property/key resolved: [module.rules](https://webpack.js.org/configuration/module/#module-rules) (for .scss,.less,.css,.postCSS files)_
If you use any sort of style in your project, such as [`.less`](http://lesscss.org/), [`.scss`](http://sass-lang.com/), [`.css`](https://developer.mozilla.org/en-US/docs/Web/CSS) or [`postCSS`](http://postcss.org/) you will need to declare this here. If you don't use CSS, answer no.
If you use any sort of style in your project, such as [`.less`](http://lesscss.org/), [`.scss`](http://sass-lang.com/), [`.css`](https://developer.mozilla.org/en-US/docs/Web/CSS) or [`postCSS`](http://postcss.org/) you will need to declare this here. If you don't use CSS, answer no.

6. `If you want to bundle your CSS files, what will you name the bundle? (press
enter to skip)`
6. `If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)`

If you indicate based on previous questions that you are using production, this will be enabled. The default value for your generated CSS file is `style.[contentHash].css`, which will collect all your `.less`, `.scss` or `.css` into one file. This will make your build faster in production.
4 changes: 2 additions & 2 deletions SECURITY.md
Expand Up @@ -8,8 +8,8 @@ webpack CLI is currently supporting webpack v4 and webpack v5. Security fixes ar

| webpack version | webpack-cli version | Supported |
| --------------- | ----------------------------- | ------------------ |
| >= 4.20.x | ^3.1.2 | :white_check_mark: |
| <= 4.19.x | ^3.1.1 | :white_check_mark: |
| >= 4.20.x | ^3.1.2 | :white_check_mark: |
| <= 4.19.x | ^3.1.1 | :white_check_mark: |
| 5.x.0 | ^3.1.2 | :white_check_mark: |
| 5.0.x | ^3.1.2 | :white_check_mark: |
| < 4.x.x | (CLI included in webpack < 4) | :x: |
Expand Down
6 changes: 5 additions & 1 deletion bin/opencollective.js
Expand Up @@ -26,7 +26,11 @@ function printBadge() {
print(`Please consider donating to our ${chalk.bold.blue("Open Collective")}`);
print("to help us maintain this package.");
console.log("\n\n");
print(`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow("https://opencollective.com/webpack/donate")}`);
print(
`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow(
"https://opencollective.com/webpack/donate"
)}`
);
console.log("\n");
}

Expand Down
4 changes: 2 additions & 2 deletions bin/utils/convert-argv.js
Expand Up @@ -110,9 +110,9 @@ module.exports = function(...args) {
argv.configRegister.forEach(dep => {
require(dep);
});
return require(configPath);
return require(path.resolve(process.cwd(), configPath));
} else {
return require(configPath);
return require(path.resolve(process.cwd(), configPath));
}
})();
options = prepareOptions(options, argv);
Expand Down
76 changes: 52 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -33,9 +33,10 @@
"clean:all": "rimraf node_modules packages/*/{node_modules}",
"commit": "git-cz",
"docs": "typedoc",
"format": "prettier-eslint ./bin/*.js ./test/**/*.js ./packages/**/*.js --write",
"lint:codeOnly": "eslint \"{bin}/**/!(__testfixtures__)/*.js\" \"{bin}/**.js\"",
"lint": "eslint \"./bin/*.js\" \"./test/**/*.js\" \"packages/**/!(node_modules)/*.ts\"",
"format": "npm run format:js && npm run format:ts",
"format:ts": "prettier-eslint ./bin/*.js ./bin/**/*.js ./test/**/*.js ./packages/**/**/*.js ./packages/**/*.js --write",
"format:js": "prettier-eslint ./packages/**/**/*.ts ./packages/**/*.ts ./packages/**/**/**/*.ts --write",
"lint": "eslint \"./bin/*.js\" \"./bin/**/*.js\" \"./test/**/*.js\" \"packages/**/!(node_modules)/*.ts\" \"packages/**/!(node_modules)/**/*.ts\"",
"postinstall": "node ./bin/opencollective.js",
"pretest": "npm run build && npm run lint",
"reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov",
Expand Down Expand Up @@ -145,8 +146,8 @@
"@commitlint/travis-cli": "^7.2.1",
"@types/jest": "^23.3.14",
"@types/node": "^10.12.9",
"@typescript-eslint/eslint-plugin": "^1.6.0",
"@typescript-eslint/parser": "^1.6.0",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"babel-preset-env": "^1.7.0",
"babel-preset-jest": "^24.3.0",
"bundlesize": "^0.17.2",
Expand Down
1 change: 1 addition & 0 deletions packages/generators/.gitignore
Expand Up @@ -2,3 +2,4 @@
**/*.js
!*.test.js
!/**/*.test.js
!/templates/*.js
13 changes: 13 additions & 0 deletions packages/generators/__tests__/add-generator.test.ts
@@ -0,0 +1,13 @@
import { generatePluginName } from "../utils/plugins";

describe("generatePluginName", () => {
it("should return webpack Standard Plugin Name for Name : extract-text-webpack-plugin", () => {
const pluginName = generatePluginName("extract-text-webpack-plugin");
expect(pluginName).toEqual("ExtractTextWebpackPlugin");
});

it("should return webpack Standard Plugin Name for Name : webpack.DefinePlugin", () => {
const pluginName = generatePluginName("webpack.DefinePlugin");
expect(pluginName).toEqual("webpack.DefinePlugin");
});
});
39 changes: 8 additions & 31 deletions packages/generators/add-generator.ts
Expand Up @@ -11,27 +11,11 @@ import { AutoComplete, Confirm, Input, List } from "@webpack-cli/webpack-scaffol

import { SchemaProperties, WebpackOptions } from "./types";
import entryQuestions from "./utils/entry";

import webpackDevServerSchema from "webpack-dev-server/lib/options.json";
import webpackSchema from "./utils/optionsSchema.json";
import { generatePluginName } from "./utils/plugins";
import * as webpackDevServerSchema from "webpack-dev-server/lib/options.json";
import * as webpackSchema from "./utils/optionsSchema.json";
const PROPS: string[] = Array.from(PROP_TYPES.keys());

/**
*
* Replaces the string with a substring at the given index
* https://gist.github.com/efenacigiray/9367920
*
* @param {String} str - string to be modified
* @param {Number} index - index to replace from
* @param {String} replace - string to replace starting from index
*
* @returns {String} string - The newly mutated string
*
*/
function replaceAt(str: string, index: number, replace: string): string {
return str.substring(0, index) + replace + str.substring(index + 1);
}

/**
*
* Checks if the given array has a given property
Expand Down Expand Up @@ -106,8 +90,9 @@ export default class AddGenerator extends Generator {
const done: () => {} = this.async();
let action: string;
const self: this = this;
const manualOrListInput: (promptAction: string) => Generator.Question = (promptAction: string): Generator.Question =>
Input("actionAnswer", `What do you want to add to ${promptAction}?`);
const manualOrListInput: (promptAction: string) => Generator.Question = (
promptAction: string
): Generator.Question => Input("actionAnswer", `What do you want to add to ${promptAction}?`);
let inputPrompt: Generator.Question;

// first index indicates if it has a deep prop, 2nd indicates what kind of
Expand Down Expand Up @@ -140,7 +125,7 @@ export default class AddGenerator extends Generator {
.then(
(entryTypeAnswer: { entryType: boolean }): Promise<void | {}> => {
// Ask different questions for entry points
return entryQuestions(self, entryTypeAnswer);
return entryQuestions(self, entryTypeAnswer.entryType);
}
)
.then(
Expand Down Expand Up @@ -395,15 +380,7 @@ export default class AddGenerator extends Generator {
(p: boolean): void => {
if (p) {
this.dependencies.push(answerToAction.actionAnswer);
const normalizePluginName = answerToAction.actionAnswer.replace(
"-webpack-plugin",
"Plugin"
);
const pluginName = replaceAt(
normalizePluginName,
0,
normalizePluginName.charAt(0).toUpperCase()
);
const pluginName = generatePluginName(answerToAction.actionAnswer);
this.configuration.config.topScope.push(
`const ${pluginName} = require("${answerToAction.actionAnswer}")`
);
Expand Down
3 changes: 2 additions & 1 deletion packages/generators/addon-generator.ts
Expand Up @@ -31,7 +31,8 @@ const addonGenerator = (
copyFiles: string[],
copyTemplateFiles: string[],
templateFn: Function
): typeof Generator => class AddonGenerator extends Generator {
): typeof Generator =>
class AddonGenerator extends Generator {
public props: Generator.Question;
public copy: (value: string, index: number, array: string[]) => void;
public copyTpl: (value: string, index: number, array: string[]) => void;
Expand Down

0 comments on commit 3d67892

Please sign in to comment.