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

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 (80) hide show
  1. package/README.md +44 -7
  2. package/package.json +4 -2
  3. package/src/adapters.mjs +56 -20
  4. package/src/add-desktop.mjs +308 -0
  5. package/src/add-macos.mjs +386 -0
  6. package/src/capabilities.mjs +352 -85
  7. package/src/cli.mjs +181 -9
  8. package/src/desktop.mjs +155 -0
  9. package/src/doctor.mjs +181 -18
  10. package/src/macos-capabilities.generated.mjs +4190 -0
  11. package/src/macos.mjs +147 -29
  12. package/src/migrate-directory.mjs +121 -0
  13. package/src/native-framework.mjs +144 -0
  14. package/src/portability.mjs +123 -5
  15. package/src/scaffold.mjs +59 -11
  16. package/src/ui.mjs +69 -12
  17. package/templates/desktop/common/LICENSE +21 -0
  18. package/templates/desktop/common/build.mjs +58 -0
  19. package/templates/desktop/common/src/components.ts +60 -0
  20. package/templates/desktop/common/src/contract.mjs +35 -0
  21. package/templates/desktop/common/src/renderer.ts +76 -0
  22. package/templates/desktop/common/src/storage.ts +29 -0
  23. package/templates/desktop/directory/main.ts +35 -0
  24. package/templates/desktop/macos/launch.mjs +6 -0
  25. package/templates/desktop/macos/package.mjs +114 -0
  26. package/templates/desktop/macos/src/host.mjs +468 -0
  27. package/templates/desktop/macos/src/motion.mjs +51 -0
  28. package/templates/desktop/welcome/Welcome.vue +56 -0
  29. package/templates/desktop/welcome/main.ts +24 -0
  30. package/templates/desktop/windows/NativeScript-LICENSE +19 -0
  31. package/templates/desktop/windows/launch.mjs +16 -0
  32. package/templates/desktop/windows/package.mjs +54 -0
  33. package/templates/desktop/windows/prepare-host.mjs +73 -0
  34. package/templates/desktop/windows/src/host.mjs +277 -0
  35. package/templates/directory/host/directory-storage.ts +78 -0
  36. package/templates/directory/macos/DirectoryStorage.swift +68 -0
  37. package/templates/directory/mobile/src/app.ts +11 -8
  38. package/templates/directory/nuxt/app/plugins/mavis.ts +11 -8
  39. package/templates/directory/shared/Edit.vue +8 -5
  40. package/templates/directory/shared/directory-store.ts +42 -46
  41. package/templates/directory/vite/src/main.ts +11 -8
  42. package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +2 -2
  43. package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +2 -2
  44. package/templates/macos/examples/tasks/shared/types.ts +1 -0
  45. package/templates/macos/mobile/src/App.vue +4 -2
  46. package/templates/macos/native/Package.swift +3 -1
  47. package/templates/macos/native/Sources/MavisDesktop/App.swift +26 -11
  48. package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +45 -0
  49. package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
  50. package/templates/macos/scripts/generate.mjs +3 -26
  51. package/templates/macos/scripts/macos-manifest.mjs +33 -0
  52. package/templates/macos/scripts/macos.mjs +20 -18
  53. package/templates/macos/web/index.html +1 -1
  54. package/templates/macos/web/src/main.js +176 -3
  55. package/templates/macos/web/src/mavis.js +2 -0
  56. package/templates/macos/web/src/style.css +2 -1
  57. package/templates/macos/web/vite.config.mjs +12 -1
  58. package/templates/migrations/directory-rc13.json +36 -0
  59. package/templates/mobile/src/mavis.ts +2 -82
  60. package/templates/mobile/webpack.config.js +4 -0
  61. package/templates/native-framework/angular/screen.ts +84 -0
  62. package/templates/native-framework/common/nativescript.config.ts +6 -0
  63. package/templates/native-framework/common/src/app.ts +5 -0
  64. package/templates/native-framework/common/src/model.ts +40 -0
  65. package/templates/native-framework/common/src/references.d.ts +8 -0
  66. package/templates/native-framework/common/tsconfig.json +16 -0
  67. package/templates/native-framework/common/webpack.config.js +67 -0
  68. package/templates/native-framework/plain/screen.ts +102 -0
  69. package/templates/native-framework/react/screen.ts +83 -0
  70. package/templates/native-framework/solid/screen.ts +111 -0
  71. package/templates/native-framework/svelte/Welcome.svelte +26 -0
  72. package/templates/native-framework/svelte/screen.ts +14 -0
  73. package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
  74. package/templates/nuxt/app/mavis.ts +2 -84
  75. package/templates/vite/src/mavis.ts +2 -84
  76. package/templates/macos/scripts/portable/emit-swift.mjs +0 -1287
  77. package/templates/macos/scripts/portable/emit-vue.mjs +0 -615
  78. package/templates/macos/scripts/portable/index.mjs +0 -95
  79. package/templates/macos/scripts/portable/model.mjs +0 -1441
  80. package/templates/macos/scripts/portable/program.mjs +0 -163
