@getcortexlabs/create-mavis 0.1.0-rc.13 → 0.1.0-rc.14
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 +26 -5
- package/package.json +4 -2
- package/src/adapters.mjs +7 -0
- package/src/add-macos.mjs +386 -0
- package/src/capabilities.mjs +78 -57
- package/src/cli.mjs +86 -4
- package/src/doctor.mjs +100 -18
- package/src/macos-capabilities.generated.mjs +4190 -0
- package/src/macos.mjs +147 -29
- package/src/migrate-directory.mjs +121 -0
- package/src/portability.mjs +108 -5
- package/src/scaffold.mjs +21 -2
- package/src/ui.mjs +21 -12
- 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/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/macos.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { versions as v, configOf, targetLabel } from './presets.mjs'
|
|
2
2
|
import { packageCommands } from './package-manager.mjs'
|
|
3
|
-
import { joltSwift } from '
|
|
3
|
+
import { joltSwift } from '@getcortexlabs/mavis-compiler'
|
|
4
4
|
|
|
5
5
|
const json = (value) => `${JSON.stringify(value, null, 2)}\n`
|
|
6
6
|
|
|
@@ -15,10 +15,12 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
15
15
|
const mac = targets.includes('macos')
|
|
16
16
|
const commands = packageCommands(preset.packageManager)
|
|
17
17
|
const tasks = preset.example === 'tasks'
|
|
18
|
+
const directory = preset.example === 'directory'
|
|
19
|
+
const nuxt = preset.web === 'nuxt'
|
|
18
20
|
// The screen every app opens. Tasks is a list beside its detail, so it gets a wider page.
|
|
19
|
-
const entry = tasks ? 'Tasks' : 'Welcome'
|
|
21
|
+
const entry = directory ? 'Directory' : tasks ? 'Tasks' : 'Welcome'
|
|
20
22
|
const hosts = [
|
|
21
|
-
web && 'Vue on the Web',
|
|
23
|
+
web && (nuxt ? `Nuxt (${preset.rendering}) on the Web` : 'Vue on the Web'),
|
|
22
24
|
native && 'NativeScript on iOS and Android',
|
|
23
25
|
mac && 'SwiftUI on the Mac',
|
|
24
26
|
].filter(Boolean)
|
|
@@ -31,7 +33,6 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
31
33
|
TARGETS: targetLabel(targets),
|
|
32
34
|
HOSTS: hosts.join(' · '),
|
|
33
35
|
JOLT_SWIFT: joltSwift.version,
|
|
34
|
-
ROOT: entry,
|
|
35
36
|
WEB_WIDTH: tasks ? '1120px' : '760px',
|
|
36
37
|
MAC_WIDTH: tasks ? '1120' : '820',
|
|
37
38
|
MAC_MIN_WIDTH: tasks ? '760' : '640',
|
|
@@ -42,21 +43,55 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
42
43
|
await copyTemplate(files, 'macos/root', '', replacements)
|
|
43
44
|
await copyTemplate(
|
|
44
45
|
files,
|
|
45
|
-
tasks ? 'macos/examples/tasks/shared' : 'macos/shared',
|
|
46
|
+
directory ? 'directory/shared' : tasks ? 'macos/examples/tasks/shared' : 'macos/shared',
|
|
46
47
|
'shared',
|
|
47
48
|
replacements,
|
|
48
49
|
)
|
|
49
50
|
await copyTemplate(files, 'macos/scripts', 'scripts', replacements)
|
|
50
|
-
|
|
51
|
+
for (const path of files.keys()) if (path.startsWith('scripts/portable/')) files.delete(path)
|
|
52
|
+
if (!mac) {
|
|
53
|
+
files.delete('scripts/macos.mjs')
|
|
54
|
+
files.delete('scripts/macos-manifest.mjs')
|
|
55
|
+
}
|
|
51
56
|
|
|
52
57
|
const common = { private: true, version: '0.0.0', engines: { node: '>=22.16' } }
|
|
53
58
|
const generate = 'node scripts/generate.mjs'
|
|
54
59
|
const builds = []
|
|
55
60
|
const scripts = { generate }
|
|
56
61
|
if (web) {
|
|
57
|
-
await copyTemplate(files, 'macos/web', 'apps/web', replacements)
|
|
62
|
+
await copyTemplate(files, nuxt ? 'nuxt' : 'macos/web', 'apps/web', replacements)
|
|
63
|
+
if (nuxt && !directory) {
|
|
64
|
+
await copyTemplate(files, 'macos/web/src', 'apps/web/app', replacements)
|
|
65
|
+
files.set('apps/web/app/assets/main.css', files.get('apps/web/app/style.css'))
|
|
66
|
+
for (const name of ['main.js', 'mavis.js', 'style.css']) files.delete(`apps/web/app/${name}`)
|
|
67
|
+
files.set(
|
|
68
|
+
'apps/web/app/app.vue',
|
|
69
|
+
`<script setup lang="ts">
|
|
70
|
+
import Root, { screen } from './generated/entry'
|
|
71
|
+
</script>
|
|
72
|
+
<template><Root v-if="screen" /><main v-else class="mavis-page"><Root /></main></template>
|
|
73
|
+
`,
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
if (directory) {
|
|
77
|
+
await copyTemplate(files, `directory/${nuxt ? 'nuxt' : 'vite'}`, 'apps/web', replacements)
|
|
78
|
+
await copyTemplate(
|
|
79
|
+
files,
|
|
80
|
+
'directory/host',
|
|
81
|
+
`apps/web/${nuxt ? 'app/utils' : 'src'}`,
|
|
82
|
+
replacements,
|
|
83
|
+
)
|
|
84
|
+
if (!nuxt) {
|
|
85
|
+
files.delete('apps/web/src/main.js')
|
|
86
|
+
files.set(
|
|
87
|
+
'apps/web/index.html',
|
|
88
|
+
files.get('apps/web/index.html').replace('/src/main.js', '/src/main.ts'),
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
58
92
|
scripts['dev:web'] = `${generate} && ${commands.run('dev', 'apps/web')}`
|
|
59
|
-
scripts['build:web'] =
|
|
93
|
+
scripts['build:web'] =
|
|
94
|
+
`${generate} && ${commands.run(nuxt && preset.rendering === 'ssg' ? 'generate' : 'build', 'apps/web')}`
|
|
60
95
|
builds.push('build:web')
|
|
61
96
|
files.set(
|
|
62
97
|
'apps/web/package.json',
|
|
@@ -64,17 +99,30 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
64
99
|
...common,
|
|
65
100
|
name: `${preset.name}-web`,
|
|
66
101
|
type: 'module',
|
|
67
|
-
scripts:
|
|
102
|
+
scripts: nuxt
|
|
103
|
+
? {
|
|
104
|
+
dev: 'nuxt dev',
|
|
105
|
+
build: 'nuxt build',
|
|
106
|
+
generate: 'nuxt generate',
|
|
107
|
+
preview: 'nuxt preview',
|
|
108
|
+
typecheck: 'nuxt typecheck',
|
|
109
|
+
postinstall: 'nuxt prepare',
|
|
110
|
+
}
|
|
111
|
+
: { dev: 'vite', build: 'vite build', preview: 'vite preview' },
|
|
68
112
|
dependencies: {
|
|
69
113
|
'@getcortexlabs/mavis-core': v.mavis,
|
|
70
114
|
'@getcortexlabs/mavis-web': v.mavis,
|
|
71
115
|
'@rafaelaugusto/jolt': v.jolt,
|
|
72
116
|
vue: v.vue,
|
|
117
|
+
'@vue/runtime-core': v.vue,
|
|
118
|
+
...(nuxt ? { nuxt: v.nuxt } : {}),
|
|
119
|
+
...(directory && !nuxt ? { 'vue-router': v.router } : {}),
|
|
73
120
|
},
|
|
74
121
|
devDependencies: {
|
|
75
122
|
typescript: v.typescript,
|
|
76
|
-
|
|
77
|
-
'@
|
|
123
|
+
'vue-tsc': v.vueTsc,
|
|
124
|
+
'@types/node': v.nodeTypes,
|
|
125
|
+
...(!nuxt ? { vite: v.vite, '@vitejs/plugin-vue': v.vuePlugin } : {}),
|
|
78
126
|
},
|
|
79
127
|
}),
|
|
80
128
|
)
|
|
@@ -82,6 +130,10 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
82
130
|
if (native) {
|
|
83
131
|
await copyTemplate(files, 'mobile', 'apps/mobile', replacements)
|
|
84
132
|
await copyTemplate(files, 'macos/mobile', 'apps/mobile', replacements)
|
|
133
|
+
if (directory) {
|
|
134
|
+
await copyTemplate(files, 'directory/mobile', 'apps/mobile', replacements)
|
|
135
|
+
await copyTemplate(files, 'directory/host', 'apps/mobile/src', replacements)
|
|
136
|
+
}
|
|
85
137
|
// The generated screens are the app's shared code; the TSX sources stay out of vue-tsc.
|
|
86
138
|
files.set(
|
|
87
139
|
'apps/mobile/tsconfig.json',
|
|
@@ -124,6 +176,7 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
124
176
|
'@getcortexlabs/mavis': v.mavis,
|
|
125
177
|
'@nativescript/core': v.nativeCore,
|
|
126
178
|
'nativescript-vue': v.nativeVue,
|
|
179
|
+
...(directory ? { 'vue-router-ns': v.nativeRouter } : {}),
|
|
127
180
|
},
|
|
128
181
|
devDependencies: {
|
|
129
182
|
'@nativescript/android': v.android,
|
|
@@ -139,10 +192,51 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
139
192
|
}
|
|
140
193
|
if (mac) {
|
|
141
194
|
await copyTemplate(files, 'macos/native', 'apps/macos', replacements)
|
|
195
|
+
if (directory) {
|
|
196
|
+
await copyTemplate(files, 'directory/macos', 'apps/macos/Sources/MavisDesktop', replacements)
|
|
197
|
+
const app = 'apps/macos/Sources/MavisDesktop/App.swift'
|
|
198
|
+
files.set(
|
|
199
|
+
app,
|
|
200
|
+
files
|
|
201
|
+
.get(app)
|
|
202
|
+
.replace(
|
|
203
|
+
'MavisEntry()',
|
|
204
|
+
'MavisEntry(services: MavisServices(directoryStorage: UserDefaultsDirectoryStorage()))',
|
|
205
|
+
),
|
|
206
|
+
)
|
|
207
|
+
}
|
|
142
208
|
scripts.macos = 'node scripts/macos.mjs run'
|
|
143
209
|
scripts['build:macos'] = 'node scripts/macos.mjs build'
|
|
144
210
|
builds.push('build:macos')
|
|
145
211
|
}
|
|
212
|
+
// The generated theme module tracks configuration edits without rewriting app hosts.
|
|
213
|
+
for (const path of [
|
|
214
|
+
web &&
|
|
215
|
+
(nuxt
|
|
216
|
+
? 'apps/web/app/plugins/mavis.ts'
|
|
217
|
+
: directory
|
|
218
|
+
? 'apps/web/src/main.ts'
|
|
219
|
+
: 'apps/web/src/main.js'),
|
|
220
|
+
native && 'apps/mobile/src/app.ts',
|
|
221
|
+
].filter(Boolean)) {
|
|
222
|
+
const nuxtHost = path.includes('/plugins/')
|
|
223
|
+
let source = files
|
|
224
|
+
.get(path)
|
|
225
|
+
.replace(/, mavis, midnight/g, '')
|
|
226
|
+
.replace(/^import \{ mavis, midnight \} from '@getcortexlabs\/mavis-core'\n/m, '')
|
|
227
|
+
.replace(/^ (?:mavis|midnight),\n/gm, '')
|
|
228
|
+
.replace(/theme: mavis/g, 'theme: appTheme')
|
|
229
|
+
.replace(/darkTheme: midnight/g, 'darkTheme: appDarkTheme')
|
|
230
|
+
if (nuxtHost)
|
|
231
|
+
source = source
|
|
232
|
+
.replace(/: '(?:light|dark)',\n/, ": appAppearance === 'dark' ? 'dark' : 'light',\n")
|
|
233
|
+
.replace(/: 'system'/g, ': appAppearance')
|
|
234
|
+
else source = source.replace(/appearance: '(?:light|dark)'/g, 'appearance: appAppearance')
|
|
235
|
+
files.set(
|
|
236
|
+
path,
|
|
237
|
+
`import { appTheme, appDarkTheme, appAppearance } from '${nuxtHost ? '../' : './'}generated/theme'\n${source}`,
|
|
238
|
+
)
|
|
239
|
+
}
|
|
146
240
|
scripts.build = builds.map((name) => commands.run(name)).join(' && ')
|
|
147
241
|
|
|
148
242
|
files.set(
|
|
@@ -155,20 +249,35 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
155
249
|
...(web && preset.packageManager === 'yarn'
|
|
156
250
|
? {
|
|
157
251
|
resolutions: { vue: v.vue, '@vue/runtime-core': v.vue },
|
|
158
|
-
dependenciesMeta: {
|
|
252
|
+
dependenciesMeta: {
|
|
253
|
+
esbuild: { built: true },
|
|
254
|
+
...(nuxt ? { 'unrs-resolver': { built: true } } : {}),
|
|
255
|
+
},
|
|
159
256
|
}
|
|
160
257
|
: {}),
|
|
161
258
|
scripts,
|
|
162
|
-
// The compiler reads theme tokens from Mavis core
|
|
259
|
+
// The compiler reads theme tokens from Mavis core, type-checks with TypeScript and parses
|
|
260
|
+
// shared Vue files with Vue's own compiler.
|
|
163
261
|
dependencies: { '@getcortexlabs/mavis-core': v.mavis },
|
|
164
|
-
devDependencies: { typescript: v.typescript },
|
|
262
|
+
devDependencies: { '@getcortexlabs/mavis-compiler': v.mavis, typescript: v.typescript },
|
|
165
263
|
}),
|
|
166
264
|
)
|
|
167
265
|
files.set(
|
|
168
266
|
'mavis.config.json',
|
|
169
267
|
json({
|
|
170
268
|
...configOf(preset),
|
|
171
|
-
|
|
269
|
+
macos: {
|
|
270
|
+
name: preset.name,
|
|
271
|
+
bundleId: `com.mavis.${preset.name.replaceAll('-', '')}`,
|
|
272
|
+
minWidth: tasks ? 760 : 640,
|
|
273
|
+
minHeight: 640,
|
|
274
|
+
},
|
|
275
|
+
portability: {
|
|
276
|
+
roots: ['shared'],
|
|
277
|
+
mode: directory ? 'shared-vue-experimental' : 'shared-tsx-experimental',
|
|
278
|
+
entry,
|
|
279
|
+
...(directory ? { startup: [{ store: 'Directory', action: 'restore' }] } : {}),
|
|
280
|
+
},
|
|
172
281
|
}),
|
|
173
282
|
)
|
|
174
283
|
files.set(
|
|
@@ -179,10 +288,15 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
179
288
|
'.pnpm-store/',
|
|
180
289
|
'.yarn/',
|
|
181
290
|
'dist/',
|
|
291
|
+
'.nuxt/',
|
|
292
|
+
'.output/',
|
|
293
|
+
'apps/web/app/generated/',
|
|
182
294
|
'platforms/',
|
|
183
295
|
'hooks/',
|
|
184
296
|
'apps/macos/.build/',
|
|
185
297
|
'apps/web/src/generated/',
|
|
298
|
+
'apps/web/app/generated/',
|
|
299
|
+
'apps/web/public/~/',
|
|
186
300
|
'apps/mobile/src/generated/',
|
|
187
301
|
'apps/macos/Sources/MavisDesktop/Generated/',
|
|
188
302
|
'mavis-env.d.ts',
|
|
@@ -194,7 +308,7 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
194
308
|
if (preset.packageManager === 'pnpm') {
|
|
195
309
|
files.set(
|
|
196
310
|
'pnpm-workspace.yaml',
|
|
197
|
-
`packages:${web ? '\n - apps/web' : ' []'}\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n`,
|
|
311
|
+
`packages:${web ? '\n - apps/web' : ' []'}\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n${nuxt ? ' "unrs-resolver": true\n' : ''}`,
|
|
198
312
|
)
|
|
199
313
|
if (native)
|
|
200
314
|
files.set(
|
|
@@ -213,6 +327,7 @@ export async function macosFiles(preset, files, copyTemplate) {
|
|
|
213
327
|
}
|
|
214
328
|
|
|
215
329
|
function readme(preset, commands, { web, native, mac, entry }) {
|
|
330
|
+
const directory = preset.example === 'directory'
|
|
216
331
|
const start = [
|
|
217
332
|
native ? commands.setup(true) : commands.install,
|
|
218
333
|
...(web ? [commands.run('dev:web')] : []),
|
|
@@ -220,7 +335,10 @@ function readme(preset, commands, { web, native, mac, entry }) {
|
|
|
220
335
|
...(mac ? [commands.run('macos')] : []),
|
|
221
336
|
]
|
|
222
337
|
const folders = [
|
|
223
|
-
web &&
|
|
338
|
+
web &&
|
|
339
|
+
(preset.web === 'nuxt'
|
|
340
|
+
? `- apps/web: Nuxt (${preset.rendering}) with Mavis Web. Generated screens in apps/web/app/generated/.`
|
|
341
|
+
: '- apps/web: Vue + Vite with Mavis Web. Generated screens in apps/web/src/generated/.'),
|
|
224
342
|
native &&
|
|
225
343
|
'- apps/mobile: NativeScript-Vue for iOS and Android with Mavis. Generated screens in apps/mobile/src/generated/.',
|
|
226
344
|
mac &&
|
|
@@ -248,26 +366,26 @@ ${hosts.join(' ')}
|
|
|
248
366
|
|
|
249
367
|
## Edit once
|
|
250
368
|
|
|
251
|
-
Screens live in **shared/**: each
|
|
369
|
+
Screens live in **shared/**: ${directory ? 'Vue screens and typed stores are the same files on every target.' : 'each `Name.lite.tsx` exports one component, and lowercase `.ts` files hold shared types, values, calculations and stores.'} \`${entry}\` is the screen every app opens (\`portability.entry\` in mavis.config.json). Run \`${commands.run('generate')}\` after editing; the start and build commands generate first. The Mavis compiler type-checks the sources with TypeScript, then writes each target's files:
|
|
252
370
|
|
|
253
371
|
${folders.join('\n')}
|
|
254
372
|
|
|
255
|
-
Generated folders are replaced on every run and kept out of Git; don't edit them. The sources use Mitosis
|
|
373
|
+
Generated folders are replaced on every run and kept out of Git; don't edit them. ${directory ? 'The directory uses shared Vue screens, a typed store and one route table. Host adapters persist the same `mavis:directory` JSON array in localStorage, ApplicationSettings and UserDefaults. App.swift only supplies the storage implementation; the generated entry creates its store.' : 'The sources use Mitosis’s component format (`useStore`, `useRef`, `Show`, `For`), but Mitosis itself is not installed.'} Each app keeps its own state.
|
|
374
|
+
|
|
375
|
+
${directory ? 'On Mac, `portability.startup` lists the shared store actions to run after the entry first appears. The generated entry owns this startup once per window identity, across renders and route changes. Startup actions take no arguments, return no value and handle their own errors. This setting is Mac-only; Web and NativeScript keep their bootstrap in `apps/web/src/main.ts` and `apps/mobile/src/app.ts`, after the router/app is ready. For Nuxt the bootstrap is in `apps/web/app/plugins/mavis.ts` and restore waits for hydration.\n\n' : ''}A screen can also be a Vue file, \`shared/Name.vue\`, next to the TSX ones: the Web and NativeScript apps run it as written, importing Mavis from \`#mavis\`, and the Mac gets SwiftUI generated from it. It uses \`<script setup lang="ts">\` with \`ref\`, \`computed\`, functions, \`defineProps\`, \`withDefaults\`, \`defineEmits\` and \`useMavisPlatform()\`, and a template of the same primitives with \`v-if\`, \`v-for\`, \`v-model\` and \`MReveal\`. A Vue file shows other Vue files, and a TSX file other TSX files. The guide lists the subset: https://mavis-ui.getcortexlabs.com/guide/macos-experimental#shared-vue-files
|
|
256
376
|
|
|
257
|
-
What the sources can use:
|
|
258
|
-
-
|
|
259
|
-
-
|
|
260
|
-
-
|
|
261
|
-
-
|
|
262
|
-
-
|
|
263
|
-
- In actions and event handlers: =, +=, -=, ++ and --, if/else, return, push, unshift and splice, and calls to other actions and callbacks.
|
|
264
|
-
- Show with else, and For with a key field. \`<Show when={…} animate>\` reveals and hides its content, and \`<For each={…} animate>\` animates rows that enter, leave or move.
|
|
377
|
+
What the shared sources can use:
|
|
378
|
+
- Vue SFC and TSX components, typed props and callbacks, slots, composition, conditional content and keyed lists. Unsupported syntax reports file:line:column before generation replaces any output.
|
|
379
|
+
- Shared typed modules, pure calculations, optional records, and app stores built with Vue ref/computed/readonly and injection. The Mac generates observable stores and receives typed services from its host.
|
|
380
|
+
- Async store actions and callbacks, loading/error state, scalar watchers, mount/unmount hooks and explicit cancellation cleanup. Shared code must declare cancellation and stale-result guards; hiding a view is not automatically an unmount.
|
|
381
|
+
- A shared route table and navigation actions, including parameters and deep links, with generated native navigation on the Mac.
|
|
382
|
+
- Built-in and statically declared custom themes, scoped providers, responsive layout and the supported component families. Each component still has explicit limits; matching a component name does not imply every prop or browser API is portable.
|
|
265
383
|
|
|
266
|
-
|
|
384
|
+
Read the [Mac guide and supported subset](https://mavis-ui.getcortexlabs.com/guide/macos-experimental) and the [component capability matrix](https://mavis-ui.getcortexlabs.com/guide/macos-capabilities), inspect \`create-mavis --capabilities\`, and run \`create-mavis --check-portability\` from the project before adopting code. Network access, persistence, platform formatting, clipboard and opening URLs belong to typed host services. There is no JavaScript runtime or WebView in the generated Mac app.
|
|
267
385
|
|
|
268
386
|
## Motion
|
|
269
387
|
|
|
270
|
-
Buttons and cards press, animated Show content enters and leaves, and animated lists move through Jolt on every target: Mavis Web and Mavis on NativeScript run Jolt, and the Mac uses JoltSwiftUI.
|
|
388
|
+
Buttons and cards press, animated Show content enters and leaves, and animated lists move through Jolt on every target: Mavis Web and Mavis on NativeScript run Jolt, and the Mac uses JoltSwiftUI. Motion uses the shared contracts and the current Jolt integration for each target. Components and explicit motion surfaces/regions own and dispose their presentation resources. Consult the Mac guide for platform-specific motion limits and Reduce Motion behavior.
|
|
271
389
|
|
|
272
390
|
## Build
|
|
273
391
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises'
|
|
3
|
+
import { dirname, join, relative, sep } from 'node:path'
|
|
4
|
+
|
|
5
|
+
const templates = new URL('../templates/', import.meta.url)
|
|
6
|
+
const hash = (text) => createHash('sha256').update(text).digest('hex')
|
|
7
|
+
const posix = (path) => path.split(sep).join('/')
|
|
8
|
+
const ignored = new Set([
|
|
9
|
+
'node_modules',
|
|
10
|
+
'.git',
|
|
11
|
+
'.nuxt',
|
|
12
|
+
'.output',
|
|
13
|
+
'.build',
|
|
14
|
+
'dist',
|
|
15
|
+
'platforms',
|
|
16
|
+
'hooks',
|
|
17
|
+
'artifacts',
|
|
18
|
+
])
|
|
19
|
+
const refusal = (name) =>
|
|
20
|
+
new Error(
|
|
21
|
+
`Directory migration stopped: ${name} differs from the published RC.13 template. Preserve your changes and migrate its typed storage adapter manually; no files changed.`,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
/** Only the exact published reference app is rewritten, and only by explicit opt-in. */
|
|
25
|
+
export async function directoryMigration({ root, sources, enabled, hostPaths, appearance, read }) {
|
|
26
|
+
const manifest = JSON.parse(
|
|
27
|
+
await readFile(new URL('migrations/directory-rc13.json', templates), 'utf8'),
|
|
28
|
+
)
|
|
29
|
+
const store = [...sources.keys()].find((name) => name.endsWith('/directory-store.ts'))
|
|
30
|
+
const files = new Map(),
|
|
31
|
+
diffs = []
|
|
32
|
+
if (!store) {
|
|
33
|
+
if (enabled) throw refusal('directory-store.ts (not found)')
|
|
34
|
+
return { files, diffs }
|
|
35
|
+
}
|
|
36
|
+
const currentStore = await readFile(
|
|
37
|
+
new URL('directory/shared/directory-store.ts', templates),
|
|
38
|
+
'utf8',
|
|
39
|
+
)
|
|
40
|
+
if (sources.get(store) === currentStore) return { files, diffs }
|
|
41
|
+
const legacy = hash(sources.get(store)) === manifest.files['shared/directory-store.ts'].source
|
|
42
|
+
if (!legacy) {
|
|
43
|
+
if (enabled) throw refusal(store)
|
|
44
|
+
return { files, diffs }
|
|
45
|
+
}
|
|
46
|
+
if (!enabled)
|
|
47
|
+
throw new Error(
|
|
48
|
+
'This is the published RC.13 Directory store. Preview its typed host migration with --add-macos --migrate-directory; apply the reviewed changes with --write.',
|
|
49
|
+
)
|
|
50
|
+
const shared = posix(dirname(store)),
|
|
51
|
+
recognized = new Set()
|
|
52
|
+
for (const name of Object.keys(manifest.files).filter((name) => name.startsWith('shared/'))) {
|
|
53
|
+
const path = `${shared}/${name.slice('shared/'.length)}`
|
|
54
|
+
if (!sources.has(path) || hash(sources.get(path)) !== manifest.files[name].source)
|
|
55
|
+
throw refusal(path)
|
|
56
|
+
recognized.add(path)
|
|
57
|
+
}
|
|
58
|
+
for (const [path, template] of hostPaths) {
|
|
59
|
+
const value = await read(path)
|
|
60
|
+
if (!value || hash(value) !== manifest.files[template]?.[appearance]) throw refusal(path)
|
|
61
|
+
recognized.add(path)
|
|
62
|
+
const next = (await readFile(new URL('directory/' + template, templates), 'utf8'))
|
|
63
|
+
.replaceAll('__MAVIS_SHARED__', '#shared-ui')
|
|
64
|
+
.replaceAll('__MAVIS_APPEARANCE__', appearance)
|
|
65
|
+
files.set(path, next)
|
|
66
|
+
const adapter = template.startsWith('nuxt/')
|
|
67
|
+
? `${posix(dirname(dirname(path)))}/utils/directory-storage.ts`
|
|
68
|
+
: `${posix(dirname(path))}/directory-storage.ts`
|
|
69
|
+
if ((await read(adapter)) !== undefined) throw refusal(adapter)
|
|
70
|
+
files.set(
|
|
71
|
+
adapter,
|
|
72
|
+
(await readFile(new URL('directory/host/directory-storage.ts', templates), 'utf8')).replace(
|
|
73
|
+
"'../shared/directory-store'",
|
|
74
|
+
"'#shared-ui/directory-store'",
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
// An extra consumer may depend on the legacy read/write interface. Never migrate only half
|
|
79
|
+
// the application, even when its shared files happen to match the reference.
|
|
80
|
+
async function inspect(directory) {
|
|
81
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
82
|
+
if (entry.name.startsWith('.') || ignored.has(entry.name)) continue
|
|
83
|
+
const full = join(directory, entry.name),
|
|
84
|
+
path = posix(relative(root, full))
|
|
85
|
+
if (entry.isSymbolicLink()) throw refusal(path + ' (linked source)')
|
|
86
|
+
if (entry.isDirectory()) await inspect(full)
|
|
87
|
+
else if (/\.(vue|[cm]?[jt]sx?)$/.test(entry.name) && !recognized.has(path)) {
|
|
88
|
+
const text = await readFile(full, 'utf8')
|
|
89
|
+
if (/directory-store|createDirectory\s*\(/.test(text))
|
|
90
|
+
throw refusal(path + ' (additional consumer)')
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
await inspect(root)
|
|
95
|
+
for (const name of ['directory-store.ts', 'Edit.vue']) {
|
|
96
|
+
const path = `${shared}/${name}`
|
|
97
|
+
files.set(path, await readFile(new URL(`directory/shared/${name}`, templates), 'utf8'))
|
|
98
|
+
}
|
|
99
|
+
for (const [path, after] of files) {
|
|
100
|
+
const before = sources.get(path) ?? (await read(path))
|
|
101
|
+
diffs.push({ file: path, before: before ?? '', after })
|
|
102
|
+
}
|
|
103
|
+
return { files, diffs }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Complete old/new lines keep an opt-in migration reviewable without guessing edits. */
|
|
107
|
+
export function migrationDiff({ file, before, after }) {
|
|
108
|
+
return [
|
|
109
|
+
`--- a/${file}`,
|
|
110
|
+
`+++ b/${file}`,
|
|
111
|
+
...before
|
|
112
|
+
.trimEnd()
|
|
113
|
+
.split('\n')
|
|
114
|
+
.filter((line) => before || line)
|
|
115
|
+
.map((line) => '-' + line),
|
|
116
|
+
...after
|
|
117
|
+
.trimEnd()
|
|
118
|
+
.split('\n')
|
|
119
|
+
.map((line) => '+' + line),
|
|
120
|
+
].join('\n')
|
|
121
|
+
}
|
package/src/portability.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { lstat, readFile, readdir, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
2
3
|
import { normalizeConfig } from './presets.mjs'
|
|
3
|
-
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
4
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
5
|
+
import { pathToFileURL } from 'node:url'
|
|
4
6
|
import ts from 'typescript'
|
|
5
7
|
import { parse } from '@vue/compiler-sfc'
|
|
6
8
|
import { components, composables } from './shared-api.mjs'
|
|
9
|
+
import { checkShared } from '@getcortexlabs/mavis-compiler'
|
|
7
10
|
|
|
8
11
|
const rendererImports = new Set(['@getcortexlabs/mavis-web', '@getcortexlabs/mavis/vue'])
|
|
9
12
|
const sharedNames = new Set([...components, ...composables])
|
|
@@ -292,6 +295,88 @@ export function inspectSource(source, filename, { allowImports = [] } = {}) {
|
|
|
292
295
|
return { diagnostics, edits, imports }
|
|
293
296
|
}
|
|
294
297
|
|
|
298
|
+
// The Mavis core a project installed: the Mac check reads its theme's tokens.
|
|
299
|
+
async function projectCore(root) {
|
|
300
|
+
for (const base of ['', 'apps/web', 'apps/mobile'])
|
|
301
|
+
try {
|
|
302
|
+
const found = createRequire(join(root, base, 'package.json')).resolve(
|
|
303
|
+
'@getcortexlabs/mavis-core',
|
|
304
|
+
)
|
|
305
|
+
return await import(pathToFileURL(found))
|
|
306
|
+
} catch {}
|
|
307
|
+
try {
|
|
308
|
+
return await import('@getcortexlabs/mavis-core')
|
|
309
|
+
} catch {}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Whether each shared file can be compiled for the experimental Mac target, with the reasons
|
|
314
|
+
* the Mac compiler's own front ends give. It reads one flat folder of Name.vue, Name.lite.tsx
|
|
315
|
+
* and type files, so every folder is checked on its own.
|
|
316
|
+
*/
|
|
317
|
+
async function macReadiness(root, sources, config, only, core) {
|
|
318
|
+
core ??= await projectCore(root)
|
|
319
|
+
if (!core)
|
|
320
|
+
return {
|
|
321
|
+
checked: false,
|
|
322
|
+
reason:
|
|
323
|
+
'Install the project dependencies first: the Mac check reads the theme from @getcortexlabs/mavis-core.',
|
|
324
|
+
}
|
|
325
|
+
const folders = new Map()
|
|
326
|
+
for (const [file, source] of sources) {
|
|
327
|
+
if (/\.d\.ts$/.test(file) || !/\.(vue|ts|lite\.tsx)$/.test(file)) continue
|
|
328
|
+
const folder = dirname(file)
|
|
329
|
+
if (!folders.has(folder)) folders.set(folder, new Map())
|
|
330
|
+
folders.get(folder).set(`shared/${basename(file)}`, source)
|
|
331
|
+
}
|
|
332
|
+
const files = []
|
|
333
|
+
for (const [folder, shared] of folders) {
|
|
334
|
+
let checked
|
|
335
|
+
try {
|
|
336
|
+
checked = await checkShared(shared, core[config.theme] ?? core.mavis)
|
|
337
|
+
} catch (error) {
|
|
338
|
+
checked = [...shared.keys()].map((file) => ({
|
|
339
|
+
file,
|
|
340
|
+
ready: false,
|
|
341
|
+
problems: [{ message: error.message }],
|
|
342
|
+
}))
|
|
343
|
+
}
|
|
344
|
+
// The compiler names every file shared/…; say where it really is.
|
|
345
|
+
const actual = (text) => text.replaceAll('shared/', `${relative(root, folder)}/`)
|
|
346
|
+
for (const item of checked)
|
|
347
|
+
files.push({
|
|
348
|
+
file: actual(item.file),
|
|
349
|
+
ready: item.ready,
|
|
350
|
+
problems: item.problems.map((problem) => ({
|
|
351
|
+
...problem,
|
|
352
|
+
message: actual(problem.message),
|
|
353
|
+
})),
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
checked: true,
|
|
358
|
+
files: files
|
|
359
|
+
.filter((item) => !only || only.has(item.file))
|
|
360
|
+
.sort((a, b) => a.file.localeCompare(b.file)),
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The Mac check as lines for a terminal. */
|
|
365
|
+
export function formatMacReadiness(macos) {
|
|
366
|
+
if (!macos.checked) return `Mac target (experimental): not checked. ${macos.reason}`
|
|
367
|
+
const ready = macos.files.filter((file) => file.ready).length
|
|
368
|
+
return [
|
|
369
|
+
`Mac target (experimental): ${ready} of ${macos.files.length} shared files are ready to compile.`,
|
|
370
|
+
...macos.files.flatMap((file) => [
|
|
371
|
+
` ${file.ready ? 'ready ' : 'not ready'} ${file.file}`,
|
|
372
|
+
...file.problems.map(
|
|
373
|
+
(problem) =>
|
|
374
|
+
` ${problem.line ? `${problem.line}:${problem.column} ` : ''}${problem.message}`,
|
|
375
|
+
),
|
|
376
|
+
]),
|
|
377
|
+
].join('\n')
|
|
378
|
+
}
|
|
379
|
+
|
|
295
380
|
async function projectConfig(root) {
|
|
296
381
|
try {
|
|
297
382
|
return normalizeConfig(JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8')))
|
|
@@ -305,9 +390,9 @@ async function projectConfig(root) {
|
|
|
305
390
|
export async function checkPortability(root = process.cwd(), options = {}) {
|
|
306
391
|
root = resolve(root)
|
|
307
392
|
const config = await projectConfig(root)
|
|
308
|
-
if (config.authoring === 'mitosis')
|
|
393
|
+
if (config.authoring === 'mitosis' && options.fixImports)
|
|
309
394
|
throw new Error(
|
|
310
|
-
'
|
|
395
|
+
'Import migrations are not supported in a project whose shared sources are compiled for each target.',
|
|
311
396
|
)
|
|
312
397
|
const roots = options.path
|
|
313
398
|
? [options.path]
|
|
@@ -321,6 +406,7 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
321
406
|
)
|
|
322
407
|
throw new Error('Configure at least one source directory in portability.roots.')
|
|
323
408
|
const files = new Map(),
|
|
409
|
+
compiled = new Map(),
|
|
324
410
|
diagnostics = [],
|
|
325
411
|
fixes = []
|
|
326
412
|
const load = async (file, dependency = false) => {
|
|
@@ -338,6 +424,9 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
338
424
|
if (dependency) return
|
|
339
425
|
for (const item of (await readdir(file)).sort())
|
|
340
426
|
if (!ignored.has(item)) await load(join(file, item))
|
|
427
|
+
} else if (/\.lite\.tsx$/.test(file)) {
|
|
428
|
+
// Compiled for every target, never run as written: only the Mac check below reads it.
|
|
429
|
+
compiled.set(file, await readFile(file, 'utf8'))
|
|
341
430
|
} else if (sourceExtensions.includes(extname(file)) && !files.has(file)) {
|
|
342
431
|
const source = await readFile(file, 'utf8')
|
|
343
432
|
const result = inspectSource(source, relative(root, file), config.portability)
|
|
@@ -402,8 +491,21 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
402
491
|
}
|
|
403
492
|
await load(file)
|
|
404
493
|
}
|
|
405
|
-
if (!files.size)
|
|
494
|
+
if (!files.size && !compiled.size)
|
|
406
495
|
throw new Error('No Vue or script sources found in the configured portability paths.')
|
|
496
|
+
const within = new Set()
|
|
497
|
+
for (const name of roots) {
|
|
498
|
+
const start = resolve(root, name)
|
|
499
|
+
for (const file of [...files.keys(), ...compiled.keys()])
|
|
500
|
+
if (file === start || file.startsWith(start + sep)) within.add(relative(root, file))
|
|
501
|
+
}
|
|
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
|
+
)
|
|
407
509
|
if (options.fixImports) {
|
|
408
510
|
if (config.portability?.alias !== '#mavis')
|
|
409
511
|
throw new Error(
|
|
@@ -450,7 +552,7 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
450
552
|
throw new Error(`Source changed during migration: ${fix.file}`)
|
|
451
553
|
}
|
|
452
554
|
for (const fix of fixes) await writeFile(join(root, fix.file), fix.after)
|
|
453
|
-
const after = await checkPortability(root, { path: options.path })
|
|
555
|
+
const after = await checkPortability(root, { path: options.path, core: options.core })
|
|
454
556
|
return { ...after, fixes, written: true }
|
|
455
557
|
}
|
|
456
558
|
}
|
|
@@ -459,6 +561,7 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
459
561
|
diagnostics: diagnostics.sort(
|
|
460
562
|
(a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column,
|
|
461
563
|
),
|
|
564
|
+
macos,
|
|
462
565
|
fixes,
|
|
463
566
|
written: false,
|
|
464
567
|
}
|
package/src/scaffold.mjs
CHANGED
|
@@ -14,8 +14,16 @@ async function copyTemplate(files, source, destination, replacements) {
|
|
|
14
14
|
const from = join(source, entry.name),
|
|
15
15
|
to = join(destination, entry.name.replace(/^_gitignore$/, '.gitignore'))
|
|
16
16
|
if (entry.isDirectory()) await copyTemplate(files, from, to, replacements)
|
|
17
|
+
// A font is copied as it is: its bytes, not text.
|
|
18
|
+
else if (/\.ttf$/.test(entry.name)) files.set(to, await readFile(join(templates, from)))
|
|
17
19
|
else {
|
|
18
20
|
let content = await readFile(join(templates, from), 'utf8')
|
|
21
|
+
// This adapter lives beside shared/ in the template, beside its host entry when generated.
|
|
22
|
+
if (from === 'directory/host/directory-storage.ts')
|
|
23
|
+
content = content.replace(
|
|
24
|
+
"'../shared/directory-store'",
|
|
25
|
+
"'__MAVIS_SHARED__/directory-store'",
|
|
26
|
+
)
|
|
19
27
|
for (const [key, value] of Object.entries(replacements))
|
|
20
28
|
content = content.replaceAll(`__MAVIS_${key}__`, value)
|
|
21
29
|
files.set(to, content)
|
|
@@ -78,7 +86,15 @@ export async function projectFiles(options) {
|
|
|
78
86
|
...replacements,
|
|
79
87
|
SHARED: '#shared-ui',
|
|
80
88
|
})
|
|
81
|
-
if (directory)
|
|
89
|
+
if (directory) {
|
|
90
|
+
await copyTemplate(files, `directory/${preset.web}`, webDir, replacements)
|
|
91
|
+
await copyTemplate(
|
|
92
|
+
files,
|
|
93
|
+
'directory/host',
|
|
94
|
+
join(webDir, preset.web === 'nuxt' ? 'app/utils' : 'src'),
|
|
95
|
+
replacements,
|
|
96
|
+
)
|
|
97
|
+
}
|
|
82
98
|
const scripts =
|
|
83
99
|
preset.web === 'vite'
|
|
84
100
|
? { dev: 'vite', build: 'vue-tsc --noEmit && vite build', preview: 'vite preview' }
|
|
@@ -122,7 +138,10 @@ export async function projectFiles(options) {
|
|
|
122
138
|
SHARED_ROOT: shared ? '../../shared' : './src/shared',
|
|
123
139
|
SHARED: '#shared-ui',
|
|
124
140
|
})
|
|
125
|
-
if (directory)
|
|
141
|
+
if (directory) {
|
|
142
|
+
await copyTemplate(files, 'directory/mobile', mobileDir, replacements)
|
|
143
|
+
await copyTemplate(files, 'directory/host', join(mobileDir, 'src'), replacements)
|
|
144
|
+
}
|
|
126
145
|
files.set(
|
|
127
146
|
join(mobileDir, 'package.json'),
|
|
128
147
|
json({
|