mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-02 06:09:35 +08:00
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
/** Keep the isolated settings bridge executable on Hermes without runtime source serialization. */
|
|
import fs from "node:fs";
|
|
import ts from "typescript";
|
|
import { fileURLToPath } from "node:url";
|
|
const source = fileURLToPath(
|
|
new URL(
|
|
"../apps/mobile/src/plugins/pluginSettingsBootstrap.ts",
|
|
import.meta.url,
|
|
),
|
|
);
|
|
const target = fileURLToPath(
|
|
new URL(
|
|
"../apps/mobile/src/plugins/pluginSettingsBootstrap.generated.ts",
|
|
import.meta.url,
|
|
),
|
|
);
|
|
const compiled = ts
|
|
.transpileModule(fs.readFileSync(source, "utf8"), {
|
|
compilerOptions: {
|
|
target: ts.ScriptTarget.ES2022,
|
|
module: ts.ModuleKind.ESNext,
|
|
},
|
|
})
|
|
.outputText.replace(
|
|
"export function settingsBootstrap(",
|
|
"function settingsBootstrap(",
|
|
)
|
|
.replace(/export \{\};?\s*$/, "");
|
|
const output =
|
|
"// Generated by scripts/generate-mobile-settings-bootstrap.mjs. Edit pluginSettingsBootstrap.ts.\n" +
|
|
"export const PLUGIN_SETTINGS_BOOTSTRAP = " +
|
|
JSON.stringify(compiled) +
|
|
";\n";
|
|
if (process.argv.includes("--check")) {
|
|
if (!fs.existsSync(target) || fs.readFileSync(target, "utf8") !== output) {
|
|
process.stderr.write(
|
|
"Mobile settings bootstrap is stale; run node scripts/generate-mobile-settings-bootstrap.mjs\n",
|
|
);
|
|
process.exitCode = 1;
|
|
}
|
|
} else fs.writeFileSync(target, output);
|