package/src/macos.mjs CHANGED
@@ -1,6 +1,6 @@
1
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
+ import { joltSwift } from '@getcortexlabs/mavis-compiler'
4
4
 
5
5
  const json = (value) => `${JSON.stringify(value, null, 2)}\n`
6
6
 
@@ -15,10 +15,12 @@ export async function macosFiles(preset, files, copyTemplate) {
15
15
  const mac = targets.includes('macos')
16
16
  const commands = packageCommands(preset.packageManager)
17
17
  const tasks = preset.example === 'tasks'
18
+ const directory = preset.example === 'directory'
19
+ const nuxt = preset.web === 'nuxt'
18
20
  // The screen every app opens. Tasks is a list beside its detail, so it gets a wider page.
19
- const entry = tasks ? 'Tasks' : 'Welcome'
21
+ const entry = directory ? 'Directory' : tasks ? 'Tasks' : 'Welcome'
20
22
  const hosts = [
21
- web && 'Vue on the Web',
23
+ web && (nuxt ? `Nuxt (${preset.rendering}) on the Web` : 'Vue on the Web'),
22
24
  native && 'NativeScript on iOS and Android',
23
25
  mac && 'SwiftUI on the Mac',
24
26
  ].filter(Boolean)
@@ -31,7 +33,6 @@ export async function macosFiles(preset, files, copyTemplate) {
31
33
  TARGETS: targetLabel(targets),
32
34
  HOSTS: hosts.join(' · '),
33
35
  JOLT_SWIFT: joltSwift.version,
34
- ROOT: entry,
35
36
  WEB_WIDTH: tasks ? '1120px' : '760px',
36
37
  MAC_WIDTH: tasks ? '1120' : '820',
37
38
  MAC_MIN_WIDTH: tasks ? '760' : '640',
@@ -42,21 +43,55 @@ export async function macosFiles(preset, files, copyTemplate) {
42
43
  await copyTemplate(files, 'macos/root', '', replacements)
43
44
  await copyTemplate(
44
45
  files,
45
- tasks ? 'macos/examples/tasks/shared' : 'macos/shared',
46
+ directory ? 'directory/shared' : tasks ? 'macos/examples/tasks/shared' : 'macos/shared',
46
47
  'shared',
47
48
  replacements,
48
49
  )
49
50
  await copyTemplate(files, 'macos/scripts', 'scripts', replacements)
50
- if (!mac) files.delete('scripts/macos.mjs')
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
+ }
51
56
 
52
57
  const common = { private: true, version: '0.0.0', engines: { node: '>=22.16' } }
53
58
  const generate = 'node scripts/generate.mjs'
54
59
  const builds = []
55
60
  const scripts = { generate }
56
61
  if (web) {
57
- await copyTemplate(files, 'macos/web', 'apps/web', replacements)
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
+ }
58
92
  scripts['dev:web'] = `${generate} && ${commands.run('dev', 'apps/web')}`
59
- scripts['build:web'] = `${generate} && ${commands.run('build', 'apps/web')}`
93
+ scripts['build:web'] =
94
+ `${generate} && ${commands.run(nuxt && preset.rendering === 'ssg' ? 'generate' : 'build', 'apps/web')}`
60
95
  builds.push('build:web')
61
96
  files.set(
62
97
  'apps/web/package.json',
@@ -64,17 +99,30 @@ export async function macosFiles(preset, files, copyTemplate) {
64
99
  ...common,
65
100
  name: `${preset.name}-web`,
66
101
  type: 'module',
67
- scripts: { dev: 'vite', build: 'vite build', preview: 'vite preview' },
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' },
68
112
  dependencies: {
69
113
  '@getcortexlabs/mavis-core': v.mavis,
70
114
  '@getcortexlabs/mavis-web': v.mavis,
71
115
  '@rafaelaugusto/jolt': v.jolt,
72
116
  vue: v.vue,
117
+ '@vue/runtime-core': v.vue,
118
+ ...(nuxt ? { nuxt: v.nuxt } : {}),
119
+ ...(directory && !nuxt ? { 'vue-router': v.router } : {}),
73
120
  },
74
121
  devDependencies: {
75
122
  typescript: v.typescript,
76
- vite: v.vite,
77
- '@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 } : {}),
78
126
  },
79
127
  }),
80
128
  )
@@ -82,6 +130,10 @@ export async function macosFiles(preset, files, copyTemplate) {
82
130
  if (native) {
83
131
  await copyTemplate(files, 'mobile', 'apps/mobile', replacements)
84
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
+ }
85
137
  // The generated screens are the app's shared code; the TSX sources stay out of vue-tsc.
86
138
  files.set(
87
139
  'apps/mobile/tsconfig.json',
@@ -124,6 +176,7 @@ export async function macosFiles(preset, files, copyTemplate) {
124
176
  '@getcortexlabs/mavis': v.mavis,
125
177
  '@nativescript/core': v.nativeCore,
126
178
  'nativescript-vue': v.nativeVue,
179
+ ...(directory ? { 'vue-router-ns': v.nativeRouter } : {}),
127
180
  },
128
181
  devDependencies: {
129
182
  '@nativescript/android': v.android,
@@ -139,10 +192,51 @@ export async function macosFiles(preset, files, copyTemplate) {
139
192
  }
140
193
  if (mac) {
141
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
+ }
142
208
  scripts.macos = 'node scripts/macos.mjs run'
143
209
  scripts['build:macos'] = 'node scripts/macos.mjs build'
144
210
  builds.push('build:macos')
145
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
+ }
146
240
  scripts.build = builds.map((name) => commands.run(name)).join(' && ')
147
241
 
148
242
  files.set(
@@ -155,20 +249,35 @@ export async function macosFiles(preset, files, copyTemplate) {
155
249
  ...(web && preset.packageManager === 'yarn'
156
250
  ? {
157
251
  resolutions: { vue: v.vue, '@vue/runtime-core': v.vue },
158
- dependenciesMeta: { esbuild: { built: true } },
252
+ dependenciesMeta: {
253
+ esbuild: { built: true },
254
+ ...(nuxt ? { 'unrs-resolver': { built: true } } : {}),
255
+ },
159
256
  }
160
257
  : {}),
161
258
  scripts,
162
- // The compiler reads theme tokens from Mavis core and type-checks with TypeScript.
259
+ // The compiler reads theme tokens from Mavis core, type-checks with TypeScript and parses
260
+ // shared Vue files with Vue's own compiler.
163
261
  dependencies: { '@getcortexlabs/mavis-core': v.mavis },
164
- devDependencies: { typescript: v.typescript },
262
+ devDependencies: { '@getcortexlabs/mavis-compiler': v.mavis, typescript: v.typescript },
165
263
  }),
166
264
  )
167
265
  files.set(
168
266
  'mavis.config.json',
169
267
  json({
170
268
  ...configOf(preset),
171
- portability: { roots: ['shared'], mode: 'shared-tsx-experimental', entry },
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
+ },
172
281
  }),
173
282
  )
174
283
  files.set(
@@ -179,10 +288,15 @@ export async function macosFiles(preset, files, copyTemplate) {
179
288
  '.pnpm-store/',
180
289
  '.yarn/',
181
290
  'dist/',
291
+ '.nuxt/',
292
+ '.output/',
293
+ 'apps/web/app/generated/',
182
294
  'platforms/',
183
295
  'hooks/',
184
296
  'apps/macos/.build/',
185
297
  'apps/web/src/generated/',
298
+ 'apps/web/app/generated/',
299
+ 'apps/web/public/~/',
186
300
  'apps/mobile/src/generated/',
187
301
  'apps/macos/Sources/MavisDesktop/Generated/',
188
302
  'mavis-env.d.ts',
@@ -194,7 +308,7 @@ export async function macosFiles(preset, files, copyTemplate) {
194
308
  if (preset.packageManager === 'pnpm') {
195
309
  files.set(
196
310
  'pnpm-workspace.yaml',
197
- `packages:${web ? '\n - apps/web' : ' []'}\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' : ''}`,
198
312
  )
199
313
  if (native)
200
314
  files.set(
@@ -213,6 +327,7 @@ export async function macosFiles(preset, files, copyTemplate) {
213
327
  }
214
328
 
215
329
  function readme(preset, commands, { web, native, mac, entry }) {
330
+ const directory = preset.example === 'directory'
216
331
  const start = [
217
332
  native ? commands.setup(true) : commands.install,
218
333
  ...(web ? [commands.run('dev:web')] : []),
@@ -220,7 +335,10 @@ function readme(preset, commands, { web, native, mac, entry }) {
220
335
  ...(mac ? [commands.run('macos')] : []),
221
336
  ]
222
337
  const folders = [
223
- web && '- apps/web: Vue + Vite with Mavis Web. Generated screens in apps/web/src/generated/.',
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/.'),
224
342
  native &&
225
343
  '- apps/mobile: NativeScript-Vue for iOS and Android with Mavis. Generated screens in apps/mobile/src/generated/.',
226
344
  mac &&
@@ -248,26 +366,26 @@ ${hosts.join(' ')}
248
366
 
249
367
  ## Edit once
250
368
 
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:
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:
252
370
 
253
371
  ${folders.join('\n')}
254
372
 
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.
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.
374
+
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
256
376
 
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.
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.
265
383
 
266
- Anything else fails generation with file:line:column before any output changes. Numbers behave like JavaScript numbers in every app (Double in Swift).
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.
267
385
 
268
386
  ## Motion
269
387
 
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.
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.
271
389
 
272
390
  ## Build
273
391
 
@@ -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
+ }
@@ -0,0 +1,144 @@
1
+ import { configOf, versions as v } from './capabilities.mjs'
2
+ import { packageCommands } from './package-manager.mjs'
3
+ const json = (value) => JSON.stringify(value, null, 2) + '\n'
4
+ const angular = Object.fromEntries(
5
+ ['animations', 'common', 'compiler', 'core', 'forms', 'router', 'platform-browser'].map(
6
+ (name) => [`@angular/${name}`, '22.3.0'],
7
+ ),
8
+ )
9
+ export const nativeFrameworkDependencies = Object.freeze({
10
+ plain: {},
11
+ react: { react: '18.3.1', 'react-nativescript': '5.0.0' },
12
+ angular: { ...angular, '@nativescript/angular': '22.0.2', rxjs: '7.8.2' },
13
+ svelte: { svelte: '4.2.20', '@nativescript-community/svelte-native': '1.0.32' },
14
+ solid: {
15
+ 'solid-js': '2.0.0',
16
+ '@nativescript-community/solid-js': '2.0.1',
17
+ '@solidjs/universal': '2.0.0',
18
+ dominative: '0.1.3',
19
+ 'undom-ng': '1.1.2',
20
+ },
21
+ })
22
+ export async function nativeFrameworkFiles(preset, copyTemplate) {
23
+ const files = new Map(),
24
+ framework = preset.framework
25
+ const replacements = {
26
+ NAME: preset.name,
27
+ APPID: preset.name.replaceAll('-', ''),
28
+ THEME: preset.theme,
29
+ FRAMEWORK: framework,
30
+ }
31
+ await copyTemplate(files, 'native-framework/common', '', replacements)
32
+ await copyTemplate(files, `native-framework/${framework}`, 'src', replacements)
33
+ if (framework === 'svelte')
34
+ await copyTemplate(files, 'native-framework/svelte-tooling', '', replacements)
35
+ await copyTemplate(files, 'mobile/App_Resources', 'App_Resources', replacements)
36
+ const peers = nativeFrameworkDependencies[framework]
37
+ const overrides =
38
+ framework === 'react'
39
+ ? { 'react-nativescript': { '@nativescript/core': '$@nativescript/core' } }
40
+ : framework === 'svelte'
41
+ ? {
42
+ '@nativescript-community/svelte-native': {
43
+ '@nativescript/core': '$@nativescript/core',
44
+ },
45
+ }
46
+ : {}
47
+ const extensions = Object.fromEntries(
48
+ Object.entries(overrides).map(([name, deps]) => [
49
+ name,
50
+ {
51
+ peerDependencies: Object.fromEntries(
52
+ Object.entries(deps).map(([dep, version]) => [
53
+ dep,
54
+ version.startsWith('$') ? (peers[dep] ?? v.nativeCore) : version,
55
+ ]),
56
+ ),
57
+ },
58
+ ]),
59
+ )
60
+ files.set(
61
+ 'package.json',
62
+ json({
63
+ name: preset.name,
64
+ private: true,
65
+ version: '0.0.0',
66
+ main: 'src/app.ts',
67
+ engines: { node: '>=22.23.3' },
68
+ scripts: {
69
+ ios: 'ns run ios',
70
+ android: 'ns run android',
71
+ 'bundle:ios': 'webpack --env ios',
72
+ 'bundle:android': 'webpack --env android',
73
+ typecheck:
74
+ framework === 'svelte' ? 'svelte-check --tsconfig ./tsconfig.json' : 'tsc --noEmit',
75
+ },
76
+ dependencies: {
77
+ '@getcortexlabs/mavis': v.mavis,
78
+ '@getcortexlabs/mavis-core': v.mavis,
79
+ '@nativescript/core': v.nativeCore,
80
+ '@rafaelaugusto/jolt': v.jolt,
81
+ ...(framework === 'plain'
82
+ ? {}
83
+ : { [`@getcortexlabs/mavis-${framework}-nativescript`]: v.mavis }),
84
+ ...peers,
85
+ },
86
+ devDependencies: {
87
+ '@nativescript/android': v.android,
88
+ '@nativescript/ios': v.ios,
89
+ '@nativescript/types': '9.1.1',
90
+ '@nativescript/webpack': v.webpack,
91
+ webpack: v.webpackCore,
92
+ 'webpack-cli': v.webpackCli,
93
+ typescript: v.typescript,
94
+ ...(framework === 'react' ? { '@types/react': '18.3.31' } : {}),
95
+ ...(framework === 'svelte' ? { 'svelte-loader': '3.2.4', 'svelte-check': '3.8.6' } : {}),
96
+ ...(framework === 'solid'
97
+ ? {
98
+ '@solidjs/babel-plugin': '2.0.2',
99
+ '@babel/core': '7.29.13',
100
+ '@babel/preset-typescript': '7.29.7',
101
+ }
102
+ : {}),
103
+ },
104
+ overrides,
105
+ ...(preset.packageManager === 'yarn'
106
+ ? {
107
+ resolutions: Object.fromEntries(
108
+ Object.entries(overrides).flatMap(([owner, deps]) =>
109
+ Object.entries(deps).map(([dep]) => [
110
+ `${owner}/${dep}`,
111
+ peers[dep] ?? v.nativeCore,
112
+ ]),
113
+ ),
114
+ ),
115
+ dependenciesMeta: {
116
+ '@nativescript/core': { built: true },
117
+ '@parcel/watcher': { built: true },
118
+ 'core-js-pure': { built: false },
119
+ },
120
+ }
121
+ : {}),
122
+ }),
123
+ )
124
+ if (preset.packageManager === 'pnpm')
125
+ files.set(
126
+ 'pnpm-workspace.yaml',
127
+ `packages: []\nnodeLinker: hoisted\nsideEffectsCache: false\nallowBuilds:\n '@nativescript/core': true\n '@parcel/watcher': true\n core-js-pure: false\n svelte-preprocess: false\npackageExtensions: ${JSON.stringify(extensions)}\n`,
128
+ )
129
+ if (preset.packageManager === 'yarn') {
130
+ files.set('yarn.lock', '')
131
+ files.set(
132
+ '.yarnrc.yml',
133
+ `nodeLinker: node-modules\npackageExtensions: ${JSON.stringify(extensions)}\n`,
134
+ )
135
+ }
136
+ files.set('.gitignore', 'node_modules/\nplatforms/\nhooks/\n.npm/\n.pnpm-store/\n.yarn/\n*.log\n')
137
+ files.set('mavis.config.json', json(configOf(preset)))
138
+ const commands = packageCommands(preset.packageManager)
139
+ files.set(
140
+ 'README.md',
141
+ `# ${preset.name}\n\nDirect ${framework === 'plain' ? 'JavaScript/TypeScript' : framework} components on NativeScript iOS and Android.\n\n\`\`\`sh\n${commands.install}\n${commands.run('ios')}\n${commands.run('android')}\n\`\`\`\n\nEdit \`src/${framework === 'svelte' ? 'Welcome.svelte' : 'screen.ts'}\`. The screen uses its framework's state and lifecycle and renders native views directly. No Vue runtime is installed. \`src/model.ts\` supplies the starting themes and a scoped motion example.\n\nRequires Node 22.23.3+, NativeScript CLI, a JDK and Android SDK; iOS builds need macOS/Xcode. Run \`ns doctor\` and \`${commands.run('typecheck')}\`.\n\nThis starter supports MBox, MRow, MColumn, MText, MButton and MInput. The full Vue component catalog is a different adapter. Rich MText children, arbitrary MButton slots and some effects are not implemented in the direct adapters; see the Mavis native adapter guide. Web, Mac and Windows creator hosts currently use Vue and cannot be combined with this framework preset.\n\nDependencies are pinned. Core 9 compatibility overrides for React NativeScript and Svelte Native are explicit in the package-manager configuration. Jolt RC.17 accepts the selected framework without peer overrides. Only the selected framework is installed. Commit the generated lockfile. ${framework === 'svelte' ? 'Svelte Native 1.0.32 still uses the tested custom-event and bootstrap ownership workarounds in Mavis; upstream adoption is tracked in Mavis #380 and #381.' : ''}\n`,
142
+ )
143
+ return { preset, files }
144
+ }