@getcortexlabs/create-mavis 0.1.0-rc.12.2 → 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 (37) hide show
  1. package/README.md +6 -6
  2. package/package.json +1 -1
  3. package/src/adapters.mjs +76 -0
  4. package/src/add-target.mjs +1 -1
  5. package/src/capabilities.mjs +626 -0
  6. package/src/cli.mjs +43 -12
  7. package/src/doctor.mjs +77 -36
  8. package/src/macos.mjs +223 -56
  9. package/src/package-manager.mjs +12 -4
  10. package/src/portability.mjs +2 -1
  11. package/src/presets.mjs +15 -108
  12. package/src/scaffold.mjs +11 -3
  13. package/src/ui.mjs +115 -82
  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 +9 -1
  21. package/templates/macos/native/Sources/MavisDesktop/App.swift +4 -4
  22. package/templates/macos/root/tsconfig.json +14 -0
  23. package/templates/macos/scripts/generate.mjs +35 -16
  24. package/templates/macos/scripts/macos.mjs +8 -3
  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 +8 -6
  31. package/templates/macos/{index.html → web/index.html} +1 -1
  32. package/templates/macos/web/src/main.js +39 -0
  33. package/templates/macos/web/{style.css → src/style.css} +1 -1
  34. package/templates/macos/web/vite.config.mjs +3 -0
  35. package/templates/macos/scripts/portable.mjs +0 -395
  36. package/templates/macos/vite.config.mjs +0 -3
  37. package/templates/macos/web/main.js +0 -15
package/src/cli.mjs CHANGED
@@ -8,28 +8,46 @@ import { planTarget, applyTarget } from './add-target.mjs'
8
8
  import { checkPortability } from './portability.mjs'
9
9
  import { doctor } from './doctor.mjs'
10
10
  import {
11
+ atLeast,
11
12
  checkPackageManager,
12
13
  detectPackageManager,
13
14
  packageCommands,
14
15
  runInstall,
15
16
  } from './package-manager.mjs'
16
17
  import { resolvePreset } from './presets.mjs'
18
+ import {
19
+ chosenTargets,
20
+ describeCapabilities,
21
+ formatCapabilities,
22
+ recommendation,
23
+ requirements,
24
+ } from './capabilities.mjs'
17
25
  import { nextSteps, projectSummary, sharedEntry, terminalUI, wizard } from './ui.mjs'
18
26
 
19
27
  const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
20
- const help = `Create Mavis — Vue Web, Nuxt and NativeScript
28
+ const help = `Create Mavis — Web, Native (iOS/Android) and Mac in any combination
21
29
 
22
30
  npm create @getcortexlabs/mavis@latest
23
- create-mavis my-app --target both --web nuxt --package-manager pnpm --no-install
31
+ create-mavis my-app --targets web,native,macos --package-manager pnpm --no-install
32
+ create-mavis my-app --targets web,native --web nuxt
24
33
 
25
- --target mobile|web|both|macos Default: web; macos is experimental Mitosis + SwiftUI
34
+ --targets web,native,macos Any combination; default: web. With macos, shared
35
+ screens are TSX compiled for every target (experimental)
36
+ --target mobile|web|both|macos
37
+ Earlier names: native, web, web+native, web+macos
26
38
  --add-native Add apps/mobile to an existing Vue/Vite or Nuxt app
27
39
  --add-web Add apps/web to an existing NativeScript-Vue app
28
40
  --screen path.vue Reuse an existing screen without moving it
29
41
  --screen-root screen|content Existing MScreen or content to wrap (auto-detected)
30
42
  --web vite|nuxt Default: vite
31
43
  --rendering client|ssr|ssg Default: client (Vite), ssr (Nuxt)
32
- --example welcome|directory Starter or shared search/detail/edit reference
44
+ --capabilities Show what can be created, how each combination has been
45
+ validated and what is planned (add --json for tools)
46
+ --familiar vue|react|angular|svelte|solid|other
47
+ What you already know. Changes the advice, not what runs
48
+ --example welcome|directory|tasks
49
+ Starter, shared search/detail/edit reference, or the
50
+ Tasks app (with macos: one source for every target)
33
51
  --check-portability Audit shared sources without SDK checks
34
52
  --path directory Override the configured shared source directory
35
53
  --fix-imports Preview safe renderer-import replacements
