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