This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
prepublish.js
115 lines (85 loc) · 2.4 KB
/
prepublish.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var
exec = require('child_process').exec;
var run = function (command) {
return new Promise(function (resolve, reject) {
exec(command, function (error, stdout, stderr) {
if (error != null) {
return reject(error);
}
if (stderr.trim() !== '') {
console.error(stderr.trim());
}
if (stdout.trim() !== '') {
console.log(stdout.trim());
}
resolve();
});
});
};
var browserify = function (source, target, options) {
options = options || {};
var cmd = './node_modules/.bin/browserify ' + source + ' -o ' + target;
if (options.debug) {
cmd += ' --debug';
}
if (options.exclude) {
cmd += ' ' + options.exclude
.map(function (exclude) {
return '-u ' + exclude;
})
.join(' ');
}
if (options.list) {
cmd += ' --list';
}
if (options.noBuiltins) {
cmd += ' --no-builtins';
}
if (options.noBundleExternal) {
cmd += ' --no-bundle-external';
}
if (options.standalone) {
cmd += ' --standalone=' + options.standalone;
}
return run(cmd);
};
var exorcist = function (source, target, options) {
options = options || {};
var cmd = 'cat ' + source + ' | ./node_modules/.bin/exorcist ' + target + ' > /dev/null';
return run(cmd);
};
var uglify = function (source, target, options) {
options = options || {};
var cmd = './node_modules/.bin/uglifyjs ' + source + ' -o ' + target;
if (options.compress) {
cmd += ' --compress';
}
if (options.inSourceMap) {
cmd += ' --in-source-map ' + options.inSourceMap;
}
if (options.sourceMap) {
cmd += ' --source-map ' + options.sourceMap;
}
if (options.sourceMapUrl) {
cmd += ' --source-map-url ' + options.sourceMapUrl;
}
return run(cmd);
};
browserify('hydra-core.js', 'dist/hydra-core.js', { debug: true, noBundleExternal:true, standalone: 'hydra' })
.then(function () {
return exorcist('dist/hydra-core.js', 'dist/hydra-core.js.map', {});
})
.then(function () {
return browserify('hydra-core.js', 'dist/hydra-core.js', { noBundleExternal:true, standalone: 'hydra' })
})
.then(function () {
return uglify('dist/hydra-core.js', 'dist/hydra-core.min.js', {
compress: true,
inSourceMap: 'dist/hydra-core.js.map',
sourceMap: 'dist/hydra-core.min.js.map',
sourceMapUrl: 'hydra-core.min.js.map'
});
})
.catch(function (error) {
console.error(error.stack);
});