@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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { configOf, versions as v } from './capabilities.mjs'
|
|
2
|
+
import { packageCommands } from './package-manager.mjs'
|
|
3
|
+
const json = (value) => JSON.stringify(value, null, 2) + '\n'
|
|
4
|
+
const angular = Object.fromEntries(
|
|
5
|
+
['animations', 'common', 'compiler', 'core', 'forms', 'router', 'platform-browser'].map(
|
|
6
|
+
(name) => [`@angular/${name}`, '22.3.0'],
|
|
7
|
+
),
|
|
8
|
+
)
|
|
9
|
+
export const nativeFrameworkDependencies = Object.freeze({
|
|
10
|
+
plain: {},
|
|
11
|
+
react: { react: '18.3.1', 'react-nativescript': '5.0.0' },
|
|
12
|
+
angular: { ...angular, '@nativescript/angular': '22.0.2', rxjs: '7.8.2' },
|
|
13
|
+
svelte: { svelte: '4.2.20', '@nativescript-community/svelte-native': '1.0.32' },
|
|
14
|
+
solid: {
|
|
15
|
+
'solid-js': '2.0.0',
|
|
16
|
+
'@nativescript-community/solid-js': '2.0.1',
|
|
17
|
+
'@solidjs/universal': '2.0.0',
|
|
18
|
+
dominative: '0.1.3',
|
|
19
|
+
'undom-ng': '1.1.2',
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
export async function nativeFrameworkFiles(preset, copyTemplate) {
|
|
23
|
+
const files = new Map(),
|
|
24
|
+
framework = preset.framework
|
|
25
|
+
const replacements = {
|
|
26
|
+
NAME: preset.name,
|
|
27
|
+
APPID: preset.name.replaceAll('-', ''),
|
|
28
|
+
THEME: preset.theme,
|
|
29
|
+
FRAMEWORK: framework,
|
|
30
|
+
}
|
|
31
|
+
await copyTemplate(files, 'native-framework/common', '', replacements)
|
|
32
|
+
await copyTemplate(files, `native-framework/${framework}`, 'src', replacements)
|
|
33
|
+
if (framework === 'svelte')
|
|
34
|
+
await copyTemplate(files, 'native-framework/svelte-tooling', '', replacements)
|
|
35
|
+
await copyTemplate(files, 'mobile/App_Resources', 'App_Resources', replacements)
|
|
36
|
+
const peers = nativeFrameworkDependencies[framework]
|
|
37
|
+
const overrides =
|
|
38
|
+
framework === 'react'
|
|
39
|
+
? { 'react-nativescript': { '@nativescript/core': '$@nativescript/core' } }
|
|
40
|
+
: framework === 'svelte'
|
|
41
|
+
? {
|
|
42
|
+
'@nativescript-community/svelte-native': {
|
|
43
|
+
'@nativescript/core': '$@nativescript/core',
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: {}
|
|
47
|
+
const extensions = Object.fromEntries(
|
|
48
|
+
Object.entries(overrides).map(([name, deps]) => [
|
|
49
|
+
name,
|
|
50
|
+
{
|
|
51
|
+
peerDependencies: Object.fromEntries(
|
|
52
|
+
Object.entries(deps).map(([dep, version]) => [
|
|
53
|
+
dep,
|
|
54
|
+
version.startsWith('$') ? (peers[dep] ?? v.nativeCore) : version,
|
|
55
|
+
]),
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
]),
|
|
59
|
+
)
|
|
60
|
+
files.set(
|
|
61
|
+
'package.json',
|
|
62
|
+
json({
|
|
63
|
+
name: preset.name,
|
|
64
|
+
private: true,
|
|
65
|
+
version: '0.0.0',
|
|
66
|
+
main: 'src/app.ts',
|
|
67
|
+
engines: { node: '>=22.23.3' },
|
|
68
|
+
scripts: {
|
|
69
|
+
ios: 'ns run ios',
|
|
70
|
+
android: 'ns run android',
|
|
71
|
+
'bundle:ios': 'webpack --env ios',
|
|
72
|
+
'bundle:android': 'webpack --env android',
|
|
73
|
+
typecheck:
|
|
74
|
+
framework === 'svelte' ? 'svelte-check --tsconfig ./tsconfig.json' : 'tsc --noEmit',
|
|
75
|
+
},
|
|
76
|
+
dependencies: {
|
|
77
|
+
'@getcortexlabs/mavis': v.mavis,
|
|
78
|
+
'@getcortexlabs/mavis-core': v.mavis,
|
|
79
|
+
'@nativescript/core': v.nativeCore,
|
|
80
|
+
'@rafaelaugusto/jolt': v.jolt,
|
|
81
|
+
...(framework === 'plain'
|
|
82
|
+
? {}
|
|
83
|
+
: { [`@getcortexlabs/mavis-${framework}-nativescript`]: v.mavis }),
|
|
84
|
+
...peers,
|
|
85
|
+
},
|
|
86
|
+
devDependencies: {
|
|
87
|
+
'@nativescript/android': v.android,
|
|
88
|
+
'@nativescript/ios': v.ios,
|
|
89
|
+
'@nativescript/types': '9.1.1',
|
|
90
|
+
'@nativescript/webpack': v.webpack,
|
|
91
|
+
webpack: v.webpackCore,
|
|
92
|
+
'webpack-cli': v.webpackCli,
|
|
93
|
+
typescript: v.typescript,
|
|
94
|
+
...(framework === 'react' ? { '@types/react': '18.3.31' } : {}),
|
|
95
|
+
...(framework === 'svelte' ? { 'svelte-loader': '3.2.4', 'svelte-check': '3.8.6' } : {}),
|
|
96
|
+
...(framework === 'solid'
|
|
97
|
+
? {
|
|
98
|
+
'@solidjs/babel-plugin': '2.0.2',
|
|
99
|
+
'@babel/core': '7.29.13',
|
|
100
|
+
'@babel/preset-typescript': '7.29.7',
|
|
101
|
+
}
|
|
102
|
+
: {}),
|
|
103
|
+
},
|
|
104
|
+
overrides,
|
|
105
|
+
...(preset.packageManager === 'yarn'
|
|
106
|
+
? {
|
|
107
|
+
resolutions: Object.fromEntries(
|
|
108
|
+
Object.entries(overrides).flatMap(([owner, deps]) =>
|
|
109
|
+
Object.entries(deps).map(([dep]) => [
|
|
110
|
+
`${owner}/${dep}`,
|
|
111
|
+
peers[dep] ?? v.nativeCore,
|
|
112
|
+
]),
|
|
113
|
+
),
|
|
114
|
+
),
|
|
115
|
+
dependenciesMeta: {
|
|
116
|
+
'@nativescript/core': { built: true },
|
|
117
|
+
'@parcel/watcher': { built: true },
|
|
118
|
+
'core-js-pure': { built: false },
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
: {}),
|
|
122
|
+
}),
|
|
123
|
+
)
|
|
124
|
+
if (preset.packageManager === 'pnpm')
|
|
125
|
+
files.set(
|
|
126
|
+
'pnpm-workspace.yaml',
|
|
127
|
+
`packages: []\nnodeLinker: hoisted\nsideEffectsCache: false\nallowBuilds:\n '@nativescript/core': true\n '@parcel/watcher': true\n core-js-pure: false\n svelte-preprocess: false\npackageExtensions: ${JSON.stringify(extensions)}\n`,
|
|
128
|
+
)
|
|
129
|
+
if (preset.packageManager === 'yarn') {
|
|
130
|
+
files.set('yarn.lock', '')
|
|
131
|
+
files.set(
|
|
132
|
+
'.yarnrc.yml',
|
|
133
|
+
`nodeLinker: node-modules\npackageExtensions: ${JSON.stringify(extensions)}\n`,
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
files.set('.gitignore', 'node_modules/\nplatforms/\nhooks/\n.npm/\n.pnpm-store/\n.yarn/\n*.log\n')
|
|
137
|
+
files.set('mavis.config.json', json(configOf(preset)))
|
|
138
|
+
const commands = packageCommands(preset.packageManager)
|
|
139
|
+
files.set(
|
|
140
|
+
'README.md',
|
|
141
|
+
`# ${preset.name}\n\nDirect ${framework === 'plain' ? 'JavaScript/TypeScript' : framework} components on NativeScript iOS and Android.\n\n\`\`\`sh\n${commands.install}\n${commands.run('ios')}\n${commands.run('android')}\n\`\`\`\n\nEdit \`src/${framework === 'svelte' ? 'Welcome.svelte' : 'screen.ts'}\`. The screen uses its framework's state and lifecycle and renders native views directly. No Vue runtime is installed. \`src/model.ts\` supplies the starting themes and a scoped motion example.\n\nRequires Node 22.23.3+, NativeScript CLI, a JDK and Android SDK; iOS builds need macOS/Xcode. Run \`ns doctor\` and \`${commands.run('typecheck')}\`.\n\nThis starter supports MBox, MRow, MColumn, MText, MButton and MInput. The full Vue component catalog is a different adapter. Rich MText children, arbitrary MButton slots and some effects are not implemented in the direct adapters; see the Mavis native adapter guide. Web, Mac and Windows creator hosts currently use Vue and cannot be combined with this framework preset.\n\nDependencies are pinned. Core 9 compatibility overrides for React NativeScript and Svelte Native are explicit in the package-manager configuration. Jolt RC.18 accepts the selected framework without peer overrides. Only the selected framework is installed. Commit the generated lockfile. ${framework === 'svelte' ? 'Svelte Native 1.0.32 still uses the tested custom-event and bootstrap ownership workarounds in Mavis; upstream adoption is tracked in Mavis #380 and #381.' : ''}\n`,
|
|
142
|
+
)
|
|
143
|
+
return { preset, files }
|
|
144
|
+
}
|
package/src/portability.mjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { lstat, readFile, readdir, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { createRequire } from 'node:module'
|
|
3
2
|
import { normalizeConfig } from './presets.mjs'
|
|
4
3
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
5
|
-
import { pathToFileURL } from 'node:url'
|
|
6
4
|
import ts from 'typescript'
|
|
7
5
|
import { parse } from '@vue/compiler-sfc'
|
|
8
6
|
import { components, composables } from './shared-api.mjs'
|
|
9
|
-
import { checkShared } from '@getcortexlabs/mavis-compiler'
|
|
10
7
|
|
|
11
8
|
const rendererImports = new Set(['@getcortexlabs/mavis-web', '@getcortexlabs/mavis/vue'])
|
|
12
9
|
const sharedNames = new Set([...components, ...composables])
|
|
@@ -295,88 +292,6 @@ export function inspectSource(source, filename, { allowImports = [] } = {}) {
|
|
|
295
292
|
return { diagnostics, edits, imports }
|
|
296
293
|
}
|
|
297
294
|
|
|
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
|
-
|
|
380
295
|
async function projectConfig(root) {
|
|
381
296
|
try {
|
|
382
297
|
return normalizeConfig(JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8')))
|
|
@@ -390,9 +305,13 @@ async function projectConfig(root) {
|
|
|
390
305
|
export async function checkPortability(root = process.cwd(), options = {}) {
|
|
391
306
|
root = resolve(root)
|
|
392
307
|
const config = await projectConfig(root)
|
|
393
|
-
if (config.
|
|
308
|
+
if (config.framework && config.framework !== 'vue')
|
|
394
309
|
throw new Error(
|
|
395
|
-
'
|
|
310
|
+
'This source audit applies to shared Vue sources. Direct native starters use their framework typecheck and platform builds.',
|
|
311
|
+
)
|
|
312
|
+
if (config.target === 'desktop' && options.fixImports)
|
|
313
|
+
throw new Error(
|
|
314
|
+
'Migrate imports in the Web/mobile project before desktop adoption. Generated desktop hosts require the declared component subset; no files changed.',
|
|
396
315
|
)
|
|
397
316
|
const roots = options.path
|
|
398
317
|
? [options.path]
|
|
@@ -406,7 +325,6 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
406
325
|
)
|
|
407
326
|
throw new Error('Configure at least one source directory in portability.roots.')
|
|
408
327
|
const files = new Map(),
|
|
409
|
-
compiled = new Map(),
|
|
410
328
|
diagnostics = [],
|
|
411
329
|
fixes = []
|
|
412
330
|
const load = async (file, dependency = false) => {
|
|
@@ -424,9 +342,6 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
424
342
|
if (dependency) return
|
|
425
343
|
for (const item of (await readdir(file)).sort())
|
|
426
344
|
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'))
|
|
430
345
|
} else if (sourceExtensions.includes(extname(file)) && !files.has(file)) {
|
|
431
346
|
const source = await readFile(file, 'utf8')
|
|
432
347
|
const result = inspectSource(source, relative(root, file), config.portability)
|
|
@@ -491,21 +406,8 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
491
406
|
}
|
|
492
407
|
await load(file)
|
|
493
408
|
}
|
|
494
|
-
if (!files.size
|
|
409
|
+
if (!files.size)
|
|
495
410
|
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
|
-
)
|
|
509
411
|
if (options.fixImports) {
|
|
510
412
|
if (config.portability?.alias !== '#mavis')
|
|
511
413
|
throw new Error(
|
|
@@ -561,7 +463,6 @@ export async function checkPortability(root = process.cwd(), options = {}) {
|
|
|
561
463
|
diagnostics: diagnostics.sort(
|
|
562
464
|
(a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column,
|
|
563
465
|
),
|
|
564
|
-
macos,
|
|
565
466
|
fixes,
|
|
566
467
|
written: false,
|
|
567
468
|
}
|
package/src/scaffold.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
3
|
+
import { dirname, join, posix, relative, resolve, sep } from 'node:path'
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import { directoryReadme } from './reference.mjs'
|
|
6
6
|
import { configOf, resolvePreset, versions as v } from './presets.mjs'
|
|
@@ -9,10 +9,13 @@ import { packageCommands, runInstall } from './package-manager.mjs'
|
|
|
9
9
|
const templates = fileURLToPath(new URL('../templates/', import.meta.url))
|
|
10
10
|
const json = (value) => `${JSON.stringify(value, null, 2)}\n`
|
|
11
11
|
|
|
12
|
-
async function copyTemplate(files, source, destination, replacements) {
|
|
12
|
+
export async function copyTemplate(files, source, destination, replacements) {
|
|
13
13
|
for (const entry of await readdir(join(templates, source), { withFileTypes: true })) {
|
|
14
|
-
const from = join(source, entry.name),
|
|
15
|
-
to = join(
|
|
14
|
+
const from = posix.join(source, entry.name),
|
|
15
|
+
to = posix.join(
|
|
16
|
+
destination.replaceAll('\\', '/'),
|
|
17
|
+
entry.name.replace(/^_gitignore$/, '.gitignore'),
|
|
18
|
+
)
|
|
16
19
|
if (entry.isDirectory()) await copyTemplate(files, from, to, replacements)
|
|
17
20
|
// A font is copied as it is: its bytes, not text.
|
|
18
21
|
else if (/\.ttf$/.test(entry.name)) files.set(to, await readFile(join(templates, from)))
|
|
@@ -34,9 +37,13 @@ async function copyTemplate(files, source, destination, replacements) {
|
|
|
34
37
|
export async function projectFiles(options) {
|
|
35
38
|
const preset = resolvePreset(options)
|
|
36
39
|
const files = new Map()
|
|
37
|
-
if (preset.
|
|
38
|
-
const {
|
|
39
|
-
return
|
|
40
|
+
if (preset.framework !== 'vue') {
|
|
41
|
+
const { nativeFrameworkFiles } = await import('./native-framework.mjs')
|
|
42
|
+
return nativeFrameworkFiles(preset, copyTemplate)
|
|
43
|
+
}
|
|
44
|
+
if (preset.target === 'desktop') {
|
|
45
|
+
const { desktopFiles } = await import('./desktop.mjs')
|
|
46
|
+
return desktopFiles(preset, copyTemplate, projectFiles)
|
|
40
47
|
}
|
|
41
48
|
const shared = preset.target === 'both'
|
|
42
49
|
const directory = preset.example === 'directory'
|
|
@@ -275,7 +282,14 @@ export async function projectFiles(options) {
|
|
|
275
282
|
].join('\n\n') + '\n',
|
|
276
283
|
)
|
|
277
284
|
if (directory) files.set('README.md', directoryReadme(preset, sharedDir))
|
|
278
|
-
return {
|
|
285
|
+
return {
|
|
286
|
+
preset,
|
|
287
|
+
files: new Map(
|
|
288
|
+
[...files]
|
|
289
|
+
.map(([path, content]) => [path.replaceAll('\\', '/'), content])
|
|
290
|
+
.sort(([a], [b]) => a.localeCompare(b)),
|
|
291
|
+
),
|
|
292
|
+
}
|
|
279
293
|
}
|
|
280
294
|
|
|
281
295
|
export async function scaffold(options, cwd = process.cwd()) {
|
|
@@ -323,10 +337,20 @@ export async function scaffold(options, cwd = process.cwd()) {
|
|
|
323
337
|
export async function installProject(plan, { signal, onProgress } = {}) {
|
|
324
338
|
// The NativeScript app has its own dependency tree next to the root project.
|
|
325
339
|
const directories =
|
|
326
|
-
plan.preset.target === '
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
340
|
+
plan.preset.target === 'desktop'
|
|
341
|
+
? [
|
|
342
|
+
'',
|
|
343
|
+
...(plan.preset.targets.includes('native') ? ['apps/mobile'] : []),
|
|
344
|
+
...(plan.preset.targets.includes('macos') && process.platform === 'darwin'
|
|
345
|
+
? ['apps/macos']
|
|
346
|
+
: []),
|
|
347
|
+
...(plan.preset.targets.includes('windows') && process.platform === 'win32'
|
|
348
|
+
? ['apps/windows']
|
|
349
|
+
: []),
|
|
350
|
+
]
|
|
351
|
+
: plan.preset.target === 'both'
|
|
352
|
+
? ['', 'apps/mobile']
|
|
353
|
+
: ['']
|
|
330
354
|
for (const directory of directories) {
|
|
331
355
|
const cwd = join(plan.destination, directory)
|
|
332
356
|
onProgress?.(directory || '.')
|
package/src/shared-api.mjs
CHANGED
package/src/ui.mjs
CHANGED
|
@@ -28,30 +28,19 @@ export function validateDestination(name, cwd = process.cwd()) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function projectSummary(preset, install) {
|
|
31
|
-
if (preset.target === '
|
|
31
|
+
if (preset.target === 'desktop')
|
|
32
32
|
return [
|
|
33
33
|
`Project ${preset.name}`,
|
|
34
34
|
`Targets ${targetLabel(preset.targets)} · EXPERIMENTAL`,
|
|
35
|
-
`Hosts ${
|
|
36
|
-
|
|
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',
|
|
35
|
+
`Hosts ${preset.targets.map((target) => (target === 'macos' ? 'NativeScript AppKit' : target === 'windows' ? 'NativeScript XAML Islands' : target === 'native' ? 'NativeScript iOS + Android' : preset.web === 'nuxt' ? 'Nuxt' : 'Vue + Vite')).join(' · ')}`,
|
|
36
|
+
'Authoring Shared Vue screens · native desktop component subset',
|
|
46
37
|
...status(preset),
|
|
47
|
-
preset.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
: 'Example Basic welcome · shared/Welcome.lite.tsx',
|
|
52
|
-
`Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
|
|
53
|
-
`Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
|
|
38
|
+
`Framework ${catalog.frameworks[preset.framework].label}`,
|
|
39
|
+
`Example ${catalog.examples[preset.example].label}`,
|
|
40
|
+
`Theme ${preset.theme}`,
|
|
41
|
+
`Packages ${preset.packageManager} · ${install ? 'install for this OS now' : 'install later'}`,
|
|
54
42
|
].join('\n')
|
|
43
|
+
|
|
55
44
|
const web = preset.web === 'nuxt' ? `Nuxt · ${preset.rendering.toUpperCase()}` : 'Vue + Vite'
|
|
56
45
|
return [
|
|
57
46
|
`Project ${preset.name}`,
|
|
@@ -64,10 +53,10 @@ export function projectSummary(preset, install) {
|
|
|
64
53
|
}
|
|
65
54
|
|
|
66
55
|
export function sharedEntry(preset) {
|
|
67
|
-
if (preset.
|
|
68
|
-
return preset.
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
if (preset.framework !== 'vue')
|
|
57
|
+
return preset.framework === 'svelte' ? 'src/Welcome.svelte' : 'src/screen.ts'
|
|
58
|
+
if (preset.target === 'desktop')
|
|
59
|
+
return `shared/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
71
60
|
const directory =
|
|
72
61
|
preset.target === 'both' ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
|
|
73
62
|
return `${directory}/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
@@ -75,18 +64,16 @@ export function sharedEntry(preset) {
|
|
|
75
64
|
|
|
76
65
|
export function nextSteps(preset, installed = false) {
|
|
77
66
|
const commands = packageCommands(preset.packageManager)
|
|
78
|
-
if (preset.target === '
|
|
79
|
-
const has = (target) => preset.targets.includes(target)
|
|
67
|
+
if (preset.target === 'desktop')
|
|
80
68
|
return [
|
|
81
69
|
`cd ${preset.name}`,
|
|
82
|
-
...(!installed ? [
|
|
83
|
-
...(
|
|
84
|
-
...(
|
|
85
|
-
...(
|
|
86
|
-
|
|
87
|
-
|
|
70
|
+
...(!installed ? [commands.run('install:apps')] : []),
|
|
71
|
+
...(preset.targets.includes('web') ? [commands.run('dev:web')] : []),
|
|
72
|
+
...(preset.targets.includes('native') ? [commands.run('ios'), commands.run('android')] : []),
|
|
73
|
+
...(preset.targets.includes('macos') ? [commands.run('macos') + ' # on macOS'] : []),
|
|
74
|
+
...(preset.targets.includes('windows') ? [commands.run('windows') + ' # on Windows'] : []),
|
|
75
|
+
'Run --doctor on each target OS. See README for the desktop component subset.',
|
|
88
76
|
].join('\n')
|
|
89
|
-
}
|
|
90
77
|
return [
|
|
91
78
|
`cd ${preset.name}`,
|
|
92
79
|
...(!installed ? [commands.setup(preset.target === 'both')] : []),
|
|
@@ -170,6 +157,13 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
170
157
|
fallback: ['web'],
|
|
171
158
|
options: choices(catalog.targets),
|
|
172
159
|
},
|
|
160
|
+
{
|
|
161
|
+
key: 'framework',
|
|
162
|
+
message: 'Choose the framework for iOS and Android',
|
|
163
|
+
when: () => targets().length === 1 && targets()[0] === 'native',
|
|
164
|
+
fallback: 'vue',
|
|
165
|
+
options: choices(catalog.frameworks),
|
|
166
|
+
},
|
|
173
167
|
{
|
|
174
168
|
key: 'web',
|
|
175
169
|
message: 'Choose your web setup',
|
|
@@ -199,12 +193,10 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
199
193
|
options: () =>
|
|
200
194
|
choices(
|
|
201
195
|
catalog.examples,
|
|
202
|
-
Object.keys(catalog.examples).filter(
|
|
203
|
-
(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
) ||
|
|
207
|
-
(targets().includes('macos') && catalog.examples[example].portableAuthoring),
|
|
196
|
+
Object.keys(catalog.examples).filter((example) =>
|
|
197
|
+
catalog.examples[example].authoring.includes(
|
|
198
|
+
answers.framework && answers.framework !== 'vue' ? 'native' : 'vue',
|
|
199
|
+
),
|
|
208
200
|
),
|
|
209
201
|
),
|
|
210
202
|
},
|
|
@@ -323,10 +315,6 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
323
315
|
io.log.warn(error.message)
|
|
324
316
|
continue
|
|
325
317
|
}
|
|
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
318
|
}
|
|
331
319
|
answers[step.key] = value
|
|
332
320
|
index++
|
|
@@ -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.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { build } from 'esbuild'
|
|
2
|
+
import { parse, compileScript } from '@vue/compiler-sfc'
|
|
3
|
+
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { dirname, resolve } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import { createHash } from 'node:crypto'
|
|
7
|
+
|
|
8
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
await build({
|
|
10
|
+
entryPoints: [resolve(here, 'src/main.ts')],
|
|
11
|
+
outfile: resolve(here, 'dist/main.mjs'),
|
|
12
|
+
bundle: true,
|
|
13
|
+
packages: undefined,
|
|
14
|
+
external: ['@nativescript/windows-napi'],
|
|
15
|
+
nodePaths: [resolve(here, 'node_modules')],
|
|
16
|
+
platform: 'node',
|
|
17
|
+
target: 'node22',
|
|
18
|
+
format: 'esm',
|
|
19
|
+
sourcemap: true,
|
|
20
|
+
define: {
|
|
21
|
+
'process.env.NODE_ENV': '"production"',
|
|
22
|
+
__VUE_OPTIONS_API__: 'true',
|
|
23
|
+
__VUE_PROD_DEVTOOLS__: 'false',
|
|
24
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
|
|
25
|
+
},
|
|
26
|
+
alias: {
|
|
27
|
+
'#mavis': resolve(here, 'src/components.ts'),
|
|
28
|
+
'#shared-ui': resolve(here, '__MAVIS_SHARED_ROOT__'),
|
|
29
|
+
'#desktop-host': resolve(here, 'src/host.mjs'),
|
|
30
|
+
vue: resolve(here, 'node_modules/vue/dist/vue.runtime.esm-bundler.js'),
|
|
31
|
+
'vue-router': resolve(here, 'node_modules/vue-router/dist/vue-router.mjs'),
|
|
32
|
+
},
|
|
33
|
+
plugins: [
|
|
34
|
+
{
|
|
35
|
+
name: 'shared-vue-screens',
|
|
36
|
+
setup(build) {
|
|
37
|
+
build.onLoad({ filter: /\.vue$/ }, async ({ path }) => {
|
|
38
|
+
const source = await readFile(path, 'utf8')
|
|
39
|
+
const { descriptor, errors } = parse(source, { filename: path })
|
|
40
|
+
if (errors.length) throw errors[0]
|
|
41
|
+
const id = createHash('sha256').update(path).digest('hex').slice(0, 8)
|
|
42
|
+
const script = compileScript(descriptor, { id, inlineTemplate: true })
|
|
43
|
+
return { contents: script.content, loader: 'ts', resolveDir: dirname(path) }
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
console.log('Built __MAVIS_NAME__ from shared Vue screens.')
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { defineComponent, h, inject } from 'vue'
|
|
2
|
+
import { routerKey } from 'vue-router'
|
|
3
|
+
|
|
4
|
+
function component(name: string, tag: string) {
|
|
5
|
+
return defineComponent({
|
|
6
|
+
name,
|
|
7
|
+
inheritAttrs: false,
|
|
8
|
+
setup(_props, { attrs, slots }) {
|
|
9
|
+
return () => h(tag, attrs, slots.default?.())
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
function action(name: string, tag: string) {
|
|
14
|
+
return defineComponent({
|
|
15
|
+
name,
|
|
16
|
+
inheritAttrs: false,
|
|
17
|
+
setup(_props, { attrs, slots }) {
|
|
18
|
+
const router = inject(routerKey, null)
|
|
19
|
+
return () =>
|
|
20
|
+
h(
|
|
21
|
+
tag,
|
|
22
|
+
{
|
|
23
|
+
...attrs,
|
|
24
|
+
onClick: () => {
|
|
25
|
+
if (attrs.disabled || attrs.loading) return
|
|
26
|
+
const listeners = Array.isArray(attrs.onClick) ? attrs.onClick : [attrs.onClick]
|
|
27
|
+
for (const listener of listeners) if (typeof listener === 'function') listener()
|
|
28
|
+
if (typeof attrs.href === 'string') void router?.push(attrs.href)
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
slots.default?.(),
|
|
32
|
+
)
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
export const MScreen = component('MScreen', 'screen')
|
|
37
|
+
export const MColumn = component('MColumn', 'column')
|
|
38
|
+
export const MRow = component('MRow', 'row')
|
|
39
|
+
export const MGrid = component('MGrid', 'grid')
|
|
40
|
+
export const MText = component('MText', 'text')
|
|
41
|
+
export const MInput = component('MInput', 'input')
|
|
42
|
+
export const MReveal = component('MReveal', 'reveal')
|
|
43
|
+
export const MButton = action('MButton', 'button')
|
|
44
|
+
export const MLink = action('MLink', 'link')
|
|
45
|
+
export const MCard = action('MCard', 'card')
|
|
46
|
+
function message(name: string) {
|
|
47
|
+
return defineComponent({
|
|
48
|
+
name,
|
|
49
|
+
inheritAttrs: false,
|
|
50
|
+
setup(_props, { attrs }) {
|
|
51
|
+
return () =>
|
|
52
|
+
h('column', { id: attrs.id, padding: 'md', gap: 'sm' }, [
|
|
53
|
+
h('text', { variant: 'heading', tone: attrs.tone }, String(attrs.title ?? '')),
|
|
54
|
+
h('text', { tone: 'muted' }, String(attrs.description ?? '')),
|
|
55
|
+
])
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
export const MAlert = message('MAlert')
|
|
60
|
+
export const MEmptyState = message('MEmptyState')
|