-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
70 lines (63 loc) · 2.28 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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 logWww = debug('test-htmljs:www');
const debugPrefix = 'test-htmljs-';
const rootDir = path.join(__dirname, '../../');
const outDir = path.join(__dirname, 'dist');
const wwwDir = path.join(__dirname, 'www');
const srcDir = path.join(__dirname, 'src');
clean(outDir);
shelljs.exec('tsc', { fatal: true });
copyAssets();
assembleWww();
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);
}
function assembleWww() {
logWww('assemble wwww: ' + wwwDir);
const scriptsDir = path.join(wwwDir, 'scripts');
const stylesDir = path.join(wwwDir, 'styles');
shelljs.exec('rm -rf www');
shelljs.exec('mkdir -p ' + scriptsDir);
shelljs.exec('mkdir -p ' + stylesDir);
cp(logWww, path.join(outDir, '*.js'), scriptsDir);
shelljs.exec('rm ' + path.join(scriptsDir, '*.spec.js'));
cp(logWww, path.join(outDir, '*.js.map'), scriptsDir);
shelljs.exec('rm ' + path.join(scriptsDir, '*.spec.js.map'));
cp(logWww, path.join(outDir, 'favicon.ico'), wwwDir);
cp(logWww, require.resolve('requirejs/require.js'), scriptsDir);
cp(logWww, path.join(outDir, 'assets'), wwwDir);
cp(logWww, path.join(srcDir, '*.html'), wwwDir);
cp(logWww, path.join(srcDir, '*.css'), stylesDir);
cp(logWww, require.resolve('emulate-key-in-browser/dist/bundles/emulate-key-in-browser.amd.js'), path.join(wwwDir, 'emulate-key-in-browser.js'));
cp(logWww, require.resolve('emulate-tab/dist/bundles/emulate-tab.amd.js'), path.join(wwwDir, 'emulate-tab.js'));
logWww('assemble www done');
}