nitro-ui-macos 0.0.0-stage → 0.0.1

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 (128) hide show
  1. package/CONTRIBUTING.md +56 -0
  2. package/LICENSE +21 -0
  3. package/PARITY.md +373 -0
  4. package/README.md +147 -2
  5. package/native/nitro-core/Package.swift +78 -0
  6. package/native/nitro-ui-core/Package.swift +112 -0
  7. package/native/nitro-ui-core/Sources/NitroUICoreMac/AnimationFrameDisplayLink.swift +127 -0
  8. package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridAnimationFrameScheduler.swift +91 -0
  9. package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridLinking.swift +18 -0
  10. package/native/nitro-ui-dev/Package.swift +102 -0
  11. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoad.swift +14 -0
  12. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoader.swift +85 -0
  13. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevLauncher.swift +192 -0
  14. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevMenu.swift +172 -0
  15. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevServerBrowser.swift +86 -0
  16. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevSession.swift +151 -0
  17. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevShortcuts.swift +85 -0
  18. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevToast.swift +85 -0
  19. package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevTools.swift +141 -0
  20. package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorModels.swift +97 -0
  21. package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorOverlay.swift +698 -0
  22. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevBundles.swift +64 -0
  23. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevErrors.swift +56 -0
  24. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevLoadingView.swift +27 -0
  25. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevMenu.swift +40 -0
  26. package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevToast.swift +19 -0
  27. package/native/nitro-ui-dev/Sources/NitroUIDevMac/LauncherWindowController.swift +217 -0
  28. package/native/nitro-ui-dev/Sources/NitroUIDevMac/LoadingOverlay.swift +104 -0
  29. package/native/nitro-ui-dev/Sources/NitroUIDevMac/RegisterDevLoader.swift +22 -0
  30. package/native/nitro-ui-dev/Sources/NitroUIDevMac/SavedBundles.swift +70 -0
  31. package/native/nitro-ui-glass/Package.swift +103 -0
  32. package/native/nitro-ui-glass/macos/HybridLiquidGlass.swift +5 -0
  33. package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassContainerView.swift +40 -0
  34. package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassView.swift +80 -0
  35. package/native/nitro-ui-glass/macos/LiquidGlassEffectView.swift +181 -0
  36. package/native/nitro-ui-glass/macos/LiquidGlassSupport.swift +17 -0
  37. package/native/nitro-ui-navigation/Package.swift +105 -0
  38. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationScreen.swift +199 -0
  39. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSharedElement.swift +17 -0
  40. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSplit.swift +889 -0
  41. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationStack.swift +404 -0
  42. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationTabs.swift +186 -0
  43. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/MacStackContainerController.swift +260 -0
  44. package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/NavigationSharedElementView.swift +28 -0
  45. package/native/nitro-ui-renderer/Package.swift +105 -0
  46. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/HybridAnimator.swift +502 -0
  47. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/NitroAnimationContext.swift +54 -0
  48. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/View+Animations.swift +35 -0
  49. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/AssetFonts.swift +36 -0
  50. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/FlippedView.swift +360 -0
  51. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridContainerView.swift +28 -0
  52. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridFonts.swift +7 -0
  53. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridLabel.swift +127 -0
  54. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridMaskedView.swift +185 -0
  55. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollView.swift +255 -0
  56. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollViewContent.swift +22 -0
  57. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridView.swift +18 -0
  58. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImage.swift +281 -0
  59. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageFactory.swift +132 -0
  60. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageLoader.swift +149 -0
  61. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageView.swift +601 -0
  62. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/ImagePixelSupport.swift +418 -0
  63. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/LabelView.swift +198 -0
  64. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/HybridListView.swift +177 -0
  65. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListCell.swift +98 -0
  66. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListContentView.swift +12 -0
  67. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListFenwickTree.swift +94 -0
  68. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListScrollView.swift +1100 -0
  69. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListSnapshot.swift +24 -0
  70. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListUpdate.swift +11 -0
  71. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListView.swift +260 -0
  72. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NativeContainerView.swift +443 -0
  73. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NitroViewProtocols.swift +275 -0
  74. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/ShadowLayers.swift +338 -0
  75. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/HybridTextInput.swift +252 -0
  76. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/NitroTextInputView.swift +447 -0
  77. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/View.swift +660 -0
  78. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/CustomViewController.swift +254 -0
  79. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/DesktopHostDelegate.swift +14 -0
  80. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Extensions.swift +102 -0
  81. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/GestureRecognizerDelegate.swift +24 -0
  82. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridGestureRecognizer.swift +41 -0
  83. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridLongPressGestureRecognizer.swift +172 -0
  84. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridPanGestureRecognizer.swift +193 -0
  85. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridTapGestureRecognizer.swift +165 -0
  86. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridAppearance.swift +75 -0
  87. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridApplication.swift +29 -0
  88. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridKeyboard.swift +26 -0
  89. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridScreen.swift +29 -0
  90. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridViewController.swift +232 -0
  91. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindow.swift +61 -0
  92. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindowScene.swift +17 -0
  93. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/LayoutNode.swift +73 -0
  94. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/NSColor+rgba.swift +29 -0
  95. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RegisterRootCallback.swift +27 -0
  96. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RuntimeReloadableAppDelegate.swift +7 -0
  97. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SafeAreaInsetsListeners.swift +26 -0
  98. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SizeListeners.swift +27 -0
  99. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/UIErrorHandler.swift +15 -0
  100. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/ViewController.swift +6 -0
  101. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Window.swift +156 -0
  102. package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/WindowScene.swift +23 -0
  103. package/native/nitro-ui-runtime/Package.swift +67 -0
  104. package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/DevLoader.swift +16 -0
  105. package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/NitroUIAppDelegate.swift +253 -0
  106. package/package.json +59 -4
  107. package/src/Platform.ts +43 -0
  108. package/src/bin.js +18 -0
  109. package/src/build.ts +453 -0
  110. package/src/bundleWorker.ts +80 -0
  111. package/src/cli.ts +157 -0
  112. package/src/config.ts +233 -0
  113. package/src/create.ts +67 -0
  114. package/src/files.ts +70 -0
  115. package/src/index.ts +1 -0
  116. package/src/init.ts +301 -0
  117. package/src/inlinePlatform.ts +140 -0
  118. package/src/modules.ts +385 -0
  119. package/src/packageApp.ts +103 -0
  120. package/src/packageDirectory.ts +61 -0
  121. package/src/preload.ts +40 -0
  122. package/src/prepare.ts +433 -0
  123. package/src/run.ts +41 -0
  124. package/src/runApp.ts +81 -0
  125. package/src/start.ts +152 -0
  126. package/src/toolchain.ts +83 -0
  127. package/src/versions.ts +103 -0
  128. package/templates/AppIcon.icns +0 -0
