-
Notifications
You must be signed in to change notification settings - Fork 0
/
deno.js
46 lines (43 loc) · 1.4 KB
/
deno.js
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
const fs = require("fs/promises")
async function copyFile(dst, src) {
let text = await fs.readFile(src, {
encoding: 'utf8'
})
text = text.replace(/from[ ]+\'((\.{1,2}\/)+[a-zA-Z0-9\/_]+)\'/g, "from '$1.ts'")
text = text.replace(/from[ ]+\"((\.{1,2}\/)+[a-zA-Z0-9\/_]+)\"/g, "from '$1.ts'")
await fs.writeFile(dst, text)
}
async function copyDir(dst, src) {
await fs.mkdir(dst, 0o775)
const files = await fs.readdir(src)
for (const file of files) {
if (file.endsWith('.js')) {
continue
}
if (file.endsWith('test.ts')) {
continue
} else if (file.endsWith('.ts')) {
await copyFile(dst + '/' + file, src + '/' + file)
} else {
await copyDir(dst + '/' + file, src + '/' + file)
}
}
}
async function main() {
let dst = __dirname + '/deno'
try {
await fs.rm(dst, {
recursive: true,
})
} catch (_) { }
const src = __dirname + '/src'
await copyDir(dst, src)
await fs.mkdir(dst + '/.vscode')
await fs.writeFile(dst + '/.vscode/settings.json', JSON.stringify({
"deno.enable": true
}, undefined, ' '))
await copyFile(`${dst}/channel_bench_test.ts`, `${__dirname}/src/channel_bench_test.ts`)
await copyFile(`${dst}/README.md`, `${__dirname}/README.md`)
await copyFile(`${dst}/LICENSE`, `${__dirname}/LICENSE`)
}
main()