-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
64 lines (57 loc) · 1.91 KB
/
index.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
import * as path from 'https://deno.land/std@0.170.0/path/mod.ts';
import type { IConfig } from './index.d.ts'
import * as _groups from './groups.js'
import * as _credits from './credits.js'
import * as generate from './src/generate.ts'
const exists = async (filename: string): Promise<boolean> => {
try {
await Deno.stat(filename);
// successful, file or directory must exist
return true;
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
// file or directory does not exist
return false;
} else {
// unexpected error, maybe permissions, pass it along
throw error;
}
}
};
let decoder = new TextDecoder('utf-8')
export const config: IConfig = {
imagePath: path.resolve('./img/'),
distPath: path.resolve('./dist/'),
groups: _groups.data,
credits: _credits.data,
headerContent: decoder.decode(Deno.readFileSync('./header.html')),
footerContent: decoder.decode(Deno.readFileSync('./footer.html'))
}
console.log(`cwd: ` + Deno.cwd());
console.log(`Files in ${path.resolve('./')}`)
for (let item of Deno.readDirSync(path.resolve('./')))
{
console.log(`- ${item.name}` + (item.isDirectory ? ' (directory)' : ''))
}
try
{
Deno.mkdirSync(config.distPath);
}
// don't throw :3
catch (e) {console.error(`Something fucked up when creating ${config.distPath}`, e);}
console.log(`Reading all files in ${config.distPath}`);
for (let item of Deno.readDirSync(config.distPath))
{
if (!item.isFile && item.name != '.gitkeep')
continue;
Deno.removeSync(path.join(config.distPath, item.name))
}
let content = generate.run()
let encoder = new TextEncoder()
Deno.writeFileSync('./dist/index.html', encoder.encode(content))
for (let item of Deno.readDirSync(config.imagePath))
{
Deno.copyFileSync(
path.join(config.imagePath, item.name),
path.join(config.distPath, item.name))
}