@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.
- package/README.md +21 -28
- package/package.json +2 -4
- package/src/adapters.mjs +45 -23
- package/src/add-desktop.mjs +354 -0
- package/src/capabilities.mjs +233 -134
- package/src/cli.mjs +64 -60
- package/src/desktop.mjs +155 -0
- package/src/doctor.mjs +77 -108
- package/src/native-framework.mjs +144 -0
- package/src/portability.mjs +7 -106
- package/src/scaffold.mjs +36 -12
- package/src/shared-api.mjs +3 -0
- package/src/ui.mjs +30 -42
- package/templates/desktop/common/LICENSE +21 -0
- package/templates/desktop/common/build.mjs +49 -0
- package/templates/desktop/common/src/components.ts +60 -0
- package/templates/desktop/common/src/contract.mjs +35 -0
- package/templates/desktop/common/src/renderer.ts +76 -0
- package/templates/desktop/common/src/storage.ts +29 -0
- package/templates/desktop/directory/main.ts +35 -0
- package/templates/desktop/macos/launch.mjs +6 -0
- package/templates/desktop/macos/package.mjs +114 -0
- package/templates/desktop/macos/src/host.mjs +471 -0
- package/templates/desktop/welcome/Welcome.vue +56 -0
- package/templates/desktop/welcome/main.ts +24 -0
- package/templates/desktop/windows/NativeScript-LICENSE +19 -0
- package/templates/desktop/windows/launch.mjs +16 -0
- package/templates/desktop/windows/package.mjs +54 -0
- package/templates/desktop/windows/prepare-host.mjs +73 -0
- package/templates/desktop/windows/src/host.mjs +294 -0
- package/templates/native-framework/angular/screen.ts +84 -0
- package/templates/native-framework/common/nativescript.config.ts +6 -0
- package/templates/native-framework/common/src/app.ts +5 -0
- package/templates/native-framework/common/src/model.ts +40 -0
- package/templates/native-framework/common/src/references.d.ts +8 -0
- package/templates/native-framework/common/tsconfig.json +16 -0
- package/templates/native-framework/common/webpack.config.js +67 -0
- package/templates/native-framework/plain/screen.ts +102 -0
- package/templates/native-framework/react/screen.ts +83 -0
- package/templates/native-framework/solid/screen.ts +111 -0
- package/templates/native-framework/svelte/Welcome.svelte +26 -0
- package/templates/native-framework/svelte/screen.ts +14 -0
- package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
- package/src/add-macos.mjs +0 -386
- package/src/macos-capabilities.generated.mjs +0 -4190
- package/src/macos.mjs +0 -394
- package/src/migrate-directory.mjs +0 -121
- package/templates/directory/macos/DirectoryStorage.swift +0 -68
- package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +0 -57
- package/templates/macos/examples/tasks/shared/TaskRow.lite.tsx +0 -33
- package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +0 -251
- package/templates/macos/examples/tasks/shared/types.ts +0 -10
- package/templates/macos/mobile/src/App.vue +0 -14
- package/templates/macos/mobile/src/app.ts +0 -7
- package/templates/macos/native/Package.swift +0 -19
- package/templates/macos/native/Sources/MavisDesktop/App.swift +0 -35
- package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +0 -45
- package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
- package/templates/macos/root/tsconfig.json +0 -14
- package/templates/macos/scripts/generate.mjs +0 -13
- package/templates/macos/scripts/macos-manifest.mjs +0 -33
- package/templates/macos/scripts/macos.mjs +0 -58
- package/templates/macos/shared/Welcome.lite.tsx +0 -42
- package/templates/macos/web/index.html +0 -12
- package/templates/macos/web/src/main.js +0 -212
- package/templates/macos/web/src/mavis.js +0 -2
- package/templates/macos/web/src/style.css +0 -14
- package/templates/macos/web/vite.config.mjs +0 -14
- package/templates/migrations/directory-rc13.json +0 -36
package/src/add-macos.mjs
DELETED
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
import { lstat, mkdir, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path'
|
|
3
|
-
import {
|
|
4
|
-
compileProject,
|
|
5
|
-
joltSwift,
|
|
6
|
-
macAppSettings,
|
|
7
|
-
startupPlan,
|
|
8
|
-
readAssets,
|
|
9
|
-
readShared,
|
|
10
|
-
} from '@getcortexlabs/mavis-compiler'
|
|
11
|
-
import { directoryMigration } from './migrate-directory.mjs'
|
|
12
|
-
import { migrateConfig, versions } from './capabilities.mjs'
|
|
13
|
-
import { detectPackageManager, packageCommands } from './package-manager.mjs'
|
|
14
|
-
|
|
15
|
-
const json = (value) => JSON.stringify(value, null, 2) + '\n'
|
|
16
|
-
const templates = new URL('../templates/', import.meta.url)
|
|
17
|
-
async function optional(path) {
|
|
18
|
-
try {
|
|
19
|
-
return await readFile(path, 'utf8')
|
|
20
|
-
} catch (error) {
|
|
21
|
-
if (error.code !== 'ENOENT') throw error
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async function safe(root, name) {
|
|
25
|
-
if (
|
|
26
|
-
typeof name !== 'string' ||
|
|
27
|
-
!name ||
|
|
28
|
-
isAbsolute(name) ||
|
|
29
|
-
name.includes('\\') ||
|
|
30
|
-
name.split('/').includes('..')
|
|
31
|
-
)
|
|
32
|
-
throw new Error('Mac target paths must stay inside the project.')
|
|
33
|
-
let current = root
|
|
34
|
-
for (const part of name.split('/').filter((part) => part && part !== '.')) {
|
|
35
|
-
current = join(current, part)
|
|
36
|
-
try {
|
|
37
|
-
if ((await lstat(current)).isSymbolicLink()) throw new Error(`Refusing symlink: ${name}`)
|
|
38
|
-
} catch (error) {
|
|
39
|
-
if (error.code !== 'ENOENT') throw error
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return current
|
|
43
|
-
}
|
|
44
|
-
async function copy(files, folder, destination, replace) {
|
|
45
|
-
const source = new URL(folder + '/', templates)
|
|
46
|
-
for (const entry of await readdir(source, { withFileTypes: true })) {
|
|
47
|
-
if (entry.isDirectory())
|
|
48
|
-
await copy(files, `${folder}/${entry.name}`, `${destination}/${entry.name}`, replace)
|
|
49
|
-
else {
|
|
50
|
-
const data = await readFile(new URL(entry.name, source))
|
|
51
|
-
files.set(
|
|
52
|
-
`${destination}/${entry.name}`,
|
|
53
|
-
/\.(ttf|icns)$/.test(entry.name) ? data : replace(data.toString('utf8')),
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const exact = (value) => typeof value === 'string' && /^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(value)
|
|
59
|
-
|
|
60
|
-
/** Preview adding a native SwiftUI host. Existing Web/native files are never rewritten. */
|
|
61
|
-
export async function planMacos(options = {}, cwd = process.cwd()) {
|
|
62
|
-
const root = resolve(cwd)
|
|
63
|
-
const original = new Map()
|
|
64
|
-
const read = async (name) => {
|
|
65
|
-
const text = await optional(await safe(root, name))
|
|
66
|
-
original.set(name, text)
|
|
67
|
-
return text
|
|
68
|
-
}
|
|
69
|
-
const pkg = JSON.parse(await read('package.json'))
|
|
70
|
-
const recorded = await read('mavis.config.json')
|
|
71
|
-
const prior = recorded ? migrateConfig(JSON.parse(recorded)) : {}
|
|
72
|
-
const manifests = [pkg]
|
|
73
|
-
for (const path of ['apps/web/package.json', 'apps/mobile/package.json']) {
|
|
74
|
-
const text = await read(path)
|
|
75
|
-
if (text) manifests.push(JSON.parse(text))
|
|
76
|
-
}
|
|
77
|
-
const dependencies = manifests.map((manifest) => ({
|
|
78
|
-
...manifest.devDependencies,
|
|
79
|
-
...manifest.dependencies,
|
|
80
|
-
}))
|
|
81
|
-
const web = dependencies.find((dep) => dep['@getcortexlabs/mavis-web'])
|
|
82
|
-
const native = dependencies.find((dep) => dep['@getcortexlabs/mavis'])
|
|
83
|
-
if (!web && !native)
|
|
84
|
-
throw new Error('--add-macos needs an existing Mavis Vue/Vite, Nuxt or NativeScript project.')
|
|
85
|
-
for (const dep of dependencies)
|
|
86
|
-
for (const name of [
|
|
87
|
-
'@getcortexlabs/mavis-core',
|
|
88
|
-
'@getcortexlabs/mavis-web',
|
|
89
|
-
'@getcortexlabs/mavis',
|
|
90
|
-
])
|
|
91
|
-
if (
|
|
92
|
-
dep[name] &&
|
|
93
|
-
![versions.mavis, `^${versions.mavis}`, `~${versions.mavis}`].includes(dep[name])
|
|
94
|
-
)
|
|
95
|
-
throw new Error(
|
|
96
|
-
`Align ${name} with this creator (${versions.mavis}) before adding Mac. No dependencies were changed.`,
|
|
97
|
-
)
|
|
98
|
-
const jolts = [
|
|
99
|
-
...new Set(
|
|
100
|
-
dependencies.flatMap((dep) =>
|
|
101
|
-
dep['@rafaelaugusto/jolt'] ? [dep['@rafaelaugusto/jolt']] : [],
|
|
102
|
-
),
|
|
103
|
-
),
|
|
104
|
-
]
|
|
105
|
-
const jolt = jolts[0] ?? prior.versions?.jolt
|
|
106
|
-
if (jolts.length > 1 || !exact(jolt) || jolt !== joltSwift.version)
|
|
107
|
-
throw new Error(
|
|
108
|
-
`Pin every existing Jolt dependency to ${joltSwift.version}, the SwiftUI version supported by this compiler. Current: ${jolts.join(', ') || jolt || 'missing'}.`,
|
|
109
|
-
)
|
|
110
|
-
const manager =
|
|
111
|
-
options.packageManager ??
|
|
112
|
-
prior.packageManager ??
|
|
113
|
-
pkg.packageManager?.split('@')[0] ??
|
|
114
|
-
detectPackageManager()
|
|
115
|
-
const commands = packageCommands(manager)
|
|
116
|
-
const knownRoots = options.roots ?? prior.portability?.roots
|
|
117
|
-
let roots = knownRoots
|
|
118
|
-
if (!roots) {
|
|
119
|
-
roots = []
|
|
120
|
-
for (const candidate of ['shared', 'src/shared', 'app/shared']) {
|
|
121
|
-
try {
|
|
122
|
-
if ((await lstat(await safe(root, candidate))).isDirectory()) roots.push(candidate)
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if (error.code !== 'ENOENT') throw error
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (roots.length !== 1)
|
|
128
|
-
throw new Error(
|
|
129
|
-
'Choose --shared-root path (or comma-separated roots) to select existing shared sources.',
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
const sources = await readShared(root, { roots })
|
|
133
|
-
for (const [name, text] of sources) original.set(name, text)
|
|
134
|
-
const migration = await directoryMigration({
|
|
135
|
-
root,
|
|
136
|
-
sources,
|
|
137
|
-
enabled: options.migrateDirectory,
|
|
138
|
-
appearance: prior.theme === 'midnight' ? 'dark' : 'light',
|
|
139
|
-
read,
|
|
140
|
-
hostPaths: [
|
|
141
|
-
...(web
|
|
142
|
-
? [
|
|
143
|
-
[
|
|
144
|
-
`${web === dependencies[0] ? '' : 'apps/web/'}${web.nuxt ? 'app/plugins/mavis.ts' : 'src/main.ts'}`,
|
|
145
|
-
web.nuxt ? 'nuxt/app/plugins/mavis.ts' : 'vite/src/main.ts',
|
|
146
|
-
],
|
|
147
|
-
]
|
|
148
|
-
: []),
|
|
149
|
-
...(native
|
|
150
|
-
? [[`${native === dependencies[0] ? '' : 'apps/mobile/'}src/app.ts`, 'mobile/src/app.ts']]
|
|
151
|
-
: []),
|
|
152
|
-
],
|
|
153
|
-
})
|
|
154
|
-
for (const [name, text] of migration.files) if (sources.has(name)) sources.set(name, text)
|
|
155
|
-
let entry = options.entry ?? prior.portability?.entry
|
|
156
|
-
if (!entry) {
|
|
157
|
-
const preferred =
|
|
158
|
-
prior.example === 'directory'
|
|
159
|
-
? 'Directory.vue'
|
|
160
|
-
: prior.example === 'tasks'
|
|
161
|
-
? 'Tasks.lite.tsx'
|
|
162
|
-
: 'Welcome.vue'
|
|
163
|
-
entry = [...sources.keys()].find((name) => name.endsWith('/' + preferred))
|
|
164
|
-
if (!entry)
|
|
165
|
-
throw new Error('Choose --entry path/to/Screen.vue (or .lite.tsx); no screen was changed.')
|
|
166
|
-
}
|
|
167
|
-
const settings = macAppSettings(
|
|
168
|
-
prior.macos,
|
|
169
|
-
pkg.name?.replace(/^@[^/]+\//, '') ?? prior.name ?? 'Mavis',
|
|
170
|
-
)
|
|
171
|
-
if (settings.icon) await readFile(await safe(root, settings.icon))
|
|
172
|
-
const host = web ? (web.nuxt ? 'nuxt' : 'vite') : null
|
|
173
|
-
if (
|
|
174
|
-
web &&
|
|
175
|
-
prior.rendering &&
|
|
176
|
-
!(host === 'nuxt' ? ['ssr', 'ssg'] : ['client']).includes(prior.rendering)
|
|
177
|
-
)
|
|
178
|
-
throw new Error('The recorded Web rendering mode does not match the existing host.')
|
|
179
|
-
const targets = [web && 'web', native && 'native', 'macos'].filter(Boolean)
|
|
180
|
-
const config = {
|
|
181
|
-
...prior,
|
|
182
|
-
schemaVersion: 2,
|
|
183
|
-
name: prior.name ?? pkg.name ?? 'mavis-app',
|
|
184
|
-
targets,
|
|
185
|
-
apps: {
|
|
186
|
-
...prior.apps,
|
|
187
|
-
...(web
|
|
188
|
-
? {
|
|
189
|
-
web: {
|
|
190
|
-
toolkit: 'mavis-web',
|
|
191
|
-
framework: 'vue',
|
|
192
|
-
host,
|
|
193
|
-
rendering: prior.rendering ?? (host === 'nuxt' ? 'ssr' : 'client'),
|
|
194
|
-
},
|
|
195
|
-
}
|
|
196
|
-
: {}),
|
|
197
|
-
...(native
|
|
198
|
-
? { native: { toolkit: 'nativescript', framework: 'vue', platforms: ['ios', 'android'] } }
|
|
199
|
-
: {}),
|
|
200
|
-
macos: { toolkit: 'swiftui', framework: null },
|
|
201
|
-
},
|
|
202
|
-
framework: 'vue',
|
|
203
|
-
authoring: prior.authoring ?? (String(entry).endsWith('.lite.tsx') ? 'mitosis' : 'vue'),
|
|
204
|
-
mode: 'portable',
|
|
205
|
-
execution: 'generated',
|
|
206
|
-
web: host,
|
|
207
|
-
rendering: web ? (prior.rendering ?? (host === 'nuxt' ? 'ssr' : 'client')) : null,
|
|
208
|
-
theme: prior.theme ?? 'mavis',
|
|
209
|
-
example: prior.example ?? 'welcome',
|
|
210
|
-
packageManager: manager,
|
|
211
|
-
versions: { ...prior.versions, mavis: versions.mavis, compiler: versions.mavis, jolt },
|
|
212
|
-
macos: settings,
|
|
213
|
-
portability: { ...prior.portability, roots, entry, generate: ['macos'], existing: true },
|
|
214
|
-
}
|
|
215
|
-
const assets = await readAssets(root, {
|
|
216
|
-
folder: config.portability.assets ?? `${config.portability.sourceRoot ?? roots[0]}/assets`,
|
|
217
|
-
})
|
|
218
|
-
// Preview proves source compilation before touching an existing project.
|
|
219
|
-
const compiled = await compileProject(sources, {
|
|
220
|
-
root: entry,
|
|
221
|
-
theme: config.theme,
|
|
222
|
-
assets,
|
|
223
|
-
sourceRoot: config.portability.sourceRoot ?? roots[0],
|
|
224
|
-
destinations: config.portability.destinations,
|
|
225
|
-
})
|
|
226
|
-
const metadataFile = 'apps/macos/mavis.host.json'
|
|
227
|
-
const metadata = await read(metadataFile)
|
|
228
|
-
if (metadata) {
|
|
229
|
-
const state = JSON.parse(metadata)
|
|
230
|
-
if (
|
|
231
|
-
state.generator !== 'create-mavis' ||
|
|
232
|
-
JSON.stringify(prior.portability?.roots) !== JSON.stringify(roots) ||
|
|
233
|
-
prior.portability?.entry !== entry
|
|
234
|
-
)
|
|
235
|
-
throw new Error(
|
|
236
|
-
'Mac is already configured with different source choices. Edit mavis.config.json explicitly; existing files were preserved.',
|
|
237
|
-
)
|
|
238
|
-
return {
|
|
239
|
-
root,
|
|
240
|
-
manager,
|
|
241
|
-
entry,
|
|
242
|
-
roots,
|
|
243
|
-
files: new Map(),
|
|
244
|
-
original,
|
|
245
|
-
config,
|
|
246
|
-
alreadyAdded: true,
|
|
247
|
-
components: compiled.model.components.length,
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
try {
|
|
251
|
-
await lstat(await safe(root, 'apps/macos'))
|
|
252
|
-
throw new Error('apps/macos already exists. Existing files were preserved.')
|
|
253
|
-
} catch (error) {
|
|
254
|
-
if (error.code !== 'ENOENT') throw error
|
|
255
|
-
}
|
|
256
|
-
const scripts = {
|
|
257
|
-
'generate:macos': 'node scripts/generate-macos.mjs',
|
|
258
|
-
macos: 'node scripts/macos.mjs run',
|
|
259
|
-
'build:macos': 'node scripts/macos.mjs build',
|
|
260
|
-
}
|
|
261
|
-
for (const [name, command] of Object.entries(scripts))
|
|
262
|
-
if (pkg.scripts?.[name] && pkg.scripts[name] !== command)
|
|
263
|
-
throw new Error(`Script conflict: ${name}. Existing scripts were preserved.`)
|
|
264
|
-
const files = new Map(migration.files)
|
|
265
|
-
const replace = (text) =>
|
|
266
|
-
text
|
|
267
|
-
.replaceAll('__MAVIS_NAME__', settings.name)
|
|
268
|
-
.replaceAll('__MAVIS_APPID__', 'app')
|
|
269
|
-
.replaceAll('__MAVIS_APPEARANCE__', config.theme === 'midnight' ? 'dark' : 'light')
|
|
270
|
-
.replaceAll('__MAVIS_MAC_MIN_WIDTH__', String(settings.minWidth))
|
|
271
|
-
.replaceAll('__MAVIS_MAC_DEFAULT_WIDTH__', String(Math.max(860, settings.minWidth)))
|
|
272
|
-
.replaceAll('__MAVIS_MAC_WIDTH__', '1120')
|
|
273
|
-
.replaceAll('__MAVIS_JOLT_SWIFT__', jolt)
|
|
274
|
-
await copy(files, 'macos/native', 'apps/macos', replace)
|
|
275
|
-
const appPath = 'apps/macos/Sources/MavisDesktop/App.swift'
|
|
276
|
-
let app = files
|
|
277
|
-
.get(appPath)
|
|
278
|
-
.replace(/WindowGroup\(".*"\)/, 'WindowGroup(MavisAppConfiguration.name)')
|
|
279
|
-
.replace(
|
|
280
|
-
'.frame(minWidth: ' + settings.minWidth + ', minHeight: 640)',
|
|
281
|
-
'.frame(minWidth: MavisAppConfiguration.minWidth, minHeight: MavisAppConfiguration.minHeight)',
|
|
282
|
-
)
|
|
283
|
-
const directory =
|
|
284
|
-
compiled.model.services.length === 1 &&
|
|
285
|
-
compiled.model.services[0].name === 'DirectoryStorage' &&
|
|
286
|
-
compiled.model.modules.some((module) =>
|
|
287
|
-
module.stores.some((store) => store.name === 'Directory'),
|
|
288
|
-
)
|
|
289
|
-
if (compiled.model.services.length && !directory)
|
|
290
|
-
throw new Error(
|
|
291
|
-
`The shared entry needs host services: ${compiled.model.services.map((service) => service.name).join(', ')}. Add their Swift implementations explicitly before generation; --add-macos cannot invent their behavior.`,
|
|
292
|
-
)
|
|
293
|
-
if (directory) {
|
|
294
|
-
await copy(files, 'directory/macos', 'apps/macos/Sources/MavisDesktop', replace)
|
|
295
|
-
app = app.replace(
|
|
296
|
-
'MavisEntry()',
|
|
297
|
-
'MavisEntry(services: MavisServices(directoryStorage: UserDefaultsDirectoryStorage()))',
|
|
298
|
-
)
|
|
299
|
-
if (!config.portability.startup)
|
|
300
|
-
config.portability.startup = [{ store: 'Directory', action: 'restore' }]
|
|
301
|
-
}
|
|
302
|
-
startupPlan(compiled.model, config.portability.startup)
|
|
303
|
-
files.set(appPath, app)
|
|
304
|
-
const wrapper = await readFile(new URL('macos/scripts/generate.mjs', templates), 'utf8')
|
|
305
|
-
files.set('scripts/generate-macos.mjs', wrapper)
|
|
306
|
-
const launcher = await readFile(new URL('macos/scripts/macos.mjs', templates), 'utf8')
|
|
307
|
-
files.set(
|
|
308
|
-
'scripts/macos-manifest.mjs',
|
|
309
|
-
await readFile(new URL('macos/scripts/macos-manifest.mjs', templates), 'utf8'),
|
|
310
|
-
)
|
|
311
|
-
files.set(
|
|
312
|
-
'scripts/macos.mjs',
|
|
313
|
-
replace(launcher).replace("['scripts/generate.mjs']", "['scripts/generate-macos.mjs']"),
|
|
314
|
-
)
|
|
315
|
-
files.set(
|
|
316
|
-
metadataFile,
|
|
317
|
-
json({ schemaVersion: 1, generator: 'create-mavis', compiler: versions.mavis }),
|
|
318
|
-
)
|
|
319
|
-
files.set(
|
|
320
|
-
'apps/macos/README.md',
|
|
321
|
-
`# ${settings.name} for Mac\n\nThis SwiftUI target reads existing shared sources (${roots.join(', ')}), starting at \`${entry}\`. Web and NativeScript sources, routes and build configuration remain in place.\n\n\`\`\`sh\n${commands.install}\n${commands.run('generate:macos')}\n${commands.run('build:macos')}\n${commands.run('macos')}\n\`\`\`\n\nThe compiler is a pinned package; update it with Mavis. \`mavis.config.json\` controls the source roots/entry and \`macos.name\`, \`bundleId\`, \`icon\` (.icns), \`minWidth\` and \`minHeight\`. Configure app-owned services in \`Sources/MavisDesktop/App.swift\`. ${directory ? 'Directory uses the same JSON array and mavis:directory key in UserDefaults; restore runs once after mounting each entry identity.' : ''}\n\nRequires macOS 14+ and Xcode. This builds an unsigned development app. Developer ID signing, provisioning and notarization are separate distribution steps; no credentials or signing settings are generated.\n`,
|
|
322
|
-
)
|
|
323
|
-
pkg.scripts = { ...pkg.scripts, ...scripts }
|
|
324
|
-
pkg.devDependencies = { ...pkg.devDependencies, '@getcortexlabs/mavis-compiler': versions.mavis }
|
|
325
|
-
files.set('package.json', json(pkg))
|
|
326
|
-
files.set('mavis.config.json', json(config))
|
|
327
|
-
for (const name of files.keys()) {
|
|
328
|
-
if (original.has(name)) continue
|
|
329
|
-
if ((await read(name)) !== undefined)
|
|
330
|
-
throw new Error(`File conflict: ${name}. Existing files were preserved.`)
|
|
331
|
-
}
|
|
332
|
-
return {
|
|
333
|
-
root,
|
|
334
|
-
manager,
|
|
335
|
-
entry,
|
|
336
|
-
roots,
|
|
337
|
-
files,
|
|
338
|
-
original,
|
|
339
|
-
config,
|
|
340
|
-
alreadyAdded: false,
|
|
341
|
-
components: compiled.model.components.length,
|
|
342
|
-
migration: migration.diffs,
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/** Optimistic transaction: refuse concurrent edits; roll back only bytes written by this plan. */
|
|
347
|
-
export async function applyMacos(plan, { signal } = {}) {
|
|
348
|
-
if (plan.alreadyAdded) return
|
|
349
|
-
const written = []
|
|
350
|
-
try {
|
|
351
|
-
for (const [name, expected] of plan.original) {
|
|
352
|
-
if ((await optional(await safe(plan.root, name))) !== expected)
|
|
353
|
-
throw new Error(`${name} changed after the preview. Run --add-macos again.`)
|
|
354
|
-
}
|
|
355
|
-
for (const [name, data] of plan.files) {
|
|
356
|
-
signal?.throwIfAborted()
|
|
357
|
-
const path = await safe(plan.root, name)
|
|
358
|
-
await mkdir(dirname(path), { recursive: true })
|
|
359
|
-
if (plan.original.get(name) === undefined) await writeFile(path, data, { flag: 'wx' })
|
|
360
|
-
else {
|
|
361
|
-
if ((await optional(path)) !== plan.original.get(name))
|
|
362
|
-
throw new Error(`${name} changed during creation.`)
|
|
363
|
-
const staging = `${path}.mavis-${process.pid}.tmp`
|
|
364
|
-
try {
|
|
365
|
-
await writeFile(staging, data, { flag: 'wx' })
|
|
366
|
-
await rename(staging, path)
|
|
367
|
-
} finally {
|
|
368
|
-
await rm(staging, { force: true })
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
written.push(name)
|
|
372
|
-
}
|
|
373
|
-
} catch (error) {
|
|
374
|
-
for (const name of written.reverse()) {
|
|
375
|
-
const path = join(plan.root, name)
|
|
376
|
-
const current = await readFile(path).catch(() => null)
|
|
377
|
-
if (!current?.equals(Buffer.from(plan.files.get(name)))) continue
|
|
378
|
-
const prior = plan.original.get(name)
|
|
379
|
-
if (prior === undefined) await rm(path)
|
|
380
|
-
else await writeFile(path, prior)
|
|
381
|
-
for (let folder = dirname(path); folder !== plan.root; folder = dirname(folder))
|
|
382
|
-
await rmdir(folder).catch(() => {})
|
|
383
|
-
}
|
|
384
|
-
throw error
|
|
385
|
-
}
|
|
386
|
-
}
|