@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.
- package/README.md +44 -7
- package/package.json +4 -2
- package/src/adapters.mjs +56 -20
- package/src/add-desktop.mjs +308 -0
- package/src/add-macos.mjs +386 -0
- package/src/capabilities.mjs +352 -85
- package/src/cli.mjs +181 -9
- package/src/desktop.mjs +155 -0
- package/src/doctor.mjs +181 -18
- package/src/macos-capabilities.generated.mjs +4190 -0
- package/src/macos.mjs +147 -29
- package/src/migrate-directory.mjs +121 -0
- package/src/native-framework.mjs +144 -0
- package/src/portability.mjs +123 -5
- package/src/scaffold.mjs +59 -11
- package/src/ui.mjs +69 -12
- package/templates/desktop/common/LICENSE +21 -0
- package/templates/desktop/common/build.mjs +58 -0
- package/templates/desktop/common/src/components.ts +60 -0
- package/templates/desktop/common/src/contract.mjs +35 -0
- package/templates/desktop/common/src/renderer.ts +76 -0
- package/templates/desktop/common/src/storage.ts +29 -0
- package/templates/desktop/directory/main.ts +35 -0
- package/templates/desktop/macos/launch.mjs +6 -0
- package/templates/desktop/macos/package.mjs +114 -0
- package/templates/desktop/macos/src/host.mjs +468 -0
- package/templates/desktop/macos/src/motion.mjs +51 -0
- package/templates/desktop/welcome/Welcome.vue +56 -0
- package/templates/desktop/welcome/main.ts +24 -0
- package/templates/desktop/windows/NativeScript-LICENSE +19 -0
- package/templates/desktop/windows/launch.mjs +16 -0
- package/templates/desktop/windows/package.mjs +54 -0
- package/templates/desktop/windows/prepare-host.mjs +73 -0
- package/templates/desktop/windows/src/host.mjs +277 -0
- package/templates/directory/host/directory-storage.ts +78 -0
- package/templates/directory/macos/DirectoryStorage.swift +68 -0
- package/templates/directory/mobile/src/app.ts +11 -8
- package/templates/directory/nuxt/app/plugins/mavis.ts +11 -8
- package/templates/directory/shared/Edit.vue +8 -5
- package/templates/directory/shared/directory-store.ts +42 -46
- package/templates/directory/vite/src/main.ts +11 -8
- package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +2 -2
- package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +2 -2
- package/templates/macos/examples/tasks/shared/types.ts +1 -0
- package/templates/macos/mobile/src/App.vue +4 -2
- package/templates/macos/native/Package.swift +3 -1
- package/templates/macos/native/Sources/MavisDesktop/App.swift +26 -11
- package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +45 -0
- package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
- package/templates/macos/scripts/generate.mjs +3 -26
- package/templates/macos/scripts/macos-manifest.mjs +33 -0
- package/templates/macos/scripts/macos.mjs +20 -18
- package/templates/macos/web/index.html +1 -1
- package/templates/macos/web/src/main.js +176 -3
- package/templates/macos/web/src/mavis.js +2 -0
- package/templates/macos/web/src/style.css +2 -1
- package/templates/macos/web/vite.config.mjs +12 -1
- package/templates/migrations/directory-rc13.json +36 -0
- package/templates/mobile/src/mavis.ts +2 -82
- package/templates/mobile/webpack.config.js +4 -0
- package/templates/native-framework/angular/screen.ts +84 -0
- package/templates/native-framework/common/nativescript.config.ts +6 -0
- package/templates/native-framework/common/src/app.ts +5 -0
- package/templates/native-framework/common/src/model.ts +40 -0
- package/templates/native-framework/common/src/references.d.ts +8 -0
- package/templates/native-framework/common/tsconfig.json +16 -0
- package/templates/native-framework/common/webpack.config.js +67 -0
- package/templates/native-framework/plain/screen.ts +102 -0
- package/templates/native-framework/react/screen.ts +83 -0
- package/templates/native-framework/solid/screen.ts +111 -0
- package/templates/native-framework/svelte/Welcome.svelte +26 -0
- package/templates/native-framework/svelte/screen.ts +14 -0
- package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
- package/templates/nuxt/app/mavis.ts +2 -84
- package/templates/vite/src/mavis.ts +2 -84
- package/templates/macos/scripts/portable/emit-swift.mjs +0 -1287
- package/templates/macos/scripts/portable/emit-vue.mjs +0 -615
- package/templates/macos/scripts/portable/index.mjs +0 -95
- package/templates/macos/scripts/portable/model.mjs +0 -1441
- package/templates/macos/scripts/portable/program.mjs +0 -163
package/src/cli.mjs
CHANGED
|
@@ -5,7 +5,10 @@ import { confirm, isCancel } from '@clack/prompts'
|
|
|
5
5
|
import { readFile } from 'node:fs/promises'
|
|
6
6
|
import { scaffold, installProject } from './scaffold.mjs'
|
|
7
7
|
import { planTarget, applyTarget } from './add-target.mjs'
|
|
8
|
-
import {
|
|
8
|
+
import { planMacos, applyMacos } from './add-macos.mjs'
|
|
9
|
+
import { planDesktop, applyDesktop } from './add-desktop.mjs'
|
|
10
|
+
import { migrationDiff } from './migrate-directory.mjs'
|
|
11
|
+
import { checkPortability, formatMacReadiness } from './portability.mjs'
|
|
9
12
|
import { doctor } from './doctor.mjs'
|
|
10
13
|
import {
|
|
11
14
|
atLeast,
|
|
@@ -25,18 +28,25 @@ import {
|
|
|
25
28
|
import { nextSteps, projectSummary, sharedEntry, terminalUI, wizard } from './ui.mjs'
|
|
26
29
|
|
|
27
30
|
const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
|
|
28
|
-
const help = `Create Mavis — Web, Native (iOS/Android)
|
|
31
|
+
const help = `Create Mavis — Web, Native (iOS/Android), Mac and Windows
|
|
29
32
|
|
|
30
33
|
npm create @getcortexlabs/mavis@latest
|
|
31
34
|
create-mavis my-app --targets web,native,macos --package-manager pnpm --no-install
|
|
32
35
|
create-mavis my-app --targets web,native --web nuxt
|
|
33
36
|
|
|
34
|
-
--targets web,native,macos
|
|
35
|
-
|
|
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
|
|
36
41
|
--target mobile|web|both|macos
|
|
37
42
|
Earlier names: native, web, web+native, web+macos
|
|
38
43
|
--add-native Add apps/mobile to an existing Vue/Vite or Nuxt app
|
|
39
44
|
--add-web Add apps/web to an existing NativeScript-Vue app
|
|
45
|
+
--add-macos Preview adding Mac; choose --macos-runtime swiftui for SwiftUI
|
|
46
|
+
--add-windows Preview adding NativeScript Windows; --write applies
|
|
47
|
+
--migrate-directory Opt in to migrate an unmodified RC.13 Directory example
|
|
48
|
+
--shared-root path Source roots for --add-macos (comma-separated)
|
|
49
|
+
--entry path.vue Shared Vue/TSX entry for --add-macos
|
|
40
50
|
--screen path.vue Reuse an existing screen without moving it
|
|
41
51
|
--screen-root screen|content Existing MScreen or content to wrap (auto-detected)
|
|
42
52
|
--web vite|nuxt Default: vite
|
|
@@ -51,13 +61,14 @@ const help = `Create Mavis — Web, Native (iOS/Android) and Mac in any combinat
|
|
|
51
61
|
--check-portability Audit shared sources without SDK checks
|
|
52
62
|
--path directory Override the configured shared source directory
|
|
53
63
|
--fix-imports Preview safe renderer-import replacements
|
|
54
|
-
--write Apply the previewed import migration
|
|
64
|
+
--write Apply the previewed import migration or Mac target
|
|
55
65
|
--json Machine-readable portability diagnostics
|
|
56
66
|
--theme mavis|midnight Default: mavis
|
|
57
67
|
--package-manager npm|pnpm|yarn
|
|
58
68
|
Default: the invoking manager, or npm
|
|
59
|
-
--framework vue
|
|
60
|
-
|
|
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
|
|
61
72
|
--yes, -y Use defaults without prompts (skip installation)
|
|
62
73
|
--install / --no-install Install dependencies now or later
|
|
63
74
|
--dry-run Show the complete file plan without writing
|
|
@@ -86,6 +97,12 @@ try {
|
|
|
86
97
|
targets: { type: 'string' },
|
|
87
98
|
'add-native': { type: 'boolean' },
|
|
88
99
|
'add-web': { type: 'boolean' },
|
|
100
|
+
'add-macos': { type: 'boolean' },
|
|
101
|
+
'add-windows': { type: 'boolean' },
|
|
102
|
+
'macos-runtime': { type: 'string' },
|
|
103
|
+
'migrate-directory': { type: 'boolean' },
|
|
104
|
+
'shared-root': { type: 'string' },
|
|
105
|
+
entry: { type: 'string' },
|
|
89
106
|
screen: { type: 'string' },
|
|
90
107
|
'screen-root': { type: 'string' },
|
|
91
108
|
web: { type: 'string' },
|
|
@@ -117,7 +134,146 @@ try {
|
|
|
117
134
|
values.json ? JSON.stringify(describeCapabilities(), null, 2) : formatCapabilities(),
|
|
118
135
|
)
|
|
119
136
|
else if (values.version) console.log(version)
|
|
120
|
-
else if (
|
|
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']) {
|
|
213
|
+
if (
|
|
214
|
+
positionals.length ||
|
|
215
|
+
values['add-native'] ||
|
|
216
|
+
values['add-web'] ||
|
|
217
|
+
values['add-windows'] ||
|
|
218
|
+
values.target ||
|
|
219
|
+
values.targets ||
|
|
220
|
+
values['check-portability'] ||
|
|
221
|
+
values['fix-imports'] ||
|
|
222
|
+
values.path ||
|
|
223
|
+
values.doctor ||
|
|
224
|
+
values.example ||
|
|
225
|
+
values.theme ||
|
|
226
|
+
values.framework ||
|
|
227
|
+
values.authoring ||
|
|
228
|
+
values.screen ||
|
|
229
|
+
values['screen-root'] ||
|
|
230
|
+
values.web ||
|
|
231
|
+
values.rendering
|
|
232
|
+
)
|
|
233
|
+
throw new Error(
|
|
234
|
+
'Run --add-macos in the existing project. Choose source roots with --shared-root and an entry with --entry.',
|
|
235
|
+
)
|
|
236
|
+
if (values.install || values['no-install'])
|
|
237
|
+
throw new Error(
|
|
238
|
+
'--add-macos does not install dependencies; review and apply with --write, then run your package manager.',
|
|
239
|
+
)
|
|
240
|
+
if (values.write && values['dry-run']) throw new Error('Choose --write or --dry-run, not both.')
|
|
241
|
+
const plan = await planMacos({
|
|
242
|
+
roots: values['shared-root']?.split(',').map((root) => root.trim()),
|
|
243
|
+
entry: values.entry,
|
|
244
|
+
packageManager: values['package-manager'],
|
|
245
|
+
migrateDirectory: values['migrate-directory'],
|
|
246
|
+
})
|
|
247
|
+
const summary = {
|
|
248
|
+
directory: 'apps/macos',
|
|
249
|
+
entry: plan.entry,
|
|
250
|
+
roots: plan.roots,
|
|
251
|
+
manager: plan.manager,
|
|
252
|
+
alreadyAdded: plan.alreadyAdded,
|
|
253
|
+
components: plan.components,
|
|
254
|
+
files: [...plan.files.keys()],
|
|
255
|
+
config: plan.config,
|
|
256
|
+
migration: plan.migration ?? [],
|
|
257
|
+
applied: Boolean(values.write && !plan.alreadyAdded),
|
|
258
|
+
}
|
|
259
|
+
if (values.write) await applyMacos(plan, { signal: cancellation.signal })
|
|
260
|
+
if (values.json) console.log(JSON.stringify(summary, null, 2))
|
|
261
|
+
else {
|
|
262
|
+
ui.message(
|
|
263
|
+
`${plan.alreadyAdded ? 'Already configured' : values.write ? 'Added' : 'Preview'}: SwiftUI in apps/macos; ${plan.components} shared components`,
|
|
264
|
+
)
|
|
265
|
+
for (const diff of summary.migration) console.log(migrationDiff(diff))
|
|
266
|
+
for (const name of summary.files)
|
|
267
|
+
console.log(` ${plan.original.get(name) === undefined ? '+' : '~'} ${name}`)
|
|
268
|
+
console.log(
|
|
269
|
+
plan.alreadyAdded
|
|
270
|
+
? 'Existing files were preserved.'
|
|
271
|
+
: values.write
|
|
272
|
+
? `Run ${packageCommands(plan.manager).install}, then ${packageCommands(plan.manager).run('build:macos')}.`
|
|
273
|
+
: 'No files changed. Review this plan and rerun with --write to add Mac and migrate mavis.config.json to schema 2.',
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
} else if (values['add-native'] || values['add-web']) {
|
|
121
277
|
if (!atLeast(process.versions.node, requirements.node))
|
|
122
278
|
throw new Error(
|
|
123
279
|
`Mavis needs Node.js ${requirements.node} or newer. You are using ${process.version}.`,
|
|
@@ -144,6 +300,8 @@ try {
|
|
|
144
300
|
throw new Error('--web and --rendering belong to --add-web.')
|
|
145
301
|
if (values.install && values['no-install'])
|
|
146
302
|
throw new Error('Choose either --install or --no-install.')
|
|
303
|
+
if (values.entry || values['shared-root'] || values['migrate-directory'])
|
|
304
|
+
throw new Error('--entry and --shared-root require --add-macos.')
|
|
147
305
|
if (values['screen-root'] && !values.screen) throw new Error('--screen-root requires --screen.')
|
|
148
306
|
const target = await planTarget({
|
|
149
307
|
target: values['add-native'] ? 'mobile' : 'web',
|
|
@@ -231,13 +389,22 @@ try {
|
|
|
231
389
|
console.log(
|
|
232
390
|
`${result.files.length} files checked; ${result.diagnostics.length} findings. ${values['fix-imports'] && !values.write ? 'Preview only. Use --write to apply safe import changes.' : ''}`,
|
|
233
391
|
)
|
|
392
|
+
console.log(formatMacReadiness(result.macos))
|
|
234
393
|
}
|
|
235
|
-
|
|
394
|
+
// A project without a Mac target is only told; one with it has to be ready.
|
|
395
|
+
const config = await readFile('mavis.config.json', 'utf8').then(JSON.parse, () => ({}))
|
|
396
|
+
const blocked =
|
|
397
|
+
config.targets?.includes('macos') &&
|
|
398
|
+
config.apps?.macos?.toolkit !== 'nativescript-appkit' &&
|
|
399
|
+
result.macos.files?.some((file) => !file.ready)
|
|
400
|
+
if (result.diagnostics.length || blocked) process.exitCode = 1
|
|
236
401
|
} else if (values.doctor) {
|
|
237
402
|
const results = await doctor()
|
|
238
403
|
for (const item of results) console.log(`${item.ok ? '✓' : '—'} ${item.name}: ${item.detail}`)
|
|
239
404
|
if (results.some((item) => !item.ok)) process.exitCode = 1
|
|
240
405
|
} else {
|
|
406
|
+
if (values.entry || values['shared-root'] || values['migrate-directory'])
|
|
407
|
+
throw new Error('--entry and --shared-root require --add-macos.')
|
|
241
408
|
if (values.screen || values['screen-root'])
|
|
242
409
|
throw new Error('--screen requires --add-native or --add-web.')
|
|
243
410
|
if (values.write || values.path || values.json)
|
|
@@ -252,6 +419,7 @@ try {
|
|
|
252
419
|
let options = {
|
|
253
420
|
...values,
|
|
254
421
|
name: positionals[0],
|
|
422
|
+
macosRuntime: values['macos-runtime'],
|
|
255
423
|
packageManager: values['package-manager'],
|
|
256
424
|
install: values['no-install'] ? false : values.install,
|
|
257
425
|
dryRun: Boolean(values['dry-run']),
|
|
@@ -297,6 +465,10 @@ try {
|
|
|
297
465
|
ui.message(
|
|
298
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.' : ''}`,
|
|
299
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
|
+
)
|
|
300
472
|
else if (plan.preset.target !== 'web')
|
|
301
473
|
ui.message(
|
|
302
474
|
'Mobile needs the NativeScript CLI and platform SDKs. Check your setup with --doctor.',
|
package/src/desktop.mjs
ADDED
|
@@ -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
|
+
}
|