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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +44 -7
  2. package/package.json +4 -2
  3. package/src/adapters.mjs +56 -20
  4. package/src/add-desktop.mjs +308 -0
  5. package/src/add-macos.mjs +386 -0
  6. package/src/capabilities.mjs +352 -85
  7. package/src/cli.mjs +181 -9
  8. package/src/desktop.mjs +155 -0
  9. package/src/doctor.mjs +181 -18
  10. package/src/macos-capabilities.generated.mjs +4190 -0
  11. package/src/macos.mjs +147 -29
  12. package/src/migrate-directory.mjs +121 -0
  13. package/src/native-framework.mjs +144 -0
  14. package/src/portability.mjs +123 -5
  15. package/src/scaffold.mjs +59 -11
  16. package/src/ui.mjs +69 -12
  17. package/templates/desktop/common/LICENSE +21 -0
  18. package/templates/desktop/common/build.mjs +58 -0
  19. package/templates/desktop/common/src/components.ts +60 -0
  20. package/templates/desktop/common/src/contract.mjs +35 -0
  21. package/templates/desktop/common/src/renderer.ts +76 -0
  22. package/templates/desktop/common/src/storage.ts +29 -0
  23. package/templates/desktop/directory/main.ts +35 -0
  24. package/templates/desktop/macos/launch.mjs +6 -0
  25. package/templates/desktop/macos/package.mjs +114 -0
  26. package/templates/desktop/macos/src/host.mjs +468 -0
  27. package/templates/desktop/macos/src/motion.mjs +51 -0
  28. package/templates/desktop/welcome/Welcome.vue +56 -0
  29. package/templates/desktop/welcome/main.ts +24 -0
  30. package/templates/desktop/windows/NativeScript-LICENSE +19 -0
  31. package/templates/desktop/windows/launch.mjs +16 -0
  32. package/templates/desktop/windows/package.mjs +54 -0
  33. package/templates/desktop/windows/prepare-host.mjs +73 -0
  34. package/templates/desktop/windows/src/host.mjs +277 -0
  35. package/templates/directory/host/directory-storage.ts +78 -0
  36. package/templates/directory/macos/DirectoryStorage.swift +68 -0
  37. package/templates/directory/mobile/src/app.ts +11 -8
  38. package/templates/directory/nuxt/app/plugins/mavis.ts +11 -8
  39. package/templates/directory/shared/Edit.vue +8 -5
  40. package/templates/directory/shared/directory-store.ts +42 -46
  41. package/templates/directory/vite/src/main.ts +11 -8
  42. package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +2 -2
  43. package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +2 -2
  44. package/templates/macos/examples/tasks/shared/types.ts +1 -0
  45. package/templates/macos/mobile/src/App.vue +4 -2
  46. package/templates/macos/native/Package.swift +3 -1
  47. package/templates/macos/native/Sources/MavisDesktop/App.swift +26 -11
  48. package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +45 -0
  49. package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
  50. package/templates/macos/scripts/generate.mjs +3 -26
  51. package/templates/macos/scripts/macos-manifest.mjs +33 -0
  52. package/templates/macos/scripts/macos.mjs +20 -18
  53. package/templates/macos/web/index.html +1 -1
  54. package/templates/macos/web/src/main.js +176 -3
  55. package/templates/macos/web/src/mavis.js +2 -0
  56. package/templates/macos/web/src/style.css +2 -1
  57. package/templates/macos/web/vite.config.mjs +12 -1
  58. package/templates/migrations/directory-rc13.json +36 -0
  59. package/templates/mobile/src/mavis.ts +2 -82
  60. package/templates/mobile/webpack.config.js +4 -0
  61. package/templates/native-framework/angular/screen.ts +84 -0
  62. package/templates/native-framework/common/nativescript.config.ts +6 -0
  63. package/templates/native-framework/common/src/app.ts +5 -0
  64. package/templates/native-framework/common/src/model.ts +40 -0
  65. package/templates/native-framework/common/src/references.d.ts +8 -0
  66. package/templates/native-framework/common/tsconfig.json +16 -0
  67. package/templates/native-framework/common/webpack.config.js +67 -0
  68. package/templates/native-framework/plain/screen.ts +102 -0
  69. package/templates/native-framework/react/screen.ts +83 -0
  70. package/templates/native-framework/solid/screen.ts +111 -0
  71. package/templates/native-framework/svelte/Welcome.svelte +26 -0
  72. package/templates/native-framework/svelte/screen.ts +14 -0
  73. package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
  74. package/templates/nuxt/app/mavis.ts +2 -84
  75. package/templates/vite/src/mavis.ts +2 -84
  76. package/templates/macos/scripts/portable/emit-swift.mjs +0 -1287
  77. package/templates/macos/scripts/portable/emit-vue.mjs +0 -615
  78. package/templates/macos/scripts/portable/index.mjs +0 -95
  79. package/templates/macos/scripts/portable/model.mjs +0 -1441
  80. package/templates/macos/scripts/portable/program.mjs +0 -163
