@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/macos.mjs CHANGED
@@ -1,109 +1,394 @@
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 '@getcortexlabs/mavis-compiler'
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
+ const directory = preset.example === 'directory'
19
+ const nuxt = preset.web === 'nuxt'
20
+ // The screen every app opens. Tasks is a list beside its detail, so it gets a wider page.
21
+ const entry = directory ? 'Directory' : tasks ? 'Tasks' : 'Welcome'
22
+ const hosts = [
23
+ web && (nuxt ? `Nuxt (${preset.rendering}) on the Web` : 'Vue on the Web'),
24
+ native && 'NativeScript on iOS and Android',
25
+ mac && 'SwiftUI on the Mac',
26
+ ].filter(Boolean)
27
+ const replacements = {
8
28
  NAME: preset.name,
9
29
  APPID: preset.name.replaceAll('-', ''),
10
30
  THEME: preset.theme,
11
31
  APPEARANCE: preset.theme === 'midnight' ? 'dark' : 'light',
12
32
  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',
33
+ TARGETS: targetLabel(targets),
34
+ HOSTS: hosts.join(' · '),
35
+ JOLT_SWIFT: joltSwift.version,
36
+ WEB_WIDTH: tasks ? '1120px' : '760px',
37
+ MAC_WIDTH: tasks ? '1120' : '820',
38
+ MAC_MIN_WIDTH: tasks ? '760' : '640',
39
+ MAC_DEFAULT_WIDTH: tasks ? '1180' : '860',
40
+ SHARED: '#shared-ui',
41
+ SHARED_ROOT: '../../shared',
42
+ }
43
+ await copyTemplate(files, 'macos/root', '', replacements)
44
+ await copyTemplate(
45
+ files,
46
+ directory ? 'directory/shared' : tasks ? 'macos/examples/tasks/shared' : 'macos/shared',
47
+ 'shared',
48
+ replacements,
49
+ )
50
+ await copyTemplate(files, 'macos/scripts', 'scripts', replacements)
51
+ for (const path of files.keys()) if (path.startsWith('scripts/portable/')) files.delete(path)
52
+ if (!mac) {
53
+ files.delete('scripts/macos.mjs')
54
+ files.delete('scripts/macos-manifest.mjs')
55
+ }
56
+
57
+ const common = { private: true, version: '0.0.0', engines: { node: '>=22.16' } }
58
+ const generate = 'node scripts/generate.mjs'
59
+ const builds = []
60
+ const scripts = { generate }
61
+ if (web) {
62
+ await copyTemplate(files, nuxt ? 'nuxt' : 'macos/web', 'apps/web', replacements)
63
+ if (nuxt && !directory) {
64
+ await copyTemplate(files, 'macos/web/src', 'apps/web/app', replacements)
65
+ files.set('apps/web/app/assets/main.css', files.get('apps/web/app/style.css'))
66
+ for (const name of ['main.js', 'mavis.js', 'style.css']) files.delete(`apps/web/app/${name}`)
67
+ files.set(
68
+ 'apps/web/app/app.vue',
69
+ `<script setup lang="ts">
70
+ import Root, { screen } from './generated/entry'
71
+ </script>
72
+ <template><Root v-if="screen" /><main v-else class="mavis-page"><Root /></main></template>
73
+ `,
74
+ )
75
+ }
76
+ if (directory) {
77
+ await copyTemplate(files, `directory/${nuxt ? 'nuxt' : 'vite'}`, 'apps/web', replacements)
78
+ await copyTemplate(
79
+ files,
80
+ 'directory/host',
81
+ `apps/web/${nuxt ? 'app/utils' : 'src'}`,
82
+ replacements,
83
+ )
84
+ if (!nuxt) {
85
+ files.delete('apps/web/src/main.js')
86
+ files.set(
87
+ 'apps/web/index.html',
88
+ files.get('apps/web/index.html').replace('/src/main.js', '/src/main.ts'),
89
+ )
90
+ }
91
+ }
92
+ scripts['dev:web'] = `${generate} && ${commands.run('dev', 'apps/web')}`
93
+ scripts['build:web'] =
94
+ `${generate} && ${commands.run(nuxt && preset.rendering === 'ssg' ? 'generate' : 'build', 'apps/web')}`
95
+ builds.push('build:web')
96
+ files.set(
97
+ 'apps/web/package.json',
98
+ json({
99
+ ...common,
100
+ name: `${preset.name}-web`,
21
101
  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
- },
102
+ scripts: nuxt
103
+ ? {
104
+ dev: 'nuxt dev',
105
+ build: 'nuxt build',
106
+ generate: 'nuxt generate',
107
+ preview: 'nuxt preview',
108
+ typecheck: 'nuxt typecheck',
109
+ postinstall: 'nuxt prepare',
110
+ }
111
+ : { dev: 'vite', build: 'vite build', preview: 'vite preview' },
30
112
  dependencies: {
31
113
  '@getcortexlabs/mavis-core': v.mavis,
32
114
  '@getcortexlabs/mavis-web': v.mavis,
33
115
  '@rafaelaugusto/jolt': v.jolt,
34
116
  vue: v.vue,
117
+ '@vue/runtime-core': v.vue,
118
+ ...(nuxt ? { nuxt: v.nuxt } : {}),
119
+ ...(directory && !nuxt ? { 'vue-router': v.router } : {}),
35
120
  },
36
121
  devDependencies: {
37
- '@builder.io/mitosis': v.mitosis,
38
122
  typescript: v.typescript,
39
- vite: v.vite,
40
- '@vitejs/plugin-vue': v.vuePlugin,
123
+ 'vue-tsc': v.vueTsc,
124
+ '@types/node': v.nodeTypes,
125
+ ...(!nuxt ? { vite: v.vite, '@vitejs/plugin-vue': v.vuePlugin } : {}),
41
126
  },
127
+ }),
128
+ )
129
+ }
130
+ if (native) {
131
+ await copyTemplate(files, 'mobile', 'apps/mobile', replacements)
132
+ await copyTemplate(files, 'macos/mobile', 'apps/mobile', replacements)
133
+ if (directory) {
134
+ await copyTemplate(files, 'directory/mobile', 'apps/mobile', replacements)
135
+ await copyTemplate(files, 'directory/host', 'apps/mobile/src', replacements)
136
+ }
137
+ // The generated screens are the app's shared code; the TSX sources stay out of vue-tsc.
138
+ files.set(
139
+ 'apps/mobile/tsconfig.json',
140
+ files
141
+ .get('apps/mobile/tsconfig.json')
142
+ .replace('"include": ["src", "../../shared"]', '"include": ["src"]'),
143
+ )
144
+ scripts.ios = `${generate} && ${commands.run('ios', 'apps/mobile')}`
145
+ scripts.android = `${generate} && ${commands.run('android', 'apps/mobile')}`
146
+ scripts['build:native'] =
147
+ `${generate} && ${commands.run('bundle:android', 'apps/mobile')} && ${commands.run('bundle:ios', 'apps/mobile')}`
148
+ scripts['install:apps'] = `${commands.install} && ${commands.installAt('apps/mobile')}`
149
+ builds.push('build:native')
150
+ files.set(
151
+ 'apps/mobile/package.json',
152
+ json({
153
+ ...common,
154
+ name: `${preset.name}-mobile`,
42
155
  ...(preset.packageManager === 'yarn'
43
- ? { resolutions: { vue: v.vue }, dependenciesMeta: { esbuild: { built: true } } }
156
+ ? {
157
+ dependenciesMeta: {
158
+ esbuild: { built: true },
159
+ '@nativescript/core': { built: true },
160
+ '@parcel/watcher': { built: true },
161
+ 'core-js-pure': { built: false },
162
+ },
163
+ }
44
164
  : {}),
45
- },
46
- null,
47
- 2,
48
- ) + '\n',
165
+ main: 'src/app.ts',
166
+ scripts: {
167
+ android: 'ns run android',
168
+ ios: 'ns run ios',
169
+ typecheck: 'vue-tsc --noEmit',
170
+ 'bundle:android': 'webpack --env android',
171
+ 'bundle:ios': 'webpack --env ios',
172
+ },
173
+ dependencies: {
174
+ '@getcortexlabs/mavis-core': v.mavis,
175
+ '@rafaelaugusto/jolt': v.jolt,
176
+ '@getcortexlabs/mavis': v.mavis,
177
+ '@nativescript/core': v.nativeCore,
178
+ 'nativescript-vue': v.nativeVue,
179
+ ...(directory ? { 'vue-router-ns': v.nativeRouter } : {}),
180
+ },
181
+ devDependencies: {
182
+ '@nativescript/android': v.android,
183
+ '@nativescript/ios': v.ios,
184
+ '@nativescript/webpack': v.webpack,
185
+ webpack: v.webpackCore,
186
+ 'webpack-cli': v.webpackCli,
187
+ typescript: v.typescript,
188
+ 'vue-tsc': v.vueTsc,
189
+ },
190
+ }),
191
+ )
192
+ }
193
+ if (mac) {
194
+ await copyTemplate(files, 'macos/native', 'apps/macos', replacements)
195
+ if (directory) {
196
+ await copyTemplate(files, 'directory/macos', 'apps/macos/Sources/MavisDesktop', replacements)
197
+ const app = 'apps/macos/Sources/MavisDesktop/App.swift'
198
+ files.set(
199
+ app,
200
+ files
201
+ .get(app)
202
+ .replace(
203
+ 'MavisEntry()',
204
+ 'MavisEntry(services: MavisServices(directoryStorage: UserDefaultsDirectoryStorage()))',
205
+ ),
206
+ )
207
+ }
208
+ scripts.macos = 'node scripts/macos.mjs run'
209
+ scripts['build:macos'] = 'node scripts/macos.mjs build'
210
+ builds.push('build:macos')
211
+ }
212
+ // The generated theme module tracks configuration edits without rewriting app hosts.
213
+ for (const path of [
214
+ web &&
215
+ (nuxt
216
+ ? 'apps/web/app/plugins/mavis.ts'
217
+ : directory
218
+ ? 'apps/web/src/main.ts'
219
+ : 'apps/web/src/main.js'),
220
+ native && 'apps/mobile/src/app.ts',
221
+ ].filter(Boolean)) {
222
+ const nuxtHost = path.includes('/plugins/')
223
+ let source = files
224
+ .get(path)
225
+ .replace(/, mavis, midnight/g, '')
226
+ .replace(/^import \{ mavis, midnight \} from '@getcortexlabs\/mavis-core'\n/m, '')
227
+ .replace(/^ (?:mavis|midnight),\n/gm, '')
228
+ .replace(/theme: mavis/g, 'theme: appTheme')
229
+ .replace(/darkTheme: midnight/g, 'darkTheme: appDarkTheme')
230
+ if (nuxtHost)
231
+ source = source
232
+ .replace(/: '(?:light|dark)',\n/, ": appAppearance === 'dark' ? 'dark' : 'light',\n")
233
+ .replace(/: 'system'/g, ': appAppearance')
234
+ else source = source.replace(/appearance: '(?:light|dark)'/g, 'appearance: appAppearance')
235
+ files.set(
236
+ path,
237
+ `import { appTheme, appDarkTheme, appAppearance } from '${nuxtHost ? '../' : './'}generated/theme'\n${source}`,
238
+ )
239
+ }
240
+ scripts.build = builds.map((name) => commands.run(name)).join(' && ')
241
+
242
+ files.set(
243
+ 'package.json',
244
+ json({
245
+ ...common,
246
+ name: preset.name,
247
+ type: 'module',
248
+ ...(web && preset.packageManager !== 'pnpm' ? { workspaces: ['apps/web'] } : {}),
249
+ ...(web && preset.packageManager === 'yarn'
250
+ ? {
251
+ resolutions: { vue: v.vue, '@vue/runtime-core': v.vue },
252
+ dependenciesMeta: {
253
+ esbuild: { built: true },
254
+ ...(nuxt ? { 'unrs-resolver': { built: true } } : {}),
255
+ },
256
+ }
257
+ : {}),
258
+ scripts,
259
+ // The compiler reads theme tokens from Mavis core, type-checks with TypeScript and parses
260
+ // shared Vue files with Vue's own compiler.
261
+ dependencies: { '@getcortexlabs/mavis-core': v.mavis },
262
+ devDependencies: { '@getcortexlabs/mavis-compiler': v.mavis, typescript: v.typescript },
263
+ }),
49
264
  )
