forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprojects.mjs
More file actions
58 lines (48 loc) · 1.76 KB
/
projects.mjs
File metadata and controls
58 lines (48 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { resolve } from "path";
import { findUpRoot } from "./findUpDir.mjs";
import cmdLineOptions from "./options.mjs";
import { Debouncer, exec } from "./utils.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(...(cmdLineOptions.bundle ? [] : ["--emitDeclarationOnly", "false"]), ...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", "--preserveWatchOutput", ...projects));
/**
* @param {string} project
*/
export const watchProject = (project) => projectWatcher.enqueue(project);