Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Simple Init UI #47

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions cli/init.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Confirm, Input } from 'https://deno.land/x/cliffy/prompt/mod.ts'
import { gzipDecode } from 'https://deno.land/x/[email protected]/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',
Expand Down Expand Up @@ -44,18 +46,18 @@ Options:

export default async function (appDir: string, options: Record<string, string | boolean>) {
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
Expand All @@ -66,9 +68,11 @@ export default async function (appDir: string, options: Record<string, string |
}
}

await ensureDir(path.join(appDir, '.vscode'))
await Deno.writeTextFile(path.join(appDir, '.vscode', 'extensions.json'), JSON.stringify(vscExtensions, undefined, 4))
await Deno.writeTextFile(path.join(appDir, '.vscode', 'settings.json'), JSON.stringify(vscSettings, undefined, 4))
if (await Confirm.prompt('Are you using Visual Studio Code?')) {
await ensureDir(path.join(appDir, '.vscode'))
await Deno.writeTextFile(path.join(appDir, '.vscode', 'extensions.json'), JSON.stringify(vscExtensions, undefined, 4))
await Deno.writeTextFile(path.join(appDir, '.vscode', 'settings.json'), JSON.stringify(vscSettings, undefined, 4))
}
await Deno.writeTextFile(path.join(appDir, '.gitignore'), gitignore.join('\n'))
await Deno.writeTextFile(path.join(appDir, 'import_map.json'), JSON.stringify({ imports: {} }, undefined, 4))

Expand Down