-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
41 lines (32 loc) · 1.18 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
#!/usr/bin/env bun
// Load env
import { $ } from 'bun'
import fs from 'node:fs'
import path from 'node:path'
import { logger } from 'toolbx'
const work_dir = process.cwd()
const assignDir = (Bun.argv.slice(2))[0]
let scaffold = work_dir
if (assignDir) scaffold = assignDir
scaffold = path.resolve(scaffold)
// Start ricing process
if (fs.existsSync(scaffold)) {
if (!(fs.readdirSync(scaffold).length === 0)) { logger(`Directory not empty, abort`, 2); process.exit(1) } // Handle dir is not empty
}
// Git clone the spin-up template
try {
await $`git clone https://github.com/kwaitsing/urn-spinup-template.git --depth 1 ${scaffold}`.quiet()
await $`cd ${scaffold} && bun install`.quiet()
// Modify the template
fs.rmSync(`${scaffold}/.git`, { recursive: true, force: true })
const dirName = path.basename(scaffold)
let contents = await Bun.file(`${scaffold}/package.json`).json();
contents.name = dirName
await Bun.write(`${scaffold}/package.json`, JSON.stringify(contents, null, 2));
} catch (err) {
logger(`Something went wrong ${err}`, 2)
}
logger(`Successfully bootstrap the URN instance
cd ${scaffold}
bun run dev
To start the dev server`, 1)