@bb-labs/bldr 0.0.12 → 0.0.14

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 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
  }
@@ -1,4 +1,9 @@
1
1
  import { type ChildProcess } from "node:child_process";
2
+ /**
3
+ * Checks if required dependencies (tsc, tsc-alias) are available.
4
+ * If not, automatically installs them.
5
+ */
6
+ export declare function checkDependencies(): Promise<boolean>;
2
7
  /**
3
8
  * Runs a command and returns a promise that resolves when the command finishes.
4
9
  * Captures output for error messages if the command fails.
@@ -1,4 +1,54 @@
1
- import { spawn } from "node:child_process";
1
+ import { spawn, spawnSync } from "node:child_process";
2
+ /**
3
+ * Checks if a command is available in the PATH.
4
+ */
5
+ function commandExists(cmd) {
6
+ const result = spawnSync("which", [cmd], { stdio: "pipe" });
7
+ return result.status === 0;
8
+ }
9
+ /**
10
+ * Installs missing dependencies using bun.
11
+ */
12
+ async function installDeps(deps) {
13
+ console.log(`\n📦 Installing: ${deps.join(", ")}...\n`);
14
+ return new Promise((resolve, reject) => {
15
+ const child = spawn("bun", ["add", "-d", ...deps], {
16
+ stdio: "inherit",
17
+ shell: true,
18
+ });
19
+ child.on("exit", (code) => {
20
+ if (code === 0) {
21
+ console.log("\n✅ Dependencies installed successfully!\n");
22
+ resolve();
23
+ }
24
+ else {
25
+ reject(new Error(`Failed to install dependencies (exit code ${code})`));
26
+ }
27
+ });
28
+ child.on("error", (error) => {
29
+ reject(new Error(`Failed to run bun: ${error.message}`));
30
+ });
31
+ });
32
+ }
33
+ /**
34
+ * Checks if required dependencies (tsc, tsc-alias) are available.
35
+ * If not, automatically installs them.
36
+ */
37
+ export async function checkDependencies() {
38
+ const missing = [];
39
+ if (!commandExists("tsc")) {
40
+ missing.push("typescript");
41
+ }
42
+ if (!commandExists("tsc-alias")) {
43
+ missing.push("tsc-alias");
44
+ }
45
+ if (missing.length === 0) {
46
+ return true;
47
+ }
48
+ console.log(`\n⚠️ Missing required dependencies: ${missing.join(", ")}`);
49
+ await installDeps(missing);
50
+ return true;
51
+ }
2
52
  /**
3
53
  * Runs a command and returns a promise that resolves when the command finishes.
4
54
  * Captures output for error messages if the command fails.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bb-labs/bldr",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
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",