diff --git a/cli/init.ts b/cli/init.ts index 018dd4a65..8382c2b4d 100644 --- a/cli/init.ts +++ b/cli/init.ts @@ -1,9 +1,11 @@ +import { Confirm, Input } from 'https://deno.land/x/cliffy/prompt/mod.ts' import { gzipDecode } from 'https://deno.land/x/wasm_gzip@v1.0.0/mod.ts' import { ensureTextFile } from '../fs.ts' import log from '../log.ts' import { colors, ensureDir, fromStreamReader, path, Untar } from '../std.ts' import util from '../util.ts' + const gitignore = [ '.DS_Store', 'Thumbs.db', @@ -44,18 +46,18 @@ Options: export default async function (appDir: string, options: Record) { const rev = 'master' + const templateRepo = await Input.prompt({ message: 'What Aleph.js Github Template Repository Do You Want To Use (Press Enter To Use Default)?', default: 'aleph.js/alephjs-templates' }) log.info('Downloading template...') - const resp = await fetch('https://codeload.github.com/alephjs/alephjs-templates/tar.gz/' + rev) + const resp = await fetch(`https://codeload.github.com/${templateRepo}/tar.gz/${rev}`) const gzData = await Deno.readAll(fromStreamReader(resp.body!.getReader())) log.info('Saving template...') const tarData = gzipDecode(gzData) const entryList = new Untar(new Deno.Buffer(tarData)) - // todo: add template select ui - let template = 'hello-world' + const template = await Input.prompt({ message: 'What Aleph.js Template Do You Want To Use (Press Enter To Use Default)?', default: '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.fileName.startsWith(`${templateRepo.match(/([^/]+$)/i)}-${rev}/${template}/`)) { + const fp = path.join(appDir, util.trimPrefix(entry.fileName, `${templateRepo.match(/([^/]+$)/i)}-${rev}/${template}/`)) if (entry.type === 'directory') { await ensureDir(fp) continue @@ -66,9 +68,11 @@ export default async function (appDir: string, options: Record