This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepublish.js
124 lines (93 loc) · 2.84 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
116
117
118
119
120
121
122
123
124
var
fs = require('fs'),
nodeExec = require('child_process').exec,
path = require('path');
var copyModule = function (module, target) {
var
fullTarget = path.join(__dirname, target),
modulePath = require.resolve(module);
if (!fs.existsSync(fullTarget)) {
exec('cp ' + modulePath + ' ' + fullTarget);
}
};
var exec = function (command) {
nodeExec(command, function (error, stdout, stderr) {
if (error != null) {
console.error('error running command: ' + error.stack);
process.exit(error.code);
}
if (stderr.length !== 0) {
console.error(stderr.toString());
process.exit(1);
}
if (stdout.length !== 0) {
console.log(stdout.toString());
}
});
};
var linkModule = function (module, target) {
var
fullTarget = path.join(__dirname, target),
modulePath = path.relative(path.dirname(fullTarget), require.resolve(module));
if (!fs.existsSync(fullTarget)) {
exec('ln -s ' + modulePath + ' ' + fullTarget);
}
};
var mkdir = function (dir) {
dir = path.join(__dirname, dir);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
};
var rmdir = function (dir) {
dir = path.join(__dirname, dir);
if (fs.existsSync(dir)) {
fs.rmdirSync(dir);
}
};
var unlink = function (file) {
file = path.join(__dirname, file);
if (fs.existsSync(file)) {
fs.unlinkSync(file);
}
};
var toCopy = {
'boomerang-client/lib/utils/request.js': 'public/js/request.js',
'bootstrap/dist/css/bootstrap.css': 'public/css/bootstrap.css',
'bootstrap/dist/css/bootstrap.css.map': 'public/css/bootstrap.css.map',
'bootstrap/dist/fonts/glyphicons-halflings-regular.eot': 'public/fonts/glyphicons-halflings-regular.eot',
'bootstrap/dist/fonts/glyphicons-halflings-regular.svg': 'public/fonts/glyphicons-halflings-regular.svg',
'bootstrap/dist/fonts/glyphicons-halflings-regular.ttf': 'public/fonts/glyphicons-halflings-regular.ttf',
'bootstrap/dist/fonts/glyphicons-halflings-regular.woff': 'public/fonts/glyphicons-halflings-regular.woff',
'bootstrap/dist/fonts/glyphicons-halflings-regular.woff2': 'public/fonts/glyphicons-halflings-regular.woff2',
'bootstrap/dist/js/bootstrap.js': 'public/js/bootstrap.js',
'jquery/dist/jquery.js': 'public/js/jquery.js',
'jsonld/js/jsonld.js': 'public/js/jsonld.js',
'promiseevent': 'public/js/promiseevent.js',
'react/dist/react.js': 'public/js/react.js'
};
var clean = function () {
Object.keys(toCopy).forEach(function (source) {
unlink(toCopy[source]);
});
rmdir('public/css');
rmdir('public/fonts');
};
var build = function () {
mkdir('public/css');
mkdir('public/fonts');
Object.keys(toCopy).forEach(function (source) {
copyModule(source, toCopy[source]);
});
};
switch(process.argv[2]) {
case 'clean':
clean();
break;
case 'build':
build();
break;
default:
clean();
build();
}