@@ -39,7 +57,7 @@ const help = `Create Mavis — Vue Web, Nuxt and NativeScript
39
57
  --package-manager npm|pnpm|yarn
40
58
  Default: the invoking manager, or npm
41
59
  --framework vue Vue is currently supported
42
- --authoring vue|mitosis Mitosis only for the experimental macos starter
60
+ --authoring vue|mitosis Follows the targets: mitosis (shared TSX) with macos
43
61
  --yes, -y Use defaults without prompts (skip installation)
44
62
  --install / --no-install Install dependencies now or later
45
63
  --dry-run Show the complete file plan without writing
@@ -65,6 +83,7 @@ try {
65
83
  allowPositionals: true,
66
84
  options: {
67
85
  target: { type: 'string' },
86
+ targets: { type: 'string' },
68
87
  'add-native': { type: 'boolean' },
69
88
  'add-web': { type: 'boolean' },
70
89
  screen: { type: 'string' },
@@ -73,6 +92,8 @@ try {
73
92
  rendering: { type: 'string' },
74
93
  theme: { type: 'string' },
75
94
  example: { type: 'string' },
95
+ capabilities: { type: 'boolean' },
96
+ familiar: { type: 'string' },
76
97
  'check-portability': { type: 'boolean' },
77
98
  path: { type: 'string' },
78
99
  'fix-imports': { type: 'boolean' },
@@ -91,15 +112,21 @@ try {
91
112
  },
92
113
  })
93
114
  if (values.help) console.log(help)
115
+ else if (values.capabilities)
116
+ console.log(
117
+ values.json ? JSON.stringify(describeCapabilities(), null, 2) : formatCapabilities(),
118
+ )
94
119
  else if (values.version) console.log(version)
95
120
  else if (values['add-native'] || values['add-web']) {
96
- const [major, minor] = process.versions.node.split('.').map(Number)
97
- if (major < 22 || (major === 22 && minor < 16))
98
- throw new Error(`Mavis needs Node.js 22.16 or newer. You are using ${process.version}.`)
121
+ if (!atLeast(process.versions.node, requirements.node))
122
+ throw new Error(
123
+ `Mavis needs Node.js ${requirements.node} or newer. You are using ${process.version}.`,
124
+ )
99
125
  if (values['add-native'] && values['add-web']) throw new Error('Add one target at a time.')
100
126
  if (
101
127
  positionals.length ||
102
128
  values.target ||
129
+ values.targets ||
103
130
  values['check-portability'] ||
104
131
  values['fix-imports'] ||
105
132
  values.write ||
@@ -218,9 +245,10 @@ try {
218
245
  if (positionals.length > 1) throw new Error('Provide one project name.')
219
246
  if (values.install && values['no-install'])
220
247
  throw new Error('Choose either --install or --no-install.')
221
- const [major, minor] = process.versions.node.split('.').map(Number)
222
- if (major < 22 || (major === 22 && minor < 16))
223
- throw new Error(`Mavis needs Node.js 22.16 or newer. You are using ${process.version}.`)
248
+ if (!atLeast(process.versions.node, requirements.node))
249
+ throw new Error(
250
+ `Mavis needs Node.js ${requirements.node} or newer. You are using ${process.version}.`,
251
+ )
224
252
  let options = {
225
253
  ...values,
226
254
  name: positionals[0],
@@ -230,6 +258,9 @@ try {
230
258
  }
231
259
  resolvePreset({ ...options, name: options.name ?? 'my-mavis-app' })
232
260
  ui.intro(version)
261
+ // Advice for someone coming from another framework. It never changes what gets created.
262
+ const advice = recommendation(values.familiar, chosenTargets(options))
263
+ if (advice) ui.message(advice)
233
264
  const useWizard = interactive && !values.yes && !options.dryRun
234
265
  if (useWizard) options = await wizard(options, cancellation.signal)
235
266
  if (!options) {
@@ -264,7 +295,7 @@ try {
264
295
  ui.message(`Make it yours: ${sharedEntry(plan.preset)}`)
265
296
  if (plan.preset.target === 'macos')
266
297
  ui.message(
267
- 'Experimental: four starter primitives; macOS 14+ and Xcode required. See the generated README for the supported subset.',
298
+ `Experimental shared TSX: see the README for the supported subset.${plan.preset.targets.includes('macos') ? ' The Mac app needs macOS 14+ and Xcode.' : ''}${plan.preset.targets.includes('native') ? ' Native needs the NativeScript CLI and platform SDKs; check with --doctor.' : ''}`,
268
299
  )
269
300
  else if (plan.preset.target !== 'web')
270
301
  ui.message(
package/src/doctor.mjs CHANGED
@@ -1,21 +1,49 @@
1
+ import { pathToFileURL } from 'node:url'
1
2
  import { spawnSync } from 'node:child_process'
2
3
  import { readFile } from 'node:fs/promises'
3
4
  import { checkPortability } from './portability.mjs'
4
5
  import { join } from 'node:path'
5
- import { checkPackageManager } from './package-manager.mjs'
6
+ import { atLeast, checkPackageManager } from './package-manager.mjs'
7
+ import {
8
+ availabilityLabel,
9
+ availabilityOf,
10
+ catalog,
11
+ checkProject,
12
+ normalizeConfig,
13
+ requirements,
14
+ targetLabel,
15
+ } from './capabilities.mjs'
6
16
 
7
17
  export async function doctor(cwd = process.cwd()) {
8
18
  let config
9
19
  try {
10
- config = JSON.parse(await readFile(join(cwd, 'mavis.config.json'), 'utf8'))
20
+ config = normalizeConfig(JSON.parse(await readFile(join(cwd, 'mavis.config.json'), 'utf8')))
11
21
  } catch {
12
22
  throw new Error('Run --doctor from a generated project containing mavis.config.json.')
13
23
  }
14
- const [major, minor] = process.versions.node.split('.').map(Number)
24
+ // The same check the creator runs before writing a project, on what this one records.
25
+ const project = checkProject({
26
+ name: config.name,
27
+ targets: config.targets,
28
+ web: config.web ?? undefined,
29
+ rendering: config.rendering ?? undefined,
30
+ framework: config.framework,
31
+ authoring: config.authoring,
32
+ example: config.example,
33
+ theme: config.theme,
34
+ packageManager: config.packageManager,
35
+ })
15
36
  const results = [
16
37
  {
17
- name: 'Node.js 22.16+',
18
- ok: major > 22 || (major === 22 && minor >= 16),
38
+ name: 'Project configuration',
39
+ ok: project.ok,
40
+ detail: project.ok
41
+ ? `${targetLabel(config.targets)} · ${catalog.authoring[config.authoring].label} · ${availabilityLabel(availabilityOf(config))}`
42
+ : project.message.split('\n')[0],
43
+ },
44
+ {
45
+ name: `Node.js ${requirements.node}+`,
46
+ ok: atLeast(process.versions.node, requirements.node),
19
47
  detail: process.version,
20
48
  },
21
49
  checkPackageManager(config.packageManager ?? 'npm'),
@@ -32,46 +60,32 @@ export async function doctor(cwd = process.cwd()) {
32
60
  ? (result.error?.message ?? (result.stdout || result.stderr)).trim().split('\n')[0]
33
61
  : 'macOS 14+ and Xcode are required for the native app. Web remains available.',
34
62
  })
35
- const { validateSource } = await import('../templates/macos/scripts/portable.mjs')
63
+ // The project's own compiler copy, with its installed TypeScript and theme packages.
36
64
  try {
37
- validateSource(await readFile(join(cwd, 'shared/Welcome.lite.tsx'), 'utf8'))
65
+ const compiler = await import(pathToFileURL(join(cwd, 'scripts/portable/index.mjs')))
66
+ const { model } = await compiler.compileProject(await compiler.readShared(cwd), {
67
+ theme: config.theme,
68
+ root: config.portability?.entry ?? 'Welcome',
69
+ })
38
70
  results.push({
39
- name: 'Experimental source grammar',
71
+ name: 'Shared sources',
40
72
  ok: true,
41
- detail:
42
- 'Grammar accepted. Run generate to validate tokens and both outputs; this does not prove a native build.',
73
+ detail: `${model.components.length} component(s) type-checked for ${config.targets.join(', ')}. Run generate to write them; this does not prove a build.`,
43
74
  })
44
75
  } catch (error) {
45
- results.push({ name: 'Experimental source grammar', ok: false, detail: error.message })
46
- }
47
- return results
48
- }
49
- if (config.target !== 'web') {
50
- const probe = (name, command, args) => {
51
- const result = spawnSync(command, args, { encoding: 'utf8', timeout: 10000 })
52
- results.push({
53
- name,
54
- ok: result.status === 0,
55
- detail: (result.error?.message ?? (result.stdout || result.stderr || 'No output'))
56
- .trim()
57
- .split('\n')[0],
58
- })
59
- }
60
- probe('NativeScript CLI', process.platform === 'win32' ? 'ns.cmd' : 'ns', ['--version'])
61
- probe('Java (Android)', 'java', ['-version'])
62
- results.push({
63
- name: 'Android SDK',
64
- ok: Boolean(process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT),
65
- detail: 'Set ANDROID_HOME for Android builds.',
66
- })
67
- if (process.platform === 'darwin') probe('Xcode (iOS)', 'xcodebuild', ['-version'])
68
- else
69
76
  results.push({
70
- name: 'iOS host',
77
+ name: 'Shared sources',
71
78
  ok: false,
72
- detail: 'iOS builds require macOS and Xcode; Android remains available.',
79
+ detail:
80
+ error.code === 'ERR_MODULE_NOT_FOUND'
81
+ ? 'Install the project dependencies, then run doctor again.'
82
+ : error.message,
73
83
  })
84
+ }
85
+ if (config.targets.includes('native')) nativeChecks(results)
86
+ return results
74
87
  }
88
+ if (config.target !== 'web') nativeChecks(results)
75
89
  const portability = await checkPortability(cwd)
76
90
  results.push({
77
91
  name: 'Shared source portability',
@@ -80,3 +94,30 @@ export async function doctor(cwd = process.cwd()) {
80
94
  })
81
95
  return results
82
96
  }
97
+
98
+ function nativeChecks(results) {
99
+ const probe = (name, command, args) => {
100
+ const result = spawnSync(command, args, { encoding: 'utf8', timeout: 10000 })
101
+ results.push({
102
+ name,
103
+ ok: result.status === 0,
104
+ detail: (result.error?.message ?? (result.stdout || result.stderr || 'No output'))
105
+ .trim()
106
+ .split('\n')[0],
107
+ })
108
+ }
109
+ probe('NativeScript CLI', process.platform === 'win32' ? 'ns.cmd' : 'ns', ['--version'])
110
+ probe('Java (Android)', 'java', ['-version'])
111
+ results.push({
112
+ name: 'Android SDK',
113
+ ok: Boolean(process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT),
114
+ detail: 'Set ANDROID_HOME for Android builds.',
115
+ })
116
+ if (process.platform === 'darwin') probe('Xcode (iOS)', 'xcodebuild', ['-version'])
117
+ else
118
+ results.push({
119
+ name: 'iOS host',
120
+ ok: false,
121
+ detail: 'iOS builds require macOS and Xcode; Android remains available.',
122
+ })
123
+ }
package/src/macos.mjs CHANGED
@@ -1,32 +1,70 @@
1
- import { versions as v } from './presets.mjs'
1
+ import { versions as v, configOf, targetLabel } from './presets.mjs'
2
2
  import { packageCommands } from './package-manager.mjs'
3
+ import { joltSwift } from '../templates/macos/scripts/portable/emit-swift.mjs'
3
4
 
4
- /** Opt-in build-time compiler; never installed by ordinary Vue/NativeScript starters. */
5
+ const json = (value) => `${JSON.stringify(value, null, 2)}\n`
6
+
7
+ /**
8
+ * Combinations with Mac: shared TSX sources compiled into Vue for the Web, Vue for
9
+ * NativeScript and SwiftUI for macOS. Projects without Mac keep Vue templates.
10
+ */
5
11
  export async function macosFiles(preset, files, copyTemplate) {
12
+ const { targets } = preset
13
+ const web = targets.includes('web')
14
+ const native = targets.includes('native')
15
+ const mac = targets.includes('macos')
6
16
  const commands = packageCommands(preset.packageManager)
7
- await copyTemplate(files, 'macos', '', {
17
+ const tasks = preset.example === 'tasks'
18
+ // The screen every app opens. Tasks is a list beside its detail, so it gets a wider page.
19
+ const entry = tasks ? 'Tasks' : 'Welcome'
20
+ const hosts = [
21
+ web && 'Vue on the Web',
22
+ native && 'NativeScript on iOS and Android',
23
+ mac && 'SwiftUI on the Mac',
24
+ ].filter(Boolean)
25
+ const replacements = {
8
26
  NAME: preset.name,
9
27
  APPID: preset.name.replaceAll('-', ''),
10
28
  THEME: preset.theme,
11
29
  APPEARANCE: preset.theme === 'midnight' ? 'dark' : 'light',
12
30
  BACKGROUND: preset.theme === 'midnight' ? '#15121C' : '#FAF7FA',
13
- })
14
- files.set(
15
- 'package.json',
16
- JSON.stringify(
17
- {
18
- name: preset.name,
19
- private: true,
20
- version: '0.0.0',
31
+ TARGETS: targetLabel(targets),
32
+ HOSTS: hosts.join(' · '),
33
+ JOLT_SWIFT: joltSwift.version,
34
+ ROOT: entry,
35
+ WEB_WIDTH: tasks ? '1120px' : '760px',
36
+ MAC_WIDTH: tasks ? '1120' : '820',
37
+ MAC_MIN_WIDTH: tasks ? '760' : '640',
38
+ MAC_DEFAULT_WIDTH: tasks ? '1180' : '860',
39
+ SHARED: '#shared-ui',
40
+ SHARED_ROOT: '../../shared',
41
+ }
42
+ await copyTemplate(files, 'macos/root', '', replacements)
43
+ await copyTemplate(
44
+ files,
45
+ tasks ? 'macos/examples/tasks/shared' : 'macos/shared',
46
+ 'shared',
47
+ replacements,
48
+ )
49
+ await copyTemplate(files, 'macos/scripts', 'scripts', replacements)
50
+ if (!mac) files.delete('scripts/macos.mjs')
51
+
52
+ const common = { private: true, version: '0.0.0', engines: { node: '>=22.16' } }
53
+ const generate = 'node scripts/generate.mjs'
54
+ const builds = []
55
+ const scripts = { generate }
56
+ if (web) {
57
+ await copyTemplate(files, 'macos/web', 'apps/web', replacements)
58
+ scripts['dev:web'] = `${generate} && ${commands.run('dev', 'apps/web')}`
59
+ scripts['build:web'] = `${generate} && ${commands.run('build', 'apps/web')}`
60
+ builds.push('build:web')
61
+ files.set(
62
+ 'apps/web/package.json',
63
+ json({
64
+ ...common,
65
+ name: `${preset.name}-web`,
21
66
  type: 'module',
22
- engines: { node: '>=22.16' },
23
- scripts: {
24
- generate: 'node scripts/generate.mjs',
25
- 'dev:web': 'node scripts/generate.mjs && vite',
26
- 'build:web': 'node scripts/generate.mjs && vite build',
27
- 'build:macos': 'node scripts/macos.mjs build',
28
- macos: 'node scripts/macos.mjs run',
29
- },
67
+ scripts: { dev: 'vite', build: 'vite build', preview: 'vite preview' },
30
68
  dependencies: {
31
69
  '@getcortexlabs/mavis-core': v.mavis,
32
70
  '@getcortexlabs/mavis-web': v.mavis,
@@ -34,76 +72,205 @@ export async function macosFiles(preset, files, copyTemplate) {
34
72
  vue: v.vue,
35
73
  },
36
74
  devDependencies: {
37
- '@builder.io/mitosis': v.mitosis,
38
75
  typescript: v.typescript,
39
76
  vite: v.vite,
40
77
  '@vitejs/plugin-vue': v.vuePlugin,
41
78
  },
79
+ }),
80
+ )
81
+ }
82
+ if (native) {
83
+ await copyTemplate(files, 'mobile', 'apps/mobile', replacements)
84
+ await copyTemplate(files, 'macos/mobile', 'apps/mobile', replacements)
85
+ // The generated screens are the app's shared code; the TSX sources stay out of vue-tsc.
86
+ files.set(
87
+ 'apps/mobile/tsconfig.json',
88
+ files
89
+ .get('apps/mobile/tsconfig.json')
90
+ .replace('"include": ["src", "../../shared"]', '"include": ["src"]'),
91
+ )
92
+ scripts.ios = `${generate} && ${commands.run('ios', 'apps/mobile')}`
93
+ scripts.android = `${generate} && ${commands.run('android', 'apps/mobile')}`
94
+ scripts['build:native'] =
95
+ `${generate} && ${commands.run('bundle:android', 'apps/mobile')} && ${commands.run('bundle:ios', 'apps/mobile')}`
96
+ scripts['install:apps'] = `${commands.install} && ${commands.installAt('apps/mobile')}`
97
+ builds.push('build:native')
98
+ files.set(
99
+ 'apps/mobile/package.json',
100
+ json({
101
+ ...common,
102
+ name: `${preset.name}-mobile`,
42
103
  ...(preset.packageManager === 'yarn'
43
- ? { resolutions: { vue: v.vue }, dependenciesMeta: { esbuild: { built: true } } }
104
+ ? {
105
+ dependenciesMeta: {
106
+ esbuild: { built: true },
107
+ '@nativescript/core': { built: true },
108
+ '@parcel/watcher': { built: true },
109
+ 'core-js-pure': { built: false },
110
+ },
111
+ }
44
112
  : {}),
45
- },
46
- null,
47
- 2,
48
- ) + '\n',
113
+ main: 'src/app.ts',
114
+ scripts: {
115
+ android: 'ns run android',
116
+ ios: 'ns run ios',
117
+ typecheck: 'vue-tsc --noEmit',
118
+ 'bundle:android': 'webpack --env android',
119
+ 'bundle:ios': 'webpack --env ios',
120
+ },
121
+ dependencies: {
122
+ '@getcortexlabs/mavis-core': v.mavis,
123
+ '@rafaelaugusto/jolt': v.jolt,
124
+ '@getcortexlabs/mavis': v.mavis,
125
+ '@nativescript/core': v.nativeCore,
126
+ 'nativescript-vue': v.nativeVue,
127
+ },
128
+ devDependencies: {
129
+ '@nativescript/android': v.android,
130
+ '@nativescript/ios': v.ios,
131
+ '@nativescript/webpack': v.webpack,
132
+ webpack: v.webpackCore,
133
+ 'webpack-cli': v.webpackCli,
134
+ typescript: v.typescript,
135
+ 'vue-tsc': v.vueTsc,
136
+ },
137
+ }),
138
+ )
139
+ }
140
+ if (mac) {
141
+ await copyTemplate(files, 'macos/native', 'apps/macos', replacements)
142
+ scripts.macos = 'node scripts/macos.mjs run'
143
+ scripts['build:macos'] = 'node scripts/macos.mjs build'
144
+ builds.push('build:macos')
145
+ }
146
+ scripts.build = builds.map((name) => commands.run(name)).join(' && ')
147
+
148
+ files.set(
149
+ 'package.json',
150
+ json({
151
+ ...common,
152
+ name: preset.name,
153
+ type: 'module',
154
+ ...(web && preset.packageManager !== 'pnpm' ? { workspaces: ['apps/web'] } : {}),
155
+ ...(web && preset.packageManager === 'yarn'
156
+ ? {
157
+ resolutions: { vue: v.vue, '@vue/runtime-core': v.vue },
158
+ dependenciesMeta: { esbuild: { built: true } },
159
+ }
160
+ : {}),
161
+ scripts,
162
+ // The compiler reads theme tokens from Mavis core and type-checks with TypeScript.
163
+ dependencies: { '@getcortexlabs/mavis-core': v.mavis },
164
+ devDependencies: { typescript: v.typescript },
165
+ }),
49
166
  )
50
167
  files.set(
51
168
  'mavis.config.json',
52
- JSON.stringify(
53
- { ...preset, portability: { roots: ['shared'], mode: 'mitosis-swiftui-experimental' } },
54
- null,
55
- 2,
56
- ) + '\n',
169
+ json({
170
+ ...configOf(preset),
171
+ portability: { roots: ['shared'], mode: 'shared-tsx-experimental', entry },
172
+ }),
57
173
  )
58
174
  files.set(
59
175
  '.gitignore',
60
- 'node_modules/\ndist/\nnative/.build/\n.yarn/\n.DS_Store\n*.log\n*.generated.vue\n*.generated.swift\n',
176
+ [
177
+ 'node_modules/',
178
+ '.npm/',
179
+ '.pnpm-store/',
180
+ '.yarn/',
181
+ 'dist/',
182
+ 'platforms/',
183
+ 'hooks/',
184
+ 'apps/macos/.build/',
185
+ 'apps/web/src/generated/',
186
+ 'apps/mobile/src/generated/',
187
+ 'apps/macos/Sources/MavisDesktop/Generated/',
188
+ 'mavis-env.d.ts',
189
+ '.DS_Store',
190
+ '*.log',
191
+ '',
192
+ ].join('\n'),
61
193
  )
62
- if (preset.packageManager === 'pnpm')
194
+ if (preset.packageManager === 'pnpm') {
63
195
  files.set(
64
196
  'pnpm-workspace.yaml',
65
- 'packages: []\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n',
197
+ `packages:${web ? '\n - apps/web' : ' []'}\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n`,
66
198
  )
199
+ if (native)
200
+ files.set(
201
+ 'apps/mobile/pnpm-workspace.yaml',
202
+ 'packages: []\nnodeLinker: hoisted\nsideEffectsCache: false\nallowBuilds:\n "esbuild": true\n "@nativescript/core": true\n "@parcel/watcher": true\n "core-js-pure": false\n',
203
+ )
204
+ }
67
205
  if (preset.packageManager === 'yarn') {
68
206
  files.set('.yarnrc.yml', 'nodeLinker: node-modules\n')
207
+ // An empty lockfile marks a separate Yarn project, including before its first install.
69
208
  files.set('yarn.lock', '')
209
+ if (native) files.set('apps/mobile/yarn.lock', '')
70
210
  }
71
- files.set(
72
- 'README.md',
73
- `# ${preset.name}
211
+ files.set('README.md', readme(preset, commands, { web, native, mac, entry }))
212
+ return { preset, files: new Map([...files].sort(([a], [b]) => a.localeCompare(b))) }
213
+ }
74
214
 
