Skip to content

Commit

Permalink
chore: merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabh3112 committed May 31, 2019
2 parents b6a438d + f6e57a8 commit b7ef7a4
Show file tree
Hide file tree
Showing 64 changed files with 985 additions and 827 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.
21 changes: 21 additions & 0 deletions SECURITY.md
@@ -0,0 +1,21 @@
# Security Policy

This document explains the security policy of webpack-cli and how we intend to support webpack and webpack-cli.

## Supported Versions

webpack CLI is currently supporting webpack v4 and webpack v5. Security fixes are released in patches.

| webpack version | webpack-cli version | Supported |
| --------------- | ----------------------------- | ------------------ |
| >= 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: |

**Note: Using webpack < 4 with webpack CLI is not required as CLI was [included](https://github.com/webpack/webpack/commit/4b0332d3909eea8115d84f9a03da2d52478daa70#diff-b9cfc7f2cdf78a7f4b91a753d10865a2) in webpack.**

## Reporting a Vulnerability

To report a vulnerability, please contact one of webpack maintainers through the email provided from either npm, GitHub or reach out at other social media platforms. For third party security vulnerabilities, submitting an issue or Pull Request to fix the security vulerability is much appreciated.
9 changes: 2 additions & 7 deletions bin/cli.js
Expand Up @@ -326,19 +326,14 @@ For more information, see https://webpack.js.org/api/cli/.`);
const SIX_DAYS = 518400000;
const now = new Date();
if (now.getDay() === MONDAY) {
const {
access,
constants,
statSync,
utimesSync,
} = require("fs");
const { access, constants, statSync, utimesSync } = require("fs");
const lastPrint = statSync(openCollectivePath).atime;
const lastPrintTS = new Date(lastPrint).getTime();
const timeSinceLastPrint = now.getTime() - lastPrintTS;
if (timeSinceLastPrint > SIX_DAYS) {
require(openCollectivePath);
// On windows we need to manually update the atime
access(openCollectivePath, constants.W_OK, (e) => {
access(openCollectivePath, constants.W_OK, e => {
if (!e) utimesSync(openCollectivePath, now, now);
});
}
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
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");
});
});
13 changes: 3 additions & 10 deletions packages/generators/add-generator.ts
Expand Up @@ -25,6 +25,7 @@ import entryQuestions from "./utils/entry";
import * as AutoComplete from "inquirer-autocomplete-prompt";
import path, { resolve } from "path";
import glob from 'glob-all'
import { generatePluginName } from "./utils/plugins";

/**
*
Expand Down Expand Up @@ -88,7 +89,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 @@ -355,15 +356,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
2 changes: 1 addition & 1 deletion packages/generators/index.ts
Expand Up @@ -13,5 +13,5 @@ export {
loaderGenerator,
pluginGenerator,
removeGenerator,
updateGenerator,
updateGenerator
};

0 comments on commit b7ef7a4

Please sign in to comment.