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

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 (69) hide show
  1. package/README.md +21 -28
  2. package/package.json +2 -4
  3. package/src/adapters.mjs +45 -23
  4. package/src/add-desktop.mjs +354 -0
  5. package/src/capabilities.mjs +233 -134
  6. package/src/cli.mjs +64 -60
  7. package/src/desktop.mjs +155 -0
  8. package/src/doctor.mjs +77 -108
  9. package/src/native-framework.mjs +144 -0
  10. package/src/portability.mjs +7 -106
  11. package/src/scaffold.mjs +36 -12
  12. package/src/shared-api.mjs +3 -0
  13. package/src/ui.mjs +30 -42
  14. package/templates/desktop/common/LICENSE +21 -0
  15. package/templates/desktop/common/build.mjs +49 -0
  16. package/templates/desktop/common/src/components.ts +60 -0
  17. package/templates/desktop/common/src/contract.mjs +35 -0
  18. package/templates/desktop/common/src/renderer.ts +76 -0
  19. package/templates/desktop/common/src/storage.ts +29 -0
  20. package/templates/desktop/directory/main.ts +35 -0
  21. package/templates/desktop/macos/launch.mjs +6 -0
  22. package/templates/desktop/macos/package.mjs +114 -0
  23. package/templates/desktop/macos/src/host.mjs +471 -0
  24. package/templates/desktop/welcome/Welcome.vue +56 -0
  25. package/templates/desktop/welcome/main.ts +24 -0
  26. package/templates/desktop/windows/NativeScript-LICENSE +19 -0
  27. package/templates/desktop/windows/launch.mjs +16 -0
  28. package/templates/desktop/windows/package.mjs +54 -0
  29. package/templates/desktop/windows/prepare-host.mjs +73 -0
  30. package/templates/desktop/windows/src/host.mjs +294 -0
  31. package/templates/native-framework/angular/screen.ts +84 -0
  32. package/templates/native-framework/common/nativescript.config.ts +6 -0
  33. package/templates/native-framework/common/src/app.ts +5 -0
  34. package/templates/native-framework/common/src/model.ts +40 -0
  35. package/templates/native-framework/common/src/references.d.ts +8 -0
  36. package/templates/native-framework/common/tsconfig.json +16 -0
  37. package/templates/native-framework/common/webpack.config.js +67 -0
  38. package/templates/native-framework/plain/screen.ts +102 -0
  39. package/templates/native-framework/react/screen.ts +83 -0
  40. package/templates/native-framework/solid/screen.ts +111 -0
  41. package/templates/native-framework/svelte/Welcome.svelte +26 -0
  42. package/templates/native-framework/svelte/screen.ts +14 -0
  43. package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
  44. package/src/add-macos.mjs +0 -386
  45. package/src/macos-capabilities.generated.mjs +0 -4190
  46. package/src/macos.mjs +0 -394
  47. package/src/migrate-directory.mjs +0 -121
  48. package/templates/directory/macos/DirectoryStorage.swift +0 -68
  49. package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +0 -57
  50. package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +0 -33
  51. package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +0 -251
  52. package/templates/macos/examples/tasks/shared/types.ts +0 -10
  53. package/templates/macos/mobile/src/App.vue +0 -14
  54. package/templates/macos/mobile/src/app.ts +0 -7
  55. package/templates/macos/native/Package.swift +0 -19
  56. package/templates/macos/native/Sources/MavisDesktop/App.swift +0 -35
  57. package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +0 -45
  58. package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
  59. package/templates/macos/root/tsconfig.json +0 -14
  60. package/templates/macos/scripts/generate.mjs +0 -13
  61. package/templates/macos/scripts/macos-manifest.mjs +0 -33
  62. package/templates/macos/scripts/macos.mjs +0 -58
  63. package/templates/macos/shared/Welcome.lite.tsx +0 -42
  64. package/templates/macos/web/index.html +0 -12
  65. package/templates/macos/web/src/main.js +0 -212
  66. package/templates/macos/web/src/mavis.js +0 -2
  67. package/templates/macos/web/src/style.css +0 -14
  68. package/templates/macos/web/vite.config.mjs +0 -14
  69. package/templates/migrations/directory-rc13.json +0 -36
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Create Mavis
2
2
 
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).
3
+ Start a project for Web, NativeScript iOS/Android, AppKit macOS and XAML Windows. The desktop presets run shared Vue. 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; desktop hosts run Vue directly with an explicit native component subset.
4
4
 
