-
Notifications
You must be signed in to change notification settings - Fork 29
/
cli.js
executable file
·93 lines (72 loc) · 2.66 KB
/
cli.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bun
import { promises as fs } from 'node:fs'
import { sep, join } from 'node:path'
import * as p from '@clack/prompts'
import color from 'picocolors';
async function copyTemplate(name, to) {
const s = p.spinner()
s.start('Copying template')
const root = new URL('.', import.meta.url).pathname
const src = join(root, name)
// const filter = path => !path.includes(sep + '.')
await fs.cp(src, to, { recursive: true, force: true })
s.stop(`Copied template ${name} to ${to}`)
}
// empty space
console.clear()
console.log('')
p.intro(color.bgCyan(color.black(' create-nue ')))
// project name
const to = await p.text({
message: 'Your project directory name:',
placeholder: 'my-app',
initialValue: '',
validate(name) {
if (!name.trim()) return `Project name is required`
},
})
if (p.isCancel(to)) {
p.cancel('No project name given. Setup cancelled')
process.exit(0)
}
// required for Bun
await void(0)
// select template
const template = await p.select({
message: 'Pick a template',
options: [
{ value: 'aimee-app', label: 'Aimee website template', hint: 'https://aimee-app.nuejs.org'},
{ value: 'sofa-company', label: 'Sofa Company website', hint: 'https://sofa-company.nuejs.org'},
{ value: 'mona-editor', label: 'Mona Editor website', hint: 'https://mona-editor.nuejs.org'},
{ value: 'nuemark-demo', label: 'Nuemark demo', hint: 'A rich, editable landing page'},
{ value: 'skeleton-site', label: 'Skeleton website', hint: '"Hello, World!" only'},
{ value: 'skeleton-app', label: 'Skeleton app', hint: '"Hello, World!" only'},
{ value: 'hotreload-demo', label: 'Hot-reload demo', hint: 'From zero to fully-designed'},
{ value: 'simple-blog', label: 'Simple blog', hint: 'The blog from Nue tutorial' },
{ value: 'simple-app', label: 'Simple app', hint: 'The single-page app from Nue tutorial' },
{ value: 'simple-crm', label: 'Simple CRM', hint: 'A more complex single-page application'},
{ value: '', label: 'Empty directory', hint: 'Start from scratch'},
],
})
if (p.isCancel(template)) {
p.cancel('No template given. Setup cancelled')
process.exit(0)
}
if (template) {
await copyTemplate(template, to)
} else {
await fs.mkdir(to, { recursive: true })
p.log.step(`Created empty directory: ${color.cyan(to)}`)
}
const nextSteps = [
'# install Nue (if not done yet)',
color.white('bun install nuekit --global'),
'',
'# switch to project directory',
color.white(`cd ${to}`),
'',
'# start developing your app',
color.white(`nue`)
]
p.note(nextSteps.join(' \n'), 'Next steps.');
p.outro(`Problems? ${color.underline(color.cyan('https://github.com/nuejs/nuejs/issues'))}`)