@getcortexlabs/create-mavis 0.1.0-rc.12.1 → 0.1.0-rc.13

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.
Files changed (34) hide show
  1. package/README.md +9 -5
  2. package/package.json +1 -1
  3. package/src/adapters.mjs +76 -0
  4. package/src/add-target.mjs +5 -0
  5. package/src/capabilities.mjs +626 -0
  6. package/src/cli.mjs +47 -12
  7. package/src/doctor.mjs +92 -25
  8. package/src/macos.mjs +276 -0
  9. package/src/package-manager.mjs +12 -4
  10. package/src/portability.mjs +6 -1
  11. package/src/presets.mjs +15 -81
  12. package/src/scaffold.mjs +15 -3
  13. package/src/ui.mjs +123 -61
  14. package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +57 -0
  15. package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +33 -0
  16. package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +251 -0
  17. package/templates/macos/examples/tasks/shared/types.ts +9 -0
  18. package/templates/macos/mobile/src/App.vue +12 -0
  19. package/templates/macos/mobile/src/app.ts +7 -0
  20. package/templates/macos/native/Package.swift +17 -0
  21. package/templates/macos/native/Sources/MavisDesktop/App.swift +20 -0
  22. package/templates/macos/root/tsconfig.json +14 -0
  23. package/templates/macos/scripts/generate.mjs +36 -0
  24. package/templates/macos/scripts/macos.mjs +56 -0
  25. package/templates/macos/scripts/portable/emit-swift.mjs +1287 -0
  26. package/templates/macos/scripts/portable/emit-vue.mjs +615 -0
  27. package/templates/macos/scripts/portable/index.mjs +95 -0
  28. package/templates/macos/scripts/portable/model.mjs +1441 -0
  29. package/templates/macos/scripts/portable/program.mjs +163 -0
  30. package/templates/macos/shared/Welcome.lite.tsx +42 -0
  31. package/templates/macos/web/index.html +12 -0
  32. package/templates/macos/web/src/main.js +39 -0
  33. package/templates/macos/web/src/style.css +13 -0
  34. package/templates/macos/web/vite.config.mjs +3 -0
