@getcortexlabs/create-mavis 0.1.0-rc.15 → 0.1.0-rc.17
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/templates/nuxt/nuxt.config.ts +2 -0
- 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/macos.mjs
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import { versions as v, configOf, targetLabel } from './presets.mjs'
|
|
2
|
-
import { packageCommands } from './package-manager.mjs'
|
|
3
|
-
import { joltSwift } from '@getcortexlabs/mavis-compiler'
|
|
4
|
-
|
|
5
|
-
const json = (value) => `${JSON.stringify(value, null, 2)}\n`
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Combinations with Mac: shared TSX sources compiled into Vue for the Web, Vue for
|
|
9
|
-
* NativeScript and SwiftUI for macOS. Projects without Mac keep Vue templates.
|
|
10
|
-
*/
|
|
11
|
-
export async function macosFiles(preset, files, copyTemplate) {
|
|
12
|
-
const { targets } = preset
|
|
13
|
-
const web = targets.includes('web')
|
|
14
|
-
const native = targets.includes('native')
|
|
15
|
-
const mac = targets.includes('macos')
|
|
16
|
-
const commands = packageCommands(preset.packageManager)
|
|
17
|
-
const tasks = preset.example === 'tasks'
|
|
18
|
-
const directory = preset.example === 'directory'
|
|
19
|
-
const nuxt = preset.web === 'nuxt'
|
|
20
|
-
// The screen every app opens. Tasks is a list beside its detail, so it gets a wider page.
|
|
21
|
-
const entry = directory ? 'Directory' : tasks ? 'Tasks' : 'Welcome'
|
|
22
|
-
const hosts = [
|
|
23
|
-
web && (nuxt ? `Nuxt (${preset.rendering}) on the Web` : 'Vue on the Web'),
|
|
24
|
-
native && 'NativeScript on iOS and Android',
|
|
25
|
-
mac && 'SwiftUI on the Mac',
|
|
26
|
-
].filter(Boolean)
|
|
27
|
-
const replacements = {
|
|
28
|
-
NAME: preset.name,
|
|
29
|
-
APPID: preset.name.replaceAll('-', ''),
|
|
30
|
-
THEME: preset.theme,
|
|
31
|
-
APPEARANCE: preset.theme === 'midnight' ? 'dark' : 'light',
|
|
32
|
-
BACKGROUND: preset.theme === 'midnight' ? '#15121C' : '#FAF7FA',
|
|
33
|
-
TARGETS: targetLabel(targets),
|
|
34
|
-
HOSTS: hosts.join(' · '),
|
|
35
|
-
JOLT_SWIFT: joltSwift.version,
|
|
36
|
-
WEB_WIDTH: tasks ? '1120px' : '760px',
|
|
37
|
-
MAC_WIDTH: tasks ? '1120' : '820',
|
|
38
|
-
MAC_MIN_WIDTH: tasks ? '760' : '640',
|
|
39
|
-
MAC_DEFAULT_WIDTH: tasks ? '1180' : '860',
|
|
40
|
-
SHARED: '#shared-ui',
|
|
41
|
-
SHARED_ROOT: '../../shared',
|
|
42
|
-
}
|
|
43
|
-
await copyTemplate(files, 'macos/root', '', replacements)
|
|
44
|
-
await copyTemplate(
|
|
45
|
-
files,
|
|
46
|
-
directory ? 'directory/shared' : tasks ? 'macos/examples/tasks/shared' : 'macos/shared',
|
|
47
|
-
'shared',
|
|
48
|
-
replacements,
|
|
49
|
-
)
|
|
50
|
-
await copyTemplate(files, 'macos/scripts', 'scripts', replacements)
|
|
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
|
-
}
|
|
56
|
-
|
|
57
|
-
const common = { private: true, version: '0.0.0', engines: { node: '>=22.16' } }
|
|
58
|
-
const generate = 'node scripts/generate.mjs'
|
|
59
|
-
const builds = []
|
|
60
|
-
const scripts = { generate }
|
|
61
|
-
if (web) {
|
|
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
|
-
}
|
|
92
|
-
scripts['dev:web'] = `${generate} && ${commands.run('dev', 'apps/web')}`
|
|
93
|
-
scripts['build:web'] =
|
|
94
|
-
`${generate} && ${commands.run(nuxt && preset.rendering === 'ssg' ? 'generate' : 'build', 'apps/web')}`
|
|
95
|
-
builds.push('build:web')
|
|
96
|
-
files.set(
|
|
97
|
-
'apps/web/package.json',
|
|
98
|
-
json({
|
|
99
|
-
...common,
|
|
100
|
-
name: `${preset.name}-web`,
|
|
101
|
-
type: 'module',
|
|
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' },
|
|
112
|
-
dependencies: {
|
|
113
|
-
'@getcortexlabs/mavis-core': v.mavis,
|
|
114
|
-
'@getcortexlabs/mavis-web': v.mavis,
|
|
115
|
-
'@rafaelaugusto/jolt': v.jolt,
|
|
116
|
-
vue: v.vue,
|
|
117
|
-
'@vue/runtime-core': v.vue,
|
|
118
|
-
...(nuxt ? { nuxt: v.nuxt } : {}),
|
|
119
|
-
...(directory && !nuxt ? { 'vue-router': v.router } : {}),
|
|
120
|
-
},
|
|
121
|
-
devDependencies: {
|
|
122
|
-
typescript: v.typescript,
|
|
123
|
-
'vue-tsc': v.vueTsc,
|
|
124
|
-
'@types/node': v.nodeTypes,
|
|
125
|
-
...(!nuxt ? { vite: v.vite, '@vitejs/plugin-vue': v.vuePlugin } : {}),
|
|
126
|
-
},
|
|
127
|
-
}),
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
if (native) {
|
|
131
|
-
await copyTemplate(files, 'mobile', 'apps/mobile', replacements)
|
|
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
|
-
}
|
|
137
|
-
// The generated screens are the app's shared code; the TSX sources stay out of vue-tsc.
|
|
138
|
-
files.set(
|
|
139
|
-
'apps/mobile/tsconfig.json',
|
|
140
|
-
files
|
|
141
|
-
.get('apps/mobile/tsconfig.json')
|
|
142
|
-
.replace('"include": ["src", "../../shared"]', '"include": ["src"]'),
|
|
143
|
-
)
|
|
144
|
-
scripts.ios = `${generate} && ${commands.run('ios', 'apps/mobile')}`
|
|
145
|
-
scripts.android = `${generate} && ${commands.run('android', 'apps/mobile')}`
|
|
146
|
-
scripts['build:native'] =
|
|
147
|
-
`${generate} && ${commands.run('bundle:android', 'apps/mobile')} && ${commands.run('bundle:ios', 'apps/mobile')}`
|
|
148
|
-
scripts['install:apps'] = `${commands.install} && ${commands.installAt('apps/mobile')}`
|
|
149
|
-
builds.push('build:native')
|
|
150
|
-
files.set(
|
|
151
|
-
'apps/mobile/package.json',
|
|
152
|
-
json({
|
|
153
|
-
...common,
|
|
154
|
-
name: `${preset.name}-mobile`,
|
|
155
|
-
...(preset.packageManager === 'yarn'
|
|
156
|
-
? {
|
|
157
|
-
dependenciesMeta: {
|
|
158
|
-
esbuild: { built: true },
|
|
159
|
-
'@nativescript/core': { built: true },
|
|
160
|
-
'@parcel/watcher': { built: true },
|
|
161
|
-
'core-js-pure': { built: false },
|
|
162
|
-
},
|
|
163
|
-
}
|
|
164
|
-
: {}),
|
|
165
|
-
main: 'src/app.ts',
|
|
166
|
-
scripts: {
|
|
167
|
-
android: 'ns run android',
|
|
168
|
-
ios: 'ns run ios',
|
|
169
|
-
typecheck: 'vue-tsc --noEmit',
|
|
170
|
-
'bundle:android': 'webpack --env android',
|
|
171
|
-
'bundle:ios': 'webpack --env ios',
|
|
172
|
-
},
|
|
173
|
-
dependencies: {
|
|
174
|
-
'@getcortexlabs/mavis-core': v.mavis,
|
|
175
|
-
'@rafaelaugusto/jolt': v.jolt,
|
|
176
|
-
'@getcortexlabs/mavis': v.mavis,
|
|
177
|
-
'@nativescript/core': v.nativeCore,
|
|
178
|
-
'nativescript-vue': v.nativeVue,
|
|
179
|
-
...(directory ? { 'vue-router-ns': v.nativeRouter } : {}),
|
|
180
|
-
},
|
|
181
|
-
devDependencies: {
|
|
182
|
-
'@nativescript/android': v.android,
|
|
183
|
-
'@nativescript/ios': v.ios,
|
|
184
|
-
'@nativescript/webpack': v.webpack,
|
|
185
|
-
webpack: v.webpackCore,
|
|
186
|
-
'webpack-cli': v.webpackCli,
|
|
187
|
-
typescript: v.typescript,
|
|
188
|
-
'vue-tsc': v.vueTsc,
|
|
189
|
-
},
|
|
190
|
-
}),
|
|
191
|
-
)
|
|
192
|
-
}
|
|
193
|
-
if (mac) {
|
|
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
|
-
}
|
|
208
|
-
scripts.macos = 'node scripts/macos.mjs run'
|
|
209
|
-
scripts['build:macos'] = 'node scripts/macos.mjs build'
|
|
210
|
-
builds.push('build:macos')
|
|
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
|
-
}
|
|
240
|
-
scripts.build = builds.map((name) => commands.run(name)).join(' && ')
|
|
241
|
-
|
|
242
|
-
files.set(
|
|
243
|
-
'package.json',
|
|
244
|
-
json({
|
|
245
|
-
...common,
|
|
246
|
-
name: preset.name,
|
|
247
|
-
type: 'module',
|
|
248
|
-
...(web && preset.packageManager !== 'pnpm' ? { workspaces: ['apps/web'] } : {}),
|
|
249
|
-
...(web && preset.packageManager === 'yarn'
|
|
250
|
-
? {
|
|
251
|
-
resolutions: { vue: v.vue, '@vue/runtime-core': v.vue },
|
|
252
|
-
dependenciesMeta: {
|
|
253
|
-
esbuild: { built: true },
|
|
254
|
-
...(nuxt ? { 'unrs-resolver': { built: true } } : {}),
|
|
255
|
-
},
|
|
256
|
-
}
|
|
257
|
-
: {}),
|
|
258
|
-
scripts,
|
|
259
|
-
// The compiler reads theme tokens from Mavis core, type-checks with TypeScript and parses
|
|
260
|
-
// shared Vue files with Vue's own compiler.
|
|
261
|
-
dependencies: { '@getcortexlabs/mavis-core': v.mavis },
|
|
262
|
-
devDependencies: { '@getcortexlabs/mavis-compiler': v.mavis, typescript: v.typescript },
|
|
263
|
-
}),
|
|
264
|
-
)
|
|
265
|
-
files.set(
|
|
266
|
-
'mavis.config.json',
|
|
267
|
-
json({
|
|
268
|
-
...configOf(preset),
|
|
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
|
-
},
|
|
281
|
-
}),
|
|
282
|
-
)
|
|
283
|
-
files.set(
|
|
284
|
-
'.gitignore',
|
|
285
|
-
[
|
|
286
|
-
'node_modules/',
|
|
287
|
-
'.npm/',
|
|
288
|
-
'.pnpm-store/',
|
|
289
|
-
'.yarn/',
|
|
290
|
-
'dist/',
|
|
291
|
-
'.nuxt/',
|
|
292
|
-
'.output/',
|
|
293
|
-
'apps/web/app/generated/',
|
|
294
|
-
'platforms/',
|
|
295
|
-
'hooks/',
|
|
296
|
-
'apps/macos/.build/',
|
|
297
|
-
'apps/web/src/generated/',
|
|
298
|
-
'apps/web/app/generated/',
|
|
299
|
-
'apps/web/public/~/',
|
|
300
|
-
'apps/mobile/src/generated/',
|
|
301
|
-
'apps/macos/Sources/MavisDesktop/Generated/',
|
|
302
|
-
'mavis-env.d.ts',
|
|
303
|
-
'.DS_Store',
|
|
304
|
-
'*.log',
|
|
305
|
-
'',
|
|
306
|
-
].join('\n'),
|
|
307
|
-
)
|
|
308
|
-
if (preset.packageManager === 'pnpm') {
|
|
309
|
-
files.set(
|
|
310
|
-
'pnpm-workspace.yaml',
|
|
311
|
-
`packages:${web ? '\n - apps/web' : ' []'}\nnodeLinker: hoisted\nallowBuilds:\n esbuild: true\n${nuxt ? ' "unrs-resolver": true\n' : ''}`,
|
|
312
|
-
)
|
|
313
|
-
if (native)
|
|
314
|
-
files.set(
|
|
315
|
-
'apps/mobile/pnpm-workspace.yaml',
|
|
316
|
-
'packages: []\nnodeLinker: hoisted\nsideEffectsCache: false\nallowBuilds:\n "esbuild": true\n "@nativescript/core": true\n "@parcel/watcher": true\n "core-js-pure": false\n',
|
|
317
|
-
)
|
|
318
|
-
}
|
|
319
|
-
if (preset.packageManager === 'yarn') {
|
|
320
|
-
files.set('.yarnrc.yml', 'nodeLinker: node-modules\n')
|
|
321
|
-
// An empty lockfile marks a separate Yarn project, including before its first install.
|
|
322
|
-
files.set('yarn.lock', '')
|
|
323
|
-
if (native) files.set('apps/mobile/yarn.lock', '')
|
|
324
|
-
}
|
|
325
|
-
files.set('README.md', readme(preset, commands, { web, native, mac, entry }))
|
|
326
|
-
return { preset, files: new Map([...files].sort(([a], [b]) => a.localeCompare(b))) }
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function readme(preset, commands, { web, native, mac, entry }) {
|
|
330
|
-
const directory = preset.example === 'directory'
|
|
331
|
-
const start = [
|
|
332
|
-
native ? commands.setup(true) : commands.install,
|
|
333
|
-
...(web ? [commands.run('dev:web')] : []),
|
|
334
|
-
...(native ? [commands.run('ios'), commands.run('android')] : []),
|
|
335
|
-
...(mac ? [commands.run('macos')] : []),
|
|
336
|
-
]
|
|
337
|
-
const folders = [
|
|
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/.'),
|
|
342
|
-
native &&
|
|
343
|
-
'- apps/mobile: NativeScript-Vue for iOS and Android with Mavis. Generated screens in apps/mobile/src/generated/.',
|
|
344
|
-
mac &&
|
|
345
|
-
'- apps/macos: a SwiftUI app (Swift package) with JoltSwiftUI. Generated views in apps/macos/Sources/MavisDesktop/Generated/.',
|
|
346
|
-
].filter(Boolean)
|
|
347
|
-
const hosts = [
|
|
348
|
-
native &&
|
|
349
|
-
`Native needs the NativeScript CLI and the platform SDK: Xcode on macOS for iOS, a JDK and the Android SDK for Android. Run \`ns doctor\` in apps/mobile. It has its own dependency tree; reinstall both from the root with \`${commands.run('install:apps')}\`.`,
|
|
350
|
-
mac &&
|
|
351
|
-
'The Mac app needs macOS 14+ and Xcode with command-line tools. It uses SwiftUI, not a WebView or a JavaScript runtime. The first build downloads JoltSwiftUI (rafaelaugustos/jolt-swift). The app is unsigned, for local development.',
|
|
352
|
-
'Code generation and the Web also work on Linux and Windows.',
|
|
353
|
-
].filter(Boolean)
|
|
354
|
-
return `# ${preset.name}
|
|
355
|
-
|
|
356
|
-
Mavis ${targetLabel(preset.targets)} project, experimental. **One shared source, compiled for each target.**
|
|
357
|
-
This is a compiler experiment for a subset of Mavis, not a complete renderer for every component.
|
|
358
|
-
|
|
359
|
-
## Start
|
|
360
|
-
|
|
361
|
-
\`\`\`sh
|
|
362
|
-
${start.join('\n')}
|
|
363
|
-
\`\`\`
|
|
364
|
-
|
|
365
|
-
${hosts.join(' ')}
|
|
366
|
-
|
|
367
|
-
## Edit once
|
|
368
|
-
|
|
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:
|
|
370
|
-
|
|
371
|
-
${folders.join('\n')}
|
|
372
|
-
|
|
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
|
|
376
|
-
|
|
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.
|
|
383
|
-
|
|
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.
|
|
385
|
-
|
|
386
|
-
## Motion
|
|
387
|
-
|
|
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.
|
|
389
|
-
|
|
390
|
-
## Build
|
|
391
|
-
|
|
392
|
-
\`${commands.run('build')}\` builds every target${mac ? `; the Mac app goes to dist/${preset.name}.app` : ''}.${native ? ' build:native bundles the NativeScript JavaScript for Android and iOS; use the NativeScript CLI for installable apps.' : ''} Commit the generated ${native ? 'lockfiles' : commands.lockfile} after installation.
|
|
393
|
-
`
|
|
394
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { createTrack, instantTrack } from '#jolt-track'
|
|
2
|
-
import { resolveTransition } from '#jolt-transition'
|
|
3
|
-
|
|
4
|
-
/** Finite opacity only. Jolt samples the curve; Core Animation owns every frame. */
|
|
5
|
-
export function opacityMotion(view, from, to, reduced, completed = () => {}) {
|
|
6
|
-
const track = reduced
|
|
7
|
-
? instantTrack('opacity', to)
|
|
8
|
-
: createTrack(
|
|
9
|
-
'opacity',
|
|
10
|
-
[from, to],
|
|
11
|
-
resolveTransition({ duration: 240, ease: 'easeOut' }, 'opacity', 2),
|
|
12
|
-
0,
|
|
13
|
-
{ timeScale: 1, reducedMotion: false },
|
|
14
|
-
)
|
|
15
|
-
const layer = view.layer
|
|
16
|
-
const key = 'mavis:jolt:opacity'
|
|
17
|
-
let active = true
|
|
18
|
-
const finish = (finished) => {
|
|
19
|
-
if (!active) return
|
|
20
|
-
active = false
|
|
21
|
-
completed(finished)
|
|
22
|
-
}
|
|
23
|
-
CATransaction.begin()
|
|
24
|
-
CATransaction.setDisableActions(true)
|
|
25
|
-
layer.opacity = track.to
|
|
26
|
-
if (track.duration > 0) {
|
|
27
|
-
const animation = CAKeyframeAnimation.animationWithKeyPath('opacity')
|
|
28
|
-
animation.values = NSArray.arrayWithArray([...track.values])
|
|
29
|
-
animation.keyTimes = NSArray.arrayWithArray([...track.times])
|
|
30
|
-
animation.duration = track.duration / 1000
|
|
31
|
-
CATransaction.setCompletionBlock(() => finish(true))
|
|
32
|
-
layer.addAnimationForKey(animation, key)
|
|
33
|
-
}
|
|
34
|
-
CATransaction.commit()
|
|
35
|
-
if (track.duration === 0) finish(true)
|
|
36
|
-
return {
|
|
37
|
-
get active() {
|
|
38
|
-
return active
|
|
39
|
-
},
|
|
40
|
-
cancel() {
|
|
41
|
-
if (!active) return
|
|
42
|
-
const value = layer.presentationLayer?.opacity ?? layer.opacity
|
|
43
|
-
finish(false)
|
|
44
|
-
CATransaction.begin()
|
|
45
|
-
CATransaction.setDisableActions(true)
|
|
46
|
-
layer.opacity = value
|
|
47
|
-
layer.removeAnimationForKey(key)
|
|
48
|
-
CATransaction.commit()
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
|
|
3
|
-
/// One instance per app. Uses the same JSON array and key as the Web and NativeScript hosts.
|
|
4
|
-
@MainActor final class UserDefaultsDirectoryStorage: DirectoryStorage {
|
|
5
|
-
private let defaults: UserDefaults
|
|
6
|
-
private let key: String
|
|
7
|
-
private var entries = DirectoryStoreModule.directorySeed
|
|
8
|
-
private var loaded = false
|
|
9
|
-
private var revision: Double = 0
|
|
10
|
-
private var loadError = false
|
|
11
|
-
|
|
12
|
-
init(defaults: UserDefaults = .standard, key: String = "mavis:directory") {
|
|
13
|
-
self.defaults = defaults
|
|
14
|
-
self.key = key
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private func snapshot() -> DirectorySnapshot {
|
|
18
|
-
DirectorySnapshot(entries: entries, revision: revision, loadError: loadError)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private func restore() {
|
|
22
|
-
guard !loaded else { return }
|
|
23
|
-
loaded = true
|
|
24
|
-
guard let text = defaults.string(forKey: key) else { return }
|
|
25
|
-
do {
|
|
26
|
-
guard let data = text.data(using: .utf8),
|
|
27
|
-
let values = try JSONSerialization.jsonObject(with: data) as? [[String: Any]]
|
|
28
|
-
else { throw MavisFailure(message: "Invalid saved directory") }
|
|
29
|
-
let decoded = try values.map { value -> DirectoryEntry in
|
|
30
|
-
guard let id = value["id"] as? String,
|
|
31
|
-
let name = value["name"] as? String,
|
|
32
|
-
let city = value["city"] as? String
|
|
33
|
-
else { throw MavisFailure(message: "Invalid saved directory") }
|
|
34
|
-
return DirectoryEntry(id: id, name: name, city: city)
|
|
35
|
-
}
|
|
36
|
-
guard DirectoryStoreModule.validDirectoryEntries(decoded)
|
|
37
|
-
else { throw MavisFailure(message: "Invalid saved directory") }
|
|
38
|
-
entries = decoded
|
|
39
|
-
} catch {
|
|
40
|
-
loadError = true
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func load() async throws -> DirectorySnapshot {
|
|
45
|
-
restore()
|
|
46
|
-
return snapshot()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
func rename(_ id: String, _ name: String) async throws -> DirectorySnapshot {
|
|
50
|
-
// This operation has no suspension: MainActor serializes restore/edit/write/commit.
|
|
51
|
-
restore()
|
|
52
|
-
let trimmed = mavisTrim(name)
|
|
53
|
-
guard !trimmed.isEmpty, entries.contains(where: { $0.id == id })
|
|
54
|
-
else { throw MavisFailure(message: "Invalid entry") }
|
|
55
|
-
let next = entries.map { entry in
|
|
56
|
-
DirectoryEntry(id: entry.id, name: entry.id == id ? trimmed : entry.name, city: entry.city)
|
|
57
|
-
}
|
|
58
|
-
let data = try JSONSerialization.data(withJSONObject: next.map {
|
|
59
|
-
["id": $0.id, "name": $0.name, "city": $0.city]
|
|
60
|
-
})
|
|
61
|
-
guard let text = String(data: data, encoding: .utf8)
|
|
62
|
-
else { throw MavisFailure(message: "Could not encode directory") }
|
|
63
|
-
defaults.set(text, forKey: key)
|
|
64
|
-
entries = next
|
|
65
|
-
revision += 1
|
|
66
|
-
return snapshot()
|
|
67
|
-
}
|
|
68
|
-
}
|