/
compile-tests.ts
62 lines (54 loc) · 1.29 KB
/
compile-tests.ts
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
import { promises as fs } from "fs";
import * as JSONC from "jsonc-parser";
import * as tsc from "tsc-prog";
/**
* The script.
*/
async function run() {
transpileTests();
await Promise.all([createTestsTsConfig(), createTestsHelpersTsConfig()]);
}
/**
* Transpile the tests.
*/
function transpileTests() {
const program = tsc.createProgramFromConfig({
basePath: `${process.cwd()}/tests`,
configFilePath: "tsconfig.json",
});
tsc.emit(program, {
clean: { outDir: true },
});
}
/**
* Create a suitable "build/tests/tsconfig.json" file.
*/
async function createTestsTsConfig() {
const testsTsConfig = JSONC.parse(
await fs.readFile("tests/tsconfig.json", { encoding: "utf-8" })
);
const updatedTestsTsConfig = {
...testsTsConfig,
extends: `../${testsTsConfig.extends}`,
compilerOptions: {
...testsTsConfig.compilerOptions,
baseUrl: "..",
},
};
return fs.writeFile(
"build/tests/tsconfig.json",
JSON.stringify(updatedTestsTsConfig, null, 2),
{ encoding: "utf-8" }
);
}
/**
* Create a suitable "build/tests/helpers/tsconfig.json" file.
*/
async function createTestsHelpersTsConfig() {
return fs.copyFile(
"tests/helpers/test-tsconfig.json",
"build/tests/helpers/test-tsconfig.json"
);
}
// Run the script.
void run();