Repository navigation
Expand file tree
/
Copy pathmetagen.ts
More file actions
167 lines (151 loc) · 4.06 KB
/
Copy pathmetagen.ts
File metadata and controls
167 lines (151 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const COMMON_FRAMEWORKS = [
"Foundation",
"CoreFoundation",
"CoreGraphics",
"CoreText",
"QuartzCore",
"WebKit",
// Optional for core compat
"Metal",
"MetalKit",
"MetalPerformanceShaders",
"SpriteKit",
"SceneKit",
"ModelIO",
"GameController",
"GameKit",
"GameplayKit",
"CloudKit",
"Intents",
"Contacts",
"CoreSpotlight",
"JavaScriptCore",
"UserNotifications",
"CoreHaptics",
"EventKit",
"AddressBook",
"MapKit",
"CoreServices",
"CoreMedia",
"CoreVideo",
"CoreImage",
"CoreData",
"CoreMIDI",
"CoreML",
"CoreBluetooth",
"CoreLocation",
"CoreMotion",
"MLCompute",
"AudioToolbox",
"AudioUnit",
"AVFoundation",
"NaturalLanguage",
"Symbols",
];
const MACOS_FRAMEWORKS = ["AppKit", "CoreAudio", "ScreenCaptureKit"];
const IOS_FRAMEWORKS = ["UIKit"];
interface SDK {
path: string;
frameworks: string[];
targets: Record<string, string>;
}
function getSDKPath(platform: string) {
const { stdout, success } = new Deno.Command("xcrun", {
args: ["--sdk", platform, "--show-sdk-path"],
stdout: "piped",
stderr: "inherit",
stdin: "null",
}).outputSync();
if (!success) {
throw new Error(`Failed to get SDK path for ${platform}`);
}
return new TextDecoder().decode(stdout).trim();
}
const sdks: Record<string, SDK> = {
macos: {
path: getSDKPath("macosx"),
frameworks: [...COMMON_FRAMEWORKS, ...MACOS_FRAMEWORKS],
targets: {
x86_64: "x86_64-apple-macos11.0",
arm64: "arm64-apple-macos11.0",
},
},
ios: {
path: getSDKPath("iphoneos"),
frameworks: [...COMMON_FRAMEWORKS, ...IOS_FRAMEWORKS],
targets: {
x86_64: "x86_64-apple-ios13.0",
arm64: "arm64-apple-ios13.0",
},
},
"ios-sim": {
path: getSDKPath("iphonesimulator"),
frameworks: [...COMMON_FRAMEWORKS, ...IOS_FRAMEWORKS],
targets: {
x86_64: "x86_64-apple-ios13.0-simulator",
arm64: "arm64-apple-ios13.0-simulator",
},
},
};
const sdkName = Deno.args[0] ?? "macos";
const sdk = sdks[sdkName];
if (!sdk) {
throw new Error(`Invalid platform: ${sdkName}`);
}
await Deno.remove(new URL(`../packages/${sdkName}/types`, import.meta.url), {
recursive: true,
}).catch(() => {});
await Deno.mkdir(new URL(`../packages/${sdkName}/types`, import.meta.url), {
recursive: true,
}).catch(() => {});
for (const arch in sdk.targets) {
const exec = new URL("../metadata/build/MetadataGenerator", import.meta.url);
const args = [
`arch=${arch}`,
`target=${sdk.targets[arch]}`,
`output=${
new URL(`../metadata/metadata.${sdkName}.${arch}.nsmd`, import.meta.url)
.pathname
}`,
// NOTE: We're not differentiating between the arch for TS types - it shouldn't matter much
`types=${
new URL(`../packages/${sdkName}/types`, import.meta.url).pathname
}`,
`sdk=${sdk.path}`,
];
for (const framework of sdk.frameworks) {
args.push(`framework=${framework}`);
}
// TODO: commit these files to the repo
// These are needed to make it work with NativeScriptCore on iOS apps (compat with old NativeScript runtime)
const TNS_WIDGETS_FRAMEWORK = Deno.env.get("TNS_WIDGETS_FRAMEWORK");
if (TNS_WIDGETS_FRAMEWORK) {
const customFrameworks = [TNS_WIDGETS_FRAMEWORK];
for (const framework of customFrameworks) {
args.push(`include=${framework}`);
args.push(`headers=${framework}/Headers`);
args.push(`import="TNSWidgets.h"`);
}
args.push(
"include=/Users/dj/Projects/NativeScript/packages/core/platforms/ios/src"
);
args.push(
"headers=/Users/dj/Projects/NativeScript/packages/core/platforms/ios/src"
);
args.push('import="NativeScriptEmbedder.h"');
args.push('import="NativeScriptUtils.h"');
args.push('import="UIView+NativeScript.h"');
}
console.log(`%c$ MetadataGenerator ${args.join(" ")}`, "color: grey");
const proc = new Deno.Command(exec, {
stdin: "null",
stdout: "inherit",
stderr: "inherit",
args,
});
const output = proc.outputSync();
if (!output.success) {
console.log(output);
throw new Error("Failed to generate metadata");
}
}