diff --git a/.eslintignore b/.eslintignore index aa24f295da5..d37187d8e9d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,3 +2,4 @@ coverage test dist +docs diff --git a/.npmignore b/.npmignore index 8ba3247df58..9e98340ece3 100644 --- a/.npmignore +++ b/.npmignore @@ -12,3 +12,4 @@ __testfixtures__ *.input.js types.js *.spec.js +docs diff --git a/.travis.yml b/.travis.yml index 2d1bce4e692..8294398d524 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,10 +11,6 @@ sudo: false notifications: email: false -before_install: -- yarn global add eslint -- yarn global add eslint-plugin-node -- yarn global add eslint-plugin-flowtype before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start diff --git a/docs/AddGenerator.html b/docs/AddGenerator.html new file mode 100644 index 00000000000..2840e15a5b0 --- /dev/null +++ b/docs/AddGenerator.html @@ -0,0 +1,201 @@ + + + + + JSDoc: Class: AddGenerator + + + + + + + + + + +
+ +

Class: AddGenerator

+ + + + + + +
+ +
+ +

AddGenerator() → {Void}

+ + +
+ +
+
+ + + + + + +

new AddGenerator() → {Void}

+ + + + + + +
+ Generator for adding properties +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ After execution, transforms are triggered +
+ + + +
+
+ Type +
+
+ +Void + + +
+
+ + + + + + + + +
+ + +

Extends

+ + + + +
    +
  • Generator
  • +
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/docs/InitGenerator.html b/docs/InitGenerator.html new file mode 100644 index 00000000000..03e0506e8ba --- /dev/null +++ b/docs/InitGenerator.html @@ -0,0 +1,201 @@ + + + + + JSDoc: Class: InitGenerator + + + + + + + + + + +
+ +

Class: InitGenerator

+ + + + + + +
+ +
+ +

InitGenerator() → {Void}

+ + +
+ +
+
+ + + + + + +

new InitGenerator() → {Void}

+ + + + + + +
+ Generator for initializing a webpack config +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ After execution, transforms are triggered +
+ + + +
+
+ Type +
+
+ +Void + + +
+
+ + + + + + + + +
+ + +

Extends

+ + + + +
    +
  • Generator
  • +
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/docs/LoaderGenerator.html b/docs/LoaderGenerator.html new file mode 100644 index 00000000000..a18649f8f04 --- /dev/null +++ b/docs/LoaderGenerator.html @@ -0,0 +1,181 @@ + + + + + JSDoc: Class: LoaderGenerator + + + + + + + + + + +
+ +

Class: LoaderGenerator

+ + + + + + +
+ +
+ +

LoaderGenerator()

+ + +
+ +
+
+ + + + + + +

new LoaderGenerator()

+ + + + + + +
+ A yeoman generator class for creating a webpack +loader project. It adds some starter loader code +and runs `webpack-defaults`. +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + +
    +
  • Generator
  • +
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/docs/PluginGenerator.html b/docs/PluginGenerator.html new file mode 100644 index 00000000000..26496645e79 --- /dev/null +++ b/docs/PluginGenerator.html @@ -0,0 +1,181 @@ + + + + + JSDoc: Class: PluginGenerator + + + + + + + + + + +
+ +

Class: PluginGenerator

+ + + + + + +
+ +
+ +

PluginGenerator()

+ + +
+ +
+
+ + + + + + +

new PluginGenerator()

+ + + + + + +
+ A yeoman generator class for creating a webpack +plugin project. It adds some starter plugin code +and runs `webpack-defaults`. +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + +
    +
  • Generator
  • +
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/docs/Tooltip%20object%20that%20consits%20of%20tooltips%20for%20various%20of%0Afeaturesmodule_.html b/docs/Tooltip%20object%20that%20consits%20of%20tooltips%20for%20various%20of%0Afeaturesmodule_.html new file mode 100644 index 00000000000..522594d804f --- /dev/null +++ b/docs/Tooltip%20object%20that%20consits%20of%20tooltips%20for%20various%20of%0Afeaturesmodule_.html @@ -0,0 +1,130 @@ + + + + + JSDoc: Module: Tooltip object that consits of tooltips for various of +features + + + + + + + + + + +
+ +

Module: Tooltip object that consits of tooltips for various of +features

+ + + + + + +
+ +
+ +
+ +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/docs/commands_add.js.html b/docs/commands_add.js.html new file mode 100644 index 00000000000..5d6c2438b4b --- /dev/null +++ b/docs/commands_add.js.html @@ -0,0 +1,67 @@ + + + + + JSDoc: Source: commands/add.js + + + + + + + + + + +
+ +

Source: commands/add.js