75
- Experimental Mavis macOS + Web starter. **One shared source, two compiled interfaces.**
76
- This is a small compiler experiment, not the complete Mavis SwiftUI renderer.
215
+ function readme(preset, commands, { web, native, mac, entry }) {
216
+ const start = [
217
+ native ? commands.setup(true) : commands.install,
218
+ ...(web ? [commands.run('dev:web')] : []),
219
+ ...(native ? [commands.run('ios'), commands.run('android')] : []),
220
+ ...(mac ? [commands.run('macos')] : []),
221
+ ]
222
+ const folders = [
223
+ web && '- apps/web: Vue + Vite with Mavis Web. Generated screens in apps/web/src/generated/.',
224
+ native &&
225
+ '- apps/mobile: NativeScript-Vue for iOS and Android with Mavis. Generated screens in apps/mobile/src/generated/.',
226
+ mac &&
227
+ '- apps/macos: a SwiftUI app (Swift package) with JoltSwiftUI. Generated views in apps/macos/Sources/MavisDesktop/Generated/.',
228
+ ].filter(Boolean)
229
+ const hosts = [
230
+ native &&
231
+ `Native needs the NativeScript CLI and the platform SDK: Xcode on macOS for iOS, a JDK and the Android SDK for Android. Run \`ns doctor\` in apps/mobile. It has its own dependency tree; reinstall both from the root with \`${commands.run('install:apps')}\`.`,
232
+ mac &&
233
+ 'The Mac app needs macOS 14+ and Xcode with command-line tools. It uses SwiftUI, not a WebView or a JavaScript runtime. The first build downloads JoltSwiftUI (rafaelaugustos/jolt-swift). The app is unsigned, for local development.',
234
+ 'Code generation and the Web also work on Linux and Windows.',
235
+ ].filter(Boolean)
236
+ return `# ${preset.name}
237
+
238
+ Mavis ${targetLabel(preset.targets)} project, experimental. **One shared source, compiled for each target.**
239
+ This is a compiler experiment for a subset of Mavis, not a complete renderer for every component.
77
240
 
78
241
  ## Start
79
242
 
80
243
  \`\`\`sh
81
- ${commands.install}
82
- ${commands.run('macos')}
83
- # Or open the same screen on the Web:
84
- ${commands.run('dev:web')}
244
+ ${start.join('\n')}
85
245
  \`\`\`
86
246
 
87
- The native app requires macOS 14+ and Xcode with command-line tools. It uses SwiftUI, not a WebView, NativeScript or a JavaScript runtime. Web/code generation also work on other operating systems. The generated app is unsigned for local development; signing/notarization and distribution are outside this experiment.
247
+ ${hosts.join(' ')}
88
248
 
89
249
  ## Edit once
90
250
 
91
- Edit **shared/Welcome.lite.tsx**, then run \`${commands.run('generate')}\`. The build and startup commands also generate automatically. When the Web dev server is already running, run generate after editing the shared source; Vite then reloads the generated Vue file. Rebuild/reopen the native app to see edits.
251
+ Screens live in **shared/**: each \`Name.lite.tsx\` exports one component, and lowercase \`.ts\` files hold shared record types. \`${entry}\` is the screen every app opens (\`portability.entry\` in mavis.config.json). Run \`${commands.run('generate')}\` after editing; the start and build commands generate first. The Mavis compiler type-checks the sources with TypeScript, then writes each target's files:
92
252
 
93
- Mitosis ${v.mitosis} parses the source and generates Vue and SwiftUI. The local build adapter maps four Mavis primitives and reads the selected theme tokens from mavis-core. Generated files in web/ and native/Sources/MavisDesktop/ are replaceable outputs, not sources to edit. native/Package.swift and App.swift own the Mac window. Each host has its own local state; state is not synchronized between processes.
253
+ ${folders.join('\n')}
94
254
 
95
- Supported subset:
96
- - MColumn/MRow: gap and padding spacing tokens.
97
- - MText: one text literal or state binding, typography variant and color tone.
98
- - MButton: text, primary/secondary variant, and onClick with one local state assignment.
99
- - useStore: string, boolean or non-negative integer literals; actions assign same-type literals or increment an integer.
255
+ Generated folders are replaced on every run and kept out of Git; don't edit them. The sources use Mitosis's component format (\`useStore\`, \`useRef\`, \`Show\`, \`For\`), but Mitosis itself is not installed. Each app keeps its own state.
100
256
 
101
- Unsupported syntax/properties fail generation with a diagnostic. Existing .vue files, all other Mavis components, Nuxt, iOS/Android output, arbitrary TypeScript, props, loops, effects, async services, navigation and persistence are not included. The general Vue portability auditor and add-target migrations are not this compiler. Run \`${commands.run('generate')}\` to check both outputs.
257
+ What the sources can use:
258
+ - MColumn/MRow (gap, padding, label, onKeyDown for arrow keys), MGrid (gap, columns, minColumnWidth: as many equal columns as fit), MCard (gap, padding, tone; with onClick and a label the whole card is one button that shows text only), MText (variant, tone, text with values), MButton (text, variant, disabled, onClick, shortcut such as \`mod+k\`: Command on the Mac, Control or Command on the Web, nothing on touch).
259
+ - Form fields with value plus a change handler: MInput (label, placeholder, helperText, error, type text/email/password, multiline, rows, maxLength, disabled, readonly, onSubmit on Return, onEscape), MCheckbox (label, checked, indeterminate, helperText, disabled) and MSelect (label, value that may be undefined, options of SelectOption, placeholder, helperText, error, disabled). \`const titleRef = useRef<MavisFieldRef>(null)\` with \`ref={titleRef}\` on an MInput lets actions call \`titleRef.focus()\` and \`titleRef.blur()\`.
260
+ - Components from other shared files, with typed properties and callback properties.
261
+ - useStore with strings, numbers, booleans, string unions, records and arrays (initial values can come from properties), getters with a return type, and actions with parameters.
262
+ - Comparisons, && || !, ternaries, arithmetic, template literals, ?. and ??; string trim, toLowerCase, toUpperCase, includes, startsWith, endsWith and length; array filter, map, find, findIndex, some, every, includes, slice, join, toSorted, length and list[index] (which may be undefined); Math.min, max, floor, ceil, abs and round.
263
+ - In actions and event handlers: =, +=, -=, ++ and --, if/else, return, push, unshift and splice, and calls to other actions and callbacks.
264
+ - Show with else, and For with a key field. \`<Show when={…} animate>\` reveals and hides its content, and \`<For each={…} animate>\` animates rows that enter, leave or move.
102
265
 
103
- Web buttons use Mavis/Jolt. Native button feedback uses SwiftUI and respects Reduce Motion; **Jolt has no macOS adapter in this release**. macOS uses the selected fixed starter theme; automatic appearance switching and exact typography parity are not promised.
266
+ Anything else fails generation with file:line:column before any output changes. Numbers behave like JavaScript numbers in every app (Double in Swift).
104
267
 
105
- Build Web: \`${commands.run('build:web')}\`. Build the local Mac app without opening it: \`${commands.run('build:macos')}\`. Output: dist/${preset.name}.app. Stop the app normally from its menu or with Cmd+Q. Commit the generated ${commands.lockfile} after installation.
106
- `,
107
- )
108
- return { preset, files: new Map([...files].sort(([a], [b]) => a.localeCompare(b))) }
268
+ ## Motion
269
+
270
+ Buttons and cards press, animated Show content enters and leaves, and animated lists move through Jolt on every target: Mavis Web and Mavis on NativeScript run Jolt, and the Mac uses JoltSwiftUI. Reduce Motion is respected everywhere. Not available yet: async work, effects, navigation, persistence and the other Mavis components.
271
+
272
+ ## Build
273
+
274
+ \`${commands.run('build')}\` builds every target${mac ? `; the Mac app goes to dist/${preset.name}.app` : ''}.${native ? ' build:native bundles the NativeScript JavaScript for Android and iOS; use the NativeScript CLI for installable apps.' : ''} Commit the generated ${native ? 'lockfiles' : commands.lockfile} after installation.
275
+ `
109
276
  }
