Skip to content

Commit a112e6d

Browse files
author
Atanas Strahilov
committed
Update CLI interface
1 parent af2da5a commit a112e6d

File tree

6 files changed

+85
-52
lines changed

6 files changed

+85
-52
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ Also, you can always switch to another file/folder structure if the current one
3333

3434
Just keep in mind that the styles should be located in `assets/styles` and the scripts should be located in `assets/scripts`.
3535

36+
## Zero config and fast installation
37+
38+
Navigate to your new project's folder and execute the following command:
39+
40+
```sh
41+
npx webpack-mpa-ts && npm i && npm start
42+
```
43+
44+
This will install Webpack-MPA in your project folder and you will be able to start right away.
45+
3646
## Download
3747

3848
You can download this setup [directly](https://github.com/scriptex/webpack-mpa-ts/archive/master.zip) and extract it.
@@ -56,17 +66,15 @@ Then navigate to the `webpack-mpa-ts` folder and proceed with the rest of the in
5666
It is possible to use the CLI tool included in Webpack MPA TS. In order to do this you must install Webpack MPA TS globally:
5767

5868
```sh
59-
npm i webpack-mpa-ts ncp -g
69+
npm i webpack-mpa-ts -g
6070
```
6171

6272
or
6373

6474
```sh
65-
yarn global add webpack-mpa-ts ncp
75+
yarn global add webpack-mpa-ts
6676
```
6777

68-
`ncp` is a peer dependency and is needed for the CLI interface. If you don't install it you will not be able to use the `wmpats` binary.
69-
7078
The `wmpats` binary is now available for you to use.
7179

7280
Go to your new project folder and execute

bin/cli.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Node dependencies
4+
*/
5+
const { join } = require('path');
6+
/**
7+
* Internal dependencies
8+
*/
9+
const { copyDir } = require('./copy');
10+
11+
const shouldSkip = name => name === 'node_modules' || name === 'bin' || name[0] === '.';
12+
13+
copyDir(join(__dirname, '../'), process.env.PWD, shouldSkip);
14+
15+
console.log('Webpack MPA Next is now setup! Run "npm i" or "yarn" to continue');

bin/copy.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const { join } = require('path');
2+
3+
const {
4+
lstatSync,
5+
mkdirSync,
6+
symlinkSync,
7+
readdirSync,
8+
readlinkSync,
9+
createReadStream,
10+
createWriteStream
11+
} = require('fs');
12+
13+
const mkdir = dir => {
14+
try {
15+
mkdirSync(dir, 0755);
16+
} catch (e) {
17+
if (e.code !== 'EEXIST') {
18+
throw e;
19+
}
20+
}
21+
};
22+
23+
const copy = (src, dest) => {
24+
const from = createReadStream(src);
25+
const to = createWriteStream(dest);
26+
27+
from.pipe(to);
28+
};
29+
30+
const copyDir = (src, dest, filter) => {
31+
mkdir(dest);
32+
33+
const files = readdirSync(src);
34+
35+
for (const file of files) {
36+
const from = join(src, file);
37+
const to = join(dest, file);
38+
const current = lstatSync(from);
39+
40+
if (typeof filter === 'function' && filter(file)) {
41+
continue;
42+
}
43+
44+
if (current.isDirectory()) {
45+
copyDir(from, to);
46+
} else if (current.isSymbolicLink()) {
47+
const symlink = readlinkSync(from);
48+
49+
symlinkSync(symlink, to);
50+
} else {
51+
copy(from, to);
52+
}
53+
}
54+
};
55+
56+
module.exports = { mkdir, copy, copyDir };

cli.js

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

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-mpa-ts",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Multi page app setup with webpack",
55
"scripts": {
66
"build": "webpack --env.NODE_ENV=production",
@@ -46,7 +46,6 @@
4646
"cssnano": "4.1.7",
4747
"extract-text-webpack-plugin": "4.0.0-beta.0",
4848
"file-loader": "2.0.0",
49-
"ncp": "2.0.0",
5049
"node-sass": "4.10.0",
5150
"node-sass-magic-importer": "5.2.0",
5251
"postcss-easy-import": "3.0.0",
@@ -67,16 +66,13 @@
6766
"webpack-spritesmith": "0.5.4",
6867
"yargs": "12.0.5"
6968
},
70-
"peerDependencies": {
71-
"ncp": "2.0.0"
72-
},
7369
"browserslist": [
7470
"> 1%",
7571
"last 2 versions"
7672
],
7773
"main": "assets/scripts/main.ts",
7874
"private": false,
7975
"bin": {
80-
"wmpants": "./cli.js"
76+
"wmpats": "./bin/cli.js"
8177
}
8278
}

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5358,11 +5358,6 @@ nanomatch@^1.2.9:
53585358
snapdragon "^0.8.1"
53595359
to-regex "^3.0.1"
53605360

5361-
ncp@^2.0.0:
5362-
version "2.0.0"
5363-
resolved "https://registry.yarnpkg.com/ncp/-/ncp-2.0.0.tgz#195a21d6c46e361d2fb1281ba38b91e9df7bdbb3"
5364-
integrity sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=
5365-
53665361
ndarray-fill@~1.0.1:
53675362
version "1.0.2"
53685363
resolved "https://registry.yarnpkg.com/ndarray-fill/-/ndarray-fill-1.0.2.tgz#a30a60f7188e0c9582fcdd58896acdcb522a1ed6"

0 commit comments

Comments
 (0)