bundo-appgen 0.0.1-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +253 -0
- package/bin.mjs +21 -0
- package/lib/bin/bin.mjs +1141 -0
- package/lib/bin/plugin-sandbox-runner.mjs +105 -0
- package/lib/commonjs/index.js +125 -0
- package/lib/module/chunk-bhc5nymd.js +12 -0
- package/lib/module/chunk-dvyy3g4j.js +25 -0
- package/lib/module/chunk-ynqw05p0.js +70 -0
- package/lib/module/config/apple/create-osx-appiconset.js +6 -0
- package/lib/module/config/apple/index.js +7 -0
- package/lib/module/config/index.js +8 -0
- package/lib/module/index.js +8 -0
- package/lib/typescript/config/apple/asset-catalog-format/app-icon/index.d.ts +3 -0
- package/lib/typescript/config/apple/asset-catalog-format/app-icon/index.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/app-icon/set-type.d.ts +42 -0
- package/lib/typescript/config/apple/asset-catalog-format/app-icon/set-type.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/app-icon/size.d.ts +21 -0
- package/lib/typescript/config/apple/asset-catalog-format/app-icon/size.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/appearances.d.ts +13 -0
- package/lib/typescript/config/apple/asset-catalog-format/appearances.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/idiom.d.ts +5 -0
- package/lib/typescript/config/apple/asset-catalog-format/idiom.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/color-space.d.ts +2 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/color-space.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/compression-type.d.ts +2 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/compression-type.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/display-gamut.d.ts +2 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/display-gamut.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/index.d.ts +6 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/index.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/language-direction.d.ts +2 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/language-direction.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/scale.d.ts +9 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/scale.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/set-type.d.ts +58 -0
- package/lib/typescript/config/apple/asset-catalog-format/image/set-type.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalog-format/index.d.ts +5 -0
- package/lib/typescript/config/apple/asset-catalog-format/index.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalogs-namespaced.d.ts +5 -0
- package/lib/typescript/config/apple/asset-catalogs-namespaced.d.ts.map +1 -0
- package/lib/typescript/config/apple/asset-catalogs.d.ts +73 -0
- package/lib/typescript/config/apple/asset-catalogs.d.ts.map +1 -0
- package/lib/typescript/config/apple/create-osx-appiconset.d.mts +72 -0
- package/lib/typescript/config/apple/create-osx-appiconset.d.mts.map +1 -0
- package/lib/typescript/config/apple/data.d.ts +103 -0
- package/lib/typescript/config/apple/data.d.ts.map +1 -0
- package/lib/typescript/config/apple/index.d.mts +8 -0
- package/lib/typescript/config/apple/index.d.mts.map +1 -0
- package/lib/typescript/config/apple/info-plist-value.d.ts +8 -0
- package/lib/typescript/config/apple/info-plist-value.d.ts.map +1 -0
- package/lib/typescript/config/apple/info-plist.d.ts +4 -0
- package/lib/typescript/config/apple/info-plist.d.ts.map +1 -0
- package/lib/typescript/config/apple/string-catalog.d.ts +2 -0
- package/lib/typescript/config/apple/string-catalog.d.ts.map +1 -0
- package/lib/typescript/config/data.d.ts +50 -0
- package/lib/typescript/config/data.d.ts.map +1 -0
- package/lib/typescript/config/index.d.mts +5 -0
- package/lib/typescript/config/index.d.mts.map +1 -0
- package/lib/typescript/config/plugin-item.d.ts +2 -0
- package/lib/typescript/config/plugin-item.d.ts.map +1 -0
- package/lib/typescript/config/plugin-registry.d.ts +3 -0
- package/lib/typescript/config/plugin-registry.d.ts.map +1 -0
- package/lib/typescript/index.d.mts +3 -0
- package/lib/typescript/index.d.mts.map +1 -0
- package/lib/typescript/plugin/apple/context.d.ts +28 -0
- package/lib/typescript/plugin/apple/context.d.ts.map +1 -0
- package/lib/typescript/plugin/apple/files.d.ts +7 -0
- package/lib/typescript/plugin/apple/files.d.ts.map +1 -0
- package/lib/typescript/plugin/apple/index.d.ts +6 -0
- package/lib/typescript/plugin/apple/index.d.ts.map +1 -0
- package/lib/typescript/plugin/apple/pod-spec-source-from-cocoapods.d.ts +5 -0
- package/lib/typescript/plugin/apple/pod-spec-source-from-cocoapods.d.ts.map +1 -0
- package/lib/typescript/plugin/apple/pod-spec-source-from-git.d.ts +11 -0
- package/lib/typescript/plugin/apple/pod-spec-source-from-git.d.ts.map +1 -0
- package/lib/typescript/plugin/apple/pod-spec-source-from-local.d.ts +7 -0
- package/lib/typescript/plugin/apple/pod-spec-source-from-local.d.ts.map +1 -0
- package/lib/typescript/plugin/context.d.ts +9 -0
- package/lib/typescript/plugin/context.d.ts.map +1 -0
- package/lib/typescript/plugin/index.d.ts +3 -0
- package/lib/typescript/plugin/index.d.ts.map +1 -0
- package/package.json +49 -0
- package/src/_bin/_global-vars/_global-vars.mts +47 -0
- package/src/_bin/_global-vars/index.mts +30 -0
- package/src/_bin/_main/_check-config-validity.mts +94 -0
- package/src/_bin/_main/_evaluate-plugin-registry.mts +181 -0
- package/src/_bin/_main/_exec-plugin-runner/_spawn-plugin-sandbox-runner.mts +149 -0
- package/src/_bin/_main/_exec-plugin-runner/exec-plugin-runner.mts +92 -0
- package/src/_bin/_main/_exec-plugin-runner/index.mts +1 -0
- package/src/_bin/_main/_get-config.mts +64 -0
- package/src/_bin/_main/_helpers/config/get-name.mts +24 -0
- package/src/_bin/_main/_helpers/config/get-project-name.mts +27 -0
- package/src/_bin/_main/_helpers/config/index.mts +2 -0
- package/src/_bin/_main/_helpers/index.mts +2 -0
- package/src/_bin/_main/_helpers/platform/compatibility-error.mts +7 -0
- package/src/_bin/_main/_helpers/platform/data.ts +9 -0
- package/src/_bin/_main/_helpers/platform/get-data.mts +48 -0
- package/src/_bin/_main/_helpers/platform/index.mts +4 -0
- package/src/_bin/_main/_helpers/platform/is-compatible.mts +30 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_init-appiconsets.mts +223 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_init-imagesets.mts +241 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_metadata-check/appearances.mts +24 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_metadata-check/idiom.mts +22 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_metadata-check/image/compression-type.mts +15 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_metadata-check/image/display-gamut.mts +12 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_metadata-check/image/index.mts +3 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_metadata-check/image/language-direction.mts +12 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/_metadata-check/index.mts +3 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/create-asset-catalogs.mts +54 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-asset-catalogs/index.mts +1 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-string-catalogs/create-string-catalog.mts +134 -0
- package/src/_bin/_main/_init-template/_init-apple/_create-string-catalogs/index.mts +1 -0
- package/src/_bin/_main/_init-template/_init-apple/_mod-files/_app-delegate-swift.mts +62 -0
- package/src/_bin/_main/_init-template/_init-apple/_mod-files/_podfile.mts +31 -0
- package/src/_bin/_main/_init-template/_init-apple/_mod-files/index.mts +1 -0
- package/src/_bin/_main/_init-template/_init-apple/_mod-files/mod-files.mts +17 -0
- package/src/_bin/_main/_init-template/_init-apple/index.mts +1 -0
- package/src/_bin/_main/_init-template/_init-apple/init-apple.mts +81 -0
- package/src/_bin/_main/_init-template/index.mts +1 -0
- package/src/_bin/_main/_init-template/init-template.mts +39 -0
- package/src/_bin/_main/_mod-plugin/index.mts +1 -0
- package/src/_bin/_main/_mod-plugin/mod-plugin.mts +77 -0
- package/src/_bin/_main/_xcodegen/_create-project-spec/_init-resources.mts +86 -0
- package/src/_bin/_main/_xcodegen/_create-project-spec/create-project-spec.mts +216 -0
- package/src/_bin/_main/_xcodegen/_create-project-spec/index.mts +1 -0
- package/src/_bin/_main/_xcodegen/_mod-known-regions/index.ts +1 -0
- package/src/_bin/_main/_xcodegen/_mod-known-regions/mod-known-regions.mts +52 -0
- package/src/_bin/_main/_xcodegen/index.mts +1 -0
- package/src/_bin/_main/_xcodegen/xcodegen.mts +46 -0
- package/src/_bin/_main/index.mts +1 -0
- package/src/_bin/_main/main.mts +160 -0
- package/src/_bin/bin.mts +68 -0
- package/src/_bin/plugin-sandbox-runner/_exec-plugins.mts +135 -0
- package/src/_bin/plugin-sandbox-runner/argv-json.ts +20 -0
- package/src/_bin/plugin-sandbox-runner/evaluated-plugin-registry.ts +12 -0
- package/src/_bin/plugin-sandbox-runner/index.ts +3 -0
- package/src/_bin/plugin-sandbox-runner/plugin-runner-context-result.ts +33 -0
- package/src/_bin/plugin-sandbox-runner/plugin-sandbox-runner.mts +68 -0
- package/src/config/apple/asset-catalog-format/app-icon/index.ts +2 -0
- package/src/config/apple/asset-catalog-format/app-icon/set-type.ts +59 -0
- package/src/config/apple/asset-catalog-format/app-icon/size.ts +37 -0
- package/src/config/apple/asset-catalog-format/appearances.ts +10 -0
- package/src/config/apple/asset-catalog-format/idiom.ts +16 -0
- package/src/config/apple/asset-catalog-format/image/color-space.ts +3 -0
- package/src/config/apple/asset-catalog-format/image/compression-type.ts +6 -0
- package/src/config/apple/asset-catalog-format/image/display-gamut.ts +3 -0
- package/src/config/apple/asset-catalog-format/image/index.ts +6 -0
- package/src/config/apple/asset-catalog-format/image/language-direction.ts +3 -0
- package/src/config/apple/asset-catalog-format/image/scale.ts +11 -0
- package/src/config/apple/asset-catalog-format/image/set-type.ts +85 -0
- package/src/config/apple/asset-catalog-format/index.ts +4 -0
- package/src/config/apple/asset-catalogs-namespaced.ts +13 -0
- package/src/config/apple/asset-catalogs.ts +76 -0
- package/src/config/apple/create-osx-appiconset.mts +135 -0
- package/src/config/apple/data.ts +123 -0
- package/src/config/apple/index.mts +7 -0
- package/src/config/apple/info-plist-value.ts +16 -0
- package/src/config/apple/info-plist.ts +6 -0
- package/src/config/apple/string-catalog.ts +0 -0
- package/src/config/data.ts +59 -0
- package/src/config/index.mts +4 -0
- package/src/config/plugin-item.ts +4 -0
- package/src/config/plugin-registry.ts +5 -0
- package/src/index.mts +2 -0
- package/src/plugin/apple/context.ts +68 -0
- package/src/plugin/apple/files.ts +14 -0
- package/src/plugin/apple/index.ts +5 -0
- package/src/plugin/apple/pod-spec-source-from-cocoapods.ts +9 -0
- package/src/plugin/apple/pod-spec-source-from-git.ts +13 -0
- package/src/plugin/apple/pod-spec-source-from-local.ts +6 -0
- package/src/plugin/context.ts +12 -0
- package/src/plugin/index.ts +2 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import * as node_fs from "node:fs"
|
|
2
|
+
import * as node_module from "node:module"
|
|
3
|
+
import * as node_path from "node:path"
|
|
4
|
+
|
|
5
|
+
import type * as Config from "../../../../config/index.mts"
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
GlobalVars,
|
|
9
|
+
} from "../../../_global-vars/index.mts"
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
ConfigHelpers,
|
|
13
|
+
} from "../../_helpers/index.mts"
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
initResources,
|
|
17
|
+
} from "./_init-resources.mts"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create `project.json` file in the "<project>/macos" directory.
|
|
21
|
+
*/
|
|
22
|
+
export function createProjectSpec(
|
|
23
|
+
platform: "macos" | "ios",
|
|
24
|
+
overrideConfig?: {
|
|
25
|
+
infoPlist?: Config.Apple.Data["infoPlist"],
|
|
26
|
+
},
|
|
27
|
+
) {
|
|
28
|
+
|
|
29
|
+
const
|
|
30
|
+
projectDirectory =
|
|
31
|
+
node_path.dirname(GlobalVars.configFilePath.get()),
|
|
32
|
+
|
|
33
|
+
nativeProjectDir =
|
|
34
|
+
node_path.join(projectDirectory, platform)
|
|
35
|
+
|
|
36
|
+
// just in case if the projectDirectory doesn't exist
|
|
37
|
+
if(!node_fs.existsSync(projectDirectory)) {
|
|
38
|
+
throw new Error(`An unexpected happened. ${projectDirectory} was not found.`)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const
|
|
42
|
+
config =
|
|
43
|
+
GlobalVars.appConfig.get()
|
|
44
|
+
|
|
45
|
+
// TODO : also check for "ios"
|
|
46
|
+
if(
|
|
47
|
+
config.macos?.appicon &&
|
|
48
|
+
(
|
|
49
|
+
!config.macos.assetCatalogs?.appiconsets?.length ||
|
|
50
|
+
!config.macos.assetCatalogs.appiconsets.some(set => set.name == config.macos?.appicon)
|
|
51
|
+
)
|
|
52
|
+
) {
|
|
53
|
+
// check if the appicon name is exist
|
|
54
|
+
throw new Error(`No appicon with the name "${config.macos.appicon}" was found in the appiconsets in Asset Catalogs.`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if(
|
|
58
|
+
(platform == "macos" && !config.macos)
|
|
59
|
+
// TODO : "ios"
|
|
60
|
+
) {
|
|
61
|
+
throw new Error(`${platform} configuration was not found.`)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const
|
|
65
|
+
requireFromNativeDirectory =
|
|
66
|
+
node_module.createRequire(nativeProjectDir),
|
|
67
|
+
|
|
68
|
+
reactNativeXcodeScriptRelativePath =
|
|
69
|
+
node_path.relative(
|
|
70
|
+
nativeProjectDir,
|
|
71
|
+
platform == "macos"
|
|
72
|
+
? requireFromNativeDirectory.resolve("react-native-macos/scripts/react-native-xcode.sh")
|
|
73
|
+
: requireFromNativeDirectory.resolve("react-native/scripts/react-native-xcode.sh"),
|
|
74
|
+
),
|
|
75
|
+
|
|
76
|
+
appleData: Config.Apple.Data =
|
|
77
|
+
// Intentionally asserted as "macos"
|
|
78
|
+
// TODO : "ios"
|
|
79
|
+
{
|
|
80
|
+
...config[platform as "macos"]!,
|
|
81
|
+
infoPlist: {
|
|
82
|
+
...overrideConfig?.infoPlist,
|
|
83
|
+
...config[platform as "macos"]!.infoPlist, // client's infoPlist takes precedence over the plugin
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
projectName =
|
|
88
|
+
ConfigHelpers.getProjectName(config, platform)!, // already validated
|
|
89
|
+
|
|
90
|
+
resourcesData =
|
|
91
|
+
initResources(
|
|
92
|
+
config.macos?.resources,
|
|
93
|
+
{
|
|
94
|
+
platform,
|
|
95
|
+
},
|
|
96
|
+
),
|
|
97
|
+
|
|
98
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* See https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md
|
|
102
|
+
*/
|
|
103
|
+
json: Record<string, any> =
|
|
104
|
+
{
|
|
105
|
+
|
|
106
|
+
name: projectName,
|
|
107
|
+
|
|
108
|
+
// https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#target
|
|
109
|
+
targets: {
|
|
110
|
+
[projectName]: {
|
|
111
|
+
type: "application",
|
|
112
|
+
platform: platform == "macos" ? "macOS" : "iOS",
|
|
113
|
+
deploymentTarget: appleData.minimumDeployment || "15.6",
|
|
114
|
+
sources: [
|
|
115
|
+
{
|
|
116
|
+
path: projectName,
|
|
117
|
+
type: "syncedFolder",
|
|
118
|
+
},
|
|
119
|
+
...(resourcesData?.map(resource => {
|
|
120
|
+
/**
|
|
121
|
+
* The path "Resources" is just our group, and also our custom directory,
|
|
122
|
+
* not an actual bundle resource directory content of macOS app, e.g. /Applications/HelloWorld.app/Contents/Resources.
|
|
123
|
+
* The naming is purely a coincidence.
|
|
124
|
+
*
|
|
125
|
+
* We intentionally to copy user files to our directory called "Resources".
|
|
126
|
+
* Any user files will be copied to our "Resources" directory.
|
|
127
|
+
*
|
|
128
|
+
* See placing content in a bundle
|
|
129
|
+
* https://developer.apple.com/documentation/bundleresources/placing-content-in-a-bundle?language=objc
|
|
130
|
+
*/
|
|
131
|
+
return {
|
|
132
|
+
path: "Resources",
|
|
133
|
+
buildPhase: {
|
|
134
|
+
copyFiles: {
|
|
135
|
+
destination: "resources",
|
|
136
|
+
subpath: resource.isDirectory
|
|
137
|
+
? resource.basename
|
|
138
|
+
: undefined,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
}) ?? []),
|
|
143
|
+
],
|
|
144
|
+
info: {
|
|
145
|
+
path: `${projectName}/Info.plist`,
|
|
146
|
+
properties: {
|
|
147
|
+
CFBundleDisplayName: ConfigHelpers.getName(config, platform),
|
|
148
|
+
CFBundleShortVersionString: "$(MARKETING_VERSION)",
|
|
149
|
+
CFBundleVersion: "$(CURRENT_PROJECT_VERSION)",
|
|
150
|
+
NSAppTransportSecurity: {
|
|
151
|
+
NSAllowsArbitraryLoads: true,
|
|
152
|
+
NSExceptionDomains: {
|
|
153
|
+
localhost: {
|
|
154
|
+
NSExceptionAllowsInsecureHTTPLoads: true,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
NSPrincipalClass: "NSApplication",
|
|
159
|
+
NSSupportsAutomaticTermination: true,
|
|
160
|
+
NSSupportsSuddenTermination: true,
|
|
161
|
+
// Let user override these properties
|
|
162
|
+
...appleData.infoPlist,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
postBuildScripts: [
|
|
166
|
+
{
|
|
167
|
+
name: "Bundle React Native code and images",
|
|
168
|
+
script: `export NODE_BINARY=node\n${reactNativeXcodeScriptRelativePath}`,
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
|
|
172
|
+
scheme: {},
|
|
173
|
+
|
|
174
|
+
settings: {
|
|
175
|
+
ASSETCATALOG_COMPILER_APPICON_NAME: appleData.appicon,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Settings correspond to Build Settings tab in Xcode.
|
|
182
|
+
*
|
|
183
|
+
* See {@link https://developer.apple.com/documentation/xcode/build-settings-reference|Build settings reference} for complete detailed list of individual Xcode build settings that control or change the way a target is built.
|
|
184
|
+
*
|
|
185
|
+
* @see https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#settings
|
|
186
|
+
*/
|
|
187
|
+
settings: {
|
|
188
|
+
base: {
|
|
189
|
+
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS: true,
|
|
190
|
+
CODE_SIGN_STYLE: "Automatic",
|
|
191
|
+
CURRENT_PROJECT_VERSION: appleData.buildVersion || "1",
|
|
192
|
+
GENERATE_INFOPLIST_FILE: true,
|
|
193
|
+
LD_RUNPATH_SEARCH_PATHS: "$(inherited) @executable_path/Frameworks",
|
|
194
|
+
MARKETING_VERSION: appleData.version || "1.0.0",
|
|
195
|
+
OTHER_LDFLAGS: "$(inherited) -ObjC -lc++",
|
|
196
|
+
PRODUCT_BUNDLE_IDENTIFIER: appleData.bundleIdentifier,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
options: {
|
|
201
|
+
useBaseInternationalization: false,
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
207
|
+
|
|
208
|
+
node_fs.writeFileSync(
|
|
209
|
+
node_path.join(
|
|
210
|
+
nativeProjectDir, "project.json",
|
|
211
|
+
),
|
|
212
|
+
JSON.stringify(json, null, 2),
|
|
213
|
+
"utf8",
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./create-project-spec.mts"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mod-known-regions.mts"
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as node_fs from "node:fs"
|
|
2
|
+
import * as node_path from "node:path"
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GlobalVars,
|
|
6
|
+
} from "../../../_global-vars/index.mts"
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
ConfigHelpers,
|
|
10
|
+
} from "../../_helpers/index.mts"
|
|
11
|
+
|
|
12
|
+
export function modKnownRegions(
|
|
13
|
+
platform: "macos" | "ios",
|
|
14
|
+
) {
|
|
15
|
+
const
|
|
16
|
+
config =
|
|
17
|
+
GlobalVars.appConfig.get(),
|
|
18
|
+
|
|
19
|
+
appleData =
|
|
20
|
+
config[platform as "macos"] // TODO : ios
|
|
21
|
+
|
|
22
|
+
if(!appleData?.locales?.length) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const
|
|
27
|
+
projectName =
|
|
28
|
+
ConfigHelpers.getProjectName(config, platform),
|
|
29
|
+
|
|
30
|
+
pbxprojPath =
|
|
31
|
+
node_path.join(
|
|
32
|
+
node_path.dirname(GlobalVars.configFilePath.get()),
|
|
33
|
+
platform,
|
|
34
|
+
`${projectName}.xcodeproj`,
|
|
35
|
+
"project.pbxproj",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
let file = node_fs.readFileSync(pbxprojPath, "utf8")
|
|
39
|
+
|
|
40
|
+
let strReplacer = "knownRegions = ("
|
|
41
|
+
appleData.locales.forEach(locale => {
|
|
42
|
+
strReplacer += `\n$2${locale},`
|
|
43
|
+
})
|
|
44
|
+
strReplacer += "$3"
|
|
45
|
+
|
|
46
|
+
file = file.replace(
|
|
47
|
+
/knownRegions = \((\n(\t+)\w+,)+(\n\t+\);)/,
|
|
48
|
+
strReplacer,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
node_fs.writeFileSync(pbxprojPath, file, "utf8")
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./xcodegen.mts"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as node_childProcess from "node:child_process"
|
|
2
|
+
import * as node_path from "node:path"
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GlobalVars,
|
|
6
|
+
} from "../../_global-vars/index.mts"
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
createProjectSpec,
|
|
10
|
+
} from "./_create-project-spec/index.mts"
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
modKnownRegions,
|
|
14
|
+
} from "./_mod-known-regions/mod-known-regions.mts"
|
|
15
|
+
|
|
16
|
+
export function xcodegen(
|
|
17
|
+
platform: "macos" | "ios",
|
|
18
|
+
overrideConfig?: Parameters<typeof createProjectSpec>[1],
|
|
19
|
+
) {
|
|
20
|
+
createProjectSpec(platform, overrideConfig)
|
|
21
|
+
|
|
22
|
+
const
|
|
23
|
+
xcodegenPath =
|
|
24
|
+
GlobalVars.argv.get().xcodegenPath,
|
|
25
|
+
|
|
26
|
+
nativeProjectDir =
|
|
27
|
+
node_path.join(node_path.dirname(GlobalVars.configFilePath.get()), platform)
|
|
28
|
+
|
|
29
|
+
node_childProcess.execSync(
|
|
30
|
+
`${xcodegenPath} --spec project.json`,
|
|
31
|
+
{
|
|
32
|
+
cwd: nativeProjectDir,
|
|
33
|
+
stdio: "inherit",
|
|
34
|
+
},
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
modKnownRegions(platform)
|
|
38
|
+
|
|
39
|
+
node_childProcess.execSync(
|
|
40
|
+
`pod install`,
|
|
41
|
+
{
|
|
42
|
+
cwd: nativeProjectDir,
|
|
43
|
+
stdio: "inherit",
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./main.mts"
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as node_fs from "node:fs"
|
|
2
|
+
import * as node_path from "node:path"
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GlobalVars,
|
|
6
|
+
} from "../_global-vars/index.mts"
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
checkConfigValidity,
|
|
10
|
+
} from "./_check-config-validity.mts"
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
evaluatePluginRegistry,
|
|
14
|
+
} from "./_evaluate-plugin-registry.mts"
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
execPluginRunner,
|
|
18
|
+
} from "./_exec-plugin-runner/index.mts"
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
getConfig,
|
|
22
|
+
} from "./_get-config.mts"
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
PlatformHelpers,
|
|
26
|
+
} from "./_helpers/index.mts"
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
initTemplate,
|
|
30
|
+
} from "./_init-template/index.mts"
|
|
31
|
+
|
|
32
|
+
import {
|
|
33
|
+
modPlugin,
|
|
34
|
+
} from "./_mod-plugin/index.mts"
|
|
35
|
+
|
|
36
|
+
import {
|
|
37
|
+
xcodegen,
|
|
38
|
+
} from "./_xcodegen/index.mts"
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Perform actions in this order
|
|
42
|
+
*
|
|
43
|
+
* - Bundo Config
|
|
44
|
+
* - Get the config object from file (e.g. bundo.config.ts)
|
|
45
|
+
* - Get the path file of plugin main function including its parameter (all the plugins)
|
|
46
|
+
*
|
|
47
|
+
* - Init template directory
|
|
48
|
+
* - Copy the directory
|
|
49
|
+
* - Modify template regarding project name and other config related
|
|
50
|
+
* - (Apple)
|
|
51
|
+
* - Init Asset Catalogs from Config
|
|
52
|
+
* - (Windows): TODO
|
|
53
|
+
|
|
54
|
+
* - Plugin runner
|
|
55
|
+
* - Retrieve the result
|
|
56
|
+
*
|
|
57
|
+
* - (Apple) XcodeGen
|
|
58
|
+
* - Create XcodeGen project spec file
|
|
59
|
+
* - Run XcodeGen to generate Xcode project
|
|
60
|
+
* - Pod installation
|
|
61
|
+
*/
|
|
62
|
+
export async function main() {
|
|
63
|
+
|
|
64
|
+
PlatformHelpers.getData()
|
|
65
|
+
|
|
66
|
+
let configFilePath: string = ""
|
|
67
|
+
|
|
68
|
+
const argv = GlobalVars.argv.get()
|
|
69
|
+
|
|
70
|
+
if(argv.path) {
|
|
71
|
+
const isValidExt = isValidConfigFileExt(argv.path)
|
|
72
|
+
if(!isValidExt) {
|
|
73
|
+
throw new Error(`App config file only compatible with ${configFileExts.join(" | ")}`)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Check if the file is existed
|
|
77
|
+
const targetConfigFilePath = node_path.resolve(process.cwd(), argv.path)
|
|
78
|
+
if(!node_fs.existsSync(targetConfigFilePath)) {
|
|
79
|
+
throw new Error(`${targetConfigFilePath} file doesn't exist.`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
configFilePath = node_path.resolve(process.cwd(), argv.path)
|
|
83
|
+
} else {
|
|
84
|
+
// Find default config file
|
|
85
|
+
for(let i = 0; i < configFileExts.length; i++) {
|
|
86
|
+
const targetConfigFilePath = node_path.join(process.cwd(), `bundo.config.${configFileExts[i]}`)
|
|
87
|
+
|
|
88
|
+
if(node_fs.existsSync(targetConfigFilePath)) {
|
|
89
|
+
configFilePath = targetConfigFilePath
|
|
90
|
+
break
|
|
91
|
+
} else if(i == configFileExts.length - 1) {
|
|
92
|
+
throw new Error("Cannot found bundo config file.")
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
GlobalVars.configFilePath.set(configFilePath)
|
|
98
|
+
|
|
99
|
+
console.log("Retrieving config")
|
|
100
|
+
const config = await getConfig(configFilePath)
|
|
101
|
+
|
|
102
|
+
console.log("Validating config")
|
|
103
|
+
checkConfigValidity(config)
|
|
104
|
+
|
|
105
|
+
// Now, user app config is available globally in this appgen script at runtime
|
|
106
|
+
GlobalVars.appConfig.set(config)
|
|
107
|
+
|
|
108
|
+
console.log("Evaluating the plugin registry if any")
|
|
109
|
+
const pluginRegistry = evaluatePluginRegistry(config.plugins)
|
|
110
|
+
const unrestrictedPluginRegistry = evaluatePluginRegistry(config.lessRestrictivePlugins)
|
|
111
|
+
|
|
112
|
+
initTemplate()
|
|
113
|
+
|
|
114
|
+
const pluginSandboxedContextResult = await execPluginRunner(
|
|
115
|
+
pluginRegistry,
|
|
116
|
+
{
|
|
117
|
+
mode: "restricted",
|
|
118
|
+
},
|
|
119
|
+
)
|
|
120
|
+
const pluginContextResult = await execPluginRunner(
|
|
121
|
+
unrestrictedPluginRegistry,
|
|
122
|
+
{
|
|
123
|
+
mode: "lessRestrictive",
|
|
124
|
+
},
|
|
125
|
+
)
|
|
126
|
+
if(pluginSandboxedContextResult) {
|
|
127
|
+
modPlugin(pluginSandboxedContextResult)
|
|
128
|
+
}
|
|
129
|
+
if(pluginContextResult) {
|
|
130
|
+
modPlugin(pluginContextResult)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// TODO : "ios"
|
|
134
|
+
xcodegen(
|
|
135
|
+
"macos",
|
|
136
|
+
{
|
|
137
|
+
infoPlist: {
|
|
138
|
+
...pluginSandboxedContextResult?.macos.infoPlist,
|
|
139
|
+
...pluginContextResult?.macos.infoPlist,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const configFileExts: string[] = [
|
|
147
|
+
"ts",
|
|
148
|
+
"mts",
|
|
149
|
+
"mjs",
|
|
150
|
+
"js",
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
function isValidConfigFileExt(filePath: string): boolean {
|
|
154
|
+
const ext = node_path.extname(filePath)
|
|
155
|
+
if(!ext) {
|
|
156
|
+
// empty string from extname returned
|
|
157
|
+
return false
|
|
158
|
+
}
|
|
159
|
+
return configFileExts.indexOf(ext.slice(1)) > -1
|
|
160
|
+
}
|
package/src/_bin/bin.mts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import yargs from "yargs"
|
|
4
|
+
import * as YargsHelper from "yargs/helpers"
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
GlobalVars,
|
|
8
|
+
} from "./_global-vars/index.mts"
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
main,
|
|
12
|
+
} from "./_main/index.mts"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param bundoAppgenRoot We need the `bundoAppgenRoot` as file path to get the templates files.
|
|
16
|
+
*/
|
|
17
|
+
export async function bin(
|
|
18
|
+
bundoAppgenRoot: string,
|
|
19
|
+
) {
|
|
20
|
+
|
|
21
|
+
GlobalVars.appgenRoot.set(bundoAppgenRoot)
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const
|
|
25
|
+
argv =
|
|
26
|
+
yargs(YargsHelper.hideBin(process.argv))
|
|
27
|
+
.options({
|
|
28
|
+
"clean": {
|
|
29
|
+
type: "boolean",
|
|
30
|
+
description: "Perform clean app generation.",
|
|
31
|
+
},
|
|
32
|
+
"force-cross-platform": {
|
|
33
|
+
type: "boolean",
|
|
34
|
+
description: "Experimentally force the script to init native app in non compatible OS.",
|
|
35
|
+
},
|
|
36
|
+
"path": {
|
|
37
|
+
alias: "p",
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "Use specific configuration file target.",
|
|
40
|
+
},
|
|
41
|
+
"xcodegen-path": {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "Use specific XcodeGen binary.",
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
.parseSync()
|
|
47
|
+
|
|
48
|
+
GlobalVars.argv.set({
|
|
49
|
+
clean: !!argv.clean,
|
|
50
|
+
forceCrossPlatform: !!argv["force-cross-platform"],
|
|
51
|
+
path: argv.path || "",
|
|
52
|
+
xcodegenPath: argv["xcodegen-path"] || "xcodegen",
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
await main()
|
|
56
|
+
} catch(err) {
|
|
57
|
+
if(err instanceof Error && err.message) {
|
|
58
|
+
console.error(
|
|
59
|
+
"\x1b[31mError\x1b[0m: " +
|
|
60
|
+
err.message,
|
|
61
|
+
)
|
|
62
|
+
process.exitCode = 1
|
|
63
|
+
} else {
|
|
64
|
+
console.error("Unknown error. Please report it to https://github.com/RakaDoank/bundo.rn", { cause: err })
|
|
65
|
+
process.exitCode = 1
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as node_fs from "node:fs"
|
|
2
|
+
import * as node_path from "node:path"
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
Plugin,
|
|
6
|
+
} from "../../index.mts"
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
ArgvJSON,
|
|
10
|
+
} from "./argv-json.ts"
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
PluginRunnerContextResult,
|
|
14
|
+
} from "./plugin-runner-context-result.ts"
|
|
15
|
+
|
|
16
|
+
export async function execPlugins({
|
|
17
|
+
projectDirectory,
|
|
18
|
+
projectName,
|
|
19
|
+
registry,
|
|
20
|
+
}: {
|
|
21
|
+
projectDirectory: ArgvJSON["projectDirectory"],
|
|
22
|
+
projectName: ArgvJSON["projectName"],
|
|
23
|
+
registry: ArgvJSON["evaluatedPluginRegistry"],
|
|
24
|
+
}): Promise<PluginRunnerContextResult> {
|
|
25
|
+
|
|
26
|
+
if(!registry?.length) {
|
|
27
|
+
throw new Error("Not a valid Evaluated Plugin Registry array.")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const
|
|
31
|
+
paths =
|
|
32
|
+
{
|
|
33
|
+
templates: {
|
|
34
|
+
macos: node_path.join(
|
|
35
|
+
projectDirectory,
|
|
36
|
+
"macos",
|
|
37
|
+
),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
contextResult: PluginRunnerContextResult =
|
|
42
|
+
{
|
|
43
|
+
macos: {
|
|
44
|
+
files: {
|
|
45
|
+
Podfile: node_fs.readFileSync(
|
|
46
|
+
node_path.join(paths.templates.macos, "Podfile"),
|
|
47
|
+
"utf8",
|
|
48
|
+
),
|
|
49
|
+
Project: {
|
|
50
|
+
"AppDelegate.swift": node_fs.readFileSync(
|
|
51
|
+
node_path.join(paths.templates.macos, projectName, "AppDelegate.swift"),
|
|
52
|
+
"utf8",
|
|
53
|
+
),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
infoPlist: {},
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for(const plugin of registry) {
|
|
61
|
+
const pluginMainFn = await import(plugin.mainPath).then((
|
|
62
|
+
mod: {
|
|
63
|
+
default: ((ctx: Plugin.Context) => Promise<void> | void),
|
|
64
|
+
},
|
|
65
|
+
) => {
|
|
66
|
+
return mod.default
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
await pluginMainFn({
|
|
71
|
+
|
|
72
|
+
get macos() {
|
|
73
|
+
return {
|
|
74
|
+
get files() {
|
|
75
|
+
return {
|
|
76
|
+
// add(filename, source) {
|
|
77
|
+
// contextResult.macos.files.pluginFiles.push({
|
|
78
|
+
// filename,
|
|
79
|
+
// source,
|
|
80
|
+
// })
|
|
81
|
+
// },
|
|
82
|
+
|
|
83
|
+
get Podfile() {
|
|
84
|
+
return contextResult.macos.files.Podfile
|
|
85
|
+
},
|
|
86
|
+
set Podfile(value) {
|
|
87
|
+
contextResult.macos.files.Podfile = value
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
get Project() {
|
|
91
|
+
return {
|
|
92
|
+
get "AppDelegate.swift"() {
|
|
93
|
+
return contextResult.macos.files.Project["AppDelegate.swift"]
|
|
94
|
+
},
|
|
95
|
+
set "AppDelegate.swift"(value) {
|
|
96
|
+
contextResult.macos.files.Project["AppDelegate.swift"] = value
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
// add(filename, source) {
|
|
100
|
+
// contextResult.macos.files.Project.pluginFiles.push({
|
|
101
|
+
// filename,
|
|
102
|
+
// source,
|
|
103
|
+
// })
|
|
104
|
+
// },
|
|
105
|
+
} satisfies Plugin.Context["macos"]["files"]["Project"]
|
|
106
|
+
},
|
|
107
|
+
} satisfies Plugin.Context["macos"]["files"]
|
|
108
|
+
},
|
|
109
|
+
infoPlist: contextResult.macos.infoPlist,
|
|
110
|
+
// get Podfile() {
|
|
111
|
+
// return {
|
|
112
|
+
// pod: contextResult.macos.Podfile.pod,
|
|
113
|
+
// } satisfies Plugin.Context["macos"]["Podfile"]
|
|
114
|
+
// },
|
|
115
|
+
} satisfies Plugin.Context["macos"]
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
parameter: plugin.parameter,
|
|
119
|
+
|
|
120
|
+
})
|
|
121
|
+
} catch(err) {
|
|
122
|
+
if(err instanceof Error) {
|
|
123
|
+
// eslint-disable-next-line preserve-caught-error
|
|
124
|
+
throw new Error(
|
|
125
|
+
plugin.name +
|
|
126
|
+
`${err.stack ? "\n" + err.stack : ""}`,
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
throw err
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return contextResult
|
|
134
|
+
|
|
135
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EvaluatedPluginRegistry,
|
|
3
|
+
} from "./evaluated-plugin-registry"
|
|
4
|
+
|
|
5
|
+
export interface ArgvJSON {
|
|
6
|
+
/**
|
|
7
|
+
* Root directory of `bundo-appgen`.
|
|
8
|
+
* We cannot use the GlobalVars.configFilePath here, because this is already in different JavaScript process/runtime.
|
|
9
|
+
*/
|
|
10
|
+
// bundoAppgenRoot: string,
|
|
11
|
+
projectDirectory: string,
|
|
12
|
+
/**
|
|
13
|
+
* Project name, not the app display name.
|
|
14
|
+
*/
|
|
15
|
+
projectName: string,
|
|
16
|
+
|
|
17
|
+
evaluatedPluginRegistry: EvaluatedPluginRegistry | undefined,
|
|
18
|
+
|
|
19
|
+
messageID: string,
|
|
20
|
+
}
|