50
265
  files.set(
51
266
  'mavis.config.json',
52
- JSON.stringify(
53
- { ...preset, portability: { roots: ['shared'], mode: 'mitosis-swiftui-experimental' } },
54
- null,
55
- 2,
56
- ) + '\n',
267
+ json({
268
+ ...configOf(preset),
269
+ macos: {
270
+ name: preset.name,
271
+ bundleId: `com.mavis.${preset.name.replaceAll('-', '')}`,
272
+ minWidth: tasks ? 760 : 640,
273
+ minHeight: 640,
274
+ },
275
+ portability: {
276
+ roots: ['shared'],
277
+ mode: directory ? 'shared-vue-experimental' : 'shared-tsx-experimental',
278
+ entry,
279
+ ...(directory ? { startup: [{ store: 'Directory', action: 'restore' }] } : {}),
280
+ },
281
+ }),
57
282
  )
58
283
  files.set(
59
284
  '.gitignore',
60
- 'node_modules/\ndist/\nnative/.build/\n.yarn/\n.DS_Store\n*.log\n*.generated.vue\n*.generated.swift\n',
285
+ [
286
+ 'node_modules/',
287
+ '.npm/',
288
+ '.pnpm-store/',
289
+ '.yarn/',
290
+ 'dist/',
291
+ '.nuxt/',
292
+ '.output/',
293
+ 'apps/web/app/generated/',
294
+ 'platforms/',
295
+ 'hooks/',
296
+ 'apps/macos/.build/',
297
+ 'apps/web/src/generated/',
298
+ 'apps/web/app/generated/',
299
+ 'apps/web/public/~/',
300
+ 'apps/mobile/src/generated/',
301
+ 'apps/macos/Sources/MavisDesktop/Generated/',
302
+ 'mavis-env.d.ts',
303
+ '.DS_Store',
304
+ '*.log',
305
+ '',
306
+ ].join('\n'),
61
307
  )
