@getcortexlabs/create-mavis 0.1.0-rc.12.2 → 0.1.0-rc.14

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 (51) hide show
  1. package/README.md +30 -9
  2. package/package.json +4 -2
  3. package/src/adapters.mjs +83 -0
  4. package/src/add-macos.mjs +386 -0
  5. package/src/add-target.mjs +1 -1
  6. package/src/capabilities.mjs +647 -0
  7. package/src/cli.mjs +129 -16
  8. package/src/doctor.mjs +159 -36
  9. package/src/macos-capabilities.generated.mjs +4190 -0
  10. package/src/macos.mjs +343 -58
  11. package/src/migrate-directory.mjs +121 -0
  12. package/src/package-manager.mjs +12 -4
  13. package/src/portability.mjs +110 -6
  14. package/src/presets.mjs +15 -108
  15. package/src/scaffold.mjs +32 -5
  16. package/src/ui.mjs +124 -82
  17. package/templates/directory/host/directory-storage.ts +78 -0
  18. package/templates/directory/macos/DirectoryStorage.swift +68 -0
  19. package/templates/directory/mobile/src/app.ts +11 -8
  20. package/templates/directory/nuxt/app/plugins/mavis.ts +11 -8
  21. package/templates/directory/shared/Edit.vue +8 -5
  22. package/templates/directory/shared/directory-store.ts +42 -46
  23. package/templates/directory/vite/src/main.ts +11 -8
  24. package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +57 -0
  25. package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +33 -0
  26. package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +251 -0
  27. package/templates/macos/examples/tasks/shared/types.ts +10 -0
  28. package/templates/macos/mobile/src/App.vue +14 -0
  29. package/templates/macos/mobile/src/app.ts +7 -0
  30. package/templates/macos/native/Package.swift +11 -1
  31. package/templates/macos/native/Sources/MavisDesktop/App.swift +27 -12
  32. package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +45 -0
  33. package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
  34. package/templates/macos/root/tsconfig.json +14 -0
  35. package/templates/macos/scripts/generate.mjs +12 -16
  36. package/templates/macos/scripts/macos-manifest.mjs +33 -0
  37. package/templates/macos/scripts/macos.mjs +26 -19
  38. package/templates/macos/shared/Welcome.lite.tsx +8 -6
  39. package/templates/macos/{index.html → web/index.html} +2 -2
  40. package/templates/macos/web/src/main.js +212 -0
  41. package/templates/macos/web/src/mavis.js +2 -0
  42. package/templates/macos/web/{style.css → src/style.css} +3 -2
  43. package/templates/macos/web/vite.config.mjs +14 -0
  44. package/templates/migrations/directory-rc13.json +36 -0
  45. package/templates/mobile/src/mavis.ts +2 -82
  46. package/templates/mobile/webpack.config.js +4 -0
  47. package/templates/nuxt/app/mavis.ts +2 -84
  48. package/templates/vite/src/mavis.ts +2 -84
  49. package/templates/macos/scripts/portable.mjs +0 -395
  50. package/templates/macos/vite.config.mjs +0 -3
  51. package/templates/macos/web/main.js +0 -15
package/src/cli.mjs CHANGED
@@ -5,41 +5,65 @@ import { confirm, isCancel } from '@clack/prompts'
5
5
  import { readFile } from 'node:fs/promises'
6
6
  import { scaffold, installProject } from './scaffold.mjs'
7
7
  import { planTarget, applyTarget } from './add-target.mjs'
8
- import { checkPortability } from './portability.mjs'
8
+ import { planMacos, applyMacos } from './add-macos.mjs'
9
+ import { migrationDiff } from './migrate-directory.mjs'
10
+ import { checkPortability, formatMacReadiness } from './portability.mjs'
9
11
  import { doctor } from './doctor.mjs'
10
12
  import {
13
+ atLeast,
11
14
  checkPackageManager,
12
15
  detectPackageManager,
13
16
  packageCommands,
14
17
  runInstall,
15
18
  } from './package-manager.mjs'
16
19
  import { resolvePreset } from './presets.mjs'
20
+ import {
21
+ chosenTargets,
22
+ describeCapabilities,
23
+ formatCapabilities,
24
+ recommendation,
25
+ requirements,
26
+ } from './capabilities.mjs'
17
27
  import { nextSteps, projectSummary, sharedEntry, terminalUI, wizard } from './ui.mjs'
