Elffuss BraidHub

kikocis/continue public

e9ecc1af12bb · 2.9 KiBRawPermalink
1const { spawn } = require("child_process");
2const path = require("path");
3const fs = require("fs");
4const fsPromises = require("fs/promises");
5
6const npmInstallCmd = process.env.CI === "true" ? "npm ci" : "npm install";
7
8function runCommand(command, cwd, packageName) {
9 return new Promise((resolve, reject) => {
10 console.log(`Starting ${packageName}: ${command}`);
11
12 const [cmd, ...args] = command.split(" ");
13 const child = spawn(cmd, args, {
14 cwd,
15 stdio: "pipe",
16 shell: true,
17 });
18
19 let stdout = "";
20 let stderr = "";
21
22 child.stdout.on("data", (data) => {
23 stdout += data.toString();
24 });
25
26 child.stderr.on("data", (data) => {
27 stderr += data.toString();
28 });
29
30 child.on("close", (code) => {
31 if (code === 0) {
32 console.log(`✅ ${packageName}: ${command} completed successfully`);
33 resolve({ packageName, command, stdout, stderr });
34 } else {
35 console.error(`❌ ${packageName}: ${command} failed with code ${code}`);
36 console.error(`stderr: ${stderr}`);
37 reject(
38 new Error(`${packageName} failed: ${command} (exit code ${code})`),
39 );
40 }
41 });
42
43 child.on("error", (error) => {
44 console.error(`❌ ${packageName}: Failed to start ${command}:`, error);
45 reject(error);
46 });
47 });
48}
49
50// Helper function to build a package (install + build)
51async function buildPackage(packageName, cleanNodeModules = false) {
52 const packagePath = path.join(__dirname, "..", "packages", packageName);
53
54 if (!fs.existsSync(packagePath)) {
55 throw new Error(`Package directory not found: ${packagePath}`);
56 }
57
58 if (cleanNodeModules) {
59 const nodeModulesPath = path.join(packagePath, "node_modules");
60 if (fs.existsSync(nodeModulesPath)) {
61 console.log(`🧹 Cleaning node_modules for ${packageName}`);
62 await fsPromises.rm(nodeModulesPath, { recursive: true, force: true });
63 }
64 }
65
66 await runCommand(npmInstallCmd, packagePath, `${packageName} (install)`);
67
68 return runCommand("npm run build", packagePath, `${packageName} (build)`);
69}
70
71async function buildPackagesInParallel(packages, cleanNodeModules = false) {
72 const buildPromises = packages.map((pkg) =>
73 buildPackage(pkg, cleanNodeModules),
74 );
75 return Promise.all(buildPromises);
76}
77
78async function main() {
79 try {
80 console.log("🚀 Starting package builds...\n");
81
82 // Phase 1: Build config-types (foundation - no dependencies)
83 await buildPackagesInParallel(["config-types"]);
84
85 // Phase 2: Build packages that depend on config-types
86 await buildPackagesInParallel(["fetch", "config-yaml", "llm-info"]);
87
88 // Phase 3: Build packages that depend on other local packages
89 await buildPackagesInParallel(["openai-adapters", "continue-sdk"]);
90
91 console.log("🎉 All packages built successfully!");
92 } catch (error) {
93 console.error("💥 Build failed:", error.message);
94 process.exit(1);
95 }
96}
97
98if (require.main === module) {
99 main();
100}