@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/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,14 +31,30 @@ 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.
|
|
@@ -49,23 +65,23 @@ MIT · [Mavis UI](https://github.com/getcortexlabs/mavis-ui)
|
|
|
49
65
|
|
|
50
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.
|
|
51
67
|
|
|
52
|
-
##
|
|
68
|
+
## Retained SwiftUI compiler
|
|
53
69
|
|
|
54
|
-
Experimental RC.14 includes Nuxt SSR/SSG with Mac, the shared Vue Directory example and `--add-macos`.
|
|
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.
|
|
55
71
|
|
|
56
72
|
```sh
|
|
57
|
-
create-mavis studio --targets web,native,macos --web nuxt --rendering ssr --example directory
|
|
73
|
+
create-mavis studio --targets web,native,macos --macos-runtime swiftui --web nuxt --rendering ssr --example directory
|
|
58
74
|
```
|
|
59
75
|
|
|
60
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.
|
|
61
77
|
|
|
62
|
-
## Add
|
|
78
|
+
## Add SwiftUI to an existing application
|
|
63
79
|
|
|
64
80
|
Run in the existing Web, NativeScript or combined project:
|
|
65
81
|
|
|
66
82
|
```sh
|
|
67
|
-
create-mavis --add-macos --shared-root src/shared --entry src/shared/screens/Home.vue
|
|
68
|
-
create-mavis --add-macos --shared-root src/shared --entry src/shared/screens/Home.vue --write
|
|
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
|
|
69
85
|
```
|
|
70
86
|
|
|
71
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.
|
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": {
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"@vue/compiler-sfc": "3.5.44",
|
|
32
32
|
"typescript": "6.0.3",
|
|
33
33
|
"@clack/prompts": "1.8.1",
|
|
34
|
-
"@getcortexlabs/mavis-compiler": "0.1.0-rc.
|
|
34
|
+
"@getcortexlabs/mavis-compiler": "0.1.0-rc.15"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/adapters.mjs
CHANGED
|
@@ -23,6 +23,55 @@ export const adapters = {
|
|
|
23
23
|
status: 'experimental',
|
|
24
24
|
rendering: ['client'],
|
|
25
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
|
+
},
|
|
26
75
|
],
|
|
27
76
|
planned: [
|
|
28
77
|
{
|
|
@@ -45,26 +94,6 @@ export const adapters = {
|
|
|
45
94
|
id: 'solid-web',
|
|
46
95
|
issue: 154,
|
|
47
96
|
},
|
|
48
|
-
{
|
|
49
|
-
id: 'react-nativescript',
|
|
50
|
-
issue: 35,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: 'angular-nativescript',
|
|
54
|
-
issue: 36,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
id: 'svelte-nativescript',
|
|
58
|
-
issue: 37,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
id: 'solid-nativescript',
|
|
62
|
-
issue: 38,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: 'typescript-nativescript',
|
|
66
|
-
issue: 39,
|
|
67
|
-
},
|
|
68
97
|
],
|
|
69
98
|
research: [
|
|
70
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
|
package/src/add-macos.mjs
CHANGED
|
@@ -103,9 +103,9 @@ export async function planMacos(options = {}, cwd = process.cwd()) {
|
|
|
103
103
|
),
|
|
104
104
|
]
|
|
105
105
|
const jolt = jolts[0] ?? prior.versions?.jolt
|
|
106
|
-
if (jolts.length > 1 || !exact(jolt) || jolt !==
|
|
106
|
+
if (jolts.length > 1 || !exact(jolt) || jolt !== versions.jolt)
|
|
107
107
|
throw new Error(
|
|
108
|
-
`Pin every existing Jolt dependency to ${
|
|
108
|
+
`Pin every existing Jolt dependency to ${versions.jolt}, the JavaScript version supported by this creator. The separate SwiftUI package uses ${joltSwift.version}. Current: ${jolts.join(', ') || jolt || 'missing'}.`,
|
|
109
109
|
)
|
|
110
110
|
const manager =
|
|
111
111
|
options.packageManager ??
|
|
@@ -270,7 +270,7 @@ export async function planMacos(options = {}, cwd = process.cwd()) {
|
|
|
270
270
|
.replaceAll('__MAVIS_MAC_MIN_WIDTH__', String(settings.minWidth))
|
|
271
271
|
.replaceAll('__MAVIS_MAC_DEFAULT_WIDTH__', String(Math.max(860, settings.minWidth)))
|
|
272
272
|
.replaceAll('__MAVIS_MAC_WIDTH__', '1120')
|
|
273
|
-
.replaceAll('__MAVIS_JOLT_SWIFT__',
|
|
273
|
+
.replaceAll('__MAVIS_JOLT_SWIFT__', joltSwift.version)
|
|
274
274
|
await copy(files, 'macos/native', 'apps/macos', replace)
|
|
275
275
|
const appPath = 'apps/macos/Sources/MavisDesktop/App.swift'
|
|
276
276
|
let app = files
|