-
Notifications
You must be signed in to change notification settings - Fork 22
/
buildRuntime.ts
75 lines (72 loc) · 2.14 KB
/
buildRuntime.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
63
64
65
66
67
68
69
70
71
72
73
74
75
import { ensureDir } from "https://deno.land/std@0.175.0/fs/mod.ts";
import { walk } from "https://deno.land/std@0.175.0/fs/walk.ts";
import { dirname, join } from "https://deno.land/std@0.175.0/path/mod.ts";
import { replaceTsFileExtensionInImportStatement } from "../../misc/compat/tsc.ts";
import { BuildConfig, NameAndVersion } from "./index.ts";
if (import.meta.main) {
buildRuntime({
name: "@pbkit/runtime",
version: "0.0.0",
dist: "tmp/npm/runtime",
tmp: "tmp/npm/tmp/runtime",
});
}
export default async function buildRuntime(config: BuildConfig) {
const packageJson = getPackageJson(config);
const tsDir = `${config.tmp}/ts`;
const runtimeDir = `${tsDir}/core/runtime`;
await ensureDir(config.dist);
await Deno.writeTextFile(
`${config.dist}/package.json`,
JSON.stringify(packageJson, null, 2) + "\n",
);
{ // copy runtime files
const entries = walk("core/runtime", { includeDirs: false, exts: [".ts"] });
for await (const { path: fromPath } of entries) {
if (fromPath.endsWith(".test.ts")) continue;
if (/\bdeno\b/.test(fromPath)) continue;
const toPath = join(tsDir, fromPath);
await ensureDir(dirname(toPath));
const code = await Deno.readTextFile(fromPath);
await Deno.writeTextFile(
toPath,
replaceTsFileExtensionInImportStatement(code, ""),
);
}
}
{ // tsc
const entries = walk(runtimeDir, { includeDirs: false, exts: [".ts"] });
const tsFiles: string[] = [];
for await (const { path } of entries) tsFiles.push(path);
await Deno.run({
cmd: [
"tsc",
"-m",
"commonjs",
"--target",
"es2019",
"--lib",
"es2019,dom",
"--declaration",
"--rootDir",
runtimeDir,
"--outDir",
config.dist,
...tsFiles,
],
}).status();
}
}
export function getPackageJson(config: NameAndVersion) {
const { name, version } = config;
return {
name,
version,
author: "JongChan Choi <jong@chan.moe>",
license: "(MIT OR Apache-2.0)",
repository: {
type: "git",
url: "git+https://github.com/pbkit/pbkit.git",
},
};
}