package/src/doctor.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { pathToFileURL } from 'node:url'
2
+ import { createRequire } from 'node:module'
2
3
  import { spawnSync } from 'node:child_process'
3
4
  import { readFile } from 'node:fs/promises'
4
5
  import { checkPortability } from './portability.mjs'
@@ -12,6 +13,7 @@ import {
12
13
  normalizeConfig,
13
14
  requirements,
14
15
  targetLabel,
16
+ versions,
15
17
  } from './capabilities.mjs'
16
18
 
17
19
  export async function doctor(cwd = process.cwd()) {
@@ -22,23 +24,13 @@ export async function doctor(cwd = process.cwd()) {
22
24
  throw new Error('Run --doctor from a generated project containing mavis.config.json.')
23
25
  }
24
26
  // The same check the creator runs before writing a project, on what this one records.
25
- const project = checkProject({
26
- name: config.name,
27
- targets: config.targets,
28
- web: config.web ?? undefined,
29
- rendering: config.rendering ?? undefined,
30
- framework: config.framework,
31
- authoring: config.authoring,
32
- example: config.example,
33
- theme: config.theme,
34
- packageManager: config.packageManager,
35
- })
27
+ const project = checkRecordedProject(config)
36
28
  const results = [
37
29
  {
38
30
  name: 'Project configuration',
39
31
  ok: project.ok,
40
32
  detail: project.ok
41
- ? `${targetLabel(config.targets)} · ${catalog.authoring[config.authoring].label} · ${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))}`
42
34
  : project.message.split('\n')[0],
43
35
  },
44
36
  {
@@ -48,6 +40,69 @@ export async function doctor(cwd = process.cwd()) {
48
40
  },
49
41
  checkPackageManager(config.packageManager ?? 'npm'),
50
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
+ }
51
106
  if (config.target === 'macos') {
52
107
  const result =
53
108
  process.platform === 'darwin'
@@ -60,13 +115,25 @@ export async function doctor(cwd = process.cwd()) {
60
115
  ? (result.error?.message ?? (result.stdout || result.stderr)).trim().split('\n')[0]
61
116
  : 'macOS 14+ and Xcode are required for the native app. Web remains available.',
62
117
  })
63
- // The project's own compiler copy, with its installed TypeScript and theme packages.
118
+ // Use the compiler installed in this project, not a copied implementation.
64
119
  try {
65
- const compiler = await import(pathToFileURL(join(cwd, 'scripts/portable/index.mjs')))
66
- const { model } = await compiler.compileProject(await compiler.readShared(cwd), {
67
- theme: config.theme,
68
- root: config.portability?.entry ?? 'Welcome',
69
- })
120
+ const compiler = await import(
121
+ pathToFileURL(
122
+ createRequire(join(cwd, 'package.json')).resolve('@getcortexlabs/mavis-compiler'),
123
+ )
124
+ )
125
+ results.push(...(await checkMacVersions(cwd, config, compiler)))
126
+ compiler.macAppSettings(config.macos, config.name)
127
+ const { model } = await compiler.compileProject(
128
+ await compiler.readShared(cwd, { roots: config.portability?.roots }),
129
+ {
130
+ theme: config.theme,
131
+ root: config.portability?.entry ?? 'Welcome',
132
+ sourceRoot: config.portability?.sourceRoot ?? config.portability?.roots?.[0] ?? 'shared',
133
+ destinations: config.portability?.destinations,
134
+ },
135
+ )
136
+ compiler.startupPlan(model, config.portability?.startup)
70
137
  results.push({
71
138
  name: 'Shared sources',
72
139
  ok: true,
@@ -86,6 +153,14 @@ export async function doctor(cwd = process.cwd()) {
86
153
  return results
87
154
  }
88
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
+ }
89
164
  const portability = await checkPortability(cwd)
90
165
  results.push({
91
166
  name: 'Shared source portability',
@@ -95,6 +170,34 @@ export async function doctor(cwd = process.cwd()) {
95
170
  return results
96
171
  }
97
172
 
173
+ /** Configuration choices only; compiler diagnostics validate custom theme modules separately. */
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
+ }
183
+ if (config.portability?.existing) return existingProject(config)
184
+ return checkProject({
185
+ name: config.name,
186
+ targets: config.targets,
187
+ web: config.web ?? undefined,
188
+ rendering: config.rendering ?? undefined,
189
+ framework: config.framework,
190
+ macosRuntime: config.macosRuntime,
191
+ authoring: config.authoring,
192
+ example: config.example,
193
+ theme:
194
+ config.targets?.includes('macos') && typeof config.theme === 'object'
195
+ ? undefined
196
+ : config.theme,
197
+ packageManager: config.packageManager,
198
+ })
199
+ }
200
+
98
201
  function nativeChecks(results) {
99
202
  const probe = (name, command, args) => {
100
203
  const result = spawnSync(command, args, { encoding: 'utf8', timeout: 10000 })
@@ -121,3 +224,63 @@ function nativeChecks(results) {
121
224
  detail: 'iOS builds require macOS and Xcode; Android remains available.',
122
225
  })
123
226
  }
227
+
228
+ function existingProject(config) {
229
+ const ok =
230
+ Array.isArray(config.targets) &&
231
+ config.targets.includes('macos') &&
232
+ config.targets.every((target) => catalog.targets[target]) &&
233
+ ['vue', 'mitosis'].includes(config.authoring) &&
234
+ catalog.packageManagers.includes(config.packageManager) &&
235
+ (!config.targets.includes('web') ||
236
+ catalog.hosts[config.web]?.rendering?.includes(config.rendering))
237
+ return {
238
+ ok,
239
+ message:
240
+ 'Invalid targets, authoring, package manager or Web host/rendering in mavis.config.json.',
241
+ }
242
+ }
243
+
244
+ /** Read-only release alignment check, independent of the Swift/NativeScript SDK probes. */
245
+ export async function checkMacVersions(cwd, config, compiler) {
246
+ const results = []
247
+ const manifests = []
248
+ for (const name of ['package.json', 'apps/web/package.json', 'apps/mobile/package.json']) {
249
+ try {
250
+ manifests.push(JSON.parse(await readFile(join(cwd, name), 'utf8')))
251
+ } catch (error) {
252
+ if (error.code !== 'ENOENT') throw error
253
+ }
254
+ }
255
+ const dependencies = manifests.map((pkg) => ({ ...pkg.devDependencies, ...pkg.dependencies }))
256
+ const declared = dependencies[0]?.['@getcortexlabs/mavis-compiler']
257
+ const expected = config.versions?.mavis ?? compiler.compilerVersion
258
+ const renderers = dependencies.flatMap((dep) =>
259
+ ['@getcortexlabs/mavis-core', '@getcortexlabs/mavis-web', '@getcortexlabs/mavis'].flatMap(
260
+ (name) => (dep[name] ? [dep[name]] : []),
261
+ ),
262
+ )
263
+ results.push({
264
+ name: 'Mavis compiler version',
265
+ ok:
266
+ declared === compiler.compilerVersion &&
267
+ compiler.compilerVersion === expected &&
268
+ renderers.every((version) => [expected, '^' + expected, '~' + expected].includes(version)),
269
+ detail: `Installed compiler ${compiler.compilerVersion}; requested ${declared ?? 'missing'}; Mavis ${expected}. Upgrade Mavis and the compiler together.`,
270
+ })
271
+ const jolts = dependencies.flatMap((dep) =>
272
+ dep['@rafaelaugusto/jolt'] ? [dep['@rafaelaugusto/jolt']] : [],
273
+ )
274
+ const swift = await readFile(join(cwd, 'apps/macos/Package.swift'), 'utf8')
275
+ const pin = /jolt-swift[^\n]*exact:\s*"([^"]+)"/.exec(swift)?.[1]
276
+ const expectedJolt = config.versions?.jolt ?? versions.jolt
277
+ results.push({
278
+ name: 'Jolt / SwiftUI version',
279
+ ok:
280
+ expectedJolt === versions.jolt &&
281
+ pin === 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}.`,
284
+ })
285
+ return results
286
+ }