5
5
  Run `npm create @getcortexlabs/mavis@latest` for the interactive wizard, or pass a project name and options:
6
6
 
@@ -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. 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.
24
+ Use `--capabilities` to list supported frameworks, platforms and examples.
25
25
 
26
26
  - `--dry-run` prints the file plan without writing or installing.
27
27
  - Existing directories are never merged or overwritten.
@@ -31,45 +31,38 @@ The wizard, package-manager selection and both examples are included in RC.12. R
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.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).
34
+ Templates pin **Mavis 0.1.0-rc.16** and **Jolt 0.1.0-rc.18**. 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 and SDUI are roadmap work. Shared Vue and TSX compilation for Mac is experimental. The creator reports unsupported choices instead of generating placeholder integrations.
38
+ React, Angular, Svelte, Solid and plain JS/TS have direct iOS/Android starters (`--targets native --framework react`, or angular/svelte/solid/plain). Web and desktop presets use Vue. React Web, Next and SDUI remain planned. 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
 
42
- ## Shared screens and portability
43
-
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
-
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
-
48
- ## Add a host to an existing Mavis application (RC.12)
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. Align the existing Mavis packages with the creator version before adding a host.
51
-
52
- ## Experimental shared sources with Mac
53
-
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.
42
+ ## NativeScript desktop (RC.15)
55
43
 
56
44
  ```sh
57
- create-mavis studio --targets web,native,macos --web nuxt --rendering ssr --example directory
45
+ create-mavis studio --targets macos,windows --example directory --no-install
46
+ cd studio
47
+ npm run install:apps
48
+ npm run macos # on macOS
49
+ npm run windows # on Windows
58
50
  ```
59
51
 
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.
52
+ These experimental presets are included in RC.15. The macOS runtime is NativeScript AppKit. Desktop needs Node 22.23.3+. Mac uses Apple Silicon/macOS 13.3+; Windows uses Windows 10 build 18362+ and the Windows SDK. Run `--doctor` on each OS.
61
53
 
62
- ## Add Mac to an existing application
54
+ The initial desktop contract has 12 components with bounded props; `--capabilities --json` lists them. It does not imply the full Vue mobile catalog runs on desktop. MReveal uses the public Jolt AppKit and Windows drivers to fade in with system motion preferences.
63
55
 
