@getcortexlabs/create-mavis 0.1.0-rc.13 → 0.1.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -7
- package/package.json +4 -2
- package/src/adapters.mjs +56 -20
- package/src/add-desktop.mjs +308 -0
- package/src/add-macos.mjs +386 -0
- package/src/capabilities.mjs +352 -85
- package/src/cli.mjs +181 -9
- package/src/desktop.mjs +155 -0
- package/src/doctor.mjs +181 -18
- package/src/macos-capabilities.generated.mjs +4190 -0
- package/src/macos.mjs +147 -29
- package/src/migrate-directory.mjs +121 -0
- package/src/native-framework.mjs +144 -0
- package/src/portability.mjs +123 -5
- package/src/scaffold.mjs +59 -11
- package/src/ui.mjs +69 -12
- package/templates/desktop/common/LICENSE +21 -0
- package/templates/desktop/common/build.mjs +58 -0
- package/templates/desktop/common/src/components.ts +60 -0
- package/templates/desktop/common/src/contract.mjs +35 -0
- package/templates/desktop/common/src/renderer.ts +76 -0
- package/templates/desktop/common/src/storage.ts +29 -0
- package/templates/desktop/directory/main.ts +35 -0
- package/templates/desktop/macos/launch.mjs +6 -0
- package/templates/desktop/macos/package.mjs +114 -0
- package/templates/desktop/macos/src/host.mjs +468 -0
- package/templates/desktop/macos/src/motion.mjs +51 -0
- package/templates/desktop/welcome/Welcome.vue +56 -0
- package/templates/desktop/welcome/main.ts +24 -0
- package/templates/desktop/windows/NativeScript-LICENSE +19 -0
- package/templates/desktop/windows/launch.mjs +16 -0
- package/templates/desktop/windows/package.mjs +54 -0
- package/templates/desktop/windows/prepare-host.mjs +73 -0
- package/templates/desktop/windows/src/host.mjs +277 -0
- package/templates/directory/host/directory-storage.ts +78 -0
- package/templates/directory/macos/DirectoryStorage.swift +68 -0
- package/templates/directory/mobile/src/app.ts +11 -8
- package/templates/directory/nuxt/app/plugins/mavis.ts +11 -8
- package/templates/directory/shared/Edit.vue +8 -5
- package/templates/directory/shared/directory-store.ts +42 -46
- package/templates/directory/vite/src/main.ts +11 -8
- package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +2 -2
- package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +2 -2
- package/templates/macos/examples/tasks/shared/types.ts +1 -0
- package/templates/macos/mobile/src/App.vue +4 -2
- package/templates/macos/native/Package.swift +3 -1
- package/templates/macos/native/Sources/MavisDesktop/App.swift +26 -11
- package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +45 -0
- package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
- package/templates/macos/scripts/generate.mjs +3 -26
- package/templates/macos/scripts/macos-manifest.mjs +33 -0
- package/templates/macos/scripts/macos.mjs +20 -18
- package/templates/macos/web/index.html +1 -1
- package/templates/macos/web/src/main.js +176 -3
- package/templates/macos/web/src/mavis.js +2 -0
- package/templates/macos/web/src/style.css +2 -1
- package/templates/macos/web/vite.config.mjs +12 -1
- package/templates/migrations/directory-rc13.json +36 -0
- package/templates/mobile/src/mavis.ts +2 -82
- package/templates/mobile/webpack.config.js +4 -0
- package/templates/native-framework/angular/screen.ts +84 -0
- package/templates/native-framework/common/nativescript.config.ts +6 -0
- package/templates/native-framework/common/src/app.ts +5 -0
- package/templates/native-framework/common/src/model.ts +40 -0
- package/templates/native-framework/common/src/references.d.ts +8 -0
- package/templates/native-framework/common/tsconfig.json +16 -0
- package/templates/native-framework/common/webpack.config.js +67 -0
- package/templates/native-framework/plain/screen.ts +102 -0
- package/templates/native-framework/react/screen.ts +83 -0
- package/templates/native-framework/solid/screen.ts +111 -0
- package/templates/native-framework/svelte/Welcome.svelte +26 -0
- package/templates/native-framework/svelte/screen.ts +14 -0
- package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
- package/templates/nuxt/app/mavis.ts +2 -84
- package/templates/vite/src/mavis.ts +2 -84
- package/templates/macos/scripts/portable/emit-swift.mjs +0 -1287
- package/templates/macos/scripts/portable/emit-vue.mjs +0 -615
- package/templates/macos/scripts/portable/index.mjs +0 -95
- package/templates/macos/scripts/portable/model.mjs +0 -1441
- package/templates/macos/scripts/portable/program.mjs +0 -163
|
@@ -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)
|