@getcortexlabs/create-mavis 0.1.0-rc.14 → 0.1.0-rc.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +21 -28
  2. package/package.json +2 -4
  3. package/src/adapters.mjs +45 -23
  4. package/src/add-desktop.mjs +354 -0
  5. package/src/capabilities.mjs +233 -134
  6. package/src/cli.mjs +64 -60
  7. package/src/desktop.mjs +155 -0
  8. package/src/doctor.mjs +77 -108
  9. package/src/native-framework.mjs +144 -0
  10. package/src/portability.mjs +7 -106
  11. package/src/scaffold.mjs +36 -12
  12. package/src/shared-api.mjs +3 -0
  13. package/src/ui.mjs +30 -42
  14. package/templates/desktop/common/LICENSE +21 -0
  15. package/templates/desktop/common/build.mjs +49 -0
  16. package/templates/desktop/common/src/components.ts +60 -0
  17. package/templates/desktop/common/src/contract.mjs +35 -0
  18. package/templates/desktop/common/src/renderer.ts +76 -0
  19. package/templates/desktop/common/src/storage.ts +29 -0
  20. package/templates/desktop/directory/main.ts +35 -0
  21. package/templates/desktop/macos/launch.mjs +6 -0
  22. package/templates/desktop/macos/package.mjs +114 -0
  23. package/templates/desktop/macos/src/host.mjs +471 -0
  24. package/templates/desktop/welcome/Welcome.vue +56 -0
  25. package/templates/desktop/welcome/main.ts +24 -0
  26. package/templates/desktop/windows/NativeScript-LICENSE +19 -0
  27. package/templates/desktop/windows/launch.mjs +16 -0
  28. package/templates/desktop/windows/package.mjs +54 -0
  29. package/templates/desktop/windows/prepare-host.mjs +73 -0
  30. package/templates/desktop/windows/src/host.mjs +294 -0
  31. package/templates/native-framework/angular/screen.ts +84 -0
  32. package/templates/native-framework/common/nativescript.config.ts +6 -0
  33. package/templates/native-framework/common/src/app.ts +5 -0
  34. package/templates/native-framework/common/src/model.ts +40 -0
  35. package/templates/native-framework/common/src/references.d.ts +8 -0
  36. package/templates/native-framework/common/tsconfig.json +16 -0
  37. package/templates/native-framework/common/webpack.config.js +67 -0
  38. package/templates/native-framework/plain/screen.ts +102 -0
  39. package/templates/native-framework/react/screen.ts +83 -0
  40. package/templates/native-framework/solid/screen.ts +111 -0
  41. package/templates/native-framework/svelte/Welcome.svelte +26 -0
  42. package/templates/native-framework/svelte/screen.ts +14 -0
  43. package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
  44. package/src/add-macos.mjs +0 -386
  45. package/src/macos-capabilities.generated.mjs +0 -4190
  46. package/src/macos.mjs +0 -394
  47. package/src/migrate-directory.mjs +0 -121
  48. package/templates/directory/macos/DirectoryStorage.swift +0 -68
  49. package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +0 -57
  50. package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +0 -33
  51. package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +0 -251
  52. package/templates/macos/examples/tasks/shared/types.ts +0 -10
  53. package/templates/macos/mobile/src/App.vue +0 -14
  54. package/templates/macos/mobile/src/app.ts +0 -7
  55. package/templates/macos/native/Package.swift +0 -19
  56. package/templates/macos/native/Sources/MavisDesktop/App.swift +0 -35
  57. package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +0 -45
  58. package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
  59. package/templates/macos/root/tsconfig.json +0 -14
  60. package/templates/macos/scripts/generate.mjs +0 -13
  61. package/templates/macos/scripts/macos-manifest.mjs +0 -33
  62. package/templates/macos/scripts/macos.mjs +0 -58
  63. package/templates/macos/shared/Welcome.lite.tsx +0 -42
  64. package/templates/macos/web/index.html +0 -12
  65. package/templates/macos/web/src/main.js +0 -212
  66. package/templates/macos/web/src/mavis.js +0 -2
  67. package/templates/macos/web/src/style.css +0 -14
  68. package/templates/macos/web/vite.config.mjs +0 -14
  69. package/templates/migrations/directory-rc13.json +0 -36