+ + + + + + +
+
+
"use strict";
+
+const defaultGenerator = require("../generators/add-generator");
+const modifyHelper = require("../utils/modify-config-helper");
+
+/**
+ * Is called and returns a scaffolding instance, adding properties
+ *
+ * @returns {Function} modifyHelper - A helper function that uses the action
+ * 	we're given on a generator
+ *
+ */
+
+module.exports = function add() {
+	return modifyHelper("add", defaultGenerator);
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/commands_init.js.html b/docs/commands_init.js.html new file mode 100644 index 00000000000..77dde9835ee --- /dev/null +++ b/docs/commands_init.js.html @@ -0,0 +1,72 @@ + + + + + JSDoc: Source: commands/init.js + + + + + + + + + + +
+ +

Source: commands/init.js

+ + + + + + +
+
+
"use strict";
+
+const npmPackagesExists = require("../utils/npm-packages-exists");
+const creator = require("../init/index").creator;
+
+/**
+ *
+ * First function to be called after running the init flag. This is a check,
+ * if we are running the init command with no arguments or if we got dependencies
+ *
+ * @param {Object} pkg - packages included when running the init command
+ * @returns {Function} creator/npmPackagesExists - returns an installation of the package,
+ * followed up with a yeoman instance of that if there's packages. If not, it creates a defaultGenerator
+ */
+
+module.exports = function initializeInquirer(pkg) {
+	if (pkg.length === 0) {
+		return creator();
+	}
+	return npmPackagesExists(pkg);
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/commands_migrate.js.html b/docs/commands_migrate.js.html new file mode 100644 index 00000000000..12a8f26dbff --- /dev/null +++ b/docs/commands_migrate.js.html @@ -0,0 +1,168 @@ + + + + + JSDoc: Source: commands/migrate.js + + + + + + + + + + +
+ +

Source: commands/migrate.js

+ + + + + + +
+
+
"use strict";
+
+const fs = require("fs");
+const chalk = require("chalk");
+const diff = require("diff");
+const inquirer = require("inquirer");
+const PLazy = require("p-lazy");
+const Listr = require("listr");
+
+const runPrettier = require("../utils/run-prettier");
+
+/**
+*
+* Runs migration on a given configuration using AST's and promises
+* to sequentially transform a configuration file.
+*
+* @param {String} currentConfigPath - Location of the configuration to be migrated
+* @param {String} outputConfigPath - Location to where the configuration should be written
+* @param {Object} options - Any additional options regarding code style of the written configuration
+
+* @returns {Promise} Runs the migration using a promise that will throw any errors during each transform
+* or output if the user decides to abort the migration
+*/
+
+module.exports = function migrate(
+	currentConfigPath,
+	outputConfigPath,
+	options
+) {
+	const recastOptions = Object.assign(
+		{
+			quote: "single"
+		},
+		options
+	);
+	const tasks = new Listr([
+		{
+			title: "Reading webpack config",
+			task: ctx =>
+				new PLazy((resolve, reject) => {
+					fs.readFile(currentConfigPath, "utf8", (err, content) => {
+						if (err) {
+							reject(err);
+						}
+						try {
+							const jscodeshift = require("jscodeshift");
+							ctx.source = content;
+							ctx.ast = jscodeshift(content);
+							resolve();
+						} catch (err) {
+							reject("Error generating AST", err);
+						}
+					});
+				})
+		},
+		{
+			title: "Migrating config from v1 to v2",
+			task: ctx => {
+				const transformations = require("../migrate").transformations;
+				return new Listr(
+					Object.keys(transformations).map(key => {
+						const transform = transformations[key];
+						return {
+							title: key,
+							task: () => transform(ctx.ast, ctx.source)
+						};
+					})
+				);
+			}
+		}
+	]);
+
+	tasks
+		.run()
+		.then(ctx => {
+			const result = ctx.ast.toSource(recastOptions);
+			const diffOutput = diff.diffLines(ctx.source, result);
+			diffOutput.forEach(diffLine => {
+				if (diffLine.added) {
+					process.stdout.write(chalk.green(`+ ${diffLine.value}`));
+				} else if (diffLine.removed) {
+					process.stdout.write(chalk.red(`- ${diffLine.value}`));
+				}
+			});
+			inquirer
+				.prompt([
+					{
+						type: "confirm",
+						name: "confirmMigration",
+						message: "Are you sure these changes are fine?",
+						default: "Y"
+					}
+				])
+				.then(answers => {
+					if (answers["confirmMigration"]) {
+						runPrettier(outputConfigPath, result, err => {
+							if (err) {
+								throw err;
+							} else {
+								console.log(
+									chalk.green(
+										`\n ✔︎ New webpack v2 config file is at ${outputConfigPath}`
+									)
+								);
+							}
+						});
+					} else {
+						console.log(chalk.red("✖ Migration aborted"));
+					}
+				});
+		})
+		.catch(err => {
+			console.log(chalk.red("✖ ︎Migration aborted due to some errors"));
+			console.error(err);
+			process.exitCode = 1;
+		});
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/commands_remove.js.html b/docs/commands_remove.js.html new file mode 100644 index 00000000000..425ed0023db --- /dev/null +++ b/docs/commands_remove.js.html @@ -0,0 +1,67 @@ + + + + + JSDoc: Source: commands/remove.js + + + + + + + + + + +
+ +

Source: commands/remove.js

+ + + + + + +
+
+
"use strict";
+
+const defaultGenerator = require("../generators/remove-generator");
+const modifyHelper = require("../utils/modify-config-helper");
+
+/**
+ * Is called and returns a scaffolding instance, removing properties
+ *
+ * @returns {Function} modifyHelper - A helper function that uses the action
+ * 	we're given on a generator
+ *
+ */
+
+module.exports = function() {
+	return modifyHelper("remove", defaultGenerator);
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/commands_update.js.html b/docs/commands_update.js.html new file mode 100644 index 00000000000..a5f38e7cc39 --- /dev/null +++ b/docs/commands_update.js.html @@ -0,0 +1,67 @@ + + + + + JSDoc: Source: commands/update.js + + + + + + + + + + +
+ +

Source: commands/update.js

+ + + + + + +
+
+
"use strict";
+
+const defaultGenerator = require("../generators/update-generator");
+const modifyHelper = require("../utils/modify-config-helper");
+
+/**
+ * Is called and returns a scaffolding instance, updating properties
+ *
+ * @returns {Function} modifyHelper - A helper function that uses the action
+ * 	we're given on a generator
+ *
+ */
+
+module.exports = function() {
+	return modifyHelper("update", defaultGenerator);
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/fonts/OpenSans-Bold-webfont.eot b/docs/fonts/OpenSans-Bold-webfont.eot new file mode 100644 index 00000000000..5d20d916338 Binary files /dev/null and b/docs/fonts/OpenSans-Bold-webfont.eot differ diff --git a/docs/fonts/OpenSans-Bold-webfont.svg b/docs/fonts/OpenSans-Bold-webfont.svg new file mode 100644 index 00000000000..3ed7be4bc5b --- /dev/null +++ b/docs/fonts/OpenSans-Bold-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/fonts/OpenSans-Bold-webfont.woff b/docs/fonts/OpenSans-Bold-webfont.woff new file mode 100644 index 00000000000..1205787b0ed Binary files /dev/null and b/docs/fonts/OpenSans-Bold-webfont.woff differ diff --git a/docs/fonts/OpenSans-BoldItalic-webfont.eot b/docs/fonts/OpenSans-BoldItalic-webfont.eot new file mode 100644 index 00000000000..1f639a15ff3 Binary files /dev/null and b/docs/fonts/OpenSans-BoldItalic-webfont.eot differ diff --git a/docs/fonts/OpenSans-BoldItalic-webfont.svg b/docs/fonts/OpenSans-BoldItalic-webfont.svg new file mode 100644 index 00000000000..6a2607b9daf --- /dev/null +++ b/docs/fonts/OpenSans-BoldItalic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/fonts/OpenSans-BoldItalic-webfont.woff b/docs/fonts/OpenSans-BoldItalic-webfont.woff new file mode 100644 index 00000000000..ed760c0628b Binary files /dev/null and b/docs/fonts/OpenSans-BoldItalic-webfont.woff differ diff --git a/docs/fonts/OpenSans-Italic-webfont.eot b/docs/fonts/OpenSans-Italic-webfont.eot new file mode 100644 index 00000000000..0c8a0ae06ed Binary files /dev/null and b/docs/fonts/OpenSans-Italic-webfont.eot differ diff --git a/docs/fonts/OpenSans-Italic-webfont.svg b/docs/fonts/OpenSans-Italic-webfont.svg new file mode 100644 index 00000000000..e1075dcc246 --- /dev/null +++ b/docs/fonts/OpenSans-Italic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/fonts/OpenSans-Italic-webfont.woff b/docs/fonts/OpenSans-Italic-webfont.woff new file mode 100644 index 00000000000..ff652e64356 Binary files /dev/null and b/docs/fonts/OpenSans-Italic-webfont.woff differ diff --git a/docs/fonts/OpenSans-Light-webfont.eot b/docs/fonts/OpenSans-Light-webfont.eot new file mode 100644 index 00000000000..14868406aa7 Binary files /dev/null and b/docs/fonts/OpenSans-Light-webfont.eot differ diff --git a/docs/fonts/OpenSans-Light-webfont.svg b/docs/fonts/OpenSans-Light-webfont.svg new file mode 100644 index 00000000000..11a472ca8a5 --- /dev/null +++ b/docs/fonts/OpenSans-Light-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/fonts/OpenSans-Light-webfont.woff b/docs/fonts/OpenSans-Light-webfont.woff new file mode 100644 index 00000000000..e786074813a Binary files /dev/null and b/docs/fonts/OpenSans-Light-webfont.woff differ diff --git a/docs/fonts/OpenSans-LightItalic-webfont.eot b/docs/fonts/OpenSans-LightItalic-webfont.eot new file mode 100644 index 00000000000..8f445929ffb Binary files /dev/null and b/docs/fonts/OpenSans-LightItalic-webfont.eot differ diff --git a/docs/fonts/OpenSans-LightItalic-webfont.svg b/docs/fonts/OpenSans-LightItalic-webfont.svg new file mode 100644 index 00000000000..431d7e35463 --- /dev/null +++ b/docs/fonts/OpenSans-LightItalic-webfont.svg @@ -0,0 +1,1835 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/fonts/OpenSans-LightItalic-webfont.woff b/docs/fonts/OpenSans-LightItalic-webfont.woff new file mode 100644 index 00000000000..43e8b9e6cc0 Binary files /dev/null and b/docs/fonts/OpenSans-LightItalic-webfont.woff differ diff --git a/docs/fonts/OpenSans-Regular-webfont.eot b/docs/fonts/OpenSans-Regular-webfont.eot new file mode 100644 index 00000000000..6bbc3cf58cb Binary files /dev/null and b/docs/fonts/OpenSans-Regular-webfont.eot differ diff --git a/docs/fonts/OpenSans-Regular-webfont.svg b/docs/fonts/OpenSans-Regular-webfont.svg new file mode 100644 index 00000000000..25a3952340f --- /dev/null +++ b/docs/fonts/OpenSans-Regular-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/fonts/OpenSans-Regular-webfont.woff b/docs/fonts/OpenSans-Regular-webfont.woff new file mode 100644 index 00000000000..e231183dce4 Binary files /dev/null and b/docs/fonts/OpenSans-Regular-webfont.woff differ diff --git a/docs/generate-loader_index.js.html b/docs/generate-loader_index.js.html new file mode 100644 index 00000000000..2b2255e1444 --- /dev/null +++ b/docs/generate-loader_index.js.html @@ -0,0 +1,68 @@ + + + + + JSDoc: Source: generate-loader/index.js + + + + + + + + + + +
+ +

Source: generate-loader/index.js

+ + + + + + +
+
+
var yeoman = require("yeoman-environment");
+var LoaderGenerator = require("../generators/loader-generator").LoaderGenerator;
+
+/**
+ * Runs a yeoman generator to create a new webpack loader project
+ * @returns {void}
+ */
+function loaderCreator() {
+	var env = yeoman.createEnv();
+	var generatorName = "webpack-loader-generator";
+
+	env.registerStub(LoaderGenerator, generatorName);
+
+	env.run(generatorName);
+}
+
+module.exports = loaderCreator;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generate-plugin_index.js.html b/docs/generate-plugin_index.js.html new file mode 100644 index 00000000000..6a775468784 --- /dev/null +++ b/docs/generate-plugin_index.js.html @@ -0,0 +1,68 @@ + + + + + JSDoc: Source: generate-plugin/index.js + + + + + + + + + + +
+ +

Source: generate-plugin/index.js

+ + + + + + +
+
+
var yeoman = require("yeoman-environment");
+var PluginGenerator = require("../generators/plugin-generator").PluginGenerator;
+
+/**
+ * Runs a yeoman generator to create a new webpack plugin project
+ * @returns {void}
+ */
+function pluginCreator() {
+	var env = yeoman.createEnv();
+	var generatorName = "webpack-plugin-generator";
+
+	env.registerStub(PluginGenerator, generatorName);
+
+	env.run(generatorName);
+}
+
+module.exports = pluginCreator;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_add-generator.js.html b/docs/generators_add-generator.js.html new file mode 100644 index 00000000000..59c09392d93 --- /dev/null +++ b/docs/generators_add-generator.js.html @@ -0,0 +1,408 @@ + + + + + JSDoc: Source: generators/add-generator.js + + + + + + + + + + +
+ +

Source: generators/add-generator.js

+ + + + + + +
+
+
const Generator = require("yeoman-generator");
+const glob = require("glob-all");
+const List = require("webpack-addons").List;
+const Input = require("webpack-addons").Input;
+
+const webpackSchema = require("webpack/schemas/WebpackOptions");
+const webpackDevServerSchema = require("webpack-dev-server/lib/optionsSchema.json");
+const PROP_TYPES = require("../utils/prop-types");
+
+const getPackageManager = require("../utils/package-manager").getPackageManager;
+const npmExists = require("../utils/npm-exists");
+
+/**
+ *
+ * Replaces the string with a substring at the given index
+ * https://gist.github.com/efenacigiray/9367920
+ *
+ * @param {String} string - 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(string, index, replace) {
+	return string.substring(0, index) + replace + string.substring(index + 1);
+}
+
+/**
+ *
+ * Checks if the given array has a given property
+ *
+ * @param {Array} arr - array to check
+ * @param {String} prop - property to check existence of
+ *
+ * @returns {Boolean} hasProp - Boolean indicating if the property
+ * is present
+ */
+const traverseAndGetProperties = (arr, prop) => {
+	let hasProp = false;
+	arr.forEach(p => {
+		if (p[prop]) {
+			hasProp = true;
+		}
+	});
+	return hasProp;
+};
+
+/**
+ *
+ * Generator for adding properties
+ * @class AddGenerator
+ * @extends Generator
+ * @returns {Void} After execution, transforms are triggered
+ *
+ */
+
+module.exports = class AddGenerator extends Generator {
+	constructor(args, opts) {
+		super(args, opts);
+		this.dependencies = [];
+		this.configuration = {
+			config: {
+				webpackOptions: {},
+				topScope: ["const webpack = require('webpack')"]
+			}
+		};
+	}
+
+	prompting() {
+		let done = this.async();
+		let action;
+		let manualOrListInput = action =>
+			Input("actionAnswer", `what do you want to add to ${action}?`);
+		// first index indicates if it has a deep prop, 2nd indicates what kind of
+		let isDeepProp = [false, false];
+
+		this.prompt([
+			List(
+				"actionType",
+				"What property do you want to add to?",
+				Array.from(PROP_TYPES.keys())
+			)
+		])
+			.then(actionTypeAnswer => {
+				// Set initial prop, like devtool
+				this.configuration.config.webpackOptions[
+					actionTypeAnswer.actionType
+				] = null;
+				// update the action variable, we're using it later
+				action = actionTypeAnswer.actionType;
+			})
+			.then(() => {
+				const webpackSchemaProp = webpackSchema.definitions[action];
+				/*
+				 * https://github.com/webpack/webpack/blob/next/schemas/WebpackOptions.json
+				 * Find the properties directly in the properties prop, or the anyOf prop
+				 */
+				let defOrPropDescription = webpackSchemaProp
+					? webpackSchemaProp.properties
+					: webpackSchema.properties[action].properties
+						? webpackSchema.properties[action].properties
+						: webpackSchema.properties[action].anyOf
+							? webpackSchema.properties[action].anyOf.filter(
+								p => p.properties || p.enum
+							)
+							: null;
+				if (Array.isArray(defOrPropDescription)) {
+					// Todo: Generalize these to go through the array, then merge enum with props if needed
+					const hasPropertiesProp = traverseAndGetProperties(
+						defOrPropDescription,
+						"properties"
+					);
+					const hasEnumProp = traverseAndGetProperties(
+						defOrPropDescription,
+						"enum"
+					);
+					/* as we know he schema only has two arrays that might hold our values,
+					 * check them for either having arr.enum or arr.properties
+					*/
+					if (hasPropertiesProp) {
+						defOrPropDescription =
+							defOrPropDescription[0].properties ||
+							defOrPropDescription[1].properties;
+						if (!defOrPropDescription) {
+							defOrPropDescription = defOrPropDescription[0].enum;
+						}
+						// TODO: manually implement stats and devtools like sourcemaps
+					} else if (hasEnumProp) {
+						const originalPropDesc = defOrPropDescription[0].enum;
+						// Array -> Object -> Merge objects into one for compat in manualOrListInput
+						defOrPropDescription = Object.keys(defOrPropDescription[0].enum)
+							.map(p => {
+								return Object.assign(
+									{},
+									{
+										[originalPropDesc[p]]: "noop"
+									}
+								);
+							})
+							.reduce((result, currentObject) => {
+								for (let key in currentObject) {
+									if (currentObject.hasOwnProperty(key)) {
+										result[key] = currentObject[key];
+									}
+								}
+								return result;
+							}, {});
+					}
+				}
+				// WDS has its own schema, so we gonna need to check that too
+				const webpackDevserverSchemaProp =
+					action === "devServer" ? webpackDevServerSchema : null;
+				// Watch has a boolean arg, but we need to append to it manually
+				if (action === "watch") {
+					defOrPropDescription = {
+						true: {},
+						false: {}
+					};
+				}
+				if (action === "mode") {
+					defOrPropDescription = {
+						development: {},
+						production: {}
+					};
+				}
+				// If we've got a schema prop or devServer Schema Prop
+				if (defOrPropDescription || webpackDevserverSchemaProp) {
+					// Check for properties in definitions[action] or properties[action]
+					if (defOrPropDescription) {
+						if (action !== "devtool") {
+							// Add the option of adding an own variable if the user wants
+							defOrPropDescription = Object.assign(defOrPropDescription, {
+								other: {}
+							});
+						} else {
+							// The schema doesn't have the source maps we can prompt, so add those
+							defOrPropDescription = Object.assign(defOrPropDescription, {
+								eval: {},
+								"cheap-eval-source-map": {},
+								"cheap-module-eval-source-map": {},
+								"eval-source-map": {},
+								"cheap-source-map": {},
+								"cheap-module-source-map": {},
+								"inline-cheap-source-map": {},
+								"inline-cheap-module-source-map": {},
+								"source-map": {},
+								"inline-source-map": {},
+								"hidden-source-map": {},
+								"nosources-source-map": {}
+							});
+						}
+						manualOrListInput = List(
+							"actionAnswer",
+							`what do you want to add to ${action}?`,
+							Object.keys(defOrPropDescription)
+						);
+						// We know we're gonna append some deep prop like module.rule
+						isDeepProp[0] = true;
+					} else if (webpackDevserverSchemaProp) {
+						// Append the custom property option
+						webpackDevserverSchemaProp.properties = Object.assign(
+							webpackDevserverSchemaProp.properties,
+							{
+								other: {}
+							}
+						);
+						manualOrListInput = List(
+							"actionAnswer",
+							`what do you want to add to ${action}?`,
+							Object.keys(webpackDevserverSchemaProp.properties)
+						);
+						// We know we are in a devServer.prop scenario
+						isDeepProp[0] = true;
+					} else {
+						// manual input if non-existent
+						manualOrListInput = manualOrListInput(action);
+					}
+				} else {
+					manualOrListInput = manualOrListInput(action);
+				}
+				return this.prompt([manualOrListInput]);
+			})
+			.then(answerToAction => {
+				/*
+				 * Plugins got their own logic,
+				 * find the names of each natively plugin and check if it matches
+				*/
+				if (action === "plugins") {
+					const pluginExist = glob
+						.sync([
+							"node_modules/webpack/lib/*Plugin.js",
+							"node_modules/webpack/lib/**/*Plugin.js"
+						])
+						.map(p =>
+							p
+								.split("/")
+								.pop()
+								.replace(".js", "")
+						)
+						.find(
+							p => p.toLowerCase().indexOf(answerToAction.actionAnswer) >= 0
+						);
+					if (pluginExist) {
+						this.configuration.config.item = pluginExist;
+						this.configuration.config.webpackOptions[
+							action
+						] = `new webpack.${pluginExist}`;
+						done();
+					} else {
+						// If its not in webpack, check npm
+						npmExists(answerToAction.actionAnswer).then(p => {
+							if (p) {
+								this.dependencies.push(answerToAction.actionAnswer);
+								const normalizePluginName = answerToAction.actionAnswer.replace(
+									"-webpack-plugin",
+									"Plugin"
+								);
+								const pluginName = replaceAt(
+									normalizePluginName,
+									0,
+									normalizePluginName.charAt(0).toUpperCase()
+								);
+								this.configuration.config.topScope.push(
+									`const ${pluginName} = require("${
+										answerToAction.actionAnswer
+									}")`
+								);
+								this.configuration.config.webpackOptions[
+									action
+								] = `new ${pluginName}`;
+								this.configuration.config.item = answerToAction.actionAnswer;
+								done();
+
+								this.runInstall(getPackageManager(), this.dependencies, {
+									"save-dev": true
+								});
+							} else {
+								console.error(
+									answerToAction.actionAnswer,
+									"doesn't exist on NPM or is built in webpack, please check for any misspellings."
+								);
+								process.exit(0);
+							}
+						});
+					}
+				} else {
+					// If we're in the scenario with a deep-property
+					if (isDeepProp[0]) {
+						isDeepProp[1] = answerToAction.actionAnswer;
+						if (
+							isDeepProp[1] !== "other" &&
+							(action === "devtool" || action === "watch" || action === "mode")
+						) {
+							this.configuration.config.item = action;
+							this.configuration.config.webpackOptions[action] = `'${
+								answerToAction.actionAnswer
+							}'`;
+							done();
+							return;
+						}
+						// Either we are adding directly at the property, else we're in a prop.theOne scenario
+						const actionMessage =
+							isDeepProp[1] === "other"
+								? `what do you want the key on ${action} to be? (press enter if you want it directly as a value on the property)`
+								: `what do you want the value of ${isDeepProp[1]} to be?`;
+
+						this.prompt([Input("deepProp", actionMessage)]).then(
+							deepPropAns => {
+								// The other option needs to be validated of either being empty or not
+								if (isDeepProp[1] === "other") {
+									let othersDeepPropKey = deepPropAns.deepProp
+										? `what do you want the value of ${
+											deepPropAns.deepProp
+										} to be?`
+										: `what do you want to be the value of ${action} to be?`;
+									// Push the answer to the array we have created, so we can use it later
+									isDeepProp.push(deepPropAns.deepProp);
+									this.prompt([Input("deepProp", othersDeepPropKey)]).then(
+										deepPropAns => {
+											// Check length, if it has none, add the prop directly on the given action
+											if (isDeepProp[2].length === 0) {
+												this.configuration.config.item = action;
+												this.configuration.config.webpackOptions[action] =
+													deepPropAns.deepProp;
+											} else {
+												// If not, we're adding to something like devServer.myProp
+												this.configuration.config.item =
+													action + "." + isDeepProp[2];
+												this.configuration.config.webpackOptions[action] = {
+													[isDeepProp[2]]: deepPropAns.deepProp
+												};
+											}
+											done();
+										}
+									);
+								} else {
+									// We got the schema prop, we've correctly prompted it, and can add it directly
+									this.configuration.config.item = action + "." + isDeepProp[1];
+									this.configuration.config.webpackOptions[action] = {
+										[isDeepProp[1]]: `'${deepPropAns.deepProp}'`
+									};
+									done();
+								}
+							}
+						);
+					} else {
+						// We're asking for input-only
+						this.configuration.config.item = action;
+						this.configuration.config.webpackOptions[action] =
+							answerToAction.actionAnswer;
+						done();
+					}
+				}
+			});
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_init-generator.js.html b/docs/generators_init-generator.js.html new file mode 100644 index 00000000000..91f774312d9 --- /dev/null +++ b/docs/generators_init-generator.js.html @@ -0,0 +1,464 @@ + + + + + JSDoc: Source: generators/init-generator.js + + + + + + + + + + +
+ +

Source: generators/init-generator.js

+ + + + + + +
+
+
"use strict";
+
+const Generator = require("yeoman-generator");
+const chalk = require("chalk");
+const logSymbols = require("log-symbols");
+
+const createCommonsChunkPlugin = require("webpack-addons")
+	.createCommonsChunkPlugin;
+
+const Input = require("webpack-addons").Input;
+const Confirm = require("webpack-addons").Confirm;
+const List = require("webpack-addons").List;
+
+const getPackageManager = require("../utils/package-manager").getPackageManager;
+
+const entryQuestions = require("./utils/entry");
+const getBabelPlugin = require("./utils/module");
+const getDefaultPlugins = require("./utils/plugins");
+const tooltip = require("./utils/tooltip");
+
+/**
+ *
+ * Generator for initializing a webpack config
+ *
+ * @class InitGenerator
+ * @extends Generator
+ * @returns {Void} After execution, transforms are triggered
+ *
+ */
+module.exports = class InitGenerator extends Generator {
+	constructor(args, opts) {
+		super(args, opts);
+		this.isProd = false;
+		this.dependencies = ["webpack", "uglifyjs-webpack-plugin"];
+		this.configuration = {
+			config: {
+				webpackOptions: {},
+				topScope: []
+			}
+		};
+	}
+	prompting() {
+		let done = this.async();
+		let self = this;
+		let oneOrMoreEntries;
+		let regExpForStyles;
+		let ExtractUseProps;
+		let outputPath = "dist";
+		process.stdout.write(
+			"\n" +
+				logSymbols.info +
+				chalk.blue(" INFO ") +
+				"For more information and a detailed description of each question, have a look at " +
+				chalk.bold.green(
+					"https://github.com/webpack/webpack-cli/blob/master/INIT.md"
+				) +
+				"\n"
+		);
+		process.stdout.write(
+			logSymbols.info +
+				chalk.blue(" INFO ") +
+				"Alternatively, run `webpack(-cli) --help` for usage info." +
+				"\n\n"
+		);
+		this.configuration.config.webpackOptions.module = {
+			rules: []
+		};
+		this.configuration.config.webpackOptions.plugins = getDefaultPlugins();
+		this.configuration.config.topScope.push(
+			"const webpack = require('webpack')",
+			"const path = require('path')",
+			tooltip.uglify(),
+			"const UglifyJSPlugin = require('uglifyjs-webpack-plugin');",
+			"\n"
+		);
+
+		this.prompt([
+			Confirm("entryType", "Will your application have multiple bundles?")
+		])
+			.then(entryTypeAnswer => {
+				// Ask different questions for entry points
+				return entryQuestions(self, entryTypeAnswer);
+			})
+			.then(entryOptions => {
+				this.configuration.config.webpackOptions.entry = entryOptions;
+				oneOrMoreEntries = Object.keys(entryOptions);
+
+				return this.prompt([
+					Input(
+						"outputType",
+						"Which folder will your generated bundles be in? [default: dist]:"
+					)
+				]);
+			})
+			.then(outputTypeAnswer => {
+				if (!this.configuration.config.webpackOptions.entry.length) {
+					this.configuration.config.topScope.push(tooltip.commonsChunk());
+					this.configuration.config.webpackOptions.output = {
+						filename: "'[name].[chunkhash].js'",
+						chunkFilename: "'[name].[chunkhash].js'"
+					};
+				} else {
+					this.configuration.config.webpackOptions.output = {
+						filename: "'[name].bundle.js'"
+					};
+				}
+				if (outputTypeAnswer["outputType"].length) {
+					outputPath = outputTypeAnswer["outputType"];
+				}
+				this.configuration.config.webpackOptions.output.path = `path.resolve(__dirname, '${outputPath}')`;
+			})
+			.then(() => {
+				return this.prompt([
+					Confirm("prodConfirm", "Are you going to use this in production?")
+				]);
+			})
+			.then(prodAnswer => {
+				if (prodAnswer["prodConfirm"] === true) {
+					this.isProd = true;
+				} else {
+					this.isProd = false;
+				}
+			})
+			.then(() => {
+				return this.prompt([
+					Confirm("babelConfirm", "Will you be using ES2015?")
+				]);
+			})
+			.then(ans => {
+				if (ans["babelConfirm"] === true) {
+					this.configuration.config.webpackOptions.module.rules.push(
+						getBabelPlugin()
+					);
+					this.dependencies.push(
+						"babel-loader",
+						"babel-core",
+						"babel-preset-env"
+					);
+				}
+			})
+			.then(() => {
+				return this.prompt([
+					List("stylingType", "Will you use one of the below CSS solutions?", [
+						"SASS",
+						"LESS",
+						"CSS",
+						"PostCSS",
+						"No"
+					])
+				]);
+			})
+			.then(stylingAnswer => {
+				if (!this.isProd) {
+					ExtractUseProps = [];
+				}
+				switch (stylingAnswer["stylingType"]) {
+					case "SASS":
+						this.dependencies.push(
+							"sass-loader",
+							"node-sass",
+							"style-loader",
+							"css-loader"
+						);
+						regExpForStyles = new RegExp(/\.(scss|css)$/);
+						if (this.isProd) {
+							ExtractUseProps = `
+								use: [{
+									loader: "css-loader",
+									options: {
+										sourceMap: true
+									}
+								}, {
+									loader: "sass-loader",
+									options: {
+										sourceMap: true
+									}
+								}],
+								fallback: "style-loader"
+							`;
+						} else {
+							ExtractUseProps.push(
+								{
+									loader: "'style-loader'"
+								},
+								{
+									loader: "'css-loader'"
+								},
+								{
+									loader: "'sass-loader'"
+								}
+							);
+						}
+						break;
+					case "LESS":
+						regExpForStyles = new RegExp(/\.(less|css)$/);
+						this.dependencies.push(
+							"less-loader",
+							"less",
+							"style-loader",
+							"css-loader"
+						);
+						if (this.isProd) {
+							ExtractUseProps = `
+								use: [{
+									loader: "css-loader",
+									options: {
+										sourceMap: true
+									}
+								}, {
+									loader: "less-loader",
+									options: {
+										sourceMap: true
+									}
+								}],
+								fallback: "style-loader"
+							`;
+						} else {
+							ExtractUseProps.push(
+								{
+									loader: "'css-loader'",
+									options: {
+										sourceMap: true
+									}
+								},
+								{
+									loader: "'less-loader'",
+									options: {
+										sourceMap: true
+									}
+								}
+							);
+						}
+						break;
+					case "PostCSS":
+						this.configuration.config.topScope.push(
+							tooltip.postcss(),
+							"const autoprefixer = require('autoprefixer');",
+							"const precss = require('precss');",
+							"\n"
+						);
+						this.dependencies.push(
+							"style-loader",
+							"css-loader",
+							"postcss-loader",
+							"precss",
+							"autoprefixer"
+						);
+						regExpForStyles = new RegExp(/\.css$/);
+						if (this.isProd) {
+							ExtractUseProps = `
+								use: [{
+									loader: "style-loader"
+								},{
+									loader: "css-loader",
+									options: {
+										sourceMap: true,
+										importLoaders: 1
+									}
+								}, {
+									loader: "postcss-loader",
+									options: {
+										plugins: function () {
+											return [
+												precss,
+												autoprefixer
+											];
+										}
+									}
+								}],
+								fallback: "style-loader"
+							`;
+						} else {
+							ExtractUseProps.push(
+								{
+									loader: "'style-loader'"
+								},
+								{
+									loader: "'css-loader'",
+									options: {
+										sourceMap: true,
+										importLoaders: 1
+									}
+								},
+								{
+									loader: "'postcss-loader'",
+									options: {
+										plugins: `function () {
+											return [
+												precss,
+												autoprefixer
+											];
+										}`
+									}
+								}
+							);
+						}
+						break;
+					case "CSS":
+						this.dependencies.push("style-loader", "css-loader");
+						regExpForStyles = new RegExp(/\.css$/);
+						if (this.isProd) {
+							ExtractUseProps = `
+								use: [{
+									loader: "css-loader",
+									options: {
+										sourceMap: true
+									}
+								}],
+								fallback: "style-loader"
+							`;
+						} else {
+							ExtractUseProps.push(
+								{
+									loader: "'style-loader'",
+									options: {
+										sourceMap: true
+									}
+								},
+								{
+									loader: "'css-loader'"
+								}
+							);
+						}
+						break;
+					default:
+						regExpForStyles = null;
+				}
+			})
+			.then(() => {
+				// Ask if the user wants to use extractPlugin
+				return this.prompt([
+					Input(
+						"extractPlugin",
+						"If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)"
+					)
+				]);
+			})
+			.then(extractAnswer => {
+				const cssBundleName = extractAnswer.extractPlugin;
+				if (regExpForStyles) {
+					if (this.isProd) {
+						this.configuration.config.topScope.push(tooltip.cssPlugin());
+						this.dependencies.push("extract-text-webpack-plugin");
+
+						if (cssBundleName.length !== 0) {
+							this.configuration.config.webpackOptions.plugins.push(
+								`new ExtractTextPlugin('${cssBundleName}.[contentHash].css')`
+							);
+						} else {
+							this.configuration.config.webpackOptions.plugins.push(
+								"new ExtractTextPlugin('style.css')"
+							);
+						}
+
+						const moduleRulesObj = {
+							test: regExpForStyles,
+							use: `ExtractTextPlugin.extract({ ${ExtractUseProps} })`
+						};
+
+						this.configuration.config.webpackOptions.module.rules.push(
+							moduleRulesObj
+						);
+						this.configuration.config.topScope.push(
+							"const ExtractTextPlugin = require('extract-text-webpack-plugin');",
+							"\n"
+						);
+					} else {
+						const moduleRulesObj = {
+							test: regExpForStyles,
+							use: ExtractUseProps
+						};
+
+						this.configuration.config.webpackOptions.module.rules.push(
+							moduleRulesObj
+						);
+					}
+				}
+			})
+			.then(() => {
+				if (this.configuration.config.webpackOptions.entry.length === 0) {
+					oneOrMoreEntries.forEach(prop => {
+						this.configuration.config.webpackOptions.plugins.push(
+							createCommonsChunkPlugin(prop)
+						);
+					});
+				}
+				done();
+			});
+	}
+	installPlugins() {
+		let asyncNamePrompt = this.async();
+		let defaultName = this.isProd ? "prod" : "config";
+		this.prompt([
+			Input(
+				"nameType",
+				`Name your 'webpack.[name].js?' [default: '${defaultName}']:`
+			)
+		])
+			.then(nameAnswer => {
+				if (nameAnswer["nameType"].length) {
+					this.configuration.config.configName = nameAnswer["nameType"];
+				} else {
+					this.configuration.config.configName = defaultName;
+				}
+			})
+			.then(() => {
+				asyncNamePrompt();
+				this.runInstall(getPackageManager(), this.dependencies, {
+					"save-dev": true
+				});
+			});
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_loader-generator.js.html b/docs/generators_loader-generator.js.html new file mode 100644 index 00000000000..b09cad1629b --- /dev/null +++ b/docs/generators_loader-generator.js.html @@ -0,0 +1,109 @@ + + + + + JSDoc: Source: generators/loader-generator.js + + + + + + + + + + +
+ +

Source: generators/loader-generator.js

+ + + + + + +
+
+
var path = require("path");
+var _ = require("lodash");
+var webpackGenerator = require("./webpack-generator");
+
+/**
+ * Formats a string into webpack loader format
+ * (eg: 'style-loader', 'raw-loader')
+ *
+ * @param {string} name A loader name to be formatted
+ * @returns {string} The formatted string
+ */
+function makeLoaderName(name) {
+	name = _.kebabCase(name);
+	if (!/loader$/.test(name)) {
+		name += "-loader";
+	}
+	return name;
+}
+
+/**
+ * A yeoman generator class for creating a webpack
+ * loader project. It adds some starter loader code
+ * and runs `webpack-defaults`.
+ *
+ * @class LoaderGenerator
+ * @extends {Generator}
+ */
+var LoaderGenerator = webpackGenerator(
+	[
+		{
+			type: "input",
+			name: "name",
+			message: "Loader name",
+			default: "my-loader",
+			filter: makeLoaderName,
+			validate: str => str.length > 0
+		}
+	],
+	path.join(__dirname, "templates"),
+	[
+		"src/cjs.js.tpl",
+		"test/test-utils.js.tpl",
+		"test/unit.test.js.tpl",
+		"test/functional.test.js.tpl",
+		"test/fixtures/simple-file.js.tpl",
+		"examples/simple/webpack.config.js.tpl",
+		"examples/simple/src/index.js.tpl",
+		"examples/simple/src/lazy-module.js.tpl",
+		"examples/simple/src/static-esm-module.js.tpl"
+	],
+	["src/_index.js.tpl"],
+	gen => ({ name: gen.props.name })
+);
+
+module.exports = {
+	makeLoaderName,
+	LoaderGenerator
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_plugin-generator.js.html b/docs/generators_plugin-generator.js.html new file mode 100644 index 00000000000..c93d9e020d1 --- /dev/null +++ b/docs/generators_plugin-generator.js.html @@ -0,0 +1,90 @@ + + + + + JSDoc: Source: generators/plugin-generator.js + + + + + + + + + + +
+ +

Source: generators/plugin-generator.js

+ + + + + + +
+
+
var path = require("path");
+var _ = require("lodash");
+var webpackGenerator = require("./webpack-generator");
+
+/**
+ * A yeoman generator class for creating a webpack
+ * plugin project. It adds some starter plugin code
+ * and runs `webpack-defaults`.
+ *
+ * @class PluginGenerator
+ * @extends {Generator}
+ */
+var PluginGenerator = webpackGenerator(
+	[
+		{
+			type: "input",
+			name: "name",
+			message: "Plugin name",
+			default: "my-webpack-plugin",
+			filter: _.kebabCase,
+			validate: str => str.length > 0
+		}
+	],
+	path.join(__dirname, "templates"),
+	[
+		"src/cjs.js.tpl",
+		"test/test-utils.js.tpl",
+		"test/functional.test.js.tpl",
+		"examples/simple/src/index.js.tpl",
+		"examples/simple/src/lazy-module.js.tpl",
+		"examples/simple/src/static-esm-module.js.tpl"
+	],
+	["src/_index.js.tpl", "examples/simple/_webpack.config.js.tpl"],
+	gen => ({ name: _.upperFirst(_.camelCase(gen.props.name)) })
+);
+
+module.exports = {
+	PluginGenerator
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_utils_entry.js.html b/docs/generators_utils_entry.js.html new file mode 100644 index 00000000000..e30eb82b102 --- /dev/null +++ b/docs/generators_utils_entry.js.html @@ -0,0 +1,141 @@ + + + + + JSDoc: Source: generators/utils/entry.js + + + + + + + + + + +
+ +

Source: generators/utils/entry.js

+ + + + + + +
+
+
"use strict";
+
+const InputValidate = require("webpack-addons").InputValidate;
+const validate = require("./validate");
+
+/**
+ *
+ * Prompts for entry points, either if it has multiple or one entry
+ *
+ * @param {Object} self - A variable holding the instance of the prompting
+ * @param {Object} answer - Previous answer from asking if the user wants single or multiple entries
+ * @returns {Object} An Object that holds the answers given by the user, later used to scaffold
+ */
+
+module.exports = (self, answer) => {
+	let entryIdentifiers;
+	let result;
+	if (answer["entryType"] === true) {
+		result = self
+			.prompt([
+				InputValidate(
+					"multipleEntries",
+					"Type the names you want for your modules (entry files), separated by comma [example: 'app,vendor']",
+					validate
+				)
+			])
+			.then(multipleEntriesAnswer => {
+				let webpackEntryPoint = {};
+				entryIdentifiers = multipleEntriesAnswer["multipleEntries"].split(",");
+				function forEachPromise(obj, fn) {
+					return obj.reduce(function(promise, prop) {
+						const trimmedProp = prop.trim();
+						return promise.then(n => {
+							if (n) {
+								Object.keys(n).forEach(val => {
+									if (
+										n[val].charAt(0) !== "(" &&
+										n[val].charAt(0) !== "[" &&
+										n[val].indexOf("function") < 0 &&
+										n[val].indexOf("path") < 0 &&
+										n[val].indexOf("process") < 0
+									) {
+										n[val] = `"${n[val]}.js"`;
+									}
+									webpackEntryPoint[val] = n[val];
+								});
+							} else {
+								n = {};
+							}
+							return fn(trimmedProp);
+						});
+					}, Promise.resolve());
+				}
+				return forEachPromise(entryIdentifiers, entryProp =>
+					self.prompt([
+						InputValidate(
+							`${entryProp}`,
+							`What is the location of "${entryProp}"? [example: "./src/${entryProp}"]`,
+							validate
+						)
+					])
+				).then(propAns => {
+					Object.keys(propAns).forEach(val => {
+						if (
+							propAns[val].charAt(0) !== "(" &&
+							propAns[val].charAt(0) !== "[" &&
+							propAns[val].indexOf("function") < 0 &&
+							propAns[val].indexOf("path") < 0 &&
+							propAns[val].indexOf("process") < 0
+						) {
+							propAns[val] = `"${propAns[val]}.js"`;
+						}
+						webpackEntryPoint[val] = propAns[val];
+					});
+					return webpackEntryPoint;
+				});
+			});
+	} else {
+		result = self
+			.prompt([
+				InputValidate(
+					"singularEntry",
+					"Which module will be the first to enter the application? [example: './src/index']",
+					validate
+				)
+			])
+			.then(singularAnswer => `"${singularAnswer["singularEntry"]}"`);
+	}
+	return result;
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_utils_module.js.html b/docs/generators_utils_module.js.html new file mode 100644 index 00000000000..702b7edd5a5 --- /dev/null +++ b/docs/generators_utils_module.js.html @@ -0,0 +1,69 @@ + + + + + JSDoc: Source: generators/utils/module.js + + + + + + + + + + +
+ +

Source: generators/utils/module.js

+ + + + + + +
+
+
"use strict";
+
+/**
+ *
+ * Returns an module.rule object that has the babel loader if invoked
+ *
+ * @returns {Function} A callable function that adds the babel-loader with env preset
+ */
+module.exports = () => {
+	return {
+		test: new RegExp(/\.js$/),
+		exclude: "/node_modules/",
+		loader: "'babel-loader'",
+		options: {
+			presets: ["'env'"]
+		}
+	};
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_utils_plugins.js.html b/docs/generators_utils_plugins.js.html new file mode 100644 index 00000000000..b19864bcc31 --- /dev/null +++ b/docs/generators_utils_plugins.js.html @@ -0,0 +1,64 @@ + + + + + JSDoc: Source: generators/utils/plugins.js + + + + + + + + + + +
+ +

Source: generators/utils/plugins.js

+ + + + + + +
+
+
"use strict";
+
+/**
+ *
+ * Callable function with the initial plugins
+ *
+ * @returns {Function} An function that returns an array
+ * that consists of the uglify plugin
+ */
+
+module.exports = () => {
+	return ["new UglifyJSPlugin()"];
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_utils_tooltip.js.html b/docs/generators_utils_tooltip.js.html new file mode 100644 index 00000000000..c46e6e8a095 --- /dev/null +++ b/docs/generators_utils_tooltip.js.html @@ -0,0 +1,107 @@ + + + + + JSDoc: Source: generators/utils/tooltip.js + + + + + + + + + + +
+ +

Source: generators/utils/tooltip.js

+ + + + + + +
+
+
"use strict";
+/**
+ *
+ * Tooltip object that consits of tooltips for various of
+ * features
+ *
+ * @returns {Object} An Object that consists of tooltip methods to be invoked
+ */
+
+module.exports = {
+	uglify: () => {
+		return `/*
+ * We've enabled UglifyJSPlugin for you! This minifies your app
+ * in order to load faster and run less javascript.
+ *
+ * https://github.com/webpack-contrib/uglifyjs-webpack-plugin
+ *
+ */`;
+	},
+	commonsChunk: () => {
+		return `/*
+ * We've enabled commonsChunkPlugin for you. This allows your app to
+ * load faster and it splits the modules you provided as entries across
+ * different bundles!
+ *
+ * https://webpack.js.org/plugins/commons-chunk-plugin/
+ *
+ */`;
+	},
+	cssPlugin: () => {
+		return `/*
+ * We've enabled ExtractTextPlugin for you. This allows your app to
+ * use css modules that will be moved into a separate CSS file instead of inside
+ * one of your module entries!
+ *
+ * https://github.com/webpack-contrib/extract-text-webpack-plugin
+ *
+ */`;
+	},
+	postcss: () => {
+		return `/*
+ * We've enabled Postcss, autoprefixer and precss for you. This allows your app
+ * to lint  CSS, support variables and mixins, transpile future CSS syntax,
+ * inline images, and more!
+ *
+ * To enable SASS or LESS, add the respective loaders to module.rules
+ *
+ * https://github.com/postcss/postcss
+ *
+ * https://github.com/postcss/autoprefixer
+ *
+ * https://github.com/jonathantneal/precss
+ *
+ */`;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_utils_validate.js.html b/docs/generators_utils_validate.js.html new file mode 100644 index 00000000000..b4772baf6c4 --- /dev/null +++ b/docs/generators_utils_validate.js.html @@ -0,0 +1,68 @@ + + + + + JSDoc: Source: generators/utils/validate.js + + + + + + + + + + +
+ +

Source: generators/utils/validate.js

+ + + + + + +
+
+
"use strict";
+
+/**
+ *
+ * Validates an input to check if an input is provided
+ *
+ * @param {String} value - The input string to validate
+ * @returns {String | Boolean } Returns truthy if its long enough
+ * Or a string if the user hasn't written anything
+ */
+module.exports = value => {
+	const pass = value.length;
+	if (pass) {
+		return true;
+	}
+	return "Please specify an answer!";
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/generators_webpack-generator.js.html b/docs/generators_webpack-generator.js.html new file mode 100644 index 00000000000..169b6e60440 --- /dev/null +++ b/docs/generators_webpack-generator.js.html @@ -0,0 +1,128 @@ + + + + + JSDoc: Source: generators/webpack-generator.js + + + + + + + + + + +
+ +

Source: generators/webpack-generator.js

+ + + + + + +
+
+
var path = require("path");
+var mkdirp = require("mkdirp");
+var Generator = require("yeoman-generator");
+var copyUtils = require("../utils/copy-utils");
+
+/**
+ * Creates a Yeoman Generator that generates a project conforming
+ * to webpack-defaults.
+ *
+ * @param {any[]} prompts An array of Yeoman prompt objects
+ *
+ * @param {string} templateDir Absolute path to template directory
+ *
+ * @param {string[]} copyFiles An array of file paths (relative to `./templates`)
+ * of files to be copied to the generated project. File paths should be of the
+ * form `path/to/file.js.tpl`.
+ *
+ * @param {string[]} copyTemplateFiles An array of file paths (relative to
+ * `./templates`) of files to be copied to the generated project. Template
+ * file paths should be of the form `path/to/_file.js.tpl`.
+ *
+ * @param {Function} templateFn A function that is passed a generator instance and
+ * returns an object containing data to be supplied to the template files.
+ *
+ * @returns {Generator} A class extending Generator
+ */
+function webpackGenerator(
+	prompts,
+	templateDir,
+	copyFiles,
+	copyTemplateFiles,
+	templateFn
+) {
+	//eslint-disable-next-line
+	return class extends Generator {
+		prompting() {
+			return this.prompt(prompts).then(props => {
+				this.props = props;
+			});
+		}
+
+		default() {
+			var currentDirName = path.basename(this.destinationPath());
+			if (currentDirName !== this.props.name) {
+				this.log(`
+				Your project must be inside a folder named ${this.props.name}
+				I will create this folder for you.
+				`);
+				mkdirp(this.props.name);
+				var pathToProjectDir = this.destinationPath(this.props.name);
+				this.destinationRoot(pathToProjectDir);
+			}
+		}
+
+		writing() {
+			this.copy = copyUtils.generatorCopy(this, templateDir);
+			this.copyTpl = copyUtils.generatorCopyTpl(
+				this,
+				templateDir,
+				templateFn(this)
+			);
+
+			copyFiles.forEach(this.copy);
+			copyTemplateFiles.forEach(this.copyTpl);
+		}
+
+		install() {
+			this.npmInstall(["webpack-defaults", "bluebird"], {
+				"save-dev": true
+			}).then(() => {
+				this.spawnCommand("npm", ["run", "webpack-defaults"]);
+			});
+		}
+	};
+}
+
+module.exports = webpackGenerator;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/global.html b/docs/global.html new file mode 100644 index 00000000000..97f54bbf5af --- /dev/null +++ b/docs/global.html @@ -0,0 +1,7032 @@ + + + + + JSDoc: Global + + + + + + + + + + +
+ +

Global

+ + + + + + +
+ +
+ +

+ + +
+ +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + +

Members

+ + + +

(constant) transformsObject

+ + + + +
+ Runs the transformations from an object we get from yeoman +
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +

Methods

+ + + + + + + +

checkIfExistsAndAddValue(j, node, key, value) → {Void}

+ + + + + + +
+ If a prop exists, it overrides it, else it creates a new one +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
node + + +Node + + + + objectexpression to check
key + + +String + + + + Key of the property
value + + +String + + + + computed value of the property
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Void + + +
+
+ + + + + + + + + + + + + +

createArrayWithChildren(j, key, subProps, shouldDropKeys) → {Array}

+ + + + + + +
+ Creates an array and iterates on an object with properties +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
key + + +String + + + + object name
subProps + + +String + + + + computed value of the property
shouldDropKeys + + +Boolean + + + + bool to ask to use obj.keys or not
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ arr - An array with the object properties +
+ + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + + + + + + + + + + +

createEmptyArrayProperty(j, key) → {Array}

+ + + + + + +
+ Creates an empty array +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
key + + +String + + + + array name
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ arr - An empty array +
+ + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + + + + + + + + + + +

createEmptyCallableFunctionWithArguments(j, name) → {Node}

+ + + + + + +
+ Creates a function call with arguments +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
name + + +String + + + + Name for the given function
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ - Returns the node for the created +function +
+ + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

createExternalRegExp(j, prop) → {Node}

+ + + + + + +
+ Finds a regexp property with an already parsed AST from the user +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
prop + + +String + + + + property to find the value at
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ - A literal node with the found regexp +
+ + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

createIdentifierOrLiteral(j, val) → {Node}

+ + + + + + +
+ Creates an appropriate identifier or literal property +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
val + + +String +| + +Boolean +| + +Number + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

createLiteral(j, val) → {Node}

+ + + + + + +
+ Creates an appropriate literal property +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
val + + +String +| + +Boolean +| + +Number + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

createObjectWithSuppliedProperty(j, key, prop) → {Node}

+ + + + + + +
+ Creates an object with an supplied property as parameter +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
key + + +String + + + + object name
prop + + +Node + + + + property to be added
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ - An property with the supplied property +
+ + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

createOrUpdatePluginByName(j, rootNodePath, pluginName, options) → {Void}

+ + + + + + +
+ Findes or creates a node for a given plugin name string with options object +If plugin decalaration already exist, options are merged. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
rootNodePath + + +Node + + + + `plugins: []` NodePath where plugin should be added. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths
pluginName + + +String + + + + ex. `webpack.LoaderOptionsPlugin`
options + + +Object + + + + plugin options
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Void + + +
+
+ + + + + + + + + + + + + +

createProperty(j, key, value) → {Node}

+ + + + + + +
+ Creates an Object's property with a given key and value +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
key + + +String +| + +Number + + + + Property key
value + + +String +| + +Number +| + +Boolean + + + + Property value
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

creator(options) → {function}

+ + + + + + +
+ Runs yeoman and runs the transformations based on the object +built up from an author/user +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
options + + +String + + + + An path to the given generator
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ runTransform - Run transformations based on the finished +yeoman instance +
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + + + + + + +

defineTest(dirName, transformName, testFilePrefixopt, transformObject, action) → {Void}

+ + + + + + +
+ Handles some boilerplate around defining a simple jest/Jasmine test for a +jscodeshift transform. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
dirName + + +String + + + + + + + + + + contains the name of the directory the test is located in. This + should normally be passed via __dirname.
transformName + + +String + + + + + + + + + + contains the filename of the transform being tested, + excluding the .js extension.
testFilePrefix + + +String + + + + + + <optional>
+ + + + + +
Optionally contains the name of the file with the test + data. If not specified, it defaults to the same value as `transformName`. + This will be suffixed with ".input.js" for the input file and ".output.js" + for the expected output. For example, if set to "foo", we will read the + "foo.input.js" file, pass this to the transform, and expect its output to + be equal to the contents of "foo.output.js".
transformObject + + +any + + + + + + + + + + Object to be transformed with the transformations
action + + +String + + + + + + + + + + init, update or remove, decides how to format the AST
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ Jest makes sure to execute the globally defined functions +
+ + + +
+
+ Type +
+
+ +Void + + +
+
+ + + + + + + + + + + + + +

findPluginsByName(j, node, pluginNamesArray) → {Node}

+ + + + + + +
+ Find paths that match `new name.space.PluginName()` for a +given array of plugin names +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
node + + +Node + + + + Node to start search from
pluginNamesArray + + +Array.<String> + + + + Array of plugin names like `webpack.LoaderOptionsPlugin`
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ Node that has the pluginName +
+ + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

findRootNodesByName(j, node, propName) → {Node}

+ + + + + + +
+ Finds the path to the `name: []` node +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
node + + +Node + + + + Node to start search from
propName + + +String + + + + property to search for
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ found node and +
+ + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

findVariableToPlugin(j, rootNode, pluginPackageName) → {String}

+ + + + + + +
+ Finds the variable to which a third party plugin is assigned to +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
rootNode + + +Node + + + + `plugins: []` Root Node. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths
pluginPackageName + + +String + + + + ex. `extract-text-plugin`
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ variable name - ex. 'var s = require(s) gives "s"` +
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + + + + +

generatorCopy(generator, templateDir) → {function}

+ + + + + + +
+ Takes in a file path in the `./templates` directory. Copies that +file to the destination, with the `.tpl` extension stripped. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
generator + + +Generator + + + + A Yeoman Generator instance
templateDir + + +string + + + + Absolute path to template directory
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ A curried function that takes a file path and copies it +
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + + + + + + +

generatorCopyTpl(generator, templateDir, templateData) → {function}

+ + + + + + +
+ Takes in a file path in the `./templates` directory. Copies that +file to the destination, with the `.tpl` extension and `_` prefix +stripped. Passes `this.props` to the template. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
generator + + +Generator + + + + A Yeoman Generator instance
templateDir + + +string + + + + Absolute path to template directory
templateData + + +any + + + + An object containing the data passed to +the template files.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ A curried function that takes a file path and copies it +
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + + + + + + +

getPackageManager() → {String}

+ + + + + + +
+ Returns the name of package manager to use, +preferring yarn over npm if available +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ - The package manager name +
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + + + + +

getRequire(j, constName, packagePath) → {Node}

+ + + + + + +
+ Returns constructed require symbol +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
constName + + +String + + + + Name of require
packagePath + + +String + + + + path of required package
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ - the created ast +
+ + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

isAssignment(j, p, cb, identifier, property) → {function}

+ + + + + + +
+ Checks if we are at the correct node and later invokes a callback +for the transforms to either use their own transform function or +use pushCreateProperty if the transform doesn't expect any properties +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
p + + +Node + + + + Node to push against
cb + + +function + + + + callback to be invoked
identifier + + +String + + + + key to use as property
property + + +Object + + + + WebpackOptions that later will be converted via +pushCreateProperty via WebpackOptions[identifier]
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ cb - Returns the callback and pushes a new node +
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + + + + + + +

isType(path, type) → {Boolean}

+ + + + + + +
+ Returns true if type is given type +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
path + + +Node + + + + pathNode
type + + +String + + + + node type
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + + + + +

loaderCreator() → {void}

+ + + + + + +
+ Runs a yeoman generator to create a new webpack loader project +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +void + + +
+
+ + + + + + + + + + + + + +

loopThroughObjects(j, p, obj) → {function|Node}

+ + + + + + +
+ Loops through an object and adds property to an object with no identifier +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
p + + +Node + + + + node to add value to
obj + + +Object + + + + Object to loop through
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ - Either pushes the node, or reruns until +nothing is left +
+ + + +
+
+ Type +
+
+ +function +| + +Node + + +
+
+ + + + + + + + + + + + + +

makeLoaderName(name) → {string}

+ + + + + + +
+ Formats a string into webpack loader format +(eg: 'style-loader', 'raw-loader') +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + A loader name to be formatted
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ The formatted string +
+ + + +
+
+ Type +
+
+ +string + + +
+
+ + + + + + + + + + + + + +

pluginCreator() → {void}

+ + + + + + +
+ Runs a yeoman generator to create a new webpack plugin project +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +void + + +
+
+ + + + + + + + + + + + + +

processPromise(child) → {Promise}

+ + + + + + +
+ Attaches a promise to the installation of the package +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
child + + +function + + + + The function to attach a promise to
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ promise - Returns a promise to the installation +
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + + + +

pushCreateProperty(j, p, key, val) → {Node}

+ + + + + + +
+ Creates a property and pushes the value to a node +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
p + + +Node + + + + Node to push against
key + + +String + + + + key used as identifier
val + + +String + + + + property value
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ - Returns node the pushed property +
+ + + +
+
+ Type +
+
+ +Node + + +
+
+ + + + + + + + + + + + + +

pushObjectKeys(j, p, webpackProperties, name) → {Node|function}

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
j + + +any + + + + — jscodeshift API
p + + +Node + + + + path to push
webpackProperties + + +Object + + + + The object to loop over
name + + +String + + + + Key that will be the identifier we find and add values to
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ Returns a function that will push a node if +subProperty is an array, else it will invoke a function that will push a single node +
+ + + +
+
+ Type +
+
+ +Node +| + +function + + +
+
+ + + + + + + + + + + + + +

replaceAt(string, index, replace) → {String}

+ + + + + + +
+ Replaces the string with a substring at the given index +https://gist.github.com/efenacigiray/9367920 +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
string + + +String + + + + string to be modified
index + + +Number + + + + index to replace from
replace + + +String + + + + string to replace starting from index
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ string - The newly mutated string +
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + + + + +

runSingleTansform(dirName, transformName, testFilePrefixopt, initOptions, action) → {function}

+ + + + + + +
+ Utility function to run a jscodeshift script within a unit test. +This makes several assumptions about the environment. + +Notes: +- The test should be located in a subdirectory next to the transform itself. + Commonly tests are located in a directory called __tests__. + +- Test data should be located in a directory called __testfixtures__ + alongside the transform and __tests__ directory. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
dirName + + +String + + + + + + + + + + contains the name of the directory the test is located in. This + should normally be passed via __dirname.
transformName + + +String + + + + + + + + + + contains the filename of the transform being tested, + excluding the .js extension.
testFilePrefix + + +String + + + + + + <optional>
+ + + + + +
Optionally contains the name of the file with the test + data. If not specified, it defaults to the same value as `transformName`. + This will be suffixed with ".input.js" for the input file and ".output.js" + for the expected output. For example, if set to "foo", we will read the + "foo.input.js" file, pass this to the transform, and expect its output to + be equal to the contents of "foo.output.js".
initOptions + + +Object +| + +Boolean +| + +String + + + + + + + + + + TBD
action + + +String + + + + + + + + + + init, update or remove, decides how to format the AST
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ Function that fires of the transforms +
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + + + + + + +

spawnChild(pkg) → {function}

+ + + + + + +
+ Spawns a new process that installs the addon/dependency +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pkg + + +String + + + + The dependency to be installed
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ spawn - Installs the package +
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + + + + + + +

spawnNPM(pkg, isNew) → {function}

+ + + + + + +
+ Spawns a new process using npm +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pkg + + +String + + + + The dependency to be installed
isNew + + +Boolean + + + + indicates if it needs to be updated or installed
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ spawn - Installs the package +
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + + + + + + +

spawnYarn(pkg, isNew) → {function}

+ + + + + + +
+ Spawns a new process using yarn +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pkg + + +String + + + + The dependency to be installed
isNew + + +Boolean + + + + indicates if it needs to be updated or installed
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ spawn - Installs the package +
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + + + + + + +

traverseAndGetProperties(arr, prop) → {Boolean}

+ + + + + + +
+ Checks if the given array has a given property +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arr + + +Array + + + + array to check
prop + + +String + + + + property to check existence of
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ hasProp - Boolean indicating if the property +is present +
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + + + + +

webpackGenerator(prompts, templateDir, copyFiles, copyTemplateFiles, templateFn) → {Generator}

+ + + + + + +
+ Creates a Yeoman Generator that generates a project conforming +to webpack-defaults. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
prompts + + +Array.<any> + + + + An array of Yeoman prompt objects
templateDir + + +string + + + + Absolute path to template directory
copyFiles + + +Array.<string> + + + + An array of file paths (relative to `./templates`) +of files to be copied to the generated project. File paths should be of the +form `path/to/file.js.tpl`.
copyTemplateFiles + + +Array.<string> + + + + An array of file paths (relative to +`./templates`) of files to be copied to the generated project. Template +file paths should be of the form `path/to/_file.js.tpl`.
templateFn + + +function + + + + A function that is passed a generator instance and +returns an object containing data to be supplied to the template files.
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ A class extending Generator +
+ + + +
+
+ Type +
+
+ +Generator + + +
+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 00000000000..8a815a59fe6 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,65 @@ + + + + + JSDoc: Home + + + + + + + + + + +
+ +

Home

+ + + + + + + + +

+ + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/docs/index.js.html b/docs/index.js.html new file mode 100644 index 00000000000..27723fa5888 --- /dev/null +++ b/docs/index.js.html @@ -0,0 +1,105 @@ + + + + + JSDoc: Source: index.js + + + + + + + + + + +
+ +

Source: index.js

+ + + + + + +
+
+
"use strict";
+
+const path = require("path");
+
+/**
+ *
+ * First function to be called after running a flag. This is a check,
+ * to match the flag with the respective require.
+ *
+ * @param {String} command - which feature to use
+ * @param {Object} args - arguments from the CLI
+ * @returns {Function} invokes the module with the supplied command
+ *
+ */
+
+module.exports = function initialize(command, args) {
+	const popArgs = args.slice(2).pop();
+	switch (command) {
+		case "init": {
+			const initPkgs = args.slice(2).length === 1 ? [] : [popArgs];
+			//eslint-disable-next-line
+			return require("./commands/init.js")(initPkgs);
+		}
+		case "migrate": {
+			const filePaths = args.slice(2).length === 1 ? [] : [popArgs];
+			if (!filePaths.length) {
+				throw new Error("Please specify a path to your webpack config");
+			}
+			const inputConfigPath = path.resolve(process.cwd(), filePaths[0]);
+			//eslint-disable-next-line
+			return require("./commands/migrate.js")(inputConfigPath, inputConfigPath);
+		}
+		case "add": {
+			//eslint-disable-next-line
+			return require("./commands/add")();
+		}
+		case "remove": {
+			//eslint-disable-next-line
+			return require("./commands/remove")();
+		}
+		case "update": {
+			return require("./commands/update")();
+		}
+		case "generate-loader": {
+			return require("./generate-loader/index.js")();
+		}
+		case "generate-plugin": {
+			return require("./generate-plugin/index.js")();
+		}
+		default: {
+			throw new Error(`Unknown command ${command} found`);
+		}
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_index.js.html b/docs/init_index.js.html new file mode 100644 index 00000000000..7ffddabbce4 --- /dev/null +++ b/docs/init_index.js.html @@ -0,0 +1,116 @@ + + + + + JSDoc: Source: init/index.js + + + + + + + + + + +
+ +

Source: init/index.js

+ + + + + + +
+
+
"use strict";
+
+const yeoman = require("yeoman-environment");
+const Generator = require("yeoman-generator");
+const path = require("path");
+const defaultGenerator = require("../generators/init-generator");
+const runTransform = require("./transformations/index");
+
+/**
+ *
+ * Runs yeoman and runs the transformations based on the object
+ * built up from an author/user
+ *
+ * @param {String} options - An path to the given generator
+ * @returns {Function} runTransform - Run transformations based on the finished
+ * yeoman instance
+ */
+
+function creator(options) {
+	let env = yeoman.createEnv("webpack", null);
+	const generatorName = options
+		? replaceGeneratorName(path.basename(options[0]))
+		: "webpack-default-generator";
+	if (options) {
+		const WebpackGenerator = class extends Generator {
+			initializing() {
+				options.forEach(path => {
+					return this.composeWith(require.resolve(path));
+				});
+			}
+		};
+		env.registerStub(WebpackGenerator, generatorName);
+	} else {
+		env.registerStub(defaultGenerator, "webpack-default-generator");
+	}
+
+	env.run(generatorName).on("end", () => {
+		if (generatorName !== "webpack-default-generator") {
+			//HACK / FIXME
+			env = env.options.env;
+			return runTransform(env.configuration);
+		} else {
+			return runTransform(env.getArgument("configuration"));
+		}
+	});
+}
+
+/*
+* @function replaceGeneratorName
+*
+* Replaces the webpack-addons pattern with the end of the addons name merged
+* with 'generator'
+*
+* @param { String } name - name of the generator
+* @returns { String } name - replaced pattern of the name
+*/
+
+function replaceGeneratorName(name) {
+	return name.replace(/(webpack-addons)?([^:]+)(:.*)?/g, "generator$2");
+}
+
+module.exports = {
+	creator,
+	replaceGeneratorName
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_context_context.js.html b/docs/init_transformations_context_context.js.html new file mode 100644 index 00000000000..24609670950 --- /dev/null +++ b/docs/init_transformations_context_context.js.html @@ -0,0 +1,106 @@ + + + + + JSDoc: Source: init/transformations/context/context.js + + + + + + + + + + +
+ +

Source: init/transformations/context/context.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for context. Finds the context property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function contextTransform(j, ast, webpackProperties, action) {
+	if (webpackProperties) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"context",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const contextNode = utils.findRootNodesByName(j, ast, "context");
+			if (contextNode.size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p =>
+						utils.checkIfExistsAndAddValue(
+							j,
+							p,
+							"context",
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						)
+					);
+			} else {
+				return contextTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_devServer_devServer.js.html b/docs/init_transformations_devServer_devServer.js.html new file mode 100644 index 00000000000..8c9bb7dd829 --- /dev/null +++ b/docs/init_transformations_devServer_devServer.js.html @@ -0,0 +1,140 @@ + + + + + JSDoc: Source: init/transformations/devServer/devServer.js + + + + + + + + + + +
+ +

Source: init/transformations/devServer/devServer.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for devServer. Finds the devServer property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function devServerTransform(
+	j,
+	ast,
+	webpackProperties,
+	action
+) {
+	function createDevServerProperty(p) {
+		utils.pushCreateProperty(j, p, "devServer", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "devServer");
+	}
+	if (webpackProperties) {
+		if (action === "init" && typeof webpackProperties === "object") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createDevServerProperty));
+		} else if (action === "init" && webpackProperties.length) {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"devServer",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const devServerNode = utils.findRootNodesByName(j, ast, "devServer");
+			if (devServerNode.size() !== 0 && typeof webpackProperties === "object") {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"devServer"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (devServerNode.size() !== 0 && webpackProperties.length) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"devServer"
+					)
+					.forEach(p => {
+						j(p).replaceWith(
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						);
+					});
+			} else {
+				return devServerTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_devtool_devtool.js.html b/docs/init_transformations_devtool_devtool.js.html new file mode 100644 index 00000000000..8924948e631 --- /dev/null +++ b/docs/init_transformations_devtool_devtool.js.html @@ -0,0 +1,105 @@ + + + + + JSDoc: Source: init/transformations/devtool/devtool.js + + + + + + + + + + +
+ +

Source: init/transformations/devtool/devtool.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for devtool. Finds the devtool property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function devToolTransform(j, ast, webpackProperties, action) {
+	if (webpackProperties || typeof webpackProperties === "boolean") {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"devtool",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const devToolNode = utils.findRootNodesByName(j, ast, "devtool");
+			if (devToolNode.size() !== 0) {
+				return devToolNode.forEach(p => {
+					j(p).replaceWith(
+						j.property(
+							"init",
+							j.identifier("devtool"),
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						)
+					);
+				});
+			} else {
+				return devToolTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_entry_entry.js.html b/docs/init_transformations_entry_entry.js.html new file mode 100644 index 00000000000..1604b85a745 --- /dev/null +++ b/docs/init_transformations_entry_entry.js.html @@ -0,0 +1,136 @@ + + + + + JSDoc: Source: init/transformations/entry/entry.js + + + + + + + + + + +
+ +

Source: init/transformations/entry/entry.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for entry. Finds the entry property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function entryTransform(j, ast, webpackProperties, action) {
+	function createEntryProperty(p) {
+		if (typeof webpackProperties === "string") {
+			return utils.pushCreateProperty(j, p, "entry", webpackProperties);
+		}
+		if (Array.isArray(webpackProperties)) {
+			const externalArray = utils.createArrayWithChildren(
+				j,
+				"entry",
+				webpackProperties,
+				true
+			);
+			return p.value.properties.push(externalArray);
+		} else {
+			utils.pushCreateProperty(j, p, "entry", j.objectExpression([]));
+			return utils.pushObjectKeys(j, p, webpackProperties, "entry");
+		}
+	}
+	if (webpackProperties) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createEntryProperty));
+		} else if (action === "add") {
+			const entryNode = utils.findRootNodesByName(j, ast, "entry");
+			if (entryNode.size() !== 0 && typeof webpackProperties === "object") {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"entry"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (entryNode.size() !== 0 && webpackProperties.length) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"entry"
+					)
+					.forEach(p => {
+						j(p).replaceWith(
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						);
+					});
+			} else {
+				return entryTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_externals_externals.js.html b/docs/init_transformations_externals_externals.js.html new file mode 100644 index 00000000000..f5c684a7e38 --- /dev/null +++ b/docs/init_transformations_externals_externals.js.html @@ -0,0 +1,160 @@ + + + + + JSDoc: Source: init/transformations/externals/externals.js + + + + + + + + + + +
+ +

Source: init/transformations/externals/externals.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for externals. Finds the externals property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function externalsTransform(
+	j,
+	ast,
+	webpackProperties,
+	action
+) {
+	function createExternalProperty(p) {
+		if (
+			webpackProperties instanceof RegExp ||
+			typeof webpackProperties === "string"
+		) {
+			return utils.pushCreateProperty(j, p, "externals", webpackProperties);
+		}
+		if (Array.isArray(webpackProperties)) {
+			const externalArray = utils.createArrayWithChildren(
+				j,
+				"externals",
+				webpackProperties,
+				true
+			);
+			return p.value.properties.push(externalArray);
+		} else {
+			utils.pushCreateProperty(j, p, "externals", j.objectExpression([]));
+			return utils.pushObjectKeys(j, p, webpackProperties, "externals");
+		}
+	}
+	if (webpackProperties) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(
+					p =>
+						utils.safeTraverse(p, [
+							"parent",
+							"value",
+							"left",
+							"property",
+							"name"
+						]) === "exports"
+				)
+				.forEach(createExternalProperty);
+		} else if (action === "add") {
+			const externalNode = utils.findRootNodesByName(j, ast, "externals");
+			if (externalNode.size() !== 0 && typeof webpackProperties === "object") {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"externals"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							// need to check for every prop beneath, use the recursion util
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (
+				externalNode.size() !== 0 &&
+				Array.isArray(webpackProperties)
+			) {
+				// Todo
+			} else if (externalNode.size() !== 0 && webpackProperties.length) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"externals"
+					)
+					.forEach(p => {
+						j(p).replaceWith(
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						);
+					});
+			} else {
+				return externalsTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_index.js.html b/docs/init_transformations_index.js.html new file mode 100644 index 00000000000..06e79ac3def --- /dev/null +++ b/docs/init_transformations_index.js.html @@ -0,0 +1,199 @@ + + + + + JSDoc: Source: init/transformations/index.js + + + + + + + + + + +
+ +

Source: init/transformations/index.js

+ + + + + + +
+
+
"use strict";
+
+const path = require("path");
+const j = require("jscodeshift");
+const chalk = require("chalk");
+const pEachSeries = require("p-each-series");
+
+const runPrettier = require("../../utils/run-prettier");
+
+const entryTransform = require("./entry/entry");
+const outputTransform = require("./output/output");
+const contextTransform = require("./context/context");
+const resolveTransform = require("./resolve/resolve");
+const devtoolTransform = require("./devtool/devtool");
+const targetTransform = require("./target/target");
+const watchTransform = require("./watch/watch");
+const watchOptionsTransform = require("./watch/watchOptions");
+const externalsTransform = require("./externals/externals");
+const nodeTransform = require("./node/node");
+const performanceTransform = require("./performance/performance");
+const statsTransform = require("./stats/stats");
+const amdTransform = require("./other/amd");
+const bailTransform = require("./other/bail");
+const cacheTransform = require("./other/cache");
+const profileTransform = require("./other/profile");
+const mergeTransform = require("./other/merge");
+const parallelismTransform = require("./other/parallelism");
+const recordsInputPathTransform = require("./other/recordsInputPath");
+const recordsOutputPathTransform = require("./other/recordsOutputPath");
+const recordsPathTransform = require("./other/recordsPath");
+const moduleTransform = require("./module/module");
+const pluginsTransform = require("./plugins/plugins");
+const topScopeTransform = require("./top-scope/top-scope");
+const devServerTransform = require("./devServer/devServer");
+const modeTransform = require("./mode/mode");
+
+/**
+ *
+ * Runs the transformations from an object we get from yeoman
+ *
+ * @param {Object} webpackProperties - Configuration to transform
+ * @param {String} action - Action to be done on the given ast
+ * @returns {Promise} - A promise that writes each transform, runs prettier
+ * and writes the file
+ */
+
+const transformsObject = {
+	entryTransform,
+	outputTransform,
+	contextTransform,
+	resolveTransform,
+	devtoolTransform,
+	targetTransform,
+	watchTransform,
+	watchOptionsTransform,
+	externalsTransform,
+	nodeTransform,
+	performanceTransform,
+	statsTransform,
+	amdTransform,
+	bailTransform,
+	cacheTransform,
+	profileTransform,
+	moduleTransform,
+	pluginsTransform,
+	topScopeTransform,
+	mergeTransform,
+	devServerTransform,
+	modeTransform,
+	parallelismTransform,
+	recordsInputPathTransform,
+	recordsOutputPathTransform,
+	recordsPathTransform
+};
+
+module.exports = function runTransform(webpackProperties, action) {
+	// webpackOptions.name sent to nameTransform if match
+	const webpackConfig = action
+		? { config: webpackProperties.config }
+		: webpackProperties;
+	Object.keys(webpackConfig).forEach(scaffoldPiece => {
+		const config = webpackConfig[scaffoldPiece];
+		const transformations = Object.keys(transformsObject)
+			.map(k => {
+				const stringVal = k.substr(0, k.indexOf("Transform"));
+				if (config.webpackOptions) {
+					if (config.webpackOptions[stringVal]) {
+						return [transformsObject[k], config.webpackOptions[stringVal]];
+					} else {
+						return [transformsObject[k], config[stringVal]];
+					}
+				} else {
+					return [transformsObject[k]];
+				}
+			})
+			.filter(e => e[1]);
+
+		const ast = j(
+			action ? webpackProperties.configFile : "module.exports = {}"
+		);
+		const transformAction = action || null;
+
+		return pEachSeries(transformations, f => {
+			if (!f[1]) {
+				return f[0](j, ast, transformAction);
+			} else {
+				return f[0](j, ast, f[1], transformAction);
+			}
+		})
+			.then(() => {
+				let configurationName;
+				if (!config.configName) {
+					configurationName = "webpack.config.js";
+				} else {
+					configurationName = "webpack." + config.configName + ".js";
+				}
+
+				const outputPath = action
+					? webpackProperties.configPath
+					: path.join(process.cwd(), configurationName);
+				const source = ast.toSource({
+					quote: "single"
+				});
+
+				runPrettier(outputPath, source);
+			})
+			.catch(err => {
+				console.error(err.message ? err.message : err);
+			});
+	});
+	if (action) {
+		process.stdout.write(
+			"\n" +
+				chalk.green(
+					`Congratulations! ${
+						webpackProperties.config.item
+					} has been ${action}ed!\n`
+				)
+		);
+	} else {
+		process.stdout.write(
+			"\n" +
+				chalk.green(
+					"Congratulations! Your new webpack configuration file has been created!\n"
+				)
+		);
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_mode_mode.js.html b/docs/init_transformations_mode_mode.js.html new file mode 100644 index 00000000000..422a6b5b707 --- /dev/null +++ b/docs/init_transformations_mode_mode.js.html @@ -0,0 +1,106 @@ + + + + + JSDoc: Source: init/transformations/mode/mode.js + + + + + + + + + + +
+ +

Source: init/transformations/mode/mode.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for mode. Finds the mode property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function modeTransform(j, ast, webpackProperties, action) {
+	if (webpackProperties) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"mode",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const modeNode = utils.findRootNodesByName(j, ast, "mode");
+			if (modeNode.size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p =>
+						utils.checkIfExistsAndAddValue(
+							j,
+							p,
+							"mode",
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						)
+					);
+			} else {
+				return modeTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_module_module.js.html b/docs/init_transformations_module_module.js.html new file mode 100644 index 00000000000..ad22d4c0d6d --- /dev/null +++ b/docs/init_transformations_module_module.js.html @@ -0,0 +1,84 @@ + + + + + JSDoc: Source: init/transformations/module/module.js + + + + + + + + + + +
+ +

Source: init/transformations/module/module.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for module. Finds the module property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function(j, ast, webpackProperties, action) {
+	function createModuleProperties(p) {
+		utils.pushCreateProperty(j, p, "module", j.objectExpression([]));
+		return utils.safeTraverse(p, ["key", "name"] === "module");
+	}
+	function createRules(p) {
+		return utils.pushObjectKeys(j, p, webpackProperties, "module");
+	}
+	if (webpackProperties && action === "init") {
+		return ast
+			.find(j.ObjectExpression)
+			.filter(p => utils.isAssignment(null, p, createModuleProperties))
+			.forEach(p => createRules(p));
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_node_node.js.html b/docs/init_transformations_node_node.js.html new file mode 100644 index 00000000000..7a3178065a6 --- /dev/null +++ b/docs/init_transformations_node_node.js.html @@ -0,0 +1,95 @@ + + + + + JSDoc: Source: init/transformations/node/node.js + + + + + + + + + + +
+ +

Source: init/transformations/node/node.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for node. Finds the node property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function nodeTransform(j, ast, webpackProperties, action) {
+	function createNodeProperty(p) {
+		utils.pushCreateProperty(j, p, "node", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "node");
+	}
+	if (webpackProperties) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createNodeProperty));
+		} else if (action === "add") {
+			const nodeNode = utils.findRootNodesByName(j, ast, "node");
+			if (nodeNode.size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p => utils.pushObjectKeys(j, p, webpackProperties, "node"));
+			} else {
+				return nodeTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_amd.js.html b/docs/init_transformations_other_amd.js.html new file mode 100644 index 00000000000..9f1083809a1 --- /dev/null +++ b/docs/init_transformations_other_amd.js.html @@ -0,0 +1,135 @@ + + + + + JSDoc: Source: init/transformations/other/amd.js + + + + + + + + + + +
+ +

Source: init/transformations/other/amd.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for amd. Finds the amd property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function amdTransform(j, ast, webpackProperties, action) {
+	function createAmdProperty(p) {
+		utils.pushCreateProperty(j, p, "amd", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "amd");
+	}
+	if (webpackProperties) {
+		if (action === "init" && typeof webpackProperties === "object") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createAmdProperty));
+		} else if (action === "init" && webpackProperties.length) {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"amd",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const amdNode = utils.findRootNodesByName(j, ast, "amd");
+			if (amdNode.size() !== 0 && typeof webpackProperties === "object") {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"amd"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (amdNode.size() !== 0 && webpackProperties.length) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"amd"
+					)
+					.forEach(p => {
+						j(p).replaceWith(
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						);
+					});
+			} else {
+				return amdTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_bail.js.html b/docs/init_transformations_other_bail.js.html new file mode 100644 index 00000000000..db8f5e94792 --- /dev/null +++ b/docs/init_transformations_other_bail.js.html @@ -0,0 +1,106 @@ + + + + + JSDoc: Source: init/transformations/other/bail.js + + + + + + + + + + +
+ +

Source: init/transformations/other/bail.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for bail. Finds the bail property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function bailTransform(j, ast, webpackProperties, action) {
+	if (webpackProperties || typeof webpackProperties === "boolean") {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"bail",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const bailNode = utils.findRootNodesByName(j, ast, "bail");
+			if (bailNode.size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p =>
+						utils.checkIfExistsAndAddValue(
+							j,
+							p,
+							"bail",
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						)
+					);
+			} else {
+				return bailTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_cache.js.html b/docs/init_transformations_other_cache.js.html new file mode 100644 index 00000000000..4f781c1cb73 --- /dev/null +++ b/docs/init_transformations_other_cache.js.html @@ -0,0 +1,139 @@ + + + + + JSDoc: Source: init/transformations/other/cache.js + + + + + + + + + + +
+ +

Source: init/transformations/other/cache.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for cache. Finds the cache property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function cacheTransform(j, ast, webpackProperties, action) {
+	function createCacheProperty(p) {
+		utils.pushCreateProperty(j, p, "cache", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "cache");
+	}
+	if (webpackProperties || typeof webpackProperties === "boolean") {
+		if (action === "init" && typeof webpackProperties === "object") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createCacheProperty));
+		} else if (
+			action === "init" &&
+			(webpackProperties.length || typeof webpackProperties === "boolean")
+		) {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"cache",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const cacheNode = utils.findRootNodesByName(j, ast, "cache");
+			if (cacheNode.size() !== 0 && typeof webpackProperties === "object") {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"cache"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (
+				cacheNode.size() !== 0 &&
+				(typeof webpackProperties === "boolean" || webpackProperties.length > 0)
+			) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p =>
+						utils.checkIfExistsAndAddValue(
+							j,
+							p,
+							"cache",
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						)
+					);
+			} else {
+				return cacheTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_merge.js.html b/docs/init_transformations_other_merge.js.html new file mode 100644 index 00000000000..008fa164f54 --- /dev/null +++ b/docs/init_transformations_other_merge.js.html @@ -0,0 +1,98 @@ + + + + + JSDoc: Source: init/transformations/other/merge.js + + + + + + + + + + +
+ +

Source: init/transformations/other/merge.js

+ + + + + + +
+
+
"use strict";
+
+/**
+ *
+ * Transform for merge. Finds the merge property from yeoman and creates a way
+ * for users to allow webpack-merge in their scaffold
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function(j, ast, webpackProperties, action) {
+	function createMergeProperty(p) {
+		// FIXME Use j.callExp()
+		let exportsDecl = p.value.body.map(n => {
+			if (n.expression) {
+				return n.expression.right;
+			}
+		});
+		const bodyLength = exportsDecl.length;
+		let newVal = {};
+		newVal.type = "ExpressionStatement";
+		newVal.expression = {
+			type: "AssignmentExpression",
+			operator: "=",
+			left: {
+				type: "MemberExpression",
+				computed: false,
+				object: j.identifier("module"),
+				property: j.identifier("exports")
+			},
+			right: j.callExpression(j.identifier("merge"), [
+				j.identifier(webpackProperties),
+				exportsDecl.pop()
+			])
+		};
+		p.value.body[bodyLength - 1] = newVal;
+	}
+	if (webpackProperties) {
+		return ast.find(j.Program).filter(p => createMergeProperty(p));
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_parallelism.js.html b/docs/init_transformations_other_parallelism.js.html new file mode 100644 index 00000000000..6afe788118f --- /dev/null +++ b/docs/init_transformations_other_parallelism.js.html @@ -0,0 +1,111 @@ + + + + + JSDoc: Source: init/transformations/other/parallelism.js + + + + + + + + + + +
+ +

Source: init/transformations/other/parallelism.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for parallelism. Finds the parallelism property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function parallelismTransform(
+	j,
+	ast,
+	webpackProperties,
+	action
+) {
+	if (webpackProperties) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"parallelism",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const parallelismNode = utils.findRootNodesByName(j, ast, "parallelism");
+			if (parallelismNode.size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p =>
+						utils.checkIfExistsAndAddValue(
+							j,
+							p,
+							"parallelism",
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						)
+					);
+			} else {
+				return parallelismTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_profile.js.html b/docs/init_transformations_other_profile.js.html new file mode 100644 index 00000000000..d6dc94c248b --- /dev/null +++ b/docs/init_transformations_other_profile.js.html @@ -0,0 +1,139 @@ + + + + + JSDoc: Source: init/transformations/other/profile.js + + + + + + + + + + +
+ +

Source: init/transformations/other/profile.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for profile. Finds the profile property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function profileTransform(j, ast, webpackProperties, action) {
+	function createProfileProperty(p) {
+		utils.pushCreateProperty(j, p, "profile", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "profile");
+	}
+	if (webpackProperties || typeof webpackProperties === "boolean") {
+		if (action === "init" && typeof webpackProperties === "object") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createProfileProperty));
+		} else if (
+			action === "init" &&
+			(webpackProperties.length || typeof webpackProperties === "boolean")
+		) {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"profile",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const profileNode = utils.findRootNodesByName(j, ast, "profile");
+			if (profileNode.size() !== 0 && typeof webpackProperties === "object") {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"profile"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (
+				profileNode.size() !== 0 &&
+				(typeof webpackProperties === "boolean" || webpackProperties.length > 0)
+			) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p =>
+						utils.checkIfExistsAndAddValue(
+							j,
+							p,
+							"profile",
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						)
+					);
+			} else {
+				return profileTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_recordsInputPath.js.html b/docs/init_transformations_other_recordsInputPath.js.html new file mode 100644 index 00000000000..b00eef23ce3 --- /dev/null +++ b/docs/init_transformations_other_recordsInputPath.js.html @@ -0,0 +1,151 @@ + + + + + JSDoc: Source: init/transformations/other/recordsInputPath.js + + + + + + + + + + +
+ +

Source: init/transformations/other/recordsInputPath.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for recordsInputPath. Finds the recordsInputPath property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function recordsInputPathTransform(
+	j,
+	ast,
+	webpackProperties,
+	action
+) {
+	function createRecordsInputPathProperty(p) {
+		utils.pushCreateProperty(j, p, "recordsInputPath", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "recordsInputPath");
+	}
+	if (webpackProperties) {
+		if (action === "init" && typeof webpackProperties === "object") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(null, p, createRecordsInputPathProperty)
+				);
+		} else if (action === "init" && webpackProperties.length) {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"recordsInputPath",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const recordsInputPathNode = utils.findRootNodesByName(
+				j,
+				ast,
+				"recordsInputPath"
+			);
+			if (
+				recordsInputPathNode.size() !== 0 &&
+				typeof webpackProperties === "object"
+			) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"recordsInputPath"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (
+				recordsInputPathNode.size() !== 0 &&
+				webpackProperties.length > 0
+			) {
+				return utils
+					.findRootNodesByName(j, ast, "recordsInputPath")
+					.forEach(p => {
+						j(p).replaceWith(
+							j.property(
+								"init",
+								utils.createIdentifierOrLiteral(j, "recordsInputPath"),
+								utils.createIdentifierOrLiteral(j, webpackProperties)
+							)
+						);
+					});
+			} else {
+				return recordsInputPathTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_recordsOutputPath.js.html b/docs/init_transformations_other_recordsOutputPath.js.html new file mode 100644 index 00000000000..69ad03c14c4 --- /dev/null +++ b/docs/init_transformations_other_recordsOutputPath.js.html @@ -0,0 +1,151 @@ + + + + + JSDoc: Source: init/transformations/other/recordsOutputPath.js + + + + + + + + + + +
+ +

Source: init/transformations/other/recordsOutputPath.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for recordsOutputPath. Finds the recordsOutputPath property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function recordsOutputPathTransform(
+	j,
+	ast,
+	webpackProperties,
+	action
+) {
+	function createRecordsOutputPathProperty(p) {
+		utils.pushCreateProperty(j, p, "recordsOutputPath", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "recordsOutputPath");
+	}
+	if (webpackProperties) {
+		if (action === "init" && typeof webpackProperties === "object") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(null, p, createRecordsOutputPathProperty)
+				);
+		} else if (action === "init" && webpackProperties.length) {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"recordsOutputPath",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const recordsOutputPathNode = utils.findRootNodesByName(
+				j,
+				ast,
+				"recordsOutputPath"
+			);
+			if (
+				recordsOutputPathNode.size() !== 0 &&
+				typeof webpackProperties === "object"
+			) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"recordsOutputPath"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (
+				recordsOutputPathNode.size() !== 0 &&
+				webpackProperties.length > 0
+			) {
+				return utils
+					.findRootNodesByName(j, ast, "recordsOutputPath")
+					.forEach(p => {
+						j(p).replaceWith(
+							j.property(
+								"init",
+								utils.createIdentifierOrLiteral(j, "recordsOutputPath"),
+								utils.createIdentifierOrLiteral(j, webpackProperties)
+							)
+						);
+					});
+			} else {
+				return recordsOutputPathTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_other_recordsPath.js.html b/docs/init_transformations_other_recordsPath.js.html new file mode 100644 index 00000000000..c8d0d0475d7 --- /dev/null +++ b/docs/init_transformations_other_recordsPath.js.html @@ -0,0 +1,140 @@ + + + + + JSDoc: Source: init/transformations/other/recordsPath.js + + + + + + + + + + +
+ +

Source: init/transformations/other/recordsPath.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for recordsPath. Finds the recordsPath property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function recordsPathTransform(
+	j,
+	ast,
+	webpackProperties,
+	action
+) {
+	function createRecordsPathProperty(p) {
+		utils.pushCreateProperty(j, p, "recordsPath", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "recordsPath");
+	}
+	if (webpackProperties) {
+		if (action === "init" && typeof webpackProperties === "object") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createRecordsPathProperty));
+		} else if (action === "init" && webpackProperties.length) {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"recordsPath",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			const recordsPathNode = utils.findRootNodesByName(j, ast, "recordsPath");
+			if (
+				recordsPathNode.size() !== 0 &&
+				typeof webpackProperties === "object"
+			) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(
+						p =>
+							utils.safeTraverse(p, ["parentPath", "value", "key", "name"]) ===
+							"recordsPath"
+					)
+					.filter(p => {
+						Object.keys(webpackProperties).forEach(prop => {
+							utils.checkIfExistsAndAddValue(
+								j,
+								p,
+								prop,
+								utils.createIdentifierOrLiteral(j, webpackProperties[prop])
+							);
+						});
+						return ast;
+					});
+			} else if (recordsPathNode.size() !== 0 && webpackProperties.length > 0) {
+				return recordsPathNode.forEach(p => {
+					j(p).replaceWith(
+						j.property(
+							"init",
+							utils.createIdentifierOrLiteral(j, "recordsPath"),
+							utils.createIdentifierOrLiteral(j, webpackProperties)
+						)
+					);
+				});
+			} else {
+				return recordsPathTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_output_output.js.html b/docs/init_transformations_output_output.js.html new file mode 100644 index 00000000000..230b97df91c --- /dev/null +++ b/docs/init_transformations_output_output.js.html @@ -0,0 +1,93 @@ + + + + + JSDoc: Source: init/transformations/output/output.js + + + + + + + + + + +
+ +

Source: init/transformations/output/output.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for output. Finds the output property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param {any} j — jscodeshift API
+ * @param {any} ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns {ast} - jscodeshift API
+ */
+module.exports = function outputTransform(j, ast, webpackProperties, action) {
+	function createOutputProperties(p) {
+		utils.pushCreateProperty(j, p, "output", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "output");
+	}
+	if (webpackProperties) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createOutputProperties));
+		} else if (action === "add") {
+			if (utils.findRootNodesByName(j, ast, "output").size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p => utils.pushObjectKeys(j, p, webpackProperties, "output"));
+			} else {
+				return outputTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_performance_performance.js.html b/docs/init_transformations_performance_performance.js.html new file mode 100644 index 00000000000..230b529890d --- /dev/null +++ b/docs/init_transformations_performance_performance.js.html @@ -0,0 +1,101 @@ + + + + + JSDoc: Source: init/transformations/performance/performance.js + + + + + + + + + + +
+ +

Source: init/transformations/performance/performance.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for performance. Finds the performance property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function performanceTransform(
+	j,
+	ast,
+	webpackProperties,
+	action
+) {
+	function createPerformanceProperty(p) {
+		utils.pushCreateProperty(j, p, "performance", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "performance");
+	}
+	if (webpackProperties && typeof webpackProperties === "object") {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createPerformanceProperty));
+		} else if (action === "add") {
+			if (utils.findRootNodesByName(j, ast, "performance").size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p =>
+						utils.pushObjectKeys(j, p, webpackProperties, "performance")
+					);
+			} else {
+				return performanceTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_plugins_plugins.js.html b/docs/init_transformations_plugins_plugins.js.html new file mode 100644 index 00000000000..6bbeea90897 --- /dev/null +++ b/docs/init_transformations_plugins_plugins.js.html @@ -0,0 +1,101 @@ + + + + + JSDoc: Source: init/transformations/plugins/plugins.js + + + + + + + + + + +
+ +

Source: init/transformations/plugins/plugins.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for plugins. Finds the plugins property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function(j, ast, webpackProperties, action) {
+	function createPluginsProperty(p) {
+		const pluginArray = utils.createArrayWithChildren(
+			j,
+			"plugins",
+			webpackProperties,
+			true
+		);
+		return p.value.properties.push(pluginArray);
+	}
+	if (webpackProperties) {
+		if (Array.isArray(webpackProperties) && action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createPluginsProperty));
+		} else if (action === "add") {
+			return utils
+				.findRootNodesByName(j, ast, "plugins")
+				.filter(p =>
+					p.value.value.elements.push(
+						utils.createEmptyCallableFunctionWithArguments(j, webpackProperties)
+					)
+				);
+		} else if (action === "remove") {
+			return utils
+				.findRootNodesByName(j, ast, "plugins")
+				.filter(p =>
+					p.value.value.elements.filter(name => name !== webpackProperties)
+				);
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_resolve_resolve.js.html b/docs/init_transformations_resolve_resolve.js.html new file mode 100644 index 00000000000..2c6e138cad4 --- /dev/null +++ b/docs/init_transformations_resolve_resolve.js.html @@ -0,0 +1,96 @@ + + + + + JSDoc: Source: init/transformations/resolve/resolve.js + + + + + + + + + + +
+ +

Source: init/transformations/resolve/resolve.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for resolve. Finds the resolve property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function resolveTransform(j, ast, webpackProperties, action) {
+	function createResolveProperties(p) {
+		utils.pushCreateProperty(j, p, "resolve", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "resolve");
+	}
+	if (webpackProperties) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createResolveProperties));
+		} else if (action === "add") {
+			if (utils.findRootNodesByName(j, ast, "resolve").size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p =>
+						utils.pushObjectKeys(j, p, webpackProperties, "resolve")
+					);
+			} else {
+				return resolveTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_stats_stats.js.html b/docs/init_transformations_stats_stats.js.html new file mode 100644 index 00000000000..c8c4482f921 --- /dev/null +++ b/docs/init_transformations_stats_stats.js.html @@ -0,0 +1,106 @@ + + + + + JSDoc: Source: init/transformations/stats/stats.js + + + + + + + + + + +
+ +

Source: init/transformations/stats/stats.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for stats. Finds the stats property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function statsTransform(j, ast, webpackProperties, action) {
+	function createStatsProperty(p) {
+		utils.pushCreateProperty(j, p, "stats", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "stats");
+	}
+	if (webpackProperties) {
+		if (action === "init" && typeof webpackProperties === "object") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p => utils.isAssignment(null, p, createStatsProperty));
+		} else if (action === "init" && webpackProperties.length) {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"stats",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			if (utils.findRootNodesByName(j, ast, "stats").size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p => utils.pushObjectKeys(j, p, webpackProperties, "stats"));
+			} else {
+				return statsTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_target_target.js.html b/docs/init_transformations_target_target.js.html new file mode 100644 index 00000000000..c5417e4c68c --- /dev/null +++ b/docs/init_transformations_target_target.js.html @@ -0,0 +1,98 @@ + + + + + JSDoc: Source: init/transformations/target/target.js + + + + + + + + + + +
+ +

Source: init/transformations/target/target.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for target. Finds the target property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function targetTransform(j, ast, webpackProperties, action) {
+	if (webpackProperties && webpackProperties.length) {
+		if (action === "init") {
+			return ast
+				.find(j.ObjectExpression)
+				.filter(p =>
+					utils.isAssignment(
+						j,
+						p,
+						utils.pushCreateProperty,
+						"target",
+						webpackProperties
+					)
+				);
+		} else if (action === "add") {
+			if (utils.findRootNodesByName(j, ast, "target").size() !== 0) {
+				return ast
+					.find(j.ObjectExpression)
+					.filter(p => utils.pushObjectKeys(j, p, webpackProperties, "target"));
+			} else {
+				return targetTransform(j, ast, webpackProperties, "init");
+			}
+		} else if (action === "remove") {
+			// TODO
+		} else if (action === "update") {
+			// TODO
+		}
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_top-scope_top-scope.js.html b/docs/init_transformations_top-scope_top-scope.js.html new file mode 100644 index 00000000000..fa182f28d1f --- /dev/null +++ b/docs/init_transformations_top-scope_top-scope.js.html @@ -0,0 +1,80 @@ + + + + + JSDoc: Source: init/transformations/top-scope/top-scope.js + + + + + + + + + + +
+ +

Source: init/transformations/top-scope/top-scope.js

+ + + + + + +
+
+
/**
+ *
+ * Get an property named topScope from yeoman and inject it to the top scope of
+ * the config, outside module.exports
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function(j, ast, webpackProperties, action) {
+	function createTopScopeProperty(p) {
+		webpackProperties.forEach(n => {
+			if (
+				!p.value.body[0].declarations ||
+				n.indexOf(p.value.body[0].declarations[0].id.name) <= 0
+			) {
+				p.value.body.splice(-1, 0, n);
+			}
+		});
+	}
+	if (webpackProperties) {
+		return ast.find(j.Program).filter(p => createTopScopeProperty(p));
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_watch_watch.js.html b/docs/init_transformations_watch_watch.js.html new file mode 100644 index 00000000000..ff3fb392425 --- /dev/null +++ b/docs/init_transformations_watch_watch.js.html @@ -0,0 +1,84 @@ + + + + + JSDoc: Source: init/transformations/watch/watch.js + + + + + + + + + + +
+ +

Source: init/transformations/watch/watch.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for watch. Finds the watch property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function(j, ast, webpackProperties, action) {
+	if (typeof webpackProperties === "boolean" && action === "init") {
+		return ast
+			.find(j.ObjectExpression)
+			.filter(p =>
+				utils.isAssignment(
+					j,
+					p,
+					utils.pushCreateProperty,
+					"watch",
+					webpackProperties
+				)
+			);
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/init_transformations_watch_watchOptions.js.html b/docs/init_transformations_watch_watchOptions.js.html new file mode 100644 index 00000000000..01367545c35 --- /dev/null +++ b/docs/init_transformations_watch_watchOptions.js.html @@ -0,0 +1,80 @@ + + + + + JSDoc: Source: init/transformations/watch/watchOptions.js + + + + + + + + + + +
+ +

Source: init/transformations/watch/watchOptions.js

+ + + + + + +
+
+
"use strict";
+
+const utils = require("../../../utils/ast-utils");
+
+/**
+ *
+ * Transform for watchOptions. Finds the watchOptions property from yeoman and creates a
+ * property based on what the user has given us.
+ *
+ * @param j — jscodeshift API
+ * @param ast - jscodeshift API
+ * @param {any} webpackProperties - transformation object to scaffold
+ * @param {String} action - action that indicates what to be done to the AST
+ * @returns ast - jscodeshift API
+ */
+
+module.exports = function(j, ast, webpackProperties, action) {
+	function createWatchOptionsProperty(p) {
+		utils.pushCreateProperty(j, p, "watchOptions", j.objectExpression([]));
+		return utils.pushObjectKeys(j, p, webpackProperties, "watchOptions");
+	}
+	if (webpackProperties && action === "init") {
+		return ast
+			.find(j.ObjectExpression)
+			.filter(p => utils.isAssignment(null, p, createWatchOptionsProperty));
+	} else {
+		return ast;
+	}
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/docs/module-A%20Set%20of%20all%20accepted%20properties.html b/docs/module-A%20Set%20of%20all%20accepted%20properties.html new file mode 100644 index 00000000000..4d4b80ba369 --- /dev/null +++ b/docs/module-A%20Set%20of%20all%20accepted%20properties.html @@ -0,0 +1,122 @@ + + + + + JSDoc: Module: A Set of all accepted properties + + + + + + + + + + +
+ +

Module: A Set of all accepted properties

+ + + + + + +
+ +
+ + + +
+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/docs/scripts/linenumber.js b/docs/scripts/linenumber.js new file mode 100644 index 00000000000..8d52f7eafdb --- /dev/null +++ b/docs/scripts/linenumber.js @@ -0,0 +1,25 @@ +/*global document */ +(function() { + var source = document.getElementsByClassName('prettyprint source linenums'); + var i = 0; + var lineNumber = 0; + var lineId; + var lines; + var totalLines; + var anchorHash; + + if (source && source[0]) { + anchorHash = document.location.hash.substring(1); + lines = source[0].getElementsByTagName('li'); + totalLines = lines.length; + + for (; i < totalLines; i++) { + lineNumber++; + lineId = 'line' + lineNumber; + lines[i].id = lineId; + if (lineId === anchorHash) { + lines[i].className += ' selected'; + } + } + } +})(); diff --git a/docs/scripts/prettify/Apache-License-2.0.txt b/docs/scripts/prettify/Apache-License-2.0.txt new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/docs/scripts/prettify/Apache-License-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/docs/scripts/prettify/lang-css.js b/docs/scripts/prettify/lang-css.js new file mode 100644 index 00000000000..041e1f59067 --- /dev/null +++ b/docs/scripts/prettify/lang-css.js @@ -0,0 +1,2 @@ +PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", +/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/docs/scripts/prettify/prettify.js b/docs/scripts/prettify/prettify.js new file mode 100644 index 00000000000..eef5ad7e6a0 --- /dev/null +++ b/docs/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p th:last-child { border-right: 1px solid #ddd; } + +.ancestors, .attribs { color: #999; } +.ancestors a, .attribs a +{ + color: #999 !important; + text-decoration: none; +} + +.clear +{ + clear: both; +} + +.important +{ + font-weight: bold; + color: #950B02; +} + +.yes-def { + text-indent: -1000px; +} + +.type-signature { + color: #aaa; +} + +.name, .signature { + font-family: Consolas, Monaco, 'Andale Mono', monospace; +} + +.details { margin-top: 14px; border-left: 2px solid #DDD; } +.details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; } +.details dd { margin-left: 70px; } +.details ul { margin: 0; } +.details ul { list-style-type: none; } +.details li { margin-left: 30px; padding-top: 6px; } +.details pre.prettyprint { margin: 0 } +.details .object-value { padding-top: 0; } + +.description { + margin-bottom: 1em; + margin-top: 1em; +} + +.code-caption +{ + font-style: italic; + font-size: 107%; + margin: 0; +} + +.prettyprint +{ + border: 1px solid #ddd; + width: 80%; + overflow: auto; +} + +.prettyprint.source { + width: inherit; +} + +.prettyprint code +{ + font-size: 100%; + line-height: 18px; + display: block; + padding: 4px 12px; + margin: 0; + background-color: #fff; + color: #4D4E53; +} + +.prettyprint code span.line +{ + display: inline-block; +} + +.prettyprint.linenums +{ + padding-left: 70px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.prettyprint.linenums ol +{ + padding-left: 0; +} + +.prettyprint.linenums li +{ + border-left: 3px #ddd solid; +} + +.prettyprint.linenums li.selected, +.prettyprint.linenums li.selected * +{ + background-color: lightyellow; +} + +.prettyprint.linenums li * +{ + -webkit-user-select: text; + -moz-user-select: text; + -ms-user-select: text; + user-select: text; +} + +.params .name, .props .name, .name code { + color: #4D4E53; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 100%; +} + +.params td.description > p:first-child, +.props td.description > p:first-child +{ + margin-top: 0; + padding-top: 0; +} + +.params td.description > p:last-child, +.props td.description > p:last-child +{ + margin-bottom: 0; + padding-bottom: 0; +} + +.disabled { + color: #454545; +} diff --git a/docs/styles/prettify-jsdoc.css b/docs/styles/prettify-jsdoc.css new file mode 100644 index 00000000000..5a2526e3748 --- /dev/null +++ b/docs/styles/prettify-jsdoc.css @@ -0,0 +1,111 @@ +/* JSDoc prettify.js theme */ + +/* plain text */ +.pln { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* string content */ +.str { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a keyword */ +.kwd { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a comment */ +.com { + font-weight: normal; + font-style: italic; +} + +/* a type name */ +.typ { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a literal value */ +.lit { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* punctuation */ +.pun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp open bracket */ +.opn { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp close bracket */ +.clo { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a markup tag name */ +.tag { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute name */ +.atn { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute value */ +.atv { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a declaration */ +.dec { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a variable name */ +.var { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a function name */ +.fun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; +} diff --git a/docs/styles/prettify-tomorrow.css b/docs/styles/prettify-tomorrow.css new file mode 100644 index 00000000000..b6f92a78db9 --- /dev/null +++ b/docs/styles/prettify-tomorrow.css @@ -0,0 +1,132 @@ +/* Tomorrow Theme */ +/* Original theme - https://github.com/chriskempson/tomorrow-theme */ +/* Pretty printing styles. Used with prettify.js. */ +/* SPAN elements with the classes below are added by prettyprint. */ +/* plain text */ +.pln { + color: #4d4d4c; } + +@media screen { + /* string content */ + .str { + color: #718c00; } + + /* a keyword */ + .kwd { + color: #8959a8; } + + /* a comment */ + .com { + color: #8e908c; } + + /* a type name */ + .typ { + color: #4271ae; } + + /* a literal value */ + .lit { + color: #f5871f; } + + /* punctuation */ + .pun { + color: #4d4d4c; } + + /* lisp open bracket */ + .opn { + color: #4d4d4c; } + + /* lisp close bracket */ + .clo { + color: #4d4d4c; } + + /* a markup tag name */ + .tag { + color: #c82829; } + + /* a markup attribute name */ + .atn { + color: #f5871f; } + + /* a markup attribute value */ + .atv { + color: #3e999f; } + + /* a declaration */ + .dec { + color: #f5871f; } + + /* a variable name */ + .var { + color: #c82829; } + + /* a function name */ + .fun { + color: #4271ae; } } +/* Use higher contrast and text-weight for printable form. */ +@media print, projection { + .str { + color: #060; } + + .kwd { + color: #006; + font-weight: bold; } + + .com { + color: #600; + font-style: italic; } + + .typ { + color: #404; + font-weight: bold; } + + .lit { + color: #044; } + + .pun, .opn, .clo { + color: #440; } + + .tag { + color: #006; + font-weight: bold; } + + .atn { + color: #404; } + + .atv { + color: #060; } } +/* Style */ +/* +pre.prettyprint { + background: white; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 12px; + line-height: 1.5; + border: 1px solid #ccc; + padding: 10px; } +*/ + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; } + +/* IE indents via margin-left */ +li.L0, +li.L1, +li.L2, +li.L3, +li.L4, +li.L5, +li.L6, +li.L7, +li.L8, +li.L9 { + /* */ } + +/* Alternate shading for lines */ +li.L1, +li.L3, +li.L5, +li.L7, +li.L9 { + /* */ } diff --git a/docs/utils_ast-utils.js.html b/docs/utils_ast-utils.js.html new file mode 100644 index 00000000000..d778bee5ff4 --- /dev/null +++ b/docs/utils_ast-utils.js.html @@ -0,0 +1,694 @@ + + + + + JSDoc: Source: utils/ast-utils.js + + + + + + + + + + +
+ +

Source: utils/ast-utils.js

+ + + + + + +
+
+
//      
+// eslint-disable-next-line node/no-unsupported-features
+             
+             
+       
+           
+          
+             
+                     
+                   
+                 
+                  
+
+function safeTraverse(obj        , paths          )       {
+	let val         = obj;
+	let idx         = 0;
+
+	while (idx < paths.length) {
+		if (!val) {
+			return null;
+		}
+		val = val[paths[idx]];
+		idx++;
+	}
+	return val;
+}
+
+// Convert nested MemberExpressions to strings like webpack.optimize.DedupePlugin
+function memberExpressionToPathString(path        )         {
+	if (path && path.object) {
+		return [memberExpressionToPathString(path.object), path.property.name].join(
+			"."
+		);
+	}
+	return path.name;
+}
+
+// Convert Array<string> like ['webpack', 'optimize', 'DedupePlugin'] to nested MemberExpressions
+function pathsToMemberExpression(j             , paths          ) {
+	if (!paths.length) {
+		return null;
+	} else if (paths.length === 1) {
+		return j.identifier(paths[0]);
+	} else {
+		const first = paths.slice(0, 1);
+		const rest = paths.slice(1);
+		return j.memberExpression(
+			pathsToMemberExpression(j, rest),
+			pathsToMemberExpression(j, first)
+		);
+	}
+}
+
+/**
+ *
+ * Find paths that match `new name.space.PluginName()` for a
+ * given array of plugin names
+ *
+ * @param {any} j — jscodeshift API
+ * @param {Node} node - Node to start search from
+ * @param {String[]} pluginNamesArray - Array of plugin names like `webpack.LoaderOptionsPlugin`
+ * @returns {Node} Node that has the pluginName
+ */
+
+function findPluginsByName(
+	j             ,
+	node          ,
+	pluginNamesArray          
+)           {
+	return node.find(j.NewExpression).filter(path => {
+		return pluginNamesArray.some(
+			plugin =>
+				memberExpressionToPathString(path.get("callee").value) === plugin
+		);
+	});
+}
+
+/**
+ *
+ * Finds the path to the `name: []` node
+ *
+ * @param {any} j — jscodeshift API
+ * @param {Node} node - Node to start search from
+ * @param {String} propName - property to search for
+ * @returns {Node} found node and
+ */
+
+function findRootNodesByName(
+	j             ,
+	node          ,
+	propName        
+)                      {
+	return node.find(j.Property, { key: { name: propName } });
+}
+
+/**
+ *
+ * Creates an Object's property with a given key and value
+ *
+ * @param {any} j — jscodeshift API
+ * @param {String | Number} key - Property key
+ * @param {String | Number | Boolean} value - Property value
+ * @returns {Node}
+ */
+
+function createProperty(
+	j             ,
+	key                 ,
+	value     
+)               {
+	return j.property(
+		"init",
+		createIdentifierOrLiteral(j, key),
+		createLiteral(j, value)
+	);
+}
+
+/**
+ *
+ * Creates an appropriate literal property
+ *
+ * @param {any} j — jscodeshift API
+ * @param {String | Boolean | Number} val
+ * @returns {Node}
+ */
+
+function createLiteral(
+	j             ,
+	val                           
+)                  {
+	let literalVal      = val;
+	// We'll need String to native type conversions
+	if (typeof val === "string") {
+		// 'true' => true
+		if (val === "true") literalVal = true;
+		// 'false' => false
+		if (val === "false") literalVal = false;
+		// '1' => 1
+		if (!isNaN(Number(val))) literalVal = Number(val);
+	}
+	return j.literal(literalVal);
+}
+
+/**
+ *
+ * Creates an appropriate identifier or literal property
+ *
+ * @param {any} j — jscodeshift API
+ * @param {String | Boolean | Number} val
+ * @returns {Node}
+ */
+
+function createIdentifierOrLiteral(j             , val     )      {
+	// IPath<IIdentifier> | IPath<ILiteral> doesn't work, find another way
+	let literalVal = val;
+	// We'll need String to native type conversions
+	if (typeof val === "string" || val.__paths) {
+		// 'true' => true
+		if (val === "true") {
+			literalVal = true;
+			return j.literal(literalVal);
+		}
+		// 'false' => false
+		if (val === "false") {
+			literalVal = false;
+			return j.literal(literalVal);
+		}
+		// '1' => 1
+		if (!isNaN(Number(val))) {
+			literalVal = Number(val);
+			return j.literal(literalVal);
+		}
+
+		if (val.__paths) {
+			return createExternalRegExp(j, val);
+		} else {
+			// Use identifier instead
+			// TODO: Check if literalVal is a valid Identifier!
+			return j.identifier(literalVal);
+		}
+	}
+	return j.literal(literalVal);
+}
+
+/**
+ *
+ * Findes or creates a node for a given plugin name string with options object
+ * If plugin decalaration already exist, options are merged.
+ *
+ * @param {any} j — jscodeshift API
+ * @param {Node} rootNodePath - `plugins: []` NodePath where plugin should be added. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths
+ * @param {String} pluginName - ex. `webpack.LoaderOptionsPlugin`
+ * @param {Object} options - plugin options
+ * @returns {Void}
+ */
+
+function createOrUpdatePluginByName(
+	j             ,
+	rootNodePath          ,
+	pluginName        ,
+	options     
+) {
+	const pluginInstancePath = findPluginsByName(j, j(rootNodePath), [
+		pluginName
+	]);
+	let optionsProps;
+	if (options) {
+		optionsProps = Object.keys(options).map(key => {
+			return createProperty(j, key, options[key]);
+		});
+	}
+
+	// If plugin declaration already exist
+	if (pluginInstancePath.size()) {
+		pluginInstancePath.forEach(path => {
+			// There are options we want to pass as argument
+			if (optionsProps) {
+				const args = path.value.arguments;
+				if (args.length) {
+					// Plugin is called with object as arguments
+					// we will merge those objects
+					let currentProps = j(path)
+						.find(j.ObjectExpression)
+						.get("properties");
+
+					optionsProps.forEach((opt     ) => {
+						// Search for same keys in the existing object
+						const existingProps = j(currentProps)
+							.find(j.Identifier)
+							.filter(path => opt.key.value === path.value.name);
+
+						if (existingProps.size()) {
+							// Replacing values for the same key
+							existingProps.forEach(path => {
+								j(path.parent).replaceWith(opt);
+							});
+						} else {
+							// Adding new key:values
+							currentProps.value.push(opt);
+						}
+					});
+				} else {
+					// Plugin is called without arguments
+					args.push(j.objectExpression(optionsProps));
+				}
+			}
+		});
+	} else {
+		let argumentsArray = [];
+		if (optionsProps) {
+			argumentsArray = [j.objectExpression(optionsProps)];
+		}
+		const loaderPluginInstance = j.newExpression(
+			pathsToMemberExpression(j, pluginName.split(".").reverse()),
+			argumentsArray
+		);
+		rootNodePath.value.elements.push(loaderPluginInstance);
+	}
+}
+
+/**
+ *
+ * Finds the variable to which a third party plugin is assigned to
+ *
+ * @param {any} j — jscodeshift API
+ * @param {Node} rootNode - `plugins: []` Root Node. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths
+ * @param {String} pluginPackageName - ex. `extract-text-plugin`
+ * @returns {String} variable name - ex. 'var s = require(s) gives "s"`
+ */
+
+function findVariableToPlugin(
+	j             ,
+	rootNode          ,
+	pluginPackageName        
+)          {
+	const moduleVarNames                        = rootNode
+		.find(j.VariableDeclarator)
+		.filter(j.filters.VariableDeclarator.requiresModule(pluginPackageName))
+		.nodes();
+	if (moduleVarNames.length === 0) return null;
+	return moduleVarNames.pop().id.name;
+}
+
+/**
+ *
+ * Returns true if type is given type
+ * @param {Node} path - pathNode
+ * @param {String} type - node type
+ * @returns {Boolean}
+ */
+
+function isType(path          , type        )          {
+	return path.type === type;
+}
+
+function findObjWithOneOfKeys(p          , keyNames          )          {
+	return p.value.properties.reduce((predicate, prop) => {
+		const name = prop.key.name;
+		return keyNames.indexOf(name) > -1 || predicate;
+	}, false);
+}
+
+/**
+ *
+ * Returns constructed require symbol
+ * @param {any} j — jscodeshift API
+ * @param {String} constName - Name of require
+ * @param {String} packagePath - path of required package
+ * @returns {Node} - the created ast
+ */
+
+function getRequire(
+	j             ,
+	constName        ,
+	packagePath        
+)                             {
+	return j.variableDeclaration("const", [
+		j.variableDeclarator(
+			j.identifier(constName),
+			j.callExpression(j.identifier("require"), [j.literal(packagePath)])
+		)
+	]);
+}
+
+/**
+ *
+ * If a prop exists, it overrides it, else it creates a new one
+ * @param {any} j — jscodeshift API
+ * @param {Node} node - objectexpression to check
+ * @param {String} key - Key of the property
+ * @param {String} value - computed value of the property
+ * @returns {Void}
+ */
+
+function checkIfExistsAndAddValue(
+	j             ,
+	node                          ,
+	key        ,
+	value        
+)       {
+	const existingProp = node.value.properties.filter(
+		prop => prop.key.name === key
+	);
+	let prop;
+	if (existingProp.length > 0) {
+		prop = existingProp[0];
+		prop.value = value;
+	} else {
+		prop = j.property("init", j.identifier(key), value);
+		node.value.properties.push(prop);
+	}
+}
+
+/**
+ *
+ * Creates an empty array
+ * @param {any} j — jscodeshift API
+ * @param {String} key - array name
+ * @returns {Array} arr - An empty array
+ */
+function createEmptyArrayProperty(
+	j             ,
+	key        
+)                              {
+	return j.property("init", j.identifier(key), j.arrayExpression([]));
+}
+
+/**
+ *
+ * Creates an array and iterates on an object with properties
+ *
+ * @param {any} j — jscodeshift API
+ * @param {String} key - object name
+ * @param {String} subProps - computed value of the property
+ * @param {Boolean} shouldDropKeys - bool to ask to use obj.keys or not
+ * @returns {Array} arr - An array with the object properties
+ */
+
+function createArrayWithChildren(
+	j             ,
+	key        ,
+	subProps                   ,
+	shouldDropKeys         
+) {
+	let arr = createEmptyArrayProperty(j, key);
+	if (shouldDropKeys) {
+		subProps.forEach((subProperty          ) => {
+			let objectOfArray = j.objectExpression([]);
+			if (typeof subProperty !== "string") {
+				loopThroughObjects(j, objectOfArray, subProperty);
+				arr.value.elements.push(objectOfArray);
+			} else {
+				return arr.value.elements.push(
+					createIdentifierOrLiteral(j, subProperty)
+				);
+			}
+		});
+	} else {
+		Object.keys(subProps[key]).forEach(subProperty => {
+			arr.value.elements.push(
+				createIdentifierOrLiteral(j, subProps[key][subProperty])
+			);
+		});
+	}
+	return arr;
+}
+
+/**
+ *
+ * Loops through an object and adds property to an object with no identifier
+ * @param {any} j — jscodeshift API
+ * @param {Node} p - node to add value to
+ * @param {Object} obj - Object to loop through
+ * @returns {Function | Node} - Either pushes the node, or reruns until
+ * nothing is left
+ */
+
+function loopThroughObjects(
+	j             ,
+	p                   ,
+	obj        
+)       {
+	Object.keys(obj).forEach(prop => {
+		if (prop.indexOf("inject") >= 0) {
+			// TODO to insert the type of node, identifier or literal
+			const propertyExpression           = createIdentifierOrLiteral(
+				j,
+				obj[prop]
+			);
+			return p.properties.push(propertyExpression);
+		}
+		// eslint-disable-next-line no-irregular-whitespace
+		if (typeof obj[prop] !== "object" || obj[prop] instanceof RegExp) {
+			p.properties.push(
+				createObjectWithSuppliedProperty(
+					j,
+					prop,
+					createIdentifierOrLiteral(j, obj[prop])
+				)
+			);
+		} else if (Array.isArray(obj[prop])) {
+			let arrayProp = createArrayWithChildren(j, prop, obj[prop], true);
+			p.properties.push(arrayProp);
+		} else {
+			let objectBlock = j.objectExpression([]);
+			let propertyOfBlock = createObjectWithSuppliedProperty(
+				j,
+				prop,
+				objectBlock
+			);
+			loopThroughObjects(j, objectBlock, obj[prop]);
+			p.properties.push(propertyOfBlock);
+		}
+	});
+}
+
+/**
+ *
+ * Creates an object with an supplied property as parameter
+ *
+ * @param {any} j — jscodeshift API
+ * @param {String} key - object name
+ * @param {Node} prop - property to be added
+ * @returns {Node} - An property with the supplied property
+ */
+
+function createObjectWithSuppliedProperty(
+	j             ,
+	key        ,
+	prop     
+)               {
+	return j.property("init", j.identifier(key), prop);
+}
+
+/**
+ *
+ * Finds a regexp property with an already parsed AST from the user
+ * @param {any} j — jscodeshift API
+ * @param {String} prop - property to find the value at
+ * @returns {Node} - A literal node with the found regexp
+ */
+
+function createExternalRegExp(j             , prop     )                  {
+	let regExpProp = prop.__paths[0].value.program.body[0].expression;
+	return j.literal(regExpProp.value);
+}
+
+/**
+ *
+ * Creates a property and pushes the value to a node
+ *
+ * @param {any} j — jscodeshift API
+ * @param {Node} p - Node to push against
+ * @param {String} key - key used as identifier
+ * @param {String} val - property value
+ * @returns {Node} - Returns node the pushed property
+ */
+
+function pushCreateProperty(
+	j             ,
+	p                          ,
+	key        ,
+	val     
+)         {
+	let property                                               ;
+	if (val.hasOwnProperty("type")) {
+		property = val;
+	} else {
+		property = createIdentifierOrLiteral(j, val);
+	}
+	return p.value.properties.push(
+		createObjectWithSuppliedProperty(j, key, property)
+	);
+}
+
+/**
+ *
+ * @param {any} j — jscodeshift API
+ * @param {Node} p - path to push
+ * @param {Object} webpackProperties - The object to loop over
+ * @param {String} name - Key that will be the identifier we find and add values to
+ * @returns {Node | Function} Returns a function that will push a node if
+ * subProperty is an array, else it will invoke a function that will push a single node
+ */
+
+function pushObjectKeys(
+	j             ,
+	p          ,
+	webpackProperties        ,
+	name        
+)      {
+	p.value.properties
+		.filter(n => safeTraverse(n, ["key", "name"]) === name)
+		.forEach(prop => {
+			Object.keys(webpackProperties).forEach(webpackProp => {
+				if (webpackProp.indexOf("inject") >= 0) {
+					return prop.value.properties.push(
+						createIdentifierOrLiteral(j, webpackProperties[webpackProp])
+					);
+				} else if (Array.isArray(webpackProperties[webpackProp])) {
+					const propArray = createArrayWithChildren(
+						j,
+						webpackProp,
+						webpackProperties[webpackProp],
+						true
+					);
+					return prop.value.properties.push(propArray);
+				} else if (
+					typeof webpackProperties[webpackProp] !== "object" ||
+					webpackProperties[webpackProp].__paths ||
+					webpackProperties[webpackProp] instanceof RegExp
+				) {
+					return pushCreateProperty(
+						j,
+						prop,
+						webpackProp,
+						webpackProperties[webpackProp]
+					);
+				} else {
+					pushCreateProperty(j, prop, webpackProp, j.objectExpression([]));
+					return pushObjectKeys(
+						j,
+						prop,
+						webpackProperties[webpackProp],
+						webpackProp
+					);
+				}
+			});
+		});
+}
+
+/**
+ *
+ * Checks if we are at the correct node and later invokes a callback
+ * for the transforms to either use their own transform function or
+ * use pushCreateProperty if the transform doesn't expect any properties
+ *
+ * @param {any} j — jscodeshift API
+ * @param {Node} p - Node to push against
+ * @param {Function} cb - callback to be invoked
+ * @param {String} identifier - key to use as property
+ * @param {Object} property - WebpackOptions that later will be converted via
+ * pushCreateProperty via WebpackOptions[identifier]
+ * @returns {Function} cb - Returns the callback and pushes a new node
+ */
+
+function isAssignment(
+	j             ,
+	p          ,
+	cb            ,
+	identifier        ,
+	property        
+)      {
+	if (p.parent.value.type === "AssignmentExpression") {
+		if (j) {
+			return cb(j, p, identifier, property);
+		} else {
+			return cb(p);
+		}
+	}
+}
+
+/**
+ *
+ * Creates a function call with arguments
+ * @param {any} j — jscodeshift API
+ * @param {String} name - Name for the given function
+ * @returns {Node} -  Returns the node for the created
+ * function
+ */
+
+function createEmptyCallableFunctionWithArguments(
+	j             ,
+	name        
+)      {
+	return j.callExpression(j.identifier(name), [
+		j.literal("/* Add your arguments here */")
+	]);
+}
+
+module.exports = {
+	safeTraverse,
+	createProperty,
+	findPluginsByName,
+	findRootNodesByName,
+	createOrUpdatePluginByName,
+	findVariableToPlugin,
+	isType,
+	createLiteral,
+	createIdentifierOrLiteral,
+	findObjWithOneOfKeys,
+	getRequire,
+	checkIfExistsAndAddValue,
+	createArrayWithChildren,
+	createEmptyArrayProperty,
+	createObjectWithSuppliedProperty,
+	createExternalRegExp,
+	createEmptyCallableFunctionWithArguments,
+	pushCreateProperty,
+	pushObjectKeys,
+	isAssignment,
+	loopThroughObjects
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_copy-utils.js.html b/docs/utils_copy-utils.js.html new file mode 100644 index 00000000000..c8fd6b3ea51 --- /dev/null +++ b/docs/utils_copy-utils.js.html @@ -0,0 +1,108 @@ + + + + + JSDoc: Source: utils/copy-utils.js + + + + + + + + + + +
+ +

Source: utils/copy-utils.js

+ + + + + + +
+
+
var path = require("path");
+
+/**
+ * Takes in a file path in the `./templates` directory. Copies that
+ * file to the destination, with the `.tpl` extension stripped.
+ *
+ * @param {Generator} generator A Yeoman Generator instance
+ * @param {string} templateDir Absolute path to template directory
+ * @returns {Function} A curried function that takes a file path and copies it
+ */
+var generatorCopy = (
+	generator,
+	templateDir
+) => /** @param {string} filePath */ filePath => {
+	var sourceParts = templateDir.split(path.delimiter);
+	sourceParts.push.apply(sourceParts, filePath.split("/"));
+	var targetParts = path.dirname(filePath).split("/");
+	targetParts.push(path.basename(filePath, ".tpl"));
+
+	generator.fs.copy(
+		path.join.apply(null, sourceParts),
+		generator.destinationPath(path.join.apply(null, targetParts))
+	);
+};
+
+/**
+ * Takes in a file path in the `./templates` directory. Copies that
+ * file to the destination, with the `.tpl` extension and `_` prefix
+ * stripped. Passes `this.props` to the template.
+ *
+ * @param {Generator} generator A Yeoman Generator instance
+ * @param {string} templateDir Absolute path to template directory
+ * @param {any} templateData An object containing the data passed to
+ * the template files.
+ * @returns {Function} A curried function that takes a file path and copies it
+ */
+var generatorCopyTpl = (
+	generator,
+	templateDir,
+	templateData
+) => /** @param {string} filePath */ filePath => {
+	var sourceParts = templateDir.split(path.delimiter);
+	sourceParts.push.apply(sourceParts, filePath.split("/"));
+	var targetParts = path.dirname(filePath).split("/");
+	targetParts.push(path.basename(filePath, ".tpl").slice(1));
+
+	generator.fs.copyTpl(
+		path.join.apply(null, sourceParts),
+		generator.destinationPath(path.join.apply(null, targetParts)),
+		templateData
+	);
+};
+
+module.exports = {
+	generatorCopy,
+	generatorCopyTpl
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_defineTest.js.html b/docs/utils_defineTest.js.html new file mode 100644 index 00000000000..0dd3e79aeaf --- /dev/null +++ b/docs/utils_defineTest.js.html @@ -0,0 +1,156 @@ + + + + + JSDoc: Source: utils/defineTest.js + + + + + + + + + + +
+ +

Source: utils/defineTest.js

+ + + + + + +
+
+
"use strict";
+
+const fs = require("fs");
+const path = require("path");
+
+/**
+ * Utility function to run a jscodeshift script within a unit test.
+ * This makes several assumptions about the environment.
+ *
+ * Notes:
+ * - The test should be located in a subdirectory next to the transform itself.
+ *   Commonly tests are located in a directory called __tests__.
+ *
+ * - Test data should be located in a directory called __testfixtures__
+ *   alongside the transform and __tests__ directory.
+ * @param  {String} dirName          contains the name of the directory the test is located in. This
+ *                                   should normally be passed via __dirname.
+ * @param  {String} transformName    contains the filename of the transform being tested,
+ *                                   excluding the .js extension.
+ * @param  {String} [testFilePrefix] Optionally contains the name of the file with the test
+ *                                   data. If not specified, it defaults to the same value as `transformName`.
+ *                                   This will be suffixed with ".input.js" for the input file and ".output.js"
+ *                                   for the expected output. For example, if set to "foo", we will read the
+ *                                   "foo.input.js" file, pass this to the transform, and expect its output to
+ *                                   be equal to the contents of "foo.output.js".
+ * @param  {Object|Boolean|String} initOptions TBD
+ * @param  {String} action init, update or remove, decides how to format the AST
+ * @return {Function} Function that fires of the transforms
+ */
+function runSingleTansform(
+	dirName,
+	transformName,
+	testFilePrefix,
+	initOptions,
+	action
+) {
+	if (!testFilePrefix) {
+		testFilePrefix = transformName;
+	}
+	const fixtureDir = path.join(dirName, "__testfixtures__");
+	const inputPath = path.join(fixtureDir, testFilePrefix + ".input.js");
+	const source = fs.readFileSync(inputPath, "utf8");
+	// Assumes transform and test are on the same level
+	const module = require(path.join(dirName, transformName + ".js"));
+	// Handle ES6 modules using default export for the transform
+	const transform = module.default ? module.default : module;
+
+	// Jest resets the module registry after each test, so we need to always get
+	// a fresh copy of jscodeshift on every test run.
+	let jscodeshift = require("jscodeshift/dist/core");
+	if (module.parser) {
+		jscodeshift = jscodeshift.withParser(module.parser);
+	}
+	const ast = jscodeshift(source);
+	if (initOptions || typeof initOptions === "boolean") {
+		return transform(jscodeshift, ast, initOptions, action).toSource({
+			quote: "single"
+		});
+	}
+	return transform(jscodeshift, ast, source, action).toSource({
+		quote: "single"
+	});
+}
+
+/**
+ * Handles some boilerplate around defining a simple jest/Jasmine test for a
+ * jscodeshift transform.
+ * @param  {String} dirName          contains the name of the directory the test is located in. This
+ *                                   should normally be passed via __dirname.
+ * @param  {String} transformName    contains the filename of the transform being tested,
+ *                                   excluding the .js extension.
+ * @param  {String} [testFilePrefix] Optionally contains the name of the file with the test
+ *                                   data. If not specified, it defaults to the same value as `transformName`.
+ *                                   This will be suffixed with ".input.js" for the input file and ".output.js"
+ *                                   for the expected output. For example, if set to "foo", we will read the
+ *                                   "foo.input.js" file, pass this to the transform, and expect its output to
+ *                                   be equal to the contents of "foo.output.js".
+ * @param  {any} transformObject     Object to be transformed with the transformations
+ * @param  {String} action init, update or remove, decides how to format the AST
+ * @return {Void} Jest makes sure to execute the globally defined functions
+ */
+function defineTest(
+	dirName,
+	transformName,
+	testFilePrefix,
+	transformObject,
+	action
+) {
+	const testName = testFilePrefix
+		? `transforms correctly using "${testFilePrefix}" data`
+		: "transforms correctly";
+	describe(transformName, () => {
+		it(testName, () => {
+			const output = runSingleTansform(
+				dirName,
+				transformName,
+				testFilePrefix,
+				transformObject,
+				action
+			);
+			expect(output).toMatchSnapshot();
+		});
+	});
+}
+module.exports = defineTest;
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_modify-config-helper.js.html b/docs/utils_modify-config-helper.js.html new file mode 100644 index 00000000000..b76f669884c --- /dev/null +++ b/docs/utils_modify-config-helper.js.html @@ -0,0 +1,91 @@ + + + + + JSDoc: Source: utils/modify-config-helper.js + + + + + + + + + + +
+ +

Source: utils/modify-config-helper.js

+ + + + + + +
+
+
"use strict";
+
+const fs = require("fs");
+const path = require("path");
+const yeoman = require("yeoman-environment");
+const runTransform = require("../init/transformations/index");
+
+/**
+ *
+ * Looks up the webpack.config in the user's path and runs a given
+ * generator scaffold followed up by a transform
+ *
+ * @param {String} action — action to be done (add, remove, update, init)
+ * @param {Class} name - Name for the given function
+ * @returns {Function} runTransform - Returns a transformation instance
+ */
+
+module.exports = function modifyHelperUtil(action, generator) {
+	const configPath = path.resolve(process.cwd(), "webpack.config.js");
+	const webpackConfigExists = fs.existsSync(configPath);
+	if (!webpackConfigExists) {
+		throw new Error(
+			"Couldn't find a webpack configuration in your project path"
+		);
+	}
+	const env = yeoman.createEnv("webpack", null);
+	const generatorName = `webpack-${action}-generator`;
+	env.registerStub(generator, generatorName);
+
+	env.run(generatorName).on("end", () => {
+		const config = Object.assign(
+			{
+				configFile: fs.readFileSync(configPath, "utf8"),
+				configPath: configPath
+			},
+			env.getArgument("configuration")
+		);
+		return runTransform(config, action);
+	});
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_npm-exists.js.html b/docs/utils_npm-exists.js.html new file mode 100644 index 00000000000..64432abb9b7 --- /dev/null +++ b/docs/utils_npm-exists.js.html @@ -0,0 +1,74 @@ + + + + + JSDoc: Source: utils/npm-exists.js + + + + + + + + + + +
+ +

Source: utils/npm-exists.js

+ + + + + + +
+
+
"use strict";
+
+const got = require("got");
+const constant = value => () => value;
+
+/**
+ *
+ * Checks if the given dependency/module is registered on npm
+ *
+ * @param {String} moduleName - The dependency to be checked
+ * @returns {Promise} constant - Returns either true or false,
+ * based on if it exists or not
+ */
+
+module.exports = function npmExists(moduleName) {
+	const hostname = "https://www.npmjs.org";
+	const pkgUrl = `${hostname}/package/${moduleName}`;
+	return got(pkgUrl, {
+		method: "HEAD"
+	})
+		.then(constant(true))
+		.catch(constant(false));
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_npm-packages-exists.js.html b/docs/utils_npm-packages-exists.js.html new file mode 100644 index 00000000000..964905a9e37 --- /dev/null +++ b/docs/utils_npm-packages-exists.js.html @@ -0,0 +1,97 @@ + + + + + JSDoc: Source: utils/npm-packages-exists.js + + + + + + + + + + +
+ +

Source: utils/npm-packages-exists.js

+ + + + + + +
+
+
"use strict";
+const chalk = require("chalk");
+const npmExists = require("./npm-exists");
+const resolvePackages = require("./resolve-packages");
+
+/**
+*
+* Loops through an array and checks if a package is registered
+* on npm and throws an error if it is not.
+*
+* @param {String[]} pkg - Array of packages to check existence of
+* @returns {Array} resolvePackages - Returns an process to install the packages
+*/
+
+module.exports = function npmPackagesExists(pkg) {
+	let acceptedPackages = [];
+	pkg.forEach(addon => {
+		//eslint-disable-next-line
+		if (addon.length <= 14 || addon.slice(0, 14) !== "webpack-addons") {
+			throw new TypeError(
+				chalk.bold(`${addon} isn't a valid name.\n`) +
+					chalk.red(
+						"\nIt should be prefixed with 'webpack-addons', but have different suffix.\n"
+					)
+			);
+		}
+		npmExists(addon)
+			.then(moduleExists => {
+				if (!moduleExists) {
+					Error.stackTraceLimit = 0;
+					throw new TypeError("Package isn't registered on npm.");
+				}
+				if (moduleExists) {
+					acceptedPackages.push(addon);
+				}
+			})
+			.catch(err => {
+				console.error(err.stack || err);
+				process.exit(0);
+			})
+			.then(() => {
+				if (acceptedPackages.length === pkg.length)
+					return resolvePackages(acceptedPackages);
+			});
+	});
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_package-manager.js.html b/docs/utils_package-manager.js.html new file mode 100644 index 00000000000..8121fdd2d45 --- /dev/null +++ b/docs/utils_package-manager.js.html @@ -0,0 +1,128 @@ + + + + + JSDoc: Source: utils/package-manager.js + + + + + + + + + + +
+ +

Source: utils/package-manager.js

+ + + + + + +
+
+
"use strict";
+
+const path = require("path");
+const fs = require("fs");
+const spawn = require("cross-spawn");
+const globalPath = require("global-modules");
+
+const SPAWN_FUNCTIONS = {
+	npm: spawnNPM,
+	yarn: spawnYarn
+};
+
+/**
+ *
+ * Spawns a new process using npm
+ *
+ * @param {String} pkg - The dependency to be installed
+ * @param {Boolean} isNew - indicates if it needs to be updated or installed
+ * @returns {Function} spawn - Installs the package
+ */
+
+function spawnNPM(pkg, isNew) {
+	return spawn.sync("npm", [isNew ? "install" : "update", "-g", pkg], {
+		stdio: "inherit"
+	});
+}
+
+/**
+ *
+ * Spawns a new process using yarn
+ *
+ * @param {String} pkg - The dependency to be installed
+ * @param {Boolean} isNew - indicates if it needs to be updated or installed
+ * @returns {Function} spawn - Installs the package
+ */
+
+function spawnYarn(pkg, isNew) {
+	return spawn.sync("yarn", ["global", isNew ? "add" : "upgrade", pkg], {
+		stdio: "inherit"
+	});
+}
+/**
+ *
+ * Spawns a new process that installs the addon/dependency
+ *
+ * @param {String} pkg - The dependency to be installed
+ * @returns {Function} spawn - Installs the package
+ */
+
+function spawnChild(pkg) {
+	const pkgPath = path.resolve(globalPath, pkg);
+	const packageManager = getPackageManager();
+	const isNew = !fs.existsSync(pkgPath);
+
+	return SPAWN_FUNCTIONS[packageManager](pkg, isNew);
+}
+
+/**
+ *
+ * Returns the name of package manager to use,
+ * preferring yarn over npm if available
+ *
+ * @returns {String} - The package manager name
+ */
+
+function getPackageManager() {
+	if (spawn.sync("yarn", [" --version"], { stdio: "ignore" }).error) {
+		return "npm";
+	}
+
+	return "yarn";
+}
+
+module.exports = {
+	getPackageManager,
+	spawnChild
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_prop-types.js.html b/docs/utils_prop-types.js.html new file mode 100644 index 00000000000..08efec772c8 --- /dev/null +++ b/docs/utils_prop-types.js.html @@ -0,0 +1,85 @@ + + + + + JSDoc: Source: utils/prop-types.js + + + + + + + + + + +
+ +

Source: utils/prop-types.js

+ + + + + + +
+
+
/**
+ *
+ * A Set of all accepted properties
+ *
+ * @returns {Set} A new set with accepted webpack properties
+ */
+
+module.exports = new Set([
+	"context",
+	"devServer",
+	"devtool",
+	"entry",
+	"externals",
+	"module",
+	"node",
+	"output",
+	"performance",
+	"plugins",
+	"resolve",
+	"target",
+	"watch",
+	"watchOptions",
+	"stats",
+	"mode",
+	"amd",
+	"bail",
+	"cache",
+	"profile",
+	"merge",
+	"parallelism",
+	"recordsInputPath",
+	"recordsOutputPath",
+	"recordsPath"
+]);
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_resolve-packages.js.html b/docs/utils_resolve-packages.js.html new file mode 100644 index 00000000000..0629e090a4e --- /dev/null +++ b/docs/utils_resolve-packages.js.html @@ -0,0 +1,119 @@ + + + + + JSDoc: Source: utils/resolve-packages.js + + + + + + + + + + +
+ +

Source: utils/resolve-packages.js

+ + + + + + +
+
+
"use strict";
+
+const path = require("path");
+const chalk = require("chalk");
+const globalPath = require("global-modules");
+
+const creator = require("../init/index").creator;
+
+const spawnChild = require("./package-manager").spawnChild;
+
+/**
+ *
+ * Attaches a promise to the installation of the package
+ *
+ * @param {Function} child - The function to attach a promise to
+ * @returns {Promise} promise - Returns a promise to the installation
+ */
+
+function processPromise(child) {
+	return new Promise(function(resolve, reject) {
+		//eslint-disable-line
+		if (child.status !== 0) {
+			reject();
+		} else {
+			resolve();
+		}
+	});
+}
+
+/**
+ *
+ * Resolves and installs the packages, later sending them to @creator
+ *
+ * @param {String[]} pkg - The dependencies to be installed
+ * @returns {Function|Error} creator - Builds
+ * a webpack configuration through yeoman or throws an error
+ */
+
+module.exports = function resolvePackages(pkg) {
+	Error.stackTraceLimit = 30;
+
+	let packageLocations = [];
+
+	pkg.forEach(addon => {
+		processPromise(spawnChild(addon))
+			.then(() => {
+				try {
+					packageLocations.push(path.resolve(globalPath, addon));
+				} catch (err) {
+					console.log("Package wasn't validated correctly..");
+					console.log("Submit an issue for", pkg, "if this persists");
+					console.log("\nReason: \n");
+					console.error(chalk.bold.red(err));
+					process.exitCode = 1;
+				}
+			})
+			.catch(err => {
+				console.log("Package Coudln't be installed, aborting..");
+				console.log("\nReason: \n");
+				console.error(chalk.bold.red(err));
+				process.exitCode = 1;
+			})
+			.then(() => {
+				if (packageLocations.length === pkg.length)
+					return creator(packageLocations);
+			});
+	});
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/docs/utils_run-prettier.js.html b/docs/utils_run-prettier.js.html new file mode 100644 index 00000000000..89d9e909b81 --- /dev/null +++ b/docs/utils_run-prettier.js.html @@ -0,0 +1,95 @@ + + + + + JSDoc: Source: utils/run-prettier.js + + + + + + + + + + +
+ +

Source: utils/run-prettier.js

+ + + + + + +
+
+
"use strict";
+
+const prettier = require("prettier");
+const fs = require("fs");
+const chalk = require("chalk");
+
+/**
+ *
+ * Runs prettier and later prints the output configuration
+ *
+ * @param {String} outputPath - Path to write the config to
+ * @param {Node} source - AST to write at the given path
+ * @param {Function} cb - exectues a callback after execution if supplied
+ * @returns {Function} Writes a file at given location and prints messages accordingly
+ */
+
+module.exports = function runPrettier(outputPath, source, cb) {
+	function validateConfig() {
+		let prettySource;
+		let error;
+		try {
+			prettySource = prettier.format(source, {
+				singleQuote: true,
+				useTabs: true,
+				tabWidth: 1
+			});
+		} catch (err) {
+			process.stdout.write(
+				"\n" +
+					chalk.yellow(
+						`WARNING: Could not apply prettier to ${outputPath}` +
+							" due validation error, but the file has been created\n"
+					)
+			);
+			prettySource = source;
+			error = err;
+		}
+		if (cb) {
+			return cb(error);
+		}
+		return fs.writeFileSync(outputPath, prettySource, "utf8");
+	}
+	return fs.writeFile(outputPath, source, "utf8", validateConfig);
+};
+
+
+
+ + + + +
+ + + +
+ +
+ Documentation generated by JSDoc 3.5.5 on Mon Dec 18 2017 13:12:38 GMT+0100 (CET) +
+ + + + + diff --git a/jsdoc.json b/jsdoc.json new file mode 100644 index 00000000000..3cd052cecfd --- /dev/null +++ b/jsdoc.json @@ -0,0 +1,10 @@ + +{ + "source": { + "include": [ + "dist/" + ], + "includePattern": "dist/.+\\.js$", + "excludePattern": "dist/migrate/.+\\.js$" + } +} diff --git a/lib/commands/add.js b/lib/commands/add.js index 6f7a73109c7..4d66abeb7f8 100644 --- a/lib/commands/add.js +++ b/lib/commands/add.js @@ -3,6 +3,14 @@ const defaultGenerator = require("../generators/add-generator"); const modifyHelper = require("../utils/modify-config-helper"); -module.exports = function() { +/** + * Is called and returns a scaffolding instance, adding properties + * + * @returns {Function} modifyHelper - A helper function that uses the action + * we're given on a generator + * + */ + +module.exports = function add() { return modifyHelper("add", defaultGenerator); }; diff --git a/lib/commands/init.js b/lib/commands/init.js index 7e63644d510..e3748d5dc85 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -3,16 +3,15 @@ const npmPackagesExists = require("../utils/npm-packages-exists"); const creator = require("../init/index").creator; -/* -* @function initializeInquirer -* -* First function to be called after running the init flag. This is a check, -* if we are running the init command with no arguments or if we got dependencies -* -* @param { Object } pkg - packages included when running the init command -* @returns { } creator|npmPackagesExists - returns an installation of the package, -* followed up with a yeoman instance of that if there's packages. If not, it creates a defaultGenerator -*/ +/** + * + * First function to be called after running the init flag. This is a check, + * if we are running the init command with no arguments or if we got dependencies + * + * @param {Object} pkg - packages included when running the init command + * @returns {Function} creator/npmPackagesExists - returns an installation of the package, + * followed up with a yeoman instance of that if there's packages. If not, it creates a defaultGenerator + */ module.exports = function initializeInquirer(pkg) { if (pkg.length === 0) { diff --git a/lib/commands/migrate.js b/lib/commands/migrate.js index 1b51c50fbfd..33adb6aa830 100644 --- a/lib/commands/migrate.js +++ b/lib/commands/migrate.js @@ -9,7 +9,20 @@ const Listr = require("listr"); const runPrettier = require("../utils/run-prettier"); -module.exports = function transformFile( +/** +* +* Runs migration on a given configuration using AST's and promises +* to sequentially transform a configuration file. +* +* @param {String} currentConfigPath - Location of the configuration to be migrated +* @param {String} outputConfigPath - Location to where the configuration should be written +* @param {Object} options - Any additional options regarding code style of the written configuration + +* @returns {Promise} Runs the migration using a promise that will throw any errors during each transform +* or output if the user decides to abort the migration +*/ + +module.exports = function migrate( currentConfigPath, outputConfigPath, options diff --git a/lib/commands/remove.js b/lib/commands/remove.js index 858869dffff..2b1b73607a6 100644 --- a/lib/commands/remove.js +++ b/lib/commands/remove.js @@ -3,6 +3,14 @@ const defaultGenerator = require("../generators/remove-generator"); const modifyHelper = require("../utils/modify-config-helper"); +/** + * Is called and returns a scaffolding instance, removing properties + * + * @returns {Function} modifyHelper - A helper function that uses the action + * we're given on a generator + * + */ + module.exports = function() { return modifyHelper("remove", defaultGenerator); }; diff --git a/lib/commands/update.js b/lib/commands/update.js index a45b4b3893a..598cf7f13de 100644 --- a/lib/commands/update.js +++ b/lib/commands/update.js @@ -3,6 +3,14 @@ const defaultGenerator = require("../generators/update-generator"); const modifyHelper = require("../utils/modify-config-helper"); +/** + * Is called and returns a scaffolding instance, updating properties + * + * @returns {Function} modifyHelper - A helper function that uses the action + * we're given on a generator + * + */ + module.exports = function() { return modifyHelper("update", defaultGenerator); }; diff --git a/lib/generators/add-generator.js b/lib/generators/add-generator.js index ae58b6d3a9e..72fe424417c 100644 --- a/lib/generators/add-generator.js +++ b/lib/generators/add-generator.js @@ -10,12 +10,32 @@ const PROP_TYPES = require("../utils/prop-types"); const getPackageManager = require("../utils/package-manager").getPackageManager; const npmExists = require("../utils/npm-exists"); -// https://gist.github.com/efenacigiray/9367920 +/** + * + * Replaces the string with a substring at the given index + * https://gist.github.com/efenacigiray/9367920 + * + * @param {String} string - 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(string, index, replace) { return string.substring(0, index) + replace + string.substring(index + 1); } -// Finds if an array has a given prop +/** + * + * Checks if the given array has a given property + * + * @param {Array} arr - array to check + * @param {String} prop - property to check existence of + * + * @returns {Boolean} hasProp - Boolean indicating if the property + * is present + */ const traverseAndGetProperties = (arr, prop) => { let hasProp = false; arr.forEach(p => { @@ -26,6 +46,15 @@ const traverseAndGetProperties = (arr, prop) => { return hasProp; }; +/** + * + * Generator for adding properties + * @class AddGenerator + * @extends Generator + * @returns {Void} After execution, transforms are triggered + * + */ + module.exports = class AddGenerator extends Generator { constructor(args, opts) { super(args, opts); diff --git a/lib/generators/init-generator.js b/lib/generators/init-generator.js index b7d50f8f397..5375ee13a59 100644 --- a/lib/generators/init-generator.js +++ b/lib/generators/init-generator.js @@ -18,7 +18,16 @@ const getBabelPlugin = require("./utils/module"); const getDefaultPlugins = require("./utils/plugins"); const tooltip = require("./utils/tooltip"); -module.exports = class WebpackGenerator extends Generator { +/** + * + * Generator for initializing a webpack config + * + * @class InitGenerator + * @extends Generator + * @returns {Void} After execution, transforms are triggered + * + */ +module.exports = class InitGenerator extends Generator { constructor(args, opts) { super(args, opts); this.isProd = false; diff --git a/lib/generators/utils/entry.js b/lib/generators/utils/entry.js index 027499c9610..f9756014bde 100644 --- a/lib/generators/utils/entry.js +++ b/lib/generators/utils/entry.js @@ -3,6 +3,15 @@ const InputValidate = require("webpack-addons").InputValidate; const validate = require("./validate"); +/** + * + * Prompts for entry points, either if it has multiple or one entry + * + * @param {Object} self - A variable holding the instance of the prompting + * @param {Object} answer - Previous answer from asking if the user wants single or multiple entries + * @returns {Object} An Object that holds the answers given by the user, later used to scaffold + */ + module.exports = (self, answer) => { let entryIdentifiers; let result; diff --git a/lib/generators/utils/module.js b/lib/generators/utils/module.js index 7b44b7e156b..43b706960af 100644 --- a/lib/generators/utils/module.js +++ b/lib/generators/utils/module.js @@ -1,3 +1,11 @@ +"use strict"; + +/** + * + * Returns an module.rule object that has the babel loader if invoked + * + * @returns {Function} A callable function that adds the babel-loader with env preset + */ module.exports = () => { return { test: new RegExp(/\.js$/), diff --git a/lib/generators/utils/plugins.js b/lib/generators/utils/plugins.js index bcd523ad462..288002c2459 100644 --- a/lib/generators/utils/plugins.js +++ b/lib/generators/utils/plugins.js @@ -1,3 +1,13 @@ +"use strict"; + +/** + * + * Callable function with the initial plugins + * + * @returns {Function} An function that returns an array + * that consists of the uglify plugin + */ + module.exports = () => { return ["new UglifyJSPlugin()"]; }; diff --git a/lib/generators/utils/tooltip.js b/lib/generators/utils/tooltip.js index 97bf748a009..2ffcccf3343 100644 --- a/lib/generators/utils/tooltip.js +++ b/lib/generators/utils/tooltip.js @@ -1,3 +1,12 @@ +"use strict"; +/** + * + * Tooltip object that consits of tooltips for various of + * features + * + * @returns {Object} An Object that consists of tooltip methods to be invoked + */ + module.exports = { uglify: () => { return `/* diff --git a/lib/generators/utils/validate.js b/lib/generators/utils/validate.js index 9f8f932f7e8..e6d71a0cc6c 100644 --- a/lib/generators/utils/validate.js +++ b/lib/generators/utils/validate.js @@ -1,5 +1,13 @@ "use strict"; +/** + * + * Validates an input to check if an input is provided + * + * @param {String} value - The input string to validate + * @returns {String | Boolean } Returns truthy if its long enough + * Or a string if the user hasn't written anything + */ module.exports = value => { const pass = value.length; if (pass) { diff --git a/lib/index.js b/lib/index.js index 2a64f867bcc..5923ec0d9be 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,17 +2,16 @@ const path = require("path"); -/* -* @function initialize -* -* First function to be called after running a flag. This is a check, -* to match the flag with the respective require. -* -* @param { String } command - which feature to use -* @param { Object } args - arguments from the CLI -* @returns { Module } returns the module with the command -* -*/ +/** + * + * First function to be called after running a flag. This is a check, + * to match the flag with the respective require. + * + * @param {String} command - which feature to use + * @param {Object} args - arguments from the CLI + * @returns {Function} invokes the module with the supplied command + * + */ module.exports = function initialize(command, args) { const popArgs = args.slice(2).pop(); diff --git a/lib/init/index.js b/lib/init/index.js index 0a9df56d2f7..a3daf4681f9 100644 --- a/lib/init/index.js +++ b/lib/init/index.js @@ -6,15 +6,15 @@ const path = require("path"); const defaultGenerator = require("../generators/init-generator"); const runTransform = require("./transformations/index"); -/* -* @function creator -* -* Runs yeoman and runs the transformations based on the object -* built up from an author/user -* -* @param { String } options - An path to the given generator -* @returns { Function } runTransform - Run transformations based on yeoman prompt -*/ +/** + * + * Runs yeoman and runs the transformations based on the object + * built up from an author/user + * + * @param {String} options - An path to the given generator + * @returns {Function} runTransform - Run transformations based on the finished + * yeoman instance + */ function creator(options) { let env = yeoman.createEnv("webpack", null); diff --git a/lib/init/transformations/context/context.js b/lib/init/transformations/context/context.js index 3c83cc6ae7a..5b4128f9bc8 100644 --- a/lib/init/transformations/context/context.js +++ b/lib/init/transformations/context/context.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for context. Finds the context property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for context. Finds the context property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function contextTransform(j, ast, webpackProperties, action) { if (webpackProperties) { diff --git a/lib/init/transformations/devServer/devServer.js b/lib/init/transformations/devServer/devServer.js index 001e6940c5d..2ebfdcee408 100644 --- a/lib/init/transformations/devServer/devServer.js +++ b/lib/init/transformations/devServer/devServer.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for devServer. Finds the devServer property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for devServer. Finds the devServer property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function devServerTransform( j, diff --git a/lib/init/transformations/devtool/devtool.js b/lib/init/transformations/devtool/devtool.js index e9759d7f251..05bea8ae4c5 100644 --- a/lib/init/transformations/devtool/devtool.js +++ b/lib/init/transformations/devtool/devtool.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for devtool. Finds the devtool property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for devtool. Finds the devtool property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function devToolTransform(j, ast, webpackProperties, action) { if (webpackProperties || typeof webpackProperties === "boolean") { diff --git a/lib/init/transformations/entry/entry.js b/lib/init/transformations/entry/entry.js index 9652934b68a..184229179e9 100644 --- a/lib/init/transformations/entry/entry.js +++ b/lib/init/transformations/entry/entry.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for entry. Finds the entry property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for entry. Finds the entry property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function entryTransform(j, ast, webpackProperties, action) { function createEntryProperty(p) { diff --git a/lib/init/transformations/externals/externals.js b/lib/init/transformations/externals/externals.js index 508d7eebb60..ebc903bc272 100644 --- a/lib/init/transformations/externals/externals.js +++ b/lib/init/transformations/externals/externals.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for externals. Finds the externals property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for externals. Finds the externals property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function externalsTransform( j, diff --git a/lib/init/transformations/index.js b/lib/init/transformations/index.js index 73da909f0da..d3326e5616d 100644 --- a/lib/init/transformations/index.js +++ b/lib/init/transformations/index.js @@ -34,15 +34,15 @@ const topScopeTransform = require("./top-scope/top-scope"); const devServerTransform = require("./devServer/devServer"); const modeTransform = require("./mode/mode"); -/* -* @function runTransform -* -* Runs the transformations from an object we get from yeoman -* -* @param { Object } transformObject - Options to transform -* @returns { } - A promise that writes each transform, runs prettier -* and writes the file -*/ +/** + * + * Runs the transformations from an object we get from yeoman + * + * @param {Object} webpackProperties - Configuration to transform + * @param {String} action - Action to be done on the given ast + * @returns {Promise} - A promise that writes each transform, runs prettier + * and writes the file + */ const transformsObject = { entryTransform, diff --git a/lib/init/transformations/mode/mode.js b/lib/init/transformations/mode/mode.js index e86fa9bd64b..3c92d2880f6 100644 --- a/lib/init/transformations/mode/mode.js +++ b/lib/init/transformations/mode/mode.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for mode. Finds the mode property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for mode. Finds the mode property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function modeTransform(j, ast, webpackProperties, action) { if (webpackProperties) { diff --git a/lib/init/transformations/module/module.js b/lib/init/transformations/module/module.js index 0e311908208..0c7abb32749 100644 --- a/lib/init/transformations/module/module.js +++ b/lib/init/transformations/module/module.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for module. Finds the module property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for module. Finds the module property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function(j, ast, webpackProperties, action) { function createModuleProperties(p) { diff --git a/lib/init/transformations/node/node.js b/lib/init/transformations/node/node.js index 6f5a820a287..e78961d6e34 100644 --- a/lib/init/transformations/node/node.js +++ b/lib/init/transformations/node/node.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for node. Finds the node property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for node. Finds the node property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function nodeTransform(j, ast, webpackProperties, action) { function createNodeProperty(p) { diff --git a/lib/init/transformations/other/amd.js b/lib/init/transformations/other/amd.js index dbc278dec20..d606eba7eb3 100644 --- a/lib/init/transformations/other/amd.js +++ b/lib/init/transformations/other/amd.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for amd. Finds the amd property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for amd. Finds the amd property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function amdTransform(j, ast, webpackProperties, action) { function createAmdProperty(p) { diff --git a/lib/init/transformations/other/bail.js b/lib/init/transformations/other/bail.js index 5d4db06d737..474300f057e 100644 --- a/lib/init/transformations/other/bail.js +++ b/lib/init/transformations/other/bail.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for bail. Finds the bail property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for bail. Finds the bail property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function bailTransform(j, ast, webpackProperties, action) { if (webpackProperties || typeof webpackProperties === "boolean") { diff --git a/lib/init/transformations/other/cache.js b/lib/init/transformations/other/cache.js index 645af35c7f7..7c808ee88ff 100644 --- a/lib/init/transformations/other/cache.js +++ b/lib/init/transformations/other/cache.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for cache. Finds the cache property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for cache. Finds the cache property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function cacheTransform(j, ast, webpackProperties, action) { function createCacheProperty(p) { diff --git a/lib/init/transformations/other/merge.js b/lib/init/transformations/other/merge.js index 6d93cdbd9b8..f77c77882a8 100644 --- a/lib/init/transformations/other/merge.js +++ b/lib/init/transformations/other/merge.js @@ -1,15 +1,16 @@ "use strict"; -/* -* -* Transform for merge. Finds the merge property from yeoman and creates a way -* for users to allow webpack-merge in their scaffold -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for merge. Finds the merge property from yeoman and creates a way + * for users to allow webpack-merge in their scaffold + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function(j, ast, webpackProperties, action) { function createMergeProperty(p) { diff --git a/lib/init/transformations/other/parallelism.js b/lib/init/transformations/other/parallelism.js index d288af153f9..6cbe456f11d 100644 --- a/lib/init/transformations/other/parallelism.js +++ b/lib/init/transformations/other/parallelism.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for parallelism. Finds the parallelism property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for parallelism. Finds the parallelism property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function parallelismTransform( j, diff --git a/lib/init/transformations/other/profile.js b/lib/init/transformations/other/profile.js index b2a4bc72536..a1454ff015b 100644 --- a/lib/init/transformations/other/profile.js +++ b/lib/init/transformations/other/profile.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for profile. Finds the profile property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for profile. Finds the profile property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function profileTransform(j, ast, webpackProperties, action) { function createProfileProperty(p) { diff --git a/lib/init/transformations/other/recordsInputPath.js b/lib/init/transformations/other/recordsInputPath.js index 15de524f24e..757d46bdb27 100644 --- a/lib/init/transformations/other/recordsInputPath.js +++ b/lib/init/transformations/other/recordsInputPath.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for recordsInputPath. Finds the recordsInputPath property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for recordsInputPath. Finds the recordsInputPath property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function recordsInputPathTransform( j, diff --git a/lib/init/transformations/other/recordsOutputPath.js b/lib/init/transformations/other/recordsOutputPath.js index 6f692a563fe..565c9021907 100644 --- a/lib/init/transformations/other/recordsOutputPath.js +++ b/lib/init/transformations/other/recordsOutputPath.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for recordsOutputPath. Finds the recordsOutputPath property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for recordsOutputPath. Finds the recordsOutputPath property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function recordsOutputPathTransform( j, diff --git a/lib/init/transformations/other/recordsPath.js b/lib/init/transformations/other/recordsPath.js index 7da8d4a0a84..d9d3720a7b9 100644 --- a/lib/init/transformations/other/recordsPath.js +++ b/lib/init/transformations/other/recordsPath.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for recordsPath. Finds the recordsPath property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for recordsPath. Finds the recordsPath property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function recordsPathTransform( j, diff --git a/lib/init/transformations/output/output.js b/lib/init/transformations/output/output.js index 268984e6ebd..0772f837684 100644 --- a/lib/init/transformations/output/output.js +++ b/lib/init/transformations/output/output.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for output. Finds the output property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for output. Finds the output property from yeoman and creates a + * property based on what the user has given us. + * + * @param {any} j — jscodeshift API + * @param {any} ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns {ast} - jscodeshift API + */ module.exports = function outputTransform(j, ast, webpackProperties, action) { function createOutputProperties(p) { utils.pushCreateProperty(j, p, "output", j.objectExpression([])); diff --git a/lib/init/transformations/performance/performance.js b/lib/init/transformations/performance/performance.js index 051b917a3f8..c84accdd034 100644 --- a/lib/init/transformations/performance/performance.js +++ b/lib/init/transformations/performance/performance.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for performance. Finds the performance property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for performance. Finds the performance property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function performanceTransform( j, diff --git a/lib/init/transformations/plugins/plugins.js b/lib/init/transformations/plugins/plugins.js index e35b827cf3c..15a10b6b3a4 100644 --- a/lib/init/transformations/plugins/plugins.js +++ b/lib/init/transformations/plugins/plugins.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for plugins. Finds the plugins property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for plugins. Finds the plugins property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function(j, ast, webpackProperties, action) { function createPluginsProperty(p) { diff --git a/lib/init/transformations/resolve/resolve.js b/lib/init/transformations/resolve/resolve.js index 7f570268f6c..c20ebe52539 100644 --- a/lib/init/transformations/resolve/resolve.js +++ b/lib/init/transformations/resolve/resolve.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for resolve. Finds the resolve property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for resolve. Finds the resolve property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function resolveTransform(j, ast, webpackProperties, action) { function createResolveProperties(p) { diff --git a/lib/init/transformations/stats/stats.js b/lib/init/transformations/stats/stats.js index d70dd53ed6b..679db8b5063 100644 --- a/lib/init/transformations/stats/stats.js +++ b/lib/init/transformations/stats/stats.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for stats. Finds the stats property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for stats. Finds the stats property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function statsTransform(j, ast, webpackProperties, action) { function createStatsProperty(p) { diff --git a/lib/init/transformations/target/target.js b/lib/init/transformations/target/target.js index 0533086dd30..a0314ceacbf 100644 --- a/lib/init/transformations/target/target.js +++ b/lib/init/transformations/target/target.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for target. Finds the target property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for target. Finds the target property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function targetTransform(j, ast, webpackProperties, action) { if (webpackProperties && webpackProperties.length) { diff --git a/lib/init/transformations/top-scope/top-scope.js b/lib/init/transformations/top-scope/top-scope.js index 6de089cc415..b897484157f 100644 --- a/lib/init/transformations/top-scope/top-scope.js +++ b/lib/init/transformations/top-scope/top-scope.js @@ -1,13 +1,14 @@ -/* -* -* Get an property named topScope from yeoman and inject it to the top scope of -* the config, outside module.exports -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing topscope properties -* @returns ast - jscodeshift API -*/ +/** + * + * Get an property named topScope from yeoman and inject it to the top scope of + * the config, outside module.exports + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function(j, ast, webpackProperties, action) { function createTopScopeProperty(p) { diff --git a/lib/init/transformations/watch/watch.js b/lib/init/transformations/watch/watch.js index ba0e66d2c21..bc70ec1d67b 100644 --- a/lib/init/transformations/watch/watch.js +++ b/lib/init/transformations/watch/watch.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for watch. Finds the watch property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for watch. Finds the watch property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function(j, ast, webpackProperties, action) { if (typeof webpackProperties === "boolean" && action === "init") { diff --git a/lib/init/transformations/watch/watchOptions.js b/lib/init/transformations/watch/watchOptions.js index 96d42e4d1af..c417ae10f4c 100644 --- a/lib/init/transformations/watch/watchOptions.js +++ b/lib/init/transformations/watch/watchOptions.js @@ -2,16 +2,17 @@ const utils = require("../../../utils/ast-utils"); -/* -* -* Transform for watchOptions. Finds the watchOptions property from yeoman and creates a -* property based on what the user has given us. -* -* @param j — jscodeshift API -* @param ast - jscodeshift API -* @param { Object } webpackProperties - Object containing transformation rules -* @returns ast - jscodeshift API -*/ +/** + * + * Transform for watchOptions. Finds the watchOptions property from yeoman and creates a + * property based on what the user has given us. + * + * @param j — jscodeshift API + * @param ast - jscodeshift API + * @param {any} webpackProperties - transformation object to scaffold + * @param {String} action - action that indicates what to be done to the AST + * @returns ast - jscodeshift API + */ module.exports = function(j, ast, webpackProperties, action) { function createWatchOptionsProperty(p) { diff --git a/lib/utils/ast-utils.js b/lib/utils/ast-utils.js index 346d9ce91d0..f01303ed132 100644 --- a/lib/utils/ast-utils.js +++ b/lib/utils/ast-utils.js @@ -51,16 +51,17 @@ function pathsToMemberExpression(j: Ijscodeshit, paths: string[]) { } } -/* -* @function findPluginsByName -* -* Find paths that match `new name.space.PluginName()` for a given array of plugin names -* -* @param j — jscodeshift API -* @param { Node } node - Node to start search from -* @param { Array } pluginNamesArray - Array of plugin names like `webpack.LoaderOptionsPlugin` -* @returns Path - * */ +/** + * + * Find paths that match `new name.space.PluginName()` for a + * given array of plugin names + * + * @param {any} j — jscodeshift API + * @param {Node} node - Node to start search from + * @param {String[]} pluginNamesArray - Array of plugin names like `webpack.LoaderOptionsPlugin` + * @returns {Node} Node that has the pluginName + */ + function findPluginsByName( j: Ijscodeshit, node: IPath<*>, @@ -74,16 +75,16 @@ function findPluginsByName( }); } -/* - * @function findRootNodesByName +/** * * Finds the path to the `name: []` node * - * @param j — jscodeshift API - * @param { Node } node - Node to start search from - * @param { String } propName - property to search for - * @returns Path - * */ + * @param {any} j — jscodeshift API + * @param {Node} node - Node to start search from + * @param {String} propName - property to search for + * @returns {Node} found node and + */ + function findRootNodesByName( j: Ijscodeshit, node: IPath<*>, @@ -92,16 +93,16 @@ function findRootNodesByName( return node.find(j.Property, { key: { name: propName } }); } -/* - * @function createProperty +/** * * Creates an Object's property with a given key and value * - * @param j — jscodeshift API - * @param { string | number } key - Property key - * @param { string | number | boolean } value - Property value - * @returns Node - * */ + * @param {any} j — jscodeshift API + * @param {String | Number} key - Property key + * @param {String | Number | Boolean} value - Property value + * @returns {Node} + */ + function createProperty( j: Ijscodeshit, key: string | number, @@ -114,15 +115,14 @@ function createProperty( ); } -/* - * @function createLiteral +/** * * Creates an appropriate literal property * - * @param j — jscodeshift API - * @param { string | boolean | number } val - * @returns { Node } - * */ + * @param {any} j — jscodeshift API + * @param {String | Boolean | Number} val + * @returns {Node} + */ function createLiteral( j: Ijscodeshit, @@ -141,15 +141,14 @@ function createLiteral( return j.literal(literalVal); } -/* - * @function createIdentifierOrLiteral +/** * * Creates an appropriate identifier or literal property * - * @param j — jscodeshift API - * @param { string | boolean | number } val - * @returns { Node } - * */ + * @param {any} j — jscodeshift API + * @param {String | Boolean | Number} val + * @returns {Node} + */ function createIdentifierOrLiteral(j: Ijscodeshit, val: any): any { // IPath | IPath doesn't work, find another way @@ -182,18 +181,19 @@ function createIdentifierOrLiteral(j: Ijscodeshit, val: any): any { } return j.literal(literalVal); } -/* - * @function createOrUpdatePluginByName + +/** * * Findes or creates a node for a given plugin name string with options object * If plugin decalaration already exist, options are merged. * - * @param j — jscodeshift API - * @param { NodePath } rooNodePath - `plugins: []` NodePath where plugin should be added. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths - * @param { string } pluginName - ex. `webpack.LoaderOptionsPlugin` - * @param { Object } options - plugin options - * @returns void - * */ + * @param {any} j — jscodeshift API + * @param {Node} rootNodePath - `plugins: []` NodePath where plugin should be added. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths + * @param {String} pluginName - ex. `webpack.LoaderOptionsPlugin` + * @param {Object} options - plugin options + * @returns {Void} + */ + function createOrUpdatePluginByName( j: Ijscodeshit, rootNodePath: IPath<*>, @@ -258,16 +258,15 @@ function createOrUpdatePluginByName( } } -/* - * @function findVariableToPlugin +/** * * Finds the variable to which a third party plugin is assigned to * - * @param j — jscodeshift API - * @param { Node } rootNode - `plugins: []` Root Node. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths - * @param { string } pluginPackageName - ex. `extract-text-plugin` - * @returns { string } variable name - ex. 'var s = require(s) gives "s"` - * */ + * @param {any} j — jscodeshift API + * @param {Node} rootNode - `plugins: []` Root Node. See https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths + * @param {String} pluginPackageName - ex. `extract-text-plugin` + * @returns {String} variable name - ex. 'var s = require(s) gives "s"` + */ function findVariableToPlugin( j: Ijscodeshit, @@ -282,14 +281,13 @@ function findVariableToPlugin( return moduleVarNames.pop().id.name; } -/* -* @function isType -* -* Returns true if type is given type -* @param { Node} path - pathNode -* @param { string } type - node type -* @returns {boolean} -*/ +/** + * + * Returns true if type is given type + * @param {Node} path - pathNode + * @param {String} type - node type + * @returns {Boolean} + */ function isType(path: IPath<*>, type: string): boolean { return path.type === type; @@ -302,15 +300,14 @@ function findObjWithOneOfKeys(p: IPath<*>, keyNames: string[]): boolean { }, false); } -/* -* @function getRequire -* -* Returns constructed require symbol -* @param j — jscodeshift API -* @param { string } constName - Name of require -* @param { string } packagePath - path of required package -* @returns {NodePath} - the created ast -*/ +/** + * + * Returns constructed require symbol + * @param {any} j — jscodeshift API + * @param {String} constName - Name of require + * @param {String} packagePath - path of required package + * @returns {Node} - the created ast + */ function getRequire( j: Ijscodeshit, @@ -325,16 +322,15 @@ function getRequire( ]); } -/* -* @function checkIfExistsAndAddValue -* -* If a prop exists, it overrides it, else it creates a new one -* @param j — jscodeshift API -* @param { Node } node - objectexpression to check -* @param { string } key - Key of the property -* @param { string } value - computed value of the property -* @returns - nothing -*/ +/** + * + * If a prop exists, it overrides it, else it creates a new one + * @param {any} j — jscodeshift API + * @param {Node} node - objectexpression to check + * @param {String} key - Key of the property + * @param {String} value - computed value of the property + * @returns {Void} + */ function checkIfExistsAndAddValue( j: Ijscodeshit, @@ -355,14 +351,13 @@ function checkIfExistsAndAddValue( } } -/* -* @function createEmptyArrayProperty -* -* Creates an empty array -* @param j — jscodeshift API -* @param { String } key - st name -* @returns - { Array } arr - An empty array -*/ +/** + * + * Creates an empty array + * @param {any} j — jscodeshift API + * @param {String} key - array name + * @returns {Array} arr - An empty array + */ function createEmptyArrayProperty( j: Ijscodeshit, key: string @@ -370,16 +365,16 @@ function createEmptyArrayProperty( return j.property("init", j.identifier(key), j.arrayExpression([])); } -/* -* @function createArrayWithChildren -* -* Creates an array and iterates on an object with properties -* @param j — jscodeshift API -* @param { String } key - object name -* @param { string } subProps - computed value of the property -* @param { Boolean } shouldDropKeys - -* @returns - { Array } arr - An array with the object properties -*/ +/** + * + * Creates an array and iterates on an object with properties + * + * @param {any} j — jscodeshift API + * @param {String} key - object name + * @param {String} subProps - computed value of the property + * @param {Boolean} shouldDropKeys - bool to ask to use obj.keys or not + * @returns {Array} arr - An array with the object properties + */ function createArrayWithChildren( j: Ijscodeshit, @@ -410,16 +405,15 @@ function createArrayWithChildren( return arr; } -/* -* @function loopThroughObjects -* -* Loops through an object and adds property to an object with no identifier -* @param j — jscodeshift API -* @param { Node } p - node to add value to -* @param { Object } obj - Object to loop through -* @returns - { Function|Node } - Either pushes the node, or reruns until -* nothing is left -*/ +/** + * + * Loops through an object and adds property to an object with no identifier + * @param {any} j — jscodeshift API + * @param {Node} p - node to add value to + * @param {Object} obj - Object to loop through + * @returns {Function | Node} - Either pushes the node, or reruns until + * nothing is left + */ function loopThroughObjects( j: Ijscodeshit, @@ -460,15 +454,15 @@ function loopThroughObjects( }); } -/* -* @function createObjectWithSuppliedProperty -* -* Creates an object with an supplied property as parameter -* @param j — jscodeshift API -* @param { String } key - object name -* @param { Node } prop - property to be added -* @returns - { Node } - An property with the supplied property -*/ +/** + * + * Creates an object with an supplied property as parameter + * + * @param {any} j — jscodeshift API + * @param {String} key - object name + * @param {Node} prop - property to be added + * @returns {Node} - An property with the supplied property + */ function createObjectWithSuppliedProperty( j: Ijscodeshit, @@ -478,30 +472,29 @@ function createObjectWithSuppliedProperty( return j.property("init", j.identifier(key), prop); } -/* -* @function createExternalRegExp -* -* Finds a regexp property with an already parsed AST from the user -* @param j — jscodeshift API -* @param { String } prop - property to find the value at -* @returns - { Node } - A literal node with the found regexp -*/ +/** + * + * Finds a regexp property with an already parsed AST from the user + * @param {any} j — jscodeshift API + * @param {String} prop - property to find the value at + * @returns {Node} - A literal node with the found regexp + */ function createExternalRegExp(j: Ijscodeshit, prop: any): IPath { let regExpProp = prop.__paths[0].value.program.body[0].expression; return j.literal(regExpProp.value); } -/* -* @function pushCreateProperty -* -* Creates a property and pushes the value to a node -* @param j — jscodeshift API -* @param { Node } p - Node to push against -* @param { String } key - key used as identifier -* @param { String } val - property value -* @returns - { Node } - Returns node the pushed property -*/ +/** + * + * Creates a property and pushes the value to a node + * + * @param {any} j — jscodeshift API + * @param {Node} p - Node to push against + * @param {String} key - key used as identifier + * @param {String} val - property value + * @returns {Node} - Returns node the pushed property + */ function pushCreateProperty( j: Ijscodeshit, @@ -520,16 +513,15 @@ function pushCreateProperty( ); } -/* -* @function pushObjectKeys -* -* @param j — jscodeshift API -* @param { Node } p - path to push -* @param { Object } webpackProperties - The object to loop over -* @param { String } name - Key that will be the identifier we find and add values to -* @returns - { Node/Function } Returns a function that will push a node if -*subProperty is an array, else it will invoke a function that will push a single node -*/ +/** + * + * @param {any} j — jscodeshift API + * @param {Node} p - path to push + * @param {Object} webpackProperties - The object to loop over + * @param {String} name - Key that will be the identifier we find and add values to + * @returns {Node | Function} Returns a function that will push a node if + * subProperty is an array, else it will invoke a function that will push a single node + */ function pushObjectKeys( j: Ijscodeshit, @@ -577,20 +569,20 @@ function pushObjectKeys( }); } -/* -* @function isAssignment -* -* Checks if we are at the correct node and later invokes a callback -* for the transforms to either use their own transform function or -* use pushCreateProperty if the transform doesn't expect any properties -* @param j — jscodeshift API -* @param { Node } p - Node to push against -* @param { Function } cb - callback to be invoked -* @param { String } identifier - key to use as property -* @param { Object } property - WebpackOptions that later will be converted via -* pushCreateProperty via WebpackOptions[identifier] -* @returns - { Function } cb - Returns the callback and pushes a new node -*/ +/** + * + * Checks if we are at the correct node and later invokes a callback + * for the transforms to either use their own transform function or + * use pushCreateProperty if the transform doesn't expect any properties + * + * @param {any} j — jscodeshift API + * @param {Node} p - Node to push against + * @param {Function} cb - callback to be invoked + * @param {String} identifier - key to use as property + * @param {Object} property - WebpackOptions that later will be converted via + * pushCreateProperty via WebpackOptions[identifier] + * @returns {Function} cb - Returns the callback and pushes a new node + */ function isAssignment( j: Ijscodeshit, @@ -608,15 +600,14 @@ function isAssignment( } } -/* -* @function createEmptyCallableFunctionWithArguments -* -* Creates a function call with arguments -* @param j — jscodeshift API -* @param name: Name for the given function -* @returns - { Function } Node - Returns the node for the created -* function -*/ +/** + * + * Creates a function call with arguments + * @param {any} j — jscodeshift API + * @param {String} name - Name for the given function + * @returns {Node} - Returns the node for the created + * function + */ function createEmptyCallableFunctionWithArguments( j: Ijscodeshit, diff --git a/lib/utils/defineTest.js b/lib/utils/defineTest.js index 39796961b1f..7a35efcbb48 100644 --- a/lib/utils/defineTest.js +++ b/lib/utils/defineTest.js @@ -25,7 +25,7 @@ const path = require("path"); * be equal to the contents of "foo.output.js". * @param {Object|Boolean|String} initOptions TBD * @param {String} action init, update or remove, decides how to format the AST - * @return {TBD} TBD + * @return {Function} Function that fires of the transforms */ function runSingleTansform( dirName, @@ -75,11 +75,17 @@ function runSingleTansform( * for the expected output. For example, if set to "foo", we will read the * "foo.input.js" file, pass this to the transform, and expect its output to * be equal to the contents of "foo.output.js". - * @param {TBD} type TBD + * @param {any} transformObject Object to be transformed with the transformations * @param {String} action init, update or remove, decides how to format the AST - * @return {TBD} TBD + * @return {Void} Jest makes sure to execute the globally defined functions */ -function defineTest(dirName, transformName, testFilePrefix, type, action) { +function defineTest( + dirName, + transformName, + testFilePrefix, + transformObject, + action +) { const testName = testFilePrefix ? `transforms correctly using "${testFilePrefix}" data` : "transforms correctly"; @@ -89,7 +95,7 @@ function defineTest(dirName, transformName, testFilePrefix, type, action) { dirName, transformName, testFilePrefix, - type, + transformObject, action ); expect(output).toMatchSnapshot(); diff --git a/lib/utils/modify-config-helper.js b/lib/utils/modify-config-helper.js index 4804c4284f2..cf2f8b81dfa 100644 --- a/lib/utils/modify-config-helper.js +++ b/lib/utils/modify-config-helper.js @@ -5,7 +5,17 @@ const path = require("path"); const yeoman = require("yeoman-environment"); const runTransform = require("../init/transformations/index"); -module.exports = function(action, generator) { +/** + * + * Looks up the webpack.config in the user's path and runs a given + * generator scaffold followed up by a transform + * + * @param {String} action — action to be done (add, remove, update, init) + * @param {Class} name - Name for the given function + * @returns {Function} runTransform - Returns a transformation instance + */ + +module.exports = function modifyHelperUtil(action, generator) { const configPath = path.resolve(process.cwd(), "webpack.config.js"); const webpackConfigExists = fs.existsSync(configPath); if (!webpackConfigExists) { diff --git a/lib/utils/npm-exists.js b/lib/utils/npm-exists.js index 96bc56bf665..8a26ba394ff 100644 --- a/lib/utils/npm-exists.js +++ b/lib/utils/npm-exists.js @@ -3,15 +3,14 @@ const got = require("got"); const constant = value => () => value; -/* -* @function npmExists -* -* Checks if the given dependency/module is registered on npm -* -* @param { String } moduleName - The dependency to be checked -* @returns { } constant - Returns either true or false, -* based on if it exists or not -*/ +/** + * + * Checks if the given dependency/module is registered on npm + * + * @param {String} moduleName - The dependency to be checked + * @returns {Promise} constant - Returns either true or false, + * based on if it exists or not + */ module.exports = function npmExists(moduleName) { const hostname = "https://www.npmjs.org"; diff --git a/lib/utils/npm-packages-exists.js b/lib/utils/npm-packages-exists.js index 0307ec63784..dd52953768b 100644 --- a/lib/utils/npm-packages-exists.js +++ b/lib/utils/npm-packages-exists.js @@ -3,15 +3,14 @@ const chalk = require("chalk"); const npmExists = require("./npm-exists"); const resolvePackages = require("./resolve-packages"); -/* -* @function npmPackagesExists -* -* Loops through an array and checks if a package is registered -* on npm and throws an error if it is not. -* -* @param { Array } pkg - Array of packages to check existence of -* @returns { Array } resolvePackages - Returns an process to install the packages -*/ +/** + * + * Loops through an array and checks if a package is registered + * on npm and throws an error if it is not. + * + * @param {String[]} pkg - Array of packages to check existence of + * @returns {Array} resolvePackages - Returns an process to install the packages + */ module.exports = function npmPackagesExists(pkg) { let acceptedPackages = []; diff --git a/lib/utils/package-manager.js b/lib/utils/package-manager.js index 57e335dfb8b..4f2fead6d56 100644 --- a/lib/utils/package-manager.js +++ b/lib/utils/package-manager.js @@ -10,25 +10,42 @@ const SPAWN_FUNCTIONS = { yarn: spawnYarn }; +/** + * + * Spawns a new process using npm + * + * @param {String} pkg - The dependency to be installed + * @param {Boolean} isNew - indicates if it needs to be updated or installed + * @returns {Function} spawn - Installs the package + */ + function spawnNPM(pkg, isNew) { return spawn.sync("npm", [isNew ? "install" : "update", "-g", pkg], { stdio: "inherit" }); } +/** + * + * Spawns a new process using yarn + * + * @param {String} pkg - The dependency to be installed + * @param {Boolean} isNew - indicates if it needs to be updated or installed + * @returns {Function} spawn - Installs the package + */ + function spawnYarn(pkg, isNew) { return spawn.sync("yarn", ["global", isNew ? "add" : "upgrade", pkg], { stdio: "inherit" }); } -/* -* @function spawnChild -* -* Spawns a new process that installs the addon/dependency -* -* @param { String } pkg - The dependency to be installed -* @returns { } spawn - Installs the package -*/ +/** + * + * Spawns a new process that installs the addon/dependency + * + * @param {String} pkg - The dependency to be installed + * @returns {Function} spawn - Installs the package + */ function spawnChild(pkg) { const pkgPath = path.resolve(globalPath, pkg); @@ -38,14 +55,13 @@ function spawnChild(pkg) { return SPAWN_FUNCTIONS[packageManager](pkg, isNew); } -/* -* @function getPackageManager -* -* Returns the name of package manager to use, -* preferring yarn over npm if available -* -* @returns { String } - The package manager name -*/ +/** + * + * Returns the name of package manager to use, + * preferring yarn over npm if available + * + * @returns {String} - The package manager name + */ function getPackageManager() { if (spawn.sync("yarn", [" --version"], { stdio: "ignore" }).error) { diff --git a/lib/utils/prop-types.js b/lib/utils/prop-types.js index 8fe34e139cf..ceac7567f59 100644 --- a/lib/utils/prop-types.js +++ b/lib/utils/prop-types.js @@ -1,3 +1,10 @@ +/** + * + * A Set of all accepted properties + * + * @returns {Set} A new set with accepted webpack properties + */ + module.exports = new Set([ "context", "devServer", diff --git a/lib/utils/resolve-packages.js b/lib/utils/resolve-packages.js index 35bd2f564c1..a38db2947ee 100644 --- a/lib/utils/resolve-packages.js +++ b/lib/utils/resolve-packages.js @@ -8,14 +8,13 @@ const creator = require("../init/index").creator; const spawnChild = require("./package-manager").spawnChild; -/* -* @function processPromise -* -* Attaches a promise to the installation of the package -* -* @param { Function } child - The function to attach a promise to -* @returns { } promise - Returns a promise to the installation -*/ +/** + * + * Attaches a promise to the installation of the package + * + * @param {Function} child - The function to attach a promise to + * @returns {Promise} promise - Returns a promise to the installation + */ function processPromise(child) { return new Promise(function(resolve, reject) { @@ -28,15 +27,14 @@ function processPromise(child) { }); } -/* -* @function resolvePackages -* -* Resolves and installs the packages, later sending them to @creator -* -* @param { Array } pkg - The dependencies to be installed -* @returns { } creator - Builds -* a webpack configuration through yeoman or throws an error -*/ +/** + * + * Resolves and installs the packages, later sending them to @creator + * + * @param {String[]} pkg - The dependencies to be installed + * @returns {Function|Error} creator - Builds + * a webpack configuration through yeoman or throws an error + */ module.exports = function resolvePackages(pkg) { Error.stackTraceLimit = 30; diff --git a/lib/utils/run-prettier.js b/lib/utils/run-prettier.js index d3aaddaaf25..3b9600cb875 100644 --- a/lib/utils/run-prettier.js +++ b/lib/utils/run-prettier.js @@ -4,14 +4,15 @@ const prettier = require("prettier"); const fs = require("fs"); const chalk = require("chalk"); -/* -* -* Runs prettier and later prints the output configuration -* -* @param { String } outputPath - Path to write the config to -* @param { Node } source - AST to write at the given path -* @returns fs - Writes a file at given location and prints messages accordingly -*/ +/** + * + * Runs prettier and later prints the output configuration + * + * @param {String} outputPath - Path to write the config to + * @param {Node} source - AST to write at the given path + * @param {Function} cb - exectues a callback after execution if supplied + * @returns {Function} Writes a file at given location and prints messages accordingly + */ module.exports = function runPrettier(outputPath, source, cb) { function validateConfig() { diff --git a/package.json b/package.json index 096c7e409a1..6919e0d3644 100644 --- a/package.json +++ b/package.json @@ -16,14 +16,15 @@ "node": ">=4.0.0" }, "scripts": { - "lint": "eslint \"**/*.js\"", + "lint": "./node_modules/eslint/bin/eslint.js \"**/*.js\"", "format": "prettier-eslint \"bin/**/**/*.js\" --write && prettier-eslint \"lib/**/**/*.js\" --write && prettier-eslint \"test/**/**/*.js\" --write", "format:dist": "prettier-eslint \"dist/**/**/*.js\" --write", "lint:codeOnly": "eslint \"{lib,bin}/**/!(__testfixtures__)/*.js\" \"{lib,bin}/**.js\"", "precommit": "lint-staged", "prepare": "flow-remove-types lib/ -d dist/ && yarn format:dist", "pretest": "yarn lint", - "test": "jest --coverage" + "test": "jest --coverage", + "jsdoc": "jsdoc -c jsdoc.json -r -d docs" }, "lint-staged": { "{lib,bin}/**/!(__testfixtures__)/**.js": [ @@ -82,6 +83,7 @@ "husky": "^0.14.3", "jest": "^21.2.1", "jest-cli": "^21.2.1", + "jsdoc": "^3.5.5", "lint-staged": "^4.1.3", "prettier-eslint-cli": "^4.6.1" }, diff --git a/test/BinTestCases.test.js b/test/BinTestCases.test.js index a173d998b80..36048d6de04 100644 --- a/test/BinTestCases.test.js +++ b/test/BinTestCases.test.js @@ -6,35 +6,54 @@ const fs = require("fs"); const child_process = require("child_process"); function spawn(args, options) { - if(process.env.running_under_istanbul) { - args = ["--no-deprecation", require.resolve("istanbul/lib/cli.js"), "cover", "--report", "none", "--print", "none", "--include-pid", "--dir", path.resolve("coverage"), "--", require.resolve("webpack/test/helpers/exec-in-directory.js"), options.cwd].concat(args); + if (process.env.running_under_istanbul) { + args = [ + "--no-deprecation", + require.resolve("istanbul/lib/cli.js"), + "cover", + "--report", + "none", + "--print", + "none", + "--include-pid", + "--dir", + path.resolve("coverage"), + "--", + require.resolve("webpack/test/helpers/exec-in-directory.js"), + options.cwd + ].concat(args); options = Object.assign({}, options, { cwd: undefined }); } - return child_process.spawn(process.execPath, ["--no-deprecation"].concat(args), options); + return child_process.spawn( + process.execPath, + ["--no-deprecation"].concat(args), + options + ); } function loadOptsFile(optsPath) { // Options file parser from Mocha // https://github.com/mochajs/mocha/blob/2bb2b9fa35818db7a02e5068364b0c417436b1af/bin/options.js#L25-L31 - return fs.readFileSync(optsPath, "utf8") + return fs + .readFileSync(optsPath, "utf8") .replace(/\\\s/g, "%20") .split(/\s/) .filter(Boolean) - .map((value) => value.replace(/%20/g, " ")); + .map(value => value.replace(/%20/g, " ")); } function getTestSpecificArguments(testDirectory) { try { return loadOptsFile(path.join(testDirectory, "test.opts")); - } catch(e) { + } catch (e) { return null; } } function convertToArrayOfLines(outputArray) { - if(outputArray.length === 0) return outputArray; + if (outputArray.length === 0) return outputArray; return outputArray.join("").split("\n"); } @@ -48,7 +67,9 @@ function findTestsRecursive(readPath) { const result = isAnyTests ? [readPath] : []; - return result.concat(folders.map(findTestsRecursive).reduce((acc, list) => acc.concat(list), [])); + return result.concat( + folders.map(findTestsRecursive).reduce((acc, list) => acc.concat(list), []) + ); } const casesPath = path.join(__dirname, "binCases"); @@ -61,7 +82,10 @@ describe("BinTestCases", function() { const testName = testDirectory.replace(casesPath, ""); const testArgs = getTestSpecificArguments(testDirectory) || defaultArgs; const testAssertions = require(path.join(testDirectory, "stdin.js")); - const outputPath = path.join(path.resolve(casesPath, "../js/bin"), testName); + const outputPath = path.join( + path.resolve(casesPath, "../js/bin"), + testName + ); const cmd = `${path.resolve(process.cwd(), "bin/webpack.js")}`; const args = testArgs.concat(["--output-path", `${outputPath}`]); @@ -77,30 +101,30 @@ describe("BinTestCases", function() { error: [] }; - if(asyncExists) { + if (asyncExists) { describe(testName, function() { it("should run successfully", function(done) { jest.setTimeout(10000); const child = spawn([cmd].concat(args), opts); - child.on("close", (code) => { + child.on("close", code => { env.code = code; }); - child.on("error", (error) => { + child.on("error", error => { env.error.push(error); }); - child.stdout.on("data", (data) => { + child.stdout.on("data", data => { env.stdout.push(data); }); - child.stderr.on("data", (data) => { + child.stderr.on("data", data => { env.stderr.push(data); }); setTimeout(() => { - if(env.code) { + if (env.code) { done(`Watch didn't run ${env.error}`); } @@ -118,20 +142,20 @@ describe("BinTestCases", function() { const child = spawn([cmd].concat(args), opts); - child.on("close", (code) => { + child.on("close", code => { env.code = code; done(); }); - child.on("error", (error) => { + child.on("error", error => { env.error.push(error); }); - child.stdout.on("data", (data) => { + child.stdout.on("data", data => { env.stdout.push(data); }); - child.stderr.on("data", (data) => { + child.stderr.on("data", data => { env.stderr.push(data); }); }); diff --git a/test/binCases/config-name/found-many/stdin.js b/test/binCases/config-name/found-many/stdin.js index e625f7bdaae..809d2b0ca08 100644 --- a/test/binCases/config-name/found-many/stdin.js +++ b/test/binCases/config-name/found-many/stdin.js @@ -3,7 +3,7 @@ module.exports = function testAssertions(code, stdout, stderr) { expect(code).toBe(0); expect(stdout).toEqual(expect.anything()); - expect(stdout[7]).toContain('./index2.js'); - expect(stdout[13]).toContain('./index3.js'); + expect(stdout[7]).toContain("./index2.js"); + expect(stdout[13]).toContain("./index3.js"); expect(stderr).toHaveLength(0); }; diff --git a/test/binCases/env/complex/index.js b/test/binCases/env/complex/index.js index cde7d6391de..0d24e266fe2 100644 --- a/test/binCases/env/complex/index.js +++ b/test/binCases/env/complex/index.js @@ -1 +1 @@ -module.exports = "index"; \ No newline at end of file +module.exports = "index"; diff --git a/test/binCases/errors/issue-5576/stdin.js b/test/binCases/errors/issue-5576/stdin.js index 0175fec7931..b211d95a820 100644 --- a/test/binCases/errors/issue-5576/stdin.js +++ b/test/binCases/errors/issue-5576/stdin.js @@ -5,9 +5,7 @@ module.exports = function testAssertions(code, stdout, stderr) { expect(stdout[0]).toContain("Hash: "); expect(stdout[1]).toContain("Version: "); expect(stdout[2]).toContain("Time: "); - expect(stdout[4]).toContain( - "bundle.js" - ); + expect(stdout[4]).toContain("bundle.js"); expect(stderr).toHaveLength(0); }; diff --git a/test/js/bin/errors/parse/null.js b/test/js/bin/errors/parse/null.js index d927afa6234..f4ccbaf3fab 100644 --- a/test/js/bin/errors/parse/null.js +++ b/test/js/bin/errors/parse/null.js @@ -1,73 +1,86 @@ -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports) { +/******/ (function(modules) { + // webpackBootstrap + /******/ // The module cache + /******/ var installedModules = {}; // The require function + /******/ + /******/ /******/ function __webpack_require__(moduleId) { + /******/ + /******/ // Check if module is in cache + /******/ if (installedModules[moduleId]) { + /******/ return installedModules[moduleId].exports; + /******/ + } // Create a new module (and put it into the cache) + /******/ /******/ var module = (installedModules[moduleId] = { + /******/ i: moduleId, + /******/ l: false, + /******/ exports: {} + /******/ + }); // Execute the module function + /******/ + /******/ /******/ modules[moduleId].call( + module.exports, + module, + module.exports, + __webpack_require__ + ); // Flag the module as loaded + /******/ + /******/ /******/ module.l = true; // Return the exports of the module + /******/ + /******/ /******/ return module.exports; + /******/ + } // expose the modules object (__webpack_modules__) + /******/ + /******/ + /******/ /******/ __webpack_require__.m = modules; // expose the module cache + /******/ + /******/ /******/ __webpack_require__.c = installedModules; // define getter function for harmony exports + /******/ + /******/ /******/ __webpack_require__.d = function(exports, name, getter) { + /******/ if (!__webpack_require__.o(exports, name)) { + /******/ Object.defineProperty(exports, name, { + /******/ configurable: false, + /******/ enumerable: true, + /******/ get: getter + /******/ + }); + /******/ + } + /******/ + }; // getDefaultExport function for compatibility with non-harmony modules + /******/ + /******/ /******/ __webpack_require__.n = function(module) { + /******/ var getter = + module && module.__esModule + ? /******/ function getDefault() { + return module["default"]; + } + : /******/ function getModuleExports() { + return module; + }; + /******/ __webpack_require__.d(getter, "a", getter); + /******/ return getter; + /******/ + }; // Object.prototype.hasOwnProperty.call + /******/ + /******/ /******/ __webpack_require__.o = function(object, property) { + return Object.prototype.hasOwnProperty.call(object, property); + }; // __webpack_public_path__ + /******/ + /******/ /******/ __webpack_require__.p = ""; // Load entry module and return exports + /******/ + /******/ /******/ return __webpack_require__((__webpack_require__.s = 0)); + /******/ +})( + /************************************************************************/ + /******/ [ + /* 0 */ + /***/ function(module, exports) { + throw new Error( + "Module parse failed: Unexpected token (1:0)\nYou may need an appropriate loader to handle this file type.\n| }\n| " + ); -throw new Error("Module parse failed: Unexpected token (1:0)\nYou may need an appropriate loader to handle this file type.\n| }\n| "); - -/***/ }) -/******/ ]); \ No newline at end of file + /***/ + } + /******/ + ] +); diff --git a/yarn.lock b/yarn.lock index c32038da84b..20a941f44d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -969,6 +969,10 @@ babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.23.0, babel-types@^6.24 lodash "^4.17.4" to-fast-properties "^1.0.3" +babylon@7.0.0-beta.19: + version "7.0.0-beta.19" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.19.tgz#e928c7e807e970e0536b078ab3e0c48f9e052503" + babylon@^6.15.0, babylon@^6.17.0, babylon@^6.17.3, babylon@^6.18.0: version "6.18.0" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" @@ -1009,7 +1013,7 @@ block-stream@*: dependencies: inherits "~2.0.0" -bluebird@^3.5.0: +bluebird@^3.5.0, bluebird@~3.5.0: version "3.5.1" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9" @@ -1254,6 +1258,12 @@ caseless@~0.12.0: version "0.12.0" resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" +catharsis@~0.8.9: + version "0.8.9" + resolved "https://registry.yarnpkg.com/catharsis/-/catharsis-0.8.9.tgz#98cc890ca652dd2ef0e70b37925310ff9e90fc8b" + dependencies: + underscore-contrib "~0.3.0" + center-align@^0.1.1: version "0.1.3" resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad" @@ -1938,7 +1948,7 @@ escape-html@~1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" -escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: +escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5, escape-string-regexp@~1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -2626,7 +2636,7 @@ got@^7.0.0, got@^7.1.0: url-parse-lax "^1.0.0" url-to-options "^1.0.1" -graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4: +graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.9: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" @@ -3513,6 +3523,12 @@ js-yaml@^3.4.3, js-yaml@^3.7.0, js-yaml@^3.9.1: argparse "^1.0.7" esprima "^4.0.0" +js2xmlparser@~3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/js2xmlparser/-/js2xmlparser-3.0.0.tgz#3fb60eaa089c5440f9319f51760ccd07e2499733" + dependencies: + xmlcreate "^1.0.1" + jsbn@~0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" @@ -3537,6 +3553,23 @@ jscodeshift@^0.4.0: temp "^0.8.1" write-file-atomic "^1.2.0" +jsdoc@^3.5.5: + version "3.5.5" + resolved "https://registry.yarnpkg.com/jsdoc/-/jsdoc-3.5.5.tgz#484521b126e81904d632ff83ec9aaa096708fa4d" + dependencies: + babylon "7.0.0-beta.19" + bluebird "~3.5.0" + catharsis "~0.8.9" + escape-string-regexp "~1.0.5" + js2xmlparser "~3.0.0" + klaw "~2.0.0" + marked "~0.3.6" + mkdirp "~0.5.1" + requizzle "~0.2.1" + strip-json-comments "~2.0.1" + taffydb "2.6.2" + underscore "~1.8.3" + jsdom@^9.12.0: version "9.12.0" resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.12.0.tgz#e8c546fffcb06c00d4833ca84410fed7f8a097d4" @@ -3628,6 +3661,12 @@ kind-of@^4.0.0: dependencies: is-buffer "^1.1.5" +klaw@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/klaw/-/klaw-2.0.0.tgz#59c128e0dc5ce410201151194eeb9cbf858650f6" + dependencies: + graceful-fs "^4.1.9" + lazy-cache@^1.0.3: version "1.0.4" resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" @@ -3854,6 +3893,10 @@ map-obj@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-2.0.0.tgz#a65cd29087a92598b8791257a523e021222ac1f9" +marked@~0.3.6: + version "0.3.7" + resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.7.tgz#80ef3bbf1bd00d1c9cfebe42ba1b8c85da258d0d" + md5.js@^1.3.4: version "1.3.4" resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.4.tgz#e9bdbde94a20a5ac18b04340fc5764d5b09d901d" @@ -4038,7 +4081,7 @@ mississippi@^1.3.0: stream-each "^1.1.0" through2 "^2.0.0" -mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0: +mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" dependencies: @@ -5011,6 +5054,12 @@ requires-port@1.0.x, requires-port@1.x.x, requires-port@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" +requizzle@~0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/requizzle/-/requizzle-0.2.1.tgz#6943c3530c4d9a7e46f1cddd51c158fc670cdbde" + dependencies: + underscore "~1.6.0" + reserved-words@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/reserved-words/-/reserved-words-0.1.2.tgz#00a0940f98cd501aeaaac316411d9adc52b31ab1" @@ -5578,6 +5627,10 @@ table@^4.0.1: slice-ansi "1.0.0" string-width "^2.1.1" +taffydb@2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/taffydb/-/taffydb-2.6.2.tgz#7cbcb64b5a141b6a2efc2c5d2c67b4e150b2a268" + tapable@^0.2.7: version "0.2.8" resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22" @@ -5786,10 +5839,20 @@ uid-number@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81" -underscore@~1.6.0: +underscore-contrib@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/underscore-contrib/-/underscore-contrib-0.3.0.tgz#665b66c24783f8fa2b18c9f8cbb0e2c7d48c26c7" + dependencies: + underscore "1.6.0" + +underscore@1.6.0, underscore@~1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8" +underscore@~1.8.3: + version "1.8.3" + resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022" + unique-filename@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/unique-filename/-/unique-filename-1.1.0.tgz#d05f2fe4032560871f30e93cbe735eea201514f3" @@ -6155,6 +6218,10 @@ xml-name-validator@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-2.0.1.tgz#4d8b8f1eccd3419aa362061becef515e1e559635" +xmlcreate@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/xmlcreate/-/xmlcreate-1.0.2.tgz#fa6bf762a60a413fb3dd8f4b03c5b269238d308f" + xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.0, xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"