@bb-labs/bldr 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -0
- package/dist/utils/process.d.ts +6 -0
- package/dist/utils/process.js +77 -3
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { parseArgs } from "./utils/args.js";
|
|
3
3
|
import { build } from "./core/builder.js";
|
|
4
|
+
import { checkDependencies } from "./utils/process.js";
|
|
4
5
|
async function main() {
|
|
6
|
+
// Check if required dependencies are installed
|
|
7
|
+
const depsOk = await checkDependencies();
|
|
8
|
+
if (!depsOk) {
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
5
11
|
const args = parseArgs(process.argv.slice(2));
|
|
6
12
|
await build(args);
|
|
7
13
|
}
|
package/dist/utils/process.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { type ChildProcess } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if required dependencies (tsc, tsc-alias) are available.
|
|
4
|
+
* If not, prompts the user to install them.
|
|
5
|
+
* Returns true if dependencies are available, false if user declined to install.
|
|
6
|
+
*/
|
|
7
|
+
export declare function checkDependencies(): Promise<boolean>;
|
|
2
8
|
/**
|
|
3
9
|
* Runs a command and returns a promise that resolves when the command finishes.
|
|
4
10
|
* Captures output for error messages if the command fails.
|
package/dist/utils/process.js
CHANGED
|
@@ -1,4 +1,78 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import * as readline from "node:readline";
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a command is available in the PATH.
|
|
5
|
+
*/
|
|
6
|
+
function commandExists(cmd) {
|
|
7
|
+
const result = spawnSync("which", [cmd], { stdio: "pipe" });
|
|
8
|
+
return result.status === 0;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Prompts the user for yes/no input. Defaults to yes on empty input.
|
|
12
|
+
*/
|
|
13
|
+
async function promptYesNo(question) {
|
|
14
|
+
const rl = readline.createInterface({
|
|
15
|
+
input: process.stdin,
|
|
16
|
+
output: process.stdout,
|
|
17
|
+
});
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
rl.question(`${question} [Y/n]: `, (answer) => {
|
|
20
|
+
rl.close();
|
|
21
|
+
const normalized = answer.trim().toLowerCase();
|
|
22
|
+
// Empty or 'y' or 'yes' = true, anything else = false
|
|
23
|
+
resolve(normalized === "" || normalized === "y" || normalized === "yes");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Installs missing dependencies using bun.
|
|
29
|
+
*/
|
|
30
|
+
async function installDeps(deps) {
|
|
31
|
+
console.log(`\n📦 Installing: ${deps.join(", ")}...\n`);
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const child = spawn("bun", ["add", "-d", ...deps], {
|
|
34
|
+
stdio: "inherit",
|
|
35
|
+
shell: true,
|
|
36
|
+
});
|
|
37
|
+
child.on("exit", (code) => {
|
|
38
|
+
if (code === 0) {
|
|
39
|
+
console.log("\n✅ Dependencies installed successfully!\n");
|
|
40
|
+
resolve();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
reject(new Error(`Failed to install dependencies (exit code ${code})`));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
child.on("error", (error) => {
|
|
47
|
+
reject(new Error(`Failed to run bun: ${error.message}`));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks if required dependencies (tsc, tsc-alias) are available.
|
|
53
|
+
* If not, prompts the user to install them.
|
|
54
|
+
* Returns true if dependencies are available, false if user declined to install.
|
|
55
|
+
*/
|
|
56
|
+
export async function checkDependencies() {
|
|
57
|
+
const missing = [];
|
|
58
|
+
if (!commandExists("tsc")) {
|
|
59
|
+
missing.push("typescript");
|
|
60
|
+
}
|
|
61
|
+
if (!commandExists("tsc-alias")) {
|
|
62
|
+
missing.push("tsc-alias");
|
|
63
|
+
}
|
|
64
|
+
if (missing.length === 0) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
console.log(`\n⚠️ Missing required dependencies: ${missing.join(", ")}`);
|
|
68
|
+
const shouldInstall = await promptYesNo("Would you like to install them now?");
|
|
69
|
+
if (shouldInstall) {
|
|
70
|
+
await installDeps(missing);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
console.log(`\n❌ Please install missing dependencies manually:\n bun add -d ${missing.join(" ")}\n`);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
2
76
|
/**
|
|
3
77
|
* Runs a command and returns a promise that resolves when the command finishes.
|
|
4
78
|
* Captures output for error messages if the command fails.
|
|
@@ -8,7 +82,7 @@ export function run(cmd, args, cwd) {
|
|
|
8
82
|
const p = spawn(cmd, args, {
|
|
9
83
|
cwd,
|
|
10
84
|
stdio: ["inherit", "pipe", "pipe"],
|
|
11
|
-
shell:
|
|
85
|
+
shell: true,
|
|
12
86
|
env: { ...process.env, FORCE_COLOR: "1" },
|
|
13
87
|
});
|
|
14
88
|
let output = "";
|
|
@@ -43,7 +117,7 @@ export function spawnLongRunning(cmd, args, cwd) {
|
|
|
43
117
|
return spawn(cmd, args, {
|
|
44
118
|
cwd,
|
|
45
119
|
stdio: ["inherit", "pipe", "pipe"],
|
|
46
|
-
shell:
|
|
120
|
+
shell: true,
|
|
47
121
|
env: { ...process.env, FORCE_COLOR: "1" },
|
|
48
122
|
});
|
|
49
123
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bb-labs/bldr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bldr": "./dist/index.js"
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"build": "tsc",
|
|
13
13
|
"postbuild": "chmod +x dist/index.js",
|
|
14
14
|
"test:build": "node dist/index.js --project test-src/tsconfig.json",
|
|
15
|
-
"test:watch": "node dist/index.js --watch --project test-src/tsconfig.json"
|
|
15
|
+
"test:watch": "node dist/index.js --watch --project test-src/tsconfig.json",
|
|
16
|
+
"clean": "rm -rf node_modules bun.lock dist"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"@types/blessed": "^0.1.27",
|