-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.js
More file actions
56 lines (54 loc) · 1.47 KB
/
build.js
File metadata and controls
56 lines (54 loc) · 1.47 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
const { exec } = require('child_process');
const themeColors = {
text: '#ff8e4d',
variable: '#ff624d',
error: '#f5426c',
};
const main = () => {
console.log(chalk.hex(themeColors.text)('Starting build...'));
exec('tsc', (err, stdout, stderr) => {
if (err) {
console.log(
chalk.hex(themeColors.error)('Build failed with the following error: ')
);
console.log(chalk.hex(themeColors.error)(stdout));
return;
}
console.log(
chalk.hex(themeColors.text)(
`Build successful! You can start the bot by running ${chalk.hex(themeColors.variable)('npm start')}\n`
)
);
});
};
try {
var chalk = require('chalk');
main();
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
console.log(
'\x1b[31mNode modules are not installed. \x1b[33mInstalling...\x1b[37m'
);
exec('npm i', (err, stdout, stderr) => {
if (err) {
console.log('\x1b[31mFailed to install node modules. \x1b[37m');
console.log(err);
process.exit(1);
}
console.log(stdout);
console.log(
'\x1b[32mNode modules successfully installed. \x1b[33mRestarting in 3 seconds... \x1b[37m'
);
setTimeout(() => {
exec('node build.js', (err, stdout, stderr) => {
if (err) {
console.log('\x1b[31mFailed to restart. \x1b[37m');
console.log(err);
process.exit(1);
}
console.log(stdout);
});
}, 3000);
});
}
}