Skip to content

Commit b2c2bbd

Browse files
committed
cli(pkgs): re-add entries
1 parent b02070d commit b2c2bbd

File tree

19 files changed

+9167
-25314
lines changed

19 files changed

+9167
-25314
lines changed

package-lock.json

Lines changed: 3885 additions & 3885 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/add/package-lock.json

Lines changed: 0 additions & 17459 deletions
This file was deleted.

packages/generate-loader/package-lock.json

Lines changed: 319 additions & 313 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/generate-plugin/package-lock.json

Lines changed: 319 additions & 313 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/generators/package-lock.json

Lines changed: 1312 additions & 1324 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/info/package-lock.json

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/init/index.js

Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,25 @@
11
"use strict";
22

3-
const path = require("path");
4-
const j = require("jscodeshift");
5-
const chalk = require("chalk");
6-
const pEachSeries = require("p-each-series");
7-
8-
const runPrettier = require("@webpack-cli/utils/run-prettier");
9-
const astTransform = require("@webpack-cli/utils/recursive-parser");
10-
const propTypes = require("@webpack-cli/utils/prop-types");
11-
12-
/**
13-
*
14-
* Maps back transforms that needs to be run using the configuration
15-
* provided.
16-
*
17-
* @param {Object} transformObject - An Object with all transformations
18-
* @param {Object} config - Configuration to transform
19-
* @returns {Object} - An Object with the transformations to be run
20-
*/
21-
22-
function mapOptionsToTransform(config) {
23-
return Object.keys(config.webpackOptions).filter(k => propTypes.has(k));
24-
}
3+
const npmPackagesExists = require("@webpack-cli/utils/npm-packages-exists");
4+
const defaultGenerator = require("@webpack-cli/utils/generators/init-generator");
5+
const modifyHelper = require("@webpack-cli/utils/modify-config-helper");
256

267
/**
278
*
28-
* Runs the transformations from an object we get from yeoman
9+
* First function to be called after running the init flag. This is a check,
10+
* if we are running the init command with no arguments or if we got dependencies
2911
*
30-
* @param {Object} webpackProperties - Configuration to transform
31-
* @param {String} action - Action to be done on the given ast
32-
* @returns {Promise} - A promise that writes each transform, runs prettier
33-
* and writes the file
12+
* @param {Array} args - array of arguments such as
13+
* packages included when running the init command
14+
* @returns {Function} creator/npmPackagesExists - returns an installation of the package,
15+
* followed up with a yeoman instance of that if there's packages. If not, it creates a defaultGenerator
3416
*/
3517

