@getcortexlabs/create-mavis 0.0.0-stage → 0.1.0-alpha.11
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/LICENSE +21 -0
- package/README.md +49 -2
- package/package.json +32 -4
- package/src/add-target.mjs +378 -0
- package/src/cli.mjs +289 -0
- package/src/doctor.mjs +56 -0
- package/src/package-manager.mjs +105 -0
- package/src/portability.mjs +460 -0
- package/src/presets.mjs +81 -0
- package/src/reference.mjs +45 -0
- package/src/scaffold.mjs +302 -0
- package/src/shared-api.mjs +57 -0
- package/src/ui.mjs +276 -0
- package/templates/directory/mobile/src/App.vue +4 -0
- package/templates/directory/mobile/src/app.ts +32 -0
- package/templates/directory/nuxt/app/app.vue +1 -0
- package/templates/directory/nuxt/app/pages/entries/[id]/edit.vue +5 -0
- package/templates/directory/nuxt/app/pages/entries/[id]/index.vue +5 -0
- package/templates/directory/nuxt/app/pages/index.vue +4 -0
- package/templates/directory/nuxt/app/plugins/mavis.ts +34 -0
- package/templates/directory/shared/Details.vue +26 -0
- package/templates/directory/shared/Directory.vue +51 -0
- package/templates/directory/shared/Edit.vue +99 -0
- package/templates/directory/shared/directory-store.ts +82 -0
- package/templates/directory/shared/routes.ts +9 -0
- package/templates/directory/vite/src/App.vue +4 -0
- package/templates/directory/vite/src/main.ts +34 -0
- package/templates/mobile/App_Resources/Android/app.gradle +10 -0
- package/templates/mobile/App_Resources/Android/src/main/AndroidManifest.xml +18 -0
- package/templates/mobile/App_Resources/Android/src/main/res/values/styles.xml +15 -0
- package/templates/mobile/App_Resources/iOS/Info.plist +20 -0
- package/templates/mobile/App_Resources/iOS/LaunchScreen.storyboard +18 -0
- package/templates/mobile/App_Resources/iOS/build.xcconfig +1 -0
- package/templates/mobile/nativescript.config.ts +6 -0
- package/templates/mobile/src/App.vue +6 -0
- package/templates/mobile/src/app.css +3 -0
- package/templates/mobile/src/app.ts +13 -0
- package/templates/mobile/src/env.d.ts +5 -0
- package/templates/mobile/src/mavis.ts +78 -0
- package/templates/mobile/tsconfig.json +21 -0
- package/templates/mobile/webpack.config.js +24 -0
- package/templates/nuxt/app/app.vue +11 -0
- package/templates/nuxt/app/assets/main.css +13 -0
- package/templates/nuxt/app/mavis.ts +78 -0
- package/templates/nuxt/app/plugins/mavis.ts +14 -0
- package/templates/nuxt/nuxt.config.ts +11 -0
- package/templates/nuxt/tsconfig.json +1 -0
- package/templates/shared/Welcome.vue +97 -0
- package/templates/shared/services.ts +11 -0
- package/templates/vite/index.html +13 -0
- package/templates/vite/src/main.ts +15 -0
- package/templates/vite/src/mavis.ts +78 -0
- package/templates/vite/src/style.css +13 -0
- package/templates/vite/tsconfig.json +16 -0
- package/templates/vite/vite.config.ts +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rafael Augusto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Create Mavis
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Start with Vue on the Web, NativeScript, or both. Web projects use Vue + Vite or Nuxt with server rendering/static generation. The generated example shares a Vue screen and gives each host its own service implementation.
|
|
4
|
+
|
|
5
|
+
Run `npm create @getcortexlabs/mavis@latest` for the interactive wizard, or pass a project name and options:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm create @getcortexlabs/mavis@latest my-app -- --target both --web nuxt --rendering ssr --theme midnight --no-install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The terminal wizard uses arrow keys and Enter, with descriptions, inline name validation and a summary before creation. Choose **Back** to revisit a choice or **Change choices** at the summary. Escape or Ctrl-C cancels. Explicit flags are preserved. In CI, supply a project name and flags, or `--yes` for defaults without installation.
|
|
12
|
+
|
|
13
|
+
Choose **Basic project** (`--example welcome`, the default) or **Search, details and editing** (`--example directory`). The summary includes the example. After creation, the CLI points to `Welcome.vue` or `Directory.vue` in the shared source directory. Both examples support all five presets and npm, pnpm and Yarn; generated instructions follow the chosen manager.
|
|
14
|
+
|
|
15
|
+
Choose **npm, pnpm or Yarn** regardless of how you launched the creator. The invoking manager is preselected when detected; otherwise npm is the default. `--package-manager pnpm` selects it without a prompt. The generated scripts, README, installation and next steps all use your choice. Before the final summary, the wizard checks whether the selected manager can run. If it cannot, choose another manager, check again, or create without installing; your project choices are preserved. Shell PATH changes require restarting the creator from the updated terminal.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm create @getcortexlabs/mavis@latest my-app -- --package-manager pnpm --yes --no-install
|
|
19
|
+
cd my-app
|
|
20
|
+
pnpm install
|
|
21
|
+
pnpm run dev
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The wizard, package-manager selection and both examples are included in alpha.11.
|
|
25
|
+
|
|
26
|
+
- `--dry-run` prints the file plan without writing or installing.
|
|
27
|
+
- Existing directories are never merged or overwritten.
|
|
28
|
+
- `--install` runs the chosen package manager after creating the project. It must already be available on PATH. A failed install preserves the source for retry.
|
|
29
|
+
- `--doctor` checks a generated project's Node, package-manager and native prerequisites without installing tools.
|
|
30
|
+
- `mavis.config.json` records the resolved choices and dependency versions.
|
|
31
|
+
|
|
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
|
+
|
|
34
|
+
Templates pin **Mavis 0.1.0-alpha.11** and **Jolt 0.1.0-rc.11**. The CLI and its generated projects use the same Mavis release. Commit the generated lockfile (both lockfiles for a shared project).
|
|
35
|
+
|
|
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
|
+
|
|
38
|
+
React, Next, Angular, Svelte, portable authoring and SDUI are roadmap work. The creator reports unsupported choices instead of generating placeholder integrations.
|
|
39
|
+
|
|
40
|
+
MIT · [Mavis UI](https://github.com/getcortexlabs/mavis-ui)
|
|
41
|
+
|
|
42
|
+
## Shared screens and portability
|
|
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. `--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 (alpha.11)
|
|
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. Upgrade the existing Mavis renderer to alpha.11 before adding a host.
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getcortexlabs/create-mavis",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-alpha.11",
|
|
4
|
+
"description": "Create Vue Web, Nuxt and NativeScript projects with Mavis UI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-mavis": "./src/cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"templates",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.16"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Rafael Augusto",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/getcortexlabs/mavis-ui.git",
|
|
23
|
+
"directory": "packages/create-mavis"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"tag": "alpha"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@vue/compiler-sfc": "3.5.44",
|
|
31
|
+
"typescript": "6.0.3",
|
|
32
|
+
"@clack/prompts": "1.8.1"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { lstat, mkdir, mkdtemp, readFile, rename, rm, rmdir, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
3
|
+
import { parse } from '@vue/compiler-sfc'
|
|
4
|
+
import { projectFiles } from './scaffold.mjs'
|
|
5
|
+
import { versions } from './presets.mjs'
|
|
6
|
+
import { checkPortability } from './portability.mjs'
|
|
7
|
+
import { detectPackageManager, packageCommands } from './package-manager.mjs'
|
|
8
|
+
|
|
9
|
+
const json = (value) => JSON.stringify(value, null, 2) + '\n'
|
|
10
|
+
const posix = (path) => path.split(sep).join('/')
|
|
11
|
+
async function optional(path) {
|
|
12
|
+
try {
|
|
13
|
+
return await readFile(path, 'utf8')
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (error.code !== 'ENOENT') throw error
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function safePath(root, name) {
|
|
19
|
+
const path = resolve(root, name),
|
|
20
|
+
rel = relative(root, path)
|
|
21
|
+
if (!rel || isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`))
|
|
22
|
+
throw new Error('Paths must stay inside the existing project.')
|
|
23
|
+
let current = root
|
|
24
|
+
for (const part of rel.split(sep)) {
|
|
25
|
+
current = join(current, part)
|
|
26
|
+
try {
|
|
27
|
+
if ((await lstat(current)).isSymbolicLink()) throw new Error(`Refusing symlink: ${current}`)
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (error.code !== 'ENOENT') throw error
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return path
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Add an isolated host; the original application is never treated as a template. */
|
|
36
|
+
export async function planTarget(options, cwd = process.cwd()) {
|
|
37
|
+
const root = resolve(cwd)
|
|
38
|
+
const packageFile = await safePath(root, 'package.json')
|
|
39
|
+
const original = await readFile(packageFile, 'utf8'),
|
|
40
|
+
pkg = JSON.parse(original)
|
|
41
|
+
const deps = { ...pkg.devDependencies, ...pkg.dependencies }
|
|
42
|
+
const target = options.target
|
|
43
|
+
if (!['mobile', 'web'].includes(target)) throw new Error('Choose --add-native or --add-web.')
|
|
44
|
+
const source = deps.nuxt
|
|
45
|
+
? 'nuxt'
|
|
46
|
+
: deps.vite && deps.vue
|
|
47
|
+
? 'vite'
|
|
48
|
+
: deps['nativescript-vue'] && deps['@nativescript/core']
|
|
49
|
+
? 'mobile'
|
|
50
|
+
: null
|
|
51
|
+
if (!source || (target === 'mobile' ? source === 'mobile' : source !== 'mobile'))
|
|
52
|
+
throw new Error(
|
|
53
|
+
target === 'mobile'
|
|
54
|
+
? '--add-native needs an existing Vue + Vite or Nuxt package.'
|
|
55
|
+
: '--add-web needs an existing NativeScript-Vue package.',
|
|
56
|
+
)
|
|
57
|
+
// A root workspace can later absorb the new renderer during root installation.
|
|
58
|
+
// Work inside a concrete host package instead of changing workspace ownership.
|
|
59
|
+
const workspace = await optional(join(root, 'pnpm-workspace.yaml'))
|
|
60
|
+
if (
|
|
61
|
+
pkg.workspaces?.length ||
|
|
62
|
+
pkg.workspaces?.packages?.length ||
|
|
63
|
+
(workspace && !/^packages:\s*\[\s*\]/m.test(workspace))
|
|
64
|
+
)
|
|
65
|
+
throw new Error(
|
|
66
|
+
'Run this command inside a standalone host package; a workspace root needs an explicit isolation plan.',
|
|
67
|
+
)
|
|
68
|
+
const mavis = deps[target === 'mobile' ? '@getcortexlabs/mavis-web' : '@getcortexlabs/mavis']
|
|
69
|
+
if (!mavis || ![versions.mavis, `^${versions.mavis}`, `~${versions.mavis}`].includes(mavis))
|
|
70
|
+
throw new Error(
|
|
71
|
+
`This creator supports Mavis ${versions.mavis}. Align the existing renderer first; no dependencies were changed.`,
|
|
72
|
+
)
|
|
73
|
+
const locks = []
|
|
74
|
+
for (const [name, file] of [
|
|
75
|
+
['npm', 'package-lock.json'],
|
|
76
|
+
['pnpm', 'pnpm-lock.yaml'],
|
|
77
|
+
['yarn', 'yarn.lock'],
|
|
78
|
+
])
|
|
79
|
+
if ((await optional(join(root, file))) !== undefined) locks.push(name)
|
|
80
|
+
const declaredManager = pkg.packageManager?.split('@')[0]
|
|
81
|
+
if (!options.packageManager && !declaredManager && locks.length > 1)
|
|
82
|
+
throw new Error('Multiple lockfiles found. Choose --package-manager npm, pnpm or yarn.')
|
|
83
|
+
const manager =
|
|
84
|
+
options.packageManager ??
|
|
85
|
+
declaredManager ??
|
|
86
|
+
locks[0] ??
|
|
87
|
+
(workspace !== undefined ? 'pnpm' : undefined) ??
|
|
88
|
+
detectPackageManager()
|
|
89
|
+
const commands = packageCommands(manager)
|
|
90
|
+
const host = target === 'mobile' ? 'mobile' : (options.web ?? 'vite')
|
|
91
|
+
const rendering =
|
|
92
|
+
host === 'mobile' ? null : (options.rendering ?? (host === 'nuxt' ? 'ssr' : 'client'))
|
|
93
|
+
const destination = `apps/${target}`
|
|
94
|
+
await safePath(root, destination)
|
|
95
|
+
const screen = options.screen ? posix(relative(root, await safePath(root, options.screen))) : null
|
|
96
|
+
if (screen && !screen.endsWith('.vue'))
|
|
97
|
+
throw new Error('--screen must name an existing .vue file.')
|
|
98
|
+
if (options.screenRoot && !['screen', 'content'].includes(options.screenRoot))
|
|
99
|
+
throw new Error('--screen-root must be screen or content.')
|
|
100
|
+
const metadataPath = join(root, destination, 'mavis.host.json')
|
|
101
|
+
const existing = await optional(metadataPath)
|
|
102
|
+
if (existing) {
|
|
103
|
+
const state = JSON.parse(existing)
|
|
104
|
+
if (
|
|
105
|
+
state.schemaVersion !== 1 ||
|
|
106
|
+
state.source !== source ||
|
|
107
|
+
state.host !== host ||
|
|
108
|
+
state.manager !== manager ||
|
|
109
|
+
state.rendering !== rendering ||
|
|
110
|
+
state.screen !== screen ||
|
|
111
|
+
state.requestedScreenRoot !== (options.screenRoot ?? null)
|
|
112
|
+
)
|
|
113
|
+
throw new Error(
|
|
114
|
+
`${destination} was added with different choices. Existing files are preserved.`,
|
|
115
|
+
)
|
|
116
|
+
for (const [name, value] of Object.entries(state.scripts))
|
|
117
|
+
if (pkg.scripts?.[name] !== value)
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Existing script ${name} changed. Resolve it explicitly; host files are preserved.`,
|
|
120
|
+
)
|
|
121
|
+
return {
|
|
122
|
+
root,
|
|
123
|
+
destination,
|
|
124
|
+
host,
|
|
125
|
+
manager,
|
|
126
|
+
screen,
|
|
127
|
+
files: new Map(),
|
|
128
|
+
scripts: state.scripts,
|
|
129
|
+
alreadyAdded: true,
|
|
130
|
+
diagnostics: [],
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
await lstat(join(root, destination))
|
|
135
|
+
throw new Error(`${destination} already exists. No files were changed.`)
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (error.code !== 'ENOENT') throw error
|
|
138
|
+
}
|
|
139
|
+
const name = (pkg.name ?? 'mavis-app')
|
|
140
|
+
.replace(/^@[^/]+\//, '')
|
|
141
|
+
.toLowerCase()
|
|
142
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
143
|
+
.slice(0, 48)
|
|
144
|
+
const generated = await projectFiles({
|
|
145
|
+
name: /^[a-z]/.test(name) ? name : `app-${name}`,
|
|
146
|
+
target,
|
|
147
|
+
web: host === 'mobile' ? 'vite' : host,
|
|
148
|
+
rendering: options.rendering,
|
|
149
|
+
packageManager: manager,
|
|
150
|
+
})
|
|
151
|
+
const files = generated.files
|
|
152
|
+
const native = target === 'mobile'
|
|
153
|
+
if (native) {
|
|
154
|
+
const file = 'webpack.config.js'
|
|
155
|
+
files.set(
|
|
156
|
+
file,
|
|
157
|
+
files
|
|
158
|
+
.get(file)
|
|
159
|
+
.replace(
|
|
160
|
+
" config.resolve.alias.set('vue$'",
|
|
161
|
+
() =>
|
|
162
|
+
" for (const [name, entry] of Object.entries({ '@getcortexlabs/mavis-core$': 'index.js', '@getcortexlabs/mavis-core/vue$': 'vue/index.js', '@getcortexlabs/mavis-core/experimental$': 'experimental.js' }))\n config.resolve.alias.set(name, resolve(__dirname, 'node_modules/@getcortexlabs/mavis-core/dist', entry))\n config.resolve.alias.set('vue$'",
|
|
163
|
+
),
|
|
164
|
+
)
|
|
165
|
+
} else if (host === 'vite') {
|
|
166
|
+
const file = 'vite.config.ts'
|
|
167
|
+
files.set(
|
|
168
|
+
file,
|
|
169
|
+
files.get(file).replace("dedupe: ['vue'", "dedupe: ['@getcortexlabs/mavis-core', 'vue'"),
|
|
170
|
+
)
|
|
171
|
+
} else {
|
|
172
|
+
const file = 'nuxt.config.ts'
|
|
173
|
+
files.set(
|
|
174
|
+
file,
|
|
175
|
+
files
|
|
176
|
+
.get(file)
|
|
177
|
+
.replace(
|
|
178
|
+
' devtools:',
|
|
179
|
+
" vite: { resolve: { dedupe: ['vue', '@vue/runtime-core', '@vue/reactivity', '@vue/shared', '@getcortexlabs/mavis-core'] } },\n devtools:",
|
|
180
|
+
),
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
const scripts = native
|
|
184
|
+
? {
|
|
185
|
+
'install:mobile': commands.installAt(destination),
|
|
186
|
+
ios: commands.run('ios', destination),
|
|
187
|
+
android: commands.run('android', destination),
|
|
188
|
+
}
|
|
189
|
+
: {
|
|
190
|
+
'install:web': commands.installAt(destination),
|
|
191
|
+
'dev:web': commands.run('dev', destination),
|
|
192
|
+
'build:web': commands.run(
|
|
193
|
+
generated.preset.rendering === 'ssg' ? 'generate' : 'build',
|
|
194
|
+
destination,
|
|
195
|
+
),
|
|
196
|
+
'preview:web': commands.run('preview', destination),
|
|
197
|
+
}
|
|
198
|
+
for (const [name, value] of Object.entries(scripts))
|
|
199
|
+
if (pkg.scripts?.[name] !== undefined && pkg.scripts[name] !== value)
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Script conflict: ${name}. Rename the existing script explicitly before adding this target.`,
|
|
202
|
+
)
|
|
203
|
+
const manifest = JSON.parse(files.get('package.json'))
|
|
204
|
+
manifest.name += native ? '-mobile' : '-web'
|
|
205
|
+
for (const name of [
|
|
206
|
+
'@getcortexlabs/mavis-core',
|
|
207
|
+
native ? '@getcortexlabs/mavis' : '@getcortexlabs/mavis-web',
|
|
208
|
+
])
|
|
209
|
+
manifest.dependencies[name] = mavis
|
|
210
|
+
manifest.dependencies['@rafaelaugusto/jolt'] = deps['@rafaelaugusto/jolt'] ?? versions.jolt
|
|
211
|
+
files.set('package.json', json(manifest))
|
|
212
|
+
if (manager === 'npm') files.set('.npmrc', 'workspaces=false\n')
|
|
213
|
+
let diagnostics = [],
|
|
214
|
+
screenRoot = null
|
|
215
|
+
if (screen) {
|
|
216
|
+
const input = await readFile(join(root, screen), 'utf8')
|
|
217
|
+
const { descriptor, errors } = parse(input, { filename: screen })
|
|
218
|
+
if (errors.length || !descriptor.template || descriptor.template.src)
|
|
219
|
+
throw new Error('The selected screen must contain a valid inline Vue template.')
|
|
220
|
+
const roots = descriptor.template.ast?.children.filter((node) => node.type === 1) ?? []
|
|
221
|
+
screenRoot =
|
|
222
|
+
options.screenRoot ??
|
|
223
|
+
(roots.length === 1 && ['MScreen', 'm-screen'].includes(roots[0].tag) ? 'screen' : 'content')
|
|
224
|
+
if (roots.some((node) => ['Frame', 'Page'].includes(node.tag)))
|
|
225
|
+
throw new Error('Select shared content or an MScreen, not a native Frame/Page entry.')
|
|
226
|
+
diagnostics = (await checkPortability(root, { path: screen })).diagnostics
|
|
227
|
+
const entry = native
|
|
228
|
+
? 'src/App.vue'
|
|
229
|
+
: host === 'nuxt'
|
|
230
|
+
? 'app/app.vue'
|
|
231
|
+
: 'src/ExistingScreen.vue'
|
|
232
|
+
const screenImport = posix(
|
|
233
|
+
relative(dirname(join(root, destination, entry)), join(root, screen)),
|
|
234
|
+
)
|
|
235
|
+
const view =
|
|
236
|
+
screenRoot === 'screen'
|
|
237
|
+
? '<ExistingScreen />'
|
|
238
|
+
: '<MScreen scroll><ExistingScreen /></MScreen>'
|
|
239
|
+
files.set(
|
|
240
|
+
entry,
|
|
241
|
+
`<script setup lang="ts">\nimport ExistingScreen from ${JSON.stringify(screenImport.startsWith('.') ? screenImport : './' + screenImport)}\n</script>\n<template>${native ? `<Frame>${view}</Frame>` : view}</template>\n`,
|
|
242
|
+
)
|
|
243
|
+
if (native)
|
|
244
|
+
files.set(
|
|
245
|
+
'src/app.ts',
|
|
246
|
+
"import { createApp } from 'nativescript-vue'\nimport { createMavis } from '@getcortexlabs/mavis/vue'\nimport App from './App.vue'\ncreateApp(App).use(createMavis()).start()\n",
|
|
247
|
+
)
|
|
248
|
+
if (host === 'vite')
|
|
249
|
+
files.set(
|
|
250
|
+
'src/main.ts',
|
|
251
|
+
"import { createApp } from 'vue'\nimport { createMavis } from '@getcortexlabs/mavis-web'\nimport App from './ExistingScreen.vue'\nimport '@getcortexlabs/mavis-web/style.css'\nimport './style.css'\ncreateApp(App).use(createMavis()).mount('#app')\n",
|
|
252
|
+
)
|
|
253
|
+
// Explicit type resolution for source files outside this host's dependency tree.
|
|
254
|
+
if (host === 'nuxt') {
|
|
255
|
+
const paths = { vue: 'vue' }
|
|
256
|
+
for (const [name, entry] of Object.entries({
|
|
257
|
+
'@getcortexlabs/mavis-core': 'index.d.ts',
|
|
258
|
+
'@getcortexlabs/mavis-core/vue': 'vue/index.d.ts',
|
|
259
|
+
'@getcortexlabs/mavis-core/experimental': 'experimental.d.ts',
|
|
260
|
+
}))
|
|
261
|
+
paths[name] = `@getcortexlabs/mavis-core/dist/${entry}`
|
|
262
|
+
const entries = Object.entries(paths)
|
|
263
|
+
.map(
|
|
264
|
+
([name, entry]) =>
|
|
265
|
+
`${JSON.stringify(name)}: [fileURLToPath(new URL(${JSON.stringify('./node_modules/' + entry)}, import.meta.url))]`,
|
|
266
|
+
)
|
|
267
|
+
.join(', ')
|
|
268
|
+
files.set(
|
|
269
|
+
'nuxt.config.ts',
|
|
270
|
+
files
|
|
271
|
+
.get('nuxt.config.ts')
|
|
272
|
+
.replace(
|
|
273
|
+
' devtools:',
|
|
274
|
+
() =>
|
|
275
|
+
` typescript: { tsConfig: { compilerOptions: { paths: { ${entries} } } } },\n devtools:`,
|
|
276
|
+
),
|
|
277
|
+
)
|
|
278
|
+
} else {
|
|
279
|
+
const config = JSON.parse(files.get('tsconfig.json'))
|
|
280
|
+
config.compilerOptions.paths.vue = [
|
|
281
|
+
native ? './node_modules/nativescript-vue' : './node_modules/vue',
|
|
282
|
+
]
|
|
283
|
+
for (const [name, entry] of Object.entries({
|
|
284
|
+
'@getcortexlabs/mavis-core': 'index.d.ts',
|
|
285
|
+
'@getcortexlabs/mavis-core/vue': 'vue/index.d.ts',
|
|
286
|
+
'@getcortexlabs/mavis-core/experimental': 'experimental.d.ts',
|
|
287
|
+
}))
|
|
288
|
+
config.compilerOptions.paths[name] = [
|
|
289
|
+
`./node_modules/@getcortexlabs/mavis-core/dist/${entry}`,
|
|
290
|
+
]
|
|
291
|
+
config.include = [
|
|
292
|
+
'src',
|
|
293
|
+
posix(relative(join(root, destination), join(root, screen))),
|
|
294
|
+
...(host === 'vite' ? ['vite.config.ts'] : []),
|
|
295
|
+
]
|
|
296
|
+
files.set('tsconfig.json', json(config))
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const state = {
|
|
300
|
+
schemaVersion: 1,
|
|
301
|
+
rendering,
|
|
302
|
+
source,
|
|
303
|
+
host,
|
|
304
|
+
manager,
|
|
305
|
+
screen,
|
|
306
|
+
screenRoot,
|
|
307
|
+
requestedScreenRoot: options.screenRoot ?? null,
|
|
308
|
+
scripts,
|
|
309
|
+
}
|
|
310
|
+
files.set('mavis.host.json', json(state))
|
|
311
|
+
files.set(
|
|
312
|
+
'README.md',
|
|
313
|
+
`# ${native ? 'NativeScript' : host === 'nuxt' ? 'Nuxt' : 'Vue + Vite'} host\n\nAdded to the existing ${source} application. Original sources, Web/native configuration and lockfiles stay in place.\n\nFrom the repository root:\n\n\`\`\`sh\n${commands.run(native ? 'install:mobile' : 'install:web')}\n${commands.run(native ? 'ios' : 'dev:web')}\n${native ? commands.run('android') : commands.run('build:web')}\n\`\`\`\n\n${screen ? `Entry: \`${screen}\` (${screenRoot}). The host imports this file; it does not copy it. Run the creator with \`--check-portability --path ${JSON.stringify(screen)}\` from the original project root. Configure app-owned services, routes and aliases used by that screen in this host.` : `Start with \`${destination}/${host === 'nuxt' ? 'app' : 'src'}/shared/Welcome.vue\`, then import a portable screen from the existing application in the host entry.`}\n\n${native ? 'NativeScript CLI, Android SDK/JDK and macOS/Xcode for iOS are required. Run `ns doctor` inside this directory. The Frame owns one MScreen/Page; use `--screen-root screen` for a component that already owns MScreen, or `content` to wrap it.' : 'The Web renderer has its own Vue runtime. Device services and native-only components need Web adapters. Nuxt SSR must not execute browser globals during setup.'}\n\nNative and Web dependencies are installed separately. Do not add this host to a workspace that hoists both Vue runtimes. No existing screen, router, service or import is migrated automatically. Review portability findings before considering a selected screen ready for the new platform.\n`,
|
|
314
|
+
)
|
|
315
|
+
return {
|
|
316
|
+
root,
|
|
317
|
+
destination,
|
|
318
|
+
host,
|
|
319
|
+
manager,
|
|
320
|
+
screen,
|
|
321
|
+
files,
|
|
322
|
+
scripts,
|
|
323
|
+
original,
|
|
324
|
+
packageFile,
|
|
325
|
+
diagnostics,
|
|
326
|
+
preset: generated.preset,
|
|
327
|
+
alreadyAdded: false,
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export async function applyTarget(plan, { signal } = {}) {
|
|
332
|
+
if (plan.alreadyAdded) return
|
|
333
|
+
signal?.throwIfAborted()
|
|
334
|
+
const target = await safePath(plan.root, plan.destination)
|
|
335
|
+
const staging = await mkdtemp(join(plan.root, '.mavis-add-'))
|
|
336
|
+
let created = false
|
|
337
|
+
const written = []
|
|
338
|
+
try {
|
|
339
|
+
for (const [file, content] of plan.files) {
|
|
340
|
+
signal?.throwIfAborted()
|
|
341
|
+
const output = join(staging, 'host', file)
|
|
342
|
+
await mkdir(dirname(output), { recursive: true })
|
|
343
|
+
await writeFile(output, content, { flag: 'wx' })
|
|
344
|
+
}
|
|
345
|
+
const pkg = JSON.parse(plan.original)
|
|
346
|
+
pkg.scripts = { ...pkg.scripts, ...plan.scripts }
|
|
347
|
+
await writeFile(join(staging, 'package.json'), json(pkg), { flag: 'wx' })
|
|
348
|
+
if ((await readFile(plan.packageFile, 'utf8')) !== plan.original)
|
|
349
|
+
throw new Error('package.json changed after planning. Run the command again.')
|
|
350
|
+
await mkdir(dirname(target), { recursive: true })
|
|
351
|
+
await mkdir(target)
|
|
352
|
+
created = true
|
|
353
|
+
for (const file of plan.files.keys()) {
|
|
354
|
+
signal?.throwIfAborted()
|
|
355
|
+
await mkdir(dirname(join(target, file)), { recursive: true })
|
|
356
|
+
await safePath(plan.root, join(plan.destination, file))
|
|
357
|
+
await writeFile(join(target, file), plan.files.get(file), { flag: 'wx' })
|
|
358
|
+
written.push(file)
|
|
359
|
+
}
|
|
360
|
+
signal?.throwIfAborted()
|
|
361
|
+
if ((await readFile(plan.packageFile, 'utf8')) !== plan.original)
|
|
362
|
+
throw new Error('package.json changed during creation. Run the command again.')
|
|
363
|
+
await rename(join(staging, 'package.json'), plan.packageFile)
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (created) {
|
|
366
|
+
for (const file of written.reverse()) {
|
|
367
|
+
const path = join(target, file)
|
|
368
|
+
if ((await optional(path)) === plan.files.get(file)) await rm(path)
|
|
369
|
+
for (let folder = dirname(path); folder.startsWith(target); folder = dirname(folder))
|
|
370
|
+
await rmdir(folder).catch(() => {})
|
|
371
|
+
}
|
|
372
|
+
await rmdir(target).catch(() => {})
|
|
373
|
+
}
|
|
374
|
+
throw error
|
|
375
|
+
} finally {
|
|
376
|
+
await rm(staging, { recursive: true, force: true })
|
|
377
|
+
}
|
|
378
|
+
}
|