@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/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 Default: web
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 Vue templates are currently supported
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) {
@@ -262,7 +293,11 @@ try {
262
293
  })
263
294
  ui.note(nextSteps(plan.preset, options.install), 'Next steps')
264
295
  ui.message(`Make it yours: ${sharedEntry(plan.preset)}`)
265
- if (plan.preset.target !== 'web')
296
+ if (plan.preset.target === 'macos')
297
+ ui.message(
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.' : ''}`,
299
+ )
300
+ else if (plan.preset.target !== 'web')
266
301
  ui.message(
267
302
  'Mobile needs the NativeScript CLI and platform SDKs. Check your setup with --doctor.',
268
303
  )
package/src/doctor.mjs CHANGED
@@ -1,51 +1,91 @@
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'),
22
50
  ]
23
- if (config.target !== 'web') {
24
- const probe = (name, command, args) => {
25
- const result = spawnSync(command, args, { encoding: 'utf8', timeout: 10000 })
26
- results.push({
27
- name,
28
- ok: result.status === 0,
29
- detail: (result.error?.message ?? (result.stdout || result.stderr || 'No output'))
30
- .trim()
31
- .split('\n')[0],
32
- })
33
- }
34
- probe('NativeScript CLI', process.platform === 'win32' ? 'ns.cmd' : 'ns', ['--version'])
35
- probe('Java (Android)', 'java', ['-version'])
51
+ if (config.target === 'macos') {
52
+ const result =
53
+ process.platform === 'darwin'
54
+ ? spawnSync('xcrun', ['swift', '--version'], { encoding: 'utf8', timeout: 10000 })
55
+ : null
36
56
  results.push({
37
- name: 'Android SDK',
38
- ok: Boolean(process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT),
39
- detail: 'Set ANDROID_HOME for Android builds.',
57
+ name: 'SwiftUI build host',
58
+ ok: result?.status === 0,
59
+ detail: result
60
+ ? (result.error?.message ?? (result.stdout || result.stderr)).trim().split('\n')[0]
61
+ : 'macOS 14+ and Xcode are required for the native app. Web remains available.',
40
62
  })
41
- if (process.platform === 'darwin') probe('Xcode (iOS)', 'xcodebuild', ['-version'])
42
- else
63
+ // The project's own compiler copy, with its installed TypeScript and theme packages.
64
+ try {
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
+ })
43
70
  results.push({
44
- name: 'iOS host',
71
+ name: 'Shared sources',
72
+ ok: true,
73
+ detail: `${model.components.length} component(s) type-checked for ${config.targets.join(', ')}. Run generate to write them; this does not prove a build.`,
74
+ })
75
+ } catch (error) {
76
+ results.push({
77
+ name: 'Shared sources',
45
78
  ok: false,
46
- 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,
47
83
  })
84
+ }
85
+ if (config.targets.includes('native')) nativeChecks(results)
86
+ return results
48
87
  }
88
+ if (config.target !== 'web') nativeChecks(results)
49
89
  const portability = await checkPortability(cwd)
50
90
  results.push({
51
91
  name: 'Shared source portability',
@@ -54,3 +94,30 @@ export async function doctor(cwd = process.cwd()) {
54
94
  })
55
95
  return results
56
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 ADDED
@@ -0,0 +1,276 @@
1
+ import { versions as v, configOf, targetLabel } from './presets.mjs'
2
+ import { packageCommands } from './package-manager.mjs'
3
+ import { joltSwift } from '../templates/macos/scripts/portable/emit-swift.mjs'
4
+
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
+ */
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')
16
+ const commands = packageCommands(preset.packageManager)
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 = {
26
+ NAME: preset.name,
27
+ APPID: preset.name.replaceAll('-', ''),
28
+ THEME: preset.theme,
29
+ APPEARANCE: preset.theme === 'midnight' ? 'dark' : 'light',
30
+ BACKGROUND: preset.theme === 'midnight' ? '#15121C' : '#FAF7FA',
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`,
66
+ type: 'module',
67
+ scripts: { dev: 'vite', build: 'vite build', preview: 'vite preview' },
68
+ dependencies: {
69
+ '@getcortexlabs/mavis-core': v.mavis,
70
+ '@getcortexlabs/mavis-web': v.mavis,
71
+ '@rafaelaugusto/jolt': v.jolt,
72
+ vue: v.vue,
73
+ },
74
+ devDependencies: {
75
+ typescript: v.typescript,
76
+ vite: v.vite,
77
+ '@vitejs/plugin-vue': v.vuePlugin,
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`,
103
+ ...(preset.packageManager === 'yarn'
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
+ }
112
+ : {}),
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
+ }),
166
+ )
167
+ files.set(
168
+ 'mavis.config.json',
169
+ json({
170
+ ...configOf(preset),
171
+ portability: { roots: ['shared'], mode: 'shared-tsx-experimental', entry },
172
+ }),
173
+ )
174
+ files.set(
175
+ '.gitignore',
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'),
193
+ )
194
+ if (preset.packageManager === 'pnpm') {
195
+ files.set(
196
+ 'pnpm-workspace.yaml',
197
+ `packages:${web ? '\n - apps/web' : ' []'}\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n`,
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
+ }
205
+ if (preset.packageManager === 'yarn') {
206
+ files.set('.yarnrc.yml', 'nodeLinker: node-modules\n')
207
+ // An empty lockfile marks a separate Yarn project, including before its first install.
208
+ files.set('yarn.lock', '')
209
+ if (native) files.set('apps/mobile/yarn.lock', '')
210
+ }
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
+ }
214
+
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.
240
+
241
+ ## Start
242
+
243
+ \`\`\`sh
244
+ ${start.join('\n')}
245
+ \`\`\`
246
+
247
+ ${hosts.join(' ')}
248
+
249
+ ## Edit once
250
+
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:
252
+
253
+ ${folders.join('\n')}
254
+
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.
256
+
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.
265
+
266
+ Anything else fails generation with file:line:column before any output changes. Numbers behave like JavaScript numbers in every app (Double in Swift).
267
+
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
+ `
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()
@@ -1,4 +1,5 @@
1
1
  import { lstat, readFile, readdir, writeFile } from 'node:fs/promises'
2
+ import { normalizeConfig } from './presets.mjs'
2
3
  import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
3
4
  import ts from 'typescript'
4
5
  import { parse } from '@vue/compiler-sfc'
@@ -293,7 +294,7 @@ export function inspectSource(source, filename, { allowImports = [] } = {}) {
293
294
 
294
295
  async function projectConfig(root) {
295
296
  try {
296
- return JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8'))
297
+ return normalizeConfig(JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8')))
297
298
  } catch (error) {
298
299
  if (error.code === 'ENOENT') return {}
299
300
  throw new Error(`Cannot read mavis.config.json: ${error.message}`)
@@ -304,6 +305,10 @@ async function projectConfig(root) {
304
305
  export async function checkPortability(root = process.cwd(), options = {}) {
305
306
  root = resolve(root)
306
307
  const config = await projectConfig(root)
308
+ if (config.authoring === 'mitosis')
309
+ throw new Error(
310
+ 'The Vue portability auditor does not validate SwiftUI. Run your package manager’s generate script to check the experimental Mitosis source; import migrations are not supported for this target.',
311
+ )
307
312
  const roots = options.path
308
313
  ? [options.path]
309
314
  : (config.portability?.roots ?? [