36-
module.exports = function runTransform(webpackProperties, action) {
37-
// webpackOptions.name sent to nameTransform if match
38-
const webpackConfig = Object.keys(webpackProperties).filter(p => {
39-
return p !== "configFile" && p !== "configPath";
40-
});
41-
const initActionNotDefined = action && action !== "init" ? true : false;
42-
43-
webpackConfig.forEach(scaffoldPiece => {
44-
const config = webpackProperties[scaffoldPiece];
45-
const transformations = mapOptionsToTransform(config);
46-
const ast = j(
47-
initActionNotDefined
48-
? webpackProperties.configFile
49-
: "module.exports = {}"
50-
);
51-
const transformAction = action || null;
52-
53-
return pEachSeries(transformations, f => {
54-
return astTransform(j, ast, config.webpackOptions[f], transformAction, f);
55-
})
56-
.then(_ => {
57-
let configurationName;
58-
if (!config.configName) {
59-
configurationName = "webpack.config.js";
60-
} else {
61-
configurationName = "webpack." + config.configName + ".js";
62-
}
63-
64-
const outputPath = initActionNotDefined
65-
? webpackProperties.configPath
66-
: path.join(process.cwd(), configurationName);
67-
const source = ast.toSource({
68-
quote: "single"
69-
});
18+
module.exports = function initializeInquirer(...args) {
19+
const packages = args.slice(3);
7020

71-
runPrettier(outputPath, source);
72-
})
73-
.catch(err => {
74-
console.error(err.message ? err.message : err);
75-
});
76-
});
77-
if (initActionNotDefined && webpackProperties.config.item) {
78-
process.stdout.write(
79-
"\n" +
80-
chalk.green(
81-
`Congratulations! ${
82-
webpackProperties.config.item
83-
} has been ${action}ed!\n`
84-
)
85-
);
86-
} else {
87-
process.stdout.write(
88-
"\n" +
89-
chalk.green(
90-
"Congratulations! Your new webpack configuration file has been created!\n"
91-
)
92-
);
21+
if (packages.length === 0) {
22+
return modifyHelper("init", defaultGenerator);
9323
}
24+
return npmPackagesExists(packages);
9425
};

packages/init/init.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"use strict";
2+
3+
const path = require("path");
4+
const j = require("jscodeshift");
5+
const chalk = require("chalk");
6+
const pEachSeries = require("p-each-series");
7+
8+
const runPrettier = require("@webpack-cli/utils/run-prettier");
9+
const astTransform = require("@webpack-cli/utils/recursive-parser");
10+
const propTypes = require("@webpack-cli/utils/prop-types");
11+
12+
/**
13+
*
14+
* Maps back transforms that needs to be run using the configuration
15+
* provided.
16+
*
17+
* @param {Object} transformObject - An Object with all transformations
18+
* @param {Object} config - Configuration to transform
19+
* @returns {Object} - An Object with the transformations to be run
20+
*/
21+
22+
function mapOptionsToTransform(config) {
23+
return Object.keys(config.webpackOptions).filter(k => propTypes.has(k));
24+
}
25+
26+
/**
27+
*
28+
* Runs the transformations from an object we get from yeoman
29+
*
30+
* @param {Object} webpackProperties - Configuration to transform
31+
* @param {String} action - Action to be done on the given ast
32+
* @returns {Promise} - A promise that writes each transform, runs prettier
33+
* and writes the file
34+
*/
35+
36+
module.exports = function runTransform(webpackProperties, action) {
37+
// webpackOptions.name sent to nameTransform if match
38+
const webpackConfig = Object.keys(webpackProperties).filter(p => {
39+
return p !== "configFile" && p !== "configPath";
40+
});
41+
const initActionNotDefined = action && action !== "init" ? true : false;
42+
43+
webpackConfig.forEach(scaffoldPiece => {
44+
const config = webpackProperties[scaffoldPiece];
45+
const transformations = mapOptionsToTransform(config);
46+
const ast = j(
47+
initActionNotDefined
48+
? webpackProperties.configFile
49+
: "module.exports = {}"
50+
);
51+
const transformAction = action || null;
52+
53+
return pEachSeries(transformations, f => {
54+
return astTransform(j, ast, config.webpackOptions[f], transformAction, f);
55+
})
56+
.then(_ => {
57+
let configurationName;
58+
if (!config.configName) {
59+
configurationName = "webpack.config.js";
60+
} else {
61+
configurationName = "webpack." + config.configName + ".js";
62+
}
63+
64+
const outputPath = initActionNotDefined
65+
? webpackProperties.configPath
66+
: path.join(process.cwd(), configurationName);
67+
const source = ast.toSource({
68+
quote: "single"
69+
});
70+
71+
runPrettier(outputPath, source);
72+
})
73+
.catch(err => {
74+
console.error(err.message ? err.message : err);
75+
});
76+
});
77+
if (initActionNotDefined && webpackProperties.config.item) {
78+
process.stdout.write(
79+
"\n" +
80+
chalk.green(
81+
`Congratulations! ${
82+
webpackProperties.config.item
83+
} has been ${action}ed!\n`
84+
)
85+
);
86+
} else {
87+
process.stdout.write(
88+
"\n" +
89+
chalk.green(
90+
"Congratulations! Your new webpack configuration file has been created!\n"
91+
)
92+
);
93+
}
94+
};

0 commit comments

Comments
 (0)