@getcortexlabs/create-mavis 0.1.0-rc.14 → 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 (44) hide show
  1. package/README.md +25 -9
  2. package/package.json +2 -2
  3. package/src/adapters.mjs +49 -20
  4. package/src/add-desktop.mjs +308 -0
  5. package/src/add-macos.mjs +3 -3
  6. package/src/capabilities.mjs +288 -42
  7. package/src/cli.mjs +98 -8
  8. package/src/desktop.mjs +155 -0
  9. package/src/doctor.mjs +86 -5
  10. package/src/native-framework.mjs +144 -0
  11. package/src/portability.mjs +22 -7
  12. package/src/scaffold.mjs +38 -9
  13. package/src/ui.mjs +51 -3
  14. package/templates/desktop/common/LICENSE +21 -0
  15. package/templates/desktop/common/build.mjs +58 -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 +468 -0
  24. package/templates/desktop/macos/src/motion.mjs +51 -0
  25. package/templates/desktop/welcome/Welcome.vue +56 -0
  26. package/templates/desktop/welcome/main.ts +24 -0
  27. package/templates/desktop/windows/NativeScript-LICENSE +19 -0
  28. package/templates/desktop/windows/launch.mjs +16 -0
  29. package/templates/desktop/windows/package.mjs +54 -0
  30. package/templates/desktop/windows/prepare-host.mjs +73 -0
  31. package/templates/desktop/windows/src/host.mjs +277 -0
  32. package/templates/native-framework/angular/screen.ts +84 -0
  33. package/templates/native-framework/common/nativescript.config.ts +6 -0
  34. package/templates/native-framework/common/src/app.ts +5 -0
  35. package/templates/native-framework/common/src/model.ts +40 -0
  36. package/templates/native-framework/common/src/references.d.ts +8 -0
  37. package/templates/native-framework/common/tsconfig.json +16 -0
  38. package/templates/native-framework/common/webpack.config.js +67 -0
  39. package/templates/native-framework/plain/screen.ts +102 -0
  40. package/templates/native-framework/react/screen.ts +83 -0
  41. package/templates/native-framework/solid/screen.ts +111 -0
  42. package/templates/native-framework/svelte/Welcome.svelte +26 -0
  43. package/templates/native-framework/svelte/screen.ts +14 -0
  44. package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
package/src/cli.mjs CHANGED
@@ -6,6 +6,7 @@ import { readFile } from 'node:fs/promises'
6
6
  import { scaffold, installProject } from './scaffold.mjs'
7
7
  import { planTarget, applyTarget } from './add-target.mjs'
8
8
  import { planMacos, applyMacos } from './add-macos.mjs'
9
+ import { planDesktop, applyDesktop } from './add-desktop.mjs'
9
10
  import { migrationDiff } from './migrate-directory.mjs'
10
11
  import { checkPortability, formatMacReadiness } from './portability.mjs'
11
12
  import { doctor } from './doctor.mjs'
