@getcortexlabs/create-mavis 0.1.0-alpha.8 → 0.1.0-alpha.9
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 +27 -6
- package/package.json +6 -1
- package/src/cli.mjs +119 -107
- package/src/doctor.mjs +9 -0
- package/src/package-manager.mjs +105 -0
- package/src/portability.mjs +445 -0
- package/src/presets.mjs +22 -6
- package/src/reference.mjs +45 -0
- package/src/scaffold.mjs +122 -32
- 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/src/App.vue +1 -3
- package/templates/mobile/src/mavis.ts +57 -0
- package/templates/mobile/tsconfig.json +9 -2
- package/templates/mobile/webpack.config.js +2 -0
- package/templates/nuxt/app/mavis.ts +57 -0
- package/templates/nuxt/nuxt.config.ts +5 -0
- package/templates/shared/Welcome.vue +13 -1
- package/templates/vite/src/mavis.ts +57 -0
- package/templates/vite/tsconfig.json +5 -1
- package/templates/vite/vite.config.ts +8 -1
package/README.md
CHANGED
|
@@ -2,24 +2,45 @@
|
|
|
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
4
|
|
|
5
|
-
Run `npm create @getcortexlabs/mavis@
|
|
5
|
+
Run `npm create @getcortexlabs/mavis@latest` for the interactive wizard, or pass a project name and options:
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm create @getcortexlabs/mavis@
|
|
8
|
+
npm create @getcortexlabs/mavis@latest my-app -- --target both --web nuxt --rendering ssr --theme midnight --no-install
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
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.9.
|
|
12
25
|
|
|
13
26
|
- `--dry-run` prints the file plan without writing or installing.
|
|
14
27
|
- Existing directories are never merged or overwritten.
|
|
15
|
-
- `--install` runs
|
|
16
|
-
- `--doctor` checks a generated project's Node and native prerequisites without installing tools.
|
|
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.
|
|
17
30
|
- `mavis.config.json` records the resolved choices and dependency versions.
|
|
18
31
|
|
|
19
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.
|
|
20
33
|
|
|
21
|
-
Templates pin **Mavis 0.1.0-alpha.
|
|
34
|
+
Templates pin **Mavis 0.1.0-alpha.9** and **Jolt 0.1.0-rc.10**. 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.
|
|
22
37
|
|
|
23
38
|
React, Next, Angular, Svelte, portable authoring and SDUI are roadmap work. The creator reports unsupported choices instead of generating placeholder integrations.
|
|
24
39
|
|
|
25
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getcortexlabs/create-mavis",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.9",
|
|
4
4
|
"description": "Create Vue Web, Nuxt and NativeScript projects with Mavis UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -25,5 +25,10 @@
|
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public",
|
|
27
27
|
"tag": "alpha"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@vue/compiler-sfc": "3.5.44",
|
|
31
|
+
"typescript": "6.0.3",
|
|
32
|
+
"@clack/prompts": "1.8.1"
|
|
28
33
|
}
|
|
29
34
|
}
|
package/src/cli.mjs
CHANGED
|
@@ -1,113 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from 'node:util'
|
|
3
|
-
import {
|
|
3
|
+
import { readFile } from 'node:fs/promises'
|
|
4
4
|
import { scaffold, installProject } from './scaffold.mjs'
|
|
5
|
+
import { checkPortability } from './portability.mjs'
|
|
5
6
|
import { doctor } from './doctor.mjs'
|
|
7
|
+
import { checkPackageManager, detectPackageManager } from './package-manager.mjs'
|
|
8
|
+
import { resolvePreset } from './presets.mjs'
|
|
9
|
+
import { nextSteps, projectSummary, sharedEntry, terminalUI, wizard } from './ui.mjs'
|
|
6
10
|
|
|
11
|
+
const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
|
|
7
12
|
const help = `Create Mavis — Vue Web, Nuxt and NativeScript
|
|
8
13
|
|
|
9
|
-
create
|
|
10
|
-
create-mavis my-app --target both --web nuxt --
|
|
14
|
+
npm create @getcortexlabs/mavis@latest
|
|
15
|
+
create-mavis my-app --target both --web nuxt --package-manager pnpm --no-install
|
|
11
16
|
|
|
12
17
|
--target mobile|web|both Default: web
|
|
13
18
|
--web vite|nuxt Default: vite
|
|
14
19
|
--rendering client|ssr|ssg Default: client (Vite), ssr (Nuxt)
|
|
20
|
+
--example welcome|directory Starter or shared search/detail/edit reference
|
|
21
|
+
--check-portability Audit shared sources without SDK checks
|
|
22
|
+
--path directory Override the configured shared source directory
|
|
23
|
+
--fix-imports Preview safe renderer-import replacements
|
|
24
|
+
--write Apply the previewed import migration
|
|
25
|
+
--json Machine-readable portability diagnostics
|
|
15
26
|
--theme mavis|midnight Default: mavis
|
|
16
|
-
--
|
|
17
|
-
|
|
18
|
-
--
|
|
19
|
-
--
|
|
27
|
+
--package-manager npm|pnpm|yarn
|
|
28
|
+
Default: the invoking manager, or npm
|
|
29
|
+
--framework vue Vue is currently supported
|
|
30
|
+
--authoring vue Vue templates are currently supported
|
|
31
|
+
--yes, -y Use defaults without prompts (skip installation)
|
|
32
|
+
--install / --no-install Install dependencies now or later
|
|
20
33
|
--dry-run Show the complete file plan without writing
|
|
21
|
-
--doctor Check
|
|
22
|
-
--
|
|
34
|
+
--doctor Check a generated project's prerequisites
|
|
35
|
+
--version, -v Show the creator version
|
|
36
|
+
--help, -h Show this help
|
|
23
37
|
|
|
24
|
-
|
|
38
|
+
Use arrow keys and Enter in the wizard. Choose Back to revisit an answer.
|
|
39
|
+
Ctrl-C or Escape cancels. Existing directories are never overwritten.
|
|
25
40
|
`
|
|
26
41
|
|
|
27
|
-
async function wizard(initial, signal) {
|
|
28
|
-
const answers = { ...initial }
|
|
29
|
-
const supplied = new Set(Object.keys(initial).filter((key) => initial[key] !== undefined))
|
|
30
|
-
const io = createInterface({ input: process.stdin, output: process.stdout })
|
|
31
|
-
const steps = [
|
|
32
|
-
{ key: 'name', question: 'Project name', fallback: 'my-mavis-app' },
|
|
33
|
-
{
|
|
34
|
-
key: 'target',
|
|
35
|
-
question: 'Where will it run? 1 Web · 2 Mobile · 3 Mobile + Web',
|
|
36
|
-
choices: ['web', 'mobile', 'both'],
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
key: 'web',
|
|
40
|
-
question: 'Web host? 1 Vue + Vite · 2 Nuxt',
|
|
41
|
-
choices: ['vite', 'nuxt'],
|
|
42
|
-
when: () => answers.target !== 'mobile',
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
key: 'rendering',
|
|
46
|
-
question: 'Rendering? 1 Server rendering · 2 Static generation',
|
|
47
|
-
choices: ['ssr', 'ssg'],
|
|
48
|
-
when: () => answers.target !== 'mobile' && answers.web === 'nuxt',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
key: 'theme',
|
|
52
|
-
question: 'Initial theme? 1 Mavis · 2 Midnight',
|
|
53
|
-
choices: ['mavis', 'midnight'],
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
key: 'install',
|
|
57
|
-
question: 'Install dependencies with npm? 1 No · 2 Yes',
|
|
58
|
-
choices: [false, true],
|
|
59
|
-
},
|
|
60
|
-
]
|
|
61
|
-
console.log(
|
|
62
|
-
'Vue templates are available today. React-style authoring for Vue is on the roadmap.\n',
|
|
63
|
-
)
|
|
64
|
-
try {
|
|
65
|
-
for (let index = 0; index < steps.length;) {
|
|
66
|
-
const step = steps[index]
|
|
67
|
-
if (supplied.has(step.key)) {
|
|
68
|
-
index++
|
|
69
|
-
continue
|
|
70
|
-
}
|
|
71
|
-
if (step.when && !step.when()) {
|
|
72
|
-
delete answers[step.key]
|
|
73
|
-
index++
|
|
74
|
-
continue
|
|
75
|
-
}
|
|
76
|
-
const value = (
|
|
77
|
-
await io.question(`${step.question} [${answers[step.key] ?? step.fallback ?? '1'}]: `, {
|
|
78
|
-
signal,
|
|
79
|
-
})
|
|
80
|
-
).trim()
|
|
81
|
-
if (value.toLowerCase() === 'cancel') return null
|
|
82
|
-
if (value.toLowerCase() === 'back') {
|
|
83
|
-
do {
|
|
84
|
-
index = Math.max(0, index - 1)
|
|
85
|
-
} while (
|
|
86
|
-
index > 0 &&
|
|
87
|
-
(supplied.has(steps[index].key) || (steps[index].when && !steps[index].when()))
|
|
88
|
-
)
|
|
89
|
-
continue
|
|
90
|
-
}
|
|
91
|
-
if (step.choices) {
|
|
92
|
-
const selection =
|
|
93
|
-
value === '' ? (answers[step.key] ?? step.choices[0]) : step.choices[Number(value) - 1]
|
|
94
|
-
if (selection === undefined) {
|
|
95
|
-
console.log('Choose one of the numbered options.')
|
|
96
|
-
continue
|
|
97
|
-
}
|
|
98
|
-
answers[step.key] = selection
|
|
99
|
-
} else answers[step.key] = value || answers[step.key] || step.fallback
|
|
100
|
-
index++
|
|
101
|
-
}
|
|
102
|
-
} finally {
|
|
103
|
-
io.close()
|
|
104
|
-
}
|
|
105
|
-
return answers
|
|
106
|
-
}
|
|
107
|
-
|
|
108
42
|
const cancellation = new AbortController()
|
|
109
43
|
const cancel = () => cancellation.abort()
|
|
44
|
+
const interactive = Boolean(
|
|
45
|
+
process.stdin.isTTY && process.stdout.isTTY && process.env.TERM !== 'dumb' && !process.env.CI,
|
|
46
|
+
)
|
|
47
|
+
const ui = terminalUI(interactive)
|
|
48
|
+
let plan
|
|
110
49
|
process.once('SIGINT', cancel)
|
|
50
|
+
process.once('SIGTERM', cancel)
|
|
111
51
|
try {
|
|
112
52
|
const { values, positionals } = parseArgs({
|
|
113
53
|
allowPositionals: true,
|
|
@@ -116,50 +56,122 @@ try {
|
|
|
116
56
|
web: { type: 'string' },
|
|
117
57
|
rendering: { type: 'string' },
|
|
118
58
|
theme: { type: 'string' },
|
|
59
|
+
example: { type: 'string' },
|
|
60
|
+
'check-portability': { type: 'boolean' },
|
|
61
|
+
path: { type: 'string' },
|
|
62
|
+
'fix-imports': { type: 'boolean' },
|
|
63
|
+
write: { type: 'boolean' },
|
|
64
|
+
json: { type: 'boolean' },
|
|
119
65
|
framework: { type: 'string' },
|
|
120
66
|
authoring: { type: 'string' },
|
|
121
|
-
|
|
67
|
+
'package-manager': { type: 'string' },
|
|
68
|
+
yes: { type: 'boolean', short: 'y' },
|
|
122
69
|
install: { type: 'boolean' },
|
|
123
70
|
'no-install': { type: 'boolean' },
|
|
124
71
|
'dry-run': { type: 'boolean' },
|
|
125
72
|
doctor: { type: 'boolean' },
|
|
73
|
+
version: { type: 'boolean', short: 'v' },
|
|
126
74
|
help: { type: 'boolean', short: 'h' },
|
|
127
75
|
},
|
|
128
76
|
})
|
|
129
77
|
if (values.help) console.log(help)
|
|
130
|
-
else if (values.
|
|
78
|
+
else if (values.version) console.log(version)
|
|
79
|
+
else if (values['check-portability'] || values['fix-imports']) {
|
|
80
|
+
if (values.write && !values['fix-imports']) throw new Error('--write requires --fix-imports.')
|
|
81
|
+
const result = await checkPortability(process.cwd(), {
|
|
82
|
+
path: values.path,
|
|
83
|
+
fixImports: values['fix-imports'],
|
|
84
|
+
write: values.write,
|
|
85
|
+
})
|
|
86
|
+
if (values.json) console.log(JSON.stringify(result, null, 2))
|
|
87
|
+
else {
|
|
88
|
+
for (const item of result.diagnostics)
|
|
89
|
+
console.log(`${item.file}:${item.line}:${item.column} [${item.code}] ${item.message}`)
|
|
90
|
+
for (const fix of result.fixes)
|
|
91
|
+
console.log(
|
|
92
|
+
`${result.written ? 'Updated' : 'Would update'} ${fix.file}: renderer import → #mavis`,
|
|
93
|
+
)
|
|
94
|
+
console.log(
|
|
95
|
+
`${result.files.length} files checked; ${result.diagnostics.length} findings. ${values['fix-imports'] && !values.write ? 'Preview only. Use --write to apply safe import changes.' : ''}`,
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
if (result.diagnostics.length) process.exitCode = 1
|
|
99
|
+
} else if (values.doctor) {
|
|
131
100
|
const results = await doctor()
|
|
132
101
|
for (const item of results) console.log(`${item.ok ? '✓' : '—'} ${item.name}: ${item.detail}`)
|
|
133
102
|
if (results.some((item) => !item.ok)) process.exitCode = 1
|
|
134
103
|
} else {
|
|
104
|
+
if (values.write || values.path || values.json)
|
|
105
|
+
throw new Error('--write, --path and --json require --check-portability or --fix-imports.')
|
|
135
106
|
if (positionals.length > 1) throw new Error('Provide one project name.')
|
|
136
107
|
if (values.install && values['no-install'])
|
|
137
108
|
throw new Error('Choose either --install or --no-install.')
|
|
109
|
+
const [major, minor] = process.versions.node.split('.').map(Number)
|
|
110
|
+
if (major < 22 || (major === 22 && minor < 16))
|
|
111
|
+
throw new Error(`Mavis needs Node.js 22.16 or newer. You are using ${process.version}.`)
|
|
138
112
|
let options = {
|
|
139
113
|
...values,
|
|
140
114
|
name: positionals[0],
|
|
115
|
+
packageManager: values['package-manager'],
|
|
141
116
|
install: values['no-install'] ? false : values.install,
|
|
142
117
|
dryRun: Boolean(values['dry-run']),
|
|
143
118
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
119
|
+
resolvePreset({ ...options, name: options.name ?? 'my-mavis-app' })
|
|
120
|
+
ui.intro(version)
|
|
121
|
+
const useWizard = interactive && !values.yes && !options.dryRun
|
|
122
|
+
if (useWizard) options = await wizard(options, cancellation.signal)
|
|
123
|
+
if (!options) {
|
|
124
|
+
ui.cancel('Cancelled. No files written.')
|
|
125
|
+
process.exitCode = 130
|
|
126
|
+
} else {
|
|
148
127
|
if (!options.name)
|
|
149
128
|
throw new Error('Provide a project name in non-interactive mode. Use --help for examples.')
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
129
|
+
options.packageManager ??= detectPackageManager()
|
|
130
|
+
if (options.install && !options.dryRun && !useWizard) {
|
|
131
|
+
const manager = checkPackageManager(options.packageManager)
|
|
132
|
+
if (!manager.ok)
|
|
133
|
+
throw new Error(
|
|
134
|
+
`${manager.detail}\nUse --no-install to create the project and install later.`,
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
plan = await scaffold({ ...options, signal: cancellation.signal })
|
|
138
|
+
ui.message(`${options.dryRun ? 'Planned' : 'Created'} ${plan.destination}`)
|
|
139
|
+
if (options.dryRun) {
|
|
140
|
+
console.log(projectSummary(plan.preset, options.install))
|
|
141
|
+
for (const file of plan.files.keys()) console.log(` ${file}`)
|
|
142
|
+
} else {
|
|
143
|
+
if (options.install)
|
|
144
|
+
await installProject(plan, {
|
|
145
|
+
signal: cancellation.signal,
|
|
146
|
+
onProgress: (directory) =>
|
|
147
|
+
ui.message(
|
|
148
|
+
`Installing with ${plan.preset.packageManager}${directory === '.' ? '' : ` in ${directory}`}…`,
|
|
149
|
+
),
|
|
150
|
+
})
|
|
151
|
+
ui.note(nextSteps(plan.preset, options.install), 'Next steps')
|
|
152
|
+
ui.message(`Make it yours: ${sharedEntry(plan.preset)}`)
|
|
153
|
+
if (plan.preset.target !== 'web')
|
|
154
|
+
ui.message(
|
|
155
|
+
'Mobile needs the NativeScript CLI and platform SDKs. Check your setup with --doctor.',
|
|
156
|
+
)
|
|
157
|
+
ui.success('Your Mavis project is ready. Happy building!')
|
|
158
|
+
}
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
} catch (error) {
|
|
161
|
-
|
|
162
|
-
|
|
162
|
+
if (cancellation.signal.aborted) {
|
|
163
|
+
ui.cancel(
|
|
164
|
+
plan
|
|
165
|
+
? `Cancelled. Project files are preserved in ${plan.destination}.`
|
|
166
|
+
: 'Cancelled. No files written.',
|
|
167
|
+
)
|
|
168
|
+
if (plan) ui.note(nextSteps(plan.preset), 'Resume when ready')
|
|
169
|
+
process.exitCode = 130
|
|
170
|
+
} else {
|
|
171
|
+
ui.error(error.message)
|
|
172
|
+
process.exitCode = 1
|
|
173
|
+
}
|
|
163
174
|
} finally {
|
|
164
175
|
process.off('SIGINT', cancel)
|
|
176
|
+
process.off('SIGTERM', cancel)
|
|
165
177
|
}
|
package/src/doctor.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process'
|
|
2
2
|
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { checkPortability } from './portability.mjs'
|
|
3
4
|
import { join } from 'node:path'
|
|
5
|
+
import { checkPackageManager } from './package-manager.mjs'
|
|
4
6
|
|
|
5
7
|
export async function doctor(cwd = process.cwd()) {
|
|
6
8
|
let config
|
|
@@ -16,6 +18,7 @@ export async function doctor(cwd = process.cwd()) {
|
|
|
16
18
|
ok: major > 22 || (major === 22 && minor >= 16),
|
|
17
19
|
detail: process.version,
|
|
18
20
|
},
|
|
21
|
+
checkPackageManager(config.packageManager ?? 'npm'),
|
|
19
22
|
]
|
|
20
23
|
if (config.target !== 'web') {
|
|
21
24
|
const probe = (name, command, args) => {
|
|
@@ -43,5 +46,11 @@ export async function doctor(cwd = process.cwd()) {
|
|
|
43
46
|
detail: 'iOS builds require macOS and Xcode; Android remains available.',
|
|
44
47
|
})
|
|
45
48
|
}
|
|
49
|
+
const portability = await checkPortability(cwd)
|
|
50
|
+
results.push({
|
|
51
|
+
name: 'Shared source portability',
|
|
52
|
+
ok: portability.diagnostics.length === 0,
|
|
53
|
+
detail: `${portability.files.length} files, ${portability.diagnostics.length} findings. Run --check-portability for locations and suggestions.`,
|
|
54
|
+
})
|
|
46
55
|
return results
|
|
47
56
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process'
|
|
2
|
+
|
|
3
|
+
export const packageManagers = ['npm', 'pnpm', 'yarn']
|
|
4
|
+
|
|
5
|
+
export function detectPackageManager(userAgent = process.env.npm_config_user_agent ?? '') {
|
|
6
|
+
const name = userAgent.split('/')[0]
|
|
7
|
+
return packageManagers.includes(name) ? name : 'npm'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function packageCommands(manager = 'npm') {
|
|
11
|
+
if (!packageManagers.includes(manager))
|
|
12
|
+
throw new Error('Package manager must be npm, pnpm or yarn.')
|
|
13
|
+
const directoryFlag = { npm: '--prefix', pnpm: '--dir', yarn: '--cwd' }[manager]
|
|
14
|
+
return {
|
|
15
|
+
creator:
|
|
16
|
+
manager === 'npm'
|
|
17
|
+
? 'npx @getcortexlabs/create-mavis'
|
|
18
|
+
: `${manager} create @getcortexlabs/mavis`,
|
|
19
|
+
install: `${manager} install`,
|
|
20
|
+
setup: (shared) =>
|
|
21
|
+
!shared
|
|
22
|
+
? `${manager} install`
|
|
23
|
+
: manager === 'yarn'
|
|
24
|
+
? 'yarn install\nyarn --cwd apps/mobile install'
|
|
25
|
+
: `${manager} run install:apps`,
|
|
26
|
+
run: (script, directory) =>
|
|
27
|
+
`${manager}${directory ? ` ${directoryFlag} ${directory}` : ''} run ${script}`,
|
|
28
|
+
installAt: (directory) => `${manager} ${directoryFlag} ${directory} install`,
|
|
29
|
+
lockfile: { npm: 'package-lock.json', pnpm: 'pnpm-lock.yaml', yarn: 'yarn.lock' }[manager],
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function checkPackageManager(manager) {
|
|
34
|
+
packageCommands(manager)
|
|
35
|
+
const result = spawnSync(manager, ['--version'], {
|
|
36
|
+
encoding: 'utf8',
|
|
37
|
+
timeout: 10000,
|
|
38
|
+
shell: process.platform === 'win32',
|
|
39
|
+
env: { ...process.env, COREPACK_ENABLE_AUTO_PIN: '0' },
|
|
40
|
+
})
|
|
41
|
+
if (result.error?.code === 'ENOENT')
|
|
42
|
+
return {
|
|
43
|
+
name: manager,
|
|
44
|
+
ok: false,
|
|
45
|
+
detail: `${manager} was not found on this terminal's PATH. If you just changed your shell setup, restart the creator from the updated terminal.`,
|
|
46
|
+
}
|
|
47
|
+
if (result.error?.code === 'ETIMEDOUT')
|
|
48
|
+
return {
|
|
49
|
+
name: manager,
|
|
50
|
+
ok: false,
|
|
51
|
+
detail: `${manager} --version timed out after 10 seconds. Check its setup and try again.`,
|
|
52
|
+
}
|
|
53
|
+
if (result.error || result.status !== 0) {
|
|
54
|
+
const detail = (
|
|
55
|
+
result.error?.message ||
|
|
56
|
+
result.stderr ||
|
|
57
|
+
result.stdout ||
|
|
58
|
+
`Exit ${result.status}`
|
|
59
|
+
)
|
|
60
|
+
.trim()
|
|
61
|
+
.split('\n')[0]
|
|
62
|
+
return { name: manager, ok: false, detail: `Could not run ${manager} --version: ${detail}` }
|
|
63
|
+
}
|
|
64
|
+
const version = result.stdout.trim().split('\n').at(-1)
|
|
65
|
+
if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(version))
|
|
66
|
+
return {
|
|
67
|
+
name: manager,
|
|
68
|
+
ok: false,
|
|
69
|
+
detail: `${manager} --version did not return a valid version.`,
|
|
70
|
+
}
|
|
71
|
+
const [major, minor] = version.split('.').map(Number)
|
|
72
|
+
const supported = manager !== 'pnpm' || major > 10 || (major === 10 && minor >= 26)
|
|
73
|
+
return {
|
|
74
|
+
name: manager,
|
|
75
|
+
ok: supported,
|
|
76
|
+
detail: supported ? version : `pnpm 10.26+ is required (found ${version}).`,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function runInstall(manager, cwd, signal) {
|
|
81
|
+
packageCommands(manager)
|
|
82
|
+
signal?.throwIfAborted()
|
|
83
|
+
await new Promise((resolve, reject) => {
|
|
84
|
+
const child = spawn(manager, ['install'], {
|
|
85
|
+
cwd,
|
|
86
|
+
stdio: 'inherit',
|
|
87
|
+
// Commands and arguments are fixed; cwd is never interpolated into a shell command.
|
|
88
|
+
shell: process.platform === 'win32',
|
|
89
|
+
env: { ...process.env, COREPACK_ENABLE_AUTO_PIN: '0' },
|
|
90
|
+
})
|
|
91
|
+
const abort = () => child.kill('SIGINT')
|
|
92
|
+
signal?.addEventListener('abort', abort, { once: true })
|
|
93
|
+
const cleanup = () => signal?.removeEventListener('abort', abort)
|
|
94
|
+
child.once('error', (error) => {
|
|
95
|
+
cleanup()
|
|
96
|
+
reject(error)
|
|
97
|
+
})
|
|
98
|
+
child.once('close', (code, stopped) => {
|
|
99
|
+
cleanup()
|
|
100
|
+
if (signal?.aborted) reject(signal.reason)
|
|
101
|
+
else if (code === 0) resolve()
|
|
102
|
+
else reject(new Error(`${manager} install stopped (${stopped ?? code}).`))
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
}
|