Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/webpack/webpack-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Apr 9, 2019
2 parents a26a48c + b96857f commit 6d75e25
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 81 deletions.
24 changes: 24 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ In case you are suggesting a new feature, we will match your idea with our curre
npm run test
```

* Run CLI tests with:

```bash
npm run test:cli
```

* Run tests of all packages:

```bash
npm run test:packages
```

* Test a single CLI test case:

```bash
Expand Down Expand Up @@ -110,6 +122,18 @@ In case you are suggesting a new feature, we will match your idea with our curre
yarn test
```

* Run CLI tests with:

```bash
yarn test:cli`
```

* Run tests of all packages:

```bash
yarn test:packages
```

* Test a single CLI test case:

```bash
Expand Down
16 changes: 11 additions & 5 deletions bin/utils/prompt-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ const npmGlobalRoot = () => {
});
};

const runWhenInstalled = (packages, pathForCmd, ...args) => {
const package = require(pathForCmd);
const func = package.default;
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;
let packageIsInstalled = false;
Expand Down Expand Up @@ -113,10 +122,7 @@ module.exports = function promptForInstallation(packages, ...args) {
}

pathForCmd = path.resolve(process.cwd(), "node_modules", "@webpack-cli", packages);
if (packages === "serve") {
return require(pathForCmd).default.serve();
}
return require(pathForCmd).default(...args); //eslint-disable-line
return runWhenInstalled(packages, pathForCmd, ...args);
})
.catch(error => {
console.error(error);
Expand All @@ -132,6 +138,6 @@ module.exports = function promptForInstallation(packages, ...args) {
}
});
} else {
require(pathForCmd).default(...args); // eslint-disable-line
return runWhenInstalled(packages, pathForCmd, ...args);
}
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"pretest": "npm run build && npm run lint && npm run tslint",
"reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov",
"test": "nyc jest --maxWorkers=4 --reporters=default --reporters=jest-junit",
"test:cli": "nyc jest test/ --maxWorkers=4 --reporters=default --reporters=jest-junit",
"test:packages": "nyc jest packages/ --maxWorkers=4 --reporters=default --reporters=jest-junit",
"test:ci": "nyc jest --maxWorkers=$(nproc) --reporters=default --reporters=jest-junit",
"travis:integration": "npm run build && npm run test && npm run reportCoverage",
"travis:lint": "npm run build && npm run lint && npm run tslint",
Expand Down Expand Up @@ -76,7 +78,10 @@
"transform": {
"^.+\\.(ts)?$": "ts-jest"
},
"testRegex": "/__tests__/.*\\.(test.js|test.ts)$",
"testRegex": [
"/__tests__/.*\\.(test.js|test.ts)$",
"/test/.*\\.(test.js|test.ts)$"
],
"moduleFileExtensions": [
"ts",
"js",
Expand Down
19 changes: 4 additions & 15 deletions packages/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,10 @@ export default function runTransform(webpackProperties: IWebpackProperties, acti
});
});

let successMessage: string = `Congratulations! Your new webpack configuration file has been created!`;
if (initActionNotDefined && webpackProperties.config.item) {
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",
),
);
successMessage = `Congratulations! ${webpackProperties.config.item} has been ${action}ed!`;

}
process.stdout.write("\n" + chalk.green(`${successMessage}\n`));
}
2 changes: 1 addition & 1 deletion packages/serve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To run the scaffolding instance programmatically, install it as a dependency. Wh

### Node
```js
const serve = require("@webpack-cli/serve").serve;
const serve = require("@webpack-cli/serve").default;
serve();
```

Expand Down
11 changes: 2 additions & 9 deletions packages/serve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const getRootPathModule = (dep: string): string => path.resolve(process.cwd(), d
*
* Prompts for installing the devServer and running it
*
* @param {Object} args - args processed from the CLI
* @param {String[]} args - args processed from the CLI
* @returns {Function} invokes the devServer API
*/

function serve() {
export default function serve(...args: string[]) {
const packageJSONPath = getRootPathModule("package.json");
if (!packageJSONPath) {
console.error(
Expand Down Expand Up @@ -169,10 +169,3 @@ function serve() {
});
}
}

export = {
getRootPathModule,
serve,
spawnNPMWithArg,
spawnYarnWithArg,
};
8 changes: 8 additions & 0 deletions packages/utils/find-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as findup from "findup-sync";
import * as path from "path";

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

0 comments on commit 6d75e25

Please sign in to comment.