@getcortexlabs/create-mavis 0.1.0-alpha.8 → 0.1.0-rc.11.1
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 +31 -6
- package/package.json +7 -2
- package/src/add-target.mjs +378 -0
- package/src/cli.mjs +231 -107
- package/src/doctor.mjs +9 -0
- package/src/package-manager.mjs +105 -0
- package/src/portability.mjs +460 -0
- package/src/presets.mjs +25 -7
- package/src/reference.mjs +45 -0
- package/src/scaffold.mjs +124 -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 +84 -0
- package/templates/mobile/tsconfig.json +9 -2
- package/templates/mobile/webpack.config.js +2 -0
- package/templates/nuxt/app/mavis.ts +84 -0
- package/templates/nuxt/nuxt.config.ts +5 -0
- package/templates/shared/Welcome.vue +114 -32
- package/templates/vite/src/mavis.ts +84 -0
- package/templates/vite/tsconfig.json +5 -1
- package/templates/vite/vite.config.ts +8 -1
package/src/scaffold.mjs
CHANGED
|
@@ -2,8 +2,9 @@ import { existsSync } from 'node:fs'
|
|
|
2
2
|
import { mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises'
|
|
3
3
|
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
|
-
import {
|
|
5
|
+
import { directoryReadme } from './reference.mjs'
|
|
6
6
|
import { resolvePreset, versions as v } from './presets.mjs'
|
|
7
|
+
import { packageCommands, runInstall } from './package-manager.mjs'
|
|
7
8
|
|
|
8
9
|
const templates = fileURLToPath(new URL('../templates/', import.meta.url))
|
|
9
10
|
const json = (value) => `${JSON.stringify(value, null, 2)}\n`
|
|
@@ -26,16 +27,35 @@ export async function projectFiles(options) {
|
|
|
26
27
|
const preset = resolvePreset(options)
|
|
27
28
|
const files = new Map()
|
|
28
29
|
const shared = preset.target === 'both'
|
|
30
|
+
const directory = preset.example === 'directory'
|
|
31
|
+
const commands = packageCommands(preset.packageManager)
|
|
32
|
+
const buildPolicy = (native) => ({
|
|
33
|
+
esbuild: true,
|
|
34
|
+
...(native
|
|
35
|
+
? { '@nativescript/core': true, '@parcel/watcher': true, 'core-js-pure': false }
|
|
36
|
+
: preset.web === 'nuxt'
|
|
37
|
+
? { 'unrs-resolver': true }
|
|
38
|
+
: {}),
|
|
39
|
+
})
|
|
40
|
+
const yarnBuilds = (native) =>
|
|
41
|
+
preset.packageManager === 'yarn'
|
|
42
|
+
? {
|
|
43
|
+
dependenciesMeta: Object.fromEntries(
|
|
44
|
+
Object.entries(buildPolicy(native)).map(([name, built]) => [name, { built }]),
|
|
45
|
+
),
|
|
46
|
+
}
|
|
47
|
+
: {}
|
|
29
48
|
const replacements = {
|
|
30
49
|
NAME: preset.name,
|
|
31
50
|
APPID: preset.name.replaceAll('-', ''),
|
|
32
51
|
THEME: preset.theme,
|
|
33
52
|
APPEARANCE: preset.theme === 'midnight' ? 'dark' : 'light',
|
|
34
|
-
SHARED:
|
|
53
|
+
SHARED: '#shared-ui',
|
|
54
|
+
SHARED_ROOT: shared ? '../../shared' : preset.web === 'nuxt' ? './app/shared' : './src/shared',
|
|
35
55
|
}
|
|
36
56
|
await copyTemplate(
|
|
37
57
|
files,
|
|
38
|
-
'shared',
|
|
58
|
+
directory ? 'directory/shared' : 'shared',
|
|
39
59
|
shared ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared',
|
|
40
60
|
replacements,
|
|
41
61
|
)
|
|
@@ -46,8 +66,9 @@ export async function projectFiles(options) {
|
|
|
46
66
|
if (preset.target !== 'mobile') {
|
|
47
67
|
await copyTemplate(files, preset.web, webDir, {
|
|
48
68
|
...replacements,
|
|
49
|
-
SHARED:
|
|
69
|
+
SHARED: '#shared-ui',
|
|
50
70
|
})
|
|
71
|
+
if (directory) await copyTemplate(files, `directory/${preset.web}`, webDir, replacements)
|
|
51
72
|
const scripts =
|
|
52
73
|
preset.web === 'vite'
|
|
53
74
|
? { dev: 'vite', build: 'vue-tsc --noEmit && vite build', preview: 'vite preview' }
|
|
@@ -64,17 +85,20 @@ export async function projectFiles(options) {
|
|
|
64
85
|
json({
|
|
65
86
|
...common,
|
|
66
87
|
name: `${preset.name}${shared ? '-web' : ''}`,
|
|
88
|
+
...yarnBuilds(false),
|
|
67
89
|
type: 'module',
|
|
68
90
|
scripts,
|
|
69
91
|
dependencies: {
|
|
70
92
|
...dependencies,
|
|
71
93
|
'@getcortexlabs/mavis-web': v.mavis,
|
|
72
94
|
vue: v.vue,
|
|
95
|
+
...(directory && preset.web === 'vite' ? { 'vue-router': v.router } : {}),
|
|
73
96
|
...(preset.web === 'nuxt' ? { nuxt: v.nuxt } : {}),
|
|
74
97
|
},
|
|
75
98
|
devDependencies: {
|
|
76
99
|
typescript: v.typescript,
|
|
77
100
|
'vue-tsc': v.vueTsc,
|
|
101
|
+
'@types/node': v.nodeTypes,
|
|
78
102
|
...(preset.web === 'vite' ? { vite: v.vite, '@vitejs/plugin-vue': v.vuePlugin } : {}),
|
|
79
103
|
},
|
|
80
104
|
}),
|
|
@@ -83,17 +107,21 @@ export async function projectFiles(options) {
|
|
|
83
107
|
if (preset.target !== 'web') {
|
|
84
108
|
await copyTemplate(files, 'mobile', mobileDir, {
|
|
85
109
|
...replacements,
|
|
86
|
-
|
|
110
|
+
SHARED_ROOT: shared ? '../../shared' : './src/shared',
|
|
111
|
+
SHARED: '#shared-ui',
|
|
87
112
|
})
|
|
113
|
+
if (directory) await copyTemplate(files, 'directory/mobile', mobileDir, replacements)
|
|
88
114
|
files.set(
|
|
89
115
|
join(mobileDir, 'package.json'),
|
|
90
116
|
json({
|
|
91
117
|
...common,
|
|
92
118
|
name: `${preset.name}${shared ? '-mobile' : ''}`,
|
|
119
|
+
...yarnBuilds(true),
|
|
93
120
|
main: 'src/app.ts',
|
|
94
121
|
scripts: {
|
|
95
122
|
android: 'ns run android',
|
|
96
123
|
ios: 'ns run ios',
|
|
124
|
+
typecheck: 'vue-tsc --noEmit',
|
|
97
125
|
'bundle:android': 'webpack --env android',
|
|
98
126
|
'bundle:ios': 'webpack --env ios',
|
|
99
127
|
},
|
|
@@ -102,12 +130,16 @@ export async function projectFiles(options) {
|
|
|
102
130
|
'@getcortexlabs/mavis': v.mavis,
|
|
103
131
|
'@nativescript/core': v.nativeCore,
|
|
104
132
|
'nativescript-vue': v.nativeVue,
|
|
133
|
+
...(directory ? { 'vue-router-ns': v.nativeRouter } : {}),
|
|
105
134
|
},
|
|
106
135
|
devDependencies: {
|
|
107
136
|
'@nativescript/android': v.android,
|
|
108
137
|
'@nativescript/ios': v.ios,
|
|
109
138
|
'@nativescript/webpack': v.webpack,
|
|
139
|
+
webpack: v.webpackCore,
|
|
140
|
+
'webpack-cli': v.webpackCli,
|
|
110
141
|
typescript: v.typescript,
|
|
142
|
+
'vue-tsc': v.vueTsc,
|
|
111
143
|
},
|
|
112
144
|
}),
|
|
113
145
|
)
|
|
@@ -118,20 +150,41 @@ export async function projectFiles(options) {
|
|
|
118
150
|
json({
|
|
119
151
|
...common,
|
|
120
152
|
name: preset.name,
|
|
121
|
-
|
|
153
|
+
...yarnBuilds(false),
|
|
154
|
+
...(preset.packageManager !== 'pnpm' ? { workspaces: ['apps/web'] } : {}),
|
|
122
155
|
scripts: {
|
|
123
|
-
'dev:web': '
|
|
124
|
-
'build:web':
|
|
125
|
-
android: '
|
|
126
|
-
ios: '
|
|
127
|
-
'install:apps':
|
|
156
|
+
'dev:web': commands.run('dev', 'apps/web'),
|
|
157
|
+
'build:web': commands.run(preset.rendering === 'ssg' ? 'generate' : 'build', 'apps/web'),
|
|
158
|
+
android: commands.run('android', 'apps/mobile'),
|
|
159
|
+
ios: commands.run('ios', 'apps/mobile'),
|
|
160
|
+
'install:apps': `${commands.install} && ${commands.installAt('apps/mobile')}`,
|
|
128
161
|
},
|
|
129
162
|
}),
|
|
130
163
|
)
|
|
131
|
-
|
|
164
|
+
if (preset.packageManager === 'pnpm') {
|
|
165
|
+
const config = (native, workspace = false) =>
|
|
166
|
+
`${workspace ? 'packages:\n - apps/web\n' : 'packages: []\n'}nodeLinker: hoisted\n${native ? 'sideEffectsCache: false\n' : ''}allowBuilds:\n${Object.entries(
|
|
167
|
+
buildPolicy(native),
|
|
168
|
+
)
|
|
169
|
+
.map(([name, allowed]) => ` ${JSON.stringify(name)}: ${allowed}\n`)
|
|
170
|
+
.join('')}`
|
|
171
|
+
files.set('pnpm-workspace.yaml', config(preset.target === 'mobile', shared))
|
|
172
|
+
if (shared) files.set('apps/mobile/pnpm-workspace.yaml', config(true))
|
|
173
|
+
}
|
|
174
|
+
if (preset.packageManager === 'yarn') {
|
|
175
|
+
files.set('.yarnrc.yml', 'nodeLinker: node-modules\n')
|
|
176
|
+
// An empty lockfile marks a separate Yarn project, including before its first install.
|
|
177
|
+
files.set('yarn.lock', '')
|
|
178
|
+
if (shared) files.set('apps/mobile/yarn.lock', '')
|
|
179
|
+
}
|
|
180
|
+
const sharedDir = shared ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
|
|
181
|
+
files.set(
|
|
182
|
+
'mavis.config.json',
|
|
183
|
+
json({ ...preset, portability: { roots: [sharedDir], alias: '#mavis', allowImports: [] } }),
|
|
184
|
+
)
|
|
132
185
|
files.set(
|
|
133
186
|
'.gitignore',
|
|
134
|
-
'node_modules/\n.npm/\ndist/\n.nuxt/\n.output/\nplatforms/\nhooks/\n.DS_Store\n*.log\n',
|
|
187
|
+
'node_modules/\n.npm/\n.pnpm-store/\n.yarn/\ndist/\n.nuxt/\n.output/\nplatforms/\nhooks/\n.DS_Store\n*.log\n',
|
|
135
188
|
)
|
|
136
189
|
const location = shared
|
|
137
190
|
? '`shared/Welcome.vue`'
|
|
@@ -140,8 +193,53 @@ export async function projectFiles(options) {
|
|
|
140
193
|
: '`src/shared/Welcome.vue`'
|
|
141
194
|
files.set(
|
|
142
195
|
'README.md',
|
|
143
|
-
|
|
196
|
+
[
|
|
197
|
+
`# ${preset.name}`,
|
|
198
|
+
`A Mavis ${shared ? 'NativeScript + Web' : preset.target} application using Vue templates.`,
|
|
199
|
+
'## Start',
|
|
200
|
+
[
|
|
201
|
+
'```sh',
|
|
202
|
+
commands.setup(shared),
|
|
203
|
+
preset.target === 'mobile'
|
|
204
|
+
? commands.run('ios')
|
|
205
|
+
: shared
|
|
206
|
+
? commands.run('dev:web')
|
|
207
|
+
: commands.run('dev'),
|
|
208
|
+
...(preset.target !== 'web'
|
|
209
|
+
? [commands.run('android'), ...(shared ? [commands.run('ios')] : [])]
|
|
210
|
+
: []),
|
|
211
|
+
'```',
|
|
212
|
+
].join('\n'),
|
|
213
|
+
`Edit ${location}. Its state and components are shared; each host provides the save service. The included service is a local demo and does not send data to a server.`,
|
|
214
|
+
...(preset.target !== 'web'
|
|
215
|
+
? [
|
|
216
|
+
'Mobile requires the NativeScript CLI and the selected platform SDK. iOS builds require macOS/Xcode; Android requires a JDK and Android SDK. Run \`ns doctor\` inside the mobile app directory.',
|
|
217
|
+
]
|
|
218
|
+
: []),
|
|
219
|
+
...(preset.web === 'nuxt'
|
|
220
|
+
? [
|
|
221
|
+
`Nuxt server rendering: \`${commands.run('build')}\`. Static output: \`${commands.run('generate')}\`. ${shared ? 'Run these inside apps/web. ' : ''}The initial appearance is deterministic during hydration; device appearance is applied after mount.`,
|
|
222
|
+
]
|
|
223
|
+
: []),
|
|
224
|
+
...(shared
|
|
225
|
+
? [
|
|
226
|
+
`The native and DOM renderers have separate dependency trees so each uses its own Vue runtime. After the initial setup above, reinstall both from the root with \`${commands.run('install:apps')}\`.`,
|
|
227
|
+
]
|
|
228
|
+
: []),
|
|
229
|
+
...(preset.packageManager === 'pnpm'
|
|
230
|
+
? [
|
|
231
|
+
'Use pnpm 10.26 or newer. The generated pnpm-workspace.yaml files configure project boundaries, a hoisted node_modules layout and the build scripts needed by the starter. This also lets shared imports, Vite deduplication and native tools resolve their dependencies.',
|
|
232
|
+
]
|
|
233
|
+
: []),
|
|
234
|
+
...(preset.packageManager === 'yarn'
|
|
235
|
+
? [
|
|
236
|
+
'Yarn Classic and modern Yarn use node_modules. The initial yarn.lock files mark project boundaries; Yarn fills them during installation. dependenciesMeta allows the starter build scripts. If Yarn reports a recently published dependency as quarantined, retry after its configured minimum package age has elapsed.',
|
|
237
|
+
]
|
|
238
|
+
: []),
|
|
239
|
+
`Dependencies are pinned in package.json. Commit ${shared ? 'both generated lockfiles' : 'the generated ' + commands.lockfile}. Mavis and Jolt are prereleases; see https://mavis-ui.getcortexlabs.com/ for current contracts.`,
|
|
240
|
+
].join('\n\n') + '\n',
|
|
144
241
|
)
|
|
242
|
+
if (directory) files.set('README.md', directoryReadme(preset, sharedDir))
|
|
145
243
|
return { preset, files: new Map([...files].sort(([a], [b]) => a.localeCompare(b))) }
|
|
146
244
|
}
|
|
147
245
|
|
|
@@ -187,24 +285,18 @@ export async function scaffold(options, cwd = process.cwd()) {
|
|
|
187
285
|
return { ...plan, destination }
|
|
188
286
|
}
|
|
189
287
|
|
|
190
|
-
export async function installProject(plan) {
|
|
288
|
+
export async function installProject(plan, { signal, onProgress } = {}) {
|
|
191
289
|
const directories = plan.preset.target === 'both' ? ['', 'apps/mobile'] : ['']
|
|
192
|
-
for (const directory of directories)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
code === 0
|
|
202
|
-
? resolve()
|
|
203
|
-
: reject(
|
|
204
|
-
new Error(
|
|
205
|
-
`npm install stopped (${signal ?? code}). Project files were preserved; retry in ${join(plan.destination, directory)}.`,
|
|
206
|
-
),
|
|
207
|
-
),
|
|
290
|
+
for (const directory of directories) {
|
|
291
|
+
const cwd = join(plan.destination, directory)
|
|
292
|
+
onProgress?.(directory || '.')
|
|
293
|
+
try {
|
|
294
|
+
await runInstall(plan.preset.packageManager ?? 'npm', cwd, signal)
|
|
295
|
+
} catch (error) {
|
|
296
|
+
if (signal?.aborted) throw error
|
|
297
|
+
throw new Error(
|
|
298
|
+
`${error.message}\nProject files were preserved. Retry with ${packageCommands(plan.preset.packageManager).install} in ${cwd}.`,
|
|
208
299
|
)
|
|
209
|
-
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
210
302
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Shared renderer exports, also used by the conservative import migration. */
|
|
2
|
+
export const components = [
|
|
3
|
+
'MThemeProvider',
|
|
4
|
+
'MSpan',
|
|
5
|
+
'MScreen',
|
|
6
|
+
'MBox',
|
|
7
|
+
'MRow',
|
|
8
|
+
'MColumn',
|
|
9
|
+
'MStack',
|
|
10
|
+
'MGrid',
|
|
11
|
+
'MLink',
|
|
12
|
+
'MCard',
|
|
13
|
+
'MText',
|
|
14
|
+
'MButton',
|
|
15
|
+
'MSlider',
|
|
16
|
+
'MSwitch',
|
|
17
|
+
'MCheckbox',
|
|
18
|
+
'MRadioGroup',
|
|
19
|
+
'MSelect',
|
|
20
|
+
'MToast',
|
|
21
|
+
'MDialog',
|
|
22
|
+
'MTabs',
|
|
23
|
+
'MSkeleton',
|
|
24
|
+
'MChip',
|
|
25
|
+
'MEmptyState',
|
|
26
|
+
'MProgress',
|
|
27
|
+
'MAccordion',
|
|
28
|
+
'MSegmentedControl',
|
|
29
|
+
'MAlert',
|
|
30
|
+
'MListItem',
|
|
31
|
+
'MSeparator',
|
|
32
|
+
'MAvatar',
|
|
33
|
+
'MBadge',
|
|
34
|
+
'MInput',
|
|
35
|
+
'MIcon',
|
|
36
|
+
'MReveal',
|
|
37
|
+
'MSheet',
|
|
38
|
+
'MDatePicker',
|
|
39
|
+
'MDateRangePicker',
|
|
40
|
+
'MNumberInput',
|
|
41
|
+
'MMultiSelect',
|
|
42
|
+
'MImage',
|
|
43
|
+
'MCombobox',
|
|
44
|
+
'MFilePicker',
|
|
45
|
+
'MFormGroup',
|
|
46
|
+
'MFormErrors',
|
|
47
|
+
'MSteps',
|
|
48
|
+
'MPagination',
|
|
49
|
+
]
|
|
50
|
+
export const composables = [
|
|
51
|
+
'useMavisTheme',
|
|
52
|
+
'useToast',
|
|
53
|
+
'useFormController',
|
|
54
|
+
'useFormField',
|
|
55
|
+
'useFileSelection',
|
|
56
|
+
'useMavisNavigation',
|
|
57
|
+
]
|
package/src/ui.mjs
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { lstatSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import * as prompts from '@clack/prompts'
|
|
4
|
+
import {
|
|
5
|
+
checkPackageManager,
|
|
6
|
+
detectPackageManager,
|
|
7
|
+
packageCommands,
|
|
8
|
+
packageManagers,
|
|
9
|
+
} from './package-manager.mjs'
|
|
10
|
+
import { resolvePreset, validateProjectName } from './presets.mjs'
|
|
11
|
+
|
|
12
|
+
export function validateDestination(name, cwd = process.cwd()) {
|
|
13
|
+
const invalid = validateProjectName(name)
|
|
14
|
+
if (invalid) return invalid
|
|
15
|
+
try {
|
|
16
|
+
lstatSync(resolve(cwd, name))
|
|
17
|
+
return `The directory "${name}" already exists. Choose a new name.`
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (error.code !== 'ENOENT') return error.message
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function projectSummary(preset, install) {
|
|
24
|
+
const web = preset.web === 'nuxt' ? `Nuxt · ${preset.rendering.toUpperCase()}` : 'Vue + Vite'
|
|
25
|
+
return [
|
|
26
|
+
`Project ${preset.name}`,
|
|
27
|
+
`Platform ${preset.target === 'mobile' ? 'iOS + Android' : preset.target === 'both' ? `${web} + iOS + Android` : web}`,
|
|
28
|
+
`Example ${preset.example === 'directory' ? 'Search, details and editing' : 'Basic project'}`,
|
|
29
|
+
`Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
|
|
30
|
+
`Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
|
|
31
|
+
].join('\n')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function sharedEntry(preset) {
|
|
35
|
+
const directory =
|
|
36
|
+
preset.target === 'both' ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
|
|
37
|
+
return `${directory}/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function nextSteps(preset, installed = false) {
|
|
41
|
+
const commands = packageCommands(preset.packageManager)
|
|
42
|
+
return [
|
|
43
|
+
`cd ${preset.name}`,
|
|
44
|
+
...(!installed ? [commands.setup(preset.target === 'both')] : []),
|
|
45
|
+
preset.target === 'mobile'
|
|
46
|
+
? commands.run('ios')
|
|
47
|
+
: preset.target === 'both'
|
|
48
|
+
? commands.run('dev:web')
|
|
49
|
+
: commands.run('dev'),
|
|
50
|
+
...(preset.target !== 'web'
|
|
51
|
+
? [
|
|
52
|
+
`${commands.run('android')}${preset.target === 'mobile' ? ' # or Android' : ''}`,
|
|
53
|
+
...(preset.target === 'both' ? [commands.run('ios')] : []),
|
|
54
|
+
]
|
|
55
|
+
: []),
|
|
56
|
+
].join('\n')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function prepareInstallation(
|
|
60
|
+
initial,
|
|
61
|
+
signal,
|
|
62
|
+
io = prompts,
|
|
63
|
+
check = checkPackageManager,
|
|
64
|
+
) {
|
|
65
|
+
const answers = { ...initial }
|
|
66
|
+
while (answers.install) {
|
|
67
|
+
signal?.throwIfAborted()
|
|
68
|
+
const manager = await check(answers.packageManager)
|
|
69
|
+
if (manager.ok) break
|
|
70
|
+
io.log.warn(manager.detail)
|
|
71
|
+
const action = await io.select({
|
|
72
|
+
message: 'How would you like to continue?',
|
|
73
|
+
signal,
|
|
74
|
+
options: [
|
|
75
|
+
{
|
|
76
|
+
value: 'change',
|
|
77
|
+
label: 'Choose another package manager',
|
|
78
|
+
hint: 'Keep your project choices',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: 'skip',
|
|
82
|
+
label: 'Create without installing',
|
|
83
|
+
hint: `Keep ${answers.packageManager} and install later`,
|
|
84
|
+
},
|
|
85
|
+
{ value: 'retry', label: 'Check again', hint: 'After making the command available' },
|
|
86
|
+
{ value: 'cancel', label: 'Cancel' },
|
|
87
|
+
],
|
|
88
|
+
})
|
|
89
|
+
if (io.isCancel(action) || action === 'cancel') return null
|
|
90
|
+
if (action === 'skip') answers.install = false
|
|
91
|
+
if (action === 'change') {
|
|
92
|
+
const selected = await io.select({
|
|
93
|
+
message: 'Choose a different package manager',
|
|
94
|
+
signal,
|
|
95
|
+
options: [
|
|
96
|
+
...packageManagers
|
|
97
|
+
.filter((name) => name !== answers.packageManager)
|
|
98
|
+
.map((name) => ({ value: name, label: name === 'yarn' ? 'Yarn' : name })),
|
|
99
|
+
{ value: 'back', label: '← Back' },
|
|
100
|
+
],
|
|
101
|
+
})
|
|
102
|
+
if (io.isCancel(selected)) return null
|
|
103
|
+
if (selected !== 'back') answers.packageManager = selected
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return answers
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function wizard(initial, signal, io = prompts, check = checkPackageManager) {
|
|
110
|
+
let answers = { ...initial }
|
|
111
|
+
const supplied = new Set(Object.keys(initial).filter((key) => initial[key] !== undefined))
|
|
112
|
+
const back = Symbol('back')
|
|
113
|
+
const steps = [
|
|
114
|
+
{ key: 'name', message: 'What is your project called?', fallback: 'my-mavis-app' },
|
|
115
|
+
{
|
|
116
|
+
key: 'target',
|
|
117
|
+
message: 'Where will it run?',
|
|
118
|
+
options: [
|
|
119
|
+
{ value: 'web', label: 'Web', hint: 'A website or web app' },
|
|
120
|
+
{
|
|
121
|
+
value: 'mobile',
|
|
122
|
+
label: 'Mobile',
|
|
123
|
+
hint: 'Native iOS and Android apps',
|
|
124
|
+
disabled: initial.web === 'nuxt' || ['ssr', 'ssg'].includes(initial.rendering),
|
|
125
|
+
},
|
|
126
|
+
{ value: 'both', label: 'Web + Mobile', hint: 'One shared screen, three platforms' },
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
key: 'web',
|
|
131
|
+
message: 'Choose your web setup',
|
|
132
|
+
when: () => answers.target !== 'mobile',
|
|
133
|
+
options: [
|
|
134
|
+
{
|
|
135
|
+
value: 'vite',
|
|
136
|
+
label: 'Vue + Vite',
|
|
137
|
+
hint: 'A client-side app, ready to build on',
|
|
138
|
+
disabled: ['ssr', 'ssg'].includes(initial.rendering),
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
value: 'nuxt',
|
|
142
|
+
label: 'Nuxt',
|
|
143
|
+
hint: 'Server rendering or a static website',
|
|
144
|
+
disabled: initial.rendering === 'client',
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
key: 'rendering',
|
|
150
|
+
message: 'How should Nuxt serve your pages?',
|
|
151
|
+
when: () => answers.target !== 'mobile' && answers.web === 'nuxt',
|
|
152
|
+
options: [
|
|
153
|
+
{ value: 'ssr', label: 'Server rendering', hint: 'Render pages on each request' },
|
|
154
|
+
{ value: 'ssg', label: 'Static generation', hint: 'Build pages ahead of time' },
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
key: 'example',
|
|
159
|
+
message: 'Choose a starting example',
|
|
160
|
+
fallback: 'welcome',
|
|
161
|
+
options: [
|
|
162
|
+
{ value: 'welcome', label: 'Basic project', hint: 'One shared screen to build on' },
|
|
163
|
+
{
|
|
164
|
+
value: 'directory',
|
|
165
|
+
label: 'Search, details and editing',
|
|
166
|
+
hint: 'Shared routes, forms and local persistence',
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
key: 'theme',
|
|
172
|
+
message: 'Pick a starting theme',
|
|
173
|
+
options: [
|
|
174
|
+
{ value: 'mavis', label: 'Mavis', hint: 'Light, warm and soft' },
|
|
175
|
+
{ value: 'midnight', label: 'Midnight', hint: 'Dark, calm and crisp' },
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
key: 'packageManager',
|
|
180
|
+
message: 'Which package manager?',
|
|
181
|
+
fallback: detectPackageManager(),
|
|
182
|
+
options: [
|
|
183
|
+
{ value: 'npm', label: 'npm', hint: 'Included with Node.js' },
|
|
184
|
+
{ value: 'pnpm', label: 'pnpm', hint: 'Fast installs, efficient disk usage · 10.26+' },
|
|
185
|
+
{ value: 'yarn', label: 'Yarn', hint: 'Classic or modern, with node_modules' },
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: 'install',
|
|
190
|
+
message: () => `Install dependencies with ${answers.packageManager}?`,
|
|
191
|
+
options: [
|
|
192
|
+
{ value: true, label: 'Yes, get it ready', hint: 'Install after creating the project' },
|
|
193
|
+
{ value: false, label: 'Not now', hint: 'Show me the commands' },
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
]
|
|
197
|
+
const visible = (step) => !supplied.has(step.key) && (!step.when || step.when())
|
|
198
|
+
const previous = (index) => {
|
|
199
|
+
for (let at = index - 1; at >= 0; at--) if (visible(steps[at])) return at
|
|
200
|
+
return -1
|
|
201
|
+
}
|
|
202
|
+
io.log.message(
|
|
203
|
+
'A shared UI. Your choice of platform.\nUse ↑/↓ to choose, Enter to continue, Ctrl-C to cancel.',
|
|
204
|
+
)
|
|
205
|
+
for (let index = 0; ;) {
|
|
206
|
+
if (index === steps.length) {
|
|
207
|
+
answers = await prepareInstallation(answers, signal, io, check)
|
|
208
|
+
if (!answers) return null
|
|
209
|
+
const preset = resolvePreset(answers)
|
|
210
|
+
io.note(projectSummary(preset, answers.install), 'Your project')
|
|
211
|
+
const action = await io.select({
|
|
212
|
+
message: 'Ready to create?',
|
|
213
|
+
signal,
|
|
214
|
+
options: [
|
|
215
|
+
{ value: 'create', label: 'Create project' },
|
|
216
|
+
...(previous(index) >= 0 ? [{ value: 'edit', label: 'Change choices' }] : []),
|
|
217
|
+
{ value: 'cancel', label: 'Cancel' },
|
|
218
|
+
],
|
|
219
|
+
})
|
|
220
|
+
if (io.isCancel(action) || action === 'cancel') return null
|
|
221
|
+
if (action === 'create') return answers
|
|
222
|
+
index = steps.findIndex(visible)
|
|
223
|
+
continue
|
|
224
|
+
}
|
|
225
|
+
const step = steps[index]
|
|
226
|
+
if (step.when && !step.when()) {
|
|
227
|
+
if (!supplied.has(step.key)) delete answers[step.key]
|
|
228
|
+
index++
|
|
229
|
+
continue
|
|
230
|
+
}
|
|
231
|
+
if (supplied.has(step.key)) {
|
|
232
|
+
index++
|
|
233
|
+
continue
|
|
234
|
+
}
|
|
235
|
+
const message = typeof step.message === 'function' ? step.message() : step.message
|
|
236
|
+
const value = step.options
|
|
237
|
+
? await io.select({
|
|
238
|
+
message,
|
|
239
|
+
signal,
|
|
240
|
+
initialValue: answers[step.key] ?? step.fallback,
|
|
241
|
+
options: [
|
|
242
|
+
...step.options,
|
|
243
|
+
...(previous(index) >= 0 ? [{ value: back, label: '← Back' }] : []),
|
|
244
|
+
],
|
|
245
|
+
})
|
|
246
|
+
: await io.text({
|
|
247
|
+
message,
|
|
248
|
+
signal,
|
|
249
|
+
placeholder: step.fallback,
|
|
250
|
+
defaultValue: step.fallback,
|
|
251
|
+
initialValue: answers[step.key],
|
|
252
|
+
validate: (value) =>
|
|
253
|
+
value === 'cancel' ? undefined : validateDestination(value || step.fallback),
|
|
254
|
+
})
|
|
255
|
+
if (io.isCancel(value) || value === 'cancel') return null
|
|
256
|
+
if (value === back) {
|
|
257
|
+
index = previous(index)
|
|
258
|
+
continue
|
|
259
|
+
}
|
|
260
|
+
answers[step.key] = value
|
|
261
|
+
index++
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function terminalUI(interactive) {
|
|
266
|
+
return {
|
|
267
|
+
intro: (version) =>
|
|
268
|
+
interactive && prompts.intro(`MAVIS / Create your next app / v${version}`),
|
|
269
|
+
message: (message) => (interactive ? prompts.log.step(message) : console.log(message)),
|
|
270
|
+
note: (message, title) =>
|
|
271
|
+
interactive ? prompts.note(message, title) : console.log(`\n${title}\n${message}`),
|
|
272
|
+
success: (message) => (interactive ? prompts.outro(message) : console.log(`\n${message}`)),
|
|
273
|
+
cancel: (message) => (interactive ? prompts.cancel(message) : console.log(message)),
|
|
274
|
+
error: (message) => (interactive ? prompts.log.error(message) : console.error(message)),
|
|
275
|
+
}
|
|
276
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createApp } from 'nativescript-vue'
|
|
2
|
+
import { ApplicationSettings } from '@nativescript/core'
|
|
3
|
+
import { createRouter } from 'vue-router-ns'
|
|
4
|
+
import { createMavisServices } from '@getcortexlabs/mavis/vue/services'
|
|
5
|
+
import { createRouterNavigation, mavis, midnight } from '@getcortexlabs/mavis-core'
|
|
6
|
+
import { createDirectory, directoryKey } from '__MAVIS_SHARED__/directory-store'
|
|
7
|
+
import { routes } from '__MAVIS_SHARED__/routes'
|
|
8
|
+
import App from './App.vue'
|
|
9
|
+
|
|
10
|
+
const router = createRouter({ routes })
|
|
11
|
+
const directory = createDirectory({
|
|
12
|
+
async read() {
|
|
13
|
+
return ApplicationSettings.getString('mavis:directory', '') || null
|
|
14
|
+
},
|
|
15
|
+
async write(value) {
|
|
16
|
+
ApplicationSettings.setString('mavis:directory', value)
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
createApp(App)
|
|
20
|
+
.use(router)
|
|
21
|
+
.use(
|
|
22
|
+
createMavisServices({
|
|
23
|
+
theme: mavis,
|
|
24
|
+
darkTheme: midnight,
|
|
25
|
+
appearance: '__MAVIS_APPEARANCE__',
|
|
26
|
+
navigation: createRouterNavigation(router),
|
|
27
|
+
claimSystemBack: (claimant) => router.claimSystemBack(claimant),
|
|
28
|
+
}),
|
|
29
|
+
)
|
|
30
|
+
.provide(directoryKey, directory)
|
|
31
|
+
.start()
|
|
32
|
+
void directory.restore()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<template><NuxtPage /></template>
|