62
- if (preset.packageManager === 'pnpm')
308
+ if (preset.packageManager === 'pnpm') {
63
309
  files.set(
64
310
  'pnpm-workspace.yaml',
65
- 'packages: []\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n',
311
+ `packages:${web ? '\n - apps/web' : ' []'}\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n${nuxt ? ' "unrs-resolver": true\n' : ''}`,
66
312
  )
313
+ if (native)
314
+ files.set(
315
+ 'apps/mobile/pnpm-workspace.yaml',
316
+ 'packages: []\nnodeLinker: hoisted\nsideEffectsCache: false\nallowBuilds:\n "esbuild": true\n "@nativescript/core": true\n "@parcel/watcher": true\n "core-js-pure": false\n',
317
+ )
318
+ }
67
319
  if (preset.packageManager === 'yarn') {
68
320
  files.set('.yarnrc.yml', 'nodeLinker: node-modules\n')
321
+ // An empty lockfile marks a separate Yarn project, including before its first install.
69
322
  files.set('yarn.lock', '')
323
+ if (native) files.set('apps/mobile/yarn.lock', '')
70
324
  }
71
- files.set(
72
- 'README.md',
73
- `# ${preset.name}
325
+ files.set('README.md', readme(preset, commands, { web, native, mac, entry }))
326
+ return { preset, files: new Map([...files].sort(([a], [b]) => a.localeCompare(b))) }
327
+ }
328
+
329
+ function readme(preset, commands, { web, native, mac, entry }) {
330
+ const directory = preset.example === 'directory'
331
+ const start = [
332
+ native ? commands.setup(true) : commands.install,
333
+ ...(web ? [commands.run('dev:web')] : []),
334
+ ...(native ? [commands.run('ios'), commands.run('android')] : []),
335
+ ...(mac ? [commands.run('macos')] : []),
336
+ ]
337
+ const folders = [
338
+ web &&
339
+ (preset.web === 'nuxt'
340
+ ? `- apps/web: Nuxt (${preset.rendering}) with Mavis Web. Generated screens in apps/web/app/generated/.`
341
+ : '- apps/web: Vue + Vite with Mavis Web. Generated screens in apps/web/src/generated/.'),
342
+ native &&
343
+ '- apps/mobile: NativeScript-Vue for iOS and Android with Mavis. Generated screens in apps/mobile/src/generated/.',
344
+ mac &&
345
+ '- apps/macos: a SwiftUI app (Swift package) with JoltSwiftUI. Generated views in apps/macos/Sources/MavisDesktop/Generated/.',
346
+ ].filter(Boolean)
347
+ const hosts = [
348
+ native &&
349
+ `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')}\`.`,
350
+ mac &&
351
+ '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.',
352
+ 'Code generation and the Web also work on Linux and Windows.',
353
+ ].filter(Boolean)
354
+ return `# ${preset.name}
74
355
 
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.
356
+ Mavis ${targetLabel(preset.targets)} project, experimental. **One shared source, compiled for each target.**
357
+ This is a compiler experiment for a subset of Mavis, not a complete renderer for every component.
77
358
 
78
359
  ## Start
79
360
 
80
361
  \`\`\`sh
81
- ${commands.install}
82
- ${commands.run('macos')}
83
- # Or open the same screen on the Web:
84
- ${commands.run('dev:web')}
362
+ ${start.join('\n')}
85
363
  \`\`\`
86
364
 
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.
365
+ ${hosts.join(' ')}
88
366
 
89
367
  ## Edit once
90
368
 
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.
369
+ Screens live in **shared/**: ${directory ? 'Vue screens and typed stores are the same files on every target.' : 'each `Name.lite.tsx` exports one component, and lowercase `.ts` files hold shared types, values, calculations and stores.'} \`${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
370
 
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.
371
+ ${folders.join('\n')}
94
372
 
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.
373
+ Generated folders are replaced on every run and kept out of Git; don't edit them. ${directory ? 'The directory uses shared Vue screens, a typed store and one route table. Host adapters persist the same `mavis:directory` JSON array in localStorage, ApplicationSettings and UserDefaults. App.swift only supplies the storage implementation; the generated entry creates its store.' : 'The sources use Mitosis’s component format (`useStore`, `useRef`, `Show`, `For`), but Mitosis itself is not installed.'} Each app keeps its own state.
100
374
 
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.
375
+ ${directory ? 'On Mac, `portability.startup` lists the shared store actions to run after the entry first appears. The generated entry owns this startup once per window identity, across renders and route changes. Startup actions take no arguments, return no value and handle their own errors. This setting is Mac-only; Web and NativeScript keep their bootstrap in `apps/web/src/main.ts` and `apps/mobile/src/app.ts`, after the router/app is ready. For Nuxt the bootstrap is in `apps/web/app/plugins/mavis.ts` and restore waits for hydration.\n\n' : ''}A screen can also be a Vue file, \`shared/Name.vue\`, next to the TSX ones: the Web and NativeScript apps run it as written, importing Mavis from \`#mavis\`, and the Mac gets SwiftUI generated from it. It uses \`<script setup lang="ts">\` with \`ref\`, \`computed\`, functions, \`defineProps\`, \`withDefaults\`, \`defineEmits\` and \`useMavisPlatform()\`, and a template of the same primitives with \`v-if\`, \`v-for\`, \`v-model\` and \`MReveal\`. A Vue file shows other Vue files, and a TSX file other TSX files. The guide lists the subset: https://mavis-ui.getcortexlabs.com/guide/macos-experimental#shared-vue-files
102
376
 
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.
377
+ What the shared sources can use:
378
+ - Vue SFC and TSX components, typed props and callbacks, slots, composition, conditional content and keyed lists. Unsupported syntax reports file:line:column before generation replaces any output.
379
+ - Shared typed modules, pure calculations, optional records, and app stores built with Vue ref/computed/readonly and injection. The Mac generates observable stores and receives typed services from its host.
380
+ - Async store actions and callbacks, loading/error state, scalar watchers, mount/unmount hooks and explicit cancellation cleanup. Shared code must declare cancellation and stale-result guards; hiding a view is not automatically an unmount.
381
+ - A shared route table and navigation actions, including parameters and deep links, with generated native navigation on the Mac.
382
+ - Built-in and statically declared custom themes, scoped providers, responsive layout and the supported component families. Each component still has explicit limits; matching a component name does not imply every prop or browser API is portable.
104
383
 
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))) }
384
+ Read the [Mac guide and supported subset](https://mavis-ui.getcortexlabs.com/guide/macos-experimental) and the [component capability matrix](https://mavis-ui.getcortexlabs.com/guide/macos-capabilities), inspect \`create-mavis --capabilities\`, and run \`create-mavis --check-portability\` from the project before adopting code. Network access, persistence, platform formatting, clipboard and opening URLs belong to typed host services. There is no JavaScript runtime or WebView in the generated Mac app.
385
+
386
+ ## Motion
387
+
388
+ 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. Motion uses the shared contracts and the current Jolt integration for each target. Components and explicit motion surfaces/regions own and dispose their presentation resources. Consult the Mac guide for platform-specific motion limits and Reduce Motion behavior.
389
+
390
+ ## Build
391
+
392
+ \`${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.
393
+ `
109
394
  }