@@ -27,19 +28,22 @@ import {
27
28
  import { nextSteps, projectSummary, sharedEntry, terminalUI, wizard } from './ui.mjs'
28
29
 
29
30
  const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
30
- const help = `Create Mavis — Web, Native (iOS/Android) and Mac in any combination
31
+ const help = `Create Mavis — Web, Native (iOS/Android), Mac and Windows
31
32
 
32
33
  npm create @getcortexlabs/mavis@latest
33
34
  create-mavis my-app --targets web,native,macos --package-manager pnpm --no-install
34
35
  create-mavis my-app --targets web,native --web nuxt
35
36
 
36
- --targets web,native,macos Any combination; default: web. With macos, shared
37
- screens are TSX compiled for every target (experimental)
37
+ --targets web,native,macos,windows
38
+ Default: web. Desktop uses shared Vue (experimental)
39
+ --macos-runtime appkit|swiftui
40
+ Default: appkit; SwiftUI keeps the compiler workflow
38
41
  --target mobile|web|both|macos
39
42
  Earlier names: native, web, web+native, web+macos
40
43
  --add-native Add apps/mobile to an existing Vue/Vite or Nuxt app
41
44
  --add-web Add apps/web to an existing NativeScript-Vue app
42
- --add-macos Preview adding SwiftUI to an existing app; --write applies
45
+ --add-macos Preview adding Mac; choose --macos-runtime swiftui for SwiftUI
46
+ --add-windows Preview adding NativeScript Windows; --write applies
43
47
  --migrate-directory Opt in to migrate an unmodified RC.13 Directory example
44
48
  --shared-root path Source roots for --add-macos (comma-separated)
45
49
  --entry path.vue Shared Vue/TSX entry for --add-macos
@@ -62,8 +66,9 @@ const help = `Create Mavis — Web, Native (iOS/Android) and Mac in any combinat
62
66
  --theme mavis|midnight Default: mavis
63
67
  --package-manager npm|pnpm|yarn
64
68
  Default: the invoking manager, or npm
65
- --framework vue Vue is currently supported
66
- --authoring vue|mitosis Follows the targets: mitosis (shared TSX) with macos
69
+ --framework vue|plain|react|angular|svelte|solid
70
+ Direct frameworks: iOS/Android only; desktop/Web use Vue
71
+ --authoring vue|mitosis|native Vue by default; mitosis with --macos-runtime swiftui
67
72
  --yes, -y Use defaults without prompts (skip installation)
68
73
  --install / --no-install Install dependencies now or later
69
74
  --dry-run Show the complete file plan without writing
@@ -93,6 +98,8 @@ try {
93
98
  'add-native': { type: 'boolean' },
94
99
  'add-web': { type: 'boolean' },
95
100
  'add-macos': { type: 'boolean' },
101
+ 'add-windows': { type: 'boolean' },
102
+ 'macos-runtime': { type: 'string' },
96
103
  'migrate-directory': { type: 'boolean' },
97
104
  'shared-root': { type: 'string' },
98
105
  entry: { type: 'string' },
@@ -127,11 +134,87 @@ try {
127
134
  values.json ? JSON.stringify(describeCapabilities(), null, 2) : formatCapabilities(),
128
135
  )
129
136
  else if (values.version) console.log(version)
130
- else if (values['add-macos']) {
137
+ else if (
138
+ values['add-windows'] ||
139
+ (values['add-macos'] && values['macos-runtime'] !== 'swiftui')
140
+ ) {
141
+ if (
142
+ positionals.length ||
143
+ values.targets ||
144
+ values.target ||
145
+ values['add-native'] ||
146
+ values['add-web'] ||
147
+ (values['add-macos'] && values['add-windows']) ||
148
+ values['check-portability'] ||
149
+ values['fix-imports'] ||
150
+ values.doctor ||
151
+ values.authoring ||
152
+ values.framework ||
153
+ values.example ||
154
+ values.theme ||
155
+ values.screen ||
156
+ values['screen-root'] ||
157
+ values.web ||
158
+ values.rendering ||
159
+ values.path ||
160
+ values['migrate-directory']
161
+ )
162
+ throw new Error(
163
+ 'Run --add-macos or --add-windows in the existing project, with --shared-root and --entry if needed. Add one target at a time.',
164
+ )
165
+ if (values['add-windows'] && values['macos-runtime'])
166
+ throw new Error('--macos-runtime belongs to --add-macos.')
167
+ if (values['macos-runtime'] && values['macos-runtime'] !== 'appkit')
168
+ throw new Error('Mac runtime must be appkit or swiftui.')
169
+ if (values.install || values['no-install'])
170
+ throw new Error(
171
+ 'Desktop adoption previews changes; use --write, then install in the new host directory.',
172
+ )
173
+ if (values.write && values['dry-run']) throw new Error('Choose --write or --dry-run, not both.')
174
+ const target = values['add-windows'] ? 'windows' : 'macos'
175
+ const preview = await planDesktop({
176
+ target,
177
+ roots: values['shared-root']?.split(',').map((root) => root.trim()),
178
+ entry: values.entry,
179
+ packageManager: values['package-manager'],
180
+ })
181
+ if (values.write) await applyDesktop(preview, { signal: cancellation.signal })
182
+ if (values.json)
183
+ console.log(
184
+ JSON.stringify(
185
+ {
186
+ directory: preview.destination,
187
+ entry: preview.entry,
188
+ files: [...preview.files.keys()],
189
+ alreadyAdded: preview.alreadyAdded,
190
+ applied: Boolean(values.write && !preview.alreadyAdded),
191
+ diagnostics: preview.diagnostics,
192
+ },
193
+ null,
194
+ 2,
195
+ ),
196
+ )
197
+ else {
198
+ ui.message(
199
+ `${preview.alreadyAdded ? 'Already configured' : values.write ? 'Added' : 'Preview'}: NativeScript ${target} in ${preview.destination}`,
200
+ )
201
+ for (const path of preview.files.keys())
202
+ console.log(` ${preview.original.get(path) === undefined ? '+' : '~'} ${path}`)
203
+ for (const diagnostic of preview.diagnostics) console.log(diagnostic)
204
+ console.log(
205
+ preview.alreadyAdded
206
+ ? 'Existing files were preserved.'
207
+ : values.write
208
+ ? `Install dependencies in ${preview.destination}, then run ${packageCommands(preview.manager).run(target)} on ${target === 'macos' ? 'macOS' : 'Windows'}.`
209
+ : 'No files changed. Review and rerun with --write.',
210
+ )
211
+ }
212
+ } else if (values['add-macos']) {
131
213
  if (
132
214
  positionals.length ||
133
215
  values['add-native'] ||
134
216
  values['add-web'] ||
217
+ values['add-windows'] ||
135
218
  values.target ||
136
219
  values.targets ||
137
220
  values['check-portability'] ||
@@ -311,7 +394,9 @@ try {
311
394
  // A project without a Mac target is only told; one with it has to be ready.
312
395
  const config = await readFile('mavis.config.json', 'utf8').then(JSON.parse, () => ({}))
313
396
  const blocked =
314
- config.targets?.includes('macos') && result.macos.files?.some((file) => !file.ready)
397
+ config.targets?.includes('macos') &&
398
+ config.apps?.macos?.toolkit !== 'nativescript-appkit' &&
399
+ result.macos.files?.some((file) => !file.ready)
315
400
  if (result.diagnostics.length || blocked) process.exitCode = 1
316
401
  } else if (values.doctor) {
317
402
  const results = await doctor()
@@ -334,6 +419,7 @@ try {
334
419
  let options = {
335
420
  ...values,
336
421
  name: positionals[0],
422
+ macosRuntime: values['macos-runtime'],
337
423
  packageManager: values['package-manager'],
338
424
  install: values['no-install'] ? false : values.install,
339
425
  dryRun: Boolean(values['dry-run']),
@@ -379,6 +465,10 @@ try {
379
465
  ui.message(
380
466
  `Experimental shared TSX: see the README for the supported subset.${plan.preset.targets.includes('macos') ? ' The Mac app needs macOS 14+ and Xcode.' : ''}${plan.preset.targets.includes('native') ? ' Native needs the NativeScript CLI and platform SDKs; check with --doctor.' : ''}`,
381
467
  )
468
+ else if (plan.preset.target === 'desktop')
469
+ ui.message(
470
+ 'Experimental NativeScript desktop subset: check the generated README and --doctor for platform requirements and supported components.',
471
+ )
382
472
  else if (plan.preset.target !== 'web')
383
473
  ui.message(
384
474
  'Mobile needs the NativeScript CLI and platform SDKs. Check your setup with --doctor.',
@@ -0,0 +1,155 @@
1
+ import { posix } from 'node:path'
2
+ const { join } = posix
3
+ import { configOf, versions as v } from './capabilities.mjs'
4
+ import { packageCommands } from './package-manager.mjs'
5
+ const json = (value) => JSON.stringify(value, null, 2) + '\n'
6
+
7
+ /** Every desktop host owns its runtime dependencies; shared Vue never imports an OS bridge. */
8
+ export async function desktopFiles(preset, copyTemplate, projectFiles) {
9
+ // Reuse the existing web/mobile hosts and their shared import configuration.
10
+ const base = await projectFiles({
11
+ ...preset,
12
+ targets: ['web', 'native'],
13
+ target: undefined,
14
+ macosRuntime: undefined,
15
+ 'macos-runtime': undefined,
16
+ web: preset.web ?? 'vite',
17
+ rendering: preset.rendering ?? 'client',
18
+ })
19
+ const files = base.files
20
+ for (const [prefix, target] of [
21
+ ['apps/web/', 'web'],
22
+ ['apps/mobile/', 'native'],
23
+ ])
24
+ if (!preset.targets.includes(target))
25
+ for (const path of files.keys()) if (path.startsWith(prefix)) files.delete(path)
26
+ if (preset.example === 'welcome') {
27
+ await copyTemplate(files, 'desktop/welcome', '.desktop-welcome', { NAME: preset.name })
28
+ files.set('shared/Welcome.vue', files.get('.desktop-welcome/Welcome.vue'))
29
+ for (const path of files.keys()) if (path.startsWith('.desktop-welcome/')) files.delete(path)
30
+ }
31
+ const commands = packageCommands(preset.packageManager)
32
+ const root = JSON.parse(files.get('package.json'))
33
+ if (!preset.targets.includes('web')) delete root.workspaces
34
+ for (const script of ['dev:web', 'build:web'])
35
+ if (!preset.targets.includes('web')) delete root.scripts[script]
36
+ for (const script of ['ios', 'android'])
37
+ if (!preset.targets.includes('native')) delete root.scripts[script]
38
+ root.engines.node = '>=22.23.3'
39
+ root.scripts['install:apps'] = 'node scripts/install-apps.mjs'
40
+ const hosts = []
41
+ for (const target of ['macos', 'windows']) {
42
+ if (!preset.targets.includes(target)) continue
43
+ hosts.push({ directory: `apps/${target}`, platform: target === 'macos' ? 'darwin' : 'win32' })
44
+ const generated = await desktopHostFiles(preset, target, copyTemplate)
45
+ generated.set(
46
+ 'mavis.host.json',
47
+ json({
48
+ schemaVersion: 1,
49
+ kind: 'nativescript-desktop',
50
+ target,
51
+ entry: `shared/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`,
52
+ }),
53
+ )
54
+ for (const [path, source] of generated) files.set(join(`apps/${target}`, path), source)
55
+ root.scripts[target] = commands.run('dev', `apps/${target}`)
56
+ root.scripts[`build:${target}`] = commands.run('build', `apps/${target}`)
57
+ root.scripts[`package:${target}`] = commands.run('package', `apps/${target}`)
58
+ }
59
+ if (preset.targets.includes('native')) hosts.unshift({ directory: 'apps/mobile' })
60
+ files.set(
61
+ 'scripts/install-apps.mjs',
62
+ `import { spawnSync } from 'node:child_process'\nimport { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nconst root = resolve(dirname(fileURLToPath(import.meta.url)), '..')\nconst hosts = ${json([{ directory: '.' }, ...hosts])}\nfor (const host of hosts) {\n if (host.platform && host.platform !== process.platform) { console.log('Install ' + host.directory + ' on ' + host.platform + '.'); continue }\n const result = spawnSync(${JSON.stringify(preset.packageManager)}, ['install'], { cwd: resolve(root, host.directory), stdio: 'inherit', shell: process.platform === 'win32' })\n if (result.error) throw result.error\n if (result.status !== 0) process.exit(result.status ?? 1)\n}\n`,
63
+ )
64
+ files.set('package.json', json(root))
65
+ if (preset.packageManager === 'pnpm' && !preset.targets.includes('web'))
66
+ files.set(
67
+ 'pnpm-workspace.yaml',
68
+ files.get('pnpm-workspace.yaml').replace('packages:\n - apps/web', 'packages: []'),
69
+ )
70
+ files.set(
71
+ 'mavis.config.json',
72
+ json({
73
+ ...configOf(preset),
74
+ portability: { roots: ['shared'], alias: '#mavis', allowImports: [] },
75
+ }),
76
+ )
77
+ files.set('.gitignore', files.get('.gitignore') + '.mavis/\nartifacts/\n')
78
+ files.set(
79
+ 'README.md',
80
+ `# ${preset.name}\n\nShared Vue screens with NativeScript desktop hosts. This is an experimental component subset.\n\n## Start\n\n\`\`\`sh\n${commands.run('install:apps')}\n${preset.targets
81
+ .filter((t) => ['macos', 'windows'].includes(t))
82
+ .map((t) => commands.run(t))
83
+ .join(
84
+ '\n',
85
+ )}\n\`\`\`\n\nThe setup command installs desktop dependencies only on their matching OS. Run Mac commands on macOS and Windows commands on Windows. ${preset.targets.includes('web') ? `Web: \`${commands.run('dev:web')}\`.` : ''} ${preset.targets.includes('native') ? `Mobile: \`${commands.run('ios')}\` or \`${commands.run('android')}\`, with NativeScript CLI and platform SDKs.` : ''}\n\nEdit \`shared/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue\`. State, Vue logic and screens stay shared. Each host supplies native controls and local storage.\n\n## Desktop requirements and packaging\n\nMac: macOS 13.3+, Apple Silicon, Node 22.23.3+ and Xcode command line tools for packaging. Windows: Windows 10 build 18362+ on x64/arm64, Node 22.23.3+ and Windows SDK (mt.exe). Set MAVIS_MT only if the SDK is installed outside its usual location. The launcher prepares a project-local copy of Node with the XAML compatibility manifest; it never changes the system installation.\n\n${preset.targets
86
+ .filter((t) => ['macos', 'windows'].includes(t))
87
+ .map(
88
+ (t) =>
89
+ `- \`${commands.run('build:' + t)}\`: bundle the Vue source.\n- \`${commands.run('package:' + t)}\`: package on ${t === 'macos' ? 'macOS as an ad-hoc signed .app (not notarized)' : 'Windows as an unsigned portable folder (not an installer)'}. Output: \`apps/${t}/artifacts/\`.`,
90
+ )
91
+ .join(
92
+ '\n',
93
+ )}\n\nPackaged apps include Node and the NativeScript runtime. They do not need a globally installed Node or a development server. For distribution, add your own signing and installer/notarization workflow.\n\n## Current component contract\n\nMScreen, MColumn, MRow, MGrid, MText, MInput, MButton, MLink, MCard, MAlert, MEmptyState and MReveal. See \`apps/*/src/host.mjs\` for accepted properties; unsupported properties produce an error. MRow divides space evenly; MGrid adapts to minColumnWidth. NativeScript Core mobile widgets are not desktop controls. Existing Mavis components outside this subset require a desktop implementation.\n\nAppKit uses native menus and a Jolt-sampled finite opacity reveal driven by Core Animation. Windows uses XAML controls; reveal changes visibility immediately while a Jolt Windows driver is unavailable. The built-in themes are supported; arbitrary theme overrides and motion recipes are outside this starter's contract.\n\nDesktop storage stays under the user's application-data directory, in \`${preset.name}\`. Nothing is sent to a server. Commit generated lockfiles. SwiftUI remains available with \`--macos-runtime swiftui\` when creating a separate project.\n`,
94
+ )
95
+ return { preset, files: new Map([...files].sort(([a], [b]) => a.localeCompare(b))) }
96
+ }
97
+
98
+ export async function desktopHostFiles(preset, target, copyTemplate, sharedRoot = '../../shared') {
99
+ const files = new Map()
100
+ const replacements = {
101
+ NAME: preset.name,
102
+ APPID: preset.name.replaceAll('-', ''),
103
+ THEME: preset.theme,
104
+ SHARED: '#shared-ui',
105
+ SHARED_ROOT: sharedRoot,
106
+ STORAGE_FILE: preset.example === 'directory' ? 'directory.json' : 'project.txt',
107
+ }
108
+ await copyTemplate(files, 'desktop/common', '', replacements)
109
+ await copyTemplate(files, `desktop/${target}`, '', replacements)
110
+ await copyTemplate(files, `desktop/${preset.example}`, '.entry', replacements)
111
+ files.set('src/main.ts', files.get('.entry/main.ts'))
112
+ for (const path of files.keys()) if (path.startsWith('.entry/')) files.delete(path)
113
+ if (preset.example === 'directory')
114
+ await copyTemplate(files, 'directory/host', 'src', replacements)
115
+ const runtime = target === 'macos' ? '@nativescript/macos-node-api' : '@nativescript/windows-napi'
116
+ files.set(
117
+ 'package.json',
118
+ json({
119
+ name: `${preset.name}-${target}`,
120
+ private: true,
121
+ version: '0.0.0',
122
+ type: 'module',
123
+ engines: { node: '>=22.23.3' },
124
+ os: [target === 'macos' ? 'darwin' : 'win32'],
125
+ cpu: target === 'macos' ? ['arm64'] : ['x64', 'arm64'],
126
+ scripts: {
127
+ build: 'node build.mjs',
128
+ dev: 'node build.mjs && node launch.mjs',
129
+ start: 'node launch.mjs',
130
+ package: 'node build.mjs && node package.mjs',
131
+ },
132
+ dependencies: {
133
+ [runtime]: target === 'macos' ? v.macosNodeApi : v.windowsNapi,
134
+ '@getcortexlabs/mavis-core': v.mavis,
135
+ '@rafaelaugusto/jolt': v.jolt,
136
+ vue: v.vue,
137
+ 'vue-router': v.router,
138
+ },
139
+ devDependencies: { esbuild: v.esbuild, '@vue/compiler-sfc': v.vue },
140
+ ...(preset.packageManager === 'yarn'
141
+ ? { dependenciesMeta: { esbuild: { built: true } } }
142
+ : {}),
143
+ }),
144
+ )
145
+ if (preset.packageManager === 'pnpm')
146
+ files.set(
147
+ 'pnpm-workspace.yaml',
148
+ 'packages: []\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n',
149
+ )
150
+ if (preset.packageManager === 'yarn') {
151
+ files.set('yarn.lock', '')
152
+ files.set('.yarnrc.yml', 'nodeLinker: node-modules\n')
153
+ }
154
+ return files
155
+ }
package/src/doctor.mjs CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  normalizeConfig,
14
14
  requirements,
