-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.ts
53 lines (48 loc) · 1.25 KB
/
clean.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
/** clean this project's temporary directories and files. */
const
shell_args = new Set(Deno.args),
dryrun = shell_args.delete("--dryrun"),
dirs_only = shell_args.delete("--dirs-only"),
files_only = shell_args.delete("--files-only"),
shell_rest_args = [...shell_args]
const delete_dir_list: string[] = [
"./docs/",
"./dist/",
"./npm/",
"./node_modules/",
"./temp/",
/*
"./backup/",
*/
]
const delete_file_list: string[] = [
"./deno.d.ts",
"./package.json",
"./tsconfig.json",
"./typedoc.json",
/*
"deno.lock",
*/
]
if (dirs_only || !files_only) {
await Promise.all(delete_dir_list.map(async (dir_path) => {
try {
const stat = await Deno.stat(dir_path)
if (stat.isDirectory) {
console.log("[in-fs] deleting directory:", dir_path)
if (!dryrun) { await Deno.remove(dir_path, { recursive: true }) }
}
} catch (error) { console.warn("directory does not exist:", dir_path) }
}))
}
if (files_only || !dirs_only) {
await Promise.all(delete_file_list.map(async (file_path) => {
try {
const stat = await Deno.stat(file_path)
if (stat.isFile) {
console.log("[in-fs] deleting file:", file_path)
if (!dryrun) { await Deno.remove(file_path) }
}
} catch (error) { console.warn("file does not exist:", file_path) }
}))
}