1 |
|
2 |
|
3 |
|
4 | const execSync = require('child_process').execSync;
|
5 | const fs = require('fs');
|
6 | const path = require('path');
|
7 | const json = require('mrm-core').json;
|
8 |
|
9 | const defaultsName = 'defaults';
|
10 | const distDirectory = 'dist';
|
11 | const localDir = process
|
12 | .cwd()
|
13 | .split('node_modules')
|
14 | .shift();
|
15 |
|
16 | writeScript();
|
17 | writeDist();
|
18 |
|
19 |
|
20 | function writeScript() {
|
21 | const pkg = json(path.resolve(localDir, 'package.json'));
|
22 | const scriptPath = ['scripts', defaultsName];
|
23 | if (!pkg.get(scriptPath)) {
|
24 | pkg.set(scriptPath, 'webpack-defaults').save();
|
25 | }
|
26 | }
|
27 |
|
28 |
|
29 | function writeDist() {
|
30 | fs.stat(distDirectory, function(error, stat) {
|
31 |
|
32 | if (process.env.TRAVIS) {
|
33 | return;
|
34 | }
|
35 |
|
36 | if (error || !stat.isDirectory()) {
|
37 |
|
38 |
|
39 | fs.mkdirSync(distDirectory);
|
40 | exec('npm install --only=dev');
|
41 | exec('npm run build');
|
42 | }
|
43 | });
|
44 | }
|
45 |
|
46 | function exec(command) {
|
47 | execSync(command, {
|
48 |
|
49 | stdio: 'inherit',
|
50 | });
|
51 | }
|