package/src/presets.mjs CHANGED
@@ -1,81 +1,15 @@
1
- import { packageManagers } from './package-manager.mjs'
2
-
3
- /** Baseline pins; coordinated releases update Mavis after validating source templates with matching tarballs. */
4
- export const versions = Object.freeze({
5
- mavis: '0.1.0-rc.12.1',
6
- jolt: '0.1.0-rc.12.1',
7
- vue: '3.5.44',
8
- nuxt: '4.6.3',
9
- vite: '6.4.5',
10
- vuePlugin: '5.2.4',
11
- typescript: '6.0.3',
12
- nodeTypes: '26.6.6',
13
- vueTsc: '3.3.13',
14
- nativeCore: '9.1.3',
15
- nativeVue: '3.1.3',
16
- android: '9.1.1',
17
- ios: '9.1.0',
18
- webpack: '5.0.39',
19
- webpackCore: '5.112.2',
20
- webpackCli: '6.0.1',
21
- router: '4.6.4',
22
- nativeRouter: '0.1.0-rc.4',
23
- })
24
-
25
- export function validateProjectName(name) {
26
- if (!/^[a-z][a-z0-9-]{0,63}$/.test(name ?? ''))
27
- return 'Use a project name of 1–64 lowercase letters, numbers or hyphens, starting with a letter.'
28
- }
29
-
30
- export function resolvePreset(options) {
31
- const {
32
- name,
33
- target = 'web',
34
- web = 'vite',
35
- rendering = web === 'nuxt' ? 'ssr' : 'client',
36
- theme = 'mavis',
37
- framework = 'vue',
38
- authoring = 'vue',
39
- example = 'welcome',
40
- packageManager = 'npm',
41
- } = options
42
- const invalidName = validateProjectName(name)
43
- if (invalidName) throw new Error(invalidName)
44
- if (!packageManagers.includes(packageManager))
45
- throw new Error('Package manager must be npm, pnpm or yarn.')
46
- if (!['welcome', 'directory'].includes(example))
47
- throw new Error('Example must be welcome or directory.')
48
- if (framework !== 'vue')
49
- throw new Error(
50
- 'This creator currently supports Vue. Other framework adapters are tracked in Mavis #145 and #35–39.',
51
- )
52
- if (authoring !== 'vue')
53
- throw new Error(
54
- 'Portable JSX/React-style authoring for Vue is planned in Mavis #167; use Vue templates in this version.',
55
- )
56
- if (!['mobile', 'web', 'both'].includes(target))
57
- throw new Error('Target must be mobile, web or both.')
58
- if (!['vite', 'nuxt'].includes(web))
59
- throw new Error('Web host must be vite or nuxt. React/Next are not available yet.')
60
- if (!['mavis', 'midnight'].includes(theme)) throw new Error('Theme must be mavis or midnight.')
61
- if (target === 'mobile' && (web !== 'vite' || rendering !== 'client'))
62
- throw new Error('A mobile-only project has no Web rendering mode.')
63
- if (
64
- (web === 'vite' && rendering !== 'client') ||
65
- (web === 'nuxt' && !['ssr', 'ssg'].includes(rendering))
66
- )
67
- throw new Error('Choose client rendering for Vite or ssr/ssg for Nuxt.')
68
- return Object.freeze({
69
- schemaVersion: 1,
70
- name,
71
- target,
72
- framework,
73
- authoring,
74
- example,
75
- web: target === 'mobile' ? null : web,
76
- rendering: target === 'mobile' ? null : rendering,
77
- theme,
78
- packageManager,
79
- versions,
80
- })
81
- }
1
+ // Project choices are resolved from the capability catalog; this module keeps the names
2
+ // the rest of the creator and its checks import.
3
+ export {
4
+ versions,
5
+ validateProjectName,
6
+ targetNames,
7
+ parseTargets,
8
+ projectTargets,
9
+ layoutOf,
10
+ targetLabel,
11
+ chosenTargets,
12
+ resolvePreset,
13
+ configOf,
14
+ normalizeConfig,
15
+ } from './capabilities.mjs'
package/src/scaffold.mjs CHANGED
@@ -3,7 +3,7 @@ import { mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, writeFile } from
3
3
  import { dirname, join, relative, resolve, sep } from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
5
  import { directoryReadme } from './reference.mjs'
6
- import { resolvePreset, versions as v } from './presets.mjs'
6
+ import { configOf, resolvePreset, versions as v } from './presets.mjs'
7
7
  import { packageCommands, runInstall } from './package-manager.mjs'
8
8
 
9
9
  const templates = fileURLToPath(new URL('../templates/', import.meta.url))
