@getcortexlabs/create-mavis 0.1.0-rc.14 → 0.1.0-rc.16
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 +21 -28
- package/package.json +2 -4
- package/src/adapters.mjs +45 -23
- package/src/add-desktop.mjs +354 -0
- package/src/capabilities.mjs +233 -134
- package/src/cli.mjs +64 -60
- package/src/desktop.mjs +155 -0
- package/src/doctor.mjs +77 -108
- package/src/native-framework.mjs +144 -0
- package/src/portability.mjs +7 -106
- package/src/scaffold.mjs +36 -12
- package/src/shared-api.mjs +3 -0
- package/src/ui.mjs +30 -42
- package/templates/desktop/common/LICENSE +21 -0
- package/templates/desktop/common/build.mjs +49 -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 +471 -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 +294 -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/add-macos.mjs +0 -386
- package/src/macos-capabilities.generated.mjs +0 -4190
- package/src/macos.mjs +0 -394
- package/src/migrate-directory.mjs +0 -121
- package/templates/directory/macos/DirectoryStorage.swift +0 -68
- package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +0 -57
- package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +0 -33
- package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +0 -251
- package/templates/macos/examples/tasks/shared/types.ts +0 -10
- package/templates/macos/mobile/src/App.vue +0 -14
- package/templates/macos/mobile/src/app.ts +0 -7
- package/templates/macos/native/Package.swift +0 -19
- package/templates/macos/native/Sources/MavisDesktop/App.swift +0 -35
- package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +0 -45
- package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
- package/templates/macos/root/tsconfig.json +0 -14
- package/templates/macos/scripts/generate.mjs +0 -13
- package/templates/macos/scripts/macos-manifest.mjs +0 -33
- package/templates/macos/scripts/macos.mjs +0 -58
- package/templates/macos/shared/Welcome.lite.tsx +0 -42
- package/templates/macos/web/index.html +0 -12
- package/templates/macos/web/src/main.js +0 -212
- package/templates/macos/web/src/mavis.js +0 -2
- package/templates/macos/web/src/style.css +0 -14
- package/templates/macos/web/vite.config.mjs +0 -14
- package/templates/migrations/directory-rc13.json +0 -36
package/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. The desktop presets run shared Vue. 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
|
|
|
@@ -21,7 +21,7 @@ pnpm install
|
|
|
21
21
|
pnpm run dev
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Use `--capabilities` to list supported frameworks, platforms and examples.
|
|
25
25
|
|
|
26
26
|
- `--dry-run` prints the file plan without writing or installing.
|
|
27
27
|
- Existing directories are never merged or overwritten.
|
|
@@ -31,45 +31,38 @@ 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.16** and **Jolt 0.1.0-rc.18**. 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
|
-
##
|
|
43
|
-
|
|
44
|
-
`#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
|
-
|
|
46
|
-
`--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
|
-
|
|
48
|
-
## Add a host to an existing Mavis application (RC.12)
|
|
49
|
-
|
|
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. Align the existing Mavis packages with the creator version before adding a host.
|
|
51
|
-
|
|
52
|
-
## Experimental shared sources with Mac
|
|
53
|
-
|
|
54
|
-
Experimental RC.14 includes Nuxt SSR/SSG with Mac, the shared Vue Directory example and `--add-macos`. Mac parity issues #338–#354 remain open; check the documented per-component and motion limits before adoption.
|
|
42
|
+
## NativeScript desktop (RC.15)
|
|
55
43
|
|
|
56
44
|
```sh
|
|
57
|
-
create-mavis studio --targets
|
|
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
|
|
58
50
|
```
|
|
59
51
|
|
|
60
|
-
|
|
52
|
+
These experimental presets are included in RC.15. The macOS runtime is NativeScript AppKit. 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.
|
|
61
53
|
|
|
62
|
-
|
|
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. MReveal uses the public Jolt AppKit and Windows drivers to fade in with system motion preferences.
|
|
63
55
|
|
|
64
|
-
|
|
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.
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```
|
|
58
|
+
## Shared screens and portability
|
|
59
|
+
|
|
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.
|
|
70
61
|
|
|
71
|
-
|
|
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.
|
|
72
63
|
|
|
73
|
-
|
|
64
|
+
## Add a host to an existing Mavis application (RC.12)
|
|
65
|
+
|
|
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.
|
|
74
67
|
|
|
75
|
-
|
|
68
|
+
The former SwiftUI target is preserved on [archive/swiftui](https://github.com/getcortexlabs/mavis-ui/tree/archive/swiftui).
|
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.16",
|
|
4
4
|
"description": "Create Vue Web, Nuxt and NativeScript projects with Mavis UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"src",
|
|
11
11
|
"templates",
|
|
12
|
-
"!templates/macos/scripts/portable",
|
|
13
12
|
"README.md",
|
|
14
13
|
"LICENSE"
|
|
15
14
|
],
|
|
@@ -30,7 +29,6 @@
|
|
|
30
29
|
"dependencies": {
|
|
31
30
|
"@vue/compiler-sfc": "3.5.44",
|
|
32
31
|
"typescript": "6.0.3",
|
|
33
|
-
"@clack/prompts": "1.8.1"
|
|
34
|
-
"@getcortexlabs/mavis-compiler": "0.1.0-rc.14"
|
|
32
|
+
"@clack/prompts": "1.8.1"
|
|
35
33
|
}
|
|
36
34
|
}
|
package/src/adapters.mjs
CHANGED
|
@@ -17,9 +17,51 @@ export const adapters = {
|
|
|
17
17
|
rendering: ['client'],
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
id: '
|
|
21
|
-
framework: '
|
|
22
|
-
renderer: '
|
|
20
|
+
id: 'vue-appkit',
|
|
21
|
+
framework: 'vue',
|
|
22
|
+
renderer: 'nativescript-appkit',
|
|
23
|
+
status: 'experimental',
|
|
24
|
+
rendering: ['client'],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 'vue-windows',
|
|
28
|
+
framework: 'vue',
|
|
29
|
+
renderer: 'nativescript-xaml',
|
|
30
|
+
status: 'experimental',
|
|
31
|
+
rendering: ['client'],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'react-nativescript',
|
|
35
|
+
framework: 'react',
|
|
36
|
+
renderer: 'nativescript',
|
|
37
|
+
status: 'experimental',
|
|
38
|
+
rendering: ['client'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'angular-nativescript',
|
|
42
|
+
framework: 'angular',
|
|
43
|
+
renderer: 'nativescript',
|
|
44
|
+
status: 'experimental',
|
|
45
|
+
rendering: ['client'],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'svelte-nativescript',
|
|
49
|
+
framework: 'svelte',
|
|
50
|
+
renderer: 'nativescript',
|
|
51
|
+
status: 'experimental',
|
|
52
|
+
rendering: ['client'],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'solid-nativescript',
|
|
56
|
+
framework: 'solid',
|
|
57
|
+
renderer: 'nativescript',
|
|
58
|
+
status: 'experimental',
|
|
59
|
+
rendering: ['client'],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'typescript-nativescript',
|
|
63
|
+
framework: 'typescript',
|
|
64
|
+
renderer: 'nativescript',
|
|
23
65
|
status: 'experimental',
|
|
24
66
|
rendering: ['client'],
|
|
25
67
|
},
|
|
@@ -45,26 +87,6 @@ export const adapters = {
|
|
|
45
87
|
id: 'solid-web',
|
|
46
88
|
issue: 154,
|
|
47
89
|
},
|
|
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
90
|
],
|
|
69
91
|
research: [
|
|
70
92
|
{
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { lstat, mkdir, readFile, readdir, rename, rm, rmdir, writeFile } 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
|
+
const json = (value) => JSON.stringify(value, null, 2) + '\n'
|
|
10
|
+
const posix = (path) => path.split(sep).join('/')
|
|
11
|
+
async function safe(root, name) {
|
|
12
|
+
const path = resolve(root, name),
|
|
13
|
+
rel = relative(root, path)
|
|
14
|
+
if (!rel || isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`))
|
|
15
|
+
throw new Error('Desktop source paths must stay inside the project.')
|
|
16
|
+
let current = root
|
|
17
|
+
for (const part of rel.split(sep)) {
|
|
18
|
+
current = join(current, part)
|
|
19
|
+
try {
|
|
20
|
+
if ((await lstat(current)).isSymbolicLink()) throw new Error(`Refusing symlink: ${name}`)
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error.code !== 'ENOENT') throw error
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return path
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function planDesktop(options, cwd = process.cwd()) {
|
|
29
|
+
const root = resolve(cwd),
|
|
30
|
+
original = new Map(),
|
|
31
|
+
files = new Map(),
|
|
32
|
+
diagnostics = []
|
|
33
|
+
const target = options.target
|
|
34
|
+
if (!['macos', 'windows'].includes(target))
|
|
35
|
+
throw new Error('Choose --add-macos or --add-windows.')
|
|
36
|
+
const read = async (name) => {
|
|
37
|
+
let value
|
|
38
|
+
try {
|
|
39
|
+
value = await readFile(await safe(root, name), 'utf8')
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (error.code !== 'ENOENT') throw error
|
|
42
|
+
}
|
|
43
|
+
original.set(name, value)
|
|
44
|
+
return value
|
|
45
|
+
}
|
|
46
|
+
const pkg = JSON.parse(await read('package.json'))
|
|
47
|
+
const raw = await read('mavis.config.json')
|
|
48
|
+
const prior = raw ? migrateConfig(JSON.parse(raw)) : {}
|
|
49
|
+
if (prior.mode === 'portable' || prior.apps?.macos?.toolkit === 'swiftui')
|
|
50
|
+
throw new Error(
|
|
51
|
+
'This project uses the SwiftUI compiler. Use its pinned creator or the archive/swiftui branch.',
|
|
52
|
+
)
|
|
53
|
+
const manager =
|
|
54
|
+
options.packageManager ??
|
|
55
|
+
prior.packageManager ??
|
|
56
|
+
pkg.packageManager?.split('@')[0] ??
|
|
57
|
+
detectPackageManager()
|
|
58
|
+
const commands = packageCommands(manager)
|
|
59
|
+
const destination = `apps/${target}`
|
|
60
|
+
const marker = `${destination}/mavis.host.json`
|
|
61
|
+
const previous = await read(marker)
|
|
62
|
+
if (previous) {
|
|
63
|
+
const state = JSON.parse(previous)
|
|
64
|
+
if (
|
|
65
|
+
state.kind !== 'nativescript-desktop' ||
|
|
66
|
+
state.target !== target ||
|
|
67
|
+
(options.entry && state.entry !== options.entry)
|
|
68
|
+
)
|
|
69
|
+
throw new Error(`${destination} already belongs to another host configuration.`)
|
|
70
|
+
return {
|
|
71
|
+
root,
|
|
72
|
+
original,
|
|
73
|
+
files,
|
|
74
|
+
destination,
|
|
75
|
+
entry: state.entry,
|
|
76
|
+
manager,
|
|
77
|
+
diagnostics,
|
|
78
|
+
alreadyAdded: true,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
await lstat(await safe(root, destination))
|
|
83
|
+
throw new Error(`${destination} already exists; no files were changed.`)
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error.code !== 'ENOENT') throw error
|
|
86
|
+
}
|
|
87
|
+
const manifests = [pkg]
|
|
88
|
+
for (const name of [
|
|
89
|
+
'apps/web/package.json',
|
|
90
|
+
'apps/mobile/package.json',
|
|
91
|
+
'apps/macos/package.json',
|
|
92
|
+
'apps/windows/package.json',
|
|
93
|
+
]) {
|
|
94
|
+
const value = await read(name)
|
|
95
|
+
if (value) manifests.push(JSON.parse(value))
|
|
96
|
+
}
|
|
97
|
+
const dependencies = manifests.map((pkg) => ({ ...pkg.devDependencies, ...pkg.dependencies }))
|
|
98
|
+
if (
|
|
99
|
+
!dependencies.some(
|
|
100
|
+
(dep) =>
|
|
101
|
+
dep['@getcortexlabs/mavis-web'] ||
|
|
102
|
+
dep['@getcortexlabs/mavis'] ||
|
|
103
|
+
dep['@getcortexlabs/mavis-core'],
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
throw new Error('Desktop adoption needs an existing Mavis Vue project.')
|
|
107
|
+
for (const dep of dependencies)
|
|
108
|
+
for (const name of [
|
|
109
|
+
'@getcortexlabs/mavis-core',
|
|
110
|
+
'@getcortexlabs/mavis-web',
|
|
111
|
+
'@getcortexlabs/mavis',
|
|
112
|
+
])
|
|
113
|
+
if (
|
|
114
|
+
dep[name] &&
|
|
115
|
+
![versions.mavis, `^${versions.mavis}`, `~${versions.mavis}`].includes(dep[name])
|
|
116
|
+
)
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Align ${name} with this creator (${versions.mavis}) before adding desktop.`,
|
|
119
|
+
)
|
|
120
|
+
let roots = options.roots ?? prior.portability?.roots
|
|
121
|
+
if (!roots) {
|
|
122
|
+
roots = []
|
|
123
|
+
for (const candidate of ['shared', 'src/shared', 'app/shared']) {
|
|
124
|
+
try {
|
|
125
|
+
if ((await lstat(await safe(root, candidate))).isDirectory()) roots.push(candidate)
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (error.code !== 'ENOENT') throw error
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (roots.length !== 1)
|
|
132
|
+
throw new Error('Choose one --shared-root for the desktop entry and its shared imports.')
|
|
133
|
+
const sourceRoot = roots[0]
|
|
134
|
+
await safe(root, sourceRoot)
|
|
135
|
+
const entry =
|
|
136
|
+
options.entry ?? `${sourceRoot}/${prior.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
137
|
+
if (!entry.endsWith('.vue') || !(await read(entry)))
|
|
138
|
+
throw new Error('Choose an existing Vue component with --entry path/to/App.vue.')
|
|
139
|
+
const sources = new Map()
|
|
140
|
+
const inspect = async (folder) => {
|
|
141
|
+
for (const item of await readdir(await safe(root, folder), { withFileTypes: true })) {
|
|
142
|
+
const name = posix(join(folder, item.name))
|
|
143
|
+
await safe(root, name)
|
|
144
|
+
if (item.isDirectory()) {
|
|
145
|
+
if (!['node_modules', '.git', 'dist'].includes(item.name)) await inspect(name)
|
|
146
|
+
} else if (/\.(vue|ts|js|mjs)$/.test(name)) sources.set(name, await read(name))
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
await inspect(sourceRoot)
|
|
150
|
+
const entryRelative = relative(resolve(root, sourceRoot), resolve(root, entry))
|
|
151
|
+
if (entryRelative.startsWith('..') || isAbsolute(entryRelative))
|
|
152
|
+
throw new Error('--entry must be inside --shared-root.')
|
|
153
|
+
for (const [file, source] of sources) {
|
|
154
|
+
for (const match of source.matchAll(/import\s*\{([^}]+)\}\s*from\s*['"]#mavis['"]/g))
|
|
155
|
+
for (const name of match[1].split(',').map((name) => name.trim().split(/\s+as\s+/)[0]))
|
|
156
|
+
if (name && !(name in desktopComponents))
|
|
157
|
+
diagnostics.push(`${file}: ${name} is outside the NativeScript desktop subset.`)
|
|
158
|
+
if (!file.endsWith('.vue')) continue
|
|
159
|
+
const { descriptor, errors } = parse(source, { filename: file })
|
|
160
|
+
if (errors.length) throw errors[0]
|
|
161
|
+
if (descriptor.styles.length)
|
|
162
|
+
diagnostics.push(
|
|
163
|
+
`${file}: CSS styles need a native desktop implementation; use the supported layout and theme props.`,
|
|
164
|
+
)
|
|
165
|
+
const visit = (node) => {
|
|
166
|
+
if (node.type === 1) {
|
|
167
|
+
const key = Object.keys(desktopComponents).find(
|
|
168
|
+
(name) =>
|
|
169
|
+
name === node.tag ||
|
|
170
|
+
name.replace(/[A-Z]/g, (c, i) => (i ? '-' : '') + c.toLowerCase()) === node.tag,
|
|
171
|
+
)
|
|
172
|
+
if (key) {
|
|
173
|
+
const component = desktopComponents[key]
|
|
174
|
+
const props = [
|
|
175
|
+
'id',
|
|
176
|
+
'key',
|
|
177
|
+
'ref',
|
|
178
|
+
'accessibilityLabel',
|
|
179
|
+
...component.props,
|
|
180
|
+
...(component[target] ?? []),
|
|
181
|
+
]
|
|
182
|
+
for (const prop of node.props) {
|
|
183
|
+
let name = prop.name
|
|
184
|
+
if (prop.type === 7) {
|
|
185
|
+
if (prop.modifiers.length) {
|
|
186
|
+
diagnostics.push(
|
|
187
|
+
`${file}:${prop.loc.start.line}: v-${name} modifiers need an explicit desktop implementation.`,
|
|
188
|
+
)
|
|
189
|
+
continue
|
|
190
|
+
}
|
|
191
|
+
if (['if', 'else', 'else-if', 'for', 'once', 'memo'].includes(name)) continue
|
|
192
|
+
if (name === 'model' && !prop.arg && !prop.modifiers.length) {
|
|
193
|
+
name = 'modelValue'
|
|
194
|
+
} else if (name === 'bind' && prop.arg?.isStatic) name = prop.arg.content
|
|
195
|
+
else if (name === 'on' && prop.arg?.isStatic)
|
|
196
|
+
name = 'on' + prop.arg.content[0].toUpperCase() + prop.arg.content.slice(1)
|
|
197
|
+
else {
|
|
198
|
+
diagnostics.push(
|
|
199
|
+
`${file}:${prop.loc.start.line}: dynamic bindings or directive v-${name} need an explicit desktop implementation.`,
|
|
200
|
+
)
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (!props.includes(name))
|
|
205
|
+
diagnostics.push(
|
|
206
|
+
`${file}:${prop.loc.start.line}: ${key}.${name} is outside the ${target} subset.`,
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
} else if (
|
|
210
|
+
/^[Mm][-A-Z]/.test(node.tag) ||
|
|
211
|
+
(node.tagType === 0 && !['template', 'slot'].includes(node.tag))
|
|
212
|
+
)
|
|
213
|
+
diagnostics.push(
|
|
214
|
+
`${file}:${node.loc.start.line}: ${node.tag} is not implemented on desktop.`,
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
for (const child of node.children ?? []) visit(child)
|
|
218
|
+
}
|
|
219
|
+
if (descriptor.template?.ast) visit(descriptor.template.ast)
|
|
220
|
+
}
|
|
221
|
+
if (diagnostics.length)
|
|
222
|
+
throw new Error(
|
|
223
|
+
`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.`,
|
|
224
|
+
)
|
|
225
|
+
const name = String(prior.name ?? pkg.name ?? 'mavis-app')
|
|
226
|
+
.replace(/^@[^/]+\//, '')
|
|
227
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
228
|
+
.slice(0, 64)
|
|
229
|
+
const directory =
|
|
230
|
+
prior.example === 'directory' &&
|
|
231
|
+
entry.endsWith('/Directory.vue') &&
|
|
232
|
+
sources.has(`${sourceRoot}/routes.ts`)
|
|
233
|
+
const preset = {
|
|
234
|
+
name,
|
|
235
|
+
theme: prior.theme ?? 'mavis',
|
|
236
|
+
packageManager: manager,
|
|
237
|
+
example: directory ? 'directory' : 'welcome',
|
|
238
|
+
}
|
|
239
|
+
const hostFiles = await desktopHostFiles(
|
|
240
|
+
preset,
|
|
241
|
+
target,
|
|
242
|
+
copyTemplate,
|
|
243
|
+
posix(relative(resolve(root, destination), resolve(root, sourceRoot))),
|
|
244
|
+
)
|
|
245
|
+
if (!directory) {
|
|
246
|
+
hostFiles.set(
|
|
247
|
+
'src/main.ts',
|
|
248
|
+
`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`,
|
|
249
|
+
)
|
|
250
|
+
diagnostics.push(
|
|
251
|
+
`Review ${destination}/src/main.ts to install any application-specific providers or router before mounting.`,
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
hostFiles.set(
|
|
255
|
+
'mavis.host.json',
|
|
256
|
+
json({ schemaVersion: 1, kind: 'nativescript-desktop', target, entry }),
|
|
257
|
+
)
|
|
258
|
+
for (const [path, value] of hostFiles) {
|
|
259
|
+
const file = posix(join(destination, path))
|
|
260
|
+
if ((await read(file)) !== undefined) throw new Error(`Refusing to overwrite ${file}.`)
|
|
261
|
+
files.set(file, value)
|
|
262
|
+
}
|
|
263
|
+
const scripts = {
|
|
264
|
+
[target]: commands.run('dev', destination),
|
|
265
|
+
[`build:${target}`]: commands.run('build', destination),
|
|
266
|
+
[`package:${target}`]: commands.run('package', destination),
|
|
267
|
+
}
|
|
268
|
+
for (const [key, value] of Object.entries(scripts))
|
|
269
|
+
if (pkg.scripts?.[key] && pkg.scripts[key] !== value)
|
|
270
|
+
throw new Error(`The existing ${key} script conflicts with this host.`)
|
|
271
|
+
files.set('package.json', json({ ...pkg, scripts: { ...pkg.scripts, ...scripts } }))
|
|
272
|
+
const targets = targetNames.filter(
|
|
273
|
+
(name) =>
|
|
274
|
+
name === target ||
|
|
275
|
+
prior.targets?.includes(name) ||
|
|
276
|
+
(name === 'web' && dependencies.some((dep) => dep['@getcortexlabs/mavis-web'])) ||
|
|
277
|
+
(name === 'native' && dependencies.some((dep) => dep['@getcortexlabs/mavis'])),
|
|
278
|
+
)
|
|
279
|
+
files.set(
|
|
280
|
+
'mavis.config.json',
|
|
281
|
+
json({
|
|
282
|
+
...prior,
|
|
283
|
+
schemaVersion: 2,
|
|
284
|
+
name,
|
|
285
|
+
targets,
|
|
286
|
+
framework: 'vue',
|
|
287
|
+
authoring: 'vue',
|
|
288
|
+
mode: 'direct',
|
|
289
|
+
execution: 'components',
|
|
290
|
+
packageManager: manager,
|
|
291
|
+
...(targets.includes('macos') ? { macosRuntime: 'appkit' } : {}),
|
|
292
|
+
apps: {
|
|
293
|
+
...prior.apps,
|
|
294
|
+
[target]: {
|
|
295
|
+
toolkit: target === 'macos' ? 'nativescript-appkit' : 'nativescript-xaml',
|
|
296
|
+
framework: 'vue',
|
|
297
|
+
runtime: target === 'macos' ? versions.macosNodeApi : versions.windowsNapi,
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
desktop: { ...prior.desktop, existing: true },
|
|
301
|
+
versions: { ...prior.versions, ...versions },
|
|
302
|
+
}),
|
|
303
|
+
)
|
|
304
|
+
return { root, original, files, destination, entry, manager, diagnostics, alreadyAdded: false }
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function optional(path) {
|
|
308
|
+
try {
|
|
309
|
+
return await readFile(path, 'utf8')
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (error.code !== 'ENOENT') throw error
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/** Optimistic transaction: refuse concurrent edits; roll back only bytes written by this plan. */
|
|
315
|
+
export async function applyDesktop(plan, { signal } = {}) {
|
|
316
|
+
if (plan.alreadyAdded) return
|
|
317
|
+
const written = []
|
|
318
|
+
try {
|
|
319
|
+
for (const [name, expected] of plan.original) {
|
|
320
|
+
if ((await optional(await safe(plan.root, name))) !== expected)
|
|
321
|
+
throw new Error(`${name} changed after the preview. Preview the desktop target again.`)
|
|
322
|
+
}
|
|
323
|
+
for (const [name, data] of plan.files) {
|
|
324
|
+
signal?.throwIfAborted()
|
|
325
|
+
const path = await safe(plan.root, name)
|
|
326
|
+
await mkdir(dirname(path), { recursive: true })
|
|
327
|
+
if (plan.original.get(name) === undefined) await writeFile(path, data, { flag: 'wx' })
|
|
328
|
+
else {
|
|
329
|
+
if ((await optional(path)) !== plan.original.get(name))
|
|
330
|
+
throw new Error(`${name} changed during creation.`)
|
|
331
|
+
const staging = `${path}.mavis-${process.pid}.tmp`
|
|
332
|
+
try {
|
|
333
|
+
await writeFile(staging, data, { flag: 'wx' })
|
|
334
|
+
await rename(staging, path)
|
|
335
|
+
} finally {
|
|
336
|
+
await rm(staging, { force: true })
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
written.push(name)
|
|
340
|
+
}
|
|
341
|
+
} catch (error) {
|
|
342
|
+
for (const name of written.reverse()) {
|
|
343
|
+
const path = join(plan.root, name)
|
|
344
|
+
const current = await readFile(path).catch(() => null)
|
|
345
|
+
if (!current?.equals(Buffer.from(plan.files.get(name)))) continue
|
|
346
|
+
const prior = plan.original.get(name)
|
|
347
|
+
if (prior === undefined) await rm(path)
|
|
348
|
+
else await writeFile(path, prior)
|
|
349
|
+
for (let folder = dirname(path); folder !== plan.root; folder = dirname(folder))
|
|
350
|
+
await rmdir(folder).catch(() => {})
|
|
351
|
+
}
|
|
352
|
+
throw error
|
|
353
|
+
}
|
|
354
|
+
}
|