-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_2.ts
57 lines (50 loc) · 1.53 KB
/
build_2.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
/** this build process simply transpiles all typescript ".ts" files under the following directories:
* - "./src/js/"
* - "./src/html/"
* to the destination directories:
* - "./dist/${extension_name}/js/"
* - "./dist/${extension_name}/html/"
*/
import { doubleCompileFiles, ensureDir, ensureFile, getDenoJson, pathJoin, walkDir } from "./build_tools.ts"
const
shell_args = new Set(Deno.args),
log_only = shell_args.delete("--log-only"),
shell_rest_args = [...shell_args],
deno_json = await getDenoJson()
// define the typescript source directories, and destination directory
const
src_dir = "./src/",
ts_dirs = [
pathJoin(src_dir, "./js/"),
pathJoin(src_dir, "./html/"),
],
dst_dir = `./dist/${deno_json.name ?? ""}-v${deno_json.version ?? "0.0.0"}/`
if (!log_only) { await ensureDir(dst_dir) }
const ts_files = (await Promise.all(ts_dirs.map(async (ts_dir) => {
const ts_files_in_dir: string[] = []
for await (const { path } of walkDir(ts_dir, { includeDirs: false })) {
if (path.endsWith(".ts")) {
ts_files_in_dir.push(path)
}
}
return ts_files_in_dir
}))).flat(1)
const output_files = await doubleCompileFiles("", dst_dir,
{
entryPoints: ts_files,
outbase: src_dir,
bundle: true,
splitting: true,
platform: "browser",
},
{ minify: true },
)
console.log("writing the following transpiled files:", output_files.map((out_file) => out_file.path))
if (!log_only) {
await Promise.all(output_files.map(
async ({ text, path }, file_number) => {
await ensureFile(path)
await Deno.writeTextFile(path, text)
}
))
}