Skip to content

Commit aa26892

Browse files
authored
chore: add prep script for Viewfinder (#1126)
1 parent 91dd038 commit aa26892

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

example/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,37 @@
5252
"roots": [
5353
"test"
5454
]
55+
},
56+
"rnx-kit": {
57+
"//": "This configuration is only used for Viewfinder",
58+
"kitType": "app",
59+
"reactNativeVersion": "0.68",
60+
"capabilities": [
61+
"core-android",
62+
"core-ios",
63+
"core-macos",
64+
"core-windows",
65+
"animation",
66+
"babel-preset-react-native",
67+
"checkbox",
68+
"clipboard",
69+
"datetime-picker",
70+
"filesystem",
71+
"floating-action",
72+
"gestures",
73+
"html",
74+
"masked-view",
75+
"modal",
76+
"navigation/native",
77+
"navigation/stack",
78+
"netinfo",
79+
"popover",
80+
"screens",
81+
"shimmer",
82+
"sqlite",
83+
"storage",
84+
"svg",
85+
"webview"
86+
]
5587
}
5688
}

scripts/prepare-viewfinder.mjs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env node
2+
// @ts-check
3+
4+
import { spawnSync } from "node:child_process";
5+
import * as fs from "node:fs";
6+
import * as path from "node:path";
7+
import { fileURLToPath } from "node:url";
8+
9+
const APP_IDENTIFIER = "com.microsoft.ReactNativeViewfinder";
10+
const PACKAGE_MANAGER = "yarn";
11+
12+
const PROJECT_ROOT = path.resolve(
13+
path.dirname(fileURLToPath(import.meta.url)),
14+
".."
15+
);
16+
const APP_ROOT = path.resolve(PROJECT_ROOT, "example");
17+
const APP_MANIFEST = path.resolve(APP_ROOT, "app.json");
18+
const PROJECT_MANIFEST = path.resolve(APP_ROOT, "package.json");
19+
20+
/**
21+
* Configures the app manifest for Viewfinder.
22+
*/
23+
function configureAppManifest() {
24+
const original = JSON.parse(
25+
fs.readFileSync(APP_MANIFEST, { encoding: "utf-8" })
26+
);
27+
28+
const manifest = {
29+
...original,
30+
$schema: undefined,
31+
name: "Viewfinder",
32+
displayName: "Viewfinder",
33+
components: [],
34+
android: {
35+
package: APP_IDENTIFIER,
36+
},
37+
ios: {
38+
bundleIdentifier: APP_IDENTIFIER,
39+
},
40+
};
41+
42+
fs.writeFileSync(APP_MANIFEST, JSON.stringify(manifest, null, 2) + "\n");
43+
}
44+
45+
/**
46+
* Runs the specified command.
47+
* @param {string} command
48+
* @param {string[]} args
49+
* @param {Record<string, unknown>=} options
50+
*/
51+
function run(command, args, options) {
52+
const { error, status } = spawnSync(command, args, {
53+
cwd: PROJECT_ROOT,
54+
stdio: "inherit",
55+
...options,
56+
});
57+
if (status !== 0) {
58+
throw error ?? new Error(`Command failed: ${command} ${args.join(" ")}`);
59+
}
60+
}
61+
62+
configureAppManifest();
63+
run("npx", ["@rnx-kit/dep-check", "--write", PROJECT_MANIFEST]);
64+
run(PACKAGE_MANAGER, ["install"]);

0 commit comments

Comments
 (0)