Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): remove findup-sync from root move to utils package && format ts files #806

Merged
merged 13 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
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
47 changes: 23 additions & 24 deletions INIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 2 additions & 7 deletions bin/cli.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
73 changes: 51 additions & 22 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
Original file line number Diff line number Diff line change
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
3 changes: 1 addition & 2 deletions packages/generators/__tests__/add-generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generatePluginName } from "../utils/plugins"
import { generatePluginName } from "../utils/plugins";

describe("generatePluginName", () => {
it("should return webpack Standard Plugin Name for Name : extract-text-webpack-plugin", () => {
Expand All @@ -11,4 +11,3 @@ describe("generatePluginName", () => {
expect(pluginName).toEqual("webpack.DefinePlugin");
});
});

8 changes: 4 additions & 4 deletions packages/generators/add-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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());


/**
*
* Checks if the given array has a given property
Expand Down Expand Up @@ -91,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 @@ -380,7 +380,7 @@ export default class AddGenerator extends Generator {
(p: boolean): void => {
if (p) {
this.dependencies.push(answerToAction.actionAnswer);
const pluginName = generatePluginName(answerToAction.actionAnswer)
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export {
loaderGenerator,
pluginGenerator,
removeGenerator,
updateGenerator,
updateGenerator
};