forked from roerohan/react-vnc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprep-repo-sbvr.js
59 lines (49 loc) · 1.71 KB
/
prep-repo-sbvr.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
const { exec } = require('child_process');
const { existsSync } = require('fs');
const { copyFile } = require('fs/promises');
const { join } = require('path');
const backupPackageFileName = "package.json.bak";
const packageFileName = "package.json";
let isBuilt = false;
const executeCommandSafely = async command => {
let promise = new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(error);
}
console.debug(`Executed command '${command}' and received output:`);
console.debug(`${stdout}`);
console.debug(`${stderr}`);
return resolve();
});
});
return await promise;
}
const run = async () => {
// First, check if we are already in a built state
if(existsSync(join(__dirname, backupPackageFileName))) {
console.info(`Found ${backupPackageFileName}, continuing in built state...`);
isBuilt = true;
}
if(isBuilt) {
try {
await copyFile(join(__dirname, backupPackageFileName), join(__dirname, packageFileName));
} catch(e) {
console.error(`Encountered exception copying ${backupPackageFileName} to ${packageFileName}: ${e}`)
return;
}
}
console.info(`Copied ${backupPackageFileName} to ${packageFileName}`);
console.info(`Installing npm dependencies...`);
const installCommand = "npm install";
await executeCommandSafely(installCommand);
console.info(`Building...`);
const buildCommand = "npm run build:lib";
await executeCommandSafely(buildCommand);
console.info(`Prepping publish...`);
const prepPublishCommand = "npm run prepublishOnly";
await executeCommandSafely(prepPublishCommand);
}
run().catch(reason => {
console.error(`Failed to run: ${reason}`);
});