-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
42 lines (33 loc) · 960 Bytes
/
utils.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
export type NameMungFn = (value: string, locale?: string) => string;
export class FileWriter {
content: string[] = [];
imports: string[] = [];
constructor(readonly path: string, readonly verbose: boolean) {
if (verbose) {
console.log(`Writing ${path}...`);
}
this.content = [];
}
register_import(s: string) {
if( !this.imports.includes(s) ) {
this.imports.push(s)
}
}
write(s: string) {
// Deno.stderr.writeSync(new TextEncoder().encode(s))
// console.log(s)
this.content.push(s);
}
cwrite(f: boolean, s: string) {
if( f ) {
this.content.push(s);
}
}
close(): Promise<void|number> {
if( this.path === "-" ) {
Deno.stdout.writeSync(new TextEncoder().encode(this.imports.join("")))
return Deno.stdout.write(new TextEncoder().encode(this.content.join("")))
}
return Deno.writeTextFile(this.path, this.imports.join("") + this.content.join(""));
}
}