-
Notifications
You must be signed in to change notification settings - Fork 2
/
clean.ts
81 lines (73 loc) · 1.9 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/** clean the project directory */
import { walkDir } from "./build_tools.ts"
const
shell_args = new Set(Deno.args),
log_only = shell_args.delete("--log-only"),
dirs_only = shell_args.delete("--dirs-only"),
files_only = shell_args.delete("--files-only"),
all_js_files = shell_args.delete("--js-only"),
shell_rest_args = [...shell_args]
const delete_file_list: string[] = [
"./deno.d.ts",
// "./deno.lock",
"./package.json",
"./tsconfig.json",
"./typedoc.json",
]
const delete_dir_list: string[] = [
// "./backup",
"./docs/",
"./dist/",
"./npm/",
"./node_modules/",
"./temp/",
]
const delete_js_in_dir_list: string[] = [
"./dist/"
]
let stat: Deno.FileInfo
if (dirs_only || !(files_only || all_js_files)) {
for (const dir_path of delete_dir_list) {
try { stat = await Deno.stat(dir_path) }
catch (error) { continue }
if (stat.isDirectory) {
console.log("deleting directory:", dir_path)
if (!log_only) {
await Deno.remove(dir_path, { recursive: true })
}
}
}
}
if (files_only || !(dirs_only || all_js_files)) {
for (const file_path of delete_file_list) {
try { stat = await Deno.stat(file_path) }
catch (error) { continue }
if (stat.isFile) {
console.log("deleting file:", file_path)
if (!log_only) {
await Deno.remove(file_path, { recursive: true })
}
}
}
}
if (all_js_files || !(dirs_only || files_only)) {
const js_files = (await Promise.all(delete_js_in_dir_list.map(async (js_dir) => {
const js_files_in_dir: string[] = []
try { stat = await Deno.stat(js_dir) }
catch (error) { return js_files_in_dir }
if (stat.isDirectory) {
for await (const { path } of walkDir(js_dir, { includeDirs: false })) {
if (path.endsWith(".js")) {
js_files_in_dir.push(path)
}
}
}
return js_files_in_dir
}))).flat(1)
for (const js_path of js_files) {
console.log("deleting javascript:", js_path)
if (!log_only) {
await Deno.remove(js_path)
}
}
}