-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
50 lines (43 loc) · 1.3 KB
/
script.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
import { exec } from "child_process";
import chalk from "chalk";
import { env } from "./src/env";
// Print header information
console.log(chalk.cyan(process.env.npm_package_name));
console.log(
`- Local: ${chalk.underline(`http://localhost:${env.PORT}`)}`
);
// check if env is set
if (env.PORT) {
console.log(`- Environments: .env`);
}
console.log(`${chalk.green("✓")} ${chalk.white("Starting...\n")}`);
// Function to run a command and print its output
function runCommand(command, name) {
return new Promise((resolve, reject) => {
const process = exec(command);
process.stdout?.on("data", (data) => {
console.log(chalk.white(`[${name}] ${data.toString()}`));
});
process.stderr?.on("data", (data) => {
console.error(chalk.red(`[${name}] ${data.toString()}`));
});
process.on("close", (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`${name} exited with code ${code}`));
}
});
});
}
// Run the dev commands in parallel
Promise.all([
runCommand("bunx --bun tsc --watch", "tsc-watch"),
runCommand("bun run --watch build/index.js", "build-watch"),
])
.then(() => {
console.log(chalk.green("\n ✓ Ready"));
})
.catch((error) => {
console.error(chalk.red(`\n ✗ Error: ${error.message}`));
});