-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackaging.js
More file actions
74 lines (65 loc) · 1.75 KB
/
packaging.js
File metadata and controls
74 lines (65 loc) · 1.75 KB
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
#!/usr/bin/env node
const { exec } = require("child_process");
// copy the scripts data to dist/scripts
async function packageScripts() {
await runCommand(
"mkdir dist/lib/scripts",
"creating the dist/lib/scripts directory if it doesn't exist"
);
await runCommand(
"cp lib/scripts/* dist/lib/scripts/.",
"copy the contents of scripts to dist/sripts"
);
}
async function runCommand(
cmd,
execMsg,
goToDirAfterExec = null,
allowError = true
) {
var execResult = await wrapExecPromise(cmd);
if (goToDirAfterExec && goToDirAfterExec.length > 0) {
cd(goToDirAfterExec);
}
allowError =
allowError !== undefined && allowError !== null ? allowError : false;
if (execResult && execResult.code !== 0 && !allowError) {
/* error happened */
debug(
"Failed to " +
execMsg +
", code: " +
execResult.code +
", reason: " +
execResult.stderr
);
process.exit(1);
} else {
debug("Completed task to " + execMsg + ".");
}
}
async function wrapExecPromise(cmd, dir) {
let result = null;
try {
let opts = dir !== undefined && dir !== null ? { cwd: dir } : {};
result = await execPromise(cmd, opts);
} catch (e) {
result = null;
}
return result;
}
function execPromise(command, opts) {
return new Promise(function(resolve, reject) {
exec(command, opts, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
resolve(stdout.trim());
});
});
}
function debug(message) {
console.log("#### " + message);
}
packageScripts();