@getcortexlabs/create-mavis 0.1.0-alpha.7 → 0.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +27 -6
  2. package/package.json +6 -1
  3. package/src/cli.mjs +119 -107
  4. package/src/doctor.mjs +9 -0
  5. package/src/package-manager.mjs +105 -0
  6. package/src/portability.mjs +445 -0
  7. package/src/presets.mjs +23 -7
  8. package/src/reference.mjs +45 -0
  9. package/src/scaffold.mjs +122 -32
  10. package/src/shared-api.mjs +57 -0
  11. package/src/ui.mjs +276 -0
  12. package/templates/directory/mobile/src/App.vue +4 -0
  13. package/templates/directory/mobile/src/app.ts +32 -0
  14. package/templates/directory/nuxt/app/app.vue +1 -0
  15. package/templates/directory/nuxt/app/pages/entries/[id]/edit.vue +5 -0
  16. package/templates/directory/nuxt/app/pages/entries/[id]/index.vue +5 -0
  17. package/templates/directory/nuxt/app/pages/index.vue +4 -0
  18. package/templates/directory/nuxt/app/plugins/mavis.ts +34 -0
  19. package/templates/directory/shared/Details.vue +26 -0
  20. package/templates/directory/shared/Directory.vue +51 -0
  21. package/templates/directory/shared/Edit.vue +99 -0
  22. package/templates/directory/shared/directory-store.ts +82 -0
  23. package/templates/directory/shared/routes.ts +9 -0
  24. package/templates/directory/vite/src/App.vue +4 -0
  25. package/templates/directory/vite/src/main.ts +34 -0
  26. package/templates/mobile/src/App.vue +1 -3
  27. package/templates/mobile/src/mavis.ts +57 -0
  28. package/templates/mobile/tsconfig.json +9 -2
  29. package/templates/mobile/webpack.config.js +2 -0
  30. package/templates/nuxt/app/mavis.ts +57 -0
  31. package/templates/nuxt/nuxt.config.ts +5 -0
  32. package/templates/shared/Welcome.vue +13 -1
  33. package/templates/vite/src/mavis.ts +57 -0
  34. package/templates/vite/tsconfig.json +5 -1
  35. 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 { spawn } from 'node:child_process'
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: shared ? '../../../shared' : './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: shared ? '../../../shared' : './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
- SHARED: shared ? '../../../shared' : './shared',
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,14 @@ 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,
110
139
  typescript: v.typescript,
140
+ 'vue-tsc': v.vueTsc,
111
141
  },
112
142
  }),
113
143
  )
@@ -118,20 +148,41 @@ export async function projectFiles(options) {
118
148
  json({
119
149
  ...common,
120
150
  name: preset.name,
121
- workspaces: ['apps/web'],
151
+ ...yarnBuilds(false),
152
+ ...(preset.packageManager !== 'pnpm' ? { workspaces: ['apps/web'] } : {}),
122
153
  scripts: {
123
- 'dev:web': 'npm --prefix apps/web run dev',
124
- 'build:web': `npm --prefix apps/web run ${preset.rendering === 'ssg' ? 'generate' : 'build'}`,
125
- android: 'npm --prefix apps/mobile run android',
126
- ios: 'npm --prefix apps/mobile run ios',
127
- 'install:apps': 'npm install && npm --prefix apps/mobile install',
154
+ 'dev:web': commands.run('dev', 'apps/web'),
155
+ 'build:web': commands.run(preset.rendering === 'ssg' ? 'generate' : 'build', 'apps/web'),
156
+ android: commands.run('android', 'apps/mobile'),
157
+ ios: commands.run('ios', 'apps/mobile'),
158
+ 'install:apps': `${commands.install} && ${commands.installAt('apps/mobile')}`,
128
159
  },
129
160
  }),
130
161
  )
131
- files.set('mavis.config.json', json(preset))
162
+ if (preset.packageManager === 'pnpm') {
163
+ const config = (native, workspace = false) =>
164
+ `${workspace ? 'packages:\n - apps/web\n' : 'packages: []\n'}nodeLinker: hoisted\n${native ? 'sideEffectsCache: false\n' : ''}allowBuilds:\n${Object.entries(
165
+ buildPolicy(native),
166
+ )
167
+ .map(([name, allowed]) => ` ${JSON.stringify(name)}: ${allowed}\n`)
168
+ .join('')}`
169
+ files.set('pnpm-workspace.yaml', config(preset.target === 'mobile', shared))
170
+ if (shared) files.set('apps/mobile/pnpm-workspace.yaml', config(true))
171
+ }
172
+ if (preset.packageManager === 'yarn') {
173
+ files.set('.yarnrc.yml', 'nodeLinker: node-modules\n')
174
+ // An empty lockfile marks a separate Yarn project, including before its first install.
175
+ files.set('yarn.lock', '')
176
+ if (shared) files.set('apps/mobile/yarn.lock', '')
177
+ }
178
+ const sharedDir = shared ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
179
+ files.set(
180
+ 'mavis.config.json',
181
+ json({ ...preset, portability: { roots: [sharedDir], alias: '#mavis', allowImports: [] } }),
182
+ )
132
183
  files.set(
133
184
  '.gitignore',
134
- 'node_modules/\n.npm/\ndist/\n.nuxt/\n.output/\nplatforms/\nhooks/\n.DS_Store\n*.log\n',
185
+ 'node_modules/\n.npm/\n.pnpm-store/\n.yarn/\ndist/\n.nuxt/\n.output/\nplatforms/\nhooks/\n.DS_Store\n*.log\n',
135
186
  )