64
- Run in the existing Web, NativeScript or combined project:
56
+ Use `--add-macos` or `--add-windows` to preview an existing Vue app's desktop host; `--write` applies it. Source files stay in place. Install the new host's dependencies separately. Custom app providers/router remain application-owned. `package:macos` produces an ad hoc signed .app; `package:windows` produces an unsigned portable folder. Both include Node and native runtimes. See the [desktop guide](https://mavis-ui.getcortexlabs.com/guide/native-desktop) for exact coverage and distribution limits.
65
57
 
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
- ```
58
+ ## Shared screens and portability
59
+
60
+ `#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.
70
61
 
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.
62
+ `--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.
72
63
 
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.
64
+ ## Add a host to an existing Mavis application (RC.12)
65
+
66
+ 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.
74
67
 
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.
68
+ The former SwiftUI target is preserved on [archive/swiftui](https://github.com/getcortexlabs/mavis-ui/tree/archive/swiftui).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getcortexlabs/create-mavis",
3
- "version": "0.1.0-rc.14",
3
+ "version": "0.1.0-rc.16",
4
4
  "description": "Create Vue Web, Nuxt and NativeScript projects with Mavis UI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,7 +9,6 @@
9
9
  "files": [
10
10
  "src",
11
11
  "templates",
12
- "!templates/macos/scripts/portable",
13
12
  "README.md",
14
13
  "LICENSE"
15
14
  ],
@@ -30,7 +29,6 @@
30
29
  "dependencies": {
31
30
  "@vue/compiler-sfc": "3.5.44",
32
31
  "typescript": "6.0.3",
33
- "@clack/prompts": "1.8.1",
34
- "@getcortexlabs/mavis-compiler": "0.1.0-rc.14"
32
+ "@clack/prompts": "1.8.1"
35
33
  }
36
34
  }
package/src/adapters.mjs CHANGED
@@ -17,9 +17,51 @@ export const adapters = {
17
17
  rendering: ['client'],
18
18
  },
19
19
  {
20
- id: 'macos-swiftui',
21
- framework: 'shared',
22
- renderer: 'swiftui',
20
+ id: 'vue-appkit',
21
+ framework: 'vue',
22
+ renderer: 'nativescript-appkit',
23
+ status: 'experimental',
24
+ rendering: ['client'],
25
+ },
26
+ {
27
+ id: 'vue-windows',
28
+ framework: 'vue',
29
+ renderer: 'nativescript-xaml',
30
+ status: 'experimental',
31
+ rendering: ['client'],
32
+ },
33
+ {
34
+ id: 'react-nativescript',
35
+ framework: 'react',
36
+ renderer: 'nativescript',
37
+ status: 'experimental',
38
+ rendering: ['client'],
39
+ },
40
+ {
41
+ id: 'angular-nativescript',
42
+ framework: 'angular',
43
+ renderer: 'nativescript',
44
+ status: 'experimental',
45
+ rendering: ['client'],
46
+ },
47
+ {
48
+ id: 'svelte-nativescript',
49
+ framework: 'svelte',
50
+ renderer: 'nativescript',
51
+ status: 'experimental',
52
+ rendering: ['client'],
53
+ },
54
+ {
55
+ id: 'solid-nativescript',
56
+ framework: 'solid',
57
+ renderer: 'nativescript',
58
+ status: 'experimental',
59
+ rendering: ['client'],
60
+ },
61
+ {
62
+ id: 'typescript-nativescript',
63
+ framework: 'typescript',
64
+ renderer: 'nativescript',
23
65
  status: 'experimental',
24
66
  rendering: ['client'],
25
67
  },
@@ -45,26 +87,6 @@ export const adapters = {
45
87
  id: 'solid-web',
46
88
  issue: 154,
47
89
  },
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
90
  ],
69
91
  research: [
70
92
  {
@@ -0,0 +1,354 @@
1
+ import { lstat, mkdir, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises'
2
+ import { isAbsolute, join, relative, resolve, sep, dirname, extname } from 'node:path'
3
+ import { parse } from '@vue/compiler-sfc'
4
+ import { desktopHostFiles } from './desktop.mjs'
5
+ import { copyTemplate } from './scaffold.mjs'
6
+ import { migrateConfig, targetNames, versions } from './capabilities.mjs'
7
+ import { desktopComponents } from '../templates/desktop/common/src/contract.mjs'
8
+ import { packageCommands, detectPackageManager } from './package-manager.mjs'
9
+ const json = (value) => JSON.stringify(value, null, 2) + '\n'
10
+ const posix = (path) => path.split(sep).join('/')
11
+ async function safe(root, name) {
12
+ const path = resolve(root, name),
13
+ rel = relative(root, path)
14
+ if (!rel || isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`))
15
+ throw new Error('Desktop source paths must stay inside the project.')
16
+ let current = root
17
+ for (const part of rel.split(sep)) {
18
+ current = join(current, part)
19
+ try {
20
+ if ((await lstat(current)).isSymbolicLink()) throw new Error(`Refusing symlink: ${name}`)
21
+ } catch (error) {
22
+ if (error.code !== 'ENOENT') throw error
23
+ }
24
+ }
25
+ return path
26
+ }
27
+
28
+ export async function planDesktop(options, cwd = process.cwd()) {
29
+ const root = resolve(cwd),
30
+ original = new Map(),
31
+ files = new Map(),
32
+ diagnostics = []
33
+ const target = options.target
34
+ if (!['macos', 'windows'].includes(target))
35
+ throw new Error('Choose --add-macos or --add-windows.')
36
+ const read = async (name) => {
37
+ let value
38
+ try {
39
+ value = await readFile(await safe(root, name), 'utf8')
40
+ } catch (error) {
41
+ if (error.code !== 'ENOENT') throw error
42
+ }
43
+ original.set(name, value)
44
+ return value
45
+ }
46
+ const pkg = JSON.parse(await read('package.json'))
47
+ const raw = await read('mavis.config.json')
48
+ const prior = raw ? migrateConfig(JSON.parse(raw)) : {}
49
+ if (prior.mode === 'portable' || prior.apps?.macos?.toolkit === 'swiftui')
50
+ throw new Error(
51
+ 'This project uses the SwiftUI compiler. Use its pinned creator or the archive/swiftui branch.',
52
+ )
53
+ const manager =
54
+ options.packageManager ??
55
+ prior.packageManager ??
56
+ pkg.packageManager?.split('@')[0] ??
57
+ detectPackageManager()
58
+ const commands = packageCommands(manager)
59
+ const destination = `apps/${target}`
60
+ const marker = `${destination}/mavis.host.json`
61
+ const previous = await read(marker)
62
+ if (previous) {
63
+ const state = JSON.parse(previous)
64
+ if (
65
+ state.kind !== 'nativescript-desktop' ||
66
+ state.target !== target ||
67
+ (options.entry && state.entry !== options.entry)
68
+ )
69
+ throw new Error(`${destination} already belongs to another host configuration.`)
70
+ return {
71
+ root,
72
+ original,
73
+ files,
74
+ destination,
75
+ entry: state.entry,
76
+ manager,
77
+ diagnostics,
78
+ alreadyAdded: true,
79
+ }
80
+ }
81
+ try {
82
+ await lstat(await safe(root, destination))
83
+ throw new Error(`${destination} already exists; no files were changed.`)
84
+ } catch (error) {
85
+ if (error.code !== 'ENOENT') throw error
86
+ }
87
+ const manifests = [pkg]
88
+ for (const name of [
89
+ 'apps/web/package.json',
90
+ 'apps/mobile/package.json',
91
+ 'apps/macos/package.json',
92
+ 'apps/windows/package.json',
93
+ ]) {
94
+ const value = await read(name)
95
+ if (value) manifests.push(JSON.parse(value))
96
+ }
97
+ const dependencies = manifests.map((pkg) => ({ ...pkg.devDependencies, ...pkg.dependencies }))
98
+ if (
99
+ !dependencies.some(
100
+ (dep) =>
101
+ dep['@getcortexlabs/mavis-web'] ||
102
+ dep['@getcortexlabs/mavis'] ||
103
+ dep['@getcortexlabs/mavis-core'],
104
+ )
105
+ )
106
+ throw new Error('Desktop adoption needs an existing Mavis Vue project.')
107
+ for (const dep of dependencies)
108
+ for (const name of [
109
+ '@getcortexlabs/mavis-core',
110
+ '@getcortexlabs/mavis-web',
111
+ '@getcortexlabs/mavis',
112
+ ])
113
+ if (
114
+ dep[name] &&
115
+ ![versions.mavis, `^${versions.mavis}`, `~${versions.mavis}`].includes(dep[name])
116
+ )
117
+ throw new Error(
118
+ `Align ${name} with this creator (${versions.mavis}) before adding desktop.`,
119
+ )
120
+ let roots = options.roots ?? prior.portability?.roots
121
+ if (!roots) {
122
+ roots = []
123
+ for (const candidate of ['shared', 'src/shared', 'app/shared']) {
124
+ try {
125
+ if ((await lstat(await safe(root, candidate))).isDirectory()) roots.push(candidate)
126
+ } catch (error) {
127
+ if (error.code !== 'ENOENT') throw error
128
+ }
129
+ }
130
+ }
131
+ if (roots.length !== 1)
132
+ throw new Error('Choose one --shared-root for the desktop entry and its shared imports.')
133
+ const sourceRoot = roots[0]
134
+ await safe(root, sourceRoot)
135
+ const entry =
136
+ options.entry ?? `${sourceRoot}/${prior.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
137
+ if (!entry.endsWith('.vue') || !(await read(entry)))
138
+ throw new Error('Choose an existing Vue component with --entry path/to/App.vue.')
139
+ const sources = new Map()
140
+ const inspect = async (folder) => {
141
+ for (const item of await readdir(await safe(root, folder), { withFileTypes: true })) {
142
+ const name = posix(join(folder, item.name))
143
+ await safe(root, name)
144
+ if (item.isDirectory()) {
145
+ if (!['node_modules', '.git', 'dist'].includes(item.name)) await inspect(name)
146
+ } else if (/\.(vue|ts|js|mjs)$/.test(name)) sources.set(name, await read(name))
147
+ }
148
+ }
149
+ await inspect(sourceRoot)
150
+ const entryRelative = relative(resolve(root, sourceRoot), resolve(root, entry))
151
+ if (entryRelative.startsWith('..') || isAbsolute(entryRelative))
152
+ throw new Error('--entry must be inside --shared-root.')
153
+ for (const [file, source] of sources) {
154
+ for (const match of source.matchAll(/import\s*\{([^}]+)\}\s*from\s*['"]#mavis['"]/g))
155
+ for (const name of match[1].split(',').map((name) => name.trim().split(/\s+as\s+/)[0]))
156
+ if (name && !(name in desktopComponents))
157
+ diagnostics.push(`${file}: ${name} is outside the NativeScript desktop subset.`)
158
+ if (!file.endsWith('.vue')) continue
159
+ const { descriptor, errors } = parse(source, { filename: file })
160
+ if (errors.length) throw errors[0]
161
+ if (descriptor.styles.length)
162
+ diagnostics.push(
163
+ `${file}: CSS styles need a native desktop implementation; use the supported layout and theme props.`,
164
+ )
165
+ const visit = (node) => {
166
+ if (node.type === 1) {
167
+ const key = Object.keys(desktopComponents).find(
168
+ (name) =>
169
+ name === node.tag ||
170
+ name.replace(/[A-Z]/g, (c, i) => (i ? '-' : '') + c.toLowerCase()) === node.tag,
171
+ )
172
+ if (key) {
173
+ const component = desktopComponents[key]
174
+ const props = [
175
+ 'id',
176
+ 'key',
177
+ 'ref',
178
+ 'accessibilityLabel',
179
+ ...component.props,
180
+ ...(component[target] ?? []),
181
+ ]
182
+ for (const prop of node.props) {
183
+ let name = prop.name
184
+ if (prop.type === 7) {
185
+ if (prop.modifiers.length) {
186
+ diagnostics.push(
187
+ `${file}:${prop.loc.start.line}: v-${name} modifiers need an explicit desktop implementation.`,
188
+ )
189
+ continue
190
+ }
191
+ if (['if', 'else', 'else-if', 'for', 'once', 'memo'].includes(name)) continue
192
+ if (name === 'model' && !prop.arg && !prop.modifiers.length) {
193
+ name = 'modelValue'
194
+ } else if (name === 'bind' && prop.arg?.isStatic) name = prop.arg.content
195
+ else if (name === 'on' && prop.arg?.isStatic)
196
+ name = 'on' + prop.arg.content[0].toUpperCase() + prop.arg.content.slice(1)
197
+ else {
198
+ diagnostics.push(
199
+ `${file}:${prop.loc.start.line}: dynamic bindings or directive v-${name} need an explicit desktop implementation.`,
200
+ )
201
+ continue
202
+ }
203
+ }
204
+ if (!props.includes(name))
205
+ diagnostics.push(
206
+ `${file}:${prop.loc.start.line}: ${key}.${name} is outside the ${target} subset.`,
207
+ )
208
+ }
209
+ } else if (
210
+ /^[Mm][-A-Z]/.test(node.tag) ||
211
+ (node.tagType === 0 && !['template', 'slot'].includes(node.tag))
212
+ )
213
+ diagnostics.push(
214
+ `${file}:${node.loc.start.line}: ${node.tag} is not implemented on desktop.`,
215
+ )
216
+ }
217
+ for (const child of node.children ?? []) visit(child)
218
+ }
219
+ if (descriptor.template?.ast) visit(descriptor.template.ast)
220
+ }
221
+ if (diagnostics.length)
222
+ throw new Error(
223
+ `Desktop adoption cannot reuse these sources yet:\n${diagnostics.join('\n')}\nNo files changed. Keep the existing app and adapt a separate shared entry to the declared subset.`,
224
+ )
225
+ const name = String(prior.name ?? pkg.name ?? 'mavis-app')
226
+ .replace(/^@[^/]+\//, '')
227
+ .replace(/[^a-z0-9-]/g, '-')
228
+ .slice(0, 64)
229
+ const directory =
230
+ prior.example === 'directory' &&
231
+ entry.endsWith('/Directory.vue') &&
232
+ sources.has(`${sourceRoot}/routes.ts`)
233
+ const preset = {
234
+ name,
235
+ theme: prior.theme ?? 'mavis',
236
+ packageManager: manager,
237
+ example: directory ? 'directory' : 'welcome',
238
+ }
239
+ const hostFiles = await desktopHostFiles(
240
+ preset,
241
+ target,
242
+ copyTemplate,
243
+ posix(relative(resolve(root, destination), resolve(root, sourceRoot))),
244
+ )
245
+ if (!directory) {
246
+ hostFiles.set(
247
+ 'src/main.ts',
248
+ `import { createHost } from '#desktop-host'\nimport { desktopRenderer } from './renderer'\nimport Entry from '#shared-ui/${posix(entryRelative)}'\nimport * as components from './components'\nlet app\nconst host = createHost({ title: ${JSON.stringify(name)}, onClose() { app?.unmount() } })\napp = desktopRenderer(host).createApp(Entry)\nfor (const [name, component] of Object.entries(components)) app.component(name, component)\n// Install application-specific providers and routing here before mounting.\nhost.setTheme(${JSON.stringify(preset.theme)} === 'midnight')\napp.mount(host.root)\nhost.show()\n`,
249
+ )
250
+ diagnostics.push(
251
+ `Review ${destination}/src/main.ts to install any application-specific providers or router before mounting.`,
252
+ )
253
+ }
254
+ hostFiles.set(
255
+ 'mavis.host.json',
256
+ json({ schemaVersion: 1, kind: 'nativescript-desktop', target, entry }),
257
+ )
258
+ for (const [path, value] of hostFiles) {
259
+ const file = posix(join(destination, path))
260
+ if ((await read(file)) !== undefined) throw new Error(`Refusing to overwrite ${file}.`)
261
+ files.set(file, value)
262
+ }
263
+ const scripts = {
264
+ [target]: commands.run('dev', destination),
265
+ [`build:${target}`]: commands.run('build', destination),
266
+ [`package:${target}`]: commands.run('package', destination),
267
+ }
268
+ for (const [key, value] of Object.entries(scripts))
269
+ if (pkg.scripts?.[key] && pkg.scripts[key] !== value)
270
+ throw new Error(`The existing ${key} script conflicts with this host.`)
271
+ files.set('package.json', json({ ...pkg, scripts: { ...pkg.scripts, ...scripts } }))
272
+ const targets = targetNames.filter(
273
+ (name) =>
274
+ name === target ||
275
+ prior.targets?.includes(name) ||
276
+ (name === 'web' && dependencies.some((dep) => dep['@getcortexlabs/mavis-web'])) ||
277
+ (name === 'native' && dependencies.some((dep) => dep['@getcortexlabs/mavis'])),
278
+ )
279
+ files.set(
280
+ 'mavis.config.json',
281
+ json({
282
+ ...prior,
283
+ schemaVersion: 2,
284
+ name,
285
+ targets,
286
+ framework: 'vue',
287
+ authoring: 'vue',
288
+ mode: 'direct',
289
+ execution: 'components',
290
+ packageManager: manager,
291
+ ...(targets.includes('macos') ? { macosRuntime: 'appkit' } : {}),
292
+ apps: {
293
+ ...prior.apps,
294
+ [target]: {
295
+ toolkit: target === 'macos' ? 'nativescript-appkit' : 'nativescript-xaml',
296
+ framework: 'vue',
297
+ runtime: target === 'macos' ? versions.macosNodeApi : versions.windowsNapi,
298
+ },
299
+ },
300
+ desktop: { ...prior.desktop, existing: true },
301
+ versions: { ...prior.versions, ...versions },
302
+ }),
303
+ )
304
+ return { root, original, files, destination, entry, manager, diagnostics, alreadyAdded: false }
305
+ }
306
+
307
+ async function optional(path) {
308
+ try {
309
+ return await readFile(path, 'utf8')
310
+ } catch (error) {
311
+ if (error.code !== 'ENOENT') throw error
312
+ }
313
+ }
314
+ /** Optimistic transaction: refuse concurrent edits; roll back only bytes written by this plan. */
315
+ export async function applyDesktop(plan, { signal } = {}) {
316
+ if (plan.alreadyAdded) return
317
+ const written = []
318
+ try {
319
+ for (const [name, expected] of plan.original) {
320
+ if ((await optional(await safe(plan.root, name))) !== expected)
321
+ throw new Error(`${name} changed after the preview. Preview the desktop target again.`)
322
+ }
323
+ for (const [name, data] of plan.files) {
324
+ signal?.throwIfAborted()
325
+ const path = await safe(plan.root, name)
326
+ await mkdir(dirname(path), { recursive: true })
327
+ if (plan.original.get(name) === undefined) await writeFile(path, data, { flag: 'wx' })
328
+ else {
329
+ if ((await optional(path)) !== plan.original.get(name))
330
+ throw new Error(`${name} changed during creation.`)
331
+ const staging = `${path}.mavis-${process.pid}.tmp`
332
+ try {
333
+ await writeFile(staging, data, { flag: 'wx' })
334
+ await rename(staging, path)
335
+ } finally {
336
+ await rm(staging, { force: true })
337
+ }
338
+ }
339
+ written.push(name)
340
+ }
341
+ } catch (error) {
342
+ for (const name of written.reverse()) {
343
+ const path = join(plan.root, name)
344
+ const current = await readFile(path).catch(() => null)
345
+ if (!current?.equals(Buffer.from(plan.files.get(name)))) continue
346
+ const prior = plan.original.get(name)
347
+ if (prior === undefined) await rm(path)
348
+ else await writeFile(path, prior)
349
+ for (let folder = dirname(path); folder !== plan.root; folder = dirname(folder))
350
+ await rmdir(folder).catch(() => {})
351
+ }
352
+ throw error
353
+ }
354
+ }