@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.
- package/README.md +27 -6
- package/package.json +6 -1
- package/src/cli.mjs +119 -107
- package/src/doctor.mjs +9 -0
- package/src/package-manager.mjs +105 -0
- package/src/portability.mjs +445 -0
- package/src/presets.mjs +23 -7
- package/src/reference.mjs +45 -0
- package/src/scaffold.mjs +122 -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 +57 -0
- package/templates/mobile/tsconfig.json +9 -2
- package/templates/mobile/webpack.config.js +2 -0
- package/templates/nuxt/app/mavis.ts +57 -0
- package/templates/nuxt/nuxt.config.ts +5 -0
- package/templates/shared/Welcome.vue +13 -1
- package/templates/vite/src/mavis.ts +57 -0
- package/templates/vite/tsconfig.json +5 -1
- package/templates/vite/vite.config.ts +8 -1
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { lstat, readFile, readdir, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
3
|
+
import ts from 'typescript'
|
|
4
|
+
import { parse } from '@vue/compiler-sfc'
|
|
5
|
+
import { components, composables } from './shared-api.mjs'
|
|
6
|
+
|
|
7
|
+
const rendererImports = new Set(['@getcortexlabs/mavis-web', '@getcortexlabs/mavis/vue'])
|
|
8
|
+
const sharedNames = new Set([...components, ...composables])
|
|
9
|
+
const browserGlobals = new Set([
|
|
10
|
+
'window',
|
|
11
|
+
'document',
|
|
12
|
+
'localStorage',
|
|
13
|
+
'sessionStorage',
|
|
14
|
+
'navigator',
|
|
15
|
+
'HTMLElement',
|
|
16
|
+
'Element',
|
|
17
|
+
'Node',
|
|
18
|
+
'ResizeObserver',
|
|
19
|
+
'MutationObserver',
|
|
20
|
+
'IntersectionObserver',
|
|
21
|
+
'getComputedStyle',
|
|
22
|
+
'matchMedia',
|
|
23
|
+
'requestAnimationFrame',
|
|
24
|
+
'cancelAnimationFrame',
|
|
25
|
+
])
|
|
26
|
+
const ignored = new Set([
|
|
27
|
+
'node_modules',
|
|
28
|
+
'.git',
|
|
29
|
+
'.nuxt',
|
|
30
|
+
'.output',
|
|
31
|
+
'dist',
|
|
32
|
+
'platforms',
|
|
33
|
+
'artifacts',
|
|
34
|
+
])
|
|
35
|
+
const sourceExtensions = ['.vue', '.ts', '.tsx', '.js', '.jsx', '.mjs']
|
|
36
|
+
const platformImports =
|
|
37
|
+
/^(?:@getcortexlabs\/mavis(?:-web)?(?:\/|$)|@nativescript\/|nativescript-vue$|vue-router(?:-ns)?$|nuxt(?:\/|$)|#app$|node:|@rafaelaugusto\/jolt(?:\/|$))/
|
|
38
|
+
const portableImports = new Set([
|
|
39
|
+
'vue',
|
|
40
|
+
'@getcortexlabs/mavis-core',
|
|
41
|
+
'@getcortexlabs/mavis-core/vue',
|
|
42
|
+
'@getcortexlabs/mavis-core/experimental',
|
|
43
|
+
'#mavis',
|
|
44
|
+
])
|
|
45
|
+
const internal = (root, file) => {
|
|
46
|
+
const path = relative(root, file)
|
|
47
|
+
return path !== '..' && !path.startsWith(`..${sep}`) && !isAbsolute(path)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A conservative source audit, not a proof that arbitrary dependencies are portable. */
|
|
51
|
+
export function inspectSource(source, filename, { allowImports = [] } = {}) {
|
|
52
|
+
const diagnostics = [],
|
|
53
|
+
edits = [],
|
|
54
|
+
imports = []
|
|
55
|
+
const report = (code, offset, message, fixable = false) => {
|
|
56
|
+
const before = source.slice(0, offset).split('\n')
|
|
57
|
+
diagnostics.push({
|
|
58
|
+
file: filename,
|
|
59
|
+
line: before.length,
|
|
60
|
+
column: before.at(-1).length + 1,
|
|
61
|
+
code,
|
|
62
|
+
message,
|
|
63
|
+
fixable,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
let script = source
|
|
67
|
+
let template
|
|
68
|
+
const templateExpressions = []
|
|
69
|
+
if (filename.endsWith('.vue')) {
|
|
70
|
+
const { descriptor, errors } = parse(source, { filename })
|
|
71
|
+
for (const error of errors)
|
|
72
|
+
report('parse', error.loc?.start?.offset ?? 0, String(error.message ?? error))
|
|
73
|
+
if (descriptor.template?.lang && descriptor.template.lang !== 'html')
|
|
74
|
+
report(
|
|
75
|
+
'template-language',
|
|
76
|
+
descriptor.template.loc.start.offset,
|
|
77
|
+
'Only Vue HTML templates can be audited; review this template language separately.',
|
|
78
|
+
)
|
|
79
|
+
template = descriptor.template?.ast
|
|
80
|
+
script = source.replace(/[^\r\n]/g, ' ')
|
|
81
|
+
for (const block of [descriptor.script, descriptor.scriptSetup].filter(Boolean)) {
|
|
82
|
+
if (block.src)
|
|
83
|
+
report(
|
|
84
|
+
'script-src',
|
|
85
|
+
block.loc.start.offset,
|
|
86
|
+
'Audit the external script separately; inline script imports can be followed automatically.',
|
|
87
|
+
)
|
|
88
|
+
script =
|
|
89
|
+
script.slice(0, block.loc.start.offset) + block.content + script.slice(block.loc.end.offset)
|
|
90
|
+
}
|
|
91
|
+
for (const style of descriptor.styles)
|
|
92
|
+
report(
|
|
93
|
+
'css',
|
|
94
|
+
style.loc.start.offset,
|
|
95
|
+
'CSS needs renderer review. Prefer Mavis layout, typography and spacing props in shared screens.',
|
|
96
|
+
)
|
|
97
|
+
const visit = (node) => {
|
|
98
|
+
if (node.type === 5) templateExpressions.push(node.content)
|
|
99
|
+
if (node.type === 1)
|
|
100
|
+
for (const prop of node.props)
|
|
101
|
+
if (prop.type === 7 && prop.exp && !['for', 'slot'].includes(prop.name))
|
|
102
|
+
templateExpressions.push(prop.exp)
|
|
103
|
+
if (node.type === 1) {
|
|
104
|
+
if (
|
|
105
|
+
(node.tagType === 0 && !['template', 'slot'].includes(node.tag)) ||
|
|
106
|
+
/^(?:RouterLink|NuxtLink|ClientOnly|Teleport|Frame|Page|GridLayout|StackLayout|Label|TextField)$/i.test(
|
|
107
|
+
node.tag,
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
report(
|
|
111
|
+
'element',
|
|
112
|
+
node.loc.start.offset,
|
|
113
|
+
`<${node.tag}> is platform-specific. Use a shared Mavis component or move it into a host adapter.`,
|
|
114
|
+
)
|
|
115
|
+
for (const prop of node.props) {
|
|
116
|
+
if (
|
|
117
|
+
(prop.type === 6 && ['style', 'class'].includes(prop.name)) ||
|
|
118
|
+
(prop.type === 7 &&
|
|
119
|
+
prop.name === 'bind' &&
|
|
120
|
+
['style', 'class'].includes(prop.arg?.content))
|
|
121
|
+
)
|
|
122
|
+
report(
|
|
123
|
+
'styling',
|
|
124
|
+
prop.loc.start.offset,
|
|
125
|
+
'Review class/style across both renderers; prefer shared props and tokens.',
|
|
126
|
+
)
|
|
127
|
+
if (
|
|
128
|
+
prop.type === 7 &&
|
|
129
|
+
(prop.name === 'html' ||
|
|
130
|
+
prop.modifiers?.some((m) =>
|
|
131
|
+
['prevent', 'stop', 'capture', 'passive', 'self'].includes(m.content),
|
|
132
|
+
))
|
|
133
|
+
)
|
|
134
|
+
report(
|
|
135
|
+
'dom-directive',
|
|
136
|
+
prop.loc.start.offset,
|
|
137
|
+
'This directive relies on DOM event/content behavior. Use the component contract or a host adapter.',
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const child of node.children ?? []) visit(child)
|
|
142
|
+
}
|
|
143
|
+
if (descriptor.template?.ast) visit(descriptor.template.ast)
|
|
144
|
+
}
|
|
145
|
+
const file = ts.createSourceFile(
|
|
146
|
+
filename + '.ts',
|
|
147
|
+
script,
|
|
148
|
+
ts.ScriptTarget.Latest,
|
|
149
|
+
true,
|
|
150
|
+
ts.ScriptKind.TSX,
|
|
151
|
+
)
|
|
152
|
+
const host = {
|
|
153
|
+
getSourceFile: (name) => (name === file.fileName ? file : undefined),
|
|
154
|
+
writeFile() {},
|
|
155
|
+
getCurrentDirectory: () => '',
|
|
156
|
+
getDirectories: () => [],
|
|
157
|
+
fileExists: (name) => name === file.fileName,
|
|
158
|
+
readFile: () => undefined,
|
|
159
|
+
getCanonicalFileName: (name) => name,
|
|
160
|
+
useCaseSensitiveFileNames: () => true,
|
|
161
|
+
getNewLine: () => '\n',
|
|
162
|
+
getDefaultLibFileName: () => '',
|
|
163
|
+
}
|
|
164
|
+
const program = ts.createProgram([file.fileName], { noLib: true, noResolve: true }, host)
|
|
165
|
+
const checker = program.getTypeChecker()
|
|
166
|
+
for (const error of program.getSyntacticDiagnostics(file))
|
|
167
|
+
report('parse', error.start ?? 0, ts.flattenDiagnosticMessageText(error.messageText, ' '))
|
|
168
|
+
const dependency = (literal, declaration) => {
|
|
169
|
+
const name = literal.text
|
|
170
|
+
imports.push(name)
|
|
171
|
+
if (rendererImports.has(name)) {
|
|
172
|
+
const bindings = declaration?.importClause?.namedBindings
|
|
173
|
+
const safe =
|
|
174
|
+
!declaration?.importClause?.name &&
|
|
175
|
+
bindings &&
|
|
176
|
+
ts.isNamedImports(bindings) &&
|
|
177
|
+
bindings.elements.length > 0 &&
|
|
178
|
+
bindings.elements.every((item) => sharedNames.has((item.propertyName ?? item.name).text))
|
|
179
|
+
report(
|
|
180
|
+
'renderer-import',
|
|
181
|
+
literal.getStart(file),
|
|
182
|
+
'Import shared components/composables from #mavis; the host selects the renderer.',
|
|
183
|
+
Boolean(safe),
|
|
184
|
+
)
|
|
185
|
+
if (safe)
|
|
186
|
+
edits.push({ start: literal.getStart(file) + 1, end: literal.getEnd() - 1, text: '#mavis' })
|
|
187
|
+
} else if (platformImports.test(name)) {
|
|
188
|
+
report(
|
|
189
|
+
'platform-import',
|
|
190
|
+
literal.getStart(file),
|
|
191
|
+
`${name} belongs in a host adapter. Core contracts are available from @getcortexlabs/mavis-core.`,
|
|
192
|
+
)
|
|
193
|
+
} else if (
|
|
194
|
+
!portableImports.has(name) &&
|
|
195
|
+
!allowImports.includes(name) &&
|
|
196
|
+
!name.startsWith('.')
|
|
197
|
+
) {
|
|
198
|
+
report(
|
|
199
|
+
'review-import',
|
|
200
|
+
literal.getStart(file),
|
|
201
|
+
`Review ${name} for each target. Audited portable dependencies can be listed in portability.allowImports.`,
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const visit = (node) => {
|
|
206
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
207
|
+
if (node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier))
|
|
208
|
+
dependency(node.moduleSpecifier, ts.isImportDeclaration(node) ? node : undefined)
|
|
209
|
+
} else if (
|
|
210
|
+
ts.isCallExpression(node) &&
|
|
211
|
+
(node.expression.kind === ts.SyntaxKind.ImportKeyword ||
|
|
212
|
+
(ts.isIdentifier(node.expression) &&
|
|
213
|
+
node.expression.text === 'require' &&
|
|
214
|
+
!checker.getSymbolAtLocation(node.expression)))
|
|
215
|
+
) {
|
|
216
|
+
const value = node.arguments[0]
|
|
217
|
+
if (value && ts.isStringLiteral(value)) dependency(value)
|
|
218
|
+
else
|
|
219
|
+
report(
|
|
220
|
+
'dynamic-import',
|
|
221
|
+
node.getStart(file),
|
|
222
|
+
'A computed dependency cannot be audited statically; isolate or review it for every target.',
|
|
223
|
+
)
|
|
224
|
+
} else if (ts.isIdentifier(node) && browserGlobals.has(node.text)) {
|
|
225
|
+
const parent = node.parent
|
|
226
|
+
const property =
|
|
227
|
+
(ts.isPropertyAccessExpression(parent) && parent.name === node) ||
|
|
228
|
+
((ts.isPropertyAssignment(parent) || ts.isMethodDeclaration(parent)) &&
|
|
229
|
+
parent.name === node)
|
|
230
|
+
if (!property && !checker.getSymbolAtLocation(node))
|
|
231
|
+
report(
|
|
232
|
+
'browser-global',
|
|
233
|
+
node.getStart(file),
|
|
234
|
+
`${node.text} is browser-specific. Inject a host service or use a shared Mavis contract.`,
|
|
235
|
+
)
|
|
236
|
+
} else if (
|
|
237
|
+
ts.isPropertyAccessExpression(node) &&
|
|
238
|
+
ts.isIdentifier(node.expression) &&
|
|
239
|
+
['globalThis', 'self'].includes(node.expression.text) &&
|
|
240
|
+
!checker.getSymbolAtLocation(node.expression)?.declarations?.length &&
|
|
241
|
+
browserGlobals.has(node.name.text)
|
|
242
|
+
) {
|
|
243
|
+
report(
|
|
244
|
+
'browser-global',
|
|
245
|
+
node.getStart(file),
|
|
246
|
+
`${node.getText(file)} is browser-specific. Inject a host service.`,
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
ts.forEachChild(node, visit)
|
|
250
|
+
}
|
|
251
|
+
visit(file)
|
|
252
|
+
if (template) {
|
|
253
|
+
const bindings = checker
|
|
254
|
+
.getSymbolsInScope(file, ts.SymbolFlags.Value)
|
|
255
|
+
.filter((symbol) =>
|
|
256
|
+
symbol.declarations?.some((declaration) => declaration.getSourceFile() === file),
|
|
257
|
+
)
|
|
258
|
+
.map((symbol) => symbol.name)
|
|
259
|
+
.filter((name) => /^[$A-Z_a-z][$\w]*$/.test(name))
|
|
260
|
+
const prefix = bindings.map((name) => `declare const ${name}: any;`).join('') + '\n'
|
|
261
|
+
for (const expression of templateExpressions) {
|
|
262
|
+
const analysis = inspectSource(prefix + expression.content, 'template-expression.ts', {
|
|
263
|
+
allowImports,
|
|
264
|
+
})
|
|
265
|
+
for (const item of analysis.diagnostics.filter((item) => item.code === 'browser-global')) {
|
|
266
|
+
const lines = (prefix + expression.content).split('\n')
|
|
267
|
+
const offset =
|
|
268
|
+
lines.slice(0, item.line - 1).reduce((length, line) => length + line.length + 1, 0) +
|
|
269
|
+
item.column -
|
|
270
|
+
1 -
|
|
271
|
+
prefix.length
|
|
272
|
+
report(item.code, expression.loc.start.offset + Math.max(0, offset), item.message)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return { diagnostics, edits, imports }
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async function projectConfig(root) {
|
|
280
|
+
try {
|
|
281
|
+
return JSON.parse(await readFile(join(root, 'mavis.config.json'), 'utf8'))
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (error.code === 'ENOENT') return {}
|
|
284
|
+
throw new Error(`Cannot read mavis.config.json: ${error.message}`)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Never follows symlinks or traverses outside the selected project. */
|
|
289
|
+
export async function checkPortability(root = process.cwd(), options = {}) {
|
|
290
|
+
root = resolve(root)
|
|
291
|
+
const config = await projectConfig(root)
|
|
292
|
+
const roots = options.path
|
|
293
|
+
? [options.path]
|
|
294
|
+
: (config.portability?.roots ?? [
|
|
295
|
+
config.target === 'both' ? 'shared' : config.web === 'nuxt' ? 'app/shared' : 'src/shared',
|
|
296
|
+
])
|
|
297
|
+
if (
|
|
298
|
+
!Array.isArray(roots) ||
|
|
299
|
+
!roots.length ||
|
|
300
|
+
roots.some((value) => typeof value !== 'string' || !value)
|
|
301
|
+
)
|
|
302
|
+
throw new Error('Configure at least one source directory in portability.roots.')
|
|
303
|
+
const files = new Map(),
|
|
304
|
+
diagnostics = [],
|
|
305
|
+
fixes = []
|
|
306
|
+
const load = async (file, dependency = false) => {
|
|
307
|
+
if (!internal(root, file)) throw new Error('Portability paths must stay inside the project.')
|
|
308
|
+
let ancestor = root
|
|
309
|
+
for (const part of relative(root, file).split(sep).filter(Boolean)) {
|
|
310
|
+
ancestor = join(ancestor, part)
|
|
311
|
+
if ((await lstat(ancestor)).isSymbolicLink())
|
|
312
|
+
throw new Error(`Portability does not follow symlinks: ${relative(root, ancestor)}`)
|
|
313
|
+
}
|
|
314
|
+
const info = await lstat(file)
|
|
315
|
+
if (info.isSymbolicLink())
|
|
316
|
+
throw new Error(`Portability does not follow symlinks: ${relative(root, file)}`)
|
|
317
|
+
if (info.isDirectory()) {
|
|
318
|
+
if (dependency) return
|
|
319
|
+
for (const item of (await readdir(file)).sort())
|
|
320
|
+
if (!ignored.has(item)) await load(join(file, item))
|
|
321
|
+
} else if (sourceExtensions.includes(extname(file)) && !files.has(file)) {
|
|
322
|
+
const source = await readFile(file, 'utf8')
|
|
323
|
+
const result = inspectSource(source, relative(root, file), config.portability)
|
|
324
|
+
files.set(file, { source, ...result })
|
|
325
|
+
diagnostics.push(...result.diagnostics)
|
|
326
|
+
for (const name of result.imports.filter((name) => name.startsWith('.'))) {
|
|
327
|
+
const target = resolve(dirname(file), name)
|
|
328
|
+
const candidates = [
|
|
329
|
+
...(/\.[cm]?jsx?$/.test(target)
|
|
330
|
+
? [target.replace(/\.[cm]?jsx?$/, '.ts'), target.replace(/\.[cm]?jsx?$/, '.tsx')]
|
|
331
|
+
: []),
|
|
332
|
+
target,
|
|
333
|
+
...sourceExtensions.map((ext) => target + ext),
|
|
334
|
+
...sourceExtensions.map((ext) => join(target, 'index' + ext)),
|
|
335
|
+
]
|
|
336
|
+
let found = false
|
|
337
|
+
for (const candidate of candidates) {
|
|
338
|
+
if (!internal(root, candidate))
|
|
339
|
+
throw new Error(`Shared dependency leaves the project: ${name}`)
|
|
340
|
+
let stat
|
|
341
|
+
try {
|
|
342
|
+
stat = await lstat(candidate)
|
|
343
|
+
} catch (error) {
|
|
344
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') continue
|
|
345
|
+
throw error
|
|
346
|
+
}
|
|
347
|
+
if (stat.isDirectory()) continue
|
|
348
|
+
if (!sourceExtensions.includes(extname(candidate)))
|
|
349
|
+
diagnostics.push({
|
|
350
|
+
file: relative(root, file),
|
|
351
|
+
line: 1,
|
|
352
|
+
column: 1,
|
|
353
|
+
code: 'review-asset',
|
|
354
|
+
message: `Review ${name} across renderers; non-script dependencies are not audited.`,
|
|
355
|
+
fixable: false,
|
|
356
|
+
})
|
|
357
|
+
await load(candidate, true)
|
|
358
|
+
found = true
|
|
359
|
+
break
|
|
360
|
+
}
|
|
361
|
+
if (!found)
|
|
362
|
+
diagnostics.push({
|
|
363
|
+
file: relative(root, file),
|
|
364
|
+
line: 1,
|
|
365
|
+
column: 1,
|
|
366
|
+
code: 'unresolved-import',
|
|
367
|
+
message: `Could not audit ${name}; check its resolution or move it into a host adapter.`,
|
|
368
|
+
fixable: false,
|
|
369
|
+
})
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
for (const name of roots) {
|
|
374
|
+
const file = resolve(root, name)
|
|
375
|
+
// Check every ancestor so a symlinked parent cannot escape the project.
|
|
376
|
+
if (!internal(root, file)) throw new Error('Portability paths must stay inside the project.')
|
|
377
|
+
let current = root
|
|
378
|
+
for (const part of relative(root, file).split(sep).filter(Boolean)) {
|
|
379
|
+
current = join(current, part)
|
|
380
|
+
if ((await lstat(current)).isSymbolicLink())
|
|
381
|
+
throw new Error('Portability does not follow symlinks.')
|
|
382
|
+
}
|
|
383
|
+
await load(file)
|
|
384
|
+
}
|
|
385
|
+
if (!files.size)
|
|
386
|
+
throw new Error('No Vue or script sources found in the configured portability paths.')
|
|
387
|
+
if (options.fixImports) {
|
|
388
|
+
if (config.portability?.alias !== '#mavis')
|
|
389
|
+
throw new Error(
|
|
390
|
+
'Import migration requires a generated #mavis alias. Configure the host and TypeScript aliases before migrating.',
|
|
391
|
+
)
|
|
392
|
+
const hosts =
|
|
393
|
+
config.target === 'both'
|
|
394
|
+
? [
|
|
395
|
+
['apps/web', config.web],
|
|
396
|
+
['apps/mobile', 'mobile'],
|
|
397
|
+
]
|
|
398
|
+
: [['', config.target === 'mobile' ? 'mobile' : config.web]]
|
|
399
|
+
for (const [directory, host] of hosts) {
|
|
400
|
+
const facade = join(root, directory, host === 'nuxt' ? 'app/mavis.ts' : 'src/mavis.ts')
|
|
401
|
+
const build = join(
|
|
402
|
+
root,
|
|
403
|
+
directory,
|
|
404
|
+
host === 'mobile'
|
|
405
|
+
? 'webpack.config.js'
|
|
406
|
+
: host === 'nuxt'
|
|
407
|
+
? 'nuxt.config.ts'
|
|
408
|
+
: 'vite.config.ts',
|
|
409
|
+
)
|
|
410
|
+
if (
|
|
411
|
+
!(await readFile(facade, 'utf8')).includes('@getcortexlabs/mavis') ||
|
|
412
|
+
!(await readFile(build, 'utf8')).includes('#mavis')
|
|
413
|
+
)
|
|
414
|
+
throw new Error('The generated #mavis host configuration is missing. No files changed.')
|
|
415
|
+
}
|
|
416
|
+
// Prepare all edits before any write. A parse error makes the migration a no-op.
|
|
417
|
+
if (diagnostics.some((item) => item.code === 'parse'))
|
|
418
|
+
throw new Error('Fix syntax errors before migrating imports. No files changed.')
|
|
419
|
+
for (const [file, result] of files) {
|
|
420
|
+
if (!result.edits.length) continue
|
|
421
|
+
let updated = result.source
|
|
422
|
+
for (const edit of [...result.edits].sort((a, b) => b.start - a.start))
|
|
423
|
+
updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end)
|
|
424
|
+
fixes.push({ file: relative(root, file), before: result.source, after: updated })
|
|
425
|
+
}
|
|
426
|
+
if (options.write) {
|
|
427
|
+
for (const fix of fixes) {
|
|
428
|
+
const file = join(root, fix.file)
|
|
429
|
+
if ((await lstat(file)).isSymbolicLink() || (await readFile(file, 'utf8')) !== fix.before)
|
|
430
|
+
throw new Error(`Source changed during migration: ${fix.file}`)
|
|
431
|
+
}
|
|
432
|
+
for (const fix of fixes) await writeFile(join(root, fix.file), fix.after)
|
|
433
|
+
const after = await checkPortability(root, { path: options.path })
|
|
434
|
+
return { ...after, fixes, written: true }
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
files: [...files.keys()].map((file) => relative(root, file)),
|
|
439
|
+
diagnostics: diagnostics.sort(
|
|
440
|
+
(a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column,
|
|
441
|
+
),
|
|
442
|
+
fixes,
|
|
443
|
+
written: false,
|
|
444
|
+
}
|
|
445
|
+
}
|
package/src/presets.mjs
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { packageManagers } from './package-manager.mjs'
|
|
2
|
+
|
|
3
|
+
/** Baseline pins; coordinated releases update Mavis after validating source templates with matching tarballs. */
|
|
2
4
|
export const versions = Object.freeze({
|
|
3
|
-
mavis: '0.1.0-alpha.
|
|
4
|
-
jolt: '0.1.0-rc.
|
|
5
|
+
mavis: '0.1.0-alpha.9',
|
|
6
|
+
jolt: '0.1.0-rc.10',
|
|
5
7
|
vue: '3.5.44',
|
|
6
8
|
nuxt: '4.6.3',
|
|
7
9
|
vite: '6.4.5',
|
|
8
10
|
vuePlugin: '5.2.4',
|
|
9
11
|
typescript: '6.0.3',
|
|
12
|
+
nodeTypes: '26.6.6',
|
|
10
13
|
vueTsc: '3.3.13',
|
|
11
14
|
nativeCore: '9.1.3',
|
|
12
15
|
nativeVue: '3.1.3',
|
|
13
16
|
android: '9.1.1',
|
|
14
17
|
ios: '9.1.0',
|
|
15
18
|
webpack: '5.0.39',
|
|
19
|
+
router: '4.6.4',
|
|
20
|
+
nativeRouter: '0.1.0-rc.4',
|
|
16
21
|
})
|
|
17
22
|
|
|
23
|
+
export function validateProjectName(name) {
|
|
24
|
+
if (!/^[a-z][a-z0-9-]{0,63}$/.test(name ?? ''))
|
|
25
|
+
return 'Use a project name of 1–64 lowercase letters, numbers or hyphens, starting with a letter.'
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
export function resolvePreset(options) {
|
|
19
29
|
const {
|
|
20
30
|
name,
|
|
@@ -24,11 +34,15 @@ export function resolvePreset(options) {
|
|
|
24
34
|
theme = 'mavis',
|
|
25
35
|
framework = 'vue',
|
|
26
36
|
authoring = 'vue',
|
|
37
|
+
example = 'welcome',
|
|
38
|
+
packageManager = 'npm',
|
|
27
39
|
} = options
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
40
|
+
const invalidName = validateProjectName(name)
|
|
41
|
+
if (invalidName) throw new Error(invalidName)
|
|
42
|
+
if (!packageManagers.includes(packageManager))
|
|
43
|
+
throw new Error('Package manager must be npm, pnpm or yarn.')
|
|
44
|
+
if (!['welcome', 'directory'].includes(example))
|
|
45
|
+
throw new Error('Example must be welcome or directory.')
|
|
32
46
|
if (framework !== 'vue')
|
|
33
47
|
throw new Error(
|
|
34
48
|
'This creator currently supports Vue. Other framework adapters are tracked in Mavis #145 and #35–39.',
|
|
@@ -55,9 +69,11 @@ export function resolvePreset(options) {
|
|
|
55
69
|
target,
|
|
56
70
|
framework,
|
|
57
71
|
authoring,
|
|
72
|
+
example,
|
|
58
73
|
web: target === 'mobile' ? null : web,
|
|
59
74
|
rendering: target === 'mobile' ? null : rendering,
|
|
60
75
|
theme,
|
|
76
|
+
packageManager,
|
|
61
77
|
versions,
|
|
62
78
|
})
|
|
63
79
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { packageCommands } from './package-manager.mjs'
|
|
2
|
+
|
|
3
|
+
export function directoryReadme(preset, shared) {
|
|
4
|
+
const commands = packageCommands(preset.packageManager)
|
|
5
|
+
const combined = preset.target === 'both'
|
|
6
|
+
const start = [
|
|
7
|
+
commands.setup(combined),
|
|
8
|
+
preset.target === 'mobile'
|
|
9
|
+
? commands.run('ios')
|
|
10
|
+
: combined
|
|
11
|
+
? commands.run('dev:web')
|
|
12
|
+
: commands.run('dev'),
|
|
13
|
+
...(preset.target !== 'web'
|
|
14
|
+
? [commands.run('android'), ...(combined ? [commands.run('ios')] : [])]
|
|
15
|
+
: []),
|
|
16
|
+
].join('\n')
|
|
17
|
+
return `# ${preset.name}
|
|
18
|
+
|
|
19
|
+
A shared directory: search → details → edit → save. The same Vue screens run in Vue + Vite SPA, Nuxt SSR/SSG and NativeScript-Vue iOS/Android. This project selects ${preset.web ?? 'NativeScript'}${preset.target === 'both' ? ' + NativeScript' : ''}.
|
|
20
|
+
|
|
21
|
+
## Run
|
|
22
|
+
|
|
23
|
+
\`\`\`sh
|
|
24
|
+
${start}
|
|
25
|
+
\`\`\`
|
|
26
|
+
|
|
27
|
+
Edit \`${shared}/Directory.vue\`, \`Details.vue\` or \`Edit.vue\`. Components and types come from \`#mavis\`, resolved by each host. The entries use MGrid and shared props; MReveal supplies the saved-state animation through the existing motion implementation. No DOM/views or animation scheduler live in these screens.
|
|
28
|
+
|
|
29
|
+
Navigation is installed once with \`createRouterNavigation(router)\`. MLink, MButton and MCard keep their hrefs, and the host owns routing/history. Vue + Vite uses Vue Router; Nuxt uses its own router; NativeScript uses vue-router-ns. SPA history deployments need a server fallback to index.html. Nuxt wrappers pass route parameters into shared screen props.
|
|
30
|
+
|
|
31
|
+
The directory service is created per app/server request. Web persistence uses localStorage after mount/hydration; native persistence uses ApplicationSettings. Stored data is a local demonstration, not a backend or cross-device synchronization. Failed writes preserve the draft and can be retried. Replace the host storage service for your application.
|
|
32
|
+
|
|
33
|
+
## Check sharing
|
|
34
|
+
|
|
35
|
+
\`\`\`sh
|
|
36
|
+
${commands.creator} --check-portability
|
|
37
|
+
${commands.creator} --fix-imports # preview
|
|
38
|
+
${commands.creator} --fix-imports --write
|
|
39
|
+
\`\`\`
|
|
40
|
+
|
|
41
|
+
The audit follows local imports, reports locations and suggestions, and never converts arbitrary HTML/CSS or device APIs. Only named, shared renderer imports can be migrated automatically after host aliases exist. An empty report does not certify third-party dependencies or replace runtime testing.
|
|
42
|
+
|
|
43
|
+
${preset.web === 'nuxt' ? `Nuxt: use \`${commands.run('build')}\` for SSR, \`${commands.run('generate')}\` for static output, and \`${commands.run('typecheck')}\`. In a combined project these commands live in apps/web. Dynamic entry routes are reached through real links during prerendering.\n\n` : ''}${preset.target !== 'web' ? `Native: run \`${commands.run('typecheck')}\`, \`${commands.run('bundle:android')}\` and \`${commands.run('bundle:ios')}\` in the mobile directory. Runtime builds require the NativeScript CLI and SDKs (macOS/Xcode for iOS).\n\n` : ''}${combined ? `Web and mobile keep separate dependency trees. After the initial setup above, reinstall both with \`${commands.run('install:apps')}\`. Do not add apps/mobile to the Web workspace.\n\n` : ''}${preset.packageManager === 'pnpm' ? 'Use pnpm 10.26+. The generated workspace files configure hoisting, build scripts and separate mobile dependencies.\n\n' : ''}${preset.packageManager === 'yarn' ? 'Yarn Classic and modern Yarn use node_modules. The initial lockfiles mark project boundaries. If a fresh dependency is quarantined, retry after the configured minimum package age.\n\n' : ''}Commit ${combined ? 'both generated lockfiles' : `the generated ${commands.lockfile}`}. When testing an unreleased creator from source, install matching local Mavis tarballs. Package pins are updated together at release.
|
|
44
|
+
`
|
|
45
|
+
}
|