@bb-labs/bldr 0.0.1 → 0.0.3
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 +46 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -134,13 +134,13 @@ async function main() {
|
|
|
134
134
|
const rootDirAbs = path.isAbsolute(cfg.rootDir) ? cfg.rootDir : path.resolve(cfg.configDir, cfg.rootDir);
|
|
135
135
|
const outDirAbs = path.isAbsolute(cfg.outDir) ? cfg.outDir : path.resolve(cfg.configDir, cfg.outDir);
|
|
136
136
|
console.log([
|
|
137
|
-
`\n[
|
|
138
|
-
`[
|
|
139
|
-
`[
|
|
140
|
-
`[
|
|
137
|
+
`\n[bldr] project: ${rel(cwd, tsconfigPath)}`,
|
|
138
|
+
`[bldr] rootDir : ${rel(cwd, rootDirAbs)}`,
|
|
139
|
+
`[bldr] outDir : ${rel(cwd, outDirAbs)}`,
|
|
140
|
+
`[bldr] mode : ${args.watch ? "watch" : "build"}\n`,
|
|
141
141
|
].join("\n"));
|
|
142
142
|
// Clean the output directory first
|
|
143
|
-
console.log(`[
|
|
143
|
+
console.log(`[bldr] cleaning output directory...`);
|
|
144
144
|
await rmIfExists(outDirAbs);
|
|
145
145
|
const tscArgs = ["-p", tsconfigPath];
|
|
146
146
|
const aliasArgs = ["-p", tsconfigPath];
|
|
@@ -152,7 +152,7 @@ async function main() {
|
|
|
152
152
|
}
|
|
153
153
|
catch (error) {
|
|
154
154
|
// Clean up partial output on build failure
|
|
155
|
-
console.error(`[
|
|
155
|
+
console.error(`[bldr] build failed, cleaning output directory...`);
|
|
156
156
|
await rmIfExists(outDirAbs);
|
|
157
157
|
throw error;
|
|
158
158
|
}
|
|
@@ -165,9 +165,9 @@ async function main() {
|
|
|
165
165
|
await run("tsc-alias", aliasArgs, cwd);
|
|
166
166
|
}
|
|
167
167
|
catch (error) {
|
|
168
|
-
console.error(`[
|
|
168
|
+
console.error(`[bldr] initial build failed: ${error}`);
|
|
169
169
|
// Continue in watch mode even if initial build fails
|
|
170
|
-
console.log(`[
|
|
170
|
+
console.log(`[bldr] continuing in watch mode...`);
|
|
171
171
|
}
|
|
172
172
|
// 2) Start watchers
|
|
173
173
|
const tscWatch = spawnLongRunning("tsc", [...tscArgs, "-w"], cwd);
|
|
@@ -211,7 +211,7 @@ async function main() {
|
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
catch (error) {
|
|
214
|
-
console.error(`[
|
|
214
|
+
console.error(`[bldr] error handling file deletion ${absPath}: ${error}`);
|
|
215
215
|
}
|
|
216
216
|
});
|
|
217
217
|
srcWatcher.on("unlinkDir", async (absDir) => {
|
|
@@ -219,33 +219,53 @@ async function main() {
|
|
|
219
219
|
await cleaner.removeOutDirForSourceDir(absDir);
|
|
220
220
|
}
|
|
221
221
|
catch (error) {
|
|
222
|
-
console.error(`[
|
|
222
|
+
console.error(`[bldr] error handling directory deletion ${absDir}: ${error}`);
|
|
223
223
|
}
|
|
224
224
|
});
|
|
225
225
|
// TypeScript compiler handles additions and changes automatically
|
|
226
226
|
const shutdown = async () => {
|
|
227
|
-
console.log("\n[
|
|
227
|
+
console.log("\n[bldr] shutting down...");
|
|
228
|
+
// Close file watcher
|
|
228
229
|
try {
|
|
229
|
-
srcWatcher.close();
|
|
230
|
-
console.log("[
|
|
230
|
+
await srcWatcher.close();
|
|
231
|
+
console.log("[bldr] src watcher closed");
|
|
231
232
|
}
|
|
232
233
|
catch (error) {
|
|
233
|
-
console.error(`[
|
|
234
|
+
console.error(`[bldr] error closing src watcher: ${error}`);
|
|
234
235
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
// Kill child processes
|
|
237
|
+
const killPromises = [];
|
|
238
|
+
if (!tscWatch.killed) {
|
|
239
|
+
killPromises.push(new Promise((resolve) => {
|
|
240
|
+
tscWatch.on("exit", () => resolve());
|
|
241
|
+
tscWatch.kill();
|
|
242
|
+
// Force kill after 5 seconds
|
|
243
|
+
setTimeout(() => {
|
|
244
|
+
if (!tscWatch.killed) {
|
|
245
|
+
tscWatch.kill("SIGKILL");
|
|
246
|
+
}
|
|
247
|
+
resolve();
|
|
248
|
+
}, 5000);
|
|
249
|
+
}));
|
|
250
|
+
console.log("[bldr] killing tsc watcher...");
|
|
241
251
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
252
|
+
if (!aliasWatch.killed) {
|
|
253
|
+
killPromises.push(new Promise((resolve) => {
|
|
254
|
+
aliasWatch.on("exit", () => resolve());
|
|
255
|
+
aliasWatch.kill();
|
|
256
|
+
// Force kill after 5 seconds
|
|
257
|
+
setTimeout(() => {
|
|
258
|
+
if (!aliasWatch.killed) {
|
|
259
|
+
aliasWatch.kill("SIGKILL");
|
|
260
|
+
}
|
|
261
|
+
resolve();
|
|
262
|
+
}, 5000);
|
|
263
|
+
}));
|
|
264
|
+
console.log("[bldr] killing tsc-alias watcher...");
|
|
248
265
|
}
|
|
266
|
+
// Wait for all child processes to exit
|
|
267
|
+
await Promise.all(killPromises);
|
|
268
|
+
console.log("[bldr] all processes cleaned up");
|
|
249
269
|
process.exit(0);
|
|
250
270
|
};
|
|
251
271
|
process.on("SIGINT", shutdown);
|