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 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
- p.intro('Create Sygnal App')
71
+ const args = parseArgs(process.argv)
28
72
 
29
- // Project name — use CLI arg if provided
30
- const argName = process.argv[2]
73
+ if (args.help) {
74
+ printHelp()
75
+ process.exit(0)
76
+ }
31
77
 
32
- const projectName = argName || await p.text({
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
- const template = await p.select({
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
- const language = await p.select({
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
- const installDeps = await p.confirm({
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
- p.cancel(`Directory "${projectName}" already exists and is not empty.`)
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
- s.stop('Failed to install dependencies. Run `npm install` manually.')
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
- p.note([
123
- `cd ${relative}`,
124
- 'npm run dev',
125
- ].join('\n'), 'Next steps')
194
+ if (interactive) {
195
+ p.note([
196
+ `cd ${relative}`,
197
+ 'npm run dev',
198
+ ].join('\n'), 'Next steps')
126
199
 
127
- p.outro('Happy building!')
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,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sygnal-app",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Scaffold a new Sygnal project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,7 +9,7 @@
9
9
  "preview": "astro preview"
10
10
  },
11
11
  "dependencies": {
12
- "astro": "^5.0.0",
13
- "sygnal": "^5.1.1"
12
+ "astro": "^6.1.1",
13
+ "sygnal": "^5.2.0"
14
14
  }
15
15
  }
@@ -9,10 +9,10 @@
9
9
  "preview": "astro preview"
10
10
  },
11
11
  "dependencies": {
12
- "astro": "^5.0.0",
13
- "sygnal": "^5.1.1"
12
+ "astro": "^6.1.1",
13
+ "sygnal": "^5.2.0"
14
14
  },
15
15
  "devDependencies": {
16
- "typescript": "^5.4.5"
16
+ "typescript": "^6.0.2"
17
17
  }
18
18
  }
@@ -1,5 +1,5 @@
1
1
  import { xs, ABORT } from 'sygnal'
2
- import type { Component } from 'sygnal'
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 = Component<State, {}, {}, Actions, Calculated>
21
+ type App = RootComponent<State, {}, Actions, Calculated>
22
22
 
23
23
  const App: App = function ({ state }) {
24
24
  return (
@@ -9,10 +9,10 @@
9
9
  "preview": "vike preview"
10
10
  },
11
11
  "dependencies": {
12
- "sygnal": "^5.1.1",
13
- "vike": "^0.4.250"
12
+ "sygnal": "^5.2.0",
13
+ "vike": "^0.4.255"
14
14
  },
15
15
  "devDependencies": {
16
- "vite": "^6.4.1"
16
+ "vite": "^8.0.3"
17
17
  }
18
18
  }
@@ -9,11 +9,11 @@
9
9
  "preview": "vike preview"
10
10
  },
11
11
  "dependencies": {
12
- "sygnal": "^5.1.1",
13
- "vike": "^0.4.250"
12
+ "sygnal": "^5.2.0",
13
+ "vike": "^0.4.255"
14
14
  },
15
15
  "devDependencies": {
16
- "typescript": "^5.4.5",
17
- "vite": "^6.4.1"
16
+ "typescript": "^6.0.2",
17
+ "vite": "^8.0.3"
18
18
  }
19
19
  }
@@ -1,10 +1,10 @@
1
- import type { Component } from 'sygnal'
1
+ import type { RootComponent } from 'sygnal'
2
2
 
3
3
  type State = {
4
4
  description: string
5
5
  }
6
6
 
7
- type Page = Component<State>
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 { Component } from 'sygnal'
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 = Component<State, {}, {}, Actions>
14
+ type Page = RootComponent<State, {}, Actions>
15
15
 
16
16
  const Page: Page = function ({ state }) {
17
17
  return (
@@ -9,9 +9,9 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
- "sygnal": "^5.1.1"
12
+ "sygnal": "^5.2.0"
13
13
  },
14
14
  "devDependencies": {
15
- "vite": "^6.4.1"
15
+ "vite": "^8.0.3"
16
16
  }
17
17
  }
@@ -9,10 +9,10 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
- "sygnal": "^5.1.1"
12
+ "sygnal": "^5.2.0"
13
13
  },
14
14
  "devDependencies": {
15
- "typescript": "^5.4.5",
16
- "vite": "^6.4.1"
15
+ "typescript": "^6.0.2",
16
+ "vite": "^8.0.3"
17
17
  }
18
18
  }
@@ -1,5 +1,5 @@
1
1
  import { xs, ABORT } from 'sygnal'
2
- import type { Component } from 'sygnal'
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 = Component<State, {}, {}, Actions, Calculated>
21
+ type App = RootComponent<State, {}, Actions, Calculated>
22
22
 
23
23
  const App: App = function ({ state }) {
24
24
  return (