-
Notifications
You must be signed in to change notification settings - Fork 1
/
postbuild.js
72 lines (57 loc) · 1.41 KB
/
postbuild.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
const {
exec
} = require('child_process');
const path = require('path');
const pkg = require(path.join(path.resolve(), 'package.json'));
function getBanner() {
let banner;
banner = '/*! ' + pkg.name + ' v' + pkg.version + ' | ';
if (typeof pkg.license === 'string') {
banner += pkg.license;
}
// old package.json
else if (typeof pkg.license === 'object') {
banner += pkg.license.type;
}
// old package.json
else if (pkg.licenses && pkg.licenses[0]) {
banner += pkg.licenses[0].type;
}
banner += ' (c) ' + (new Date().getFullYear());
if (pkg.author && pkg.author.name) {
banner += ' ' + pkg.author.name;
}
if (pkg.homepage) {
banner += ' - ' + pkg.homepage;
}
banner += ' */';
return banner;
}
function writeBanner(file) {
exec('echo "' + getBanner() + '\n$(cat ' + file + ')" > ' + file, (err, stdout, stderr) => {
if (err) {
console.error(`exec error: ${err}`);
return;
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
});
exec('head -n 1 ' + file, (err, stdout, stderr) => {
if (err) {
console.error(`exec error: ${err}`);
return;
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.error(`stderr: ${stderr}`);
}
});
}
writeBanner('./dist/storux.es.js')
writeBanner('./dist/storux.umd.js')