15
15
  targetLabel,
16
+ versions,
16
17
  } from './capabilities.mjs'
17
18
 
18
19
  export async function doctor(cwd = process.cwd()) {
@@ -29,7 +30,7 @@ export async function doctor(cwd = process.cwd()) {
29
30
  name: 'Project configuration',
30
31
  ok: project.ok,
31
32
  detail: project.ok
32
- ? `${targetLabel(config.targets)} · ${catalog.authoring[config.authoring].label} · ${config.portability?.existing ? 'existing application; experimental Mac target' : availabilityLabel(availabilityOf(config))}`
33
+ ? `${targetLabel(config.targets)} · ${catalog.authoring[config.authoring]?.label ?? config.framework} · ${config.portability?.existing ? 'existing application; experimental Mac target' : availabilityLabel(availabilityOf(config))}`
33
34
  : project.message.split('\n')[0],
34
35
  },
35
36
  {
@@ -39,6 +40,69 @@ export async function doctor(cwd = process.cwd()) {
39
40
  },
40
41
  checkPackageManager(config.packageManager ?? 'npm'),
41
42
  ]
43
+ if (config.target === 'desktop') {
44
+ results.push({
45
+ name: 'Desktop Node.js 22.23.3+',
46
+ ok: atLeast(process.versions.node, '22.23.3'),
47
+ detail: process.version,
48
+ })
49
+ for (const target of ['macos', 'windows']) {
50
+ if (!config.targets.includes(target)) continue
51
+ const matching = process.platform === (target === 'macos' ? 'darwin' : 'win32')
52
+ results.push({
53
+ name: `${target} build host`,
54
+ ok: matching && (target !== 'macos' || process.arch === 'arm64'),
55
+ detail: requirements[target],
56
+ })
57
+ const name =
58
+ target === 'macos' ? '@nativescript/macos-node-api' : '@nativescript/windows-napi'
59
+ try {
60
+ const manifest = JSON.parse(
61
+ await readFile(join(cwd, 'apps', target, 'package.json'), 'utf8'),
62
+ )
63
+ const expected = config.versions?.[target === 'macos' ? 'macosNodeApi' : 'windowsNapi']
64
+ const resolver = createRequire(join(cwd, 'apps', target, 'package.json'))
65
+ // Resolve only. Importing a native runtime would open platform resources during a diagnostic.
66
+ resolver.resolve(name)
67
+ results.push({
68
+ name: `${target} runtime`,
69
+ ok: manifest.dependencies?.[name] === expected,
70
+ detail: `${name} ${manifest.dependencies?.[name] ?? 'missing'}; expected ${expected}`,
71
+ })
72
+ } catch (error) {
73
+ results.push({
74
+ name: `${target} runtime`,
75
+ ok: false,
76
+ detail: `Install dependencies in apps/${target} on the matching OS. ${error.message.split('\n')[0]}`,
77
+ })
78
+ }
79
+ if (matching && target === 'windows') {
80
+ const { findManifestTool } = await import('../templates/desktop/windows/prepare-host.mjs')
81
+ const tool = findManifestTool()
82
+ results.push({
83
+ name: 'Windows SDK Manifest Tool',
84
+ ok: Boolean(tool),
85
+ detail: tool ?? 'Install the Windows SDK, or set MAVIS_MT to mt.exe.',
86
+ })
87
+ }
88
+ if (matching && target === 'macos') {
89
+ const clang = spawnSync('xcrun', ['--find', 'clang'], { encoding: 'utf8', timeout: 10000 })
90
+ results.push({
91
+ name: 'AppKit packaging toolchain',
92
+ ok: clang.status === 0,
93
+ detail: (clang.error?.message ?? clang.stdout ?? clang.stderr).trim(),
94
+ })
95
+ }
96
+ }
97
+ if (config.targets.includes('native')) nativeChecks(results)
98
+ results.push({
99
+ name: 'Desktop component contract',
100
+ ok: true,
101
+ detail:
102
+ 'Experimental subset; build and run each host to validate its controls. --capabilities --json lists exact accepted props. SwiftUI portability is a separate compiler check.',
103
+ })
104
+ return results
105
+ }
42
106
  if (config.target === 'macos') {
43
107
  const result =
44
108
  process.platform === 'darwin'
@@ -89,6 +153,14 @@ export async function doctor(cwd = process.cwd()) {
89
153
  return results
90
154
  }
91
155
  if (config.target !== 'web') nativeChecks(results)
156
+ if (config.framework !== 'vue') {
157
+ results.push({
158
+ name: 'Direct native adapter',
159
+ ok: true,
160
+ detail: `${config.framework}: MBox, MRow, MColumn, MText, MButton and MInput. Run typecheck and bundle:ios/bundle:android in this project.`,
161
+ })
162
+ return results
163
+ }
92
164
  const portability = await checkPortability(cwd)
93
165
  results.push({
94
166
  name: 'Shared source portability',
@@ -100,6 +172,14 @@ export async function doctor(cwd = process.cwd()) {
100
172
 
101
173
  /** Configuration choices only; compiler diagnostics validate custom theme modules separately. */
102
174
  export function checkRecordedProject(config) {
175
+ if (config.desktop?.existing)
176
+ return {
177
+ ok:
178
+ config.mode === 'direct' &&
179
+ config.framework === 'vue' &&
180
+ config.targets.every((target) => catalog.targets[target]),
181
+ message: 'Invalid NativeScript desktop configuration.',
182
+ }
103
183
  if (config.portability?.existing) return existingProject(config)
104
184
  return checkProject({
105
185
  name: config.name,
@@ -107,6 +187,7 @@ export function checkRecordedProject(config) {
107
187
  web: config.web ?? undefined,
108
188
  rendering: config.rendering ?? undefined,
109
189
  framework: config.framework,
190
+ macosRuntime: config.macosRuntime,
110
191
  authoring: config.authoring,
111
192
  example: config.example,
112
193
  theme:
@@ -192,14 +273,14 @@ export async function checkMacVersions(cwd, config, compiler) {
192
273
  )
193
274
  const swift = await readFile(join(cwd, 'apps/macos/Package.swift'), 'utf8')
194
275
  const pin = /jolt-swift[^\n]*exact:\s*"([^"]+)"/.exec(swift)?.[1]
195
- const expectedJolt = config.versions?.jolt ?? compiler.joltSwift.version
276
+ const expectedJolt = config.versions?.jolt ?? versions.jolt
196
277
  results.push({
197
278
  name: 'Jolt / SwiftUI version',
198
279
  ok:
199
- pin === expectedJolt &&
280
+ expectedJolt === versions.jolt &&
200
281
  pin === compiler.joltSwift.version &&
201
- jolts.every((version) => version === pin),
202
- detail: `Jolt ${[...new Set(jolts)].join(', ') || expectedJolt}; SwiftUI ${pin ?? 'missing exact pin'}; compiler expects ${compiler.joltSwift.version}.`,
282
+ jolts.every((version) => version === expectedJolt),
283
+ detail: `Jolt ${[...new Set(jolts)].join(', ') || expectedJolt}; SwiftUI ${pin ?? 'missing exact pin'}; creator expects JavaScript ${versions.jolt}; compiler expects SwiftUI ${compiler.joltSwift.version}.`,
203
284
  })
204
285
  return results
205
286
  }
@@ -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
+ }
@@ -390,6 +390,14 @@ async function projectConfig(root) {
390
390
  export async function checkPortability(root = process.cwd(), options = {}) {
391
391
  root = resolve(root)
392
392
  const config = await projectConfig(root)
393
+ if (config.framework && config.framework !== 'vue')
394
+ throw new Error(
395
+ 'This source audit applies to shared Vue and SwiftUI sources. Direct native starters use their framework typecheck and platform builds.',
396
+ )
397
+ if (config.target === 'desktop' && options.fixImports)
398
+ throw new Error(
399
+ 'Migrate imports in the Web/mobile project before desktop adoption. Generated desktop hosts require the declared component subset; no files changed.',
400
+ )
393
401
  if (config.authoring === 'mitosis' && options.fixImports)
394
402
  throw new Error(
395
403
  'Import migrations are not supported in a project whose shared sources are compiled for each target.',
@@ -499,13 +507,20 @@ export async function checkPortability(root = process.cwd(), options = {}) {
499
507
  for (const file of [...files.keys(), ...compiled.keys()])
500
508
  if (file === start || file.startsWith(start + sep)) within.add(relative(root, file))
501
509
  }
502
- const macos = await macReadiness(
503
- root,
504
- new Map([...[...files].map(([file, { source }]) => [file, source]), ...compiled]),
505
- config,
506
- within,
507
- options.core,
508
- )
510
+ const macos =
511
+ config.apps?.macos?.toolkit === 'nativescript-appkit' || config.targets?.includes('windows')
512
+ ? {
513
+ checked: false,
514
+ reason:
515
+ 'NativeScript desktop uses direct Vue; the SwiftUI compiler audit does not apply. Build and test each desktop host against its declared subset.',
516
+ }
517
+ : await macReadiness(
518
+ root,
519
+ new Map([...[...files].map(([file, { source }]) => [file, source]), ...compiled]),
520
+ config,
521
+ within,
522
+ options.core,
523
+ )
509
524
  if (options.fixImports) {
510
525
  if (config.portability?.alias !== '#mavis')
511
526
  throw new Error(