UNPKG

1.22 kBJavaScriptView Raw
1/* eslint-disable */
2// adapted based on rackt/history (MIT)
3// Node 4+
4const execSync = require('child_process').execSync;
5const fs = require('fs');
6const path = require('path');
7const json = require('mrm-core').json;
8
9const defaultsName = 'defaults';
10const distDirectory = 'dist';
11const localDir = process
12 .cwd()
13 .split('node_modules')
14 .shift();
15
16writeScript();
17writeDist();
18
19// Create webpack-defaults in package.json if it doesn’t exist
20function 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// Compile sources in case of installation from Git
29function writeDist() {
30 fs.stat(distDirectory, function(error, stat) {
31 // Skip building on Travis
32 if (process.env.TRAVIS) {
33 return;
34 }
35
36 if (error || !stat.isDirectory()) {
37 // Create a directory to avoid getting stuck
38 // in postinstall loop
39 fs.mkdirSync(distDirectory);
40 exec('npm install --only=dev');
41 exec('npm run build');
42 }
43 });
44}
45
46function exec(command) {
47 execSync(command, {
48 // Print stdin/stdout/stderr
49 stdio: 'inherit',
50 });
51}