@getcortexlabs/create-mavis 0.1.0-rc.12.2 → 0.1.0-rc.14
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 +30 -9
- package/package.json +4 -2
- package/src/adapters.mjs +83 -0
- package/src/add-macos.mjs +386 -0
- package/src/add-target.mjs +1 -1
- package/src/capabilities.mjs +647 -0
- package/src/cli.mjs +129 -16
- package/src/doctor.mjs +159 -36
- package/src/macos-capabilities.generated.mjs +4190 -0
- package/src/macos.mjs +343 -58
- package/src/migrate-directory.mjs +121 -0
- package/src/package-manager.mjs +12 -4
- package/src/portability.mjs +110 -6
- package/src/presets.mjs +15 -108
- package/src/scaffold.mjs +32 -5
- package/src/ui.mjs +124 -82
- package/templates/directory/host/directory-storage.ts +78 -0
- package/templates/directory/macos/DirectoryStorage.swift +68 -0
- package/templates/directory/mobile/src/app.ts +11 -8
- package/templates/directory/nuxt/app/plugins/mavis.ts +11 -8
- package/templates/directory/shared/Edit.vue +8 -5
- package/templates/directory/shared/directory-store.ts +42 -46
- package/templates/directory/vite/src/main.ts +11 -8
- package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +57 -0
- package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +33 -0
- package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +251 -0
- package/templates/macos/examples/tasks/shared/types.ts +10 -0
- package/templates/macos/mobile/src/App.vue +14 -0
- package/templates/macos/mobile/src/app.ts +7 -0
- package/templates/macos/native/Package.swift +11 -1
- package/templates/macos/native/Sources/MavisDesktop/App.swift +27 -12
- package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +45 -0
- package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
- package/templates/macos/root/tsconfig.json +14 -0
- package/templates/macos/scripts/generate.mjs +12 -16
- package/templates/macos/scripts/macos-manifest.mjs +33 -0
- package/templates/macos/scripts/macos.mjs +26 -19
- package/templates/macos/shared/Welcome.lite.tsx +8 -6
- package/templates/macos/{index.html → web/index.html} +2 -2
- package/templates/macos/web/src/main.js +212 -0
- package/templates/macos/web/src/mavis.js +2 -0
- package/templates/macos/web/{style.css → src/style.css} +3 -2
- package/templates/macos/web/vite.config.mjs +14 -0
- package/templates/migrations/directory-rc13.json +36 -0
- package/templates/mobile/src/mavis.ts +2 -82
- package/templates/mobile/webpack.config.js +4 -0
- package/templates/nuxt/app/mavis.ts +2 -84
- package/templates/vite/src/mavis.ts +2 -84
- package/templates/macos/scripts/portable.mjs +0 -395
- package/templates/macos/vite.config.mjs +0 -3
- package/templates/macos/web/main.js +0 -15
package/src/portability.mjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { lstat, readFile, readdir, writeFile } from 'node:fs/promises'
|
|
2
|
-
import {
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { normalizeConfig } from './presets.mjs'
|
|
4
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
5
|
+
import { pathToFileURL } from 'node:url'
|
|
3
6
|
import ts from 'typescript'
|
|
4
7
|
import { parse } from '@vue/compiler-sfc'
|
|
5
8
|
import { components, composables } from './shared-api.mjs'
|
|
9
|
+
import { checkShared } from '@getcortexlabs/mavis-compiler'
|
|
6
10
|
|
|
7
11
|
const rendererImports = new Set(['@getcortexlabs/mavis-web', '@getcortexlabs/mavis/vue'])
|
|
8
12
|
const sharedNames = new Set([...components, ...composables])
|
|
@@ -291,9 +295,91 @@ export function inspectSource(source, filename, { allowImports = [] } = {}) {
|
|
|
291
295
|
return { diagnostics, edits, imports }
|
|
292
296
|
}
|
|
293
297
|
|
|
298
|
+
// The Mavis core a project installed: the Mac check reads its theme's tokens.
|
|
299
|
+
async function projectCore(root) {
|
|
300
|
+
for (const base of ['', 'apps/web', 'apps/mobile'])
|
|
301
|
+
try {
|
|
302
|
+
const found = createRequire(join(root, base, 'package.json')).resolve(
|
|
303
|
+
'@getcortexlabs/mavis-core',
|
|
304
|
+
)
|
|
305
|
+
return await import(pathToFileURL(found))
|
|
306
|
+
} catch {}
|
|
307
|
+
try {
|
|
308
|
+
return await import('@getcortexlabs/mavis-core')
|
|
309
|
+
} catch {}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Whether each shared file can be compiled for the experimental Mac target, with the reasons
|
|
314
|
+
* the Mac compiler's own front ends give. It reads one flat folder of Name.vue, Name.lite.tsx
|
|
315
|
+
* and type files, so every folder is checked on its own.
|
|
316
|
+
*/
|
|
317
|
+
async function macReadiness(root, sources, config, only, core) {
|
|
318
|
+
core ??= await projectCore(root)
|
|
319
|
+
if (!core)
|
|
320
|
+
return {
|
|
321
|
+
checked: false,
|
|
322
|
+
reason:
|
|
323
|
+
'Install the project dependencies first: the Mac check reads the theme from @getcortexlabs/mavis-core.',
|
|
324
|
+
}
|
|
325
|
+
const folders = new Map()
|
|
326
|
+
for (const [file, source] of sources) {
|
|
327
|
+
if (/\.d\.ts$/.test(file) || !/\.(vue|ts|lite\.tsx)$/.test(file)) continue
|
|
328
|
+
const folder = dirname(file)
|
|
329
|
+
if (!folders.has(folder)) folders.set(folder, new Map())
|
|
330
|
+
folders.get(folder).set(`shared/${basename(file)}`, source)
|
|
331
|
+
}
|
|
332
|
+
const files = []
|
|
333
|
+
for (const [folder, shared] of folders) {
|
|
334
|
+
let checked
|
|
335
|
+
try {
|
|
336
|
+
checked = await checkShared(shared, core[config.theme] ?? core.mavis)
|
|
337
|
+
} catch (error) {
|
|
338
|
+
checked = [...shared.keys()].map((file) => ({
|
|
339
|
+
file,
|
|
340
|
+
ready: false,
|
|
341
|
+
problems: [{ message: error.message }],
|
|
342
|
+
}))
|
|
343
|
+
}
|
|
344
|
+
// The compiler names every file shared/…; say where it really is.
|
|
345
|
+
const actual = (text) => text.replaceAll('shared/', `${relative(root, folder)}/`)
|
|
346
|
+
for (const item of checked)
|
|
347
|
+
files.push({
|
|
348
|
+
file: actual(item.file),
|
|
349
|
+
ready: item.ready,
|
|
350
|
+
problems: item.problems.map((problem) => ({
|
|
351
|
+
...problem,
|
|
352
|
+
message: actual(problem.message),
|
|
353
|
+
})),
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
checked: true,
|
|
358
|
+
files: files
|
|
359
|
+
.filter((item) => !only || only.has(item.file))
|
|
360
|
+
.sort((a, b) => a.file.localeCompare(b.file)),
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The Mac check as lines for a terminal. */
|
|
365
|
+
export function formatMacReadiness(macos) {
|
|
366
|
+
if (!macos.checked) return `Mac target (experimental): not checked. ${macos.reason}`
|
|
367
|
+
const ready = macos.files.filter((file) => file.ready).length
|
|
368
|
+
return [
|
|
369
|
+
`Mac target (experimental): ${ready} of ${macos.files.length} shared files are ready to compile.`,
|
|
370
|
+
...macos.files.flatMap((file) => [
|
|
371
|
+
` ${file.ready ? 'ready ' : 'not ready'} ${file.file}`,
|
|
372
|
+
...file.problems.map(
|
|
373
|
+
(problem) =>
|
|
374
|
+
` ${problem.line ? `${problem.line}:${problem.column} ` : ''}${problem.message}`,
|
|
375
|
+
),
|
|
376
|
+
]),
|
|
377
|
+
].join('\n')
|
|
378
|
+
}
|
|
379
|
+
|
|
294
380
|
async function projectConfig(root) {
|
|
295
381
|
try {
|
|
296
|
-
return JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8'))
|
|
382
|
+
return normalizeConfig(JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8')))
|
|
297
383
|
} catch (error) {
|
|
298
384
|
if (error.code === 'ENOENT') return {}
|
|
299
385
|
throw new Error(`Cannot read mavis.config.json: ${error.message}`)
|
|
@@ -304,9 +390,9 @@ async function projectConfig(root) {
|
|
|
304
390
|
export async function checkPortability(root = process.cwd(), options = {}) {
|
|
305
391
|
root = resolve(root)
|
|
306
392
|
const config = await projectConfig(root)
|
|
307
|
-
if (config.authoring === 'mitosis')
|
|
393
|
+
if (config.authoring === 'mitosis' && options.fixImports)
|
|
308
394
|
throw new Error(
|
|
309
|
-
'
|
|
395
|
+
'Import migrations are not supported in a project whose shared sources are compiled for each target.',
|
|
310
396
|
)
|
|
311
397
|
const roots = options.path
|
|
312
398
|
? [options.path]
|
|
@@ -320,6 +406,7 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
320
406
|
)
|
|
321
407
|
throw new Error('Configure at least one source directory in portability.roots.')
|
|
322
408
|
const files = new Map(),
|
|
409
|
+
compiled = new Map(),
|
|
323
410
|
diagnostics = [],
|
|
324
411
|
fixes = []
|
|
325
412
|
const load = async (file, dependency = false) => {
|
|
@@ -337,6 +424,9 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
337
424
|
if (dependency) return
|
|
338
425
|
for (const item of (await readdir(file)).sort())
|
|
339
426
|
if (!ignored.has(item)) await load(join(file, item))
|
|
427
|
+
} else if (/\.lite\.tsx$/.test(file)) {
|
|
428
|
+
// Compiled for every target, never run as written: only the Mac check below reads it.
|
|
429
|
+
compiled.set(file, await readFile(file, 'utf8'))
|
|
340
430
|
} else if (sourceExtensions.includes(extname(file)) && !files.has(file)) {
|
|
341
431
|
const source = await readFile(file, 'utf8')
|
|
342
432
|
const result = inspectSource(source, relative(root, file), config.portability)
|
|
@@ -401,8 +491,21 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
401
491
|
}
|
|
402
492
|
await load(file)
|
|
403
493
|
}
|
|
404
|
-
if (!files.size)
|
|
494
|
+
if (!files.size && !compiled.size)
|
|
405
495
|
throw new Error('No Vue or script sources found in the configured portability paths.')
|
|
496
|
+
const within = new Set()
|
|
497
|
+
for (const name of roots) {
|
|
498
|
+
const start = resolve(root, name)
|
|
499
|
+
for (const file of [...files.keys(), ...compiled.keys()])
|
|
500
|
+
if (file === start || file.startsWith(start + sep)) within.add(relative(root, file))
|
|
501
|
+
}
|
|
502
|
+
const macos = await macReadiness(
|
|
503
|
+
root,
|
|
504
|
+
new Map([...[...files].map(([file, { source }]) => [file, source]), ...compiled]),
|
|
505
|
+
config,
|
|
506
|
+
within,
|
|
507
|
+
options.core,
|
|
508
|
+
)
|
|
406
509
|
if (options.fixImports) {
|
|
407
510
|
if (config.portability?.alias !== '#mavis')
|
|
408
511
|
throw new Error(
|
|
@@ -449,7 +552,7 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
449
552
|
throw new Error(`Source changed during migration: ${fix.file}`)
|
|
450
553
|
}
|
|
451
554
|
for (const fix of fixes) await writeFile(join(root, fix.file), fix.after)
|
|
452
|
-
const after = await checkPortability(root, { path: options.path })
|
|
555
|
+
const after = await checkPortability(root, { path: options.path, core: options.core })
|
|
453
556
|
return { ...after, fixes, written: true }
|
|
454
557
|
}
|
|
455
558
|
}
|
|
@@ -458,6 +561,7 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
458
561
|
diagnostics: diagnostics.sort(
|
|
459
562
|
(a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column,
|
|
460
563
|
),
|
|
564
|
+
macos,
|
|
461
565
|
fixes,
|
|
462
566
|
written: false,
|
|
463
567
|
}
|
package/src/presets.mjs
CHANGED
|
@@ -1,108 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
nativeVue: '3.1.3',
|
|
17
|
-
android: '9.1.1',
|
|
18
|
-
ios: '9.1.0',
|
|
19
|
-
webpack: '5.0.39',
|
|
20
|
-
webpackCore: '5.112.2',
|
|
21
|
-
webpackCli: '6.0.1',
|
|
22
|
-
router: '4.6.4',
|
|
23
|
-
nativeRouter: '0.1.0-rc.4',
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
export function validateProjectName(name) {
|
|
27
|
-
if (!/^[a-z][a-z0-9-]{0,63}$/.test(name ?? ''))
|
|
28
|
-
return 'Use a project name of 1–64 lowercase letters, numbers or hyphens, starting with a letter.'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function resolvePreset(options) {
|
|
32
|
-
const {
|
|
33
|
-
name,
|
|
34
|
-
target = 'web',
|
|
35
|
-
web = 'vite',
|
|
36
|
-
rendering = web === 'nuxt' ? 'ssr' : 'client',
|
|
37
|
-
theme = 'mavis',
|
|
38
|
-
framework = 'vue',
|
|
39
|
-
authoring = target === 'macos' ? 'mitosis' : 'vue',
|
|
40
|
-
example = 'welcome',
|
|
41
|
-
packageManager = 'npm',
|
|
42
|
-
} = options
|
|
43
|
-
const invalidName = validateProjectName(name)
|
|
44
|
-
if (invalidName) throw new Error(invalidName)
|
|
45
|
-
if (!packageManagers.includes(packageManager))
|
|
46
|
-
throw new Error('Package manager must be npm, pnpm or yarn.')
|
|
47
|
-
if (!['welcome', 'directory'].includes(example))
|
|
48
|
-
throw new Error('Example must be welcome or directory.')
|
|
49
|
-
if (framework !== 'vue')
|
|
50
|
-
throw new Error(
|
|
51
|
-
'This creator currently supports Vue. Other framework adapters are tracked in Mavis #145 and #35–39.',
|
|
52
|
-
)
|
|
53
|
-
if (target === 'macos') {
|
|
54
|
-
if (
|
|
55
|
-
authoring !== 'mitosis' ||
|
|
56
|
-
web !== 'vite' ||
|
|
57
|
-
rendering !== 'client' ||
|
|
58
|
-
example !== 'welcome'
|
|
59
|
-
)
|
|
60
|
-
throw new Error(
|
|
61
|
-
'Experimental macOS supports Mitosis authoring, Vue + Vite and the basic welcome example only. Existing Vue screens, Nuxt and directory are not converted.',
|
|
62
|
-
)
|
|
63
|
-
if (!['mavis', 'midnight'].includes(theme)) throw new Error('Theme must be mavis or midnight.')
|
|
64
|
-
return Object.freeze({
|
|
65
|
-
schemaVersion: 1,
|
|
66
|
-
name,
|
|
67
|
-
target,
|
|
68
|
-
framework,
|
|
69
|
-
authoring,
|
|
70
|
-
example,
|
|
71
|
-
web,
|
|
72
|
-
rendering,
|
|
73
|
-
theme,
|
|
74
|
-
packageManager,
|
|
75
|
-
experimental: 'mitosis-swiftui',
|
|
76
|
-
versions,
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
if (authoring !== 'vue')
|
|
80
|
-
throw new Error(
|
|
81
|
-
'Portable JSX/React-style authoring for Vue is planned in Mavis #167; use Vue templates in this version.',
|
|
82
|
-
)
|
|
83
|
-
if (!['mobile', 'web', 'both'].includes(target))
|
|
84
|
-
throw new Error('Target must be mobile, web, both or macos (experimental).')
|
|
85
|
-
if (!['vite', 'nuxt'].includes(web))
|
|
86
|
-
throw new Error('Web host must be vite or nuxt. React/Next are not available yet.')
|
|
87
|
-
if (!['mavis', 'midnight'].includes(theme)) throw new Error('Theme must be mavis or midnight.')
|
|
88
|
-
if (target === 'mobile' && (web !== 'vite' || rendering !== 'client'))
|
|
89
|
-
throw new Error('A mobile-only project has no Web rendering mode.')
|
|
90
|
-
if (
|
|
91
|
-
(web === 'vite' && rendering !== 'client') ||
|
|
92
|
-
(web === 'nuxt' && !['ssr', 'ssg'].includes(rendering))
|
|
93
|
-
)
|
|
94
|
-
throw new Error('Choose client rendering for Vite or ssr/ssg for Nuxt.')
|
|
95
|
-
return Object.freeze({
|
|
96
|
-
schemaVersion: 1,
|
|
97
|
-
name,
|
|
98
|
-
target,
|
|
99
|
-
framework,
|
|
100
|
-
authoring,
|
|
101
|
-
example,
|
|
102
|
-
web: target === 'mobile' ? null : web,
|
|
103
|
-
rendering: target === 'mobile' ? null : rendering,
|
|
104
|
-
theme,
|
|
105
|
-
packageManager,
|
|
106
|
-
versions,
|
|
107
|
-
})
|
|
108
|
-
}
|
|
1
|
+
// Project choices are resolved from the capability catalog; this module keeps the names
|
|
2
|
+
// the rest of the creator and its checks import.
|
|
3
|
+
export {
|
|
4
|
+
versions,
|
|
5
|
+
validateProjectName,
|
|
6
|
+
targetNames,
|
|
7
|
+
parseTargets,
|
|
8
|
+
projectTargets,
|
|
9
|
+
layoutOf,
|
|
10
|
+
targetLabel,
|
|
11
|
+
chosenTargets,
|
|
12
|
+
resolvePreset,
|
|
13
|
+
configOf,
|
|
14
|
+
normalizeConfig,
|
|
15
|
+
} from './capabilities.mjs'
|
package/src/scaffold.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, writeFile } from
|
|
|
3
3
|
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import { directoryReadme } from './reference.mjs'
|
|
6
|
-
import { resolvePreset, versions as v } from './presets.mjs'
|
|
6
|
+
import { configOf, resolvePreset, versions as v } from './presets.mjs'
|
|
7
7
|
import { packageCommands, runInstall } from './package-manager.mjs'
|
|
8
8
|
|
|
9
9
|
const templates = fileURLToPath(new URL('../templates/', import.meta.url))
|
|
@@ -14,8 +14,16 @@ async function copyTemplate(files, source, destination, replacements) {
|
|
|
14
14
|
const from = join(source, entry.name),
|
|
15
15
|
to = join(destination, entry.name.replace(/^_gitignore$/, '.gitignore'))
|
|
16
16
|
if (entry.isDirectory()) await copyTemplate(files, from, to, replacements)
|
|
17
|
+
// A font is copied as it is: its bytes, not text.
|
|
18
|
+
else if (/\.ttf$/.test(entry.name)) files.set(to, await readFile(join(templates, from)))
|
|
17
19
|
else {
|
|
18
20
|
let content = await readFile(join(templates, from), 'utf8')
|
|
21
|
+
// This adapter lives beside shared/ in the template, beside its host entry when generated.
|
|
22
|
+
if (from === 'directory/host/directory-storage.ts')
|
|
23
|
+
content = content.replace(
|
|
24
|
+
"'../shared/directory-store'",
|
|
25
|
+
"'__MAVIS_SHARED__/directory-store'",
|
|
26
|
+
)
|
|
19
27
|
for (const [key, value] of Object.entries(replacements))
|
|
20
28
|
content = content.replaceAll(`__MAVIS_${key}__`, value)
|
|
21
29
|
files.set(to, content)
|
|
@@ -78,7 +86,15 @@ export async function projectFiles(options) {
|
|
|
78
86
|
...replacements,
|
|
79
87
|
SHARED: '#shared-ui',
|
|
80
88
|
})
|
|
81
|
-
if (directory)
|
|
89
|
+
if (directory) {
|
|
90
|
+
await copyTemplate(files, `directory/${preset.web}`, webDir, replacements)
|
|
91
|
+
await copyTemplate(
|
|
92
|
+
files,
|
|
93
|
+
'directory/host',
|
|
94
|
+
join(webDir, preset.web === 'nuxt' ? 'app/utils' : 'src'),
|
|
95
|
+
replacements,
|
|
96
|
+
)
|
|
97
|
+
}
|
|
82
98
|
const scripts =
|
|
83
99
|
preset.web === 'vite'
|
|
84
100
|
? { dev: 'vite', build: 'vue-tsc --noEmit && vite build', preview: 'vite preview' }
|
|
@@ -122,7 +138,10 @@ export async function projectFiles(options) {
|
|
|
122
138
|
SHARED_ROOT: shared ? '../../shared' : './src/shared',
|
|
123
139
|
SHARED: '#shared-ui',
|
|
124
140
|
})
|
|
125
|
-
if (directory)
|
|
141
|
+
if (directory) {
|
|
142
|
+
await copyTemplate(files, 'directory/mobile', mobileDir, replacements)
|
|
143
|
+
await copyTemplate(files, 'directory/host', join(mobileDir, 'src'), replacements)
|
|
144
|
+
}
|
|
126
145
|
files.set(
|
|
127
146
|
join(mobileDir, 'package.json'),
|
|
128
147
|
json({
|
|
@@ -193,7 +212,10 @@ export async function projectFiles(options) {
|
|
|
193
212
|
const sharedDir = shared ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
|
|
194
213
|
files.set(
|
|
195
214
|
'mavis.config.json',
|
|
196
|
-
json({
|
|
215
|
+
json({
|
|
216
|
+
...configOf(preset),
|
|
217
|
+
portability: { roots: [sharedDir], alias: '#mavis', allowImports: [] },
|
|
218
|
+
}),
|
|
197
219
|
)
|
|
198
220
|
files.set(
|
|
199
221
|
'.gitignore',
|
|
@@ -299,7 +321,12 @@ export async function scaffold(options, cwd = process.cwd()) {
|
|
|
299
321
|
}
|
|
300
322
|
|
|
301
323
|
export async function installProject(plan, { signal, onProgress } = {}) {
|
|
302
|
-
|
|
324
|
+
// The NativeScript app has its own dependency tree next to the root project.
|
|
325
|
+
const directories =
|
|
326
|
+
plan.preset.target === 'both' ||
|
|
327
|
+
(plan.preset.target === 'macos' && plan.preset.targets.includes('native'))
|
|
328
|
+
? ['', 'apps/mobile']
|
|
329
|
+
: ['']
|
|
303
330
|
for (const directory of directories) {
|
|
304
331
|
const cwd = join(plan.destination, directory)
|
|
305
332
|
onProgress?.(directory || '.')
|
package/src/ui.mjs
CHANGED
|
@@ -7,7 +7,14 @@ import {
|
|
|
7
7
|
packageCommands,
|
|
8
8
|
packageManagers,
|
|
9
9
|
} from './package-manager.mjs'
|
|
10
|
-
import { resolvePreset, validateProjectName } from './presets.mjs'
|
|
10
|
+
import { chosenTargets, resolvePreset, targetLabel, validateProjectName } from './presets.mjs'
|
|
11
|
+
import { availabilityLabel, catalog, requirements } from './capabilities.mjs'
|
|
12
|
+
|
|
13
|
+
// Wizard options come from the catalog, so prompts and flags accept the same things.
|
|
14
|
+
const choices = (family, names = Object.keys(family)) =>
|
|
15
|
+
names.map((value) => ({ value, label: family[value].label, hint: family[value].hint }))
|
|
16
|
+
const status = (preset) =>
|
|
17
|
+
preset.availability === 'published' ? [] : [`Status ${availabilityLabel(preset.availability)}`]
|
|
11
18
|
|
|
12
19
|
export function validateDestination(name, cwd = process.cwd()) {
|
|
13
20
|
const invalid = validateProjectName(name)
|
|
@@ -24,24 +31,43 @@ export function projectSummary(preset, install) {
|
|
|
24
31
|
if (preset.target === 'macos')
|
|
25
32
|
return [
|
|
26
33
|
`Project ${preset.name}`,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
`Targets ${targetLabel(preset.targets)} · EXPERIMENTAL`,
|
|
35
|
+
`Hosts ${[
|
|
36
|
+
preset.targets.includes('web') &&
|
|
37
|
+
(preset.web === 'nuxt' ? `Nuxt · ${preset.rendering.toUpperCase()}` : 'Vue + Vite'),
|
|
38
|
+
preset.targets.includes('native') && 'NativeScript iOS + Android',
|
|
39
|
+
preset.targets.includes('macos') && 'SwiftUI macOS',
|
|
40
|
+
]
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.join(' · ')}`,
|
|
43
|
+
preset.authoring === 'vue'
|
|
44
|
+
? 'Authoring Shared Vue (shared/*.vue), compiled to SwiftUI for Mac'
|
|
45
|
+
: 'Authoring Shared TSX (shared/*.lite.tsx), compiled for each target',
|
|
46
|
+
...status(preset),
|
|
47
|
+
preset.example === 'directory'
|
|
48
|
+
? 'Example Search, details and editing · shared/Directory.vue'
|
|
49
|
+
: preset.example === 'tasks'
|
|
50
|
+
? 'Example Tasks · list and detail, forms, shortcuts and motion · shared/Tasks.lite.tsx'
|
|
51
|
+
: 'Example Basic welcome · shared/Welcome.lite.tsx',
|
|
52
|
+
`Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
|
|
31
53
|
`Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
|
|
32
54
|
].join('\n')
|
|
33
55
|
const web = preset.web === 'nuxt' ? `Nuxt · ${preset.rendering.toUpperCase()}` : 'Vue + Vite'
|
|
34
56
|
return [
|
|
35
57
|
`Project ${preset.name}`,
|
|
36
58
|
`Platform ${preset.target === 'mobile' ? 'iOS + Android' : preset.target === 'both' ? `${web} + iOS + Android` : web}`,
|
|
37
|
-
`Example ${preset.example
|
|
59
|
+
`Example ${catalog.examples[preset.example].label}`,
|
|
60
|
+
...status(preset),
|
|
38
61
|
`Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
|
|
39
62
|
`Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
|
|
40
63
|
].join('\n')
|
|
41
64
|
}
|
|
42
65
|
|
|
43
66
|
export function sharedEntry(preset) {
|
|
44
|
-
if (preset.target === 'macos')
|
|
67
|
+
if (preset.target === 'macos')
|
|
68
|
+
return preset.example === 'directory'
|
|
69
|
+
? 'shared/Directory.vue'
|
|
70
|
+
: `shared/${preset.example === 'tasks' ? 'Tasks' : 'Welcome'}.lite.tsx`
|
|
45
71
|
const directory =
|
|
46
72
|
preset.target === 'both' ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
|
|
47
73
|
return `${directory}/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
@@ -49,14 +75,18 @@ export function sharedEntry(preset) {
|
|
|
49
75
|
|
|
50
76
|
export function nextSteps(preset, installed = false) {
|
|
51
77
|
const commands = packageCommands(preset.packageManager)
|
|
52
|
-
if (preset.target === 'macos')
|
|
78
|
+
if (preset.target === 'macos') {
|
|
79
|
+
const has = (target) => preset.targets.includes(target)
|
|
53
80
|
return [
|
|
54
81
|
`cd ${preset.name}`,
|
|
55
|
-
...(!installed ? [commands.install] : []),
|
|
56
|
-
commands.run('
|
|
57
|
-
|
|
58
|
-
'
|
|
82
|
+
...(!installed ? [has('native') ? commands.setup(true) : commands.install] : []),
|
|
83
|
+
...(has('web') ? [commands.run('dev:web')] : []),
|
|
84
|
+
...(has('native') ? [commands.run('ios'), commands.run('android')] : []),
|
|
85
|
+
...(has('macos')
|
|
86
|
+
? [commands.run('macos'), 'macOS 14+ and Xcode required for the Mac app.']
|
|
87
|
+
: []),
|
|
59
88
|
].join('\n')
|
|
89
|
+
}
|
|
60
90
|
return [
|
|
61
91
|
`cd ${preset.name}`,
|
|
62
92
|
...(!installed ? [commands.setup(preset.target === 'both')] : []),
|
|
@@ -127,82 +157,61 @@ export async function prepareInstallation(
|
|
|
127
157
|
export async function wizard(initial, signal, io = prompts, check = checkPackageManager) {
|
|
128
158
|
let answers = { ...initial }
|
|
129
159
|
const supplied = new Set(Object.keys(initial).filter((key) => initial[key] !== undefined))
|
|
160
|
+
// --target and --targets both answer the targets question.
|
|
161
|
+
if (initial.target !== undefined) supplied.add('targets')
|
|
162
|
+
const targets = () => (answers.targets || answers.target ? chosenTargets(answers) : [])
|
|
130
163
|
const back = Symbol('back')
|
|
131
164
|
const steps = [
|
|
132
165
|
{ key: 'name', message: 'What is your project called?', fallback: 'my-mavis-app' },
|
|
133
166
|
{
|
|
134
|
-
key: '
|
|
135
|
-
message: 'Where will it run?',
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
value: 'mobile',
|
|
140
|
-
label: 'Mobile',
|
|
141
|
-
hint: 'Native iOS and Android apps',
|
|
142
|
-
disabled: initial.web === 'nuxt' || ['ssr', 'ssg'].includes(initial.rendering),
|
|
143
|
-
},
|
|
144
|
-
{ value: 'both', label: 'Web + Mobile', hint: 'One shared screen, three platforms' },
|
|
145
|
-
{
|
|
146
|
-
value: 'macos',
|
|
147
|
-
label: 'macOS + Web · experimental',
|
|
148
|
-
hint: 'Mitosis → SwiftUI and Vue · basic starter only',
|
|
149
|
-
disabled:
|
|
150
|
-
initial.web === 'nuxt' ||
|
|
151
|
-
['ssr', 'ssg'].includes(initial.rendering) ||
|
|
152
|
-
initial.example === 'directory' ||
|
|
153
|
-
(initial.authoring && initial.authoring !== 'mitosis'),
|
|
154
|
-
},
|
|
155
|
-
],
|
|
167
|
+
key: 'targets',
|
|
168
|
+
message: 'Where will it run? Space selects, Enter continues',
|
|
169
|
+
multiple: true,
|
|
170
|
+
fallback: ['web'],
|
|
171
|
+
options: choices(catalog.targets),
|
|
156
172
|
},
|
|
157
173
|
{
|
|
158
174
|
key: 'web',
|
|
159
175
|
message: 'Choose your web setup',
|
|
160
|
-
when: () =>
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
value
|
|
170
|
-
|
|
171
|
-
hint: 'Server rendering or a static website',
|
|
172
|
-
disabled: initial.rendering === 'client',
|
|
173
|
-
},
|
|
174
|
-
],
|
|
176
|
+
when: () => targets().includes('web'),
|
|
177
|
+
// A --rendering flag leaves only the hosts that can serve it.
|
|
178
|
+
options: choices(
|
|
179
|
+
catalog.hosts,
|
|
180
|
+
Object.keys(catalog.hosts).filter((host) => catalog.hosts[host].status !== 'planned'),
|
|
181
|
+
).map((option) => ({
|
|
182
|
+
...option,
|
|
183
|
+
disabled:
|
|
184
|
+
initial.rendering !== undefined &&
|
|
185
|
+
!catalog.hosts[option.value].rendering.includes(initial.rendering),
|
|
186
|
+
})),
|
|
175
187
|
},
|
|
176
188
|
{
|
|
177
189
|
key: 'rendering',
|
|
178
190
|
message: 'How should Nuxt serve your pages?',
|
|
179
|
-
when: () =>
|
|
180
|
-
options:
|
|
181
|
-
{ value: 'ssr', label: 'Server rendering', hint: 'Render pages on each request' },
|
|
182
|
-
{ value: 'ssg', label: 'Static generation', hint: 'Build pages ahead of time' },
|
|
183
|
-
],
|
|
191
|
+
when: () => targets().includes('web') && answers.web === 'nuxt',
|
|
192
|
+
options: choices(catalog.rendering, catalog.hosts.nuxt.rendering),
|
|
184
193
|
},
|
|
185
194
|
{
|
|
186
195
|
key: 'example',
|
|
187
|
-
when: () => answers.target !== 'macos',
|
|
188
196
|
message: 'Choose a starting example',
|
|
189
197
|
fallback: 'welcome',
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
// The examples written the way these targets are: Vue templates, or shared TSX with Mac.
|
|
199
|
+
options: () =>
|
|
200
|
+
choices(
|
|
201
|
+
catalog.examples,
|
|
202
|
+
Object.keys(catalog.examples).filter(
|
|
203
|
+
(example) =>
|
|
204
|
+
catalog.examples[example].authoring.includes(
|
|
205
|
+
targets().includes('macos') ? 'mitosis' : 'vue',
|
|
206
|
+
) ||
|
|
207
|
+
(targets().includes('macos') && catalog.examples[example].portableAuthoring),
|
|
208
|
+
),
|
|
209
|
+
),
|
|
198
210
|
},
|
|
199
211
|
{
|
|
200
212
|
key: 'theme',
|
|
201
213
|
message: 'Pick a starting theme',
|
|
202
|
-
options:
|
|
203
|
-
{ value: 'mavis', label: 'Mavis', hint: 'Light, warm and soft' },
|
|
204
|
-
{ value: 'midnight', label: 'Midnight', hint: 'Dark, calm and crisp' },
|
|
205
|
-
],
|
|
214
|
+
options: choices(catalog.themes),
|
|
206
215
|
},
|
|
207
216
|
{
|
|
208
217
|
key: 'packageManager',
|
|
@@ -210,7 +219,11 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
210
219
|
fallback: detectPackageManager(),
|
|
211
220
|
options: [
|
|
212
221
|
{ value: 'npm', label: 'npm', hint: 'Included with Node.js' },
|
|
213
|
-
{
|
|
222
|
+
{
|
|
223
|
+
value: 'pnpm',
|
|
224
|
+
label: 'pnpm',
|
|
225
|
+
hint: `Fast installs, efficient disk usage · ${requirements.packageManagers.pnpm}+`,
|
|
226
|
+
},
|
|
214
227
|
{ value: 'yarn', label: 'Yarn', hint: 'Classic or modern, with node_modules' },
|
|
215
228
|
],
|
|
216
229
|
},
|
|
@@ -262,30 +275,59 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
262
275
|
continue
|
|
263
276
|
}
|
|
264
277
|
const message = typeof step.message === 'function' ? step.message() : step.message
|
|
265
|
-
const
|
|
266
|
-
|
|
278
|
+
const options = typeof step.options === 'function' ? step.options() : step.options
|
|
279
|
+
const value = step.multiple
|
|
280
|
+
? await io.multiselect({
|
|
267
281
|
message,
|
|
268
282
|
signal,
|
|
269
|
-
|
|
283
|
+
required: true,
|
|
284
|
+
initialValues: answers[step.key] ?? step.fallback,
|
|
270
285
|
options: [
|
|
271
|
-
...
|
|
286
|
+
...options,
|
|
272
287
|
...(previous(index) >= 0 ? [{ value: back, label: '← Back' }] : []),
|
|
273
288
|
],
|
|
274
289
|
})
|
|
275
|
-
:
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
290
|
+
: options
|
|
291
|
+
? await io.select({
|
|
292
|
+
message,
|
|
293
|
+
signal,
|
|
294
|
+
// An earlier answer may not exist for the targets chosen since.
|
|
295
|
+
initialValue: options.some((option) => option.value === answers[step.key])
|
|
296
|
+
? answers[step.key]
|
|
297
|
+
: step.fallback,
|
|
298
|
+
options: [
|
|
299
|
+
...options,
|
|
300
|
+
...(previous(index) >= 0 ? [{ value: back, label: '← Back' }] : []),
|
|
301
|
+
],
|
|
302
|
+
})
|
|
303
|
+
: await io.text({
|
|
304
|
+
message,
|
|
305
|
+
signal,
|
|
306
|
+
placeholder: step.fallback,
|
|
307
|
+
defaultValue: step.fallback,
|
|
308
|
+
initialValue: answers[step.key],
|
|
309
|
+
validate: (value) =>
|
|
310
|
+
value === 'cancel' ? undefined : validateDestination(value || step.fallback),
|
|
311
|
+
})
|
|
284
312
|
if (io.isCancel(value) || value === 'cancel') return null
|
|
285
|
-
if (value === back) {
|
|
313
|
+
if (value === back || (Array.isArray(value) && value.includes(back))) {
|
|
286
314
|
index = previous(index)
|
|
287
315
|
continue
|
|
288
316
|
}
|
|
317
|
+
if (step.key === 'targets') {
|
|
318
|
+
// Explain choices that don't fit together before going further, then ask again.
|
|
319
|
+
try {
|
|
320
|
+
// Only flags constrain the targets; later answers are asked again for these targets.
|
|
321
|
+
resolvePreset({ ...initial, name: answers.name ?? 'my-mavis-app', targets: value })
|
|
322
|
+
} catch (error) {
|
|
323
|
+
io.log.warn(error.message)
|
|
324
|
+
continue
|
|
325
|
+
}
|
|
326
|
+
if (value.includes('macos'))
|
|
327
|
+
io.log.message(
|
|
328
|
+
`The Mac app uses generated SwiftUI. Choose shared TSX or the Directory example with shared Vue screens. Web can use Vue + Vite or Nuxt.`,
|
|
329
|
+
)
|
|
330
|
+
}
|
|
289
331
|
answers[step.key] = value
|
|
290
332
|
index++
|
|
291
333
|
}
|