@getcortexlabs/create-mavis 0.1.0-rc.14 → 0.1.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -9
- package/package.json +2 -2
- package/src/adapters.mjs +49 -20
- package/src/add-desktop.mjs +308 -0
- package/src/add-macos.mjs +3 -3
- package/src/capabilities.mjs +288 -42
- package/src/cli.mjs +98 -8
- package/src/desktop.mjs +155 -0
- package/src/doctor.mjs +86 -5
- package/src/native-framework.mjs +144 -0
- package/src/portability.mjs +22 -7
- package/src/scaffold.mjs +38 -9
- package/src/ui.mjs +51 -3
- package/templates/desktop/common/LICENSE +21 -0
- package/templates/desktop/common/build.mjs +58 -0
- package/templates/desktop/common/src/components.ts +60 -0
- package/templates/desktop/common/src/contract.mjs +35 -0
- package/templates/desktop/common/src/renderer.ts +76 -0
- package/templates/desktop/common/src/storage.ts +29 -0
- package/templates/desktop/directory/main.ts +35 -0
- package/templates/desktop/macos/launch.mjs +6 -0
- package/templates/desktop/macos/package.mjs +114 -0
- package/templates/desktop/macos/src/host.mjs +468 -0
- package/templates/desktop/macos/src/motion.mjs +51 -0
- package/templates/desktop/welcome/Welcome.vue +56 -0
- package/templates/desktop/welcome/main.ts +24 -0
- package/templates/desktop/windows/NativeScript-LICENSE +19 -0
- package/templates/desktop/windows/launch.mjs +16 -0
- package/templates/desktop/windows/package.mjs +54 -0
- package/templates/desktop/windows/prepare-host.mjs +73 -0
- package/templates/desktop/windows/src/host.mjs +277 -0
- package/templates/native-framework/angular/screen.ts +84 -0
- package/templates/native-framework/common/nativescript.config.ts +6 -0
- package/templates/native-framework/common/src/app.ts +5 -0
- package/templates/native-framework/common/src/model.ts +40 -0
- package/templates/native-framework/common/src/references.d.ts +8 -0
- package/templates/native-framework/common/tsconfig.json +16 -0
- package/templates/native-framework/common/webpack.config.js +67 -0
- package/templates/native-framework/plain/screen.ts +102 -0
- package/templates/native-framework/react/screen.ts +83 -0
- package/templates/native-framework/solid/screen.ts +111 -0
- package/templates/native-framework/svelte/Welcome.svelte +26 -0
- package/templates/native-framework/svelte/screen.ts +14 -0
- package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
package/src/scaffold.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
3
|
+
import { dirname, join, posix, relative, resolve, sep } from 'node:path'
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import { directoryReadme } from './reference.mjs'
|
|
6
6
|
import { configOf, resolvePreset, versions as v } from './presets.mjs'
|
|
@@ -9,10 +9,13 @@ import { packageCommands, runInstall } from './package-manager.mjs'
|
|
|
9
9
|
const templates = fileURLToPath(new URL('../templates/', import.meta.url))
|
|
10
10
|
const json = (value) => `${JSON.stringify(value, null, 2)}\n`
|
|
11
11
|
|
|
12
|
-
async function copyTemplate(files, source, destination, replacements) {
|
|
12
|
+
export async function copyTemplate(files, source, destination, replacements) {
|
|
13
13
|
for (const entry of await readdir(join(templates, source), { withFileTypes: true })) {
|
|
14
|
-
const from = join(source, entry.name),
|
|
15
|
-
to = join(
|
|
14
|
+
const from = posix.join(source, entry.name),
|
|
15
|
+
to = posix.join(
|
|
16
|
+
destination.replaceAll('\\', '/'),
|
|
17
|
+
entry.name.replace(/^_gitignore$/, '.gitignore'),
|
|
18
|
+
)
|
|
16
19
|
if (entry.isDirectory()) await copyTemplate(files, from, to, replacements)
|
|
17
20
|
// A font is copied as it is: its bytes, not text.
|
|
18
21
|
else if (/\.ttf$/.test(entry.name)) files.set(to, await readFile(join(templates, from)))
|
|
@@ -34,6 +37,14 @@ async function copyTemplate(files, source, destination, replacements) {
|
|
|
34
37
|
export async function projectFiles(options) {
|
|
35
38
|
const preset = resolvePreset(options)
|
|
36
39
|
const files = new Map()
|
|
40
|
+
if (preset.framework !== 'vue') {
|
|
41
|
+
const { nativeFrameworkFiles } = await import('./native-framework.mjs')
|
|
42
|
+
return nativeFrameworkFiles(preset, copyTemplate)
|
|
43
|
+
}
|
|
44
|
+
if (preset.target === 'desktop') {
|
|
45
|
+
const { desktopFiles } = await import('./desktop.mjs')
|
|
46
|
+
return desktopFiles(preset, copyTemplate, projectFiles)
|
|
47
|
+
}
|
|
37
48
|
if (preset.target === 'macos') {
|
|
38
49
|
const { macosFiles } = await import('./macos.mjs')
|
|
39
50
|
return macosFiles(preset, files, copyTemplate)
|
|
@@ -275,7 +286,14 @@ export async function projectFiles(options) {
|
|
|
275
286
|
].join('\n\n') + '\n',
|
|
276
287
|
)
|
|
277
288
|
if (directory) files.set('README.md', directoryReadme(preset, sharedDir))
|
|
278
|
-
return {
|
|
289
|
+
return {
|
|
290
|
+
preset,
|
|
291
|
+
files: new Map(
|
|
292
|
+
[...files]
|
|
293
|
+
.map(([path, content]) => [path.replaceAll('\\', '/'), content])
|
|
294
|
+
.sort(([a], [b]) => a.localeCompare(b)),
|
|
295
|
+
),
|
|
296
|
+
}
|
|
279
297
|
}
|
|
280
298
|
|
|
281
299
|
export async function scaffold(options, cwd = process.cwd()) {
|
|
@@ -323,10 +341,21 @@ export async function scaffold(options, cwd = process.cwd()) {
|
|
|
323
341
|
export async function installProject(plan, { signal, onProgress } = {}) {
|
|
324
342
|
// The NativeScript app has its own dependency tree next to the root project.
|
|
325
343
|
const directories =
|
|
326
|
-
plan.preset.target === '
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
344
|
+
plan.preset.target === 'desktop'
|
|
345
|
+
? [
|
|
346
|
+
'',
|
|
347
|
+
...(plan.preset.targets.includes('native') ? ['apps/mobile'] : []),
|
|
348
|
+
...(plan.preset.targets.includes('macos') && process.platform === 'darwin'
|
|
349
|
+
? ['apps/macos']
|
|
350
|
+
: []),
|
|
351
|
+
...(plan.preset.targets.includes('windows') && process.platform === 'win32'
|
|
352
|
+
? ['apps/windows']
|
|
353
|
+
: []),
|
|
354
|
+
]
|
|
355
|
+
: plan.preset.target === 'both' ||
|
|
356
|
+
(plan.preset.target === 'macos' && plan.preset.targets.includes('native'))
|
|
357
|
+
? ['', 'apps/mobile']
|
|
358
|
+
: ['']
|
|
330
359
|
for (const directory of directories) {
|
|
331
360
|
const cwd = join(plan.destination, directory)
|
|
332
361
|
onProgress?.(directory || '.')
|
package/src/ui.mjs
CHANGED
|
@@ -28,6 +28,19 @@ export function validateDestination(name, cwd = process.cwd()) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function projectSummary(preset, install) {
|
|
31
|
+
if (preset.target === 'desktop')
|
|
32
|
+
return [
|
|
33
|
+
`Project ${preset.name}`,
|
|
34
|
+
`Targets ${targetLabel(preset.targets)} · EXPERIMENTAL`,
|
|
35
|
+
`Hosts ${preset.targets.map((target) => (target === 'macos' ? 'NativeScript AppKit' : target === 'windows' ? 'NativeScript XAML Islands' : target === 'native' ? 'NativeScript iOS + Android' : preset.web === 'nuxt' ? 'Nuxt' : 'Vue + Vite')).join(' · ')}`,
|
|
36
|
+
'Authoring Shared Vue screens · native desktop component subset',
|
|
37
|
+
...status(preset),
|
|
38
|
+
`Framework ${catalog.frameworks[preset.framework].label}`,
|
|
39
|
+
`Example ${catalog.examples[preset.example].label}`,
|
|
40
|
+
`Theme ${preset.theme}`,
|
|
41
|
+
`Packages ${preset.packageManager} · ${install ? 'install for this OS now' : 'install later'}`,
|
|
42
|
+
].join('\n')
|
|
43
|
+
|
|
31
44
|
if (preset.target === 'macos')
|
|
32
45
|
return [
|
|
33
46
|
`Project ${preset.name}`,
|
|
@@ -64,6 +77,10 @@ export function projectSummary(preset, install) {
|
|
|
64
77
|
}
|
|
65
78
|
|
|
66
79
|
export function sharedEntry(preset) {
|
|
80
|
+
if (preset.framework !== 'vue')
|
|
81
|
+
return preset.framework === 'svelte' ? 'src/Welcome.svelte' : 'src/screen.ts'
|
|
82
|
+
if (preset.target === 'desktop')
|
|
83
|
+
return `shared/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
67
84
|
if (preset.target === 'macos')
|
|
68
85
|
return preset.example === 'directory'
|
|
69
86
|
? 'shared/Directory.vue'
|
|
@@ -75,6 +92,16 @@ export function sharedEntry(preset) {
|
|
|
75
92
|
|
|
76
93
|
export function nextSteps(preset, installed = false) {
|
|
77
94
|
const commands = packageCommands(preset.packageManager)
|
|
95
|
+
if (preset.target === 'desktop')
|
|
96
|
+
return [
|
|
97
|
+
`cd ${preset.name}`,
|
|
98
|
+
...(!installed ? [commands.run('install:apps')] : []),
|
|
99
|
+
...(preset.targets.includes('web') ? [commands.run('dev:web')] : []),
|
|
100
|
+
...(preset.targets.includes('native') ? [commands.run('ios'), commands.run('android')] : []),
|
|
101
|
+
...(preset.targets.includes('macos') ? [commands.run('macos') + ' # on macOS'] : []),
|
|
102
|
+
...(preset.targets.includes('windows') ? [commands.run('windows') + ' # on Windows'] : []),
|
|
103
|
+
'Run --doctor on each target OS. See README for the desktop component subset.',
|
|
104
|
+
].join('\n')
|
|
78
105
|
if (preset.target === 'macos') {
|
|
79
106
|
const has = (target) => preset.targets.includes(target)
|
|
80
107
|
return [
|
|
@@ -170,6 +197,21 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
170
197
|
fallback: ['web'],
|
|
171
198
|
options: choices(catalog.targets),
|
|
172
199
|
},
|
|
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
|
+
{
|
|
209
|
+
key: 'framework',
|
|
210
|
+
message: 'Choose the framework for iOS and Android',
|
|
211
|
+
when: () => targets().length === 1 && targets()[0] === 'native',
|
|
212
|
+
fallback: 'vue',
|
|
213
|
+
options: choices(catalog.frameworks),
|
|
214
|
+
},
|
|
173
215
|
{
|
|
174
216
|
key: 'web',
|
|
175
217
|
message: 'Choose your web setup',
|
|
@@ -202,9 +244,15 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
202
244
|
Object.keys(catalog.examples).filter(
|
|
203
245
|
(example) =>
|
|
204
246
|
catalog.examples[example].authoring.includes(
|
|
205
|
-
|
|
247
|
+
answers.framework && answers.framework !== 'vue'
|
|
248
|
+
? 'native'
|
|
249
|
+
: targets().includes('macos') && answers.macosRuntime === 'swiftui'
|
|
250
|
+
? 'mitosis'
|
|
251
|
+
: 'vue',
|
|
206
252
|
) ||
|
|
207
|
-
(targets().includes('macos') &&
|
|
253
|
+
(targets().includes('macos') &&
|
|
254
|
+
answers.macosRuntime === 'swiftui' &&
|
|
255
|
+
catalog.examples[example].portableAuthoring),
|
|
208
256
|
),
|
|
209
257
|
),
|
|
210
258
|
},
|
|
@@ -325,7 +373,7 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
325
373
|
}
|
|
326
374
|
if (value.includes('macos'))
|
|
327
375
|
io.log.message(
|
|
328
|
-
`The Mac app
|
|
376
|
+
`The Mac app defaults to NativeScript AppKit with shared Vue. SwiftUI remains available as a separate runtime choice.`,
|
|
329
377
|
)
|
|
330
378
|
}
|
|
331
379
|
answers[step.key] = value
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rafael Augusto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { build } from 'esbuild'
|
|
2
|
+
import { parse, compileScript } from '@vue/compiler-sfc'
|
|
3
|
+
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
5
|
+
import { dirname, resolve } from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { createHash } from 'node:crypto'
|
|
8
|
+
|
|
9
|
+
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
|
+
await build({
|
|
16
|
+
entryPoints: [resolve(here, 'src/main.ts')],
|
|
17
|
+
outfile: resolve(here, 'dist/main.mjs'),
|
|
18
|
+
bundle: true,
|
|
19
|
+
packages: undefined,
|
|
20
|
+
external: ['@nativescript/windows-napi'],
|
|
21
|
+
nodePaths: [resolve(here, 'node_modules')],
|
|
22
|
+
platform: 'node',
|
|
23
|
+
target: 'node22',
|
|
24
|
+
format: 'esm',
|
|
25
|
+
sourcemap: true,
|
|
26
|
+
define: {
|
|
27
|
+
'process.env.NODE_ENV': '"production"',
|
|
28
|
+
__VUE_OPTIONS_API__: 'true',
|
|
29
|
+
__VUE_PROD_DEVTOOLS__: 'false',
|
|
30
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
|
|
31
|
+
},
|
|
32
|
+
alias: {
|
|
33
|
+
'#mavis': resolve(here, 'src/components.ts'),
|
|
34
|
+
'#shared-ui': resolve(here, '__MAVIS_SHARED_ROOT__'),
|
|
35
|
+
'#desktop-host': resolve(here, 'src/host.mjs'),
|
|
36
|
+
vue: resolve(here, 'node_modules/vue/dist/vue.runtime.esm-bundler.js'),
|
|
37
|
+
'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
|
+
},
|
|
42
|
+
plugins: [
|
|
43
|
+
{
|
|
44
|
+
name: 'shared-vue-screens',
|
|
45
|
+
setup(build) {
|
|
46
|
+
build.onLoad({ filter: /\.vue$/ }, async ({ path }) => {
|
|
47
|
+
const source = await readFile(path, 'utf8')
|
|
48
|
+
const { descriptor, errors } = parse(source, { filename: path })
|
|
49
|
+
if (errors.length) throw errors[0]
|
|
50
|
+
const id = createHash('sha256').update(path).digest('hex').slice(0, 8)
|
|
51
|
+
const script = compileScript(descriptor, { id, inlineTemplate: true })
|
|
52
|
+
return { contents: script.content, loader: 'ts', resolveDir: dirname(path) }
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
})
|
|
58
|
+
console.log('Built __MAVIS_NAME__ from shared Vue screens.')
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { defineComponent, h, inject } from 'vue'
|
|
2
|
+
import { routerKey } from 'vue-router'
|
|
3
|
+
|
|
4
|
+
function component(name: string, tag: string) {
|
|
5
|
+
return defineComponent({
|
|
6
|
+
name,
|
|
7
|
+
inheritAttrs: false,
|
|
8
|
+
setup(_props, { attrs, slots }) {
|
|
9
|
+
return () => h(tag, attrs, slots.default?.())
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
function action(name: string, tag: string) {
|
|
14
|
+
return defineComponent({
|
|
15
|
+
name,
|
|
16
|
+
inheritAttrs: false,
|
|
17
|
+
setup(_props, { attrs, slots }) {
|
|
18
|
+
const router = inject(routerKey, null)
|
|
19
|
+
return () =>
|
|
20
|
+
h(
|
|
21
|
+
tag,
|
|
22
|
+
{
|
|
23
|
+
...attrs,
|
|
24
|
+
onClick: () => {
|
|
25
|
+
if (attrs.disabled || attrs.loading) return
|
|
26
|
+
const listeners = Array.isArray(attrs.onClick) ? attrs.onClick : [attrs.onClick]
|
|
27
|
+
for (const listener of listeners) if (typeof listener === 'function') listener()
|
|
28
|
+
if (typeof attrs.href === 'string') void router?.push(attrs.href)
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
slots.default?.(),
|
|
32
|
+
)
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
export const MScreen = component('MScreen', 'screen')
|
|
37
|
+
export const MColumn = component('MColumn', 'column')
|
|
38
|
+
export const MRow = component('MRow', 'row')
|
|
39
|
+
export const MGrid = component('MGrid', 'grid')
|
|
40
|
+
export const MText = component('MText', 'text')
|
|
41
|
+
export const MInput = component('MInput', 'input')
|
|
42
|
+
export const MReveal = component('MReveal', 'reveal')
|
|
43
|
+
export const MButton = action('MButton', 'button')
|
|
44
|
+
export const MLink = action('MLink', 'link')
|
|
45
|
+
export const MCard = action('MCard', 'card')
|
|
46
|
+
function message(name: string) {
|
|
47
|
+
return defineComponent({
|
|
48
|
+
name,
|
|
49
|
+
inheritAttrs: false,
|
|
50
|
+
setup(_props, { attrs }) {
|
|
51
|
+
return () =>
|
|
52
|
+
h('column', { id: attrs.id, padding: 'md', gap: 'sm' }, [
|
|
53
|
+
h('text', { variant: 'heading', tone: attrs.tone }, String(attrs.title ?? '')),
|
|
54
|
+
h('text', { tone: 'muted' }, String(attrs.description ?? '')),
|
|
55
|
+
])
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
export const MAlert = message('MAlert')
|
|
60
|
+
export const MEmptyState = message('MEmptyState')
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The deliberately bounded contract shared by adoption diagnostics and both native hosts. */
|
|
2
|
+
export const desktopComponents = Object.freeze({
|
|
3
|
+
MScreen: { tag: 'screen', props: ['scroll'] },
|
|
4
|
+
MColumn: { tag: 'column', props: ['padding', 'gap'] },
|
|
5
|
+
MRow: { tag: 'row', props: ['padding', 'gap'] },
|
|
6
|
+
MGrid: { tag: 'grid', props: ['minColumnWidth', 'gap'] },
|
|
7
|
+
MText: { tag: 'text', props: ['text', 'as', 'variant', 'tone'] },
|
|
8
|
+
MInput: {
|
|
9
|
+
tag: 'input',
|
|
10
|
+
props: [
|
|
11
|
+
'modelValue',
|
|
12
|
+
'label',
|
|
13
|
+
'placeholder',
|
|
14
|
+
'readonly',
|
|
15
|
+
'disabled',
|
|
16
|
+
'onUpdate:modelValue',
|
|
17
|
+
'onSubmit',
|
|
18
|
+
'onEscape',
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
MReveal: { tag: 'reveal', props: ['show'] },
|
|
22
|
+
MButton: {
|
|
23
|
+
tag: 'button',
|
|
24
|
+
props: ['href', 'text', 'loading', 'loadingText', 'disabled', 'onClick'],
|
|
25
|
+
macos: ['shortcut'],
|
|
26
|
+
},
|
|
27
|
+
MLink: { tag: 'link', props: ['href', 'text', 'disabled', 'onClick'] },
|
|
28
|
+
MCard: { tag: 'card', props: ['href', 'padding', 'gap', 'onClick', 'disabled'] },
|
|
29
|
+
MAlert: { tag: null, props: ['title', 'description', 'tone'] },
|
|
30
|
+
MEmptyState: { tag: null, props: ['title', 'description'] },
|
|
31
|
+
})
|
|
32
|
+
export function nativeProps(kind, target) {
|
|
33
|
+
const component = Object.values(desktopComponents).find((component) => component.tag === kind)
|
|
34
|
+
return ['id', 'accessibilityLabel', ...(component?.props ?? []), ...(component?.[target] ?? [])]
|
|
35
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createRenderer } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** Vue owns the tree; a desktop host owns native views, geometry and event delivery. */
|
|
4
|
+
export interface NativeNode {
|
|
5
|
+
kind: string
|
|
6
|
+
text: string
|
|
7
|
+
props: Record<string, any>
|
|
8
|
+
children: NativeNode[]
|
|
9
|
+
parent: NativeNode | null
|
|
10
|
+
native?: any
|
|
11
|
+
content?: any
|
|
12
|
+
dispose?: () => void
|
|
13
|
+
}
|
|
14
|
+
export interface NativeHost {
|
|
15
|
+
create(kind: string): NativeNode
|
|
16
|
+
update(node: NativeNode): void
|
|
17
|
+
attach(node: NativeNode, parent: NativeNode): void
|
|
18
|
+
detach(node: NativeNode): void
|
|
19
|
+
layout(): void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function desktopRenderer(host: NativeHost) {
|
|
23
|
+
const remove = (node: NativeNode) => {
|
|
24
|
+
for (const child of [...node.children]) remove(child)
|
|
25
|
+
node.dispose?.()
|
|
26
|
+
host.detach(node)
|
|
27
|
+
const siblings = node.parent?.children
|
|
28
|
+
if (siblings) siblings.splice(siblings.indexOf(node), 1)
|
|
29
|
+
node.parent = null
|
|
30
|
+
host.layout()
|
|
31
|
+
}
|
|
32
|
+
return createRenderer<NativeNode, NativeNode>({
|
|
33
|
+
createElement: (kind) => host.create(kind),
|
|
34
|
+
createText(text) {
|
|
35
|
+
const node = host.create('#text')
|
|
36
|
+
node.text = text
|
|
37
|
+
return node
|
|
38
|
+
},
|
|
39
|
+
createComment: () => host.create('#comment'),
|
|
40
|
+
insert(node, parent, anchor) {
|
|
41
|
+
// A keyed move retains native view/delegate, first responder and animation.
|
|
42
|
+
if (node.parent) {
|
|
43
|
+
const siblings = node.parent.children
|
|
44
|
+
siblings.splice(siblings.indexOf(node), 1)
|
|
45
|
+
}
|
|
46
|
+
node.parent = parent
|
|
47
|
+
const index = anchor ? parent.children.indexOf(anchor) : -1
|
|
48
|
+
parent.children.splice(index < 0 ? parent.children.length : index, 0, node)
|
|
49
|
+
host.attach(node, parent)
|
|
50
|
+
host.update(parent)
|
|
51
|
+
host.layout()
|
|
52
|
+
},
|
|
53
|
+
remove,
|
|
54
|
+
setText(node, text) {
|
|
55
|
+
node.text = text
|
|
56
|
+
host.update(node.parent ?? node)
|
|
57
|
+
host.layout()
|
|
58
|
+
},
|
|
59
|
+
setElementText(node, text) {
|
|
60
|
+
for (const child of [...node.children]) remove(child)
|
|
61
|
+
node.text = text
|
|
62
|
+
host.update(node)
|
|
63
|
+
host.layout()
|
|
64
|
+
},
|
|
65
|
+
parentNode: (node) => node.parent,
|
|
66
|
+
nextSibling: (node) => {
|
|
67
|
+
const siblings = node.parent?.children ?? []
|
|
68
|
+
return siblings[siblings.indexOf(node) + 1] ?? null
|
|
69
|
+
},
|
|
70
|
+
patchProp(node, key, _old, value) {
|
|
71
|
+
node.props[key] = value
|
|
72
|
+
host.update(node)
|
|
73
|
+
host.layout()
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
const applicationData =
|
|
5
|
+
process.platform === 'win32'
|
|
6
|
+
? (process.env.LOCALAPPDATA ?? join(homedir(), 'AppData/Local'))
|
|
7
|
+
: join(homedir(), 'Library/Application Support')
|
|
8
|
+
export const storageFile =
|
|
9
|
+
process.env.MAVIS_DESKTOP_STORAGE ??
|
|
10
|
+
join(applicationData, '__MAVIS_NAME__', '__MAVIS_STORAGE_FILE__')
|
|
11
|
+
export function persistence(isClosed: () => boolean) {
|
|
12
|
+
return {
|
|
13
|
+
async read() {
|
|
14
|
+
try {
|
|
15
|
+
return await readFile(storageFile, 'utf8')
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null
|
|
18
|
+
throw error
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
async write(value: string) {
|
|
22
|
+
if (isClosed()) throw new Error('Window closed')
|
|
23
|
+
await mkdir(dirname(storageFile), { recursive: true })
|
|
24
|
+
const temporary = `${storageFile}.${process.pid}.tmp`
|
|
25
|
+
await writeFile(temporary, value, 'utf8')
|
|
26
|
+
await rename(temporary, storageFile)
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { h } from 'vue'
|
|
2
|
+
import { createRouter, createMemoryHistory, RouterView } from 'vue-router'
|
|
3
|
+
import { createHost } from '#desktop-host'
|
|
4
|
+
import { desktopRenderer } from './renderer'
|
|
5
|
+
import { persistence, storageFile } from './storage'
|
|
6
|
+
import { routes } from '#shared-ui/routes'
|
|
7
|
+
import { createDirectory, directoryKey } from '#shared-ui/directory-store'
|
|
8
|
+
import { createDirectoryStorage } from './directory-storage'
|
|
9
|
+
let application: ReturnType<ReturnType<typeof desktopRenderer>['createApp']>
|
|
10
|
+
const host = createHost({
|
|
11
|
+
title: '__MAVIS_NAME__',
|
|
12
|
+
onClose() {
|
|
13
|
+
application?.unmount()
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
const directory = createDirectory(createDirectoryStorage(persistence(() => host.closed)))
|
|
17
|
+
const router = createRouter({ history: createMemoryHistory(), routes })
|
|
18
|
+
application = desktopRenderer(host).createApp({ render: () => h(RouterView) })
|
|
19
|
+
application.use(router).provide(directoryKey, directory)
|
|
20
|
+
host.addMenu?.('Navigate', [
|
|
21
|
+
['Back', 'activate:', '[', () => router.back()],
|
|
22
|
+
['Forward', 'activate:', ']', () => router.forward()],
|
|
23
|
+
['All places', 'activate:', '1', () => router.push('/')],
|
|
24
|
+
])
|
|
25
|
+
await router.push('/')
|
|
26
|
+
await router.isReady()
|
|
27
|
+
host.setTheme('__MAVIS_THEME__' === 'midnight')
|
|
28
|
+
application.mount(host.root)
|
|
29
|
+
host.show()
|
|
30
|
+
await directory.restore()
|
|
31
|
+
if (process.env.MAVIS_DESKTOP_CHECK) {
|
|
32
|
+
const { pathToFileURL } = await import('node:url')
|
|
33
|
+
const { default: check } = await import(pathToFileURL(process.env.MAVIS_DESKTOP_CHECK).href)
|
|
34
|
+
await check({ host, application, storageFile, directory, router })
|
|
35
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process'
|
|
2
|
+
import { cpSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { dirname, join, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
if (process.platform !== 'darwin' || process.arch !== 'arm64')
|
|
8
|
+
throw new Error('Package on macOS arm64.')
|
|
9
|
+
if (Number(process.versions.node.split('.')[0]) < 22)
|
|
10
|
+
throw new Error('Build with Node 22 or newer.')
|
|
11
|
+
const output = resolve(here, 'artifacts/__MAVIS_NAME__.app')
|
|
12
|
+
rmSync(output, { recursive: true, force: true })
|
|
13
|
+
const macos = join(output, 'Contents/MacOS')
|
|
14
|
+
const resources = join(output, 'Contents/Resources')
|
|
15
|
+
mkdirSync(macos, { recursive: true })
|
|
16
|
+
mkdirSync(resources, { recursive: true })
|
|
17
|
+
cpSync(process.execPath, join(macos, 'node'))
|
|
18
|
+
cpSync(join(here, 'dist/main.mjs'), join(resources, 'dist/main.mjs'))
|
|
19
|
+
cpSync(join(here, 'launch.mjs'), join(resources, 'launch.mjs'))
|
|
20
|
+
cpSync(join(here, 'node_modules/@nativescript'), join(resources, 'node_modules/@nativescript'), {
|
|
21
|
+
recursive: true,
|
|
22
|
+
})
|
|
23
|
+
writeFileSync(
|
|
24
|
+
join(output, 'Contents/Info.plist'),
|
|
25
|
+
`<?xml version="1.0" encoding="UTF-8"?>
|
|
26
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
27
|
+
<plist version="1.0"><dict>
|
|
28
|
+
<key>CFBundleIdentifier</key><string>org.nativescript.__MAVIS_APPID__</string>
|
|
29
|
+
<key>CFBundleName</key><string>__MAVIS_NAME__</string>
|
|
30
|
+
<key>CFBundleExecutable</key><string>MavisDesktop</string>
|
|
31
|
+
<key>CFBundlePackageType</key><string>APPL</string>
|
|
32
|
+
<key>CFBundleVersion</key><string>1</string>
|
|
33
|
+
<key>CFBundleShortVersionString</key><string>0.0.1</string>
|
|
34
|
+
<key>LSMinimumSystemVersion</key><string>13.3</string>
|
|
35
|
+
<key>NSHighResolutionCapable</key><true/>
|
|
36
|
+
</dict></plist>
|
|
37
|
+
`,
|
|
38
|
+
)
|
|
39
|
+
// exec preserves signals/exit status. Every runtime path is relative to this app,
|
|
40
|
+
// so launching needs neither a globally installed Node nor an Edge/dev server.
|
|
41
|
+
const source = join(here, 'artifacts/launcher.c')
|
|
42
|
+
writeFileSync(
|
|
43
|
+
source,
|
|
44
|
+
`#include <mach-o/dyld.h>
|
|
45
|
+
#include <limits.h>
|
|
46
|
+
#include <libgen.h>
|
|
47
|
+
#include <stdio.h>
|
|
48
|
+
#include <stdlib.h>
|
|
49
|
+
#include <string.h>
|
|
50
|
+
#include <unistd.h>
|
|
51
|
+
int main(int argc, char **argv) {
|
|
52
|
+
char executable[PATH_MAX], node[PATH_MAX], script[PATH_MAX];
|
|
53
|
+
uint32_t size = sizeof(executable);
|
|
54
|
+
if (_NSGetExecutablePath(executable, &size) != 0) return 1;
|
|
55
|
+
char *directory = dirname(executable);
|
|
56
|
+
snprintf(node, sizeof(node), "%s/node", directory);
|
|
57
|
+
snprintf(script, sizeof(script), "%s/../Resources/launch.mjs", directory);
|
|
58
|
+
char **args = calloc((size_t)argc + 2, sizeof(char *));
|
|
59
|
+
if (!args) return 1;
|
|
60
|
+
args[0] = node; args[1] = script;
|
|
61
|
+
for (int i = 1; i < argc; i++) args[i + 1] = argv[i];
|
|
62
|
+
execv(node, args);
|
|
63
|
+
perror("__MAVIS_NAME__ launch");
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
`,
|
|
67
|
+
)
|
|
68
|
+
execFileSync(
|
|
69
|
+
'xcrun',
|
|
70
|
+
['clang', '-mmacosx-version-min=13.3', source, '-o', join(macos, 'MavisDesktop')],
|
|
71
|
+
{ stdio: 'inherit' },
|
|
72
|
+
)
|
|
73
|
+
const licenses = join(resources, 'Licenses')
|
|
74
|
+
mkdirSync(licenses)
|
|
75
|
+
for (const [name, path] of [
|
|
76
|
+
['Mavis', 'LICENSE'],
|
|
77
|
+
['Vue', 'node_modules/vue/LICENSE'],
|
|
78
|
+
['VueRouter', 'node_modules/vue-router/LICENSE'],
|
|
79
|
+
['Jolt', 'node_modules/@rafaelaugusto/jolt/LICENSE'],
|
|
80
|
+
['NativeScript', 'node_modules/@nativescript/macos-node-api/LICENSE'],
|
|
81
|
+
['NativeScriptObjC', 'node_modules/@nativescript/objc-node-api/LICENSE'],
|
|
82
|
+
])
|
|
83
|
+
cpSync(resolve(here, path), join(licenses, `${name}.txt`))
|
|
84
|
+
cpSync(resolve(dirname(process.execPath), '../LICENSE'), join(licenses, 'Node.txt'))
|
|
85
|
+
const native = join(
|
|
86
|
+
resources,
|
|
87
|
+
'node_modules/@nativescript/macos-node-api/build/RelWithDebInfo/NativeScript.apple.node/macos-arm64/NativeScript.framework',
|
|
88
|
+
)
|
|
89
|
+
// npm omits symlinks. Reconstruct the versioned framework layout in the copy
|
|
90
|
+
// before codesigning; the installed dependency is never modified.
|
|
91
|
+
symlinkSync('A', join(native, 'Versions/Current'))
|
|
92
|
+
for (const entry of ['NativeScript', 'Resources', 'Headers'])
|
|
93
|
+
symlinkSync(`Versions/Current/${entry}`, join(native, entry))
|
|
94
|
+
for (const target of [native, join(macos, 'node'), join(macos, 'MavisDesktop'), output])
|
|
95
|
+
execFileSync('codesign', ['--force', '--sign', '-', target], { stdio: 'inherit' })
|
|
96
|
+
execFileSync('codesign', ['--verify', '--deep', '--strict', output], { stdio: 'inherit' })
|
|
97
|
+
writeFileSync(
|
|
98
|
+
join(here, 'artifacts/package.json'),
|
|
99
|
+
JSON.stringify(
|
|
100
|
+
{
|
|
101
|
+
app: output,
|
|
102
|
+
node: process.version,
|
|
103
|
+
runtime: JSON.parse(
|
|
104
|
+
readFileSync(join(here, 'node_modules/@nativescript/macos-node-api/package.json'), 'utf8'),
|
|
105
|
+
).version,
|
|
106
|
+
arch: process.arch,
|
|
107
|
+
minimumMacOS: '13.3',
|
|
108
|
+
signing: 'ad-hoc; not notarized',
|
|
109
|
+
},
|
|
110
|
+
null,
|
|
111
|
+
2,
|
|
112
|
+
) + '\n',
|
|
113
|
+
)
|
|
114
|
+
console.log(output)
|