create-sygnal-app 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +95 -19
- package/package.json +1 -1
- package/template-astro/package.json +2 -2
- package/template-astro-ts/package.json +3 -3
- package/template-astro-ts/src/components/App.tsx +2 -2
- package/template-vike/package.json +3 -3
- package/template-vike-ts/package.json +4 -4
- package/template-vike-ts/pages/about/+Page.tsx +2 -2
- package/template-vike-ts/pages/index/+Page.tsx +2 -2
- package/template-vite/package.json +2 -2
- package/template-vite-ts/package.json +3 -3
- package/template-vite-ts/src/App.tsx +2 -2
package/index.js
CHANGED
|
@@ -23,13 +23,72 @@ const TEMPLATES = {
|
|
|
23
23
|
},
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function parseArgs(argv) {
|
|
27
|
+
const args = { positional: null }
|
|
28
|
+
for (let i = 2; i < argv.length; i++) {
|
|
29
|
+
const arg = argv[i]
|
|
30
|
+
if (arg === '--template' || arg === '-t') {
|
|
31
|
+
args.template = argv[++i]
|
|
32
|
+
} else if (arg.startsWith('--template=')) {
|
|
33
|
+
args.template = arg.slice('--template='.length)
|
|
34
|
+
} else if (arg === '--typescript' || arg === '--ts') {
|
|
35
|
+
args.language = 'ts'
|
|
36
|
+
} else if (arg === '--javascript' || arg === '--js') {
|
|
37
|
+
args.language = 'js'
|
|
38
|
+
} else if (arg === '--no-install') {
|
|
39
|
+
args.install = false
|
|
40
|
+
} else if (arg === '--install') {
|
|
41
|
+
args.install = true
|
|
42
|
+
} else if (arg === '--help' || arg === '-h') {
|
|
43
|
+
args.help = true
|
|
44
|
+
} else if (!arg.startsWith('-')) {
|
|
45
|
+
args.positional = arg
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return args
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function printHelp() {
|
|
52
|
+
console.log(`
|
|
53
|
+
Usage: create-sygnal-app [project-name] [options]
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
-t, --template <name> Template to use: vite, vike, astro
|
|
57
|
+
--ts, --typescript Use TypeScript
|
|
58
|
+
--js, --javascript Use JavaScript
|
|
59
|
+
--install Install dependencies (default)
|
|
60
|
+
--no-install Skip installing dependencies
|
|
61
|
+
-h, --help Show this help message
|
|
62
|
+
|
|
63
|
+
Examples:
|
|
64
|
+
create-sygnal-app my-app --template vite --ts
|
|
65
|
+
create-sygnal-app my-app -t vike --no-install
|
|
66
|
+
npx create-sygnal-app my-app --template astro --js
|
|
67
|
+
`.trim())
|
|
68
|
+
}
|
|
69
|
+
|
|
26
70
|
async function main() {
|
|
27
|
-
|
|
71
|
+
const args = parseArgs(process.argv)
|
|
28
72
|
|
|
29
|
-
|
|
30
|
-
|
|
73
|
+
if (args.help) {
|
|
74
|
+
printHelp()
|
|
75
|
+
process.exit(0)
|
|
76
|
+
}
|
|
31
77
|
|
|
32
|
-
|
|
78
|
+
// Validate --template value if provided
|
|
79
|
+
if (args.template && !TEMPLATES[args.template]) {
|
|
80
|
+
console.error(`Unknown template: "${args.template}". Available templates: ${Object.keys(TEMPLATES).join(', ')}`)
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const interactive = !args.template || !args.language
|
|
85
|
+
|
|
86
|
+
if (interactive) {
|
|
87
|
+
p.intro('Create Sygnal App')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Project name — use positional arg or prompt
|
|
91
|
+
const projectName = args.positional || await p.text({
|
|
33
92
|
message: 'Project name:',
|
|
34
93
|
placeholder: 'my-sygnal-app',
|
|
35
94
|
defaultValue: 'my-sygnal-app',
|
|
@@ -44,7 +103,8 @@ async function main() {
|
|
|
44
103
|
process.exit(0)
|
|
45
104
|
}
|
|
46
105
|
|
|
47
|
-
|
|
106
|
+
// Template — use flag or prompt
|
|
107
|
+
const template = args.template || await p.select({
|
|
48
108
|
message: 'Template:',
|
|
49
109
|
options: Object.entries(TEMPLATES).map(([value, { label, hint }]) => ({
|
|
50
110
|
value,
|
|
@@ -58,7 +118,8 @@ async function main() {
|
|
|
58
118
|
process.exit(0)
|
|
59
119
|
}
|
|
60
120
|
|
|
61
|
-
|
|
121
|
+
// Language — use flag or prompt
|
|
122
|
+
const language = args.language || await p.select({
|
|
62
123
|
message: 'Language:',
|
|
63
124
|
options: [
|
|
64
125
|
{ value: 'js', label: 'JavaScript' },
|
|
@@ -71,7 +132,8 @@ async function main() {
|
|
|
71
132
|
process.exit(0)
|
|
72
133
|
}
|
|
73
134
|
|
|
74
|
-
|
|
135
|
+
// Install — use flag or prompt
|
|
136
|
+
const installDeps = args.install ?? await p.confirm({
|
|
75
137
|
message: 'Install dependencies?',
|
|
76
138
|
initialValue: true,
|
|
77
139
|
})
|
|
@@ -84,14 +146,19 @@ async function main() {
|
|
|
84
146
|
const targetDir = resolve(process.cwd(), projectName)
|
|
85
147
|
|
|
86
148
|
if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
|
|
87
|
-
|
|
149
|
+
const msg = `Directory "${projectName}" already exists and is not empty.`
|
|
150
|
+
if (interactive) {
|
|
151
|
+
p.cancel(msg)
|
|
152
|
+
} else {
|
|
153
|
+
console.error(msg)
|
|
154
|
+
}
|
|
88
155
|
process.exit(1)
|
|
89
156
|
}
|
|
90
157
|
|
|
91
|
-
const s = p.spinner()
|
|
158
|
+
const s = interactive ? p.spinner() : null
|
|
92
159
|
|
|
93
160
|
// Copy template
|
|
94
|
-
s.start('Scaffolding project...')
|
|
161
|
+
if (s) s.start('Scaffolding project...')
|
|
95
162
|
const templateName = language === 'ts' ? `template-${template}-ts` : `template-${template}`
|
|
96
163
|
const templateDir = join(__dirname, templateName)
|
|
97
164
|
copyDir(templateDir, targetDir)
|
|
@@ -103,28 +170,37 @@ async function main() {
|
|
|
103
170
|
pkg.name = basename(projectName)
|
|
104
171
|
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
105
172
|
}
|
|
106
|
-
s.stop('Project scaffolded.')
|
|
173
|
+
if (s) s.stop('Project scaffolded.')
|
|
174
|
+
else console.log(`Scaffolded ${templateName} into ${projectName}`)
|
|
107
175
|
|
|
108
176
|
// Install
|
|
109
177
|
if (installDeps) {
|
|
110
|
-
s.start('Installing dependencies...')
|
|
178
|
+
if (s) s.start('Installing dependencies...')
|
|
179
|
+
else console.log('Installing dependencies...')
|
|
111
180
|
try {
|
|
112
181
|
execSync('npm install', { cwd: targetDir, stdio: 'ignore' })
|
|
113
|
-
s.stop('Dependencies installed.')
|
|
182
|
+
if (s) s.stop('Dependencies installed.')
|
|
183
|
+
else console.log('Dependencies installed.')
|
|
114
184
|
} catch {
|
|
115
|
-
|
|
185
|
+
const msg = 'Failed to install dependencies. Run `npm install` manually.'
|
|
186
|
+
if (s) s.stop(msg)
|
|
187
|
+
else console.error(msg)
|
|
116
188
|
}
|
|
117
189
|
}
|
|
118
190
|
|
|
119
191
|
// Done
|
|
120
192
|
const relative = targetDir === process.cwd() ? '.' : projectName
|
|
121
193
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
194
|
+
if (interactive) {
|
|
195
|
+
p.note([
|
|
196
|
+
`cd ${relative}`,
|
|
197
|
+
'npm run dev',
|
|
198
|
+
].join('\n'), 'Next steps')
|
|
126
199
|
|
|
127
|
-
|
|
200
|
+
p.outro('Happy building!')
|
|
201
|
+
} else {
|
|
202
|
+
console.log(`\nDone. Run:\n cd ${relative}\n npm run dev`)
|
|
203
|
+
}
|
|
128
204
|
}
|
|
129
205
|
|
|
130
206
|
function copyDir(src, dest) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { xs, ABORT } from 'sygnal'
|
|
2
|
-
import type {
|
|
2
|
+
import type { RootComponent } from 'sygnal'
|
|
3
3
|
import TaskItem from './TaskItem'
|
|
4
4
|
|
|
5
5
|
type State = {
|
|
@@ -18,7 +18,7 @@ type Calculated = {
|
|
|
18
18
|
remaining: number
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
type App =
|
|
21
|
+
type App = RootComponent<State, {}, Actions, Calculated>
|
|
22
22
|
|
|
23
23
|
const App: App = function ({ state }) {
|
|
24
24
|
return (
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"preview": "vike preview"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"sygnal": "^5.
|
|
13
|
-
"vike": "^0.4.
|
|
12
|
+
"sygnal": "^5.2.0",
|
|
13
|
+
"vike": "^0.4.255"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"typescript": "^
|
|
17
|
-
"vite": "^
|
|
16
|
+
"typescript": "^6.0.2",
|
|
17
|
+
"vite": "^8.0.3"
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RootComponent } from 'sygnal'
|
|
2
2
|
|
|
3
3
|
type State = {
|
|
4
4
|
description: string
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
type Page =
|
|
7
|
+
type Page = RootComponent<State>
|
|
8
8
|
|
|
9
9
|
const Page: Page = function ({ state }) {
|
|
10
10
|
return (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ABORT } from 'sygnal'
|
|
2
|
-
import type {
|
|
2
|
+
import type { RootComponent } from 'sygnal'
|
|
3
3
|
|
|
4
4
|
type State = {
|
|
5
5
|
count: number
|
|
@@ -11,7 +11,7 @@ type Actions = {
|
|
|
11
11
|
RESET: Event
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
type Page =
|
|
14
|
+
type Page = RootComponent<State, {}, Actions>
|
|
15
15
|
|
|
16
16
|
const Page: Page = function ({ state }) {
|
|
17
17
|
return (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { xs, ABORT } from 'sygnal'
|
|
2
|
-
import type {
|
|
2
|
+
import type { RootComponent } from 'sygnal'
|
|
3
3
|
import TaskItem from './components/TaskItem'
|
|
4
4
|
|
|
5
5
|
type State = {
|
|
@@ -18,7 +18,7 @@ type Calculated = {
|
|
|
18
18
|
remaining: number
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
type App =
|
|
21
|
+
type App = RootComponent<State, {}, Actions, Calculated>
|
|
22
22
|
|
|
23
23
|
const App: App = function ({ state }) {
|
|
24
24
|
return (
|