nitro-ui-macos 0.0.0 → 0.0.2
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/CONTRIBUTING.md +49 -0
- package/LICENSE +4 -3
- package/PARITY.md +373 -0
- package/README.md +144 -5
- package/native/nitro-core/Package.swift +78 -0
- package/native/nitro-ui-core/Package.swift +112 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/AnimationFrameDisplayLink.swift +127 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridAnimationFrameScheduler.swift +91 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridLinking.swift +18 -0
- package/native/nitro-ui-dev/Package.swift +102 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoad.swift +14 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoader.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevLauncher.swift +192 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevMenu.swift +172 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevServerBrowser.swift +86 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevSession.swift +151 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevShortcuts.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevToast.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevTools.swift +141 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorModels.swift +97 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorOverlay.swift +698 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevBundles.swift +64 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevErrors.swift +56 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevLoadingView.swift +27 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevMenu.swift +40 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevToast.swift +19 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LauncherWindowController.swift +217 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LoadingOverlay.swift +104 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/RegisterDevLoader.swift +22 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/SavedBundles.swift +70 -0
- package/native/nitro-ui-glass/Package.swift +103 -0
- package/native/nitro-ui-glass/macos/HybridLiquidGlass.swift +5 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassContainerView.swift +40 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassView.swift +80 -0
- package/native/nitro-ui-glass/macos/LiquidGlassEffectView.swift +181 -0
- package/native/nitro-ui-glass/macos/LiquidGlassSupport.swift +17 -0
- package/native/nitro-ui-navigation/Package.swift +105 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationScreen.swift +199 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSharedElement.swift +17 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSplit.swift +889 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationStack.swift +404 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationTabs.swift +186 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/MacStackContainerController.swift +260 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/NavigationSharedElementView.swift +28 -0
- package/native/nitro-ui-renderer/Package.swift +105 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/HybridAnimator.swift +502 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/NitroAnimationContext.swift +54 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/View+Animations.swift +35 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/AssetFonts.swift +36 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/FlippedView.swift +360 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridContainerView.swift +28 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridFonts.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridLabel.swift +127 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridMaskedView.swift +185 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollView.swift +255 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollViewContent.swift +22 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridView.swift +18 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImage.swift +281 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageFactory.swift +132 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageLoader.swift +149 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageView.swift +601 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/ImagePixelSupport.swift +418 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/LabelView.swift +198 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/HybridListView.swift +177 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListCell.swift +98 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListContentView.swift +12 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListFenwickTree.swift +94 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListScrollView.swift +1100 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListSnapshot.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListUpdate.swift +11 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListView.swift +260 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NativeContainerView.swift +443 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NitroViewProtocols.swift +275 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/ShadowLayers.swift +338 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/HybridTextInput.swift +252 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/NitroTextInputView.swift +447 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/View.swift +660 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/CustomViewController.swift +254 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/DesktopHostDelegate.swift +14 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Extensions.swift +102 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/GestureRecognizerDelegate.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridGestureRecognizer.swift +41 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridLongPressGestureRecognizer.swift +172 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridPanGestureRecognizer.swift +193 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridTapGestureRecognizer.swift +165 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridAppearance.swift +75 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridApplication.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridKeyboard.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridScreen.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridViewController.swift +232 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindow.swift +61 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindowScene.swift +17 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/LayoutNode.swift +73 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/NSColor+rgba.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RegisterRootCallback.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RuntimeReloadableAppDelegate.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SafeAreaInsetsListeners.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SizeListeners.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/UIErrorHandler.swift +15 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/ViewController.swift +6 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Window.swift +156 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/WindowScene.swift +23 -0
- package/native/nitro-ui-runtime/Package.swift +67 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/DevLoader.swift +16 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/NitroUIAppDelegate.swift +253 -0
- package/package.json +59 -8
- package/src/Platform.ts +43 -0
- package/src/bin.js +18 -0
- package/src/build.ts +453 -0
- package/src/bundleWorker.ts +80 -0
- package/src/cli.ts +157 -0
- package/src/config.ts +233 -0
- package/src/create.ts +67 -0
- package/src/files.ts +70 -0
- package/src/index.ts +1 -0
- package/src/init.ts +301 -0
- package/src/inlinePlatform.ts +140 -0
- package/src/modules.ts +385 -0
- package/src/packageApp.ts +103 -0
- package/src/packageDirectory.ts +61 -0
- package/src/preload.ts +40 -0
- package/src/prepare.ts +433 -0
- package/src/run.ts +41 -0
- package/src/runApp.ts +81 -0
- package/src/start.ts +152 -0
- package/src/toolchain.ts +83 -0
- package/src/versions.ts +103 -0
- package/templates/AppIcon.icns +0 -0
package/src/config.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import { isMissingFile } from './files'
|
|
5
|
+
|
|
6
|
+
export function escapeSwiftString(value: string): string {
|
|
7
|
+
return value
|
|
8
|
+
.replaceAll('\\', '\\\\')
|
|
9
|
+
.replaceAll('"', '\\"')
|
|
10
|
+
.replaceAll('\r', '\\r')
|
|
11
|
+
.replaceAll('\n', '\\n')
|
|
12
|
+
.replaceAll('\t', '\\t')
|
|
13
|
+
.replaceAll('\0', '\\0')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function escapeXml(value: string): string {
|
|
17
|
+
return value
|
|
18
|
+
.replaceAll('&', '&')
|
|
19
|
+
.replaceAll('<', '<')
|
|
20
|
+
.replaceAll('>', '>')
|
|
21
|
+
.replaceAll('"', '"')
|
|
22
|
+
.replaceAll("'", ''')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function validateAppName(value: string): string | undefined {
|
|
26
|
+
if (value.trim().length === 0) {
|
|
27
|
+
return 'name must not be empty or whitespace-only'
|
|
28
|
+
}
|
|
29
|
+
if (value.startsWith('.')) {
|
|
30
|
+
return 'name must not start with "."'
|
|
31
|
+
}
|
|
32
|
+
if (value.includes('/')) {
|
|
33
|
+
return 'name must not contain "/" (macOS app bundle names cannot contain path separators)'
|
|
34
|
+
}
|
|
35
|
+
if (/[\x00-\x1f\x7f]/.test(value)) {
|
|
36
|
+
return 'name must not contain control characters'
|
|
37
|
+
}
|
|
38
|
+
return undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ParsedMacOSVersion {
|
|
42
|
+
major: number
|
|
43
|
+
minor: number
|
|
44
|
+
patch: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function parseMinimumMacOS(version: string): ParsedMacOSVersion | undefined {
|
|
48
|
+
const match = /^(\d+)\.(\d+)(?:\.(\d+))?$/.exec(version.trim())
|
|
49
|
+
if (match === null) return undefined
|
|
50
|
+
const major = Number(match[1])
|
|
51
|
+
const minor = Number(match[2])
|
|
52
|
+
const patch = match[3] !== undefined ? Number(match[3]) : 0
|
|
53
|
+
if (Number.isInteger(major) === false || Number.isInteger(minor) === false || Number.isInteger(patch) === false) {
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
return { major: major, minor: minor, patch: patch }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function macOSVersionsMatch(a: string, b: string): boolean {
|
|
60
|
+
const pa = parseMinimumMacOS(a)
|
|
61
|
+
const pb = parseMinimumMacOS(b)
|
|
62
|
+
if (pa === undefined || pb === undefined) return a.trim() === b.trim()
|
|
63
|
+
return pa.major === pb.major && pa.minor === pb.minor && pa.patch === pb.patch
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const NAMED_MACOS_PLATFORM_VERSIONS = new Set([13, 14, 15, 26])
|
|
67
|
+
|
|
68
|
+
export function macOSPlatformClause(minimumMacOS: string): string {
|
|
69
|
+
const parsed = parseMinimumMacOS(minimumMacOS)
|
|
70
|
+
if (parsed === undefined) {
|
|
71
|
+
return `.macOS("${escapeSwiftString(minimumMacOS)}")`
|
|
72
|
+
}
|
|
73
|
+
if (parsed.minor === 0 && parsed.patch === 0 && NAMED_MACOS_PLATFORM_VERSIONS.has(parsed.major)) {
|
|
74
|
+
return `.macOS(.v${parsed.major})`
|
|
75
|
+
}
|
|
76
|
+
const normalized = parsed.patch === 0
|
|
77
|
+
? `${parsed.major}.${parsed.minor}`
|
|
78
|
+
: `${parsed.major}.${parsed.minor}.${parsed.patch}`
|
|
79
|
+
return `.macOS("${normalized}")`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function extractPackageMacOSVersion(manifestContents: string): string | undefined {
|
|
83
|
+
const withoutBlockComments = manifestContents.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
84
|
+
const withoutComments = withoutBlockComments.replace(/\/\/[^\n]*/g, '')
|
|
85
|
+
const platformsMatch = /\bplatforms\s*:\s*\[([\s\S]*?)\]/.exec(withoutComments)
|
|
86
|
+
if (platformsMatch === null) return undefined
|
|
87
|
+
const body = platformsMatch[1] ?? ''
|
|
88
|
+
const namedMatch = /(?:SupportedPlatform)?\.macOS\s*\(\s*\.v(\d+)(?:_(\d+))?\s*\)/.exec(body)
|
|
89
|
+
if (namedMatch !== null) {
|
|
90
|
+
const major = namedMatch[1]
|
|
91
|
+
const minor = namedMatch[2] ?? '0'
|
|
92
|
+
return `${major}.${minor}`
|
|
93
|
+
}
|
|
94
|
+
const stringMatch = /(?:SupportedPlatform)?\.macOS\s*\(\s*"([^"]+)"\s*\)/.exec(body)
|
|
95
|
+
if (stringMatch !== null) {
|
|
96
|
+
const raw = stringMatch[1] ?? ''
|
|
97
|
+
if (/^\d+$/.test(raw)) return `${raw}.0`
|
|
98
|
+
return raw
|
|
99
|
+
}
|
|
100
|
+
return undefined
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const macOSConfigSchema = z.object({
|
|
104
|
+
/** Display name of the macOS application (also used for the .app bundle name). */
|
|
105
|
+
name: z.string().superRefine((value, ctx) => {
|
|
106
|
+
const issue = validateAppName(value)
|
|
107
|
+
if (issue !== undefined) {
|
|
108
|
+
ctx.addIssue({ code: 'custom', message: issue })
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
/** SwiftPM executable product and target name. Defaults to an alphanumeric identifier derived from name. */
|
|
112
|
+
product: z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/, 'product must be a valid Swift identifier').optional(),
|
|
113
|
+
/** Bundle identifier, e.g. com.example.myapp. */
|
|
114
|
+
bundleId: z.string().regex(/^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/, 'bundleId must be a reverse-DNS identifier (e.g. com.example.myapp)'),
|
|
115
|
+
/** Marketing version (CFBundleShortVersionString). */
|
|
116
|
+
version: z.string().min(1).default('1.0.0'),
|
|
117
|
+
/** Build number (CFBundleVersion). */
|
|
118
|
+
buildNumber: z.string().min(1).default('1'),
|
|
119
|
+
/** Minimum macOS version (LSMinimumSystemVersion). */
|
|
120
|
+
minimumMacOS: z.string()
|
|
121
|
+
.regex(/^\d+\.\d+(?:\.\d+)?$/, 'minimumMacOS must be a version like "13.0"')
|
|
122
|
+
.superRefine((value, ctx) => {
|
|
123
|
+
const parsed = parseMinimumMacOS(value)
|
|
124
|
+
if (parsed === undefined || parsed.major < 13) {
|
|
125
|
+
ctx.addIssue({ code: 'custom', message: 'minimumMacOS must be 13.0 or newer' })
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
.default('13.0'),
|
|
129
|
+
/** Optional entry file relative to app root (falls back to app.json entry, then src/index.tsx). */
|
|
130
|
+
entry: z.string().min(1).optional(),
|
|
131
|
+
/** Optional icon path (.icns, .iconset, or .png) relative to app root. */
|
|
132
|
+
icon: z.string().min(1).optional(),
|
|
133
|
+
/** Optional Info.plist path relative to app root (defaults to macos/Info.plist). */
|
|
134
|
+
infoPlist: z.string().min(1).optional(),
|
|
135
|
+
/** Optional entitlements plist path relative to app root (defaults to macos/Entitlements.plist if present). */
|
|
136
|
+
entitlements: z.string().min(1).optional(),
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
export type MacOSConfig = z.infer<typeof macOSConfigSchema>
|
|
140
|
+
|
|
141
|
+
export interface ResolvedMacOSConfig extends MacOSConfig {
|
|
142
|
+
product: string
|
|
143
|
+
entry: string
|
|
144
|
+
infoPlist: string
|
|
145
|
+
layoutEngine: string
|
|
146
|
+
reactCompiler: boolean
|
|
147
|
+
modules: string[]
|
|
148
|
+
iosProject: string
|
|
149
|
+
iosScheme: string
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const optionalAppConfigSchema = z.object({
|
|
153
|
+
name: z.string().min(1).optional(),
|
|
154
|
+
layoutEngine: z.string().min(1).optional(),
|
|
155
|
+
reactCompiler: z.boolean().default(true),
|
|
156
|
+
entry: z.string().min(1).default('src/index.tsx'),
|
|
157
|
+
modules: z.array(z.string().min(1)).default(['Modules/*']),
|
|
158
|
+
ios: z.object({
|
|
159
|
+
project: z.string().min(1).default('ios/NitroUI.xcodeproj'),
|
|
160
|
+
scheme: z.string().min(1).default('NitroUI'),
|
|
161
|
+
}).prefault({}),
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
export type OptionalAppConfig = z.infer<typeof optionalAppConfigSchema>
|
|
165
|
+
|
|
166
|
+
export function deriveProductName(appName: string): string {
|
|
167
|
+
const cleaned = appName.replace(/[^A-Za-z0-9_]/g, '')
|
|
168
|
+
if (/^[A-Za-z]/.test(cleaned)) return cleaned
|
|
169
|
+
if (cleaned.length > 0) return `App${cleaned}`
|
|
170
|
+
return 'NitroMacOSApp'
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function deriveBundleId(appName: string): string {
|
|
174
|
+
const slug = appName
|
|
175
|
+
.toLowerCase()
|
|
176
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
177
|
+
.replace(/^-+|-+$/g, '')
|
|
178
|
+
const segment = slug.length > 0 ? slug : 'nitrouiapp'
|
|
179
|
+
return `com.example.${segment}`
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function readOptionalAppConfig(root: string): Promise<OptionalAppConfig> {
|
|
183
|
+
const path = join(root, 'app.json')
|
|
184
|
+
try {
|
|
185
|
+
const raw = await readFile(path, 'utf8')
|
|
186
|
+
const parsed: unknown = Bun.JSONC.parse(raw)
|
|
187
|
+
return optionalAppConfigSchema.parse(parsed)
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (isMissingFile(error)) {
|
|
190
|
+
return optionalAppConfigSchema.parse({})
|
|
191
|
+
}
|
|
192
|
+
throw error
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export async function readMacOSConfig(root: string): Promise<ResolvedMacOSConfig> {
|
|
197
|
+
const configPath = join(root, 'macos/config.json')
|
|
198
|
+
let raw: string
|
|
199
|
+
try {
|
|
200
|
+
raw = await readFile(configPath, 'utf8')
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (isMissingFile(error)) {
|
|
203
|
+
throw new Error(`Missing ${configPath}. Run \`nitro-ui-macos init\` first to add macOS support to this app.`)
|
|
204
|
+
}
|
|
205
|
+
throw error
|
|
206
|
+
}
|
|
207
|
+
const parsed: unknown = Bun.JSONC.parse(raw)
|
|
208
|
+
const macConfig = macOSConfigSchema.parse(parsed)
|
|
209
|
+
const appConfig = await readOptionalAppConfig(root)
|
|
210
|
+
|
|
211
|
+
const product = macConfig.product ?? deriveProductName(macConfig.name)
|
|
212
|
+
const entry = macConfig.entry ?? appConfig.entry
|
|
213
|
+
const infoPlist = macConfig.infoPlist ?? 'macos/Info.plist'
|
|
214
|
+
const layoutEngine = appConfig.layoutEngine ?? 'nitro-ui-layout-starlight'
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
name: macConfig.name,
|
|
218
|
+
product: product,
|
|
219
|
+
bundleId: macConfig.bundleId,
|
|
220
|
+
version: macConfig.version,
|
|
221
|
+
buildNumber: macConfig.buildNumber,
|
|
222
|
+
minimumMacOS: macConfig.minimumMacOS,
|
|
223
|
+
entry: entry,
|
|
224
|
+
icon: macConfig.icon,
|
|
225
|
+
infoPlist: infoPlist,
|
|
226
|
+
entitlements: macConfig.entitlements,
|
|
227
|
+
layoutEngine: layoutEngine,
|
|
228
|
+
reactCompiler: appConfig.reactCompiler,
|
|
229
|
+
modules: appConfig.modules,
|
|
230
|
+
iosProject: appConfig.ios.project,
|
|
231
|
+
iosScheme: appConfig.ios.scheme,
|
|
232
|
+
}
|
|
233
|
+
}
|
package/src/create.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises'
|
|
2
|
+
import { basename, join, resolve } from 'node:path'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import { initMacOS } from './init'
|
|
5
|
+
import { packageRoot, readPackageManifest } from './packageDirectory'
|
|
6
|
+
import { prepareMacOS } from './prepare'
|
|
7
|
+
import { run } from './run'
|
|
8
|
+
import { SUPPORTED_NITRO_UI_VERSION } from './versions'
|
|
9
|
+
|
|
10
|
+
const appNameSchema = z.string().regex(
|
|
11
|
+
/^[A-Za-z][A-Za-z0-9]*$/,
|
|
12
|
+
'Use an app name containing letters and numbers, starting with a letter.',
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const selfManifestSchema = z.object({
|
|
16
|
+
version: z.string(),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const appPackageSchema = z.object({
|
|
20
|
+
dependencies: z.record(z.string(), z.string()).optional(),
|
|
21
|
+
}).passthrough()
|
|
22
|
+
|
|
23
|
+
export interface CreateOptions {
|
|
24
|
+
destination: string
|
|
25
|
+
noInstall: boolean
|
|
26
|
+
macosPackageSpec?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function createMacOSApp(options: CreateOptions): Promise<void> {
|
|
30
|
+
const { destination, noInstall, macosPackageSpec } = options
|
|
31
|
+
const directory = resolve(destination)
|
|
32
|
+
const name = basename(directory)
|
|
33
|
+
appNameSchema.parse(name)
|
|
34
|
+
|
|
35
|
+
await run(
|
|
36
|
+
['bunx', `create-nitro-ui@${SUPPORTED_NITRO_UI_VERSION}`, directory, '--no-install'],
|
|
37
|
+
{ cwd: process.cwd() },
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const selfManifestRaw = await readPackageManifest(join(packageRoot(), 'package.json'))
|
|
41
|
+
const selfManifest = selfManifestSchema.parse(selfManifestRaw)
|
|
42
|
+
const packageSpec = macosPackageSpec ?? selfManifest.version
|
|
43
|
+
|
|
44
|
+
const appPkgPath = join(directory, 'package.json')
|
|
45
|
+
const appPkgRaw = await readPackageManifest(appPkgPath)
|
|
46
|
+
const appPkg = appPackageSchema.parse(appPkgRaw)
|
|
47
|
+
const dependencies: Record<string, string> = {
|
|
48
|
+
...(appPkg.dependencies ?? {}),
|
|
49
|
+
'nitro-ui-macos': packageSpec,
|
|
50
|
+
}
|
|
51
|
+
const updatedPkg = { ...appPkg, dependencies: dependencies }
|
|
52
|
+
await writeFile(appPkgPath, `${JSON.stringify(updatedPkg, undefined, 2)}\n`)
|
|
53
|
+
|
|
54
|
+
await initMacOS({ root: directory, name: name })
|
|
55
|
+
|
|
56
|
+
if (noInstall === false) {
|
|
57
|
+
await run(['bun', 'install'], { cwd: directory })
|
|
58
|
+
await prepareMacOS(directory)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
console.log(
|
|
62
|
+
`\nCreated ${name} with macOS support.\n\n` +
|
|
63
|
+
` cd ${destination}\n` +
|
|
64
|
+
` bun run macos:start # start the dev server\n` +
|
|
65
|
+
` bun run macos # build and launch the macOS app\n`,
|
|
66
|
+
)
|
|
67
|
+
}
|
package/src/files.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { lstat, mkdir, readFile, readlink, rm, stat, symlink, unlink, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { dirname, resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
export function isMissingFile(error: unknown): boolean {
|
|
5
|
+
return error instanceof Error && 'code' in error && error.code === 'ENOENT'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function fileExists(path: string): Promise<boolean> {
|
|
9
|
+
try {
|
|
10
|
+
const information = await stat(path)
|
|
11
|
+
return information.isFile()
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if (isMissingFile(error)) return false
|
|
14
|
+
throw error
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function directoryExists(path: string): Promise<boolean> {
|
|
19
|
+
try {
|
|
20
|
+
const information = await stat(path)
|
|
21
|
+
return information.isDirectory()
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (isMissingFile(error)) return false
|
|
24
|
+
throw error
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function pathExists(path: string): Promise<boolean> {
|
|
29
|
+
try {
|
|
30
|
+
await lstat(path)
|
|
31
|
+
return true
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (isMissingFile(error)) return false
|
|
34
|
+
throw error
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function writeChanged(path: string, contents: string): Promise<boolean> {
|
|
39
|
+
try {
|
|
40
|
+
const previous = await readFile(path, 'utf8')
|
|
41
|
+
if (previous === contents) return false
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (isMissingFile(error) === false) throw error
|
|
44
|
+
}
|
|
45
|
+
const parent = dirname(path)
|
|
46
|
+
await mkdir(parent, { recursive: true })
|
|
47
|
+
await writeFile(path, contents)
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function linkPath(path: string, target: string): Promise<void> {
|
|
52
|
+
const absoluteTarget = resolve(target)
|
|
53
|
+
try {
|
|
54
|
+
const existing = await lstat(path)
|
|
55
|
+
if (existing.isSymbolicLink()) {
|
|
56
|
+
const previous = await readlink(path)
|
|
57
|
+
const parent = dirname(path)
|
|
58
|
+
const previousTarget = resolve(parent, previous)
|
|
59
|
+
if (previousTarget === absoluteTarget) return
|
|
60
|
+
await unlink(path)
|
|
61
|
+
} else {
|
|
62
|
+
await rm(path, { recursive: true, force: true })
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (isMissingFile(error) === false) throw error
|
|
66
|
+
}
|
|
67
|
+
const parent = dirname(path)
|
|
68
|
+
await mkdir(parent, { recursive: true })
|
|
69
|
+
await symlink(absoluteTarget, path)
|
|
70
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Platform, type MacOSPlatform, type PlatformOS } from './Platform'
|
package/src/init.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { copyFile, mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { basename, dirname, join } from 'node:path'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import {
|
|
5
|
+
deriveBundleId,
|
|
6
|
+
deriveProductName,
|
|
7
|
+
escapeSwiftString,
|
|
8
|
+
escapeXml,
|
|
9
|
+
macOSConfigSchema,
|
|
10
|
+
macOSPlatformClause,
|
|
11
|
+
readOptionalAppConfig,
|
|
12
|
+
} from './config'
|
|
13
|
+
import { fileExists, isMissingFile, pathExists } from './files'
|
|
14
|
+
import { packageRoot, readPackageManifest } from './packageDirectory'
|
|
15
|
+
|
|
16
|
+
const packageManifestSchema = z.object({
|
|
17
|
+
name: z.string().optional(),
|
|
18
|
+
scripts: z.record(z.string(), z.string()).optional(),
|
|
19
|
+
}).passthrough()
|
|
20
|
+
|
|
21
|
+
export interface InitOptions {
|
|
22
|
+
root: string
|
|
23
|
+
name?: string
|
|
24
|
+
bundleId?: string
|
|
25
|
+
quiet?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface InitResult {
|
|
29
|
+
created: string[]
|
|
30
|
+
skipped: string[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function writeIfMissing(
|
|
34
|
+
root: string,
|
|
35
|
+
relativePath: string,
|
|
36
|
+
contents: string,
|
|
37
|
+
result: InitResult,
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
const fullPath = join(root, relativePath)
|
|
40
|
+
if (await pathExists(fullPath)) {
|
|
41
|
+
result.skipped.push(relativePath)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
await mkdir(dirname(fullPath), { recursive: true })
|
|
45
|
+
await writeFile(fullPath, contents)
|
|
46
|
+
result.created.push(relativePath)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function copyIfMissing(
|
|
50
|
+
root: string,
|
|
51
|
+
relativePath: string,
|
|
52
|
+
sourcePath: string,
|
|
53
|
+
result: InitResult,
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
const fullPath = join(root, relativePath)
|
|
56
|
+
if (await pathExists(fullPath)) {
|
|
57
|
+
result.skipped.push(relativePath)
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
await mkdir(dirname(fullPath), { recursive: true })
|
|
61
|
+
await copyFile(sourcePath, fullPath)
|
|
62
|
+
result.created.push(relativePath)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function updateGitignore(root: string): Promise<boolean> {
|
|
66
|
+
const gitignorePath = join(root, '.gitignore')
|
|
67
|
+
const entriesToEnsure = ['.nitro/', 'macos/.build/', 'macos/.swiftpm/', 'macos/build/']
|
|
68
|
+
let existing = ''
|
|
69
|
+
try {
|
|
70
|
+
existing = await readFile(gitignorePath, 'utf8')
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (isMissingFile(error) === false) throw error
|
|
73
|
+
}
|
|
74
|
+
const existingLines = new Set(existing.split(/\r?\n/).map((line) => line.trim()))
|
|
75
|
+
const missing = entriesToEnsure.filter((entry) => existingLines.has(entry) === false)
|
|
76
|
+
if (missing.length === 0) return false
|
|
77
|
+
const separator = existing.length === 0 || existing.endsWith('\n') ? '' : '\n'
|
|
78
|
+
const updated = `${existing}${separator}${missing.join('\n')}\n`
|
|
79
|
+
await writeFile(gitignorePath, updated)
|
|
80
|
+
return true
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function updatePackageScripts(root: string): Promise<string[]> {
|
|
84
|
+
const manifestPath = join(root, 'package.json')
|
|
85
|
+
if ((await fileExists(manifestPath)) === false) return []
|
|
86
|
+
const raw = await readPackageManifest(manifestPath)
|
|
87
|
+
const manifest = packageManifestSchema.parse(raw)
|
|
88
|
+
const scripts: Record<string, string> = { ...(manifest.scripts ?? {}) }
|
|
89
|
+
const desired: Record<string, string> = {
|
|
90
|
+
'macos': 'nitro-ui-macos run',
|
|
91
|
+
'macos:start': 'nitro-ui-macos start',
|
|
92
|
+
'macos:prepare': 'nitro-ui-macos prepare',
|
|
93
|
+
'macos:build': 'nitro-ui-macos build',
|
|
94
|
+
'macos:package': 'nitro-ui-macos package',
|
|
95
|
+
}
|
|
96
|
+
const added: string[] = []
|
|
97
|
+
for (const [key, value] of Object.entries(desired)) {
|
|
98
|
+
if (scripts[key] === undefined) {
|
|
99
|
+
scripts[key] = value
|
|
100
|
+
added.push(key)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (added.length === 0) return []
|
|
104
|
+
const nextManifest = { ...manifest, scripts: scripts }
|
|
105
|
+
await writeFile(manifestPath, `${JSON.stringify(nextManifest, undefined, 2)}\n`)
|
|
106
|
+
return added
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function initMacOS(options: InitOptions): Promise<InitResult> {
|
|
110
|
+
const { root } = options
|
|
111
|
+
const appConfig = await readOptionalAppConfig(root)
|
|
112
|
+
|
|
113
|
+
let fallbackName = basename(root)
|
|
114
|
+
const pkgPath = join(root, 'package.json')
|
|
115
|
+
if (await fileExists(pkgPath)) {
|
|
116
|
+
const raw = await readPackageManifest(pkgPath)
|
|
117
|
+
const parsed = packageManifestSchema.safeParse(raw)
|
|
118
|
+
if (parsed.success && parsed.data.name !== undefined && parsed.data.name !== '') {
|
|
119
|
+
fallbackName = parsed.data.name
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const rawName = options.name ?? appConfig.name ?? fallbackName
|
|
124
|
+
const product = deriveProductName(rawName)
|
|
125
|
+
const rawBundleId = options.bundleId ?? deriveBundleId(rawName)
|
|
126
|
+
const validated = macOSConfigSchema.safeParse({
|
|
127
|
+
name: rawName,
|
|
128
|
+
product: product,
|
|
129
|
+
bundleId: rawBundleId,
|
|
130
|
+
version: '1.0.0',
|
|
131
|
+
buildNumber: '1',
|
|
132
|
+
minimumMacOS: '13.0',
|
|
133
|
+
icon: 'macos/AppIcon.icns',
|
|
134
|
+
})
|
|
135
|
+
if (validated.success === false) {
|
|
136
|
+
const details = validated.error.issues.map((issue) => `${issue.path.join('.') || 'config'}: ${issue.message}`).join('; ')
|
|
137
|
+
throw new Error(`Invalid macOS app configuration (${details}).`)
|
|
138
|
+
}
|
|
139
|
+
const appName = validated.data.name
|
|
140
|
+
const bundleId = validated.data.bundleId
|
|
141
|
+
const minimumMacOS = validated.data.minimumMacOS
|
|
142
|
+
const swiftAppName = escapeSwiftString(appName)
|
|
143
|
+
const xmlAppName = escapeXml(appName)
|
|
144
|
+
const xmlProduct = escapeXml(product)
|
|
145
|
+
const xmlBundleId = escapeXml(bundleId)
|
|
146
|
+
const xmlMinMacOS = escapeXml(minimumMacOS)
|
|
147
|
+
|
|
148
|
+
const result: InitResult = { created: [], skipped: [] }
|
|
149
|
+
|
|
150
|
+
const configContents = `${JSON.stringify(
|
|
151
|
+
{
|
|
152
|
+
name: appName,
|
|
153
|
+
product: product,
|
|
154
|
+
bundleId: bundleId,
|
|
155
|
+
version: '1.0.0',
|
|
156
|
+
buildNumber: '1',
|
|
157
|
+
minimumMacOS: minimumMacOS,
|
|
158
|
+
icon: 'macos/AppIcon.icns',
|
|
159
|
+
},
|
|
160
|
+
undefined,
|
|
161
|
+
2,
|
|
162
|
+
)}\n`
|
|
163
|
+
|
|
164
|
+
const packageSwift = `// swift-tools-version: 6.4
|
|
165
|
+
|
|
166
|
+
import PackageDescription
|
|
167
|
+
|
|
168
|
+
let package = Package(
|
|
169
|
+
name: "${product}",
|
|
170
|
+
platforms: [${macOSPlatformClause(minimumMacOS)}],
|
|
171
|
+
dependencies: [
|
|
172
|
+
.package(path: "../.nitro/macos/NitroUIApp"),
|
|
173
|
+
],
|
|
174
|
+
targets: [
|
|
175
|
+
.executableTarget(
|
|
176
|
+
name: "${product}",
|
|
177
|
+
dependencies: [
|
|
178
|
+
.product(name: "NitroUIApp", package: "NitroUIApp"),
|
|
179
|
+
],
|
|
180
|
+
swiftSettings: [
|
|
181
|
+
.interoperabilityMode(.Cxx),
|
|
182
|
+
]
|
|
183
|
+
),
|
|
184
|
+
],
|
|
185
|
+
cxxLanguageStandard: .cxx20
|
|
186
|
+
)
|
|
187
|
+
`
|
|
188
|
+
|
|
189
|
+
const mainSwift = `import AppKit
|
|
190
|
+
import Foundation
|
|
191
|
+
import NitroUIApp
|
|
192
|
+
|
|
193
|
+
@MainActor
|
|
194
|
+
final class AppDelegate: NitroUIAppDelegate {
|
|
195
|
+
override var windowTitle: String { "${swiftAppName}" }
|
|
196
|
+
override var defaultContentSize: CGSize { CGSize(width: 960, height: 640) }
|
|
197
|
+
|
|
198
|
+
override func registerAppModules() {
|
|
199
|
+
nitroUIRegisterAppModules()
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
override func applicationDidFinishLaunching(_ notification: Notification) {
|
|
203
|
+
#if DEBUG
|
|
204
|
+
registerDevLoader()
|
|
205
|
+
#endif
|
|
206
|
+
super.applicationDidFinishLaunching(notification)
|
|
207
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@main
|
|
212
|
+
struct ${product}Main {
|
|
213
|
+
@MainActor
|
|
214
|
+
static func main() {
|
|
215
|
+
let app = NSApplication.shared
|
|
216
|
+
app.setActivationPolicy(.regular)
|
|
217
|
+
let delegate = AppDelegate()
|
|
218
|
+
app.delegate = delegate
|
|
219
|
+
withExtendedLifetime(delegate) {
|
|
220
|
+
app.run()
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
`
|
|
225
|
+
|
|
226
|
+
const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
227
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
228
|
+
<plist version="1.0">
|
|
229
|
+
<dict>
|
|
230
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
231
|
+
<string>en</string>
|
|
232
|
+
<key>CFBundleDisplayName</key>
|
|
233
|
+
<string>${xmlAppName}</string>
|
|
234
|
+
<key>CFBundleExecutable</key>
|
|
235
|
+
<string>${xmlProduct}</string>
|
|
236
|
+
<key>CFBundleIconFile</key>
|
|
237
|
+
<string>AppIcon</string>
|
|
238
|
+
<key>CFBundleIdentifier</key>
|
|
239
|
+
<string>${xmlBundleId}</string>
|
|
240
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
241
|
+
<string>6.0</string>
|
|
242
|
+
<key>CFBundleName</key>
|
|
243
|
+
<string>${xmlAppName}</string>
|
|
244
|
+
<key>CFBundlePackageType</key>
|
|
245
|
+
<string>APPL</string>
|
|
246
|
+
<key>CFBundleShortVersionString</key>
|
|
247
|
+
<string>1.0.0</string>
|
|
248
|
+
<key>CFBundleVersion</key>
|
|
249
|
+
<string>1</string>
|
|
250
|
+
<key>LSMinimumSystemVersion</key>
|
|
251
|
+
<string>${xmlMinMacOS}</string>
|
|
252
|
+
<key>NSAppTransportSecurity</key>
|
|
253
|
+
<dict>
|
|
254
|
+
<key>NSAllowsLocalNetworking</key>
|
|
255
|
+
<true/>
|
|
256
|
+
</dict>
|
|
257
|
+
<key>NSHighResolutionCapable</key>
|
|
258
|
+
<true/>
|
|
259
|
+
<key>NSPrincipalClass</key>
|
|
260
|
+
<string>NSApplication</string>
|
|
261
|
+
</dict>
|
|
262
|
+
</plist>
|
|
263
|
+
`
|
|
264
|
+
|
|
265
|
+
const entitlementsPlist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
266
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
267
|
+
<plist version="1.0">
|
|
268
|
+
<dict>
|
|
269
|
+
<key>com.apple.security.network.client</key>
|
|
270
|
+
<true/>
|
|
271
|
+
</dict>
|
|
272
|
+
</plist>
|
|
273
|
+
`
|
|
274
|
+
|
|
275
|
+
await writeIfMissing(root, 'macos/config.json', configContents, result)
|
|
276
|
+
await writeIfMissing(root, 'macos/Package.swift', packageSwift, result)
|
|
277
|
+
await writeIfMissing(root, `macos/Sources/${product}/main.swift`, mainSwift, result)
|
|
278
|
+
await writeIfMissing(root, 'macos/Info.plist', infoPlist, result)
|
|
279
|
+
await writeIfMissing(root, 'macos/Entitlements.plist', entitlementsPlist, result)
|
|
280
|
+
|
|
281
|
+
const templateIcon = join(packageRoot(), 'templates/AppIcon.icns')
|
|
282
|
+
if (await fileExists(templateIcon)) {
|
|
283
|
+
await copyIfMissing(root, 'macos/AppIcon.icns', templateIcon, result)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const gitignoreUpdated = await updateGitignore(root)
|
|
287
|
+
const scriptsAdded = await updatePackageScripts(root)
|
|
288
|
+
|
|
289
|
+
if (options.quiet !== true) {
|
|
290
|
+
if (result.created.length > 0) {
|
|
291
|
+
console.log(`Created:\n${result.created.map((file) => ` - ${file}`).join('\n')}`)
|
|
292
|
+
}
|
|
293
|
+
if (result.skipped.length > 0) {
|
|
294
|
+
console.log(`Skipped existing:\n${result.skipped.map((file) => ` - ${file}`).join('\n')}`)
|
|
295
|
+
}
|
|
296
|
+
if (gitignoreUpdated) console.log('Updated .gitignore with macOS build directories.')
|
|
297
|
+
if (scriptsAdded.length > 0) console.log(`Added package.json scripts: ${scriptsAdded.join(', ')}`)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return result
|
|
301
|
+
}
|