18
28
 
19
29
  const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
20
- const help = `Create Mavis — Vue Web, Nuxt and NativeScript
30
+ const help = `Create Mavis — Web, Native (iOS/Android) and Mac in any combination
21
31
 
22
32
  npm create @getcortexlabs/mavis@latest
23
- create-mavis my-app --target both --web nuxt --package-manager pnpm --no-install
33
+ create-mavis my-app --targets web,native,macos --package-manager pnpm --no-install
34
+ create-mavis my-app --targets web,native --web nuxt
24
35
 
25
- --target mobile|web|both|macos Default: web; macos is experimental Mitosis + SwiftUI
36
+ --targets web,native,macos Any combination; default: web. With macos, shared
37
+ screens are TSX compiled for every target (experimental)
38
+ --target mobile|web|both|macos
39
+ Earlier names: native, web, web+native, web+macos
26
40
  --add-native Add apps/mobile to an existing Vue/Vite or Nuxt app
27
41
  --add-web Add apps/web to an existing NativeScript-Vue app
42
+ --add-macos Preview adding SwiftUI to an existing app; --write applies
43
+ --migrate-directory Opt in to migrate an unmodified RC.13 Directory example
44
+ --shared-root path Source roots for --add-macos (comma-separated)
45
+ --entry path.vue Shared Vue/TSX entry for --add-macos
28
46
  --screen path.vue Reuse an existing screen without moving it
29
47
  --screen-root screen|content Existing MScreen or content to wrap (auto-detected)
30
48
  --web vite|nuxt Default: vite
31
49
  --rendering client|ssr|ssg Default: client (Vite), ssr (Nuxt)
32
- --example welcome|directory Starter or shared search/detail/edit reference
50
+ --capabilities Show what can be created, how each combination has been
51
+ validated and what is planned (add --json for tools)
52
+ --familiar vue|react|angular|svelte|solid|other
53
+ What you already know. Changes the advice, not what runs
54
+ --example welcome|directory|tasks
55
+ Starter, shared search/detail/edit reference, or the
56
+ Tasks app (with macos: one source for every target)
33
57
  --check-portability Audit shared sources without SDK checks
34
58
  --path directory Override the configured shared source directory
35
59
  --fix-imports Preview safe renderer-import replacements
36
- --write Apply the previewed import migration
60
+ --write Apply the previewed import migration or Mac target
37
61
  --json Machine-readable portability diagnostics
38
62
  --theme mavis|midnight Default: mavis
39
63
  --package-manager npm|pnpm|yarn
40
64
  Default: the invoking manager, or npm
41
65
  --framework vue Vue is currently supported
42
- --authoring vue|mitosis Mitosis only for the experimental macos starter
66
+ --authoring vue|mitosis Follows the targets: mitosis (shared TSX) with macos
43
67
  --yes, -y Use defaults without prompts (skip installation)
44
68
  --install / --no-install Install dependencies now or later
45
69
  --dry-run Show the complete file plan without writing
@@ -65,14 +89,21 @@ try {
65
89
  allowPositionals: true,
66
90
  options: {
67
91
  target: { type: 'string' },
92
+ targets: { type: 'string' },
68
93
  'add-native': { type: 'boolean' },
69
94
  'add-web': { type: 'boolean' },
95
+ 'add-macos': { type: 'boolean' },
96
+ 'migrate-directory': { type: 'boolean' },
97
+ 'shared-root': { type: 'string' },
98
+ entry: { type: 'string' },
70
99
  screen: { type: 'string' },
71
100
  'screen-root': { type: 'string' },
72
101
  web: { type: 'string' },
73
102
  rendering: { type: 'string' },
74
103
  theme: { type: 'string' },
75
104
  example: { type: 'string' },
105
+ capabilities: { type: 'boolean' },
106
+ familiar: { type: 'string' },
76
107
  'check-portability': { type: 'boolean' },
77
108
  path: { type: 'string' },
78
109
  'fix-imports': { type: 'boolean' },
@@ -91,15 +122,84 @@ try {
91
122
  },
92
123
  })
93
124
  if (values.help) console.log(help)
125
+ else if (values.capabilities)
126
+ console.log(
127
+ values.json ? JSON.stringify(describeCapabilities(), null, 2) : formatCapabilities(),
128
+ )
94
129
  else if (values.version) console.log(version)