@@ -1,6 +1,7 @@
1
1
  import { spawn, spawnSync } from 'node:child_process'
2
+ import { catalog, requirements } from './capabilities.mjs'
2
3
 
3
- export const packageManagers = ['npm', 'pnpm', 'yarn']
4
+ export const packageManagers = catalog.packageManagers
4
5
 
5
6
  export function detectPackageManager(userAgent = process.env.npm_config_user_agent ?? '') {
6
7
  const name = userAgent.split('/')[0]
@@ -68,15 +69,22 @@ export function checkPackageManager(manager) {
68
69
  ok: false,
69
70
  detail: `${manager} --version did not return a valid version.`,
70
71
  }
71
- const [major, minor] = version.split('.').map(Number)
72
- const supported = manager !== 'pnpm' || major > 10 || (major === 10 && minor >= 26)
72
+ const minimum = requirements.packageManagers[manager]
73
+ const supported = !minimum || atLeast(version, minimum)
73
74
  return {
74
75
  name: manager,
75
76
  ok: supported,
76
- detail: supported ? version : `pnpm 10.26+ is required (found ${version}).`,
77
+ detail: supported ? version : `${manager} ${minimum}+ is required (found ${version}).`,
77
78
  }
78
79
  }
79
80
 
81
+ /** Whether a major.minor version reaches a minimum such as 22.16. */
82
+ export function atLeast(version, minimum) {
83
+ const [major, minor] = version.replace(/^v/, '').split('.').map(Number)
84
+ const [wantedMajor, wantedMinor = 0] = minimum.split('.').map(Number)
85
+ return major > wantedMajor || (major === wantedMajor && minor >= wantedMinor)
86
+ }
87
+
80
88
  export async function runInstall(manager, cwd, signal) {
81
89
  packageCommands(manager)
82
90
  signal?.throwIfAborted()