-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
68 lines (59 loc) · 2.38 KB
/
gulpfile.js
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
59
60
61
62
63
64
65
66
67
68
import gulp from "gulp";
import {spawn} from "node:child_process";
import {readdir, readFile, rm, writeFile} from "node:fs/promises";
import {join} from "node:path";
import pkg from "./package.json" with {type: "json"};
/** Builds the project. */
export async function build() {
const file = "src/client.ts";
await writeFile(file, (await readFile(file, "utf8")).replace(/#version = "\d+(\.\d+){2}"/, `#version = "${pkg.version}"`));
await npx("tsc", "--build", "src/tsconfig.json");
}
/** Deletes all generated files. */
export async function clean() {
await rm("lib", {force: true, recursive: true});
for (const file of await readdir("var")) if (file != ".gitkeep") await rm(join("var", file), {recursive: true});
}
/** Builds the documentation. */
export async function doc() {
await npx("typedoc", "--options", "etc/typedoc.js");
}
/** Performs the static analysis of source code. */
export async function lint() {
await npx("tsc", "--build", "tsconfig.json", "--noEmit");
await npx("eslint", "--config=etc/eslint.js", "gulpfile.js", "example", "src", "test");
}
/** Publishes the package. */
export async function publish() {
await npx("gulp");
for (const registry of ["https://registry.npmjs.org", "https://npm.pkg.github.com"]) await run("npm", "publish", `--registry=${registry}`);
for (const action of [["tag"], ["push", "origin"]]) await run("git", ...action, `v${pkg.version}`);
}
/** Runs the test suite. */
export async function test() {
await npx("tsc", "--build", "src/tsconfig.json", "--sourceMap");
await run("node", "--enable-source-maps", "--test");
}
/** The default task. */
export default gulp.series(clean, build);
/**
* Executes a command from a local package.
* @param {string} command The command to run.
* @param {...string} args The command arguments.
* @return {Promise<void>} Resolves when the command is terminated.
*/
function npx(command, ...args) {
return run("npm", "exec", "--", command, ...args);
}
/**
* Spawns a new process using the specified command.
* @param {string} command The command to run.
* @param {...string} args The command arguments.
* @return {Promise<void>} Resolves when the command is terminated.
*/
function run(command, ...args) {
return new Promise((resolve, reject) => {
const process = spawn(command, args, {shell: true, stdio: "inherit"});
process.on("close", code => code ? reject(Error([command, ...args].join(" "))) : resolve());
});
}