@@ -0,0 +1,471 @@
1
+ import { nativeProps } from './contract.mjs'
2
+ import { mavis, midnight } from '@getcortexlabs/mavis-core'
3
+ import { appKitMotion } from '@rafaelaugusto/jolt/appkit'
4
+
5
+ const rect = (x, y, width, height) => ({ origin: { x, y }, size: { width, height } })
6
+ const emit = (listener, ...args) => {
7
+ for (const fn of Array.isArray(listener) ? listener : [listener])
8
+ if (typeof fn === 'function') fn(...args)
9
+ }
10
+ const nativeColor = (hex) => {
11
+ const rgb = Number.parseInt(hex.replace('#', '').slice(0, 6), 16)
12
+ return NSColor.colorWithSRGBRedGreenBlueAlpha(
13
+ (rgb >> 16) / 255,
14
+ ((rgb >> 8) & 255) / 255,
15
+ (rgb & 255) / 255,
16
+ 1,
17
+ )
18
+ }
19
+
20
+ class MavisAppKitView extends NSView {
21
+ static {
22
+ NativeClass(this)
23
+ }
24
+ // The bridge overrides the Objective-C property name, not its isFlipped selector.
25
+ get flipped() {
26
+ return true
27
+ }
28
+ }
29
+ class MavisAppKitCard extends NSButton {
30
+ static {
31
+ NativeClass(this)
32
+ }
33
+ hitTest(point) {
34
+ return super.hitTest(point) ? this : null
35
+ }
36
+ }
37
+ class MavisAppKitAction extends NSObject {
38
+ static ObjCExposedMethods = {
39
+ activate: { returns: interop.types.void, params: [interop.types.id] },
40
+ }
41
+ static {
42
+ NativeClass(this)
43
+ }
44
+ activate() {
45
+ this.callback?.()
46
+ }
47
+ }
48
+ class MavisAppKitInputDelegate extends NSObject {
49
+ static ObjCProtocols = [NSTextFieldDelegate]
50
+ static {
51
+ NativeClass(this)
52
+ }
53
+ controlTextDidChange() {
54
+ this.change?.()
55
+ }
56
+ controlTextViewDoCommandBySelector(_control, _editor, selector) {
57
+ if (selector === 'insertNewline:') {
58
+ this.submit?.()
59
+ return true
60
+ }
61
+ if (selector === 'cancelOperation:') {
62
+ this.escape?.()
63
+ return true
64
+ }
65
+ return false
66
+ }
67
+ }
68
+ class MavisAppKitWindowDelegate extends NSObject {
69
+ static ObjCProtocols = [NSWindowDelegate]
70
+ static {
71
+ NativeClass(this)
72
+ }
73
+ windowDidResize() {
74
+ this.resize?.()
75
+ }
76
+ windowWillClose() {
77
+ this.close?.()
78
+ }
79
+ }
80
+
81
+ /** Small, explicit component host for the desktop starter, not the full Mavis renderer. */
82
+ export function createHost({ title = '__MAVIS_NAME__', onClose = () => {} } = {}) {
83
+ const app = NSApplication.sharedApplication
84
+ app.setActivationPolicy(NSApplicationActivationPolicy.Regular)
85
+ const window = NSWindow.alloc().initWithContentRectStyleMaskBackingDefer(
86
+ rect(0, 0, 780, 620),
87
+ NSWindowStyleMask.Titled |
88
+ NSWindowStyleMask.Closable |
89
+ NSWindowStyleMask.Miniaturizable |
90
+ NSWindowStyleMask.Resizable,
91
+ NSBackingStoreType.Buffered,
92
+ false,
93
+ )
94
+ window.title = title
95
+ window.releasedWhenClosed = false
96
+ window.minSize = { width: 360, height: 380 }
97
+ const rootView = MavisAppKitView.alloc().initWithFrame(rect(0, 0, 780, 620))
98
+ window.contentView = rootView
99
+ const root = {
100
+ kind: 'root',
101
+ text: '',
102
+ props: {},
103
+ children: [],
104
+ parent: null,
105
+ native: rootView,
106
+ content: rootView,
107
+ }
108
+ const nodes = new Set([root])
109
+ let theme = mavis,
110
+ closed = false,
111
+ scheduled = false,
112
+ pumpTimer
113
+ let reducedOverride = null
114
+ const reduced = () =>
115
+ reducedOverride ?? NSWorkspace.sharedWorkspace.accessibilityDisplayShouldReduceMotion
116
+ const actions = [] // Cocoa targets/delegates are weak. Retain until their owner is disposed.
117
+ const sheets = new Set()
118
+ const tokens = (key) => (typeof key === 'number' ? key : (theme.space[key] ?? 0))
119
+ const text = (node) => node.text || node.children.map(text).join('')
120
+ const setBackground = (view, color) => {
121
+ view.wantsLayer = true
122
+ view.layer.backgroundColor = nativeColor(color).CGColor
123
+ }
124
+ function action(target, callback) {
125
+ const delegate = MavisAppKitAction.new()
126
+ delegate.callback = callback
127
+ target.target = delegate
128
+ target.action = 'activate'
129
+ return delegate
130
+ }
131
+ function create(kind) {
132
+ if (
133
+ ![
134
+ '#text',
135
+ '#comment',
136
+ 'screen',
137
+ 'column',
138
+ 'row',
139
+ 'grid',
140
+ 'text',
141
+ 'input',
142
+ 'reveal',
143
+ 'button',
144
+ 'link',
145
+ 'card',
146
+ ].includes(kind)
147
+ )
148
+ throw new Error(`AppKit desktop host does not implement ${kind}`)
149
+ const node = { kind, text: '', props: {}, children: [], parent: null }
150
+ nodes.add(node)
151
+ if (kind[0] === '#') return node
152
+ if (kind === 'text') {
153
+ node.native = NSTextField.labelWithString('')
154
+ node.native.lineBreakMode = NSLineBreakMode.ByWordWrapping
155
+ node.native.maximumNumberOfLines = 0
156
+ } else if (kind === 'input') {
157
+ node.native = MavisAppKitView.new()
158
+ node.label = NSTextField.labelWithString('')
159
+ node.editor = NSTextField.new()
160
+ node.editor.bezelStyle = NSTextFieldBezelStyle.RoundedBezel
161
+ node.delegate = MavisAppKitInputDelegate.new()
162
+ node.delegate.change = () => emit(node.props['onUpdate:modelValue'], node.editor.stringValue)
163
+ node.delegate.submit = () => emit(node.props.onSubmit)
164
+ node.delegate.escape = () => emit(node.props.onEscape)
165
+ node.editor.delegate = node.delegate
166
+ node.native.addSubview(node.label)
167
+ node.native.addSubview(node.editor)
168
+ } else if (['button', 'link', 'card'].includes(kind)) {
169
+ node.native = kind === 'card' ? MavisAppKitCard.new() : NSButton.new()
170
+ node.native.setButtonType(NSButtonType.MomentaryPushIn)
171
+ node.native.bezelStyle = NSBezelStyle.Rounded
172
+ node.delegate = action(node.native, () => emit(node.props.onClick))
173
+ if (kind === 'link') node.native.bordered = false
174
+ if (kind === 'card') {
175
+ node.content = MavisAppKitView.new()
176
+ node.native.addSubview(node.content)
177
+ }
178
+ } else if (kind === 'screen') {
179
+ node.native = NSScrollView.new()
180
+ node.native.hasVerticalScroller = true
181
+ node.native.autohidesScrollers = true
182
+ node.native.drawsBackground = false
183
+ node.content = MavisAppKitView.new()
184
+ node.native.documentView = node.content
185
+ } else node.native = MavisAppKitView.new()
186
+ node.content ??= node.native
187
+ node.native.wantsLayer = true
188
+ if (kind === 'reveal') {
189
+ node.motion = appKitMotion(node.native)
190
+ node.motion.animate('opacity', 0, { reducedMotion: true })
191
+ }
192
+ node.dispose = () => {
193
+ node.motion?.dispose()
194
+ if (node.editor) node.editor.delegate = null
195
+ if (node.delegate) {
196
+ node.delegate.callback =
197
+ node.delegate.change =
198
+ node.delegate.submit =
199
+ node.delegate.escape =
200
+ null
201
+ if ('target' in node.native) node.native.target = null
202
+ node.delegate = null
203
+ }
204
+ nodes.delete(node)
205
+ }
206
+ return node
207
+ }
208
+ function update(node) {
209
+ if (!node.native || closed) return
210
+ const p = node.props,
211
+ view = node.native
212
+ for (const key of Object.keys(p))
213
+ if (!nativeProps(node.kind, 'macos').includes(key))
214
+ throw new Error(`AppKit desktop host does not implement ${node.kind}.${key}`)
215
+ const identifier = String(p.id ?? '')
216
+ view.accessibilityIdentifier = identifier
217
+ if (p.accessibilityLabel) view.accessibilityLabel = p.accessibilityLabel
218
+ if (node.kind === 'text') {
219
+ view.stringValue = p.text ?? text(node)
220
+ const size = { title: 28, heading: 20, caption: 12 }[p.variant] ?? 14
221
+ view.font =
222
+ p.variant === 'title' || p.variant === 'heading'
223
+ ? NSFont.boldSystemFontOfSize(size)
224
+ : NSFont.systemFontOfSize(size)
225
+ view.textColor = nativeColor(theme.colors[p.tone] ?? theme.colors.text)
226
+ }
227
+ if (node.kind === 'input') {
228
+ node.label.stringValue = String(p.label ?? '')
229
+ node.label.textColor = nativeColor(theme.colors.text)
230
+ const value = String(p.modelValue ?? '')
231
+ // Re-rendering unrelated state must not reset the editor's selection/caret.
232
+ if (node.editor.stringValue !== value) node.editor.stringValue = value
233
+ node.editor.placeholderString = String(p.placeholder ?? '')
234
+ node.editor.editable = !p.readonly && !p.disabled
235
+ node.editor.enabled = !p.disabled
236
+ node.editor.accessibilityIdentifier = identifier
237
+ node.editor.accessibilityLabel = String(p.label ?? '')
238
+ }
239
+ if (['button', 'link', 'card'].includes(node.kind)) {
240
+ view.title =
241
+ node.kind === 'card'
242
+ ? ''
243
+ : String(p.loading ? (p.loadingText ?? 'Loading…') : (p.text ?? text(node)))
244
+ view.enabled = !p.disabled && !p.loading
245
+ view.keyEquivalent = p.shortcut === 'mod+s' ? 's' : ''
246
+ if (node.kind === 'card') {
247
+ setBackground(node.content, theme.colors.surface)
248
+ node.content.layer.cornerRadius = 10
249
+ }
250
+ }
251
+ if (node.kind === 'reveal') {
252
+ const shown = p.show !== false
253
+ if (node.shown !== shown) {
254
+ if (!shown) node.motion.animate('opacity', 0, { reducedMotion: true })
255
+ node.shown = shown
256
+ view.hidden = !shown
257
+ node.pendingReveal = shown
258
+ }
259
+ }
260
+ }
261
+ function attach(node, parent) {
262
+ if (!node.native) return
263
+ const host = parent.content
264
+ if (host && node.native.superview !== host) host.addSubview(node.native)
265
+ }
266
+ function detach(node) {
267
+ node.native?.removeFromSuperview()
268
+ nodes.delete(node)
269
+ }
270
+ function layoutNode(node, x, y, width, viewport = 0) {
271
+ if (!node.native) return 0
272
+ if (node.kind === 'reveal' && !node.shown) {
273
+ node.native.frame = rect(x, y, width, 0)
274
+ return 0
275
+ }
276
+ const p = node.props
277
+ let height = 0
278
+ if (node.kind === 'text') {
279
+ height = Math.ceil(node.native.cell.cellSizeForBounds(rect(0, 0, width, 10000)).height) + 2
280
+ } else if (node.kind === 'input') {
281
+ const label = p.label ? 20 : 0
282
+ node.label.frame = rect(0, 0, width, label)
283
+ node.editor.frame = rect(0, label + 4, width, 28)
284
+ height = label + 36
285
+ } else if (node.kind === 'button' || node.kind === 'link') height = 34
286
+ else {
287
+ const pad = tokens(p.padding ?? (node.kind === 'card' ? 'md' : 'none'))
288
+ const gap = tokens(p.gap)
289
+ const children = node.children.filter(
290
+ (child) => child.native && !(child.kind === 'reveal' && !child.shown),
291
+ )
292
+ const columns =
293
+ node.kind === 'grid'
294
+ ? Math.max(
295
+ 1,
296
+ Math.floor((width - pad * 2 + gap) / (Number(p.minColumnWidth ?? 240) + gap)),
297
+ )
298
+ : node.kind === 'row'
299
+ ? Math.max(1, children.length)
300
+ : 1
301
+ const cellWidth = (width - pad * 2 - gap * (columns - 1)) / columns
302
+ let top = pad
303
+ for (let index = 0; index < children.length; index += columns) {
304
+ let rowHeight = 0
305
+ for (let col = 0; col < columns && index + col < children.length; col++)
306
+ rowHeight = Math.max(
307
+ rowHeight,
308
+ layoutNode(
309
+ children[index + col],
310
+ pad + col * (cellWidth + gap),
311
+ top,
312
+ cellWidth,
313
+ viewport,
314
+ ),
315
+ )
316
+ top += rowHeight + gap
317
+ }
318
+ height = top + pad - (children.length ? gap : 0)
319
+ if (node.kind === 'screen') {
320
+ node.content.frame = rect(0, 0, width, Math.max(viewport, height))
321
+ height = viewport
322
+ } else if (node.kind === 'card') node.content.frame = rect(4, 4, width - 8, height)
323
+ }
324
+ if (node.kind === 'root') height = viewport
325
+ node.native.frame = rect(x, y, width, Math.max(height, 0))
326
+ return height
327
+ }
328
+ function layout() {
329
+ if (scheduled || closed) return
330
+ scheduled = true
331
+ queueMicrotask(() => {
332
+ scheduled = false
333
+ if (closed) return
334
+ const { width, height } = window.contentView.bounds.size
335
+ layoutNode(root, 0, 0, width, height)
336
+ for (const node of nodes) {
337
+ if (node.pendingReveal && node.native.window) {
338
+ node.pendingReveal = false
339
+ node.revealPlayback = node.motion.animate('opacity', 1, { reducedMotion: reduced() })
340
+ }
341
+ }
342
+ window.recalculateKeyViewLoop()
343
+ })
344
+ }
345
+ function setTheme(dark) {
346
+ theme = dark ? midnight : mavis
347
+ window.appearance = NSAppearance.appearanceNamed(
348
+ dark ? 'NSAppearanceNameDarkAqua' : 'NSAppearanceNameAqua',
349
+ )
350
+ window.backgroundColor = nativeColor(theme.colors.background)
351
+ for (const node of nodes) update(node)
352
+ layout()
353
+ }
354
+ function stop() {
355
+ if (closed) return
356
+ closed = true
357
+ clearTimeout(pumpTimer)
358
+ for (const sheet of sheets) window.endSheetReturnCode(sheet.window, NSModalResponseCancel)
359
+ sheets.clear()
360
+ NSWorkspace.sharedWorkspace.notificationCenter.removeObserver(accessibilityObserver)
361
+ for (const node of nodes) node.dispose?.()
362
+ nodes.clear()
363
+ window.delegate = null
364
+ delegate.resize = delegate.close = null
365
+ for (const target of actions) target.callback = null
366
+ app.mainMenu = null
367
+ }
368
+ const delegate = MavisAppKitWindowDelegate.new()
369
+ delegate.resize = layout
370
+ delegate.close = () => {
371
+ onClose()
372
+ stop()
373
+ }
374
+ window.delegate = delegate
375
+ const menu = NSMenu.new()
376
+ function addMenu(name, items) {
377
+ const submenu = NSMenu.alloc().initWithTitle(name)
378
+ for (const [label, selector, key, callback] of items) {
379
+ const item = submenu.addItemWithTitleActionKeyEquivalent(label, selector, key)
380
+ if (callback) actions.push(action(item, callback))
381
+ }
382
+ const item = NSMenuItem.new()
383
+ item.submenu = submenu
384
+ menu.addItem(item)
385
+ }
386
+ addMenu('Mavis', [['Quit Mavis', 'activate:', 'q', () => window.performClose(null)]])
387
+ addMenu('Edit', [
388
+ ['Undo', 'undo:', 'z'],
389
+ ['Redo', 'redo:', 'Z'],
390
+ ['Cut', 'cut:', 'x'],
391
+ ['Copy', 'copy:', 'c'],
392
+ ['Paste', 'paste:', 'v'],
393
+ ['Select All', 'selectAll:', 'a'],
394
+ ])
395
+ addMenu('View', [['Toggle theme', 'activate:', 't', () => setTheme(theme === mavis)]])
396
+ function openInfoSheet() {
397
+ const sheet = NSAlert.new()
398
+ sheet.messageText = 'Community directory'
399
+ sheet.informativeText =
400
+ 'Find a place to learn, create or meet your neighbours. Changes are saved on this Mac.'
401
+ sheet.addButtonWithTitle('Done')
402
+ sheet.addButtonWithTitle('Cancel')
403
+ sheets.add(sheet)
404
+ sheet.beginSheetModalForWindowCompletionHandler(window, () => sheets.delete(sheet))
405
+ return sheet
406
+ }
407
+ addMenu('Help', [['About Community directory', 'activate:', '', openInfoSheet]])
408
+ app.mainMenu = menu
409
+ setTheme(false)
410
+ function show() {
411
+ app.finishLaunching()
412
+ window.center()
413
+ window.makeKeyAndOrderFront(null)
414
+ app.activateIgnoringOtherApps(true)
415
+ const pump = () => {
416
+ if (closed) return
417
+ for (let i = 0; i < 64; i++) {
418
+ const event = app.nextEventMatchingMaskUntilDateInModeDequeue(
419
+ NSEventMask.Any,
420
+ null,
421
+ 'kCFRunLoopDefaultMode',
422
+ true,
423
+ )
424
+ if (!event) break
425
+ app.sendEvent(event)
426
+ }
427
+ app.updateWindows()
428
+ pumpTimer = setTimeout(pump, 4)
429
+ }
430
+ pump()
431
+ layout()
432
+ }
433
+ function setReducedMotion(value) {
434
+ reducedOverride = value
435
+ if (reduced())
436
+ for (const node of nodes)
437
+ if (node.kind === 'reveal' && node.shown) {
438
+ node.revealPlayback = node.motion.animate('opacity', 1, { reducedMotion: true })
439
+ }
440
+ }
441
+ const accessibilityObserver =
442
+ NSWorkspace.sharedWorkspace.notificationCenter.addObserverForNameObjectQueueUsingBlock(
443
+ 'NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification',
444
+ null,
445
+ null,
446
+ () => setReducedMotion(reducedOverride),
447
+ )
448
+ return {
449
+ root,
450
+ window,
451
+ nodes,
452
+ sheets,
453
+ create,
454
+ update,
455
+ attach,
456
+ detach,
457
+ layout,
458
+ show,
459
+ close() {
460
+ window.performClose(null)
461
+ },
462
+ stop,
463
+ setTheme,
464
+ addMenu,
465
+ openInfoSheet,
466
+ setReducedMotion,
467
+ get closed() {
468
+ return closed
469
+ },
470
+ }
471
+ }
@@ -0,0 +1,56 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue'
3
+ import { MScreen, MColumn, MRow, MText, MInput, MButton, MReveal, MAlert } from '#mavis'
4
+ import { useProjectService } from './services'
5
+ const service = useProjectService()
6
+ const name = ref('A new beginning'),
7
+ count = ref(0),
8
+ saving = ref(false),
9
+ saved = ref(false),
10
+ error = ref('')
11
+ async function save() {
12
+ if (saving.value || !name.value.trim()) return
13
+ saving.value = true
14
+ error.value = ''
15
+ saved.value = false
16
+ try {
17
+ await service.save(name.value.trim())
18
+ saved.value = true
19
+ } catch {
20
+ error.value = 'Could not save. Your draft is still here; try again.'
21
+ } finally {
22
+ saving.value = false
23
+ }
24
+ }
25
+ </script>
26
+ <template>
27
+ <MScreen scroll>
28
+ <MColumn padding="lg" gap="lg">
29
+ <MText variant="title">__MAVIS_NAME__</MText>
30
+ <MText tone="muted">One Vue screen, native controls on every selected platform.</MText>
31
+ <MInput
32
+ id="project-name"
33
+ v-model="name"
34
+ label="Project name"
35
+ @submit="save"
36
+ @update:modelValue="saved = false"
37
+ />
38
+ <MText id="greeting">{{ name }}</MText>
39
+ <MRow gap="md">
40
+ <MButton id="increment" :text="`Count ${count}`" @click="count++" />
41
+ <MButton
42
+ id="save-project"
43
+ text="Save project"
44
+ :disabled="!name.trim()"
45
+ :loading="saving"
46
+ loadingText="Saving…"
47
+ @click="save"
48
+ />
49
+ </MRow>
50
+ <MAlert v-if="error" title="Save failed" :description="error" />
51
+ <MReveal :show="saved"
52
+ ><MText id="saved" tone="success">Your project is saved.</MText></MReveal
53
+ >
54
+ </MColumn>
55
+ </MScreen>
56
+ </template>
@@ -0,0 +1,24 @@
1
+ import { createHost } from '#desktop-host'
2
+ import { desktopRenderer } from './renderer'
3
+ import { persistence, storageFile } from './storage'
4
+ import Welcome from '#shared-ui/Welcome.vue'
5
+ import { projectServiceKey } from '#shared-ui/services'
6
+ let application: ReturnType<ReturnType<typeof desktopRenderer>['createApp']>
7
+ const host = createHost({
8
+ title: '__MAVIS_NAME__',
9
+ onClose() {
10
+ application?.unmount()
11
+ },
12
+ })
13
+ const storage = persistence(() => host.closed)
14
+ application = desktopRenderer(host).createApp(Welcome)
15
+ application.provide(projectServiceKey, { save: (name: string) => storage.write(name) })
16
+ host.setTheme('__MAVIS_THEME__' === 'midnight')
17
+ application.mount(host.root)
18
+ host.show()
19
+ // A local acceptance hook is loaded only when explicitly supplied by the developer.
20
+ if (process.env.MAVIS_DESKTOP_CHECK) {
21
+ const { pathToFileURL } = await import('node:url')
22
+ const { default: check } = await import(pathToFileURL(process.env.MAVIS_DESKTOP_CHECK).href)
23
+ await check({ host, application, storageFile })
24
+ }
@@ -0,0 +1,19 @@
1
+ Copyright OpenJS Foundation and other contributors, https://openjsf.org
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ import { spawn } from 'node:child_process'
2
+ import { dirname, resolve } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { prepareWindowsHost } from './prepare-host.mjs'
5
+ const here = dirname(fileURLToPath(import.meta.url))
6
+ const executable = prepareWindowsHost(resolve(here, '.mavis/runtime/node.exe'))
7
+ const child = spawn(executable, [resolve(here, 'dist/main.mjs'), ...process.argv.slice(2)], {
8
+ stdio: 'inherit',
9
+ })
10
+ child.on('error', (error) => {
11
+ console.error(error.message)
12
+ process.exitCode = 1
13
+ })
14
+ child.on('exit', (code) => {
15
+ process.exitCode = code ?? 1
16
+ })
@@ -0,0 +1,54 @@
1
+ import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import { dirname, join, resolve } from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+ import { prepareWindowsHost } from './prepare-host.mjs'
6
+ const here = dirname(fileURLToPath(import.meta.url))
7
+ const require = createRequire(import.meta.url)
8
+ const output = resolve(here, `artifacts/__MAVIS_NAME__-win32-${process.arch}`)
9
+ if (process.platform !== 'win32') throw new Error('Package the Windows app on Windows.')
10
+ rmSync(output, { recursive: true, force: true })
11
+ mkdirSync(output, { recursive: true })
12
+ prepareWindowsHost(join(output, 'node.exe'))
13
+ cpSync(join(here, 'dist/main.mjs'), join(output, 'dist/main.mjs'))
14
+ const runtime = dirname(require.resolve('@nativescript/windows-napi'))
15
+ cpSync(runtime, join(output, 'node_modules/@nativescript/windows-napi'), { recursive: true })
16
+ writeFileSync(
17
+ join(output, '__MAVIS_NAME__.cmd'),
18
+ '@echo off\r\n"%~dp0node.exe" "%~dp0dist\\main.mjs" %*\r\n',
19
+ )
20
+ const licenses = join(output, 'Licenses')
21
+ mkdirSync(licenses)
22
+ for (const [name, source] of [
23
+ ['Mavis', join(here, 'LICENSE')],
24
+ ['Vue', join(here, 'node_modules/vue/LICENSE')],
25
+ ['VueRouter', join(here, 'node_modules/vue-router/LICENSE')],
26
+ ['Jolt', join(here, 'node_modules/@rafaelaugusto/jolt/LICENSE')],
27
+ ['NativeScript', join(here, 'NativeScript-LICENSE')],
28
+ ])
29
+ cpSync(source, join(licenses, `${name}.txt`))
30
+ const nodeLicense = [
31
+ join(dirname(process.execPath), 'LICENSE'),
32
+ join(dirname(process.execPath), '../LICENSE'),
33
+ ].find(existsSync)
34
+ if (!nodeLicense)
35
+ throw new Error(
36
+ 'Use the official Node distribution including its LICENSE to package the runtime.',
37
+ )
38
+ cpSync(nodeLicense, join(licenses, 'Node.txt'))
39
+ writeFileSync(
40
+ join(here, 'artifacts/package.json'),
41
+ JSON.stringify(
42
+ {
43
+ directory: output,
44
+ node: process.version,
45
+ arch: process.arch,
46
+ runtime: JSON.parse(readFileSync(join(runtime, 'package.json'), 'utf8')).version,
47
+ minimumWindows: '10 build 18362',
48
+ signing: 'unsigned portable folder; not an installer',
49
+ },
50
+ null,
51
+ 2,
52
+ ) + '\n',
53
+ )
54
+ console.log(output)