-
Notifications
You must be signed in to change notification settings - Fork 170
/
init.ts
38 lines (32 loc) · 1.34 KB
/
init.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
import { ensureDir, ensureFile, fromStreamReader, gzipDecode, path, Untar } from '../deps.ts'
import util from '../util.ts'
export const helpMessage = `Initiate a new aleph app.
Usage:
aleph init <dir> [...options]
<dir> represents the directory of the aleph app,
if the <dir> is empty, the current directory will be used.
Options:
-h, --help Prints help message
`
export default async function (appDir: string, options: Record<string, string | boolean>) {
const rev = 'master'
const resp = await fetch('https://codeload.github.com/postui/alephjs-templates/tar.gz/' + rev)
const gzData = await Deno.readAll(fromStreamReader(resp.body!.getReader()))
const tarData = gzipDecode(gzData)
const entryList = new Untar(new Deno.Buffer(tarData))
// todo: add template select ui
let template = 'hello-world'
for await (const entry of entryList) {
if (entry.fileName.startsWith(`alephjs-templates-${rev}/${template}/`)) {
const fp = path.join(appDir, util.trimPrefix(entry.fileName, `alephjs-templates-${rev}/${template}/`))
if (entry.type === 'directory') {
await ensureDir(fp)
continue
}
await ensureFile(fp)
const file = await Deno.open(fp, { write: true })
await Deno.copy(entry, file)
}
}
Deno.exit(0)
}