-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
53 lines (46 loc) · 1.35 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// process.env.FORCE_COLOR = 2;
// process.stdout.isTTY = true;
const shelljs = require('shelljs');
const path = require('path');
const fs = require('fs');
const { W_OK } = require('constants');
const debug = require('debug');
const log = debug('test-htmljs');
const debugPrefix = 'test-htmljs-';
const rootDir = path.join(__dirname, '../../');
const outDir = path.join(__dirname, 'www');
copyLibs();
copyAssets();
log('done');
function copyLibs() {
const log = debug(debugPrefix + 'libs');
const libs = path.join(outDir, 'libs');
clean(libs);
cp(log, path.join(rootDir, 'dist', 'bundles', 'emulate-key-in-browser.js'), libs);
cp(log, path.join(rootDir, 'dist', 'bundles', 'emulate-key-in-browser.min.js'), libs);
log('done');
}
function copyAssets() {
const log = debug(debugPrefix + 'assets');
const dest = path.join(outDir, 'assets');
clean(dest);
const src = path.join(rootDir, 'test/assets');
cp(log, path.join(src, '*.png'), dest);
cp(log, path.join(src, '*.css'), dest);
cp(log, path.join(src, 'favicon.ico'), outDir);
log('done');
}
function clean(dest) {
try {
fs.accessSync(dest, W_OK);
log('clean up dest');
shelljs.exec('rm -rf ' + dest);
} catch (e) {
log('dest is clean');
}
shelljs.mkdir('-p', dest);
}
function cp(log, src, dest) {
log('copy files: ', path.basename(src));
shelljs.cp('-r', src, dest);
}