@getcortexlabs/create-mavis 0.1.0-rc.12.2 → 0.1.0-rc.13
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 +6 -6
- package/package.json +1 -1
- package/src/adapters.mjs +76 -0
- package/src/add-target.mjs +1 -1
- package/src/capabilities.mjs +626 -0
- package/src/cli.mjs +43 -12
- package/src/doctor.mjs +77 -36
- package/src/macos.mjs +223 -56
- package/src/package-manager.mjs +12 -4
- package/src/portability.mjs +2 -1
- package/src/presets.mjs +15 -108
- package/src/scaffold.mjs +11 -3
- package/src/ui.mjs +115 -82
- 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 +9 -0
- package/templates/macos/mobile/src/App.vue +12 -0
- package/templates/macos/mobile/src/app.ts +7 -0
- package/templates/macos/native/Package.swift +9 -1
- package/templates/macos/native/Sources/MavisDesktop/App.swift +4 -4
- package/templates/macos/root/tsconfig.json +14 -0
- package/templates/macos/scripts/generate.mjs +35 -16
- package/templates/macos/scripts/macos.mjs +8 -3
- package/templates/macos/scripts/portable/emit-swift.mjs +1287 -0
- package/templates/macos/scripts/portable/emit-vue.mjs +615 -0
- package/templates/macos/scripts/portable/index.mjs +95 -0
- package/templates/macos/scripts/portable/model.mjs +1441 -0
- package/templates/macos/scripts/portable/program.mjs +163 -0
- package/templates/macos/shared/Welcome.lite.tsx +8 -6
- package/templates/macos/{index.html → web/index.html} +1 -1
- package/templates/macos/web/src/main.js +39 -0
- package/templates/macos/web/{style.css → src/style.css} +1 -1
- package/templates/macos/web/vite.config.mjs +3 -0
- 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,4 +1,5 @@
|
|
|
1
1
|
import { lstat, readFile, readdir, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { normalizeConfig } from './presets.mjs'
|
|
2
3
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
3
4
|
import ts from 'typescript'
|
|
4
5
|
import { parse } from '@vue/compiler-sfc'
|
|
@@ -293,7 +294,7 @@ export function inspectSource(source, filename, { allowImports = [] } = {}) {
|
|
|
293
294
|
|
|
294
295
|
async function projectConfig(root) {
|
|
295
296
|
try {
|
|
296
|
-
return JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8'))
|
|
297
|
+
return normalizeConfig(JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8')))
|
|
297
298
|
} catch (error) {
|
|
298
299
|
if (error.code === 'ENOENT') return {}
|
|
299
300
|
throw new Error(`Cannot read mavis.config.json: ${error.message}`)
|
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))
|
|
@@ -193,7 +193,10 @@ export async function projectFiles(options) {
|
|
|
193
193
|
const sharedDir = shared ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
|
|
194
194
|
files.set(
|
|
195
195
|
'mavis.config.json',
|
|
196
|
-
json({
|
|
196
|
+
json({
|
|
197
|
+
...configOf(preset),
|
|
198
|
+
portability: { roots: [sharedDir], alias: '#mavis', allowImports: [] },
|
|
199
|
+
}),
|
|
197
200
|
)
|
|
198
201
|
files.set(
|
|
199
202
|
'.gitignore',
|
|
@@ -299,7 +302,12 @@ export async function scaffold(options, cwd = process.cwd()) {
|
|
|
299
302
|
}
|
|
300
303
|
|
|
301
304
|
export async function installProject(plan, { signal, onProgress } = {}) {
|
|
302
|
-
|
|
305
|
+
// The NativeScript app has its own dependency tree next to the root project.
|
|
306
|
+
const directories =
|
|
307
|
+
plan.preset.target === 'both' ||
|
|
308
|
+
(plan.preset.target === 'macos' && plan.preset.targets.includes('native'))
|
|
309
|
+
? ['', 'apps/mobile']
|
|
310
|
+
: ['']
|
|
303
311
|
for (const directory of directories) {
|
|
304
312
|
const cwd = join(plan.destination, directory)
|
|
305
313
|
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,36 @@ 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') && 'Vue + Vite',
|
|
37
|
+
preset.targets.includes('native') && 'NativeScript iOS + Android',
|
|
38
|
+
preset.targets.includes('macos') && 'SwiftUI macOS',
|
|
39
|
+
]
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.join(' · ')}`,
|
|
42
|
+
'Authoring Shared TSX (shared/*.lite.tsx), compiled for each target',
|
|
43
|
+
...status(preset),
|
|
44
|
+
preset.example === 'tasks'
|
|
45
|
+
? 'Example Tasks · list and detail, forms, shortcuts and motion · shared/Tasks.lite.tsx'
|
|
46
|
+
: 'Example Basic welcome · shared/Welcome.lite.tsx',
|
|
47
|
+
`Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
|
|
31
48
|
`Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
|
|
32
49
|
].join('\n')
|
|
33
50
|
const web = preset.web === 'nuxt' ? `Nuxt · ${preset.rendering.toUpperCase()}` : 'Vue + Vite'
|
|
34
51
|
return [
|
|
35
52
|
`Project ${preset.name}`,
|
|
36
53
|
`Platform ${preset.target === 'mobile' ? 'iOS + Android' : preset.target === 'both' ? `${web} + iOS + Android` : web}`,
|
|
37
|
-
`Example ${preset.example
|
|
54
|
+
`Example ${catalog.examples[preset.example].label}`,
|
|
55
|
+
...status(preset),
|
|
38
56
|
`Theme ${preset.theme === 'midnight' ? 'Midnight · dark' : 'Mavis · light'}`,
|
|
39
57
|
`Packages ${preset.packageManager} · ${install ? 'install now' : 'install later'}`,
|
|
40
58
|
].join('\n')
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
export function sharedEntry(preset) {
|
|
44
|
-
if (preset.target === 'macos')
|
|
62
|
+
if (preset.target === 'macos')
|
|
63
|
+
return `shared/${preset.example === 'tasks' ? 'Tasks' : 'Welcome'}.lite.tsx`
|
|
45
64
|
const directory =
|
|
46
65
|
preset.target === 'both' ? 'shared' : preset.web === 'nuxt' ? 'app/shared' : 'src/shared'
|
|
47
66
|
return `${directory}/${preset.example === 'directory' ? 'Directory' : 'Welcome'}.vue`
|
|
@@ -49,14 +68,18 @@ export function sharedEntry(preset) {
|
|
|
49
68
|
|
|
50
69
|
export function nextSteps(preset, installed = false) {
|
|
51
70
|
const commands = packageCommands(preset.packageManager)
|
|
52
|
-
if (preset.target === 'macos')
|
|
71
|
+
if (preset.target === 'macos') {
|
|
72
|
+
const has = (target) => preset.targets.includes(target)
|
|
53
73
|
return [
|
|
54
74
|
`cd ${preset.name}`,
|
|
55
|
-
...(!installed ? [commands.install] : []),
|
|
56
|
-
commands.run('
|
|
57
|
-
|
|
58
|
-
'
|
|
75
|
+
...(!installed ? [has('native') ? commands.setup(true) : commands.install] : []),
|
|
76
|
+
...(has('web') ? [commands.run('dev:web')] : []),
|
|
77
|
+
...(has('native') ? [commands.run('ios'), commands.run('android')] : []),
|
|
78
|
+
...(has('macos')
|
|
79
|
+
? [commands.run('macos'), 'macOS 14+ and Xcode required for the Mac app.']
|
|
80
|
+
: []),
|
|
59
81
|
].join('\n')
|
|
82
|
+
}
|
|
60
83
|
return [
|
|
61
84
|
`cd ${preset.name}`,
|
|
62
85
|
...(!installed ? [commands.setup(preset.target === 'both')] : []),
|
|
@@ -127,82 +150,59 @@ export async function prepareInstallation(
|
|
|
127
150
|
export async function wizard(initial, signal, io = prompts, check = checkPackageManager) {
|
|
128
151
|
let answers = { ...initial }
|
|
129
152
|
const supplied = new Set(Object.keys(initial).filter((key) => initial[key] !== undefined))
|
|
153
|
+
// --target and --targets both answer the targets question.
|
|
154
|
+
if (initial.target !== undefined) supplied.add('targets')
|
|
155
|
+
const targets = () => (answers.targets || answers.target ? chosenTargets(answers) : [])
|
|
130
156
|
const back = Symbol('back')
|
|
131
157
|
const steps = [
|
|
132
158
|
{ key: 'name', message: 'What is your project called?', fallback: 'my-mavis-app' },
|
|
133
159
|
{
|
|
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
|
-
],
|
|
160
|
+
key: 'targets',
|
|
161
|
+
message: 'Where will it run? Space selects, Enter continues',
|
|
162
|
+
multiple: true,
|
|
163
|
+
fallback: ['web'],
|
|
164
|
+
options: choices(catalog.targets),
|
|
156
165
|
},
|
|
157
166
|
{
|
|
158
167
|
key: 'web',
|
|
159
168
|
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
|
-
],
|
|
169
|
+
when: () => targets().includes('web') && !targets().includes('macos'),
|
|
170
|
+
// A --rendering flag leaves only the hosts that can serve it.
|
|
171
|
+
options: choices(
|
|
172
|
+
catalog.hosts,
|
|
173
|
+
Object.keys(catalog.hosts).filter((host) => catalog.hosts[host].status !== 'planned'),
|
|
174
|
+
).map((option) => ({
|
|
175
|
+
...option,
|
|
176
|
+
disabled:
|
|
177
|
+
initial.rendering !== undefined &&
|
|
178
|
+
!catalog.hosts[option.value].rendering.includes(initial.rendering),
|
|
179
|
+
})),
|
|
175
180
|
},
|
|
176
181
|
{
|
|
177
182
|
key: 'rendering',
|
|
178
183
|
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
|
-
],
|
|
184
|
+
when: () => targets().includes('web') && answers.web === 'nuxt',
|
|
185
|
+
options: choices(catalog.rendering, catalog.hosts.nuxt.rendering),
|
|
184
186
|
},
|
|
185
187
|
{
|
|
186
188
|
key: 'example',
|
|
187
|
-
when: () => answers.target !== 'macos',
|
|
188
189
|
message: 'Choose a starting example',
|
|
189
190
|
fallback: 'welcome',
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
// The examples written the way these targets are: Vue templates, or shared TSX with Mac.
|
|
192
|
+
options: () =>
|
|
193
|
+
choices(
|
|
194
|
+
catalog.examples,
|
|
195
|
+
Object.keys(catalog.examples).filter((example) =>
|
|
196
|
+
catalog.examples[example].authoring.includes(
|
|
197
|
+
targets().includes('macos') ? 'mitosis' : 'vue',
|
|
198
|
+
),
|
|
199
|
+
),
|
|
200
|
+
),
|
|
198
201
|
},
|
|
199
202
|
{
|
|
200
203
|
key: 'theme',
|
|
201
204
|
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
|
-
],
|
|
205
|
+
options: choices(catalog.themes),
|
|
206
206
|
},
|
|
207
207
|
{
|
|
208
208
|
key: 'packageManager',
|
|
@@ -210,7 +210,11 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
210
210
|
fallback: detectPackageManager(),
|
|
211
211
|
options: [
|
|
212
212
|
{ value: 'npm', label: 'npm', hint: 'Included with Node.js' },
|
|
213
|
-
{
|
|
213
|
+
{
|
|
214
|
+
value: 'pnpm',
|
|
215
|
+
label: 'pnpm',
|
|
216
|
+
hint: `Fast installs, efficient disk usage · ${requirements.packageManagers.pnpm}+`,
|
|
217
|
+
},
|
|
214
218
|
{ value: 'yarn', label: 'Yarn', hint: 'Classic or modern, with node_modules' },
|
|
215
219
|
],
|
|
216
220
|
},
|
|
@@ -262,30 +266,59 @@ export async function wizard(initial, signal, io = prompts, check = checkPackage
|
|
|
262
266
|
continue
|
|
263
267
|
}
|
|
264
268
|
const message = typeof step.message === 'function' ? step.message() : step.message
|
|
265
|
-
const
|
|
266
|
-
|
|
269
|
+
const options = typeof step.options === 'function' ? step.options() : step.options
|
|
270
|
+
const value = step.multiple
|
|
271
|
+
? await io.multiselect({
|
|
267
272
|
message,
|
|
268
273
|
signal,
|
|
269
|
-
|
|
274
|
+
required: true,
|
|
275
|
+
initialValues: answers[step.key] ?? step.fallback,
|
|
270
276
|
options: [
|
|
271
|
-
...
|
|
277
|
+
...options,
|
|
272
278
|
...(previous(index) >= 0 ? [{ value: back, label: '← Back' }] : []),
|
|
273
279
|
],
|
|
274
280
|
})
|
|
275
|
-
:
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
281
|
+
: options
|
|
282
|
+
? await io.select({
|
|
283
|
+
message,
|
|
284
|
+
signal,
|
|
285
|
+
// An earlier answer may not exist for the targets chosen since.
|
|
286
|
+
initialValue: options.some((option) => option.value === answers[step.key])
|
|
287
|
+
? answers[step.key]
|
|
288
|
+
: step.fallback,
|
|
289
|
+
options: [
|
|
290
|
+
...options,
|
|
291
|
+
...(previous(index) >= 0 ? [{ value: back, label: '← Back' }] : []),
|
|
292
|
+
],
|
|
293
|
+
})
|
|
294
|
+
: await io.text({
|
|
295
|
+
message,
|
|
296
|
+
signal,
|
|
297
|
+
placeholder: step.fallback,
|
|
298
|
+
defaultValue: step.fallback,
|
|
299
|
+
initialValue: answers[step.key],
|
|
300
|
+
validate: (value) =>
|
|
301
|
+
value === 'cancel' ? undefined : validateDestination(value || step.fallback),
|
|
302
|
+
})
|
|
284
303
|
if (io.isCancel(value) || value === 'cancel') return null
|
|
285
|
-
if (value === back) {
|
|
304
|
+
if (value === back || (Array.isArray(value) && value.includes(back))) {
|
|
286
305
|
index = previous(index)
|
|
287
306
|
continue
|
|
288
307
|
}
|
|
308
|
+
if (step.key === 'targets') {
|
|
309
|
+
// Explain choices that don't fit together before going further, then ask again.
|
|
310
|
+
try {
|
|
311
|
+
// Only flags constrain the targets; later answers are asked again for these targets.
|
|
312
|
+
resolvePreset({ ...initial, name: answers.name ?? 'my-mavis-app', targets: value })
|
|
313
|
+
} catch (error) {
|
|
314
|
+
io.log.warn(error.message)
|
|
315
|
+
continue
|
|
316
|
+
}
|
|
317
|
+
if (value.includes('macos'))
|
|
318
|
+
io.log.message(
|
|
319
|
+
`Shared screens will be TSX (shared/*.lite.tsx), compiled for ${value.join(', ')}.${value.includes('web') ? ' The Web app uses Vue + Vite: Nuxt needs server rendering in the compiler, which is not there yet.' : ''}`,
|
|
320
|
+
)
|
|
321
|
+
}
|
|
289
322
|
answers[step.key] = value
|
|
290
323
|
index++
|
|
291
324
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Task } from './types'
|
|
2
|
+
|
|
3
|
+
// The selected task. Every edit goes straight to the list, so the row updates while you type.
|
|
4
|
+
export default function TaskDetail(props: {
|
|
5
|
+
task: Task
|
|
6
|
+
priorities: SelectOption[]
|
|
7
|
+
canMoveUp: boolean
|
|
8
|
+
canMoveDown: boolean
|
|
9
|
+
onToggle: () => void
|
|
10
|
+
onRename: (title: string) => void
|
|
11
|
+
onNotes: (notes: string) => void
|
|
12
|
+
onPriority: (priority: string) => void
|
|
13
|
+
onMove: (by: number) => void
|
|
14
|
+
}) {
|
|
15
|
+
return (
|
|
16
|
+
<MCard gap="md">
|
|
17
|
+
<MText variant="overline" tone="muted">
|
|
18
|
+
SELECTED TASK
|
|
19
|
+
</MText>
|
|
20
|
+
<MCheckbox label="Done" checked={props.task.done} onChange={() => props.onToggle()} />
|
|
21
|
+
<MInput
|
|
22
|
+
label="Task title"
|
|
23
|
+
value={props.task.title}
|
|
24
|
+
onChange={(value) => props.onRename(value)}
|
|
25
|
+
maxLength={60}
|
|
26
|
+
/>
|
|
27
|
+
<MInput
|
|
28
|
+
label="Task notes"
|
|
29
|
+
multiline
|
|
30
|
+
rows={3}
|
|
31
|
+
value={props.task.notes}
|
|
32
|
+
onChange={(value) => props.onNotes(value)}
|
|
33
|
+
placeholder="Anything worth remembering"
|
|
34
|
+
/>
|
|
35
|
+
<MSelect
|
|
36
|
+
label="Task priority"
|
|
37
|
+
value={props.task.priority}
|
|
38
|
+
options={props.priorities}
|
|
39
|
+
onChange={(value) => props.onPriority(value)}
|
|
40
|
+
/>
|
|
41
|
+
<MRow gap="sm">
|
|
42
|
+
<MButton
|
|
43
|
+
text="Move up"
|
|
44
|
+
variant="secondary"
|
|
45
|
+
disabled={!props.canMoveUp}
|
|
46
|
+
onClick={() => props.onMove(-1)}
|
|
47
|
+
/>
|
|
48
|
+
<MButton
|
|
49
|
+
text="Move down"
|
|
50
|
+
variant="secondary"
|
|
51
|
+
disabled={!props.canMoveDown}
|
|
52
|
+
onClick={() => props.onMove(1)}
|
|
53
|
+
/>
|
|
54
|
+
</MRow>
|
|
55
|
+
</MCard>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Show } from '@builder.io/mitosis'
|
|
2
|
+
import type { Task } from './types'
|
|
3
|
+
|
|
4
|
+
// One task in the list. The whole card is a button; its label is what assistive technology reads.
|
|
5
|
+
export default function TaskRow(props: {
|
|
6
|
+
task: Task
|
|
7
|
+
selected: boolean
|
|
8
|
+
onSelect: (id: string) => void
|
|
9
|
+
}) {
|
|
10
|
+
return (
|
|
11
|
+
<MCard
|
|
12
|
+
gap="xs"
|
|
13
|
+
padding="md"
|
|
14
|
+
tone={props.selected ? 'primarySoft' : 'surface'}
|
|
15
|
+
label={`${props.task.title}, ${props.task.done ? 'done' : 'open'}, ${props.task.priority} priority${props.selected ? ', selected' : ''}`}
|
|
16
|
+
onClick={() => props.onSelect(props.task.id)}
|
|
17
|
+
>
|
|
18
|
+
<MText tone={props.task.done ? 'muted' : 'text'}>{props.task.title}</MText>
|
|
19
|
+
<MText variant="caption" tone="muted">
|
|
20
|
+
{props.task.priority === 'high'
|
|
21
|
+
? 'High priority'
|
|
22
|
+
: props.task.priority === 'low'
|
|
23
|
+
? 'Low priority'
|
|
24
|
+
: 'Normal priority'}
|
|
25
|
+
</MText>
|
|
26
|
+
<Show when={props.task.done} animate>
|
|
27
|
+
<MText variant="caption" tone="success">
|
|
28
|
+
Done
|
|
29
|
+
</MText>
|
|
30
|
+
</Show>
|
|
31
|
+
</MCard>
|
|
32
|
+
)
|
|
33
|
+
}
|