@nativue/core 0.13.0 → 0.14.0
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/AGENTS.md +31 -7
- package/README.md +1 -0
- package/android/build.gradle.kts +4 -0
- package/android/nativue.settings.gradle.kts +2 -0
- package/android/src/main/java/dev/nativue/Bridge.kt +66 -7
- package/android/src/main/java/dev/nativue/NativueActivity.kt +12 -5
- package/android/src/main/java/dev/nativue/Permissions.kt +107 -0
- package/android/src/main/java/dev/nativue/Plugins.kt +98 -15
- package/cli/android-project.mjs +377 -0
- package/cli/app-config.mjs +515 -0
- package/cli/config.d.mts +162 -3
- package/cli/ios-project.mjs +652 -0
- package/cli/link.mjs +66 -71
- package/cli/nativue.mjs +39 -5
- package/cli/plugins.mjs +236 -0
- package/cli/prebuild.mjs +458 -0
- package/cli/run.mjs +2 -2
- package/cli/serialize.mjs +168 -0
- package/ios/AppLifecycle.swift +165 -0
- package/ios/Bridge.swift +53 -4
- package/ios/NativueView.swift +5 -1
- package/ios/Permissions.swift +19 -0
- package/ios/Plugins.swift +24 -0
- package/package.json +3 -2
- package/src/globals.ts +7 -1
- package/src/native-events.ts +99 -0
- package/src/native-functions.ts +16 -2
- package/src/permissions.ts +57 -0
- package/src/renderer.ts +5 -1
- package/src/router.ts +2 -1
- package/src/types.ts +3 -0
- package/template/android/app/src/debug/AndroidManifest.xml +4 -0
- package/template/android/app/src/main/java/MainActivity.kt +5 -0
- package/template/android/app/src/main/res/drawable-night-xxxhdpi/splash_logo.png +0 -0
- package/template/android/app/src/main/res/drawable-xxxhdpi/splash_logo.png +0 -0
- package/template/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
- package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
- package/template/android/app/src/main/res/values/colors.xml +4 -0
- package/template/android/app/src/main/res/values/styles.xml +15 -0
- package/template/android/app/src/main/res/values-night/styles.xml +5 -0
- package/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/template/android/gradle/wrapper/gradle-wrapper.properties +9 -0
- package/template/android/gradlew +248 -0
- package/template/android/gradlew.bat +112 -0
- package/template/ios/App/App.swift +18 -0
- package/template/ios/App/Assets.xcassets/AppIcon.appiconset/Contents.json +1 -0
- package/template/ios/App/Assets.xcassets/AppIcon.appiconset/icon.png +0 -0
- package/template/ios/App/Assets.xcassets/Contents.json +1 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/Contents.json +11 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@1x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@2x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@3x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@1x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@2x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@3x.png +0 -0
- package/template/ios/App.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +15 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
// The iOS project files prebuild builds from the config, instead of copying them from the template:
|
|
2
|
+
// the Xcode project, Info.plist, the entitlements, and the icon and launch screen. A null file
|
|
3
|
+
// removes the template's.
|
|
4
|
+
import { createHash } from 'node:crypto'
|
|
5
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
6
|
+
import { join, relative, resolve } from 'node:path'
|
|
7
|
+
import {
|
|
8
|
+
appResources,
|
|
9
|
+
EXTENSION_POINTS,
|
|
10
|
+
iosFonts,
|
|
11
|
+
validateExtensionTargets,
|
|
12
|
+
} from './app-config.mjs'
|
|
13
|
+
import { applyMods } from './plugins.mjs'
|
|
14
|
+
import { toPosixPath } from './link.mjs'
|
|
15
|
+
import { pbxproj, plist } from './serialize.mjs'
|
|
16
|
+
|
|
17
|
+
const DEPLOYMENT_TARGET = '15.1'
|
|
18
|
+
const ENTITLEMENTS_FILE = 'App.entitlements'
|
|
19
|
+
const ASSETS = 'App/Assets.xcassets'
|
|
20
|
+
const TEMPLATE_LAUNCH_LOGOS = ['logo', 'logo-dark'].flatMap((name) =>
|
|
21
|
+
[1, 2, 3].map((scale) => `${name}@${scale}x.png`),
|
|
22
|
+
)
|
|
23
|
+
const DEV_SERVER_HOST_SCRIPT = `# Lets a physical device reach the dev server on this Mac.
|
|
24
|
+
[ "$CONFIGURATION" = "Debug" ] || exit 0
|
|
25
|
+
echo "$(scutil --get LocalHostName).local" > "$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/dev-server-host.txt"
|
|
26
|
+
`
|
|
27
|
+
|
|
28
|
+
// The app's objects keep the ids the hand-written project had.
|
|
29
|
+
const ID = {
|
|
30
|
+
product: 'AA0000000000000000000001',
|
|
31
|
+
appFolder: 'AA0000000000000000000002',
|
|
32
|
+
frameworksPhase: 'AA0000000000000000000003',
|
|
33
|
+
mainGroup: 'AA0000000000000000000004',
|
|
34
|
+
productsGroup: 'AA0000000000000000000005',
|
|
35
|
+
target: 'AA0000000000000000000006',
|
|
36
|
+
sourcesPhase: 'AA0000000000000000000007',
|
|
37
|
+
resourcesPhase: 'AA0000000000000000000008',
|
|
38
|
+
project: 'AA0000000000000000000009',
|
|
39
|
+
targetConfigurations: 'AA000000000000000000000A',
|
|
40
|
+
projectConfigurations: 'AA000000000000000000000B',
|
|
41
|
+
projectDebug: 'AA000000000000000000000C',
|
|
42
|
+
projectRelease: 'AA000000000000000000000D',
|
|
43
|
+
targetDebug: 'AA000000000000000000000E',
|
|
44
|
+
targetRelease: 'AA000000000000000000000F',
|
|
45
|
+
pluginsBuildFile: 'AA0000000000000000000010',
|
|
46
|
+
pluginsPackage: 'AA0000000000000000000011',
|
|
47
|
+
pluginsProduct: 'AA0000000000000000000012',
|
|
48
|
+
devServerHostPhase: 'AA0000000000000000000020',
|
|
49
|
+
embedExtensionsPhase: 'AA0000000000000000000021',
|
|
50
|
+
}
|
|
51
|
+
// In PlugIns, where iOS looks for an app's extensions.
|
|
52
|
+
const PLUGINS_FOLDER = 13
|
|
53
|
+
|
|
54
|
+
function buildPhase(isa) {
|
|
55
|
+
return { isa, buildActionMask: 2147483647, files: [], runOnlyForDeploymentPostprocessing: 0 }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function configurationList(configurations) {
|
|
59
|
+
return {
|
|
60
|
+
isa: 'XCConfigurationList',
|
|
61
|
+
buildConfigurations: configurations,
|
|
62
|
+
defaultConfigurationIsVisible: 0,
|
|
63
|
+
defaultConfigurationName: 'Release',
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function targetBuildSettings(app, hasEntitlements) {
|
|
68
|
+
return {
|
|
69
|
+
ASSETCATALOG_COMPILER_APPICON_NAME: 'AppIcon',
|
|
70
|
+
CODE_SIGN_ENTITLEMENTS: hasEntitlements ? ENTITLEMENTS_FILE : undefined,
|
|
71
|
+
CODE_SIGN_STYLE: 'Automatic',
|
|
72
|
+
CURRENT_PROJECT_VERSION: app.buildNumber,
|
|
73
|
+
DEVELOPMENT_TEAM: app.ios.appleTeamId,
|
|
74
|
+
GENERATE_INFOPLIST_FILE: 'YES',
|
|
75
|
+
INFOPLIST_FILE: 'Info.plist',
|
|
76
|
+
INFOPLIST_KEY_CFBundleDisplayName: app.name,
|
|
77
|
+
LD_RUNPATH_SEARCH_PATHS: '$(inherited) @executable_path/Frameworks',
|
|
78
|
+
MARKETING_VERSION: app.version,
|
|
79
|
+
PRODUCT_BUNDLE_IDENTIFIER: app.ios.bundleIdentifier,
|
|
80
|
+
PRODUCT_NAME: '$(TARGET_NAME)',
|
|
81
|
+
TARGETED_DEVICE_FAMILY: '1,2',
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A stable id, the same on every prebuild: from the extension's name and the object's role. */
|
|
86
|
+
function extensionId(name, role) {
|
|
87
|
+
return createHash('sha256')
|
|
88
|
+
.update(`extension/${name}/${role}`)
|
|
89
|
+
.digest('hex')
|
|
90
|
+
.slice(0, 24)
|
|
91
|
+
.toUpperCase()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const EXTENSION_ROLES = [
|
|
95
|
+
'product',
|
|
96
|
+
'folder',
|
|
97
|
+
'target',
|
|
98
|
+
'sourcesPhase',
|
|
99
|
+
'frameworksPhase',
|
|
100
|
+
'resourcesPhase',
|
|
101
|
+
'configurations',
|
|
102
|
+
'debug',
|
|
103
|
+
'release',
|
|
104
|
+
'proxy',
|
|
105
|
+
'dependency',
|
|
106
|
+
'embedBuildFile',
|
|
107
|
+
'settingsException',
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
function extensionIds(name) {
|
|
111
|
+
return Object.fromEntries(EXTENSION_ROLES.map((role) => [role, extensionId(name, role)]))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function extensionSupportPath(name, file) {
|
|
115
|
+
return `ExtensionSupport/${name}/${file}`
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function extensionBuildSettings(app, extension) {
|
|
119
|
+
const { name } = extension
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
CODE_SIGN_ENTITLEMENTS: extension.hasEntitlements
|
|
123
|
+
? extensionSupportPath(name, `${name}.entitlements`)
|
|
124
|
+
: undefined,
|
|
125
|
+
CODE_SIGN_STYLE: 'Automatic',
|
|
126
|
+
CURRENT_PROJECT_VERSION: app.buildNumber,
|
|
127
|
+
DEVELOPMENT_TEAM: app.ios.appleTeamId,
|
|
128
|
+
GENERATE_INFOPLIST_FILE: 'YES',
|
|
129
|
+
INFOPLIST_FILE: extensionSupportPath(name, 'Info.plist'),
|
|
130
|
+
INFOPLIST_KEY_CFBundleDisplayName: name,
|
|
131
|
+
IPHONEOS_DEPLOYMENT_TARGET: extension.deploymentTarget,
|
|
132
|
+
LD_RUNPATH_SEARCH_PATHS:
|
|
133
|
+
'$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks',
|
|
134
|
+
MARKETING_VERSION: app.version,
|
|
135
|
+
PRODUCT_BUNDLE_IDENTIFIER: `${app.ios.bundleIdentifier}${extension.bundleIdSuffix}`,
|
|
136
|
+
// App<Name>, as for native/ modules: a share extension named Social doesn't hide the framework.
|
|
137
|
+
PRODUCT_MODULE_NAME: `App${name}`,
|
|
138
|
+
PRODUCT_NAME: '$(TARGET_NAME)',
|
|
139
|
+
SKIP_INSTALL: 'YES',
|
|
140
|
+
TARGETED_DEVICE_FAMILY: '1,2',
|
|
141
|
+
...extension.buildSettings,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** An extension target: its product, its buildable folder, and how the app embeds it. */
|
|
146
|
+
function extensionObjects(app, extension) {
|
|
147
|
+
const { name, folder } = extension
|
|
148
|
+
const ids = extensionIds(name)
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
[ids.product]: {
|
|
152
|
+
isa: 'PBXFileReference',
|
|
153
|
+
explicitFileType: 'wrapper.app-extension',
|
|
154
|
+
includeInIndex: 0,
|
|
155
|
+
path: `${name}.appex`,
|
|
156
|
+
sourceTree: 'BUILT_PRODUCTS_DIR',
|
|
157
|
+
},
|
|
158
|
+
[ids.folder]: {
|
|
159
|
+
isa: 'PBXFileSystemSynchronizedRootGroup',
|
|
160
|
+
exceptions: extension.hasSettingsFile ? [ids.settingsException] : undefined,
|
|
161
|
+
path: folder,
|
|
162
|
+
sourceTree: '<group>',
|
|
163
|
+
},
|
|
164
|
+
// nativue.json sets the target up: it isn't one of the extension's resources.
|
|
165
|
+
...(extension.hasSettingsFile && {
|
|
166
|
+
[ids.settingsException]: {
|
|
167
|
+
isa: 'PBXFileSystemSynchronizedBuildFileExceptionSet',
|
|
168
|
+
membershipExceptions: ['nativue.json'],
|
|
169
|
+
target: ids.target,
|
|
170
|
+
},
|
|
171
|
+
}),
|
|
172
|
+
[ids.sourcesPhase]: buildPhase('PBXSourcesBuildPhase'),
|
|
173
|
+
[ids.frameworksPhase]: buildPhase('PBXFrameworksBuildPhase'),
|
|
174
|
+
[ids.resourcesPhase]: buildPhase('PBXResourcesBuildPhase'),
|
|
175
|
+
[ids.target]: {
|
|
176
|
+
isa: 'PBXNativeTarget',
|
|
177
|
+
buildConfigurationList: ids.configurations,
|
|
178
|
+
buildPhases: [ids.sourcesPhase, ids.frameworksPhase, ids.resourcesPhase],
|
|
179
|
+
buildRules: [],
|
|
180
|
+
dependencies: [],
|
|
181
|
+
fileSystemSynchronizedGroups: [ids.folder],
|
|
182
|
+
name,
|
|
183
|
+
productName: name,
|
|
184
|
+
productReference: ids.product,
|
|
185
|
+
productType: 'com.apple.product-type.app-extension',
|
|
186
|
+
},
|
|
187
|
+
[ids.debug]: {
|
|
188
|
+
isa: 'XCBuildConfiguration',
|
|
189
|
+
buildSettings: extensionBuildSettings(app, extension),
|
|
190
|
+
name: 'Debug',
|
|
191
|
+
},
|
|
192
|
+
[ids.release]: {
|
|
193
|
+
isa: 'XCBuildConfiguration',
|
|
194
|
+
buildSettings: extensionBuildSettings(app, extension),
|
|
195
|
+
name: 'Release',
|
|
196
|
+
},
|
|
197
|
+
[ids.configurations]: configurationList([ids.debug, ids.release]),
|
|
198
|
+
[ids.proxy]: {
|
|
199
|
+
isa: 'PBXContainerItemProxy',
|
|
200
|
+
containerPortal: ID.project,
|
|
201
|
+
proxyType: 1,
|
|
202
|
+
remoteGlobalIDString: ids.target,
|
|
203
|
+
remoteInfo: name,
|
|
204
|
+
},
|
|
205
|
+
[ids.dependency]: { isa: 'PBXTargetDependency', target: ids.target, targetProxy: ids.proxy },
|
|
206
|
+
[ids.embedBuildFile]: {
|
|
207
|
+
isa: 'PBXBuildFile',
|
|
208
|
+
fileRef: ids.product,
|
|
209
|
+
settings: { ATTRIBUTES: ['RemoveHeadersOnCopy'] },
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function extensionComments(extensions) {
|
|
215
|
+
return Object.fromEntries(
|
|
216
|
+
extensions.flatMap(({ name, folder }) => {
|
|
217
|
+
const ids = extensionIds(name)
|
|
218
|
+
|
|
219
|
+
return [
|
|
220
|
+
[ids.product, `${name}.appex`],
|
|
221
|
+
[ids.folder, folder],
|
|
222
|
+
[ids.target, name],
|
|
223
|
+
[ids.sourcesPhase, 'Sources'],
|
|
224
|
+
[ids.frameworksPhase, 'Frameworks'],
|
|
225
|
+
[ids.resourcesPhase, 'Resources'],
|
|
226
|
+
[ids.configurations, `Build configuration list for PBXNativeTarget "${name}"`],
|
|
227
|
+
[ids.debug, 'Debug'],
|
|
228
|
+
[ids.release, 'Release'],
|
|
229
|
+
[ids.proxy, 'PBXContainerItemProxy'],
|
|
230
|
+
[ids.dependency, 'PBXTargetDependency'],
|
|
231
|
+
[ids.embedBuildFile, `${name}.appex in Embed Foundation Extensions`],
|
|
232
|
+
[ids.settingsException, `Exceptions for "${folder}" folder in "${name}" target`],
|
|
233
|
+
]
|
|
234
|
+
}),
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The app's objects, then each extension's; the app embeds them, built first. */
|
|
239
|
+
function projectObjects(app, hasEntitlements, extensions) {
|
|
240
|
+
const objects = appObjects(app, hasEntitlements)
|
|
241
|
+
const ids = extensions.map(({ name }) => extensionIds(name))
|
|
242
|
+
|
|
243
|
+
if (extensions.length === 0) return objects
|
|
244
|
+
|
|
245
|
+
const appTarget = objects[ID.target]
|
|
246
|
+
|
|
247
|
+
objects[ID.mainGroup].children.splice(1, 0, ...ids.map(({ folder }) => folder))
|
|
248
|
+
objects[ID.productsGroup].children.push(...ids.map(({ product }) => product))
|
|
249
|
+
objects[ID.project].targets.push(...ids.map(({ target }) => target))
|
|
250
|
+
appTarget.buildPhases.push(ID.embedExtensionsPhase)
|
|
251
|
+
appTarget.dependencies.push(...ids.map(({ dependency }) => dependency))
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
...objects,
|
|
255
|
+
[ID.embedExtensionsPhase]: {
|
|
256
|
+
...buildPhase('PBXCopyFilesBuildPhase'),
|
|
257
|
+
dstPath: '',
|
|
258
|
+
dstSubfolderSpec: PLUGINS_FOLDER,
|
|
259
|
+
files: ids.map(({ embedBuildFile }) => embedBuildFile),
|
|
260
|
+
name: 'Embed Foundation Extensions',
|
|
261
|
+
},
|
|
262
|
+
...Object.assign({}, ...extensions.map((extension) => extensionObjects(app, extension))),
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function appObjects(app, hasEntitlements) {
|
|
267
|
+
return {
|
|
268
|
+
[ID.pluginsBuildFile]: { isa: 'PBXBuildFile', productRef: ID.pluginsProduct },
|
|
269
|
+
[ID.product]: {
|
|
270
|
+
isa: 'PBXFileReference',
|
|
271
|
+
explicitFileType: 'wrapper.application',
|
|
272
|
+
includeInIndex: 0,
|
|
273
|
+
path: 'App.app',
|
|
274
|
+
sourceTree: 'BUILT_PRODUCTS_DIR',
|
|
275
|
+
},
|
|
276
|
+
[ID.appFolder]: {
|
|
277
|
+
isa: 'PBXFileSystemSynchronizedRootGroup',
|
|
278
|
+
path: 'App',
|
|
279
|
+
sourceTree: '<group>',
|
|
280
|
+
},
|
|
281
|
+
[ID.frameworksPhase]: {
|
|
282
|
+
...buildPhase('PBXFrameworksBuildPhase'),
|
|
283
|
+
files: [ID.pluginsBuildFile],
|
|
284
|
+
},
|
|
285
|
+
[ID.mainGroup]: {
|
|
286
|
+
isa: 'PBXGroup',
|
|
287
|
+
children: [ID.appFolder, ID.productsGroup],
|
|
288
|
+
sourceTree: '<group>',
|
|
289
|
+
},
|
|
290
|
+
[ID.productsGroup]: {
|
|
291
|
+
isa: 'PBXGroup',
|
|
292
|
+
children: [ID.product],
|
|
293
|
+
name: 'Products',
|
|
294
|
+
sourceTree: '<group>',
|
|
295
|
+
},
|
|
296
|
+
[ID.target]: {
|
|
297
|
+
isa: 'PBXNativeTarget',
|
|
298
|
+
buildConfigurationList: ID.targetConfigurations,
|
|
299
|
+
buildPhases: [ID.sourcesPhase, ID.frameworksPhase, ID.resourcesPhase, ID.devServerHostPhase],
|
|
300
|
+
buildRules: [],
|
|
301
|
+
dependencies: [],
|
|
302
|
+
fileSystemSynchronizedGroups: [ID.appFolder],
|
|
303
|
+
name: 'App',
|
|
304
|
+
packageProductDependencies: [ID.pluginsProduct],
|
|
305
|
+
productName: 'App',
|
|
306
|
+
productReference: ID.product,
|
|
307
|
+
productType: 'com.apple.product-type.application',
|
|
308
|
+
},
|
|
309
|
+
[ID.project]: {
|
|
310
|
+
isa: 'PBXProject',
|
|
311
|
+
attributes: {
|
|
312
|
+
BuildIndependentTargetsInParallel: 1,
|
|
313
|
+
LastSwiftUpdateCheck: 1600,
|
|
314
|
+
LastUpgradeCheck: 1600,
|
|
315
|
+
},
|
|
316
|
+
buildConfigurationList: ID.projectConfigurations,
|
|
317
|
+
developmentRegion: 'en',
|
|
318
|
+
hasScannedForEncodings: 0,
|
|
319
|
+
knownRegions: ['en', 'Base'],
|
|
320
|
+
mainGroup: ID.mainGroup,
|
|
321
|
+
minimizedProjectReferenceProxies: 1,
|
|
322
|
+
packageReferences: [ID.pluginsPackage],
|
|
323
|
+
preferredProjectObjectVersion: 77,
|
|
324
|
+
productRefGroup: ID.productsGroup,
|
|
325
|
+
projectDirPath: '',
|
|
326
|
+
projectRoot: '',
|
|
327
|
+
targets: [ID.target],
|
|
328
|
+
},
|
|
329
|
+
[ID.resourcesPhase]: buildPhase('PBXResourcesBuildPhase'),
|
|
330
|
+
[ID.devServerHostPhase]: {
|
|
331
|
+
...buildPhase('PBXShellScriptBuildPhase'),
|
|
332
|
+
alwaysOutOfDate: 1,
|
|
333
|
+
inputPaths: [],
|
|
334
|
+
name: 'Write Dev Server Host',
|
|
335
|
+
outputPaths: ['$(TARGET_BUILD_DIR)/$(UNLOCALIZED_RESOURCES_FOLDER_PATH)/dev-server-host.txt'],
|
|
336
|
+
shellPath: '/bin/sh',
|
|
337
|
+
shellScript: DEV_SERVER_HOST_SCRIPT,
|
|
338
|
+
},
|
|
339
|
+
[ID.sourcesPhase]: buildPhase('PBXSourcesBuildPhase'),
|
|
340
|
+
[ID.projectDebug]: {
|
|
341
|
+
isa: 'XCBuildConfiguration',
|
|
342
|
+
buildSettings: {
|
|
343
|
+
ALWAYS_SEARCH_USER_PATHS: 'NO',
|
|
344
|
+
ENABLE_TESTABILITY: 'YES',
|
|
345
|
+
IPHONEOS_DEPLOYMENT_TARGET: DEPLOYMENT_TARGET,
|
|
346
|
+
ONLY_ACTIVE_ARCH: 'YES',
|
|
347
|
+
SDKROOT: 'iphoneos',
|
|
348
|
+
SWIFT_ACTIVE_COMPILATION_CONDITIONS: 'DEBUG',
|
|
349
|
+
SWIFT_OPTIMIZATION_LEVEL: '-Onone',
|
|
350
|
+
SWIFT_VERSION: '5.0',
|
|
351
|
+
},
|
|
352
|
+
name: 'Debug',
|
|
353
|
+
},
|
|
354
|
+
[ID.projectRelease]: {
|
|
355
|
+
isa: 'XCBuildConfiguration',
|
|
356
|
+
buildSettings: {
|
|
357
|
+
ALWAYS_SEARCH_USER_PATHS: 'NO',
|
|
358
|
+
IPHONEOS_DEPLOYMENT_TARGET: DEPLOYMENT_TARGET,
|
|
359
|
+
SDKROOT: 'iphoneos',
|
|
360
|
+
SWIFT_COMPILATION_MODE: 'wholemodule',
|
|
361
|
+
SWIFT_VERSION: '5.0',
|
|
362
|
+
VALIDATE_PRODUCT: 'YES',
|
|
363
|
+
},
|
|
364
|
+
name: 'Release',
|
|
365
|
+
},
|
|
366
|
+
[ID.targetDebug]: {
|
|
367
|
+
isa: 'XCBuildConfiguration',
|
|
368
|
+
buildSettings: targetBuildSettings(app, hasEntitlements),
|
|
369
|
+
name: 'Debug',
|
|
370
|
+
},
|
|
371
|
+
[ID.targetRelease]: {
|
|
372
|
+
isa: 'XCBuildConfiguration',
|
|
373
|
+
buildSettings: targetBuildSettings(app, hasEntitlements),
|
|
374
|
+
name: 'Release',
|
|
375
|
+
},
|
|
376
|
+
[ID.targetConfigurations]: configurationList([ID.targetDebug, ID.targetRelease]),
|
|
377
|
+
[ID.projectConfigurations]: configurationList([ID.projectDebug, ID.projectRelease]),
|
|
378
|
+
[ID.pluginsPackage]: { isa: 'XCLocalSwiftPackageReference', relativePath: 'NativuePlugins' },
|
|
379
|
+
[ID.pluginsProduct]: { isa: 'XCSwiftPackageProductDependency', productName: 'NativuePlugins' },
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const COMMENTS = {
|
|
384
|
+
[ID.product]: 'App.app',
|
|
385
|
+
[ID.appFolder]: 'App',
|
|
386
|
+
[ID.frameworksPhase]: 'Frameworks',
|
|
387
|
+
[ID.productsGroup]: 'Products',
|
|
388
|
+
[ID.target]: 'App',
|
|
389
|
+
[ID.sourcesPhase]: 'Sources',
|
|
390
|
+
[ID.resourcesPhase]: 'Resources',
|
|
391
|
+
[ID.project]: 'Project object',
|
|
392
|
+
[ID.targetConfigurations]: 'Build configuration list for PBXNativeTarget "App"',
|
|
393
|
+
[ID.projectConfigurations]: 'Build configuration list for PBXProject "App"',
|
|
394
|
+
[ID.projectDebug]: 'Debug',
|
|
395
|
+
[ID.projectRelease]: 'Release',
|
|
396
|
+
[ID.targetDebug]: 'Debug',
|
|
397
|
+
[ID.targetRelease]: 'Release',
|
|
398
|
+
[ID.pluginsBuildFile]: 'NativuePlugins in Frameworks',
|
|
399
|
+
[ID.pluginsPackage]: 'XCLocalSwiftPackageReference "NativuePlugins"',
|
|
400
|
+
[ID.pluginsProduct]: 'NativuePlugins',
|
|
401
|
+
[ID.devServerHostPhase]: 'Write Dev Server Host',
|
|
402
|
+
[ID.embedExtensionsPhase]: 'Embed Foundation Extensions',
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function isDictionary(value) {
|
|
406
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** The app's keys win over nativue's; dictionaries in both are merged, lists joined without repeats. */
|
|
410
|
+
function mergeDictionaries(base, overrides = {}) {
|
|
411
|
+
const keys = [...new Set([...Object.keys(base), ...Object.keys(overrides)])]
|
|
412
|
+
|
|
413
|
+
return Object.fromEntries(
|
|
414
|
+
keys.map((key) => {
|
|
415
|
+
const [value, override] = [base[key], overrides[key]]
|
|
416
|
+
const merged =
|
|
417
|
+
isDictionary(value) && isDictionary(override)
|
|
418
|
+
? mergeDictionaries(value, override)
|
|
419
|
+
: Array.isArray(value) && Array.isArray(override)
|
|
420
|
+
? [...new Set([...value, ...override])]
|
|
421
|
+
: (override ?? value)
|
|
422
|
+
|
|
423
|
+
return [key, merged]
|
|
424
|
+
}),
|
|
425
|
+
)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** nativue's keys, then the plugins', then the app's. */
|
|
429
|
+
function infoPlist(app, plugins, context) {
|
|
430
|
+
const fonts = iosFonts(appResources(app, plugins))
|
|
431
|
+
const base = { ...nativueInfoPlist(app), ...(fonts.length > 0 && { UIAppFonts: fonts }) }
|
|
432
|
+
const document = applyMods(plugins, 'ios', 'infoPlist', base, context)
|
|
433
|
+
|
|
434
|
+
return mergeDictionaries(document, app.ios.infoPlist)
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const APP_GROUPS_ENTITLEMENT = 'com.apple.security.application-groups'
|
|
438
|
+
|
|
439
|
+
function appGroupsEntitlement(app) {
|
|
440
|
+
const appGroups = app.ios.appGroups ?? []
|
|
441
|
+
|
|
442
|
+
return appGroups.length > 0 ? { [APP_GROUPS_ENTITLEMENT]: appGroups } : {}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function entitlements(app, plugins, context) {
|
|
446
|
+
const document = applyMods(plugins, 'ios', 'entitlements', appGroupsEntitlement(app), context)
|
|
447
|
+
|
|
448
|
+
return mergeDictionaries(document, app.ios.entitlements)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function readSettings(path) {
|
|
452
|
+
try {
|
|
453
|
+
return JSON.parse(readFileSync(path, 'utf8'))
|
|
454
|
+
} catch (error) {
|
|
455
|
+
throw new Error(`${path}: ${error.message}`, { cause: error })
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** native/extensions/<name>: an extension of the app, set up by its nativue.json. */
|
|
460
|
+
function appExtensions(appDirectory) {
|
|
461
|
+
const directory = join(appDirectory, 'native', 'extensions')
|
|
462
|
+
// statSync follows links: a linked folder is an extension too.
|
|
463
|
+
const names = readdirSync(directory).filter((name) =>
|
|
464
|
+
statSync(join(directory, name)).isDirectory(),
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
return names.map((name) => {
|
|
468
|
+
const settingsPath = join(directory, name, 'nativue.json')
|
|
469
|
+
|
|
470
|
+
if (!existsSync(settingsPath)) {
|
|
471
|
+
throw new Error(
|
|
472
|
+
`native/extensions/${name} needs a nativue.json: { "ios": { "target": { "type": "widget", "bundleIdSuffix": ".${name}" } } }`,
|
|
473
|
+
)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// The folder sets the name and the sources, whatever nativue.json says.
|
|
477
|
+
return {
|
|
478
|
+
...readSettings(settingsPath).ios?.target,
|
|
479
|
+
name,
|
|
480
|
+
sources: join(directory, name),
|
|
481
|
+
hasSettingsFile: true,
|
|
482
|
+
}
|
|
483
|
+
})
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** The plugins' targets mods, then the app's own extensions. */
|
|
487
|
+
export function extensionTargets(app, plugins, context) {
|
|
488
|
+
const fromPlugins = applyMods(plugins, 'ios', 'targets', [], context)
|
|
489
|
+
const fromApp = existsSync(join(context.projectRoot, 'native', 'extensions'))
|
|
490
|
+
? appExtensions(context.projectRoot)
|
|
491
|
+
: []
|
|
492
|
+
|
|
493
|
+
const targets = [...fromPlugins, ...fromApp]
|
|
494
|
+
|
|
495
|
+
validateExtensionTargets(targets, {
|
|
496
|
+
appDirectory: context.projectRoot,
|
|
497
|
+
appGroups: app.ios.appGroups,
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
return targets
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function extensionInfoPlist(target) {
|
|
504
|
+
const base = { NSExtension: { NSExtensionPointIdentifier: EXTENSION_POINTS[target.type] } }
|
|
505
|
+
|
|
506
|
+
return mergeDictionaries(base, target.infoPlist)
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function extensionEntitlements(app, target) {
|
|
510
|
+
return mergeDictionaries(target.appGroups ? appGroupsEntitlement(app) : {}, target.entitlements)
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* The target's buildable folder: Extensions/<name>, a link to its sources, as NativuePlugins links
|
|
515
|
+
* the packages' Swift. Xcode builds and archives through it, and picks up edits to the sources.
|
|
516
|
+
*/
|
|
517
|
+
function extensionFolder(target, appDirectory) {
|
|
518
|
+
const folder = `Extensions/${target.name}`
|
|
519
|
+
const sources = resolve(appDirectory, target.sources)
|
|
520
|
+
const link = toPosixPath(relative(join(appDirectory, 'ios', 'Extensions'), sources))
|
|
521
|
+
|
|
522
|
+
return { folder, files: { [folder]: { symlink: link } } }
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function extensionFiles(app, extensions) {
|
|
526
|
+
return Object.assign(
|
|
527
|
+
{},
|
|
528
|
+
...extensions.map((extension) => ({
|
|
529
|
+
[extensionSupportPath(extension.name, 'Info.plist')]: plist(extensionInfoPlist(extension)),
|
|
530
|
+
...(extension.hasEntitlements && {
|
|
531
|
+
[extensionSupportPath(extension.name, `${extension.name}.entitlements`)]: plist(
|
|
532
|
+
extensionEntitlements(app, extension),
|
|
533
|
+
),
|
|
534
|
+
}),
|
|
535
|
+
...extension.files,
|
|
536
|
+
})),
|
|
537
|
+
)
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function nativueInfoPlist(app) {
|
|
541
|
+
return {
|
|
542
|
+
CFBundleURLTypes: [
|
|
543
|
+
{ CFBundleURLName: app.ios.bundleIdentifier, CFBundleURLSchemes: app.schemes },
|
|
544
|
+
],
|
|
545
|
+
NSAppTransportSecurity: { NSAllowsLocalNetworking: true },
|
|
546
|
+
NSLocalNetworkUsageDescription:
|
|
547
|
+
'Connects to the Nativue dev server on your Mac for hot reload.',
|
|
548
|
+
UILaunchScreen: { UIColorName: 'LaunchBackground', UIImageName: 'LaunchLogo' },
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const DARK_APPEARANCE = [{ appearance: 'luminosity', value: 'dark' }]
|
|
553
|
+
const ASSET_INFO = { author: 'xcode', version: 1 }
|
|
554
|
+
|
|
555
|
+
function assetJson(contents) {
|
|
556
|
+
return `${JSON.stringify(contents, null, 2)}\n`
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function colorComponents(hex) {
|
|
560
|
+
const [red, green, blue] = [1, 3, 5].map((start) =>
|
|
561
|
+
(parseInt(hex.slice(start, start + 2), 16) / 255).toFixed(3),
|
|
562
|
+
)
|
|
563
|
+
|
|
564
|
+
return { 'color-space': 'srgb', components: { red, green, blue, alpha: '1.000' } }
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function launchBackground(splash) {
|
|
568
|
+
return assetJson({
|
|
569
|
+
colors: [
|
|
570
|
+
{ color: colorComponents(splash.backgroundColor), idiom: 'universal' },
|
|
571
|
+
{
|
|
572
|
+
appearances: DARK_APPEARANCE,
|
|
573
|
+
color: colorComponents(splash.darkBackgroundColor),
|
|
574
|
+
idiom: 'universal',
|
|
575
|
+
},
|
|
576
|
+
],
|
|
577
|
+
info: ASSET_INFO,
|
|
578
|
+
})
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** The template's logo, or the app's: one 360px image, shown at 120 points (@3x). */
|
|
582
|
+
function launchLogoFiles(splash, readAppFile) {
|
|
583
|
+
if (!splash.image) return {}
|
|
584
|
+
|
|
585
|
+
const directory = `${ASSETS}/LaunchLogo.imageset`
|
|
586
|
+
const removed = Object.fromEntries(
|
|
587
|
+
TEMPLATE_LAUNCH_LOGOS.map((file) => [`${directory}/${file}`, null]),
|
|
588
|
+
)
|
|
589
|
+
const contents = {
|
|
590
|
+
images: [
|
|
591
|
+
{ filename: 'logo@3x.png', idiom: 'universal', scale: '3x' },
|
|
592
|
+
{
|
|
593
|
+
appearances: DARK_APPEARANCE,
|
|
594
|
+
filename: 'logo-dark@3x.png',
|
|
595
|
+
idiom: 'universal',
|
|
596
|
+
scale: '3x',
|
|
597
|
+
},
|
|
598
|
+
],
|
|
599
|
+
info: ASSET_INFO,
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
return {
|
|
603
|
+
...removed,
|
|
604
|
+
[`${directory}/Contents.json`]: assetJson(contents),
|
|
605
|
+
[`${directory}/logo@3x.png`]: { content: readAppFile(splash.image) },
|
|
606
|
+
[`${directory}/logo-dark@3x.png`]: { content: readAppFile(splash.darkImage) },
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** In the app's buildable folder, so Xcode copies them to the bundle's root. */
|
|
611
|
+
function resourceFiles(resources, readAppFile) {
|
|
612
|
+
return Object.fromEntries(
|
|
613
|
+
resources
|
|
614
|
+
.filter(({ ios }) => ios)
|
|
615
|
+
.map(({ source, ios }) => [
|
|
616
|
+
`App/Resources/${ios.destination}`,
|
|
617
|
+
{ content: readAppFile(source) },
|
|
618
|
+
]),
|
|
619
|
+
)
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/** Paths relative to ios/. */
|
|
623
|
+
export function iosProjectFiles(app, appDirectory, plugins = []) {
|
|
624
|
+
const readAppFile = (path) => readFileSync(resolve(appDirectory, path))
|
|
625
|
+
const context = { config: app, projectRoot: appDirectory }
|
|
626
|
+
const appEntitlements = entitlements(app, plugins, context)
|
|
627
|
+
const hasEntitlements = Object.keys(appEntitlements).length > 0
|
|
628
|
+
const extensions = extensionTargets(app, plugins, context).map((target) => ({
|
|
629
|
+
...target,
|
|
630
|
+
hasEntitlements: Object.keys(extensionEntitlements(app, target)).length > 0,
|
|
631
|
+
...extensionFolder(target, appDirectory),
|
|
632
|
+
}))
|
|
633
|
+
const project = {
|
|
634
|
+
objectVersion: 77,
|
|
635
|
+
objects: projectObjects(app, hasEntitlements, extensions),
|
|
636
|
+
rootObject: ID.project,
|
|
637
|
+
comments: { ...COMMENTS, ...extensionComments(extensions) },
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
return {
|
|
641
|
+
'App.xcodeproj/project.pbxproj': pbxproj(project),
|
|
642
|
+
'Info.plist': plist(infoPlist(app, plugins, context)),
|
|
643
|
+
...(hasEntitlements && { [ENTITLEMENTS_FILE]: plist(appEntitlements) }),
|
|
644
|
+
...(app.icon && {
|
|
645
|
+
[`${ASSETS}/AppIcon.appiconset/icon.png`]: { content: readAppFile(app.icon) },
|
|
646
|
+
}),
|
|
647
|
+
[`${ASSETS}/LaunchBackground.colorset/Contents.json`]: launchBackground(app.splash),
|
|
648
|
+
...launchLogoFiles(app.splash, readAppFile),
|
|
649
|
+
...resourceFiles(appResources(app, plugins), readAppFile),
|
|
650
|
+
...extensionFiles(app, extensions),
|
|
651
|
+
}
|
|
652
|
+
}
|