TypeScript/scripts/build/projects.mjs
Jake Bailey 4139807e75 Add build via esbuild
This configures the existing build tasks to use esbuild by default. If
using the plain files is desired, passing `--bundle=false` will build
using plain files and still produce a runnable system.

This is only a basic build; a more efficient build is provided later
when gulp is replaced by hereby.
2022-11-07 13:34:44 -08:00

58 lines
1.7 KiB
JavaScript

import { exec, Debouncer } from "./utils.mjs";
import { resolve } from "path";
import { findUpRoot } from "./findUpDir.mjs";
import cmdLineOptions from "./options.mjs";
class ProjectQueue {
/**
* @param {(projects: string[]) => Promise<any>} action
*/
constructor(action) {
/** @type {string[] | undefined} */
this._projects = undefined;
this._debouncer = new Debouncer(100, async () => {
const projects = this._projects;
if (projects) {
this._projects = undefined;
await action(projects);
}
});
}
/**
* @param {string} project
*/
enqueue(project) {
if (!this._projects) this._projects = [];
this._projects.push(project);
return this._debouncer.enqueue();
}
}
const execTsc = (/** @type {string[]} */ ...args) =>
exec(process.execPath,
[resolve(findUpRoot(), cmdLineOptions.lkg ? "./lib/tsc.js" : "./built/local/tsc.js"),
"-b", ...args],
{ hidePrompt: true });
const projectBuilder = new ProjectQueue((projects) => execTsc(...projects));
/**
* @param {string} project
*/
export const buildProject = (project) => projectBuilder.enqueue(project);
const projectCleaner = new ProjectQueue((projects) => execTsc("--clean", ...projects));
/**
* @param {string} project
*/
export const cleanProject = (project) => projectCleaner.enqueue(project);
const projectWatcher = new ProjectQueue((projects) => execTsc("--watch", ...projects));
/**
* @param {string} project
*/
export const watchProject = (project) => projectWatcher.enqueue(project);