|
1 |
| -"use strict" |
| 1 | +"use strict"; |
2 | 2 |
|
3 |
| -const path = require('path') |
4 |
| -const _exec = require('child_process').exec |
5 |
| -const sw = require('./build.serviceWorker'); |
6 |
| -const fs = require('fs-extra'); |
7 |
| -const staticAssets = require('./static-assets.json'); |
| 3 | +const path = require("path"); |
| 4 | +const _exec = require("child_process").exec; |
| 5 | +const sw = require("./build.serviceWorker"); |
| 6 | +const fs = require("fs-extra"); |
| 7 | +const staticAssets = require("./static-assets.json"); |
8 | 8 |
|
9 | 9 | const promisify = (ctx, func = ctx) => (...args) => {
|
10 | 10 | return new Promise((resolve, reject) => {
|
11 |
| - func.apply(ctx, [...args, (err, result) => err ? reject(err) : resolve(result)]) |
12 |
| - }) |
13 |
| -} |
14 |
| -const exec = promisify(_exec) |
15 |
| -const tasks = new Map() |
16 |
| -const run = (task) => { |
17 |
| - const start = new Date() |
18 |
| - return Promise.all([].concat(tasks.get(task)())).then(() => { |
19 |
| - console.log(`[build] '${task}' done in ${new Date().getTime() - start.getTime()}ms`) |
20 |
| - }, (err) => console.error(err.stack)) |
21 |
| -} |
| 11 | + func.apply(ctx, [ |
| 12 | + ...args, |
| 13 | + (err, result) => (err ? reject(err) : resolve(result)) |
| 14 | + ]); |
| 15 | + }); |
| 16 | +}; |
| 17 | +const exec = promisify(_exec); |
| 18 | +const tasks = new Map(); |
| 19 | +const run = task => { |
| 20 | + const start = new Date(); |
| 21 | + return Promise.all([].concat(tasks.get(task)())).then( |
| 22 | + () => { |
| 23 | + console.log( |
| 24 | + `[build] '${task}' done in ${new Date().getTime() - start.getTime()}ms` |
| 25 | + ); |
| 26 | + }, |
| 27 | + err => console.error(err.stack) |
| 28 | + ); |
| 29 | +}; |
22 | 30 |
|
23 |
| -const clear = () => exec('rimraf ./dist') |
24 |
| -const webpackClient = () => exec('cross-env NODE_ENV=production webpack --config ./build/webpack.client.config.js --progress --hide-modules') |
25 |
| -const webpackServer = () => exec('cross-env NODE_ENV=production webpack --config ./build/webpack.server.config.js --progress --hide-modules') |
26 |
| -const copyStaticAssets = () => { |
| 31 | +const clear = () => exec("rimraf ./dist"); |
| 32 | +const webpackClient = () => |
| 33 | + exec( |
| 34 | + "cross-env NODE_ENV=production ./node_modules/webpack/bin/webpack.js --config ./build/webpack.client.config.js --progress --hide-modules" |
| 35 | + ); |
| 36 | +const webpackServer = () => |
| 37 | + exec( |
| 38 | + "cross-env NODE_ENV=production ./node_modules/webpack/bin/webpack.js --config ./build/webpack.server.config.js --progress --hide-modules" |
| 39 | + ); |
| 40 | +const copyStaticAssets = () => { |
27 | 41 | return new Promise((resolve, reject) => {
|
28 |
| - for(var prop in staticAssets){ |
29 |
| - fs.copySync(path.resolve(__dirname, prop), path.resolve(__dirname, staticAssets[prop])); |
| 42 | + for (var prop in staticAssets) { |
| 43 | + fs.copySync( |
| 44 | + path.resolve(__dirname, prop), |
| 45 | + path.resolve(__dirname, staticAssets[prop]) |
| 46 | + ); |
30 | 47 | }
|
31 |
| - resolve() |
32 |
| - }) |
33 |
| -} |
34 |
| -const purifyCSS = () => exec('purifycss ./dist/assets/styles.css ./dist/assets/js/app.js --min --info --out ./dist/assets/styles.css') |
| 48 | + resolve(); |
| 49 | + }); |
| 50 | +}; |
| 51 | +const purifyCSS = () => |
| 52 | + exec( |
| 53 | + "purifycss ./dist/assets/styles.css ./dist/assets/js/app.js --min --info --out ./dist/assets/styles.css" |
| 54 | + ); |
35 | 55 |
|
36 |
| -tasks.set('clear', clear); |
37 |
| -tasks.set('webpackClient', webpackClient); |
38 |
| -tasks.set('webpackServer', webpackServer); |
39 |
| -tasks.set('copyStaticAssets', copyStaticAssets); |
40 |
| -tasks.set('serviceWorker', sw.exec); |
41 |
| -tasks.set('purifyCSS', purifyCSS); |
| 56 | +tasks.set("clear", clear); |
| 57 | +tasks.set("webpackClient", webpackClient); |
| 58 | +tasks.set("webpackServer", webpackServer); |
| 59 | +tasks.set("copyStaticAssets", copyStaticAssets); |
| 60 | +tasks.set("serviceWorker", sw.exec); |
| 61 | +tasks.set("purifyCSS", purifyCSS); |
42 | 62 |
|
43 |
| -tasks.set('build', () => |
| 63 | +tasks.set("build", () => |
44 | 64 | // run('serviceWorker')
|
45 |
| - run('clear') |
46 |
| - .then(() => Promise.all([run('webpackClient')])) |
47 |
| - .then(() => Promise.all([run('webpackServer')])) |
48 |
| - .then(() => Promise.all([run('copyStaticAssets')])) |
49 |
| - .then(() => Promise.all([run('serviceWorker')])) |
50 |
| - .then(() => Promise.all([run('purifyCSS')])) |
51 |
| -) |
| 65 | + run("clear") |
| 66 | + .then(() => Promise.all([run("webpackClient")])) |
| 67 | + .then(() => Promise.all([run("webpackServer")])) |
| 68 | + .then(() => Promise.all([run("copyStaticAssets")])) |
| 69 | + .then(() => Promise.all([run("serviceWorker")])) |
| 70 | + .then(() => Promise.all([run("purifyCSS")])) |
| 71 | +); |
52 | 72 |
|
53 |
| -run('build') |
| 73 | +run("build"); |
0 commit comments