136
187
  const location = shared
137
188
  ? '`shared/Welcome.vue`'
@@ -140,8 +191,53 @@ export async function projectFiles(options) {
140
191
  : '`src/shared/Welcome.vue`'
141
192
  files.set(
142
193
  'README.md',
143
- `# ${preset.name}\n\nA Mavis ${preset.target === 'both' ? 'NativeScript + Web' : preset.target} application using Vue templates.\n\n## Start\n\n\`\`\`sh\n${shared ? 'npm run install:apps' : 'npm install'}\n${preset.target === 'mobile' ? 'npm run ios # or npm run android' : shared ? 'npm run dev:web' : 'npm run dev'}\n\`\`\`\n\nEdit ${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.\n\n${preset.target !== 'web' ? '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.\n\n' : ''}${preset.web === 'nuxt' ? 'Nuxt server rendering: `npm run build`. Static output: `npm run generate`. In a shared project, run these inside `apps/web`. The initial appearance is deterministic during hydration; device appearance is applied after mount.\n\n' : ''}${shared ? 'The native and DOM renderers have separate dependency trees so each uses its own Vue runtime. No compiler converts arbitrary Vue/React code.\n\n' : ''}Dependencies are pinned in package.json. Commit the lockfile generated by npm install. Mavis and Jolt are prereleases; see https://mavis-ui.getcortexlabs.com/ for current contracts.\n`,
194
+ [
195
+ `# ${preset.name}`,
196
+ `A Mavis ${shared ? 'NativeScript + Web' : preset.target} application using Vue templates.`,
197
+ '## Start',
198
+ [
199
+ '```sh',
200
+ commands.setup(shared),
201
+ preset.target === 'mobile'
202
+ ? commands.run('ios')
203
+ : shared
204
+ ? commands.run('dev:web')
205
+ : commands.run('dev'),
206
+ ...(preset.target !== 'web'
207
+ ? [commands.run('android'), ...(shared ? [commands.run('ios')] : [])]
208
+ : []),
209
+ '```',
210
+ ].join('\n'),
211
+ `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.`,
212
+ ...(preset.target !== 'web'
213
+ ? [
214
+ '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.',
215
+ ]
216
+ : []),
217
+ ...(preset.web === 'nuxt'
218
+ ? [
219
+ `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.`,
220
+ ]
221
+ : []),
222
+ ...(shared
223
+ ? [
224
+ `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')}\`.`,
225
+ ]
226
+ : []),
227
+ ...(preset.packageManager === 'pnpm'
228
+ ? [
229
+ '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.',
230
+ ]
231
+ : []),
232
+ ...(preset.packageManager === 'yarn'
233
+ ? [
234
+ '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.',
235
+ ]
236
+ : []),
237
+ `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.`,
238
+ ].join('\n\n') + '\n',
144
239
  )
240
+ if (directory) files.set('README.md', directoryReadme(preset, sharedDir))
145
241
  return { preset, files: new Map([...files].sort(([a], [b]) => a.localeCompare(b))) }
146
242
  }
147
243
 
@@ -187,24 +283,18 @@ export async function scaffold(options, cwd = process.cwd()) {
187
283
  return { ...plan, destination }
188
284
  }
189
285
 
190
- export async function installProject(plan) {
286
+ export async function installProject(plan, { signal, onProgress } = {}) {
191
287
  const directories = plan.preset.target === 'both' ? ['', 'apps/mobile'] : ['']
192
- for (const directory of directories)
193
- await new Promise((resolve, reject) => {
194
- const child = spawn(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['install'], {
195
- cwd: join(plan.destination, directory),
196
- stdio: 'inherit',
197
- shell: false,
198
- })
199
- child.on('error', reject)
200
- child.on('exit', (code, signal) =>
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
- ),
288
+ for (const directory of directories) {
289
+ const cwd = join(plan.destination, directory)
290
+ onProgress?.(directory || '.')
291
+ try {
292
+ await runInstall(plan.preset.packageManager ?? 'npm', cwd, signal)
293
+ } catch (error) {
294
+ if (signal?.aborted) throw error
295
+ throw new Error(
296
+ `${error.message}\nProject files were preserved. Retry with ${packageCommands(plan.preset.packageManager).install} in ${cwd}.`,
208
297
  )
209
- })
298
+ }
299
+ }
210
300
  }
@@ -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,4 @@
1
+ <script setup lang="ts">
2
+ import { RouterView } from 'vue-router-ns'
3
+ </script>
4
+ <template><RouterView initial="/" /></template>
@@ -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>
@@ -0,0 +1,5 @@
1
+ <script setup lang="ts">
2
+ import Edit from '__MAVIS_SHARED__/Edit.vue'
3
+ const route = useRoute()
4
+ </script>
5
+ <template><Edit :id="String(route.params.id)" /></template>
@@ -0,0 +1,5 @@
1
+ <script setup lang="ts">
2
+ import Details from '__MAVIS_SHARED__/Details.vue'
3
+ const route = useRoute()
4
+ </script>
5
+ <template><Details :id="String(route.params.id)" /></template>
@@ -0,0 +1,4 @@
1
+ <script setup lang="ts">
2
+ import Directory from '__MAVIS_SHARED__/Directory.vue'
3
+ </script>
4
+ <template><Directory /></template>