@getcortexlabs/create-mavis 0.1.0-rc.15 → 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.
- package/README.md +6 -29
- package/package.json +2 -4
- package/src/adapters.mjs +0 -7
- package/src/add-desktop.mjs +50 -4
- package/src/capabilities.mjs +39 -186
- package/src/cli.mjs +16 -102
- package/src/desktop.mjs +1 -1
- package/src/doctor.mjs +4 -116
- package/src/native-framework.mjs +1 -1
- package/src/portability.mjs +2 -116
- package/src/scaffold.mjs +1 -6
- package/src/shared-api.mjs +3 -0
- package/src/ui.mjs +4 -64
- package/templates/desktop/common/build.mjs +0 -9
- package/templates/desktop/macos/src/host.mjs +9 -6
- package/templates/desktop/windows/src/host.mjs +21 -4
- package/src/add-macos.mjs +0 -386
- package/src/macos-capabilities.generated.mjs +0 -4190
- package/src/macos.mjs +0 -394
- package/src/migrate-directory.mjs +0 -121
- package/templates/desktop/macos/src/motion.mjs +0 -51
- package/templates/directory/macos/DirectoryStorage.swift +0 -68
- package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +0 -57
- package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +0 -33
- package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +0 -251
- package/templates/macos/examples/tasks/shared/types.ts +0 -10
- package/templates/macos/mobile/src/App.vue +0 -14
- package/templates/macos/mobile/src/app.ts +0 -7
- package/templates/macos/native/Package.swift +0 -19
- package/templates/macos/native/Sources/MavisDesktop/App.swift +0 -35
- package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +0 -45
- package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
- package/templates/macos/root/tsconfig.json +0 -14
- package/templates/macos/scripts/generate.mjs +0 -13
- package/templates/macos/scripts/macos-manifest.mjs +0 -33
- package/templates/macos/scripts/macos.mjs +0 -58
- package/templates/macos/shared/Welcome.lite.tsx +0 -42
- package/templates/macos/web/index.html +0 -12
- package/templates/macos/web/src/main.js +0 -212
- package/templates/macos/web/src/mavis.js +0 -2
- package/templates/macos/web/src/style.css +0 -14
- package/templates/macos/web/vite.config.mjs +0 -14
- package/templates/migrations/directory-rc13.json +0 -36
package/src/ui.mjs
CHANGED
|
@@ -41,30 +41,6 @@ export function projectSummary(preset, install) {
|
|
|
41
41
|
`Packages ${preset.packageManager} · ${install ? 'install for this OS now' : 'install later'}`,
|
|
42
42
|
].join('\n')
|
|
43
43
|
|
|
44
|
-
if (preset.target === 'macos')
|
|
45
|
-
return [
|
|
46
|
-
`Project ${preset.name}`,
|
|
47
|
-
`Targets ${targetLabel(preset.targets)} · EXPERIMENTAL`,
|
|
48
|
-
`Hosts ${[
|
|
49
|
-
preset.targets.includes('web') &&
|
|
50
|
-
(preset.web === 'nuxt' ? `Nuxt · ${preset.rendering.toUpperCase()}` : 'Vue + Vite'),
|
|
51
|
-
preset.targets.includes('native') && 'NativeScript iOS + Android',
|
|
52
|
-
preset.targets.includes('macos') && 'SwiftUI macOS',
|
|
53
|
-
]
|
|
54
|
-
.filter(Boolean)
|
|
55
|
-
.join(' · ')}`,
|
|
56
|
-
preset.authoring === 'vue'
|
|
57
|
-
? 'Authoring Shared Vue (shared/*.vue), compiled to SwiftUI for Mac'
|
|
58
|
-
: 'Authoring Shared TSX (shared/*.lite.tsx), compiled for each target',
|
|
59
|
-
...status(preset),
|
|
60
|
-
preset.example === 'directory'
|
|
61
|
-
? 'Example Search, details and editing · shared/Directory.vue'
|
|
62
|
-
: preset.example === 'tasks'
|
|
63
|
-
? 'Example Tasks · list and detail, forms, shortcuts and motion · shared/Tasks.lite.tsx'
|
|
64
|
-
: 'Example Basic welcome · shared/Welcome.lite.tsx',
|
|
65
|
-
`Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
|
|
66
|
-
`Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
|
|
67
|
-
].join('\n')
|
|
68
44
|
const web = preset.web === 'nuxt' ? `Nuxt · ${preset.rendering.toUpperCase()}` : 'Vue + Vite'
|
|
69
45
|
return [
|
|
70
46
|
`Project ${preset.name}`,
|
|
@@ -81,10 +57,6 @@ export function sharedEntry(preset) {
|
|
|
81
57
|
return preset.framework === 'svelte' ? 'src/Welcome.svelte' : 'src/screen.ts'
|
|
82
58
|
if (preset.target === 'desktop')
|
|
83
59
|
return `shared/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
84
|
-
if (preset.target === 'macos')
|
|
85
|
-
return preset.example === 'directory'
|
|
86
|
-
? 'shared/Directory.vue'
|
|
87
|
-
: `shared/${preset.example === 'tasks' ? 'Tasks' : 'Welcome'}.lite.tsx`
|
|
88
60
|
const directory =
|
|
89
61
|
preset.target === 'both' ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
|
|
90
62
|
return `${directory}/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
@@ -102,18 +74,6 @@ export function nextSteps(preset, installed = false) {
|
|
|
102
74
|
...(preset.targets.includes('windows') ? [commands.run('windows') + ' # on Windows'] : []),
|
|
103
75
|
'Run --doctor on each target OS. See README for the desktop component subset.',
|
|
104
76
|
].join('\n')
|
|
105
|
-
if (preset.target === 'macos') {
|
|
106
|
-
const has = (target) => preset.targets.includes(target)
|
|
107
|
-
return [
|
|
108
|
-
`cd ${preset.name}`,
|
|
109
|
-
...(!installed ? [has('native') ? commands.setup(true) : commands.install] : []),
|
|
110
|
-
...(has('web') ? [commands.run('dev:web')] : []),
|
|
111
|
-
...(has('native') ? [commands.run('ios'), commands.run('android')] : []),
|
|
112
|
-
...(has('macos')
|
|
113
|
-
? [commands.run('macos'), 'macOS 14+ and Xcode required for the Mac app.']
|
|
114
|
-
: []),
|
|
115
|
-
].join('\n')
|
|
116
|
-
}
|
|
117
77
|
return [
|
|
118
78
|
`cd ${preset.name}`,
|
|
119
79
|
...(!installed ? [commands.setup(preset.target === 'both')] : []),
|
|
@@ -197,14 +157,6 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
197
157
|
fallback: ['web'],
|
|
198
158
|
options: choices(catalog.targets),
|
|
199
159
|
},
|
|
200
|
-
{
|
|
201
|
-
key: 'macosRuntime',
|
|
202
|
-
message: 'Choose the Mac runtime',
|
|
203
|
-
when: () => targets().includes('macos'),
|
|
204
|
-
fallback: 'appkit',
|
|
205
|
-
options: () =>
|
|
206
|
-
choices(catalog.macosRuntimes, targets().includes('windows') ? ['appkit'] : undefined),
|
|
207
|
-
},
|
|
208
160
|
{
|
|
209
161
|
key: 'framework',
|
|
210
162
|
message: 'Choose the framework for iOS and Android',
|
|
@@ -241,18 +193,10 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
241
193
|
options: () =>
|
|
242
194
|
choices(
|
|
243
195
|
catalog.examples,
|
|
244
|
-
Object.keys(catalog.examples).filter(
|
|
245
|
-
(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
? 'native'
|
|
249
|
-
: targets().includes('macos') && answers.macosRuntime === 'swiftui'
|
|
250
|
-
? 'mitosis'
|
|
251
|
-
: 'vue',
|
|
252
|
-
) ||
|
|
253
|
-
(targets().includes('macos') &&
|
|
254
|
-
answers.macosRuntime === 'swiftui' &&
|
|
255
|
-
catalog.examples[example].portableAuthoring),
|
|
196
|
+
Object.keys(catalog.examples).filter((example) =>
|
|
197
|
+
catalog.examples[example].authoring.includes(
|
|
198
|
+
answers.framework && answers.framework !== 'vue' ? 'native' : 'vue',
|
|
199
|
+
),
|
|
256
200
|
),
|
|
257
201
|
),
|
|
258
202
|
},
|
|
@@ -371,10 +315,6 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
371
315
|
io.log.warn(error.message)
|
|
372
316
|
continue
|
|
373
317
|
}
|
|
374
|
-
if (value.includes('macos'))
|
|
375
|
-
io.log.message(
|
|
376
|
-
`The Mac app defaults to NativeScript AppKit with shared Vue. SwiftUI remains available as a separate runtime choice.`,
|
|
377
|
-
)
|
|
378
318
|
}
|
|
379
319
|
answers[step.key] = value
|
|
380
320
|
index++
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { build } from 'esbuild'
|
|
2
2
|
import { parse, compileScript } from '@vue/compiler-sfc'
|
|
3
3
|
import { readFile } from 'node:fs/promises'
|
|
4
|
-
import { createRequire } from 'node:module'
|
|
5
4
|
import { dirname, resolve } from 'node:path'
|
|
6
5
|
import { fileURLToPath } from 'node:url'
|
|
7
6
|
import { createHash } from 'node:crypto'
|
|
8
7
|
|
|
9
8
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
10
|
-
const require = createRequire(import.meta.url)
|
|
11
|
-
const jolt = dirname(require.resolve('@rafaelaugusto/jolt/package.json'))
|
|
12
|
-
const version = JSON.parse(await readFile(resolve(jolt, 'package.json'), 'utf8')).version
|
|
13
|
-
if (version !== '0.1.0-rc.17')
|
|
14
|
-
throw new Error(`This private adapter requires Jolt RC.17, found ${version}`)
|
|
15
9
|
await build({
|
|
16
10
|
entryPoints: [resolve(here, 'src/main.ts')],
|
|
17
11
|
outfile: resolve(here, 'dist/main.mjs'),
|
|
@@ -35,9 +29,6 @@ await build({
|
|
|
35
29
|
'#desktop-host': resolve(here, 'src/host.mjs'),
|
|
36
30
|
vue: resolve(here, 'node_modules/vue/dist/vue.runtime.esm-bundler.js'),
|
|
37
31
|
'vue-router': resolve(here, 'node_modules/vue-router/dist/vue-router.mjs'),
|
|
38
|
-
// Private, version-checked experiment. No public AppKit API is claimed.
|
|
39
|
-
'#jolt-track': resolve(jolt, 'dist/core/track.js'),
|
|
40
|
-
'#jolt-transition': resolve(jolt, 'dist/core/transition.js'),
|
|
41
32
|
},
|
|
42
33
|
plugins: [
|
|
43
34
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { nativeProps } from './contract.mjs'
|
|
2
2
|
import { mavis, midnight } from '@getcortexlabs/mavis-core'
|
|
3
|
-
import {
|
|
3
|
+
import { appKitMotion } from '@rafaelaugusto/jolt/appkit'
|
|
4
4
|
|
|
5
5
|
const rect = (x, y, width, height) => ({ origin: { x, y }, size: { width, height } })
|
|
6
6
|
const emit = (listener, ...args) => {
|
|
@@ -185,8 +185,12 @@ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}
|
|
|
185
185
|
} else node.native = MavisAppKitView.new()
|
|
186
186
|
node.content ??= node.native
|
|
187
187
|
node.native.wantsLayer = true
|
|
188
|
+
if (kind === 'reveal') {
|
|
189
|
+
node.motion = appKitMotion(node.native)
|
|
190
|
+
node.motion.animate('opacity', 0, { reducedMotion: true })
|
|
191
|
+
}
|
|
188
192
|
node.dispose = () => {
|
|
189
|
-
node.motion?.
|
|
193
|
+
node.motion?.dispose()
|
|
190
194
|
if (node.editor) node.editor.delegate = null
|
|
191
195
|
if (node.delegate) {
|
|
192
196
|
node.delegate.callback =
|
|
@@ -247,7 +251,7 @@ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}
|
|
|
247
251
|
if (node.kind === 'reveal') {
|
|
248
252
|
const shown = p.show !== false
|
|
249
253
|
if (node.shown !== shown) {
|
|
250
|
-
node.motion
|
|
254
|
+
if (!shown) node.motion.animate('opacity', 0, { reducedMotion: true })
|
|
251
255
|
node.shown = shown
|
|
252
256
|
view.hidden = !shown
|
|
253
257
|
node.pendingReveal = shown
|
|
@@ -332,7 +336,7 @@ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}
|
|
|
332
336
|
for (const node of nodes) {
|
|
333
337
|
if (node.pendingReveal && node.native.window) {
|
|
334
338
|
node.pendingReveal = false
|
|
335
|
-
node.
|
|
339
|
+
node.revealPlayback = node.motion.animate('opacity', 1, { reducedMotion: reduced() })
|
|
336
340
|
}
|
|
337
341
|
}
|
|
338
342
|
window.recalculateKeyViewLoop()
|
|
@@ -431,8 +435,7 @@ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}
|
|
|
431
435
|
if (reduced())
|
|
432
436
|
for (const node of nodes)
|
|
433
437
|
if (node.kind === 'reveal' && node.shown) {
|
|
434
|
-
node.motion
|
|
435
|
-
node.motion = opacityMotion(node.native, 1, 1, true)
|
|
438
|
+
node.revealPlayback = node.motion.animate('opacity', 1, { reducedMotion: true })
|
|
436
439
|
}
|
|
437
440
|
}
|
|
438
441
|
const accessibilityObserver =
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { windowsMotion } from '@rafaelaugusto/jolt/windows'
|
|
1
2
|
import { nativeProps } from './contract.mjs'
|
|
2
3
|
import { createRequire } from 'node:module'
|
|
3
4
|
import { mavis, midnight } from '@getcortexlabs/mavis-core'
|
|
@@ -90,7 +91,12 @@ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}
|
|
|
90
91
|
node.native.Content = node.content = new C.Canvas()
|
|
91
92
|
} else node.native = new C.Canvas()
|
|
92
93
|
node.content ??= node.native
|
|
94
|
+
if (kind === 'reveal') {
|
|
95
|
+
node.motion = windowsMotion(node.native, Windows)
|
|
96
|
+
node.motion.animate('opacity', 0, { reducedMotion: true })
|
|
97
|
+
}
|
|
93
98
|
node.dispose = () => {
|
|
99
|
+
node.motion?.dispose()
|
|
94
100
|
if (node.editor) {
|
|
95
101
|
node.editor.TextChanged = null
|
|
96
102
|
node.editor.KeyDown = null
|
|
@@ -133,8 +139,13 @@ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}
|
|
|
133
139
|
view.IsEnabled = !p.disabled && !p.loading
|
|
134
140
|
}
|
|
135
141
|
if (node.kind === 'reveal') {
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
const shown = p.show !== false
|
|
143
|
+
if (node.shown !== shown) {
|
|
144
|
+
if (!shown) node.motion.animate('opacity', 0, { reducedMotion: true })
|
|
145
|
+
node.shown = shown
|
|
146
|
+
view.Visibility = shown ? Xaml.Visibility.Visible : Xaml.Visibility.Collapsed
|
|
147
|
+
node.pendingReveal = shown
|
|
148
|
+
}
|
|
138
149
|
}
|
|
139
150
|
if (node.kind === 'screen')
|
|
140
151
|
view.VerticalScrollMode = p.scroll === false ? C.ScrollMode.Disabled : C.ScrollMode.Enabled
|
|
@@ -226,8 +237,14 @@ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}
|
|
|
226
237
|
scheduled = true
|
|
227
238
|
queueMicrotask(() => {
|
|
228
239
|
scheduled = false
|
|
229
|
-
if (
|
|
230
|
-
|
|
240
|
+
if (closed) return
|
|
241
|
+
layoutNode(root, 0, 0, root.native.ActualWidth || 780, root.native.ActualHeight || 620)
|
|
242
|
+
for (const node of nodes) {
|
|
243
|
+
if (node.pendingReveal && node.attached) {
|
|
244
|
+
node.pendingReveal = false
|
|
245
|
+
node.revealPlayback = node.motion.animate('opacity', 1)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
231
248
|
})
|
|
232
249
|
}
|
|
233
250
|
root.native.SizeChanged = layout
|
package/src/add-macos.mjs
DELETED
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
import { lstat, mkdir, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path'
|
|
3
|
-
import {
|
|
4
|
-
compileProject,
|
|
5
|
-
joltSwift,
|
|
6
|
-
macAppSettings,
|
|
7
|
-
startupPlan,
|
|
8
|
-
readAssets,
|
|
9
|
-
readShared,
|
|
10
|
-
} from '@getcortexlabs/mavis-compiler'
|
|
11
|
-
import { directoryMigration } from './migrate-directory.mjs'
|
|
12
|
-
import { migrateConfig, versions } from './capabilities.mjs'
|
|
13
|
-
import { detectPackageManager, packageCommands } from './package-manager.mjs'
|
|
14
|
-
|
|
15
|
-
const json = (value) => JSON.stringify(value, null, 2) + '\n'
|
|
16
|
-
const templates = new URL('../templates/', import.meta.url)
|
|
17
|
-
async function optional(path) {
|
|
18
|
-
try {
|
|
19
|
-
return await readFile(path, 'utf8')
|
|
20
|
-
} catch (error) {
|
|
21
|
-
if (error.code !== 'ENOENT') throw error
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async function safe(root, name) {
|
|
25
|
-
if (
|
|
26
|
-
typeof name !== 'string' ||
|
|
27
|
-
!name ||
|
|
28
|
-
isAbsolute(name) ||
|
|
29
|
-
name.includes('\\') ||
|
|
30
|
-
name.split('/').includes('..')
|
|
31
|
-
)
|
|
32
|
-
throw new Error('Mac target paths must stay inside the project.')
|
|
33
|
-
let current = root
|
|
34
|
-
for (const part of name.split('/').filter((part) => part && part !== '.')) {
|
|
35
|
-
current = join(current, part)
|
|
36
|
-
try {
|
|
37
|
-
if ((await lstat(current)).isSymbolicLink()) throw new Error(`Refusing symlink: ${name}`)
|
|
38
|
-
} catch (error) {
|
|
39
|
-
if (error.code !== 'ENOENT') throw error
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return current
|
|
43
|
-
}
|
|
44
|
-
async function copy(files, folder, destination, replace) {
|
|
45
|
-
const source = new URL(folder + '/', templates)
|
|
46
|
-
for (const entry of await readdir(source, { withFileTypes: true })) {
|
|
47
|
-
if (entry.isDirectory())
|
|
48
|
-
await copy(files, `${folder}/${entry.name}`, `${destination}/${entry.name}`, replace)
|
|
49
|
-
else {
|
|
50
|
-
const data = await readFile(new URL(entry.name, source))
|
|
51
|
-
files.set(
|
|
52
|
-
`${destination}/${entry.name}`,
|
|
53
|
-
/\.(ttf|icns)$/.test(entry.name) ? data : replace(data.toString('utf8')),
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const exact = (value) => typeof value === 'string' && /^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(value)
|
|
59
|
-
|
|
60
|
-
/** Preview adding a native SwiftUI host. Existing Web/native files are never rewritten. */
|
|
61
|
-
export async function planMacos(options = {}, cwd = process.cwd()) {
|
|
62
|
-
const root = resolve(cwd)
|
|
63
|
-
const original = new Map()
|
|
64
|
-
const read = async (name) => {
|
|
65
|
-
const text = await optional(await safe(root, name))
|
|
66
|
-
original.set(name, text)
|
|
67
|
-
return text
|
|
68
|
-
}
|
|
69
|
-
const pkg = JSON.parse(await read('package.json'))
|
|
70
|
-
const recorded = await read('mavis.config.json')
|
|
71
|
-
const prior = recorded ? migrateConfig(JSON.parse(recorded)) : {}
|
|
72
|
-
const manifests = [pkg]
|
|
73
|
-
for (const path of ['apps/web/package.json', 'apps/mobile/package.json']) {
|
|
74
|
-
const text = await read(path)
|
|
75
|
-
if (text) manifests.push(JSON.parse(text))
|
|
76
|
-
}
|
|
77
|
-
const dependencies = manifests.map((manifest) => ({
|
|
78
|
-
...manifest.devDependencies,
|
|
79
|
-
...manifest.dependencies,
|
|
80
|
-
}))
|
|
81
|
-
const web = dependencies.find((dep) => dep['@getcortexlabs/mavis-web'])
|
|
82
|
-
const native = dependencies.find((dep) => dep['@getcortexlabs/mavis'])
|
|
83
|
-
if (!web && !native)
|
|
84
|
-
throw new Error('--add-macos needs an existing Mavis Vue/Vite, Nuxt or NativeScript project.')
|
|
85
|
-
for (const dep of dependencies)
|
|
86
|
-
for (const name of [
|
|
87
|
-
'@getcortexlabs/mavis-core',
|
|
88
|
-
'@getcortexlabs/mavis-web',
|
|
89
|
-
'@getcortexlabs/mavis',
|
|
90
|
-
])
|
|
91
|
-
if (
|
|
92
|
-
dep[name] &&
|
|
93
|
-
![versions.mavis, `^${versions.mavis}`, `~${versions.mavis}`].includes(dep[name])
|
|
94
|
-
)
|
|
95
|
-
throw new Error(
|
|
96
|
-
`Align ${name} with this creator (${versions.mavis}) before adding Mac. No dependencies were changed.`,
|
|
97
|
-
)
|
|
98
|
-
const jolts = [
|
|
99
|
-
...new Set(
|
|
100
|
-
dependencies.flatMap((dep) =>
|
|
101
|
-
dep['@rafaelaugusto/jolt'] ? [dep['@rafaelaugusto/jolt']] : [],
|
|
102
|
-
),
|
|
103
|
-
),
|
|
104
|
-
]
|
|
105
|
-
const jolt = jolts[0] ?? prior.versions?.jolt
|
|
106
|
-
if (jolts.length > 1 || !exact(jolt) || jolt !== versions.jolt)
|
|
107
|
-
throw new Error(
|
|
108
|
-
`Pin every existing Jolt dependency to ${versions.jolt}, the JavaScript version supported by this creator. The separate SwiftUI package uses ${joltSwift.version}. Current: ${jolts.join(', ') || jolt || 'missing'}.`,
|
|
109
|
-
)
|
|
110
|
-
const manager =
|
|
111
|
-
options.packageManager ??
|
|
112
|
-
prior.packageManager ??
|
|
113
|
-
pkg.packageManager?.split('@')[0] ??
|
|
114
|
-
detectPackageManager()
|
|
115
|
-
const commands = packageCommands(manager)
|
|
116
|
-
const knownRoots = options.roots ?? prior.portability?.roots
|
|
117
|
-
let roots = knownRoots
|
|
118
|
-
if (!roots) {
|
|
119
|
-
roots = []
|
|
120
|
-
for (const candidate of ['shared', 'src/shared', 'app/shared']) {
|
|
121
|
-
try {
|
|
122
|
-
if ((await lstat(await safe(root, candidate))).isDirectory()) roots.push(candidate)
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if (error.code !== 'ENOENT') throw error
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (roots.length !== 1)
|
|
128
|
-
throw new Error(
|
|
129
|
-
'Choose --shared-root path (or comma-separated roots) to select existing shared sources.',
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
const sources = await readShared(root, { roots })
|
|
133
|
-
for (const [name, text] of sources) original.set(name, text)
|
|
134
|
-
const migration = await directoryMigration({
|
|
135
|
-
root,
|
|
136
|
-
sources,
|
|
137
|
-
enabled: options.migrateDirectory,
|
|
138
|
-
appearance: prior.theme === 'midnight' ? 'dark' : 'light',
|
|
139
|
-
read,
|
|
140
|
-
hostPaths: [
|
|
141
|
-
...(web
|
|
142
|
-
? [
|
|
143
|
-
[
|
|
144
|
-
`${web === dependencies[0] ? '' : 'apps/web/'}${web.nuxt ? 'app/plugins/mavis.ts' : 'src/main.ts'}`,
|
|
145
|
-
web.nuxt ? 'nuxt/app/plugins/mavis.ts' : 'vite/src/main.ts',
|
|
146
|
-
],
|
|
147
|
-
]
|
|
148
|
-
: []),
|
|
149
|
-
...(native
|
|
150
|
-
? [[`${native === dependencies[0] ? '' : 'apps/mobile/'}src/app.ts`, 'mobile/src/app.ts']]
|
|
151
|
-
: []),
|
|
152
|
-
],
|
|
153
|
-
})
|
|
154
|
-
for (const [name, text] of migration.files) if (sources.has(name)) sources.set(name, text)
|
|
155
|
-
let entry = options.entry ?? prior.portability?.entry
|
|
156
|
-
if (!entry) {
|
|
157
|
-
const preferred =
|
|
158
|
-
prior.example === 'directory'
|
|
159
|
-
? 'Directory.vue'
|
|
160
|
-
: prior.example === 'tasks'
|
|
161
|
-
? 'Tasks.lite.tsx'
|
|
162
|
-
: 'Welcome.vue'
|
|
163
|
-
entry = [...sources.keys()].find((name) => name.endsWith('/' + preferred))
|
|
164
|
-
if (!entry)
|
|
165
|
-
throw new Error('Choose --entry path/to/Screen.vue (or .lite.tsx); no screen was changed.')
|
|
166
|
-
}
|
|
167
|
-
const settings = macAppSettings(
|
|
168
|
-
prior.macos,
|
|
169
|
-
pkg.name?.replace(/^@[^/]+\//, '') ?? prior.name ?? 'Mavis',
|
|
170
|
-
)
|
|
171
|
-
if (settings.icon) await readFile(await safe(root, settings.icon))
|
|
172
|
-
const host = web ? (web.nuxt ? 'nuxt' : 'vite') : null
|
|
173
|
-
if (
|
|
174
|
-
web &&
|
|
175
|
-
prior.rendering &&
|
|
176
|
-
!(host === 'nuxt' ? ['ssr', 'ssg'] : ['client']).includes(prior.rendering)
|
|
177
|
-
)
|
|
178
|
-
throw new Error('The recorded Web rendering mode does not match the existing host.')
|
|
179
|
-
const targets = [web && 'web', native && 'native', 'macos'].filter(Boolean)
|
|
180
|
-
const config = {
|
|
181
|
-
...prior,
|
|
182
|
-
schemaVersion: 2,
|
|
183
|
-
name: prior.name ?? pkg.name ?? 'mavis-app',
|
|
184
|
-
targets,
|
|
185
|
-
apps: {
|
|
186
|
-
...prior.apps,
|
|
187
|
-
...(web
|
|
188
|
-
? {
|
|
189
|
-
web: {
|
|
190
|
-
toolkit: 'mavis-web',
|
|
191
|
-
framework: 'vue',
|
|
192
|
-
host,
|
|
193
|
-
rendering: prior.rendering ?? (host === 'nuxt' ? 'ssr' : 'client'),
|
|
194
|
-
},
|
|
195
|
-
}
|
|
196
|
-
: {}),
|
|
197
|
-
...(native
|
|
198
|
-
? { native: { toolkit: 'nativescript', framework: 'vue', platforms: ['ios', 'android'] } }
|
|
199
|
-
: {}),
|
|
200
|
-
macos: { toolkit: 'swiftui', framework: null },
|
|
201
|
-
},
|
|
202
|
-
framework: 'vue',
|
|
203
|
-
authoring: prior.authoring ?? (String(entry).endsWith('.lite.tsx') ? 'mitosis' : 'vue'),
|
|
204
|
-
mode: 'portable',
|
|
205
|
-
execution: 'generated',
|
|
206
|
-
web: host,
|
|
207
|
-
rendering: web ? (prior.rendering ?? (host === 'nuxt' ? 'ssr' : 'client')) : null,
|
|
208
|
-
theme: prior.theme ?? 'mavis',
|
|
209
|
-
example: prior.example ?? 'welcome',
|
|
210
|
-
packageManager: manager,
|
|
211
|
-
versions: { ...prior.versions, mavis: versions.mavis, compiler: versions.mavis, jolt },
|
|
212
|
-
macos: settings,
|
|
213
|
-
portability: { ...prior.portability, roots, entry, generate: ['macos'], existing: true },
|
|
214
|
-
}
|
|
215
|
-
const assets = await readAssets(root, {
|
|
216
|
-
folder: config.portability.assets ?? `${config.portability.sourceRoot ?? roots[0]}/assets`,
|
|
217
|
-
})
|
|
218
|
-
// Preview proves source compilation before touching an existing project.
|
|
219
|
-
const compiled = await compileProject(sources, {
|
|
220
|
-
root: entry,
|
|
221
|
-
theme: config.theme,
|
|
222
|
-
assets,
|
|
223
|
-
sourceRoot: config.portability.sourceRoot ?? roots[0],
|
|
224
|
-
destinations: config.portability.destinations,
|
|
225
|
-
})
|
|
226
|
-
const metadataFile = 'apps/macos/mavis.host.json'
|
|
227
|
-
const metadata = await read(metadataFile)
|
|
228
|
-
if (metadata) {
|
|
229
|
-
const state = JSON.parse(metadata)
|
|
230
|
-
if (
|
|
231
|
-
state.generator !== 'create-mavis' ||
|
|
232
|
-
JSON.stringify(prior.portability?.roots) !== JSON.stringify(roots) ||
|
|
233
|
-
prior.portability?.entry !== entry
|
|
234
|
-
)
|
|
235
|
-
throw new Error(
|
|
236
|
-
'Mac is already configured with different source choices. Edit mavis.config.json explicitly; existing files were preserved.',
|
|
237
|
-
)
|
|
238
|
-
return {
|
|
239
|
-
root,
|
|
240
|
-
manager,
|
|
241
|
-
entry,
|
|
242
|
-
roots,
|
|
243
|
-
files: new Map(),
|
|
244
|
-
original,
|
|
245
|
-
config,
|
|
246
|
-
alreadyAdded: true,
|
|
247
|
-
components: compiled.model.components.length,
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
try {
|
|
251
|
-
await lstat(await safe(root, 'apps/macos'))
|
|
252
|
-
throw new Error('apps/macos already exists. Existing files were preserved.')
|
|
253
|
-
} catch (error) {
|
|
254
|
-
if (error.code !== 'ENOENT') throw error
|
|
255
|
-
}
|
|
256
|
-
const scripts = {
|
|
257
|
-
'generate:macos': 'node scripts/generate-macos.mjs',
|
|
258
|
-
macos: 'node scripts/macos.mjs run',
|
|
259
|
-
'build:macos': 'node scripts/macos.mjs build',
|
|
260
|
-
}
|
|
261
|
-
for (const [name, command] of Object.entries(scripts))
|
|
262
|
-
if (pkg.scripts?.[name] && pkg.scripts[name] !== command)
|
|
263
|
-
throw new Error(`Script conflict: ${name}. Existing scripts were preserved.`)
|
|
264
|
-
const files = new Map(migration.files)
|
|
265
|
-
const replace = (text) =>
|
|
266
|
-
text
|
|
267
|
-
.replaceAll('__MAVIS_NAME__', settings.name)
|
|
268
|
-
.replaceAll('__MAVIS_APPID__', 'app')
|
|
269
|
-
.replaceAll('__MAVIS_APPEARANCE__', config.theme === 'midnight' ? 'dark' : 'light')
|
|
270
|
-
.replaceAll('__MAVIS_MAC_MIN_WIDTH__', String(settings.minWidth))
|
|
271
|
-
.replaceAll('__MAVIS_MAC_DEFAULT_WIDTH__', String(Math.max(860, settings.minWidth)))
|
|
272
|
-
.replaceAll('__MAVIS_MAC_WIDTH__', '1120')
|
|
273
|
-
.replaceAll('__MAVIS_JOLT_SWIFT__', joltSwift.version)
|
|
274
|
-
await copy(files, 'macos/native', 'apps/macos', replace)
|
|
275
|
-
const appPath = 'apps/macos/Sources/MavisDesktop/App.swift'
|
|
276
|
-
let app = files
|
|
277
|
-
.get(appPath)
|
|
278
|
-
.replace(/WindowGroup\(".*"\)/, 'WindowGroup(MavisAppConfiguration.name)')
|
|
279
|
-
.replace(
|
|
280
|
-
'.frame(minWidth: ' + settings.minWidth + ', minHeight: 640)',
|
|
281
|
-
'.frame(minWidth: MavisAppConfiguration.minWidth, minHeight: MavisAppConfiguration.minHeight)',
|
|
282
|
-
)
|
|
283
|
-
const directory =
|
|
284
|
-
compiled.model.services.length === 1 &&
|
|
285
|
-
compiled.model.services[0].name === 'DirectoryStorage' &&
|
|
286
|
-
compiled.model.modules.some((module) =>
|
|
287
|
-
module.stores.some((store) => store.name === 'Directory'),
|
|
288
|
-
)
|
|
289
|
-
if (compiled.model.services.length && !directory)
|
|
290
|
-
throw new Error(
|
|
291
|
-
`The shared entry needs host services: ${compiled.model.services.map((service) => service.name).join(', ')}. Add their Swift implementations explicitly before generation; --add-macos cannot invent their behavior.`,
|
|
292
|
-
)
|
|
293
|
-
if (directory) {
|
|
294
|
-
await copy(files, 'directory/macos', 'apps/macos/Sources/MavisDesktop', replace)
|
|
295
|
-
app = app.replace(
|
|
296
|
-
'MavisEntry()',
|
|
297
|
-
'MavisEntry(services: MavisServices(directoryStorage: UserDefaultsDirectoryStorage()))',
|
|
298
|
-
)
|
|
299
|
-
if (!config.portability.startup)
|
|
300
|
-
config.portability.startup = [{ store: 'Directory', action: 'restore' }]
|
|
301
|
-
}
|
|
302
|
-
startupPlan(compiled.model, config.portability.startup)
|
|
303
|
-
files.set(appPath, app)
|
|
304
|
-
const wrapper = await readFile(new URL('macos/scripts/generate.mjs', templates), 'utf8')
|
|
305
|
-
files.set('scripts/generate-macos.mjs', wrapper)
|
|
306
|
-
const launcher = await readFile(new URL('macos/scripts/macos.mjs', templates), 'utf8')
|
|
307
|
-
files.set(
|
|
308
|
-
'scripts/macos-manifest.mjs',
|
|
309
|
-
await readFile(new URL('macos/scripts/macos-manifest.mjs', templates), 'utf8'),
|
|
310
|
-
)
|
|
311
|
-
files.set(
|
|
312
|
-
'scripts/macos.mjs',
|
|
313
|
-
replace(launcher).replace("['scripts/generate.mjs']", "['scripts/generate-macos.mjs']"),
|
|
314
|
-
)
|
|
315
|
-
files.set(
|
|
316
|
-
metadataFile,
|
|
317
|
-
json({ schemaVersion: 1, generator: 'create-mavis', compiler: versions.mavis }),
|
|
318
|
-
)
|
|
319
|
-
files.set(
|
|
320
|
-
'apps/macos/README.md',
|
|
321
|
-
`# ${settings.name} for Mac\n\nThis SwiftUI target reads existing shared sources (${roots.join(', ')}), starting at \`${entry}\`. Web and NativeScript sources, routes and build configuration remain in place.\n\n\`\`\`sh\n${commands.install}\n${commands.run('generate:macos')}\n${commands.run('build:macos')}\n${commands.run('macos')}\n\`\`\`\n\nThe compiler is a pinned package; update it with Mavis. \`mavis.config.json\` controls the source roots/entry and \`macos.name\`, \`bundleId\`, \`icon\` (.icns), \`minWidth\` and \`minHeight\`. Configure app-owned services in \`Sources/MavisDesktop/App.swift\`. ${directory ? 'Directory uses the same JSON array and mavis:directory key in UserDefaults; restore runs once after mounting each entry identity.' : ''}\n\nRequires macOS 14+ and Xcode. This builds an unsigned development app. Developer ID signing, provisioning and notarization are separate distribution steps; no credentials or signing settings are generated.\n`,
|
|
322
|
-
)
|
|
323
|
-
pkg.scripts = { ...pkg.scripts, ...scripts }
|
|
324
|
-
pkg.devDependencies = { ...pkg.devDependencies, '@getcortexlabs/mavis-compiler': versions.mavis }
|
|
325
|
-
files.set('package.json', json(pkg))
|
|
326
|
-
files.set('mavis.config.json', json(config))
|
|
327
|
-
for (const name of files.keys()) {
|
|
328
|
-
if (original.has(name)) continue
|
|
329
|
-
if ((await read(name)) !== undefined)
|
|
330
|
-
throw new Error(`File conflict: ${name}. Existing files were preserved.`)
|
|
331
|
-
}
|
|
332
|
-
return {
|
|
333
|
-
root,
|
|
334
|
-
manager,
|
|
335
|
-
entry,
|
|
336
|
-
roots,
|
|
337
|
-
files,
|
|
338
|
-
original,
|
|
339
|
-
config,
|
|
340
|
-
alreadyAdded: false,
|
|
341
|
-
components: compiled.model.components.length,
|
|
342
|
-
migration: migration.diffs,
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/** Optimistic transaction: refuse concurrent edits; roll back only bytes written by this plan. */
|
|
347
|
-
export async function applyMacos(plan, { signal } = {}) {
|
|
348
|
-
if (plan.alreadyAdded) return
|
|
349
|
-
const written = []
|
|
350
|
-
try {
|
|
351
|
-
for (const [name, expected] of plan.original) {
|
|
352
|
-
if ((await optional(await safe(plan.root, name))) !== expected)
|
|
353
|
-
throw new Error(`${name} changed after the preview. Run --add-macos again.`)
|
|
354
|
-
}
|
|
355
|
-
for (const [name, data] of plan.files) {
|
|
356
|
-
signal?.throwIfAborted()
|
|
357
|
-
const path = await safe(plan.root, name)
|
|
358
|
-
await mkdir(dirname(path), { recursive: true })
|
|
359
|
-
if (plan.original.get(name) === undefined) await writeFile(path, data, { flag: 'wx' })
|
|
360
|
-
else {
|
|
361
|
-
if ((await optional(path)) !== plan.original.get(name))
|
|
362
|
-
throw new Error(`${name} changed during creation.`)
|
|
363
|
-
const staging = `${path}.mavis-${process.pid}.tmp`
|
|
364
|
-
try {
|
|
365
|
-
await writeFile(staging, data, { flag: 'wx' })
|
|
366
|
-
await rename(staging, path)
|
|
367
|
-
} finally {
|
|
368
|
-
await rm(staging, { force: true })
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
written.push(name)
|
|
372
|
-
}
|
|
373
|
-
} catch (error) {
|
|
374
|
-
for (const name of written.reverse()) {
|
|
375
|
-
const path = join(plan.root, name)
|
|
376
|
-
const current = await readFile(path).catch(() => null)
|
|
377
|
-
if (!current?.equals(Buffer.from(plan.files.get(name)))) continue
|
|
378
|
-
const prior = plan.original.get(name)
|
|
379
|
-
if (prior === undefined) await rm(path)
|
|
380
|
-
else await writeFile(path, prior)
|
|
381
|
-
for (let folder = dirname(path); folder !== plan.root; folder = dirname(folder))
|
|
382
|
-
await rmdir(folder).catch(() => {})
|
|
383
|
-
}
|
|
384
|
-
throw error
|
|
385
|
-
}
|
|
386
|
-
}
|