Skip to content

Commit

Permalink
chore: format and revise code w.r.t style
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed May 30, 2019
1 parent 5a0952e commit e9d426d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 38 deletions.
6 changes: 5 additions & 1 deletion bin/opencollective.js
Expand Up @@ -26,7 +26,11 @@ function printBadge() {
print(`Please consider donating to our ${chalk.bold.blue("Open Collective")}`);
print("to help us maintain this package.");
console.log("\n\n");
print(`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow("https://opencollective.com/webpack/donate")}`);
print(
`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow(
"https://opencollective.com/webpack/donate"
)}`
);
console.log("\n");
}

Expand Down
19 changes: 9 additions & 10 deletions bin/utils/prompt-command.js
Expand Up @@ -31,20 +31,20 @@ const npmGlobalRoot = () => {
const cp = require("child_process");
return new Promise((resolve, reject) => {
const command = cp.spawn("npm", ["root", "-g"]);
command.on("error", (error) => reject(error));
command.stdout.on("data", (data) => resolve(data.toString()));
command.stderr.on("data", (data) => reject(data));
command.on("error", error => reject(error));
command.stdout.on("data", data => resolve(data.toString()));
command.stderr.on("data", data => reject(data));
});
};

const runWhenInstalled = (packages, pathForCmd, ...args) => {
const package = require(pathForCmd);
const func = package.default;
if (typeof func !== 'function') {
if (typeof func !== "function") {
throw new Error(`@webpack-cli/${packages} failed to export a default function`);
}
return func(...args);
}
};

module.exports = function promptForInstallation(packages, ...args) {
const nameOfPackage = "@webpack-cli/" + packages;
Expand Down Expand Up @@ -102,19 +102,18 @@ module.exports = function promptForInstallation(packages, ...args) {
case "y":
case "yes":
case "1": {

runCommand(packageManager, options)
.then(_=> {
.then(_ => {
if (packages === "init") {
npmGlobalRoot()
.then((root) => {
.then(root => {
const pathtoInit = path.resolve(root.trim(), "@webpack-cli", "init");
return pathtoInit;
})
.then((pathForInit) => {
.then(pathForInit => {
return require(pathForInit).default(...args);
})
.catch((error) => {
.catch(error => {
console.error(error);
process.exitCode = 1;
});
Expand Down
41 changes: 30 additions & 11 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -33,8 +33,7 @@
"clean:all": "rimraf node_modules packages/*/{node_modules}",
"commit": "git-cz",
"docs": "typedoc",
"format": "prettier-eslint ./bin/*.js ./test/**/*.js ./packages/**/*.js --write",
"lint:codeOnly": "eslint \"{bin}/**/!(__testfixtures__)/*.js\" \"{bin}/**.js\"",
"format": "prettier-eslint ./bin/*.js ./bin/**/*.js ./test/**/*.js ./packages/**/*.js ./packages/**/**/*.js --write",
"lint": "eslint \"./bin/*.js\" \"./test/**/*.js\" \"packages/**/!(node_modules)/*.test.js\"",
"postinstall": "node ./bin/opencollective.js",
"pretest": "npm run build && npm run lint && npm run tslint",
Expand Down
15 changes: 1 addition & 14 deletions packages/utils/path-utils.ts
Expand Up @@ -17,27 +17,14 @@ export function isLocalPath(str: string): boolean {
return path.isAbsolute(str) || /^\./.test(str) || fs.existsSync(str);
}

/**
* Get absolute path of a webpack config in a project.
*
* @param {String[]} str - array of extensions to look for.
* @returns {String} Absolute path of the config.
*/

export function webpackConfigPath(extensions: string[]): string {
const defaultConfigFileNames = ["webpack.config", "webpackfile"].join("|");
const webpackConfigFileRegExp = `(${defaultConfigFileNames})(${extensions.join("|")})`;
return findup(webpackConfigFileRegExp);
}

/**
* Find the root directory path of a project.
*
* @returns {String} Absolute path of the project root.
*/

export function findProjectRoot(): string {
const rootFilePath = findup(`package.json`);
const rootFilePath = findup("package.json");
const projectRoot = path.dirname(rootFilePath);
return projectRoot;
}

0 comments on commit e9d426d

Please sign in to comment.