95
- 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}.`)
130
+ else if (values['add-macos']) {
131
+ if (
132
+ positionals.length ||
133
+ values['add-native'] ||
134
+ values['add-web'] ||
135
+ values.target ||
136
+ values.targets ||
137
+ values['check-portability'] ||
138
+ values['fix-imports'] ||
139
+ values.path ||
140
+ values.doctor ||
141
+ values.example ||
142
+ values.theme ||
143
+ values.framework ||
144
+ values.authoring ||
145
+ values.screen ||
146
+ values['screen-root'] ||
147
+ values.web ||
148
+ values.rendering
149
+ )
150
+ throw new Error(
151
+ 'Run --add-macos in the existing project. Choose source roots with --shared-root and an entry with --entry.',
152
+ )
153
+ if (values.install || values['no-install'])
154
+ throw new Error(
155
+ '--add-macos does not install dependencies; review and apply with --write, then run your package manager.',
156
+ )
157
+ if (values.write && values['dry-run']) throw new Error('Choose --write or --dry-run, not both.')
158
+ const plan = await planMacos({
159
+ roots: values['shared-root']?.split(',').map((root) => root.trim()),
160
+ entry: values.entry,
161
+ packageManager: values['package-manager'],
162
+ migrateDirectory: values['migrate-directory'],
163
+ })
164
+ const summary = {
165
+ directory: 'apps/macos',
166
+ entry: plan.entry,
167
+ roots: plan.roots,
168
+ manager: plan.manager,
169
+ alreadyAdded: plan.alreadyAdded,
170
+ components: plan.components,
171
+ files: [...plan.files.keys()],
172
+ config: plan.config,
173
+ migration: plan.migration ?? [],
174
+ applied: Boolean(values.write && !plan.alreadyAdded),
175
+ }
176
+ if (values.write) await applyMacos(plan, { signal: cancellation.signal })
177
+ if (values.json) console.log(JSON.stringify(summary, null, 2))
178
+ else {
179
+ ui.message(
180
+ `${plan.alreadyAdded ? 'Already configured' : values.write ? 'Added' : 'Preview'}: SwiftUI in apps/macos; ${plan.components} shared components`,
181
+ )
182
+ for (const diff of summary.migration) console.log(migrationDiff(diff))
183
+ for (const name of summary.files)
184
+ console.log(` ${plan.original.get(name) === undefined ? '+' : '~'} ${name}`)
185
+ console.log(
186
+ plan.alreadyAdded
187
+ ? 'Existing files were preserved.'
188
+ : values.write
189
+ ? `Run ${packageCommands(plan.manager).install}, then ${packageCommands(plan.manager).run('build:macos')}.`
190
+ : 'No files changed. Review this plan and rerun with --write to add Mac and migrate mavis.config.json to schema 2.',
191
+ )
192
+ }
193
+ } else if (values['add-native'] || values['add-web']) {
194
+ if (!atLeast(process.versions.node, requirements.node))
195
+ throw new Error(
196
+ `Mavis needs Node.js ${requirements.node} or newer. You are using ${process.version}.`,
197
+ )
99
198
  if (values['add-native'] && values['add-web']) throw new Error('Add one target at a time.')
100
199
  if (
101
200
  positionals.length ||
102
201
  values.target ||
202
+ values.targets ||
103
203
  values['check-portability'] ||
104
204
  values['fix-imports'] ||
105
205
  values.write ||
@@ -117,6 +217,8 @@ try {
117
217
  throw new Error('--web and --rendering belong to --add-web.')
118
218
  if (values.install && values['no-install'])
119
219
  throw new Error('Choose either --install or --no-install.')
220
+ if (values.entry || values['shared-root'] || values['migrate-directory'])
221
+ throw new Error('--entry and --shared-root require --add-macos.')
120
222
  if (values['screen-root'] && !values.screen) throw new Error('--screen-root requires --screen.')
121
223
  const target = await planTarget({
122
224
  target: values['add-native'] ? 'mobile' : 'web',
@@ -204,13 +306,20 @@ try {
204
306
  console.log(
205
307
  `${result.files.length} files checked; ${result.diagnostics.length} findings. ${values['fix-imports'] && !values.write ? 'Preview only. Use --write to apply safe import changes.' : ''}`,
206
308
  )
309
+ console.log(formatMacReadiness(result.macos))
207
310
  }
208
- if (result.diagnostics.length) process.exitCode = 1
311
+ // A project without a Mac target is only told; one with it has to be ready.
312
+ const config = await readFile('mavis.config.json', 'utf8').then(JSON.parse, () => ({}))
313
+ const blocked =
314
+ config.targets?.includes('macos') && result.macos.files?.some((file) => !file.ready)
315
+ if (result.diagnostics.length || blocked) process.exitCode = 1
209
316
  } else if (values.doctor) {
210
317
  const results = await doctor()
211
318
  for (const item of results) console.log(`${item.ok ? '✓' : '—'} ${item.name}: ${item.detail}`)
212
319
  if (results.some((item) => !item.ok)) process.exitCode = 1
213
320
  } else {
321
+ if (values.entry || values['shared-root'] || values['migrate-directory'])
322
+ throw new Error('--entry and --shared-root require --add-macos.')
214
323
  if (values.screen || values['screen-root'])
215
324
  throw new Error('--screen requires --add-native or --add-web.')
216
325
  if (values.write || values.path || values.json)
@@ -218,9 +327,10 @@ try {
218
327
  if (positionals.length > 1) throw new Error('Provide one project name.')
219
328
  if (values.install && values['no-install'])
220
329
  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}.`)
