@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/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Create Mavis
2
2
 
3
- Start with Vue on the Web, NativeScript, or both. Web projects use Vue + Vite or Nuxt with server rendering/static generation. The generated example shares a Vue screen and gives each host its own service implementation.
3
+ Start a project for the Web, Native (iOS and Android through NativeScript) and the Mac, in any combination. Web projects use Vue + Vite or Nuxt with server rendering/static generation. Web and Native share a Vue screen and give each host its own service implementation; with the Mac, screens are written once and generated for each target (experimental, see below).
4
4
 
5
5
  Run `npm create @getcortexlabs/mavis@latest` for the interactive wizard, or pass a project name and options:
6
6
 
7
7
  ```sh
8
- npm create @getcortexlabs/mavis@latest my-app -- --target both --web nuxt --rendering ssr --theme midnight --no-install
8
+ npm create @getcortexlabs/mavis@latest my-app -- --targets web,native --web nuxt --rendering ssr --theme midnight --no-install
9
9
  ```
10
10
 
11
11
  The terminal wizard uses arrow keys and Enter, with descriptions, inline name validation and a summary before creation. Choose **Back** to revisit a choice or **Change choices** at the summary. Escape or Ctrl-C cancels. Explicit flags are preserved. In CI, supply a project name and flags, or `--yes` for defaults without installation.
@@ -21,7 +21,7 @@ pnpm install
21
21
  pnpm run dev
22
22
  ```
23
23
 
24
- The wizard, package-manager selection and both examples are included in RC.12.
24
+ The wizard, package-manager selection and both examples are included in RC.12. RC.13 adds `--targets` with any combination of `web`, `native` and `macos` (`--target` keeps working), the Tasks example and `--capabilities`, which prints what can be created and how far each combination has been validated.
25
25
 
26
26
  - `--dry-run` prints the file plan without writing or installing.
27
27
  - Existing directories are never merged or overwritten.
@@ -31,11 +31,11 @@ The wizard, package-manager selection and both examples are included in RC.12.
31
31
 
32
32
  Node.js 22.16+ is required. Native projects also need the NativeScript CLI and the platform SDK. iOS requires macOS and Xcode. A shared project keeps native dependencies separate from its Web workspace so each renderer loads the correct Vue runtime.
33
33
 
34
- Templates pin **Mavis 0.1.0-rc.12.2** and **Jolt 0.1.0-rc.12.1**. The CLI and its generated projects use the same Mavis release. Commit the generated lockfile (both lockfiles for a shared project).
34
+ Templates pin **Mavis 0.1.0-rc.14** and **Jolt 0.1.0-rc.15**. The CLI and its generated projects use the same Mavis release. Commit the generated lockfile (both lockfiles for a shared project).
35
35
 
36
36
  pnpm requires **10.26+**. Its generated workspace files keep the mobile installation separate, use a hoisted layout for Vite deduplication, shared imports and NativeScript, and allow only the starter's required dependency build scripts. Yarn Classic and modern Yarn use `node_modules`; initial empty `yarn.lock` files mark separate projects before installation. The starter declares its dependency build scripts explicitly; other package-manager policies remain in effect. If modern Yarn reports a fresh dependency as quarantined, retry after its configured minimum package age. Do not add `apps/mobile` to the Web workspace.
37
37
 
38
- React, Next, Angular, Svelte, portable authoring and SDUI are roadmap work. The creator reports unsupported choices instead of generating placeholder integrations.
38
+ React, Next, Angular, Svelte and SDUI are roadmap work. Shared Vue and TSX compilation for Mac is experimental. The creator reports unsupported choices instead of generating placeholder integrations.
39
39
 
40
40
  MIT · [Mavis UI](https://github.com/getcortexlabs/mavis-ui)
41
41
 
@@ -43,12 +43,33 @@ MIT · [Mavis UI](https://github.com/getcortexlabs/mavis-ui)
43
43
 
44
44
  `#mavis` resolves shared named imports and types for Vue + Vite SPA, Nuxt SSR/SSG and NativeScript iOS/Android. The new `--example directory` adds shared search, details, editing, persistence and automatic navigation through an app-owned router adapter.
