Skip to content

Commit

Permalink
feat: gh create
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Feb 19, 2025
1 parent bb650fd commit af63c8b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/nuekit/src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ async function serve(args) {

export async function create(args = {}) {
if (!args.name) args.name = 'simple-blog'
if (!args.root) args.root = args.name
if (!args.root) args.root = args.name.replaceAll('/', '-')

// debug mode with: `nue create test`
args.debug = args.name == 'test'
if (args.debug) args.name = 'simple-blog'

const { debug, name, root } = args

// TODO: needs more checks
const is_gh = name.includes('/')

// check if template exists
if (!Object.keys(templates).includes(name)){
if (!is_gh && !Object.keys(templates).includes(name)){
console.error(`Template "${name}" does not exist!`)
console.error('Available templates:')
for (const t of Object.keys(templates)) console.error(' -', t)
Expand All @@ -51,8 +54,8 @@ export async function create(args = {}) {

// download archive
console.info('Loading template...')
const archive_name = join(root, `${name}-source.tar.gz`)
const archive_web = `https://${name}.nuejs.org/${debug ? 'test' : 'source'}.tar.gz`
const archive_name = join(root, 'source.tar.gz')
const archive_web = is_gh ? `https://api.github.com/repos/${name}/tarball` : `https://${name}.nuejs.org/${debug ? 'test' : 'source'}.tar.gz`
const archive = await fetch(archive_web)

// catch download issues
Expand All @@ -66,5 +69,6 @@ export async function create(args = {}) {
await fs.rm(archive_name)

// serve
return await serve(args)
console.info(`Created template '${name}' to '${root}'.`)
if (!is_gh) return await serve(args)
}

0 comments on commit af63c8b

Please sign in to comment.