330
+ if (!atLeast(process.versions.node, requirements.node))
331
+ throw new Error(
332
+ `Mavis needs Node.js ${requirements.node} or newer. You are using ${process.version}.`,
333
+ )
224
334
  let options = {
225
335
  ...values,
226
336
  name: positionals[0],
@@ -230,6 +340,9 @@ try {
230
340
  }
231
341
  resolvePreset({ ...options, name: options.name ?? 'my-mavis-app' })
232
342
  ui.intro(version)
343
+ // Advice for someone coming from another framework. It never changes what gets created.
344
+ const advice = recommendation(values.familiar, chosenTargets(options))
345
+ if (advice) ui.message(advice)
233
346
  const useWizard = interactive && !values.yes && !options.dryRun
234
347
  if (useWizard) options = await wizard(options, cancellation.signal)
235
348
  if (!options) {
@@ -264,7 +377,7 @@ try {
264
377
  ui.message(`Make it yours: ${sharedEntry(plan.preset)}`)
265
378
  if (plan.preset.target === 'macos')
266
379
  ui.message(
267
- 'Experimental: four starter primitives; macOS 14+ and Xcode required. See the generated README for the supported subset.',
380
+ `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
381
  )
269
382
  else if (plan.preset.target !== 'web')
270
383
  ui.message(
package/src/doctor.mjs CHANGED
@@ -1,21 +1,40 @@
1
+ import { pathToFileURL } from 'node:url'
2
+ import { createRequire } from 'node:module'
1
3
  import { spawnSync } from 'node:child_process'
2
4
  import { readFile } from 'node:fs/promises'
3
5
  import { checkPortability } from './portability.mjs'
4
6
  import { join } from 'node:path'
5
- import { checkPackageManager } from './package-manager.mjs'
7
+ import { atLeast, checkPackageManager } from './package-manager.mjs'
8
+ import {
9
+ availabilityLabel,
10
+ availabilityOf,
11
+ catalog,
12
+ checkProject,
13
+ normalizeConfig,
14
+ requirements,
15
+ targetLabel,
16
+ } from './capabilities.mjs'
6
17
 
7
18
  export async function doctor(cwd = process.cwd()) {
8
19
  let config
9
20
  try {
10
- config = JSON.parse(await readFile(join(cwd, 'mavis.config.json'), 'utf8'))
21
+ config = normalizeConfig(JSON.parse(await readFile(join(cwd, 'mavis.config.json'), 'utf8')))
11
22
  } catch {
12
23
  throw new Error('Run --doctor from a generated project containing mavis.config.json.')
13
24
  }
14
- const [major, minor] = process.versions.node.split('.').map(Number)
25
+ // The same check the creator runs before writing a project, on what this one records.
26
+ const project = checkRecordedProject(config)
15
27
  const results = [
16
28
  {
17
- name: 'Node.js 22.16+',
18
- ok: major > 22 || (major === 22 && minor >= 16),
29
+ name: 'Project configuration',
30
+ ok: project.ok,
31
+ detail: project.ok
32
+ ? `${targetLabel(config.targets)} · ${catalog.authoring[config.authoring].label} · ${config.portability?.existing ? 'existing application; experimental Mac target' : availabilityLabel(availabilityOf(config))}`
33
+ : project.message.split('\n')[0],
34
+ },
35
+ {
36
+ name: `Node.js ${requirements.node}+`,
37
+ ok: atLeast(process.versions.node, requirements.node),
19
38
  detail: process.version,
20
39
  },
21
40
  checkPackageManager(config.packageManager ?? 'npm'),
@@ -32,46 +51,44 @@ export async function doctor(cwd = process.cwd()) {
32
51
  ? (result.error?.message ?? (result.stdout || result.stderr)).trim().split('\n')[0]
33
52
  : 'macOS 14+ and Xcode are required for the native app. Web remains available.',
34
53
  })
35
- const { validateSource } = await import('../templates/macos/scripts/portable.mjs')
54
+ // Use the compiler installed in this project, not a copied implementation.
36
55
  try {
37
- validateSource(await readFile(join(cwd, 'shared/Welcome.lite.tsx'), 'utf8'))
56
+ const compiler = await import(
57
+ pathToFileURL(
58
+ createRequire(join(cwd, 'package.json')).resolve('@getcortexlabs/mavis-compiler'),
59
+ )
60
+ )
61
+ results.push(...(await checkMacVersions(cwd, config, compiler)))
62
+ compiler.macAppSettings(config.macos, config.name)
63
+ const { model } = await compiler.compileProject(
64
+ await compiler.readShared(cwd, { roots: config.portability?.roots }),
65
+ {
66
+ theme: config.theme,
67
+ root: config.portability?.entry ?? 'Welcome',
68
+ sourceRoot: config.portability?.sourceRoot ?? config.portability?.roots?.[0] ?? 'shared',
69
+ destinations: config.portability?.destinations,
70
+ },
71
+ )
72
+ compiler.startupPlan(model, config.portability?.startup)
38
73
  results.push({
39
- name: 'Experimental source grammar',
74
+ name: 'Shared sources',
40
75
  ok: true,
41
- detail:
42
- 'Grammar accepted. Run generate to validate tokens and both outputs; this does not prove a native build.',
76
+ detail: `${model.components.length} component(s) type-checked for ${config.targets.join(', ')}. Run generate to write them; this does not prove a build.`,
43
77
  })
44
78
  } 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
79
  results.push({
70
- name: 'iOS host',
80
+ name: 'Shared sources',
71
81
  ok: false,
72
- detail: 'iOS builds require macOS and Xcode; Android remains available.',
82
+ detail:
83
+ error.code === 'ERR_MODULE_NOT_FOUND'
84
+ ? 'Install the project dependencies, then run doctor again.'
85
+ : error.message,
73
86
  })
87
+ }
88
+ if (config.targets.includes('native')) nativeChecks(results)
89
+ return results
74
90
  }
91
+ if (config.target !== 'web') nativeChecks(results)
75
92
  const portability = await checkPortability(cwd)
76
93
  results.push({
77
94
  name: 'Shared source portability',
@@ -80,3 +97,109 @@ export async function doctor(cwd = process.cwd()) {
80
97
  })
81
98
  return results
82
99
  }
100
+
101
+ /** Configuration choices only; compiler diagnostics validate custom theme modules separately. */
102
+ export function checkRecordedProject(config) {
103
+ if (config.portability?.existing) return existingProject(config)
104
+ return checkProject({
105
+ name: config.name,
106
+ targets: config.targets,
107
+ web: config.web ?? undefined,
108
+ rendering: config.rendering ?? undefined,
109
+ framework: config.framework,
110
+ authoring: config.authoring,
111
+ example: config.example,
112
+ theme:
113
+ config.targets?.includes('macos') && typeof config.theme === 'object'
114
+ ? undefined
115
+ : config.theme,
116
+ packageManager: config.packageManager,
117
+ })
118
+ }
119
+
120
+ function nativeChecks(results) {
121
+ const probe = (name, command, args) => {
122
+ const result = spawnSync(command, args, { encoding: 'utf8', timeout: 10000 })
123
+ results.push({
124
+ name,
125
+ ok: result.status === 0,
126
+ detail: (result.error?.message ?? (result.stdout || result.stderr || 'No output'))
127
+ .trim()
128
+ .split('\n')[0],
129
+ })
130
+ }
131
+ probe('NativeScript CLI', process.platform === 'win32' ? 'ns.cmd' : 'ns', ['--version'])
132
+ probe('Java (Android)', 'java', ['-version'])
133
+ results.push({
134
+ name: 'Android SDK',
135
+ ok: Boolean(process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT),
136
+ detail: 'Set ANDROID_HOME for Android builds.',
137
+ })
138
+ if (process.platform === 'darwin') probe('Xcode (iOS)', 'xcodebuild', ['-version'])
139
+ else
140
+ results.push({
141
+ name: 'iOS host',
142
+ ok: false,
143
+ detail: 'iOS builds require macOS and Xcode; Android remains available.',
144
+ })
145
+ }
146
+
147
+ function existingProject(config) {
148
+ const ok =
149
+ Array.isArray(config.targets) &&
150
+ config.targets.includes('macos') &&
151
+ config.targets.every((target) => catalog.targets[target]) &&
152
+ ['vue', 'mitosis'].includes(config.authoring) &&
153
+ catalog.packageManagers.includes(config.packageManager) &&
154
+ (!config.targets.includes('web') ||
155
+ catalog.hosts[config.web]?.rendering?.includes(config.rendering))
156
+ return {
157
+ ok,
158
+ message:
159
+ 'Invalid targets, authoring, package manager or Web host/rendering in mavis.config.json.',
160
+ }
161
+ }
162
+
163
+ /** Read-only release alignment check, independent of the Swift/NativeScript SDK probes. */
164
+ export async function checkMacVersions(cwd, config, compiler) {
165
+ const results = []
166
+ const manifests = []
167
+ for (const name of ['package.json', 'apps/web/package.json', 'apps/mobile/package.json']) {
168
+ try {
169
+ manifests.push(JSON.parse(await readFile(join(cwd, name), 'utf8')))
170
+ } catch (error) {
171
+ if (error.code !== 'ENOENT') throw error
172
+ }
173
+ }
174
+ const dependencies = manifests.map((pkg) => ({ ...pkg.devDependencies, ...pkg.dependencies }))
175
+ const declared = dependencies[0]?.['@getcortexlabs/mavis-compiler']
176
+ const expected = config.versions?.mavis ?? compiler.compilerVersion
177
+ const renderers = dependencies.flatMap((dep) =>
178
+ ['@getcortexlabs/mavis-core', '@getcortexlabs/mavis-web', '@getcortexlabs/mavis'].flatMap(
179
+ (name) => (dep[name] ? [dep[name]] : []),
180
+ ),
181
+ )
182
+ results.push({
183
+ name: 'Mavis compiler version',
184
+ ok:
185
+ declared === compiler.compilerVersion &&
186
+ compiler.compilerVersion === expected &&
187
+ renderers.every((version) => [expected, '^' + expected, '~' + expected].includes(version)),
188
+ detail: `Installed compiler ${compiler.compilerVersion}; requested ${declared ?? 'missing'}; Mavis ${expected}. Upgrade Mavis and the compiler together.`,
189
+ })
190
+ const jolts = dependencies.flatMap((dep) =>
191
+ dep['@rafaelaugusto/jolt'] ? [dep['@rafaelaugusto/jolt']] : [],
192
+ )
193
+ const swift = await readFile(join(cwd, 'apps/macos/Package.swift'), 'utf8')
194
+ const pin = /jolt-swift[^\n]*exact:\s*"([^"]+)"/.exec(swift)?.[1]
195
+ const expectedJolt = config.versions?.jolt ?? compiler.joltSwift.version
196
+ results.push({
197
+ name: 'Jolt / SwiftUI version',
198
+ ok:
199
+ pin === expectedJolt &&
200
+ pin === compiler.joltSwift.version &&
201
+ jolts.every((version) => version === pin),
202
+ detail: `Jolt ${[...new Set(jolts)].join(', ') || expectedJolt}; SwiftUI ${pin ?? 'missing exact pin'}; compiler expects ${compiler.joltSwift.version}.`,
203
+ })
204
+ return results
205
+ }