@@ -0,0 +1,121 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { readFile, readdir } from 'node:fs/promises'
3
+ import { dirname, join, relative, sep } from 'node:path'
4
+
5
+ const templates = new URL('../templates/', import.meta.url)
6
+ const hash = (text) => createHash('sha256').update(text).digest('hex')
7
+ const posix = (path) => path.split(sep).join('/')
8
+ const ignored = new Set([
9
+ 'node_modules',
10
+ '.git',
11
+ '.nuxt',
12
+ '.output',
13
+ '.build',
14
+ 'dist',
15
+ 'platforms',
16
+ 'hooks',
17
+ 'artifacts',
18
+ ])
19
+ const refusal = (name) =>
20
+ new Error(
21
+ `Directory migration stopped: ${name} differs from the published RC.13 template. Preserve your changes and migrate its typed storage adapter manually; no files changed.`,
22
+ )
23
+
24
+ /** Only the exact published reference app is rewritten, and only by explicit opt-in. */
25
+ export async function directoryMigration({ root, sources, enabled, hostPaths, appearance, read }) {
26
+ const manifest = JSON.parse(
27
+ await readFile(new URL('migrations/directory-rc13.json', templates), 'utf8'),
28
+ )
29
+ const store = [...sources.keys()].find((name) => name.endsWith('/directory-store.ts'))
30
+ const files = new Map(),
31
+ diffs = []
32
+ if (!store) {
33
+ if (enabled) throw refusal('directory-store.ts (not found)')
34
+ return { files, diffs }
35
+ }
36
+ const currentStore = await readFile(
37
+ new URL('directory/shared/directory-store.ts', templates),
38
+ 'utf8',
39
+ )
40
+ if (sources.get(store) === currentStore) return { files, diffs }
41
+ const legacy = hash(sources.get(store)) === manifest.files['shared/directory-store.ts'].source
42
+ if (!legacy) {
43
+ if (enabled) throw refusal(store)
44
+ return { files, diffs }
45
+ }
46
+ if (!enabled)
47
+ throw new Error(
48
+ 'This is the published RC.13 Directory store. Preview its typed host migration with --add-macos --migrate-directory; apply the reviewed changes with --write.',
49
+ )
50
+ const shared = posix(dirname(store)),
51
+ recognized = new Set()
52
+ for (const name of Object.keys(manifest.files).filter((name) => name.startsWith('shared/'))) {
53
+ const path = `${shared}/${name.slice('shared/'.length)}`
54
+ if (!sources.has(path) || hash(sources.get(path)) !== manifest.files[name].source)
55
+ throw refusal(path)
56
+ recognized.add(path)
57
+ }
58
+ for (const [path, template] of hostPaths) {
59
+ const value = await read(path)
60
+ if (!value || hash(value) !== manifest.files[template]?.[appearance]) throw refusal(path)
61
+ recognized.add(path)
62
+ const next = (await readFile(new URL('directory/' + template, templates), 'utf8'))
63
+ .replaceAll('__MAVIS_SHARED__', '#shared-ui')
64
+ .replaceAll('__MAVIS_APPEARANCE__', appearance)
65
+ files.set(path, next)
66
+ const adapter = template.startsWith('nuxt/')
67
+ ? `${posix(dirname(dirname(path)))}/utils/directory-storage.ts`
68
+ : `${posix(dirname(path))}/directory-storage.ts`
69
+ if ((await read(adapter)) !== undefined) throw refusal(adapter)
70
+ files.set(
71
+ adapter,
72
+ (await readFile(new URL('directory/host/directory-storage.ts', templates), 'utf8')).replace(
73
+ "'../shared/directory-store'",
74
+ "'#shared-ui/directory-store'",
75
+ ),
76
+ )
77
+ }
78
+ // An extra consumer may depend on the legacy read/write interface. Never migrate only half
79
+ // the application, even when its shared files happen to match the reference.
80
+ async function inspect(directory) {
81
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
82
+ if (entry.name.startsWith('.') || ignored.has(entry.name)) continue
83
+ const full = join(directory, entry.name),
84
+ path = posix(relative(root, full))
85
+ if (entry.isSymbolicLink()) throw refusal(path + ' (linked source)')
86
+ if (entry.isDirectory()) await inspect(full)
87
+ else if (/\.(vue|[cm]?[jt]sx?)$/.test(entry.name) && !recognized.has(path)) {
88
+ const text = await readFile(full, 'utf8')
89
+ if (/directory-store|createDirectory\s*\(/.test(text))
90
+ throw refusal(path + ' (additional consumer)')
91
+ }
92
+ }
93
+ }
94
+ await inspect(root)
95
+ for (const name of ['directory-store.ts', 'Edit.vue']) {
96
+ const path = `${shared}/${name}`
97
+ files.set(path, await readFile(new URL(`directory/shared/${name}`, templates), 'utf8'))
98
+ }
99
+ for (const [path, after] of files) {
100
+ const before = sources.get(path) ?? (await read(path))
101
+ diffs.push({ file: path, before: before ?? '', after })
102
+ }
103
+ return { files, diffs }
104
+ }
105
+
106
+ /** Complete old/new lines keep an opt-in migration reviewable without guessing edits. */
107
+ export function migrationDiff({ file, before, after }) {
108
+ return [
109
+ `--- a/${file}`,
110
+ `+++ b/${file}`,
111
+ ...before
112
+ .trimEnd()
113
+ .split('\n')
114
+ .filter((line) => before || line)
115
+ .map((line) => '-' + line),
116
+ ...after
117
+ .trimEnd()
118
+ .split('\n')
119
+ .map((line) => '+' + line),
120
+ ].join('\n')
121
+ }
@@ -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()