@@ -26,6 +26,10 @@ async function copyTemplate(files, source, destination, replacements) {
26
26
  export async function projectFiles(options) {
27
27
  const preset = resolvePreset(options)
28
28
  const files = new Map()
29
+ if (preset.target === 'macos') {
30
+ const { macosFiles } = await import('./macos.mjs')
31
+ return macosFiles(preset, files, copyTemplate)
32
+ }
29
33
  const shared = preset.target === 'both'
30
34
  const directory = preset.example === 'directory'
31
35
  const commands = packageCommands(preset.packageManager)
@@ -189,7 +193,10 @@ export async function projectFiles(options) {
189
193
  const sharedDir = shared ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
190
194
  files.set(
191
195
  'mavis.config.json',
192
- json({ ...preset, portability: { roots: [sharedDir], alias: '#mavis', allowImports: [] } }),
196
+ json({
197
+ ...configOf(preset),
198
+ portability: { roots: [sharedDir], alias: '#mavis', allowImports: [] },
199
+ }),
193
200
  )
194
201
  files.set(
195
202
  '.gitignore',
@@ -295,7 +302,12 @@ export async function scaffold(options, cwd = process.cwd()) {
295
302
  }
296
303
 
297
304
  export async function installProject(plan, { signal, onProgress } = {}) {
298
- const directories = plan.preset.target === 'both' ? ['', 'apps/mobile'] : ['']
305
+ // The NativeScript app has its own dependency tree next to the root project.
306
+ const directories =
307
+ plan.preset.target === 'both' ||
308
+ (plan.preset.target === 'macos' && plan.preset.targets.includes('native'))
309
+ ? ['', 'apps/mobile']
310
+ : ['']
299
311
  for (const directory of directories) {
300
312
  const cwd = join(plan.destination, directory)
301
313
  onProgress?.(directory || '.')
package/src/ui.mjs CHANGED
@@ -7,7 +7,14 @@ import {
7
7
  packageCommands,
8
8
  packageManagers,
9
9
  } from './package-manager.mjs'
10
- import { resolvePreset, validateProjectName } from './presets.mjs'
10
+ import { chosenTargets, resolvePreset, targetLabel, validateProjectName } from './presets.mjs'
11
+ import { availabilityLabel, catalog, requirements } from './capabilities.mjs'
12
+
13
+ // Wizard options come from the catalog, so prompts and flags accept the same things.
14
+ const choices = (family, names = Object.keys(family)) =>
15
+ names.map((value) => ({ value, label: family[value].label, hint: family[value].hint }))
16
+ const status = (preset) =>
17
+ preset.availability === 'published' ? [] : [`Status ${availabilityLabel(preset.availability)}`]
11
18
 
12
19
  export function validateDestination(name, cwd = process.cwd()) {
13
20
  const invalid = validateProjectName(name)
@@ -21,17 +28,39 @@ export function validateDestination(name, cwd = process.cwd()) {
21
28
  }
22
29
 
23
30
  export function projectSummary(preset, install) {
31
+ if (preset.target === 'macos')
32
+ return [
33
+ `Project ${preset.name}`,
34
+ `Targets ${targetLabel(preset.targets)} · EXPERIMENTAL`,
35
+ `Hosts ${[
36
+ preset.targets.includes('web') && 'Vue + Vite',
37
+ preset.targets.includes('native') && 'NativeScript iOS + Android',
38
+ preset.targets.includes('macos') && 'SwiftUI macOS',
39
+ ]
40
+ .filter(Boolean)
41
+ .join(' · ')}`,
42
+ 'Authoring Shared TSX (shared/*.lite.tsx), compiled for each target',
43
+ ...status(preset),
44
+ preset.example === 'tasks'
45
+ ? 'Example Tasks · list and detail, forms, shortcuts and motion · shared/Tasks.lite.tsx'
46
+ : 'Example Basic welcome · shared/Welcome.lite.tsx',
47
+ `Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
48
+ `Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
49
+ ].join('\n')
24
50
  const web = preset.web === 'nuxt' ? `Nuxt · ${preset.rendering.toUpperCase()}` : 'Vue + Vite'
25
51
  return [
26
52
  `Project ${preset.name}`,
27
53
  `Platform ${preset.target === 'mobile' ? 'iOS + Android' : preset.target === 'both' ? `${web} + iOS + Android` : web}`,
28
- `Example ${preset.example === 'directory' ? 'Search, details and editing' : 'Basic project'}`,
54
+ `Example ${catalog.examples[preset.example].label}`,
55
+ ...status(preset),
29
56
  `Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
30
57
  `Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
31
58
  ].join('\n')
32
59
  }
33
60
 
34
61
  export function sharedEntry(preset) {
62
+ if (preset.target === 'macos')
63
+ return `shared/${preset.example === 'tasks' ? 'Tasks' : 'Welcome'}.lite.tsx`
35
64
  const directory =
36
65
  preset.target === 'both' ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
37
66
  return `${directory}/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
@@ -39,6 +68,18 @@ export function sharedEntry(preset) {
39
68
 
40
69
  export function nextSteps(preset, installed = false) {
41
70
  const commands = packageCommands(preset.packageManager)
71
+ if (preset.target === 'macos') {
72
+ const has = (target) => preset.targets.includes(target)
73
+ return [
74
+ `cd ${preset.name}`,
75
+ ...(!installed ? [has('native') ? commands.setup(true) : commands.install] : []),
76
+ ...(has('web') ? [commands.run('dev:web')] : []),
77
+ ...(has('native') ? [commands.run('ios'), commands.run('android')] : []),
78
+ ...(has('macos')
79
+ ? [commands.run('macos'), 'macOS 14+ and Xcode required for the Mac app.']
80
+ : []),
81
+ ].join('\n')
82
+ }
42
83
  return [
43
84
  `cd ${preset.name}`,
44
85
  ...(!installed ? [commands.setup(preset.target === 'both')] : []),
@@ -109,71 +150,59 @@ export async function prepareInstallation(
109
150
  export async function wizard(initial, signal, io = prompts, check = checkPackageManager) {
110
151
  let answers = { ...initial }
111
152
  const supplied = new Set(Object.keys(initial).filter((key) => initial[key] !== undefined))
153
+ // --target and --targets both answer the targets question.
154
+ if (initial.target !== undefined) supplied.add('targets')
155
+ const targets = () => (answers.targets || answers.target ? chosenTargets(answers) : [])
112
156
  const back = Symbol('back')
113
157
  const steps = [
114
158
  { key: 'name', message: 'What is your project called?', fallback: 'my-mavis-app' },
115
159
  {
116
- key: 'target',
117
- message: 'Where will it run?',
118
- options: [
119
- { value: 'web', label: 'Web', hint: 'A website or web app' },
120
- {
121
- value: 'mobile',
122
- label: 'Mobile',
123
- hint: 'Native iOS and Android apps',
124
- disabled: initial.web === 'nuxt' || ['ssr', 'ssg'].includes(initial.rendering),
125
- },
126
- { value: 'both', label: 'Web + Mobile', hint: 'One shared screen, three platforms' },
127
- ],
160
+ key: 'targets',
161
+ message: 'Where will it run? Space selects, Enter continues',
162
+ multiple: true,
163
+ fallback: ['web'],
164
+ options: choices(catalog.targets),
128
165
  },
129
166
  {
130
167
  key: 'web',
131
168
  message: 'Choose your web setup',
132
- when: () => answers.target !== 'mobile',
133
- options: [
134
- {
135
- value: 'vite',
136
- label: 'Vue + Vite',
137
- hint: 'A client-side app, ready to build on',
138
- disabled: ['ssr', 'ssg'].includes(initial.rendering),
139
- },
140
- {
141
- value: 'nuxt',
142
- label: 'Nuxt',
143
- hint: 'Server rendering or a static website',
144
- disabled: initial.rendering === 'client',
145
- },
146
- ],
169
+ when: () => targets().includes('web') && !targets().includes('macos'),
170
+ // A --rendering flag leaves only the hosts that can serve it.
171
+ options: choices(
172
+ catalog.hosts,
173
+ Object.keys(catalog.hosts).filter((host) => catalog.hosts[host].status !== 'planned'),
174
+ ).map((option) => ({
175
+ ...option,
176
+ disabled:
177
+ initial.rendering !== undefined &&
178
+ !catalog.hosts[option.value].rendering.includes(initial.rendering),
179
+ })),
147
180
  },
148
181
  {
149
182
  key: 'rendering',
150
183
  message: 'How should Nuxt serve your pages?',
151
- when: () => answers.target !== 'mobile' && answers.web === 'nuxt',
152
- options: [
153
- { value: 'ssr', label: 'Server rendering', hint: 'Render pages on each request' },
154
- { value: 'ssg', label: 'Static generation', hint: 'Build pages ahead of time' },
155
- ],
184
+ when: () => targets().includes('web') && answers.web === 'nuxt',
185
+ options: choices(catalog.rendering, catalog.hosts.nuxt.rendering),
156
186
  },
157
187
  {
158
188
  key: 'example',
159
189
  message: 'Choose a starting example',
160
190
  fallback: 'welcome',
161
- options: [
162
- { value: 'welcome', label: 'Basic project', hint: 'One shared screen to build on' },
163
- {
164
- value: 'directory',
165
- label: 'Search, details and editing',
166
- hint: 'Shared routes, forms and local persistence',
167
- },
168
- ],
191
+ // The examples written the way these targets are: Vue templates, or shared TSX with Mac.
192
+ options: () =>
193
+ choices(
194
+ catalog.examples,
195
+ Object.keys(catalog.examples).filter((example) =>
196
+ catalog.examples[example].authoring.includes(
197
+ targets().includes('macos') ? 'mitosis' : 'vue',
198
+ ),
199
+ ),
200
+ ),
169
201
  },
170
202
  {
171
203
  key: 'theme',
172
204
  message: 'Pick a starting theme',
173
- options: [
174
- { value: 'mavis', label: 'Mavis', hint: 'Light, warm and soft' },
175
- { value: 'midnight', label: 'Midnight', hint: 'Dark, calm and crisp' },
176
- ],
205
+ options: choices(catalog.themes),
177
206
  },
178
207
  {
179
208
  key: 'packageManager',
@@ -181,7 +210,11 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
181
210
  fallback: detectPackageManager(),
182
211
  options: [
183
212
  { value: 'npm', label: 'npm', hint: 'Included with Node.js' },
184
- { value: 'pnpm', label: 'pnpm', hint: 'Fast installs, efficient disk usage · 10.26+' },
213
+ {
214
+ value: 'pnpm',
215
+ label: 'pnpm',
216
+ hint: `Fast installs, efficient disk usage · ${requirements.packageManagers.pnpm}+`,
217
+ },
185
218
  { value: 'yarn', label: 'Yarn', hint: 'Classic or modern, with node_modules' },
186
219
  ],
187
220
  },
@@ -233,30 +266,59 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
233
266
  continue
234
267
  }
235
268
  const message = typeof step.message === 'function' ? step.message() : step.message
236
- const value = step.options
237
- ? await io.select({
269
+ const options = typeof step.options === 'function' ? step.options() : step.options
270
+ const value = step.multiple
271
+ ? await io.multiselect({
238
272
  message,
239
273
  signal,
240
- initialValue: answers[step.key] ?? step.fallback,
274
+ required: true,
275
+ initialValues: answers[step.key] ?? step.fallback,
241
276
  options: [
242
- ...step.options,
277
+ ...options,
243
278
  ...(previous(index) >= 0 ? [{ value: back, label: '← Back' }] : []),
244
279
  ],
245
280
  })
246
- : await io.text({
247
- message,
248
- signal,
249
- placeholder: step.fallback,
250
- defaultValue: step.fallback,
251
- initialValue: answers[step.key],
252
- validate: (value) =>
253
- value === 'cancel' ? undefined : validateDestination(value || step.fallback),
254
- })
281
+ : options
282
+ ? await io.select({
283
+ message,
284
+ signal,
285
+ // An earlier answer may not exist for the targets chosen since.
286
+ initialValue: options.some((option) => option.value === answers[step.key])
287
+ ? answers[step.key]
288
+ : step.fallback,
289
+ options: [
290
+ ...options,
291
+ ...(previous(index) >= 0 ? [{ value: back, label: '← Back' }] : []),
292
+ ],
293
+ })
294
+ : await io.text({
295
+ message,
296
+ signal,
297
+ placeholder: step.fallback,
298
+ defaultValue: step.fallback,
299
+ initialValue: answers[step.key],
300
+ validate: (value) =>
301
+ value === 'cancel' ? undefined : validateDestination(value || step.fallback),
302
+ })
255
303
  if (io.isCancel(value) || value === 'cancel') return null
256
- if (value === back) {
304
+ if (value === back || (Array.isArray(value) && value.includes(back))) {
257
305
  index = previous(index)
258
306
  continue
259
307
  }
308
+ if (step.key === 'targets') {
309
+ // Explain choices that don't fit together before going further, then ask again.
310
+ try {
311
+ // Only flags constrain the targets; later answers are asked again for these targets.
312
+ resolvePreset({ ...initial, name: answers.name ?? 'my-mavis-app', targets: value })
313
+ } catch (error) {
314
+ io.log.warn(error.message)
315
+ continue
316
+ }
317
+ if (value.includes('macos'))
318
+ io.log.message(
319
+ `Shared screens will be TSX (shared/*.lite.tsx), compiled for ${value.join(', ')}.${value.includes('web') ? ' The Web app uses Vue + Vite: Nuxt needs server rendering in the compiler, which is not there yet.' : ''}`,
320
+ )
321
+ }
260
322
  answers[step.key] = value
261
323
  index++
262
324
  }
@@ -0,0 +1,57 @@
1
+ import type { Task } from './types'
2
+
3
+ // The selected task. Every edit goes straight to the list, so the row updates while you type.
4
+ export default function TaskDetail(props: {
5
+ task: Task
6
+ priorities: SelectOption[]
7
+ canMoveUp: boolean
8
+ canMoveDown: boolean
9
+ onToggle: () => void
10
+ onRename: (title: string) => void
11
+ onNotes: (notes: string) => void
12
+ onPriority: (priority: string) => void
13
+ onMove: (by: number) => void
14
+ }) {
15
+ return (
16
+ <MCard gap="md">
17
+ <MText variant="overline" tone="muted">
18
+ SELECTED TASK
19
+ </MText>
20
+ <MCheckbox label="Done" checked={props.task.done} onChange={() => props.onToggle()} />
21
+ <MInput
22
+ label="Task title"
23
+ value={props.task.title}
24
+ onChange={(value) => props.onRename(value)}
25
+ maxLength={60}
26
+ />
27
+ <MInput
28
+ label="Task notes"
29
+ multiline
30
+ rows={3}
31
+ value={props.task.notes}
32
+ onChange={(value) => props.onNotes(value)}
33
+ placeholder="Anything worth remembering"
34
+ />
35
+ <MSelect
36
+ label="Task priority"
37
+ value={props.task.priority}
38
+ options={props.priorities}
39
+ onChange={(value) => props.onPriority(value)}
40
+ />
41
+ <MRow gap="sm">
42
+ <MButton
43
+ text="Move up"
44
+ variant="secondary"
45
+ disabled={!props.canMoveUp}
46
+ onClick={() => props.onMove(-1)}
47
+ />
48
+ <MButton
49
+ text="Move down"
50
+ variant="secondary"
51
+ disabled={!props.canMoveDown}
52
+ onClick={() => props.onMove(1)}
53
+ />
54
+ </MRow>
55
+ </MCard>
56
+ )
57
+ }
@@ -0,0 +1,33 @@
1
+ import { Show } from '@builder.io/mitosis'
2
+ import type { Task } from './types'
3
+
4
+ // One task in the list. The whole card is a button; its label is what assistive technology reads.
5
+ export default function TaskRow(props: {
6
+ task: Task
7
+ selected: boolean
8
+ onSelect: (id: string) => void
9
+ }) {
10
+ return (
11
+ <MCard
12
+ gap="xs"
13
+ padding="md"
14
+ tone={props.selected ? 'primarySoft' : 'surface'}
15
+ label={`${props.task.title}, ${props.task.done ? 'done' : 'open'}, ${props.task.priority} priority${props.selected ? ', selected' : ''}`}
16
+ onClick={() => props.onSelect(props.task.id)}
17
+ >
18
+ <MText tone={props.task.done ? 'muted' : 'text'}>{props.task.title}</MText>
19
+ <MText variant="caption" tone="muted">
20
+ {props.task.priority === 'high'
21
+ ? 'High priority'
22
+ : props.task.priority === 'low'
23
+ ? 'Low priority'
24
+ : 'Normal priority'}
25
+ </MText>
26
+ <Show when={props.task.done} animate>
27
+ <MText variant="caption" tone="success">
28
+ Done
29
+ </MText>
30
+ </Show>
31
+ </MCard>
32
+ )
33
+ }