45
45
 
46
- `--check-portability` reports platform dependencies with locations. `--fix-imports` previews safe named-import changes to `#mavis`; add `--write` to apply. `--path` selects a source directory and `--json` emits structured diagnostics. `--doctor` also runs this source audit. Unknown dependencies, HTML/CSS and device services still require review and target tests.
46
+ `--check-portability` reports platform dependencies with locations, and then, for each shared file, whether the experimental Mac target can compile it and why not. `--fix-imports` previews safe named-import changes to `#mavis`; add `--write` to apply. `--path` selects a source directory and `--json` emits structured diagnostics. `--doctor` also runs this source audit. Unknown dependencies, HTML/CSS and device services still require review and target tests.
47
47
 
48
48
  ## Add a host to an existing Mavis application (RC.12)
49
49
 
50
- Run `create-mavis --add-native` in a Vue + Vite/Nuxt package, or `create-mavis --add-web [--web nuxt]` in a NativeScript-Vue package. Use `--dry-run` to inspect the plan and `--screen path/to/Screen.vue` to reuse an existing screen without moving it. The command creates an isolated host under `apps`, adds root launch/install scripts and preserves existing source/configuration/lockfiles. Dependencies install only with `--install`; npm, pnpm and Yarn are supported. Conflicts and unsupported workspaces/version baselines are reported before writing. The selected screen's services, aliases and router remain application-owned; portability diagnostics are not automatic conversion. Upgrade the existing Mavis renderer to RC.12.2 before adding a host.
50
+ Run `create-mavis --add-native` in a Vue + Vite/Nuxt package, or `create-mavis --add-web [--web nuxt]` in a NativeScript-Vue package. Use `--dry-run` to inspect the plan and `--screen path/to/Screen.vue` to reuse an existing screen without moving it. The command creates an isolated host under `apps`, adds root launch/install scripts and preserves existing source/configuration/lockfiles. Dependencies install only with `--install`; npm, pnpm and Yarn are supported. Conflicts and unsupported workspaces/version baselines are reported before writing. The selected screen's services, aliases and router remain application-owned; portability diagnostics are not automatic conversion. Align the existing Mavis packages with the creator version before adding a host.
51
51
 
52
- ## Experimental macOS starter (RC.12.2)
52
+ ## Experimental shared sources with Mac
53
53
 