package/src/build.ts ADDED
@@ -0,0 +1,453 @@
1
+ import { chmod, copyFile, mkdir, mkdtemp, readFile, readdir, rm, stat } from 'node:fs/promises'
2
+ import { tmpdir } from 'node:os'
3
+ import { extname, join, resolve } from 'node:path'
4
+ import type { ResolvedMacOSConfig } from './config'
5
+ import { directoryExists, fileExists, isMissingFile, writeChanged } from './files'
6
+ import { packageDirectory, resolutionRoots } from './packageDirectory'
7
+ import { prepareMacOS } from './prepare'
8
+ import { run, runCapture } from './run'
9
+ import { verifyMacOSToolchain } from './toolchain'
10
+
11
+ export type BuildArch = 'arm64' | 'x86_64'
12
+ export type BuildConfiguration = 'debug' | 'release'
13
+
14
+ export interface BuildOptions {
15
+ root: string
16
+ release: boolean
17
+ arch?: BuildArch
18
+ jobs?: number
19
+ scratchPath?: string
20
+ clean?: boolean
21
+ signIdentity?: string
22
+ skipSign?: boolean
23
+ }
24
+
25
+ export interface BuildResult {
26
+ appBundlePath: string
27
+ executablePath: string
28
+ configuration: BuildConfiguration
29
+ arch: BuildArch
30
+ config: ResolvedMacOSConfig
31
+ }
32
+
33
+ export function defaultArch(): BuildArch {
34
+ return process.arch === 'x64' ? 'x86_64' : 'arm64'
35
+ }
36
+
37
+ export function parseArch(value: string | undefined): BuildArch {
38
+ if (value === undefined) return defaultArch()
39
+ if (value === 'arm64' || value === 'x86_64') return value
40
+ throw new Error(`Unsupported architecture "${value}". Use "arm64" or "x86_64".`)
41
+ }
42
+
43
+ export function parseJobs(value: string | undefined): number | undefined {
44
+ if (value === undefined) return undefined
45
+ const parsed = Number(value)
46
+ if (Number.isInteger(parsed) === false || parsed < 1) {
47
+ throw new Error(`Invalid --jobs value "${value}". Expected a positive integer.`)
48
+ }
49
+ return parsed
50
+ }
51
+
52
+ async function compileStaticFrameworkIncremental(options: {
53
+ root: string
54
+ frameworkSource: string
55
+ objectFile: string
56
+ flagsStampPath: string
57
+ arch: BuildArch
58
+ minimumMacOS: string
59
+ nativeDirectory: string
60
+ }): Promise<string> {
61
+ const { root, frameworkSource, objectFile, flagsStampPath, arch, minimumMacOS, nativeDirectory } = options
62
+ const hermesGeneratedInclude = join(nativeDirectory, 'nitro-hermes/Generated/include')
63
+ const hermesInclude = join(nativeDirectory, 'nitro-hermes/hermes/include')
64
+ const runtimeCxxInclude = join(nativeDirectory, 'nitro-ui-runtime/Sources/NitroUIRuntimeCxx/include')
65
+
66
+ const command = [
67
+ 'xcrun',
68
+ 'clang',
69
+ '-c',
70
+ '-O3',
71
+ '-w',
72
+ '-arch',
73
+ arch,
74
+ `-mmacosx-version-min=${minimumMacOS}`,
75
+ '-fno-modules',
76
+ '-DSTATIC_HERMES',
77
+ '-DNDEBUG',
78
+ '-fno-strict-aliasing',
79
+ '-fno-strict-overflow',
80
+ '-I',
81
+ hermesGeneratedInclude,
82
+ '-I',
83
+ hermesInclude,
84
+ '-I',
85
+ runtimeCxxInclude,
86
+ '-o',
87
+ objectFile,
88
+ frameworkSource,
89
+ ]
90
+
91
+ const flagsSignature = JSON.stringify({ arch: arch, minimumMacOS: minimumMacOS, includes: [hermesGeneratedInclude, hermesInclude, runtimeCxxInclude] })
92
+ let upToDate = false
93
+ try {
94
+ const [srcStat, objStat, prevFlags] = await Promise.all([
95
+ stat(frameworkSource),
96
+ stat(objectFile),
97
+ readFile(flagsStampPath, 'utf8'),
98
+ ])
99
+ if (objStat.mtimeMs >= srcStat.mtimeMs && prevFlags === flagsSignature) {
100
+ upToDate = true
101
+ }
102
+ } catch (error) {
103
+ if (isMissingFile(error) === false) throw error
104
+ }
105
+
106
+ if (upToDate === false) {
107
+ await run(command, { cwd: root })
108
+ await writeChanged(flagsStampPath, flagsSignature)
109
+ }
110
+ return objectFile
111
+ }
112
+
113
+ async function compileAssetCatalogIfNonEmpty(options: {
114
+ root: string
115
+ assetCatalogPath: string
116
+ resourcesDir: string
117
+ minimumMacOS: string
118
+ }): Promise<void> {
119
+ const { root, assetCatalogPath, resourcesDir, minimumMacOS } = options
120
+ if ((await directoryExists(assetCatalogPath)) === false) return
121
+ const entries = await readdir(assetCatalogPath)
122
+ const hasAssets = entries.some((entry) => entry.endsWith('.imageset') || entry.endsWith('.dataset'))
123
+ if (hasAssets === false) return
124
+ await run(
125
+ [
126
+ 'xcrun',
127
+ 'actool',
128
+ '--compile',
129
+ resourcesDir,
130
+ '--platform',
131
+ 'macosx',
132
+ '--minimum-deployment-target',
133
+ minimumMacOS,
134
+ assetCatalogPath,
135
+ ],
136
+ { cwd: root },
137
+ )
138
+ }
139
+
140
+ async function installAppIcon(options: {
141
+ root: string
142
+ config: ResolvedMacOSConfig
143
+ resourcesDir: string
144
+ }): Promise<boolean> {
145
+ const { root, config, resourcesDir } = options
146
+ let iconSource: string | undefined
147
+ if (config.icon !== undefined) {
148
+ iconSource = resolve(root, config.icon)
149
+ if ((await fileExists(iconSource)) === false && (await directoryExists(iconSource)) === false) {
150
+ throw new Error(`Configured macOS icon does not exist: ${iconSource}`)
151
+ }
152
+ } else {
153
+ const defaultIcon = join(root, 'macos/AppIcon.icns')
154
+ if (await fileExists(defaultIcon)) {
155
+ iconSource = defaultIcon
156
+ }
157
+ }
158
+
159
+ if (iconSource === undefined) return false
160
+
161
+ const icnsDestination = join(resourcesDir, 'AppIcon.icns')
162
+ const ext = extname(iconSource).toLowerCase()
163
+ if (ext === '.icns') {
164
+ await copyFile(iconSource, icnsDestination)
165
+ return true
166
+ }
167
+ if (ext === '.iconset' && (await directoryExists(iconSource))) {
168
+ await run(['iconutil', '-c', 'icns', iconSource, '-o', icnsDestination], { cwd: root })
169
+ return true
170
+ }
171
+ if (ext === '.png') {
172
+ const tempDir = await mkdtemp(join(tmpdir(), 'nitro-macos-icon-'))
173
+ try {
174
+ const iconsetDir = join(tempDir, 'AppIcon.iconset')
175
+ await mkdir(iconsetDir, { recursive: true })
176
+ const sizes: { name: string; pixels: number }[] = [
177
+ { name: 'icon_16x16.png', pixels: 16 },
178
+ { name: 'icon_16x16@2x.png', pixels: 32 },
179
+ { name: 'icon_32x32.png', pixels: 32 },
180
+ { name: 'icon_32x32@2x.png', pixels: 64 },
181
+ { name: 'icon_128x128.png', pixels: 128 },
182
+ { name: 'icon_128x128@2x.png', pixels: 256 },
183
+ { name: 'icon_256x256.png', pixels: 256 },
184
+ { name: 'icon_256x256@2x.png', pixels: 512 },
185
+ { name: 'icon_512x512.png', pixels: 512 },
186
+ { name: 'icon_512x512@2x.png', pixels: 1024 },
187
+ ]
188
+ for (const size of sizes) {
189
+ const out = join(iconsetDir, size.name)
190
+ await run(['sips', '-z', String(size.pixels), String(size.pixels), iconSource, '--out', out], { cwd: root })
191
+ }
192
+ await run(['iconutil', '-c', 'icns', iconsetDir, '-o', icnsDestination], { cwd: root })
193
+ } finally {
194
+ await rm(tempDir, { recursive: true, force: true })
195
+ }
196
+ return true
197
+ }
198
+ throw new Error(`Unsupported icon format "${iconSource}". Provide a .icns, .iconset directory, or .png file.`)
199
+ }
200
+
201
+ async function setPlistString(plistPath: string, key: string, value: string, cwd: string): Promise<void> {
202
+ const result = await runCapture(['plutil', '-replace', key, '-string', value, plistPath], { cwd: cwd })
203
+ if (result.exitCode !== 0) {
204
+ const details = result.stderr.trim() || result.stdout.trim()
205
+ throw new Error(`plutil failed setting ${key}: ${details}`)
206
+ }
207
+ }
208
+
209
+ async function syncInfoPlist(options: {
210
+ root: string
211
+ config: ResolvedMacOSConfig
212
+ plistDestination: string
213
+ hasIcon: boolean
214
+ }): Promise<void> {
215
+ const { root, config, plistDestination, hasIcon } = options
216
+ const sourcePlist = resolve(root, config.infoPlist)
217
+ if (await fileExists(sourcePlist)) {
218
+ await copyFile(sourcePlist, plistDestination)
219
+ } else {
220
+ const generated = `<?xml version="1.0" encoding="UTF-8"?>
221
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
222
+ <plist version="1.0">
223
+ <dict>
224
+ <key>CFBundleDevelopmentRegion</key>
225
+ <string>en</string>
226
+ <key>CFBundleInfoDictionaryVersion</key>
227
+ <string>6.0</string>
228
+ <key>CFBundlePackageType</key>
229
+ <string>APPL</string>
230
+ <key>NSHighResolutionCapable</key>
231
+ <true/>
232
+ <key>NSPrincipalClass</key>
233
+ <string>NSApplication</string>
234
+ </dict>
235
+ </plist>
236
+ `
237
+ await writeChanged(plistDestination, generated)
238
+ }
239
+
240
+ await setPlistString(plistDestination, 'CFBundleName', config.name, root)
241
+ await setPlistString(plistDestination, 'CFBundleDisplayName', config.name, root)
242
+ await setPlistString(plistDestination, 'CFBundleExecutable', config.product, root)
243
+ await setPlistString(plistDestination, 'CFBundleIdentifier', config.bundleId, root)
244
+ await setPlistString(plistDestination, 'CFBundleShortVersionString', config.version, root)
245
+ await setPlistString(plistDestination, 'CFBundleVersion', config.buildNumber, root)
246
+ await setPlistString(plistDestination, 'LSMinimumSystemVersion', config.minimumMacOS, root)
247
+ if (hasIcon) {
248
+ await setPlistString(plistDestination, 'CFBundleIconFile', 'AppIcon', root)
249
+ }
250
+ }
251
+
252
+ /** Stamps the active macOS SDK version onto the binary so AppKit uses its current appearance (e.g. Liquid Glass). */
253
+ async function stampBuildSdk(options: {
254
+ root: string
255
+ binary: string
256
+ minimumMacOS: string
257
+ sdkVersion: string
258
+ }): Promise<void> {
259
+ const { root, binary, minimumMacOS, sdkVersion } = options
260
+ await run(
261
+ ['xcrun', 'vtool', '-set-build-version', 'macos', minimumMacOS, sdkVersion, '-replace', '-output', binary, binary],
262
+ { cwd: root },
263
+ )
264
+ }
265
+
266
+ export async function signAppBundle(options: {
267
+ root: string
268
+ appBundlePath: string
269
+ identity?: string
270
+ entitlementsPath?: string
271
+ }): Promise<void> {
272
+ const { root, appBundlePath, identity, entitlementsPath } = options
273
+ const args = ['codesign', '--force', '--deep']
274
+ if (identity !== undefined) {
275
+ args.push('--options', 'runtime', '--timestamp')
276
+ }
277
+ if (entitlementsPath !== undefined && (await fileExists(entitlementsPath))) {
278
+ args.push('--entitlements', entitlementsPath)
279
+ }
280
+ args.push('--sign', identity ?? '-', appBundlePath)
281
+ await run(args, { cwd: root })
282
+ if (identity !== undefined) {
283
+ await run(['codesign', '--verify', '--deep', '--strict', appBundlePath], { cwd: root })
284
+ }
285
+ }
286
+
287
+ export async function buildMacOS(options: BuildOptions): Promise<BuildResult> {
288
+ const { root, release } = options
289
+ const configuration: BuildConfiguration = release ? 'release' : 'debug'
290
+ const arch = options.arch ?? defaultArch()
291
+
292
+ const toolchain = await verifyMacOSToolchain(root)
293
+ const prepared = await prepareMacOS(root, { clean: options.clean, includeDev: release === false })
294
+ const { config, nativeDirectory } = prepared
295
+
296
+ const macosDir = join(root, 'macos')
297
+ const stageDir = join(root, '.nitro/macos')
298
+ const scratchDir = options.scratchPath !== undefined ? resolve(root, options.scratchPath) : join(stageDir, 'build')
299
+ const bundleDir = join(stageDir, 'bundle', configuration)
300
+ await mkdir(bundleDir, { recursive: true })
301
+
302
+ const bundlerDir = packageDirectory('nitro-ui-bundler', resolutionRoots(root))
303
+ const preloadPath = resolve(import.meta.dir, 'preload.ts')
304
+ const workerPath = resolve(import.meta.dir, 'bundleWorker.ts')
305
+ const entryPath = resolve(root, config.entry)
306
+ const assetCatalogPath = join(bundleDir, 'NitroUIImages.xcassets')
307
+
308
+ const bundleResourceName = release ? 'main.hbc' : 'main.js'
309
+ const bundleFile = join(bundleDir, bundleResourceName)
310
+ const frameworkSource = release ? join(bundleDir, 'NitroUIFramework.c') : undefined
311
+
312
+ const workerArgs = [
313
+ process.execPath,
314
+ '--preload',
315
+ preloadPath,
316
+ workerPath,
317
+ '--bundler',
318
+ bundlerDir,
319
+ '--mode',
320
+ configuration,
321
+ '--entry',
322
+ entryPath,
323
+ '--output',
324
+ bundleFile,
325
+ '--asset-catalog',
326
+ assetCatalogPath,
327
+ '--react-compiler',
328
+ String(config.reactCompiler),
329
+ ]
330
+ if (frameworkSource !== undefined) {
331
+ workerArgs.push('--framework-source', frameworkSource)
332
+ }
333
+
334
+ await run(workerArgs, {
335
+ cwd: root,
336
+ env: {
337
+ ...process.env,
338
+ NITRO_UI_MACOS_BUNDLER_INLINE_PLATFORM: join(bundlerDir, 'src/inlinePlatform.ts'),
339
+ },
340
+ })
341
+
342
+ const swiftBaseArgs = [
343
+ 'swift',
344
+ 'build',
345
+ '-c',
346
+ configuration,
347
+ '--arch',
348
+ arch,
349
+ '--package-path',
350
+ macosDir,
351
+ '--scratch-path',
352
+ scratchDir,
353
+ ]
354
+
355
+ const swiftBuildArgs = [...swiftBaseArgs]
356
+ if (options.jobs !== undefined) {
357
+ swiftBuildArgs.push('-j', String(options.jobs))
358
+ }
359
+ swiftBuildArgs.push('--product', config.product)
360
+ if (frameworkSource !== undefined) {
361
+ const objectFile = await compileStaticFrameworkIncremental({
362
+ root: root,
363
+ frameworkSource: frameworkSource,
364
+ objectFile: join(bundleDir, `NitroUIFramework-${arch}.o`),
365
+ flagsStampPath: join(bundleDir, `NitroUIFramework-${arch}.flags`),
366
+ arch: arch,
367
+ minimumMacOS: config.minimumMacOS,
368
+ nativeDirectory: nativeDirectory,
369
+ })
370
+ swiftBuildArgs.push('-Xlinker', objectFile, '-Xlinker', '-dead_strip')
371
+ }
372
+
373
+ try {
374
+ await run(swiftBuildArgs, { cwd: root })
375
+ } catch {
376
+ throw new Error('macOS native build failed. See the Swift compiler diagnostics above.')
377
+ }
378
+
379
+ const binPathResult = await runCapture([...swiftBaseArgs, '--show-bin-path'], { cwd: root })
380
+ if (binPathResult.exitCode !== 0 || binPathResult.stdout.trim() === '') {
381
+ throw new Error(`Could not determine Swift build output directory: ${binPathResult.stderr.trim()}`)
382
+ }
383
+ const binarySource = join(binPathResult.stdout.trim(), config.product)
384
+ if ((await fileExists(binarySource)) === false) {
385
+ throw new Error(`Expected built executable at ${binarySource}, but it was not found.`)
386
+ }
387
+
388
+ const outputDir = join(macosDir, 'build', configuration)
389
+ const appBundlePath = join(outputDir, `${config.name}.app`)
390
+ const contentsDir = join(appBundlePath, 'Contents')
391
+ const macOSBinDir = join(contentsDir, 'MacOS')
392
+ const resourcesDir = join(contentsDir, 'Resources')
393
+
394
+ await rm(appBundlePath, { recursive: true, force: true })
395
+ await mkdir(macOSBinDir, { recursive: true })
396
+ await mkdir(resourcesDir, { recursive: true })
397
+
398
+ const executablePath = join(macOSBinDir, config.product)
399
+ await copyFile(binarySource, executablePath)
400
+ await stampBuildSdk({
401
+ root: root,
402
+ binary: executablePath,
403
+ minimumMacOS: config.minimumMacOS,
404
+ sdkVersion: toolchain.sdkVersion,
405
+ })
406
+ if (release) {
407
+ // The unstripped executable stays in the SwiftPM build directory for symbolicating crashes.
408
+ await run(['xcrun', 'strip', '-rSTx', executablePath], { cwd: root })
409
+ }
410
+ await chmod(executablePath, 0o755)
411
+
412
+ await copyFile(bundleFile, join(resourcesDir, bundleResourceName))
413
+ const hasIcon = await installAppIcon({ root: root, config: config, resourcesDir: resourcesDir })
414
+ await syncInfoPlist({
415
+ root: root,
416
+ config: config,
417
+ plistDestination: join(contentsDir, 'Info.plist'),
418
+ hasIcon: hasIcon,
419
+ })
420
+ await compileAssetCatalogIfNonEmpty({
421
+ root: root,
422
+ assetCatalogPath: assetCatalogPath,
423
+ resourcesDir: resourcesDir,
424
+ minimumMacOS: config.minimumMacOS,
425
+ })
426
+
427
+ if (options.skipSign !== true) {
428
+ let entitlementsPath: string | undefined
429
+ if (config.entitlements !== undefined) {
430
+ entitlementsPath = resolve(root, config.entitlements)
431
+ } else {
432
+ const defaultEntitlements = join(root, 'macos/Entitlements.plist')
433
+ if (await fileExists(defaultEntitlements)) {
434
+ entitlementsPath = defaultEntitlements
435
+ }
436
+ }
437
+ await signAppBundle({
438
+ root: root,
439
+ appBundlePath: appBundlePath,
440
+ identity: options.signIdentity,
441
+ entitlementsPath: entitlementsPath,
442
+ })
443
+ }
444
+
445
+ console.log(`Built ${appBundlePath} (${configuration}, ${arch})`)
446
+ return {
447
+ appBundlePath: appBundlePath,
448
+ executablePath: executablePath,
449
+ configuration: configuration,
450
+ arch: arch,
451
+ config: config,
452
+ }
453
+ }
@@ -0,0 +1,80 @@
1
+ import { join } from 'node:path'
2
+ import { parseArgs } from 'node:util'
3
+ import { z } from 'zod'
4
+
5
+ const bundlerModuleSchema = z.object({
6
+ bundle: z.function({
7
+ input: z.tuple([
8
+ z.string(),
9
+ z.string(),
10
+ z.object({
11
+ mode: z.enum(['development', 'production']),
12
+ platform: z.enum(['ios', 'android']),
13
+ assetCatalog: z.string(),
14
+ reactCompiler: z.boolean(),
15
+ }),
16
+ ]),
17
+ output: z.unknown(),
18
+ }),
19
+ })
20
+
21
+ const releaseModuleSchema = z.object({
22
+ bundleStaticFramework: z.function({
23
+ input: z.tuple([
24
+ z.string(),
25
+ z.string(),
26
+ z.string(),
27
+ z.string(),
28
+ z.enum(['ios', 'android']),
29
+ z.boolean(),
30
+ ]),
31
+ output: z.unknown(),
32
+ }),
33
+ })
34
+
35
+ const { values } = parseArgs({
36
+ args: process.argv.slice(2),
37
+ options: {
38
+ bundler: { type: 'string' },
39
+ mode: { type: 'string' },
40
+ entry: { type: 'string' },
41
+ output: { type: 'string' },
42
+ 'asset-catalog': { type: 'string' },
43
+ 'framework-source': { type: 'string' },
44
+ 'react-compiler': { type: 'string' },
45
+ },
46
+ })
47
+
48
+ const bundlerDir = values.bundler
49
+ const mode = values.mode
50
+ const entry = values.entry
51
+ const output = values.output
52
+ const assetCatalog = values['asset-catalog']
53
+ const frameworkSource = values['framework-source']
54
+ const reactCompiler = values['react-compiler'] !== 'false'
55
+
56
+ if (bundlerDir === undefined || mode === undefined || entry === undefined || output === undefined || assetCatalog === undefined) {
57
+ throw new Error('bundleWorker requires --bundler, --mode, --entry, --output, and --asset-catalog.')
58
+ }
59
+
60
+ if (mode === 'release') {
61
+ if (frameworkSource === undefined) {
62
+ throw new Error('bundleWorker in release mode requires --framework-source.')
63
+ }
64
+ const releaseEntry = join(bundlerDir, 'src/release.ts')
65
+ const imported: unknown = await import(releaseEntry)
66
+ const releaseApi = releaseModuleSchema.parse(imported)
67
+ await releaseApi.bundleStaticFramework(entry, output, frameworkSource, assetCatalog, 'ios', reactCompiler)
68
+ } else if (mode === 'debug') {
69
+ const bundleEntry = join(bundlerDir, 'src/bundle.ts')
70
+ const imported: unknown = await import(bundleEntry)
71
+ const bundleApi = bundlerModuleSchema.parse(imported)
72
+ await bundleApi.bundle(entry, output, {
73
+ mode: 'development',
74
+ platform: 'ios',
75
+ assetCatalog: assetCatalog,
76
+ reactCompiler: reactCompiler,
77
+ })
78
+ } else {
79
+ throw new Error(`Unsupported bundleWorker mode: ${mode}`)
80
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env bun
2
+ import { resolve } from 'node:path'
3
+ import { parseArgs } from 'node:util'
4
+ import { parseArch, parseJobs } from './build'
5
+
6
+ const usage = `Usage: nitro-ui-macos <command> [options]
7
+
8
+ Commands:
9
+ create <AppName> [--no-install] [--package <spec>]
10
+ Create a new NitroUI ${'0.3.0'} app initialized for macOS.
11
+ init [--name <Name>] [--bundle-id <id>]
12
+ Add a macos/ project to an existing NitroUI app (never overwrites existing files).
13
+ prepare [--clean]
14
+ Verify NitroUI/nitro-core versions and stage .nitro/macos native packages and autolinking.
15
+ start [--port <port>]
16
+ Start the NitroUI dev server with the macOS platform transform.
17
+ build [--release] [--arch arm64|x86_64] [--jobs <n>] [--scratch-path <dir>] [--clean]
18
+ Bundle JS/assets and build macos/build/<config>/<Name>.app.
19
+ run [--release] [--arch arm64|x86_64] [--jobs <n>] [--scratch-path <dir>] [--skip-build] [--server <url>] [--no-dev-server] [-- <app args...>]
20
+ Build (unless --skip-build) and launch the macOS app.
21
+ package [--arch arm64|x86_64] [--jobs <n>] [--scratch-path <dir>] [--sign <identity>] [--notarize <keychain-profile>] [--output <path.dmg>] [--no-dmg]
22
+ Build a Release .app and .dmg (ad-hoc signed by default; hardened runtime with --sign).
23
+
24
+ Global options:
25
+ --root <directory> Run against a specific app directory instead of the current directory.
26
+ --help, -h Show this help message.
27
+ `
28
+
29
+ try {
30
+ const rawArgs = process.argv.slice(2)
31
+ const separatorIndex = rawArgs.indexOf('--')
32
+ const cliArgs = separatorIndex === -1 ? rawArgs : rawArgs.slice(0, separatorIndex)
33
+ const passthroughArgs = separatorIndex === -1 ? [] : rawArgs.slice(separatorIndex + 1)
34
+
35
+ const { values, positionals } = parseArgs({
36
+ args: cliArgs,
37
+ allowPositionals: true,
38
+ options: {
39
+ root: { type: 'string' },
40
+ name: { type: 'string' },
41
+ 'bundle-id': { type: 'string' },
42
+ clean: { type: 'boolean', default: false },
43
+ release: { type: 'boolean', default: false },
44
+ arch: { type: 'string' },
45
+ jobs: { type: 'string', short: 'j' },
46
+ 'scratch-path': { type: 'string' },
47
+ 'skip-build': { type: 'boolean', default: false },
48
+ server: { type: 'string' },
49
+ 'no-dev-server': { type: 'boolean', default: false },
50
+ port: { type: 'string' },
51
+ sign: { type: 'string' },
52
+ notarize: { type: 'string' },
53
+ output: { type: 'string' },
54
+ 'no-dmg': { type: 'boolean', default: false },
55
+ 'no-install': { type: 'boolean', default: false },
56
+ package: { type: 'string' },
57
+ help: { type: 'boolean', short: 'h', default: false },
58
+ },
59
+ })
60
+
61
+ const root = resolve(values.root ?? process.cwd())
62
+ const [command, target] = positionals
63
+
64
+ if (values.help || command === undefined) {
65
+ console.log(usage)
66
+ } else {
67
+ switch (command) {
68
+ case 'init': {
69
+ const { initMacOS } = await import('./init')
70
+ await initMacOS({ root: root, name: values.name, bundleId: values['bundle-id'] })
71
+ break
72
+ }
73
+ case 'prepare': {
74
+ const { prepareMacOS } = await import('./prepare')
75
+ await prepareMacOS(root, { clean: values.clean })
76
+ break
77
+ }
78
+ case 'start': {
79
+ const { startMacOSDevServer } = await import('./start')
80
+ let port: number | undefined
81
+ if (values.port !== undefined) {
82
+ port = Number(values.port)
83
+ if (Number.isInteger(port) === false || port < 1 || port > 65535) {
84
+ throw new Error(`Invalid port "${values.port}". Expected an integer between 1 and 65535.`)
85
+ }
86
+ }
87
+ await startMacOSDevServer({ root: root, port: port })
88
+ break
89
+ }
90
+ case 'build': {
91
+ const { buildMacOS } = await import('./build')
92
+ const arch = parseArch(values.arch)
93
+ const jobs = parseJobs(values.jobs)
94
+ await buildMacOS({
95
+ root: root,
96
+ release: values.release,
97
+ arch: arch,
98
+ jobs: jobs,
99
+ scratchPath: values['scratch-path'],
100
+ clean: values.clean,
101
+ })
102
+ break
103
+ }
104
+ case 'run': {
105
+ const { runMacOS } = await import('./runApp')
106
+ const arch = parseArch(values.arch)
107
+ const jobs = parseJobs(values.jobs)
108
+ await runMacOS({
109
+ root: root,
110
+ release: values.release,
111
+ arch: arch,
112
+ jobs: jobs,
113
+ scratchPath: values['scratch-path'],
114
+ skipBuild: values['skip-build'],
115
+ serverURL: values.server,
116
+ noDevServer: values['no-dev-server'],
117
+ appArgs: passthroughArgs,
118
+ })
119
+ break
120
+ }
121
+ case 'package': {
122
+ const { packageMacOS } = await import('./packageApp')
123
+ const arch = parseArch(values.arch)
124
+ const jobs = parseJobs(values.jobs)
125
+ await packageMacOS({
126
+ root: root,
127
+ arch: arch,
128
+ jobs: jobs,
129
+ scratchPath: values['scratch-path'],
130
+ signIdentity: values.sign,
131
+ notarizeProfile: values.notarize,
132
+ output: values.output,
133
+ noDmg: values['no-dmg'],
134
+ })
135
+ break
136
+ }
137
+ case 'create': {
138
+ if (target === undefined) {
139
+ throw new Error('Specify a project name or directory, for example: bunx nitro-ui-macos create MyApp')
140
+ }
141
+ const { createMacOSApp } = await import('./create')
142
+ await createMacOSApp({
143
+ destination: target,
144
+ noInstall: values['no-install'],
145
+ macosPackageSpec: values.package,
146
+ })
147
+ break
148
+ }
149
+ default:
150
+ throw new Error(`Unknown command "${command}". Run \`nitro-ui-macos --help\` for available commands.`)
151
+ }
152
+ }
153
+ } catch (error) {
154
+ const message = error instanceof Error ? error.message : String(error)
155
+ console.error(message)
156
+ process.exitCode = 1
157
+ }