|
| 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