54
- `create-mavis first-light --target macos --yes` creates a bounded Mitosis 0.14.2 → SwiftUI and Vue/Vite starter. Run the generated `macos` script on macOS 14+ with Xcode. Four primitives and simple local state are supported; existing Vue screens and the full Mavis component catalog are not converted. Mitosis is installed only in this experimental project. See the [scope and commands](https://mavis-ui.getcortexlabs.com/guide/macos-experimental).
54
+ Experimental RC.14 includes Nuxt SSR/SSG with Mac, the shared Vue Directory example and `--add-macos`. Mac parity issues #338–#354 remain open; check the documented per-component and motion limits before adoption.
55
+
56
+ ```sh
57
+ create-mavis studio --targets web,native,macos --web nuxt --rendering ssr --example directory
58
+ ```
59
+
60
+ `--example directory` keeps the same Vue screens, typed store and route table across Web, NativeScript and SwiftUI. Welcome and Tasks use shared TSX. The compiler is the versioned `@getcortexlabs/mavis-compiler` package, pinned with Mavis; generated projects contain a small launcher instead of a copy of the compiler. The Web host remains Vue + Vite or Nuxt. Run the generated Mac script on macOS 14+ with Xcode. See the [supported source contracts](https://mavis-ui.getcortexlabs.com/guide/macos-experimental) and source diagnostics before adopting an existing screen.
61
+
62
+ ## Add Mac to an existing application
63
+
64
+ Run in the existing Web, NativeScript or combined project:
65
+
66
+ ```sh
67
+ create-mavis --add-macos --shared-root src/shared --entry src/shared/screens/Home.vue
68
+ create-mavis --add-macos --shared-root src/shared --entry src/shared/screens/Home.vue --write
69
+ ```
70
+
71
+ The first command is a preview. `--write` applies the reviewed plan; `--json` emits the plan for tools. Nested source folders stay in place. The command adds `apps/macos`, `generate:macos`, `build:macos` and `macos`, and migrates schema 1 configuration to schema 2. It preserves existing Web/native hosts and lockfiles, detects conflicts before writing, and never installs packages. Run your package manager after applying. `--shared-root` accepts comma-separated roots; `portability.roots`, `sourceRoot` and `entry` retain those choices.
72
+
73
+ For the unchanged RC.13 Directory template, `--add-macos --migrate-directory` previews the typed storage adapter migration; add `--write` to apply it. The migration requires exact original sources and host entries, preserves the stored JSON array and `mavis:directory` key, and rejects customized versions. It does not transfer stored data between devices. Directory's Swift host uses UserDefaults. Other app-owned service interfaces require explicit Swift implementations; the CLI reports these instead of inventing service behavior.
74
+
75
+ Set `macos.name`, `bundleId`, `icon` (project-relative `.icns`), `minWidth` and `minHeight` in `mavis.config.json`. `--doctor` checks installed compiler/Mavis alignment, the exact Jolt/JoltSwiftUI pin and shared-source diagnostics. Align dependencies first; adoption does not silently upgrade them. Signing, provisioning, notarization and store distribution are separate from this unsigned development build.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getcortexlabs/create-mavis",
3
- "version": "0.1.0-rc.12.2",
3
+ "version": "0.1.0-rc.14",
4
4
  "description": "Create Vue Web, Nuxt and NativeScript projects with Mavis UI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,6 +9,7 @@
9
9
  "files": [
10
10
  "src",
11
11
  "templates",
12
+ "!templates/macos/scripts/portable",
12
13
  "README.md",
13
14
  "LICENSE"
14
15
  ],
@@ -29,6 +30,7 @@
29
30
  "dependencies": {
30
31
  "@vue/compiler-sfc": "3.5.44",
31
32
  "typescript": "6.0.3",
32
- "@clack/prompts": "1.8.1"
33
+ "@clack/prompts": "1.8.1",
34
+ "@getcortexlabs/mavis-compiler": "0.1.0-rc.14"
33
35
  }
34
36
  }
@@ -0,0 +1,83 @@
1
+ // Generated from targetCapabilities in @getcortexlabs/mavis-core by scripts/sync-creator-adapters.mjs.
2
+ // Do not edit: change core's capabilities and run the script.
3
+ export const adapters = {
4
+ available: [
5
+ {
6
+ id: 'vue-web',
7
+ framework: 'vue',
8
+ renderer: 'dom',
9
+ status: 'experimental',
10
+ rendering: ['client', 'serverImport', 'serverHTML', 'hydration', 'ssg', 'streaming'],
11
+ },
12
+ {
13
+ id: 'vue-nativescript',
14
+ framework: 'vue',
15
+ renderer: 'nativescript',
16
+ status: 'experimental',
17
+ rendering: ['client'],
18
+ },
19
+ {
20
+ id: 'macos-swiftui',
21
+ framework: 'shared',
22
+ renderer: 'swiftui',
23
+ status: 'experimental',
24
+ rendering: ['client'],
25
+ },
26
+ ],
27
+ planned: [
28
+ {
29
+ id: 'react-web',
30
+ issue: 145,
31
+ },
32
+ {
33
+ id: 'next',
34
+ issue: 159,
35
+ },
36
+ {
37
+ id: 'angular-web',
38
+ issue: 152,
39
+ },
40
+ {
41
+ id: 'svelte-web',
42
+ issue: 153,
43
+ },
44
+ {
45
+ id: 'solid-web',
46
+ issue: 154,
47
+ },
48
+ {
49
+ id: 'react-nativescript',
50
+ issue: 35,
51
+ },
52
+ {
53
+ id: 'angular-nativescript',
54
+ issue: 36,
55
+ },
56
+ {
57
+ id: 'svelte-nativescript',
58
+ issue: 37,
59
+ },
60
+ {
61
+ id: 'solid-nativescript',
62
+ issue: 38,
63
+ },
64
+ {
65
+ id: 'typescript-nativescript',
66
+ issue: 39,
67
+ },
68
+ ],
69
+ research: [
70
+ {
71
+ id: 'react-native',
72
+ issue: 40,
73
+ },
74
+ {
75
+ id: 'flutter',
76
+ issue: 41,
77
+ },
78
+ {
79
+ id: 'swiftui-compose',
80
+ issue: 42,
81
+ },
82
+ ],
83
+ }
@@ -0,0 +1,386 @@
1
+ import { lstat, mkdir, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises'
2
+ import { dirname, isAbsolute, join, resolve } from 'node:path'
3
+ import {
4
+ compileProject,
5
+ joltSwift,
6
+ macAppSettings,
7
+ startupPlan,
8
+ readAssets,
9
+ readShared,
10
+ } from '@getcortexlabs/mavis-compiler'
11
+ import { directoryMigration } from './migrate-directory.mjs'
12
+ import { migrateConfig, versions } from './capabilities.mjs'
13
+ import { detectPackageManager, packageCommands } from './package-manager.mjs'
14
+
15
+ const json = (value) => JSON.stringify(value, null, 2) + '\n'
16
+ const templates = new URL('../templates/', import.meta.url)
17
+ async function optional(path) {
18
+ try {
19
+ return await readFile(path, 'utf8')
20
+ } catch (error) {
21
+ if (error.code !== 'ENOENT') throw error
22
+ }
23
+ }
24
+ async function safe(root, name) {
25
+ if (
26
+ typeof name !== 'string' ||
27
+ !name ||
28
+ isAbsolute(name) ||
29
+ name.includes('\\') ||
30
+ name.split('/').includes('..')
31
+ )
32
+ throw new Error('Mac target paths must stay inside the project.')
33
+ let current = root
34
+ for (const part of name.split('/').filter((part) => part && part !== '.')) {
35
+ current = join(current, part)
36
+ try {
37
+ if ((await lstat(current)).isSymbolicLink()) throw new Error(`Refusing symlink: ${name}`)
38
+ } catch (error) {
39
+ if (error.code !== 'ENOENT') throw error
40
+ }
41
+ }
42
+ return current
43
+ }
44
+ async function copy(files, folder, destination, replace) {
45
+ const source = new URL(folder + '/', templates)
46
+ for (const entry of await readdir(source, { withFileTypes: true })) {
47
+ if (entry.isDirectory())
48
+ await copy(files, `${folder}/${entry.name}`, `${destination}/${entry.name}`, replace)
49
+ else {
50
+ const data = await readFile(new URL(entry.name, source))
51
+ files.set(
52
+ `${destination}/${entry.name}`,
53
+ /\.(ttf|icns)$/.test(entry.name) ? data : replace(data.toString('utf8')),
54
+ )
55
+ }
56
+ }
57
+ }
58
+ const exact = (value) => typeof value === 'string' && /^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(value)
59
+
60
+ /** Preview adding a native SwiftUI host. Existing Web/native files are never rewritten. */
61
+ export async function planMacos(options = {}, cwd = process.cwd()) {
62
+ const root = resolve(cwd)
63
+ const original = new Map()
64
+ const read = async (name) => {
65
+ const text = await optional(await safe(root, name))
66
+ original.set(name, text)
67
+ return text
68
+ }
69
+ const pkg = JSON.parse(await read('package.json'))
70
+ const recorded = await read('mavis.config.json')
71
+ const prior = recorded ? migrateConfig(JSON.parse(recorded)) : {}
72
+ const manifests = [pkg]
73
+ for (const path of ['apps/web/package.json', 'apps/mobile/package.json']) {
74
+ const text = await read(path)
75
+ if (text) manifests.push(JSON.parse(text))
76
+ }
77
+ const dependencies = manifests.map((manifest) => ({
78
+ ...manifest.devDependencies,
79
+ ...manifest.dependencies,
80
+ }))
81
+ const web = dependencies.find((dep) => dep['@getcortexlabs/mavis-web'])
82
+ const native = dependencies.find((dep) => dep['@getcortexlabs/mavis'])
83
+ if (!web && !native)
84
+ throw new Error('--add-macos needs an existing Mavis Vue/Vite, Nuxt or NativeScript project.')
85
+ for (const dep of dependencies)
86
+ for (const name of [
87
+ '@getcortexlabs/mavis-core',
88
+ '@getcortexlabs/mavis-web',
89
+ '@getcortexlabs/mavis',
90
+ ])
91
+ if (
92
+ dep[name] &&
93
+ ![versions.mavis, `^${versions.mavis}`, `~${versions.mavis}`].includes(dep[name])
94
+ )
95
+ throw new Error(
96
+ `Align ${name} with this creator (${versions.mavis}) before adding Mac. No dependencies were changed.`,
97
+ )
98
+ const jolts = [
99
+ ...new Set(
100
+ dependencies.flatMap((dep) =>
101
+ dep['@rafaelaugusto/jolt'] ? [dep['@rafaelaugusto/jolt']] : [],
102
+ ),
103
+ ),
104
+ ]
105
+ const jolt = jolts[0] ?? prior.versions?.jolt
106
+ if (jolts.length > 1 || !exact(jolt) || jolt !== joltSwift.version)
107
+ throw new Error(
108
+ `Pin every existing Jolt dependency to ${joltSwift.version}, the SwiftUI version supported by this compiler. Current: ${jolts.join(', ') || jolt || 'missing'}.`,
109
+ )
110
+ const manager =
111
+ options.packageManager ??
112
+ prior.packageManager ??
113
+ pkg.packageManager?.split('@')[0] ??
114
+ detectPackageManager()
115
+ const commands = packageCommands(manager)
116
+ const knownRoots = options.roots ?? prior.portability?.roots
117
+ let roots = knownRoots
118
+ if (!roots) {
119
+ roots = []
120
+ for (const candidate of ['shared', 'src/shared', 'app/shared']) {
121
+ try {
122
+ if ((await lstat(await safe(root, candidate))).isDirectory()) roots.push(candidate)
123
+ } catch (error) {
124
+ if (error.code !== 'ENOENT') throw error
125
+ }
126
+ }
127
+ if (roots.length !== 1)
128
+ throw new Error(
129
+ 'Choose --shared-root path (or comma-separated roots) to select existing shared sources.',
130
+ )
131
+ }
132
+ const sources = await readShared(root, { roots })
133
+ for (const [name, text] of sources) original.set(name, text)
134
+ const migration = await directoryMigration({
135
+ root,
136
+ sources,
137
+ enabled: options.migrateDirectory,
138
+ appearance: prior.theme === 'midnight' ? 'dark' : 'light',
139
+ read,
140
+ hostPaths: [
141
+ ...(web
142
+ ? [
143
+ [
144
+ `${web === dependencies[0] ? '' : 'apps/web/'}${web.nuxt ? 'app/plugins/mavis.ts' : 'src/main.ts'}`,
145
+ web.nuxt ? 'nuxt/app/plugins/mavis.ts' : 'vite/src/main.ts',
146
+ ],
147
+ ]
148
+ : []),
149
+ ...(native
150
+ ? [[`${native === dependencies[0] ? '' : 'apps/mobile/'}src/app.ts`, 'mobile/src/app.ts']]
151
+ : []),
152
+ ],
153
+ })
154
+ for (const [name, text] of migration.files) if (sources.has(name)) sources.set(name, text)
155
+ let entry = options.entry ?? prior.portability?.entry
156
+ if (!entry) {
157
+ const preferred =
158
+ prior.example === 'directory'
159
+ ? 'Directory.vue'
160
+ : prior.example === 'tasks'
161
+ ? 'Tasks.lite.tsx'
162
+ : 'Welcome.vue'
163
+ entry = [...sources.keys()].find((name) => name.endsWith('/' + preferred))
164
+ if (!entry)
165
+ throw new Error('Choose --entry path/to/Screen.vue (or .lite.tsx); no screen was changed.')
166
+ }
167
+ const settings = macAppSettings(
168
+ prior.macos,
169
+ pkg.name?.replace(/^@[^/]+\//, '') ?? prior.name ?? 'Mavis',
170
+ )
171
+ if (settings.icon) await readFile(await safe(root, settings.icon))
172
+ const host = web ? (web.nuxt ? 'nuxt' : 'vite') : null
173
+ if (
174
+ web &&
175
+ prior.rendering &&
176
+ !(host === 'nuxt' ? ['ssr', 'ssg'] : ['client']).includes(prior.rendering)
177
+ )
178
+ throw new Error('The recorded Web rendering mode does not match the existing host.')
179
+ const targets = [web && 'web', native && 'native', 'macos'].filter(Boolean)
180
+ const config = {
181
+ ...prior,
182
+ schemaVersion: 2,
183
+ name: prior.name ?? pkg.name ?? 'mavis-app',
184
+ targets,
185
+ apps: {
186
+ ...prior.apps,
187
+ ...(web
188
+ ? {
189
+ web: {
190
+ toolkit: 'mavis-web',
191
+ framework: 'vue',
192
+ host,
193
+ rendering: prior.rendering ?? (host === 'nuxt' ? 'ssr' : 'client'),
194
+ },
195
+ }
196
+ : {}),
197
+ ...(native
198
+ ? { native: { toolkit: 'nativescript', framework: 'vue', platforms: ['ios', 'android'] } }
199
+ : {}),
200
+ macos: { toolkit: 'swiftui', framework: null },
201
+ },
202
+ framework: 'vue',
203
+ authoring: prior.authoring ?? (String(entry).endsWith('.lite.tsx') ? 'mitosis' : 'vue'),
204
+ mode: 'portable',
205
+ execution: 'generated',
206
+ web: host,
207
+ rendering: web ? (prior.rendering ?? (host === 'nuxt' ? 'ssr' : 'client')) : null,
208
+ theme: prior.theme ?? 'mavis',
209
+ example: prior.example ?? 'welcome',
210
+ packageManager: manager,
211
+ versions: { ...prior.versions, mavis: versions.mavis, compiler: versions.mavis, jolt },
212
+ macos: settings,
213
+ portability: { ...prior.portability, roots, entry, generate: ['macos'], existing: true },
214
+ }
215
+ const assets = await readAssets(root, {
216
+ folder: config.portability.assets ?? `${config.portability.sourceRoot ?? roots[0]}/assets`,
217
+ })
218
+ // Preview proves source compilation before touching an existing project.
219
+ const compiled = await compileProject(sources, {
220
+ root: entry,
221
+ theme: config.theme,
222
+ assets,
223
+ sourceRoot: config.portability.sourceRoot ?? roots[0],
224
+ destinations: config.portability.destinations,
225
+ })
226
+ const metadataFile = 'apps/macos/mavis.host.json'
227
+ const metadata = await read(metadataFile)
228
+ if (metadata) {
229
+ const state = JSON.parse(metadata)
230
+ if (
231
+ state.generator !== 'create-mavis' ||
232
+ JSON.stringify(prior.portability?.roots) !== JSON.stringify(roots) ||
233
+ prior.portability?.entry !== entry
234
+ )
235
+ throw new Error(
236
+ 'Mac is already configured with different source choices. Edit mavis.config.json explicitly; existing files were preserved.',
237
+ )
238
+ return {
239
+ root,
240
+ manager,
241
+ entry,
242
+ roots,
243
+ files: new Map(),
244
+ original,
245
+ config,
246
+ alreadyAdded: true,
247
+ components: compiled.model.components.length,
248
+ }
249
+ }
250
+ try {
251
+ await lstat(await safe(root, 'apps/macos'))
252
+ throw new Error('apps/macos already exists. Existing files were preserved.')
253
+ } catch (error) {
254
+ if (error.code !== 'ENOENT') throw error
255
+ }
256
+ const scripts = {
257
+ 'generate:macos': 'node scripts/generate-macos.mjs',
258
+ macos: 'node scripts/macos.mjs run',
259
+ 'build:macos': 'node scripts/macos.mjs build',
260
+ }
261
+ for (const [name, command] of Object.entries(scripts))
262
+ if (pkg.scripts?.[name] && pkg.scripts[name] !== command)
263
+ throw new Error(`Script conflict: ${name}. Existing scripts were preserved.`)
264
+ const files = new Map(migration.files)
265
+ const replace = (text) =>
266
+ text
267
+ .replaceAll('__MAVIS_NAME__', settings.name)
268
+ .replaceAll('__MAVIS_APPID__', 'app')
269
+ .replaceAll('__MAVIS_APPEARANCE__', config.theme === 'midnight' ? 'dark' : 'light')
270
+ .replaceAll('__MAVIS_MAC_MIN_WIDTH__', String(settings.minWidth))
271
+ .replaceAll('__MAVIS_MAC_DEFAULT_WIDTH__', String(Math.max(860, settings.minWidth)))
272
+ .replaceAll('__MAVIS_MAC_WIDTH__', '1120')
273
+ .replaceAll('__MAVIS_JOLT_SWIFT__', jolt)
274
+ await copy(files, 'macos/native', 'apps/macos', replace)
275
+ const appPath = 'apps/macos/Sources/MavisDesktop/App.swift'
276
+ let app = files
277
+ .get(appPath)
278
+ .replace(/WindowGroup\(".*"\)/, 'WindowGroup(MavisAppConfiguration.name)')
279
+ .replace(
280
+ '.frame(minWidth: ' + settings.minWidth + ', minHeight: 640)',
281
+ '.frame(minWidth: MavisAppConfiguration.minWidth, minHeight: MavisAppConfiguration.minHeight)',
282
+ )
283
+ const directory =
284
+ compiled.model.services.length === 1 &&
285
+ compiled.model.services[0].name === 'DirectoryStorage' &&
286
+ compiled.model.modules.some((module) =>
287
+ module.stores.some((store) => store.name === 'Directory'),
288
+ )
289
+ if (compiled.model.services.length && !directory)
290
+ throw new Error(
291
+ `The shared entry needs host services: ${compiled.model.services.map((service) => service.name).join(', ')}. Add their Swift implementations explicitly before generation; --add-macos cannot invent their behavior.`,
292
+ )
293
+ if (directory) {
294
+ await copy(files, 'directory/macos', 'apps/macos/Sources/MavisDesktop', replace)
295
+ app = app.replace(
296
+ 'MavisEntry()',
297
+ 'MavisEntry(services: MavisServices(directoryStorage: UserDefaultsDirectoryStorage()))',
298
+ )
299
+ if (!config.portability.startup)
300
+ config.portability.startup = [{ store: 'Directory', action: 'restore' }]
301
+ }
302
+ startupPlan(compiled.model, config.portability.startup)
303
+ files.set(appPath, app)
304
+ const wrapper = await readFile(new URL('macos/scripts/generate.mjs', templates), 'utf8')
305
+ files.set('scripts/generate-macos.mjs', wrapper)
306
+ const launcher = await readFile(new URL('macos/scripts/macos.mjs', templates), 'utf8')
307
+ files.set(
308
+ 'scripts/macos-manifest.mjs',
309
+ await readFile(new URL('macos/scripts/macos-manifest.mjs', templates), 'utf8'),
310
+ )
311
+ files.set(
312
+ 'scripts/macos.mjs',
313
+ replace(launcher).replace("['scripts/generate.mjs']", "['scripts/generate-macos.mjs']"),
314
+ )
315
+ files.set(
316
+ metadataFile,
317
+ json({ schemaVersion: 1, generator: 'create-mavis', compiler: versions.mavis }),
318
+ )
319
+ files.set(
320
+ 'apps/macos/README.md',
321
+ `# ${settings.name} for Mac\n\nThis SwiftUI target reads existing shared sources (${roots.join(', ')}), starting at \`${entry}\`. Web and NativeScript sources, routes and build configuration remain in place.\n\n\`\`\`sh\n${commands.install}\n${commands.run('generate:macos')}\n${commands.run('build:macos')}\n${commands.run('macos')}\n\`\`\`\n\nThe compiler is a pinned package; update it with Mavis. \`mavis.config.json\` controls the source roots/entry and \`macos.name\`, \`bundleId\`, \`icon\` (.icns), \`minWidth\` and \`minHeight\`. Configure app-owned services in \`Sources/MavisDesktop/App.swift\`. ${directory ? 'Directory uses the same JSON array and mavis:directory key in UserDefaults; restore runs once after mounting each entry identity.' : ''}\n\nRequires macOS 14+ and Xcode. This builds an unsigned development app. Developer ID signing, provisioning and notarization are separate distribution steps; no credentials or signing settings are generated.\n`,
322
+ )
323
+ pkg.scripts = { ...pkg.scripts, ...scripts }
324
+ pkg.devDependencies = { ...pkg.devDependencies, '@getcortexlabs/mavis-compiler': versions.mavis }
325
+ files.set('package.json', json(pkg))
326
+ files.set('mavis.config.json', json(config))
327
+ for (const name of files.keys()) {
328
+ if (original.has(name)) continue
329
+ if ((await read(name)) !== undefined)
330
+ throw new Error(`File conflict: ${name}. Existing files were preserved.`)
331
+ }
332
+ return {
333
+ root,
334
+ manager,
335
+ entry,
336
+ roots,
337
+ files,
338
+ original,
339
+ config,
340
+ alreadyAdded: false,
341
+ components: compiled.model.components.length,
342
+ migration: migration.diffs,
343
+ }
344
+ }
345
+
346
+ /** Optimistic transaction: refuse concurrent edits; roll back only bytes written by this plan. */
347
+ export async function applyMacos(plan, { signal } = {}) {
348
+ if (plan.alreadyAdded) return
349
+ const written = []
350
+ try {
351
+ for (const [name, expected] of plan.original) {
352
+ if ((await optional(await safe(plan.root, name))) !== expected)
353
+ throw new Error(`${name} changed after the preview. Run --add-macos again.`)
354
+ }
355
+ for (const [name, data] of plan.files) {
356
+ signal?.throwIfAborted()
357
+ const path = await safe(plan.root, name)
358
+ await mkdir(dirname(path), { recursive: true })
359
+ if (plan.original.get(name) === undefined) await writeFile(path, data, { flag: 'wx' })
360
+ else {
361
+ if ((await optional(path)) !== plan.original.get(name))
362
+ throw new Error(`${name} changed during creation.`)
363
+ const staging = `${path}.mavis-${process.pid}.tmp`
364
+ try {
365
+ await writeFile(staging, data, { flag: 'wx' })
366
+ await rename(staging, path)
367
+ } finally {
368
+ await rm(staging, { force: true })
369
+ }
370
+ }
371
+ written.push(name)
372
+ }
373
+ } catch (error) {
374
+ for (const name of written.reverse()) {
375
+ const path = join(plan.root, name)
376
+ const current = await readFile(path).catch(() => null)
377
+ if (!current?.equals(Buffer.from(plan.files.get(name)))) continue
378
+ const prior = plan.original.get(name)
379
+ if (prior === undefined) await rm(path)
380
+ else await writeFile(path, prior)
381
+ for (let folder = dirname(path); folder !== plan.root; folder = dirname(folder))
382
+ await rmdir(folder).catch(() => {})
383
+ }
384
+ throw error
385
+ }
386
+ }
@@ -41,7 +41,7 @@ export async function planTarget(options, cwd = process.cwd()) {
41
41
  const config = await optional(join(root, 'mavis.config.json'))
42
42
  if (config && JSON.parse(config).authoring === 'mitosis')
43
43
  throw new Error(
44
- 'Add-target migrations do not support the experimental Mitosis macOS starter. Its Vue and SwiftUI hosts are already generated from shared/Welcome.lite.tsx.',
44
+ 'Add-target migrations do not apply to projects with shared TSX sources. Create a project with the targets you need, for example --targets web,native,macos.',
45
45
  )
46
46
  const deps = { ...pkg.devDependencies, ...pkg.dependencies }
47
47
  const target = options.target