@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
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Create Mavis
|
|
2
2
|
|
|
3
|
-
Start a project for
|
|
3
|
+
Start a project for Web, NativeScript iOS/Android, AppKit macOS and XAML Windows. New desktop presets use shared Vue; select `--macos-runtime swiftui` to retain the compiler pipeline. Web projects use Vue + Vite or Nuxt with server rendering/static generation. Web and Native share a Vue screen and give each host its own service implementation; desktop hosts run Vue directly with an explicit native component subset.
|
|
4
4
|
|
|
5
5
|
Run `npm create @getcortexlabs/mavis@latest` for the interactive wizard, or pass a project name and options:
|
|
6
6
|
|
|
@@ -31,24 +31,61 @@ The wizard, package-manager selection and both examples are included in RC.12. R
|
|
|
31
31
|
|
|
32
32
|
Node.js 22.16+ is required. Native projects also need the NativeScript CLI and the platform SDK. iOS requires macOS and Xcode. A shared project keeps native dependencies separate from its Web workspace so each renderer loads the correct Vue runtime.
|
|
33
33
|
|
|
34
|
-
Templates pin **Mavis 0.1.0-rc.
|
|
34
|
+
Templates pin **Mavis 0.1.0-rc.15** and **Jolt 0.1.0-rc.17**. The CLI and its generated projects use the same Mavis release. Commit the generated lockfile (both lockfiles for a shared project).
|
|
35
35
|
|
|
36
36
|
pnpm requires **10.26+**. Its generated workspace files keep the mobile installation separate, use a hoisted layout for Vite deduplication, shared imports and NativeScript, and allow only the starter's required dependency build scripts. Yarn Classic and modern Yarn use `node_modules`; initial empty `yarn.lock` files mark separate projects before installation. The starter declares its dependency build scripts explicitly; other package-manager policies remain in effect. If modern Yarn reports a fresh dependency as quarantined, retry after its configured minimum package age. Do not add `apps/mobile` to the Web workspace.
|
|
37
37
|
|
|
38
|
-
React,
|
|
38
|
+
React, Angular, Svelte, Solid and plain JS/TS have direct iOS/Android starters (`--targets native --framework react`, or angular/svelte/solid/plain). Web and desktop presets use Vue. React Web, Next and SDUI remain planned. Shared Vue and TSX compilation for Mac is experimental. The creator reports unsupported choices instead of generating placeholder integrations.
|
|
39
39
|
|
|
40
40
|
MIT · [Mavis UI](https://github.com/getcortexlabs/mavis-ui)
|
|
41
41
|
|
|
42
|
+
## NativeScript desktop (RC.15)
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
create-mavis studio --targets macos,windows --example directory --no-install
|
|
46
|
+
cd studio
|
|
47
|
+
npm run install:apps
|
|
48
|
+
npm run macos # on macOS
|
|
49
|
+
npm run windows # on Windows
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
These experimental presets are included in RC.15. `--macos-runtime appkit` is the new default; `--target macos` keeps its legacy SwiftUI meaning. Desktop needs Node 22.23.3+. Mac uses Apple Silicon/macOS 13.3+; Windows uses Windows 10 build 18362+ and the Windows SDK. Run `--doctor` on each OS.
|
|
53
|
+
|
|
54
|
+
The initial desktop contract has 12 components with bounded props; `--capabilities --json` lists them. It does not imply the full Vue mobile catalog runs on desktop. Jolt Windows motion is pending upstream #519; Reveal changes visibility immediately on Windows. AppKit uses a private pinned finite-opacity integration.
|
|
55
|
+
|
|
56
|
+
Use `--add-macos` or `--add-windows` to preview an existing Vue app's desktop host; `--write` applies it. Source files stay in place. Install the new host's dependencies separately. Custom app providers/router remain application-owned. `package:macos` produces an ad hoc signed .app; `package:windows` produces an unsigned portable folder. Both include Node and native runtimes. See the [desktop guide](https://mavis-ui.getcortexlabs.com/guide/native-desktop) for exact coverage and distribution limits.
|
|
57
|
+
|
|
42
58
|
## Shared screens and portability
|
|
43
59
|
|
|
44
60
|
`#mavis` resolves shared named imports and types for Vue + Vite SPA, Nuxt SSR/SSG and NativeScript iOS/Android. The new `--example directory` adds shared search, details, editing, persistence and automatic navigation through an app-owned router adapter.
|
|
45
61
|
|
|
46
|
-
`--check-portability` reports platform dependencies with locations. `--fix-imports` previews safe named-import changes to `#mavis`; add `--write` to apply. `--path` selects a source directory and `--json` emits structured diagnostics. `--doctor` also runs this source audit. Unknown dependencies, HTML/CSS and device services still require review and target tests.
|
|
62
|
+
`--check-portability` reports platform dependencies with locations, and then, for each shared file, whether the experimental Mac target can compile it and why not. `--fix-imports` previews safe named-import changes to `#mavis`; add `--write` to apply. `--path` selects a source directory and `--json` emits structured diagnostics. `--doctor` also runs this source audit. Unknown dependencies, HTML/CSS and device services still require review and target tests.
|
|
47
63
|
|
|
48
64
|
## Add a host to an existing Mavis application (RC.12)
|
|
49
65
|
|
|
50
|
-
Run `create-mavis --add-native` in a Vue + Vite/Nuxt package, or `create-mavis --add-web [--web nuxt]` in a NativeScript-Vue package. Use `--dry-run` to inspect the plan and `--screen path/to/Screen.vue` to reuse an existing screen without moving it. The command creates an isolated host under `apps`, adds root launch/install scripts and preserves existing source/configuration/lockfiles. Dependencies install only with `--install`; npm, pnpm and Yarn are supported. Conflicts and unsupported workspaces/version baselines are reported before writing. The selected screen's services, aliases and router remain application-owned; portability diagnostics are not automatic conversion.
|
|
66
|
+
Run `create-mavis --add-native` in a Vue + Vite/Nuxt package, or `create-mavis --add-web [--web nuxt]` in a NativeScript-Vue package. Use `--dry-run` to inspect the plan and `--screen path/to/Screen.vue` to reuse an existing screen without moving it. The command creates an isolated host under `apps`, adds root launch/install scripts and preserves existing source/configuration/lockfiles. Dependencies install only with `--install`; npm, pnpm and Yarn are supported. Conflicts and unsupported workspaces/version baselines are reported before writing. The selected screen's services, aliases and router remain application-owned; portability diagnostics are not automatic conversion. Align the existing Mavis packages with the creator version before adding a host.
|
|
67
|
+
|
|
68
|
+
## Retained SwiftUI compiler
|
|
69
|
+
|
|
70
|
+
Experimental RC.14 includes Nuxt SSR/SSG with Mac, the shared Vue Directory example and `--add-macos`. Check the documented per-component and motion limits before adoption.
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
create-mavis studio --targets web,native,macos --macos-runtime swiftui --web nuxt --rendering ssr --example directory
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`--example directory` keeps the same Vue screens, typed store and route table across Web, NativeScript and SwiftUI. Welcome and Tasks use shared TSX. The compiler is the versioned `@getcortexlabs/mavis-compiler` package, pinned with Mavis; generated projects contain a small launcher instead of a copy of the compiler. The Web host remains Vue + Vite or Nuxt. Run the generated Mac script on macOS 14+ with Xcode. See the [supported source contracts](https://mavis-ui.getcortexlabs.com/guide/macos-experimental) and source diagnostics before adopting an existing screen.
|
|
77
|
+
|
|
78
|
+
## Add SwiftUI to an existing application
|
|
79
|
+
|
|
80
|
+
Run in the existing Web, NativeScript or combined project:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
create-mavis --add-macos --macos-runtime swiftui --shared-root src/shared --entry src/shared/screens/Home.vue
|
|
84
|
+
create-mavis --add-macos --macos-runtime swiftui --shared-root src/shared --entry src/shared/screens/Home.vue --write
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The first command is a preview. `--write` applies the reviewed plan; `--json` emits the plan for tools. Nested source folders stay in place. The command adds `apps/macos`, `generate:macos`, `build:macos` and `macos`, and migrates schema 1 configuration to schema 2. It preserves existing Web/native hosts and lockfiles, detects conflicts before writing, and never installs packages. Run your package manager after applying. `--shared-root` accepts comma-separated roots; `portability.roots`, `sourceRoot` and `entry` retain those choices.
|
|
51
88
|
|
|
52
|
-
|
|
89
|
+
For the unchanged RC.13 Directory template, `--add-macos --migrate-directory` previews the typed storage adapter migration; add `--write` to apply it. The migration requires exact original sources and host entries, preserves the stored JSON array and `mavis:directory` key, and rejects customized versions. It does not transfer stored data between devices. Directory's Swift host uses UserDefaults. Other app-owned service interfaces require explicit Swift implementations; the CLI reports these instead of inventing service behavior.
|
|
53
90
|
|
|
54
|
-
`
|
|
91
|
+
Set `macos.name`, `bundleId`, `icon` (project-relative `.icns`), `minWidth` and `minHeight` in `mavis.config.json`. `--doctor` checks installed compiler/Mavis alignment, the exact Jolt/JoltSwiftUI pin and shared-source diagnostics. Align dependencies first; adoption does not silently upgrade them. Signing, provisioning, notarization and store distribution are separate from this unsigned development build.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getcortexlabs/create-mavis",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.15",
|
|
4
4
|
"description": "Create Vue Web, Nuxt and NativeScript projects with Mavis UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"src",
|
|
11
11
|
"templates",
|
|
12
|
+
"!templates/macos/scripts/portable",
|
|
12
13
|
"README.md",
|
|
13
14
|
"LICENSE"
|
|
14
15
|
],
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@vue/compiler-sfc": "3.5.44",
|
|
31
32
|
"typescript": "6.0.3",
|
|
32
|
-
"@clack/prompts": "1.8.1"
|
|
33
|
+
"@clack/prompts": "1.8.1",
|
|
34
|
+
"@getcortexlabs/mavis-compiler": "0.1.0-rc.15"
|
|
33
35
|
}
|
|
34
36
|
}
|
package/src/adapters.mjs
CHANGED
|
@@ -16,6 +16,62 @@ export const adapters = {
|
|
|
16
16
|
status: 'experimental',
|
|
17
17
|
rendering: ['client'],
|
|
18
18
|
},
|
|
19
|
+
{
|
|
20
|
+
id: 'macos-swiftui',
|
|
21
|
+
framework: 'shared',
|
|
22
|
+
renderer: 'swiftui',
|
|
23
|
+
status: 'experimental',
|
|
24
|
+
rendering: ['client'],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 'vue-appkit',
|
|
28
|
+
framework: 'vue',
|
|
29
|
+
renderer: 'nativescript-appkit',
|
|
30
|
+
status: 'experimental',
|
|
31
|
+
rendering: ['client'],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'vue-windows',
|
|
35
|
+
framework: 'vue',
|
|
36
|
+
renderer: 'nativescript-xaml',
|
|
37
|
+
status: 'experimental',
|
|
38
|
+
rendering: ['client'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'react-nativescript',
|
|
42
|
+
framework: 'react',
|
|
43
|
+
renderer: 'nativescript',
|
|
44
|
+
status: 'experimental',
|
|
45
|
+
rendering: ['client'],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'angular-nativescript',
|
|
49
|
+
framework: 'angular',
|
|
50
|
+
renderer: 'nativescript',
|
|
51
|
+
status: 'experimental',
|
|
52
|
+
rendering: ['client'],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'svelte-nativescript',
|
|
56
|
+
framework: 'svelte',
|
|
57
|
+
renderer: 'nativescript',
|
|
58
|
+
status: 'experimental',
|
|
59
|
+
rendering: ['client'],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'solid-nativescript',
|
|
63
|
+
framework: 'solid',
|
|
64
|
+
renderer: 'nativescript',
|
|
65
|
+
status: 'experimental',
|
|
66
|
+
rendering: ['client'],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: 'typescript-nativescript',
|
|
70
|
+
framework: 'typescript',
|
|
71
|
+
renderer: 'nativescript',
|
|
72
|
+
status: 'experimental',
|
|
73
|
+
rendering: ['client'],
|
|
74
|
+
},
|
|
19
75
|
],
|
|
20
76
|
planned: [
|
|
21
77
|
{
|
|
@@ -38,26 +94,6 @@ export const adapters = {
|
|
|
38
94
|
id: 'solid-web',
|
|
39
95
|
issue: 154,
|
|
40
96
|
},
|
|
41
|
-
{
|
|
42
|
-
id: 'react-nativescript',
|
|
43
|
-
issue: 35,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
id: 'angular-nativescript',
|
|
47
|
-
issue: 36,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
id: 'svelte-nativescript',
|
|
51
|
-
issue: 37,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: 'solid-nativescript',
|
|
55
|
-
issue: 38,
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
id: 'typescript-nativescript',
|
|
59
|
-
issue: 39,
|
|
60
|
-
},
|
|
61
97
|
],
|
|
62
98
|
research: [
|
|
63
99
|
{
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { lstat, readFile, readdir } from 'node:fs/promises'
|
|
2
|
+
import { isAbsolute, join, relative, resolve, sep, dirname, extname } from 'node:path'
|
|
3
|
+
import { parse } from '@vue/compiler-sfc'
|
|
4
|
+
import { desktopHostFiles } from './desktop.mjs'
|
|
5
|
+
import { copyTemplate } from './scaffold.mjs'
|
|
6
|
+
import { migrateConfig, targetNames, versions } from './capabilities.mjs'
|
|
7
|
+
import { desktopComponents } from '../templates/desktop/common/src/contract.mjs'
|
|
8
|
+
import { packageCommands, detectPackageManager } from './package-manager.mjs'
|
|
9
|
+
import { applyMacos } from './add-macos.mjs'
|
|
10
|
+
const json = (value) => JSON.stringify(value, null, 2) + '\n'
|
|
11
|
+
const posix = (path) => path.split(sep).join('/')
|
|
12
|
+
async function safe(root, name) {
|
|
13
|
+
const path = resolve(root, name),
|
|
14
|
+
rel = relative(root, path)
|
|
15
|
+
if (!rel || isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`))
|
|
16
|
+
throw new Error('Desktop source paths must stay inside the project.')
|
|
17
|
+
let current = root
|
|
18
|
+
for (const part of rel.split(sep)) {
|
|
19
|
+
current = join(current, part)
|
|
20
|
+
try {
|
|
21
|
+
if ((await lstat(current)).isSymbolicLink()) throw new Error(`Refusing symlink: ${name}`)
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (error.code !== 'ENOENT') throw error
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return path
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function planDesktop(options, cwd = process.cwd()) {
|
|
30
|
+
const root = resolve(cwd),
|
|
31
|
+
original = new Map(),
|
|
32
|
+
files = new Map(),
|
|
33
|
+
diagnostics = []
|
|
34
|
+
const target = options.target
|
|
35
|
+
if (!['macos', 'windows'].includes(target))
|
|
36
|
+
throw new Error('Choose --add-macos or --add-windows.')
|
|
37
|
+
const read = async (name) => {
|
|
38
|
+
let value
|
|
39
|
+
try {
|
|
40
|
+
value = await readFile(await safe(root, name), 'utf8')
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error.code !== 'ENOENT') throw error
|
|
43
|
+
}
|
|
44
|
+
original.set(name, value)
|
|
45
|
+
return value
|
|
46
|
+
}
|
|
47
|
+
const pkg = JSON.parse(await read('package.json'))
|
|
48
|
+
const raw = await read('mavis.config.json')
|
|
49
|
+
const prior = raw ? migrateConfig(JSON.parse(raw)) : {}
|
|
50
|
+
if (prior.mode === 'portable' || prior.apps?.macos?.toolkit === 'swiftui')
|
|
51
|
+
throw new Error(
|
|
52
|
+
'This project uses the SwiftUI compiler. It is preserved; create a separate NativeScript desktop project or select --add-macos --macos-runtime swiftui.',
|
|
53
|
+
)
|
|
54
|
+
const manager =
|
|
55
|
+
options.packageManager ??
|
|
56
|
+
prior.packageManager ??
|
|
57
|
+
pkg.packageManager?.split('@')[0] ??
|
|
58
|
+
detectPackageManager()
|
|
59
|
+
const commands = packageCommands(manager)
|
|
60
|
+
const destination = `apps/${target}`
|
|
61
|
+
const marker = `${destination}/mavis.host.json`
|
|
62
|
+
const previous = await read(marker)
|
|
63
|
+
if (previous) {
|
|
64
|
+
const state = JSON.parse(previous)
|
|
65
|
+
if (
|
|
66
|
+
state.kind !== 'nativescript-desktop' ||
|
|
67
|
+
state.target !== target ||
|
|
68
|
+
(options.entry && state.entry !== options.entry)
|
|
69
|
+
)
|
|
70
|
+
throw new Error(`${destination} already belongs to another host configuration.`)
|
|
71
|
+
return {
|
|
72
|
+
root,
|
|
73
|
+
original,
|
|
74
|
+
files,
|
|
75
|
+
destination,
|
|
76
|
+
entry: state.entry,
|
|
77
|
+
manager,
|
|
78
|
+
diagnostics,
|
|
79
|
+
alreadyAdded: true,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
await lstat(await safe(root, destination))
|
|
84
|
+
throw new Error(`${destination} already exists; no files were changed.`)
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error.code !== 'ENOENT') throw error
|
|
87
|
+
}
|
|
88
|
+
const manifests = [pkg]
|
|
89
|
+
for (const name of [
|
|
90
|
+
'apps/web/package.json',
|
|
91
|
+
'apps/mobile/package.json',
|
|
92
|
+
'apps/macos/package.json',
|
|
93
|
+
'apps/windows/package.json',
|
|
94
|
+
]) {
|
|
95
|
+
const value = await read(name)
|
|
96
|
+
if (value) manifests.push(JSON.parse(value))
|
|
97
|
+
}
|
|
98
|
+
const dependencies = manifests.map((pkg) => ({ ...pkg.devDependencies, ...pkg.dependencies }))
|
|
99
|
+
if (
|
|
100
|
+
!dependencies.some(
|
|
101
|
+
(dep) =>
|
|
102
|
+
dep['@getcortexlabs/mavis-web'] ||
|
|
103
|
+
dep['@getcortexlabs/mavis'] ||
|
|
104
|
+
dep['@getcortexlabs/mavis-core'],
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
throw new Error('Desktop adoption needs an existing Mavis Vue project.')
|
|
108
|
+
for (const dep of dependencies)
|
|
109
|
+
for (const name of [
|
|
110
|
+
'@getcortexlabs/mavis-core',
|
|
111
|
+
'@getcortexlabs/mavis-web',
|
|
112
|
+
'@getcortexlabs/mavis',
|
|
113
|
+
])
|
|
114
|
+
if (
|
|
115
|
+
dep[name] &&
|
|
116
|
+
![versions.mavis, `^${versions.mavis}`, `~${versions.mavis}`].includes(dep[name])
|
|
117
|
+
)
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Align ${name} with this creator (${versions.mavis}) before adding desktop.`,
|
|
120
|
+
)
|
|
121
|
+
let roots = options.roots ?? prior.portability?.roots
|
|
122
|
+
if (!roots) {
|
|
123
|
+
roots = []
|
|
124
|
+
for (const candidate of ['shared', 'src/shared', 'app/shared']) {
|
|
125
|
+
try {
|
|
126
|
+
if ((await lstat(await safe(root, candidate))).isDirectory()) roots.push(candidate)
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (error.code !== 'ENOENT') throw error
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (roots.length !== 1)
|
|
133
|
+
throw new Error('Choose one --shared-root for the desktop entry and its shared imports.')
|
|
134
|
+
const sourceRoot = roots[0]
|
|
135
|
+
await safe(root, sourceRoot)
|
|
136
|
+
const entry =
|
|
137
|
+
options.entry ?? `${sourceRoot}/${prior.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
138
|
+
if (!entry.endsWith('.vue') || !(await read(entry)))
|
|
139
|
+
throw new Error('Choose an existing Vue component with --entry path/to/App.vue.')
|
|
140
|
+
const sources = new Map()
|
|
141
|
+
const inspect = async (folder) => {
|
|
142
|
+
for (const item of await readdir(await safe(root, folder), { withFileTypes: true })) {
|
|
143
|
+
const name = posix(join(folder, item.name))
|
|
144
|
+
await safe(root, name)
|
|
145
|
+
if (item.isDirectory()) {
|
|
146
|
+
if (!['node_modules', '.git', 'dist'].includes(item.name)) await inspect(name)
|
|
147
|
+
} else if (/\.(vue|ts|js|mjs)$/.test(name)) sources.set(name, await read(name))
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
await inspect(sourceRoot)
|
|
151
|
+
const entryRelative = relative(resolve(root, sourceRoot), resolve(root, entry))
|
|
152
|
+
if (entryRelative.startsWith('..') || isAbsolute(entryRelative))
|
|
153
|
+
throw new Error('--entry must be inside --shared-root.')
|
|
154
|
+
for (const [file, source] of sources) {
|
|
155
|
+
for (const match of source.matchAll(/import\s*\{([^}]+)\}\s*from\s*['"]#mavis['"]/g))
|
|
156
|
+
for (const name of match[1].split(',').map((name) => name.trim().split(/\s+as\s+/)[0]))
|
|
157
|
+
if (name && !(name in desktopComponents))
|
|
158
|
+
diagnostics.push(`${file}: ${name} is outside the NativeScript desktop subset.`)
|
|
159
|
+
if (!file.endsWith('.vue')) continue
|
|
160
|
+
const { descriptor, errors } = parse(source, { filename: file })
|
|
161
|
+
if (errors.length) throw errors[0]
|
|
162
|
+
if (descriptor.styles.length)
|
|
163
|
+
diagnostics.push(
|
|
164
|
+
`${file}: CSS styles need a native desktop implementation; use the supported layout and theme props.`,
|
|
165
|
+
)
|
|
166
|
+
const visit = (node) => {
|
|
167
|
+
if (node.type === 1) {
|
|
168
|
+
const key = Object.keys(desktopComponents).find(
|
|
169
|
+
(name) =>
|
|
170
|
+
name === node.tag ||
|
|
171
|
+
name.replace(/[A-Z]/g, (c, i) => (i ? '-' : '') + c.toLowerCase()) === node.tag,
|
|
172
|
+
)
|
|
173
|
+
if (key) {
|
|
174
|
+
const component = desktopComponents[key]
|
|
175
|
+
const props = [
|
|
176
|
+
'id',
|
|
177
|
+
'key',
|
|
178
|
+
'ref',
|
|
179
|
+
'accessibilityLabel',
|
|
180
|
+
...component.props,
|
|
181
|
+
...(component[target] ?? []),
|
|
182
|
+
]
|
|
183
|
+
for (const prop of node.props) {
|
|
184
|
+
let name = prop.name
|
|
185
|
+
if (prop.type === 7) {
|
|
186
|
+
if (prop.modifiers.length) {
|
|
187
|
+
diagnostics.push(
|
|
188
|
+
`${file}:${prop.loc.start.line}: v-${name} modifiers need an explicit desktop implementation.`,
|
|
189
|
+
)
|
|
190
|
+
continue
|
|
191
|
+
}
|
|
192
|
+
if (['if', 'else', 'else-if', 'for', 'once', 'memo'].includes(name)) continue
|
|
193
|
+
if (name === 'model' && !prop.arg && !prop.modifiers.length) {
|
|
194
|
+
name = 'modelValue'
|
|
195
|
+
} else if (name === 'bind' && prop.arg?.isStatic) name = prop.arg.content
|
|
196
|
+
else if (name === 'on' && prop.arg?.isStatic)
|
|
197
|
+
name = 'on' + prop.arg.content[0].toUpperCase() + prop.arg.content.slice(1)
|
|
198
|
+
else {
|
|
199
|
+
diagnostics.push(
|
|
200
|
+
`${file}:${prop.loc.start.line}: dynamic bindings or directive v-${name} need an explicit desktop implementation.`,
|
|
201
|
+
)
|
|
202
|
+
continue
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (!props.includes(name))
|
|
206
|
+
diagnostics.push(
|
|
207
|
+
`${file}:${prop.loc.start.line}: ${key}.${name} is outside the ${target} subset.`,
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
} else if (
|
|
211
|
+
/^[Mm][-A-Z]/.test(node.tag) ||
|
|
212
|
+
(node.tagType === 0 && !['template', 'slot'].includes(node.tag))
|
|
213
|
+
)
|
|
214
|
+
diagnostics.push(
|
|
215
|
+
`${file}:${node.loc.start.line}: ${node.tag} is not implemented on desktop.`,
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
for (const child of node.children ?? []) visit(child)
|
|
219
|
+
}
|
|
220
|
+
if (descriptor.template?.ast) visit(descriptor.template.ast)
|
|
221
|
+
}
|
|
222
|
+
if (diagnostics.length)
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Desktop adoption cannot reuse these sources yet:\n${diagnostics.join('\n')}\nNo files changed. Keep the existing app and adapt a separate shared entry to the declared subset.`,
|
|
225
|
+
)
|
|
226
|
+
const name = String(prior.name ?? pkg.name ?? 'mavis-app')
|
|
227
|
+
.replace(/^@[^/]+\//, '')
|
|
228
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
229
|
+
.slice(0, 64)
|
|
230
|
+
const directory =
|
|
231
|
+
prior.example === 'directory' &&
|
|
232
|
+
entry.endsWith('/Directory.vue') &&
|
|
233
|
+
sources.has(`${sourceRoot}/routes.ts`)
|
|
234
|
+
const preset = {
|
|
235
|
+
name,
|
|
236
|
+
theme: prior.theme ?? 'mavis',
|
|
237
|
+
packageManager: manager,
|
|
238
|
+
example: directory ? 'directory' : 'welcome',
|
|
239
|
+
}
|
|
240
|
+
const hostFiles = await desktopHostFiles(
|
|
241
|
+
preset,
|
|
242
|
+
target,
|
|
243
|
+
copyTemplate,
|
|
244
|
+
posix(relative(resolve(root, destination), resolve(root, sourceRoot))),
|
|
245
|
+
)
|
|
246
|
+
if (!directory) {
|
|
247
|
+
hostFiles.set(
|
|
248
|
+
'src/main.ts',
|
|
249
|
+
`import { createHost } from '#desktop-host'\nimport { desktopRenderer } from './renderer'\nimport Entry from '#shared-ui/${posix(entryRelative)}'\nimport * as components from './components'\nlet app\nconst host = createHost({ title: ${JSON.stringify(name)}, onClose() { app?.unmount() } })\napp = desktopRenderer(host).createApp(Entry)\nfor (const [name, component] of Object.entries(components)) app.component(name, component)\n// Install application-specific providers and routing here before mounting.\nhost.setTheme(${JSON.stringify(preset.theme)} === 'midnight')\napp.mount(host.root)\nhost.show()\n`,
|
|
250
|
+
)
|
|
251
|
+
diagnostics.push(
|
|
252
|
+
`Review ${destination}/src/main.ts to install any application-specific providers or router before mounting.`,
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
hostFiles.set(
|
|
256
|
+
'mavis.host.json',
|
|
257
|
+
json({ schemaVersion: 1, kind: 'nativescript-desktop', target, entry }),
|
|
258
|
+
)
|
|
259
|
+
for (const [path, value] of hostFiles) {
|
|
260
|
+
const file = posix(join(destination, path))
|
|
261
|
+
if ((await read(file)) !== undefined) throw new Error(`Refusing to overwrite ${file}.`)
|
|
262
|
+
files.set(file, value)
|
|
263
|
+
}
|
|
264
|
+
const scripts = {
|
|
265
|
+
[target]: commands.run('dev', destination),
|
|
266
|
+
[`build:${target}`]: commands.run('build', destination),
|
|
267
|
+
[`package:${target}`]: commands.run('package', destination),
|
|
268
|
+
}
|
|
269
|
+
for (const [key, value] of Object.entries(scripts))
|
|
270
|
+
if (pkg.scripts?.[key] && pkg.scripts[key] !== value)
|
|
271
|
+
throw new Error(`The existing ${key} script conflicts with this host.`)
|
|
272
|
+
files.set('package.json', json({ ...pkg, scripts: { ...pkg.scripts, ...scripts } }))
|
|
273
|
+
const targets = targetNames.filter(
|
|
274
|
+
(name) =>
|
|
275
|
+
name === target ||
|
|
276
|
+
prior.targets?.includes(name) ||
|
|
277
|
+
(name === 'web' && dependencies.some((dep) => dep['@getcortexlabs/mavis-web'])) ||
|
|
278
|
+
(name === 'native' && dependencies.some((dep) => dep['@getcortexlabs/mavis'])),
|
|
279
|
+
)
|
|
280
|
+
files.set(
|
|
281
|
+
'mavis.config.json',
|
|
282
|
+
json({
|
|
283
|
+
...prior,
|
|
284
|
+
schemaVersion: 2,
|
|
285
|
+
name,
|
|
286
|
+
targets,
|
|
287
|
+
framework: 'vue',
|
|
288
|
+
authoring: 'vue',
|
|
289
|
+
mode: 'direct',
|
|
290
|
+
execution: 'components',
|
|
291
|
+
packageManager: manager,
|
|
292
|
+
...(targets.includes('macos') ? { macosRuntime: 'appkit' } : {}),
|
|
293
|
+
apps: {
|
|
294
|
+
...prior.apps,
|
|
295
|
+
[target]: {
|
|
296
|
+
toolkit: target === 'macos' ? 'nativescript-appkit' : 'nativescript-xaml',
|
|
297
|
+
framework: 'vue',
|
|
298
|
+
runtime: target === 'macos' ? versions.macosNodeApi : versions.windowsNapi,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
desktop: { ...prior.desktop, existing: true },
|
|
302
|
+
versions: { ...prior.versions, ...versions },
|
|
303
|
+
}),
|
|
304
|
+
)
|
|
305
|
+
return { root, original, files, destination, entry, manager, diagnostics, alreadyAdded: false }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export const applyDesktop = applyMacos
|