-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_1.ts
59 lines (52 loc) · 2.11 KB
/
build_1.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
/** this build process simply copies all files under "./src/" to "./dist/${extension_name}/",
* while excluding all typescript ".ts" files.
*/
import { ensureDir, ensureFile, getDenoJson, pathJoin, relativePath, 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 source and destination directories
const
src_dir = "./src/",
dst_dir = `./dist/${deno_json.name ?? ""}-v${deno_json.version ?? "0.0.0"}/`,
// additionl files to copy over to the `dst_dir`
additional_files: Array<[source_root_path: string, destination_relative_path: string]> = [
["./license.md", "./license.md"],
]
const buildManifestJson = (base_manifest_obj: { [key: string]: any }) => {
const
{ author, version, repository, description } = deno_json,
homepage_url = (repository.url as string).replace(/^git\+/, "").replace(/\.git$/, "")
Object.assign(base_manifest_obj, { author, version, description, homepage_url })
delete base_manifest_obj["$schema"]
return base_manifest_obj
}
if (!log_only) { await ensureDir(dst_dir) }
// iterate over the files in the source directory recursively
for await (const { path } of walkDir(src_dir, { includeDirs: false })) {
// ignore typescript files
if (path.endsWith(".ts")) { continue }
const rel_path = relativePath(src_dir, path)
const dst_path = pathJoin(dst_dir, rel_path)
console.log(`copying ${path} to ${dst_path}`)
if (!log_only) {
await ensureFile(dst_path)
if (path.endsWith("manifest.json")) {
// before copying `manifest.json`, merge some of the fields from `deno.json` into it, and delete some other fields
const manifest_obj = buildManifestJson(JSON.parse(await Deno.readTextFile(path)))
await Deno.writeTextFile(dst_path, JSON.stringify(manifest_obj))
} else {
await Deno.copyFile(path, dst_path)
}
}
}
for (const [path, dst_relpath] of additional_files) {
const dst_path = pathJoin(dst_dir, dst_relpath)
console.log(`copying ${path} to ${dst_path}`)
if (!log_only) {
await ensureFile(dst_path)
await Deno.copyFile(path, dst_path)
}
}