opencode-agent-harness 0.0.0-stage → 0.2.0
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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +590 -2
- package/bin/agent-harness.js +3059 -0
- package/contrib/global-plugins/README.md +49 -0
- package/contrib/global-plugins/harness-freshness.ts +355 -0
- package/package.json +48 -4
- package/templates/.agents/AGENTS.md +204 -0
- package/templates/.agents/features/INDEX.md +10 -0
- package/templates/.agents/handoffs/README.md +87 -0
- package/templates/.agents/memory/dev-loop.md +59 -0
- package/templates/.agents/memory/domain-map.md +29 -0
- package/templates/.agents/memory/environments.md +35 -0
- package/templates/.agents/memory/flow-map.md +23 -0
- package/templates/.agents/memory/history.md +7 -0
- package/templates/.agents/memory/locations.md +14 -0
- package/templates/.agents/memory/model-routing.md +261 -0
- package/templates/.agents/memory/orchestration.md +183 -0
- package/templates/.agents/memory/owned-files.md +19 -0
- package/templates/.agents/memory/product-principles.md +37 -0
- package/templates/.agents/memory/quality-parameters.md +37 -0
- package/templates/.agents/memory/stack-versions.md +35 -0
- package/templates/.agents/memory/test-design-parameters.md +36 -0
- package/templates/.agents/nightly.json +17 -0
- package/templates/.agents/qa-plans/README.md +70 -0
- package/templates/.agents/qa-runs/README.md +21 -0
- package/templates/.agents/reviews/README.md +47 -0
- package/templates/.agents/rules/00-operating.md +199 -0
- package/templates/.agents/skills/data-engineer/SKILL.md +31 -0
- package/templates/.agents/skills/devops-engineer/SKILL.md +50 -0
- package/templates/.agents/skills/diagnostics-expert/SKILL.md +44 -0
- package/templates/.agents/skills/docs/SKILL.md +140 -0
- package/templates/.agents/skills/features/SKILL.md +187 -0
- package/templates/.agents/skills/frontend-engineer/SKILL.md +81 -0
- package/templates/.agents/skills/handoff/SKILL.md +85 -0
- package/templates/.agents/skills/mobile-engineer/SKILL.md +101 -0
- package/templates/.agents/skills/planner/SKILL.md +112 -0
- package/templates/.agents/skills/product-manager/SKILL.md +115 -0
- package/templates/.agents/skills/qa-architect/SKILL.md +224 -0
- package/templates/.agents/skills/qa-runner/SKILL.md +64 -0
- package/templates/.agents/skills/security-engineer/SKILL.md +53 -0
- package/templates/.agents/skills/system-architect/SKILL.md +42 -0
- package/templates/.agents/skills/ui-designer/SKILL.md +71 -0
- package/templates/.github/workflows/ci.yml +148 -0
- package/templates/.github/workflows/deploy-uat.yml +95 -0
- package/templates/.github/workflows/nightly.yml +83 -0
- package/templates/.github/workflows/uat-health.yml +41 -0
- package/templates/.husky/pre-push +23 -0
- package/templates/.ignore +28 -0
- package/templates/.opencode/agents/data-engineer.md +37 -0
- package/templates/.opencode/agents/devops-engineer.md +37 -0
- package/templates/.opencode/agents/diagnostics-expert.md +37 -0
- package/templates/.opencode/agents/docs.md +37 -0
- package/templates/.opencode/agents/features.md +21 -0
- package/templates/.opencode/agents/frontend-engineer.md +37 -0
- package/templates/.opencode/agents/handoff.md +21 -0
- package/templates/.opencode/agents/mobile-engineer.md +37 -0
- package/templates/.opencode/agents/planner.md +34 -0
- package/templates/.opencode/agents/product-manager.md +29 -0
- package/templates/.opencode/agents/qa-architect.md +27 -0
- package/templates/.opencode/agents/qa-runner.md +17 -0
- package/templates/.opencode/agents/security-engineer.md +37 -0
- package/templates/.opencode/agents/system-architect.md +37 -0
- package/templates/.opencode/agents/ui-designer.md +37 -0
- package/templates/.opencode/commands/board.md +15 -0
- package/templates/.opencode/commands/checkpoint.md +25 -0
- package/templates/.opencode/commands/feature.md +56 -0
- package/templates/.opencode/commands/finish.md +36 -0
- package/templates/.opencode/commands/next.md +49 -0
- package/templates/.opencode/commands/report.md +55 -0
- package/templates/.opencode/commands/resume.md +39 -0
- package/templates/.opencode/commands/switch-model.md +34 -0
- package/templates/.opencode/commands/tidy.md +49 -0
- package/templates/.opencode/plugins/backlog-notify.ts +57 -0
- package/templates/.opencode/plugins/backlog.ts +272 -0
- package/templates/.opencode/plugins/checkpoint.ts +160 -0
- package/templates/.opencode/plugins/context-guard.ts +1164 -0
- package/templates/.opencode/plugins/diff.ts +85 -0
- package/templates/.opencode/plugins/gates.ts +71 -0
- package/templates/.opencode/plugins/job-notify.ts +241 -0
- package/templates/.opencode/plugins/orient.ts +67 -0
- package/templates/.opencode/plugins/session.ts +89 -0
- package/templates/.opencode/plugins/wait.ts +101 -0
- package/templates/.opencode/plugins/where.ts +70 -0
- package/templates/.opencode/skills/bounded-explore/SKILL.md +38 -0
- package/templates/.opencode/skills/dev-loop/SKILL.md +87 -0
- package/templates/.vercelignore +16 -0
- package/templates/AGENTS.md +27 -0
- package/templates/BACKLOG.md +95 -0
- package/templates/docs/ci-cd-pipeline.md +81 -0
- package/templates/docs/gates.md +128 -0
- package/templates/docs/mcp-integrations.md +97 -0
- package/templates/docs/mobile-testing.md +555 -0
- package/templates/docs/nightly-testing.md +106 -0
- package/templates/docs/wsl-optimizations.md +290 -0
- package/templates/opencode.json +188 -0
- package/templates/scripts/agent-report.js +541 -0
- package/templates/scripts/agent-search.sh +117 -0
- package/templates/scripts/backlog.js +1864 -0
- package/templates/scripts/board-service.sh +207 -0
- package/templates/scripts/checkpoint.js +290 -0
- package/templates/scripts/finalize.js +277 -0
- package/templates/scripts/nightly.js +913 -0
- package/templates/scripts/orient.js +514 -0
- package/templates/scripts/qa/board-client.js +260 -0
- package/templates/scripts/qa/board-lib.js +96 -0
- package/templates/scripts/qa/board-sync.js +469 -0
- package/templates/scripts/qa/capacity-lib.js +916 -0
- package/templates/scripts/qa/check-backlog.js +427 -0
- package/templates/scripts/qa/check-capacity.js +85 -0
- package/templates/scripts/qa/check-ci-policy.js +164 -0
- package/templates/scripts/qa/check-concurrency.js +344 -0
- package/templates/scripts/qa/check-dispatch-config.js +296 -0
- package/templates/scripts/qa/check-docs.js +284 -0
- package/templates/scripts/qa/check-integrate.js +98 -0
- package/templates/scripts/qa/check-linger.js +160 -0
- package/templates/scripts/qa/check-prefix-stability.js +183 -0
- package/templates/scripts/qa/check-product.js +177 -0
- package/templates/scripts/qa/check-qa-plan.js +378 -0
- package/templates/scripts/qa/check-qa-scripts.js +85 -0
- package/templates/scripts/qa/check-quality.js +249 -0
- package/templates/scripts/qa/check-test-wiring.js +253 -0
- package/templates/scripts/qa/ci-triage.js +346 -0
- package/templates/scripts/qa/ci-usage-lib.js +185 -0
- package/templates/scripts/qa/ci-wait-lib.js +294 -0
- package/templates/scripts/qa/command-classifier.js +552 -0
- package/templates/scripts/qa/context-guard-core.js +1618 -0
- package/templates/scripts/qa/diff.js +174 -0
- package/templates/scripts/qa/feature-scaffold.js +224 -0
- package/templates/scripts/qa/fixtures/backlog.md +104 -0
- package/templates/scripts/qa/governance.js +174 -0
- package/templates/scripts/qa/hash-file.js +32 -0
- package/templates/scripts/qa/lease-lib.js +263 -0
- package/templates/scripts/qa/merge-backlog.js +324 -0
- package/templates/scripts/qa/mobile-e2e/analyze-timings.js +300 -0
- package/templates/scripts/qa/mobile-e2e/apk-cache.js +420 -0
- package/templates/scripts/qa/mobile-e2e/backend-build-cache.js +203 -0
- package/templates/scripts/qa/mobile-e2e/boot-emulator.sh +432 -0
- package/templates/scripts/qa/mobile-e2e/build-apk.sh +210 -0
- package/templates/scripts/qa/mobile-e2e/check-flows.js +453 -0
- package/templates/scripts/qa/mobile-e2e/config.yaml +18 -0
- package/templates/scripts/qa/mobile-e2e/device-down.sh +88 -0
- package/templates/scripts/qa/mobile-e2e/device-up.sh +258 -0
- package/templates/scripts/qa/mobile-e2e/ios-simulator-down.sh +72 -0
- package/templates/scripts/qa/mobile-e2e/ios-simulator-up.sh +153 -0
- package/templates/scripts/qa/mobile-e2e/job-events.js +181 -0
- package/templates/scripts/qa/mobile-e2e/prewarm.sh +56 -0
- package/templates/scripts/qa/mobile-e2e/run-detached.sh +222 -0
- package/templates/scripts/qa/mobile-e2e/run-maestro.js +1543 -0
- package/templates/scripts/qa/mobile-e2e/ui-dump.js +327 -0
- package/templates/scripts/qa/models.allowlist.txt +32 -0
- package/templates/scripts/qa/provider-stats.js +878 -0
- package/templates/scripts/qa/run-clean.js +83 -0
- package/templates/scripts/qa/run-gates.js +212 -0
- package/templates/scripts/qa/run-loop.js +220 -0
- package/templates/scripts/qa/session-recon.js +512 -0
- package/templates/scripts/qa/store-lib.js +324 -0
- package/templates/scripts/qa/tool-lib.js +134 -0
- package/templates/scripts/qa/where.js +214 -0
- package/templates/scripts/qa/wslconfig-merge.js +157 -0
- package/templates/scripts/serve.js +1328 -0
- package/templates/scripts/setup-nightly.sh +185 -0
- package/templates/scripts/setup-tmpfs.sh +374 -0
- package/templates/scripts/ship.js +586 -0
- package/templates/scripts/switch-reasoning-model.ps1 +101 -0
- package/templates/scripts/switch-reasoning-model.sh +104 -0
- package/templates/scripts/wait-for.js +342 -0
- package/templates/scripts/wsl-gpu.sh +180 -0
- package/templates/scripts/wsl-tune.sh +261 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* apk-cache — cut the device-tier bring-up time by reusing the parts of the
|
|
5
|
+
* release APK that do not change between feature worktrees.
|
|
6
|
+
*
|
|
7
|
+
* The device tier's cost is dominated by a cold `./gradlew assembleRelease`
|
|
8
|
+
* (the reanimated/worklets/screens C++ compile, codegen, dex merge, and the
|
|
9
|
+
* Hermes JS bundle). Almost all of that is invariant across worktrees for a
|
|
10
|
+
* fixed dependency/toolchain set; only the JS bundle changes per feature. This
|
|
11
|
+
* module content-addresses each stage so the invariant work is done once:
|
|
12
|
+
*
|
|
13
|
+
* native/<nativeKey>/base.apk the native shell (ignores JS)
|
|
14
|
+
* bundle/<bundleKey>/ the Hermes bundle + exported assets
|
|
15
|
+
* apk/<fullKey>/app-release.apk a ready-to-install APK
|
|
16
|
+
*
|
|
17
|
+
* `nativeKey` hashes the dependency/toolchain inputs only (package-lock,
|
|
18
|
+
* patches, app.json, the generated android gradle files, ABIs, build-apk.sh).
|
|
19
|
+
* `bundleKey` hashes the JS/resource sources + the baked API URL. `fullKey` is
|
|
20
|
+
* both, so an unchanged worktree is an instant cache hit.
|
|
21
|
+
*
|
|
22
|
+
* CLI (all paths printed on stdout, diagnostics on stderr):
|
|
23
|
+
* apk-cache.js key [--json] print fullKey (or {native,bundle,full})
|
|
24
|
+
* apk-cache.js get print a cached final APK path (exit 1 if none)
|
|
25
|
+
* apk-cache.js put <apk> store <apk> under fullKey
|
|
26
|
+
* apk-cache.js base-get print a cached native base APK (exit 1 if none)
|
|
27
|
+
* apk-cache.js base-put <apk> store <apk> as the native base
|
|
28
|
+
* apk-cache.js overlay base + fresh bundle -> final APK (exit 2 if it
|
|
29
|
+
* cannot safely overlay; caller does a full build)
|
|
30
|
+
* apk-cache.js status human-readable cache state
|
|
31
|
+
*
|
|
32
|
+
* `overlay` NEVER touches resources.arsc or the compiled res/: it replaces only
|
|
33
|
+
* `assets/index.android.bundle`, and only when every exported asset name is
|
|
34
|
+
* already present in the base APK's resource table (a feature that adds a new
|
|
35
|
+
* static image falls back to a full Gradle build). It re-signs with the app's
|
|
36
|
+
* debug keystore and verifies the result; any doubt -> a non-zero exit so the
|
|
37
|
+
* caller builds normally. It is a pure accelerator: correctness never depends
|
|
38
|
+
* on it.
|
|
39
|
+
*
|
|
40
|
+
* Env:
|
|
41
|
+
* MOBILE_E2E_CACHE_DIR cache root (default ~/.cache/agent-harness/mobile-e2e)
|
|
42
|
+
* MOBILE_E2E_ABI ABI built (default x86_64)
|
|
43
|
+
* MOBILE_E2E_API_URL baked dev API (default http://10.0.2.2:3000)
|
|
44
|
+
* MOBILE_E2E_APK APK path (default conventional Gradle output)
|
|
45
|
+
* ANDROID_HOME Android SDK root (default ~/android-sdk)
|
|
46
|
+
*/
|
|
47
|
+
const fs = require("fs");
|
|
48
|
+
const os = require("os");
|
|
49
|
+
const path = require("path");
|
|
50
|
+
const crypto = require("crypto");
|
|
51
|
+
const { spawnSync } = require("child_process");
|
|
52
|
+
|
|
53
|
+
const ROOT = path.resolve(__dirname, "..", "..", "..");
|
|
54
|
+
const MOBILE = path.join(ROOT, "mobile");
|
|
55
|
+
const ANDROID = path.join(MOBILE, "android");
|
|
56
|
+
const SDK = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || path.join(os.homedir(), "android-sdk");
|
|
57
|
+
const ABI = process.env.MOBILE_E2E_ABI || "x86_64";
|
|
58
|
+
const API_URL = process.env.MOBILE_E2E_API_URL || "http://10.0.2.2:3000";
|
|
59
|
+
const CACHE = process.env.MOBILE_E2E_CACHE_DIR || path.join(
|
|
60
|
+
process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"),
|
|
61
|
+
"agent-harness", "mobile-e2e"
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const SKIP_DIRS = new Set(["node_modules", ".git", ".expo", "android", "ios", "build", ".cxx", "tmp", ".gradle"]);
|
|
65
|
+
const ANCHOR_FILES = [
|
|
66
|
+
"package.json",
|
|
67
|
+
"package-lock.json",
|
|
68
|
+
"app.json",
|
|
69
|
+
"babel.config.js",
|
|
70
|
+
"metro.config.js",
|
|
71
|
+
"tailwind.config.js",
|
|
72
|
+
"global.css",
|
|
73
|
+
"tsconfig.json",
|
|
74
|
+
"android/gradle.properties",
|
|
75
|
+
"android/build.gradle",
|
|
76
|
+
"android/settings.gradle",
|
|
77
|
+
"android/gradle/wrapper/gradle-wrapper.properties",
|
|
78
|
+
"android/app/build.gradle",
|
|
79
|
+
"android/app/src/main/AndroidManifest.xml",
|
|
80
|
+
];
|
|
81
|
+
const NATIVE_TREES = ["patches"];
|
|
82
|
+
const JS_TREES = ["app", "components", "lib", "assets"];
|
|
83
|
+
|
|
84
|
+
function sha256(buf) { return crypto.createHash("sha256").update(buf).digest("hex"); }
|
|
85
|
+
function sha256File(p) { try { return sha256(fs.readFileSync(p)); } catch (_) { return ""; } }
|
|
86
|
+
|
|
87
|
+
function walkFiles(dir, base) {
|
|
88
|
+
const out = [];
|
|
89
|
+
if (!fs.existsSync(dir)) return out;
|
|
90
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
91
|
+
if (entry.isDirectory()) {
|
|
92
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
93
|
+
out.push(...walkFiles(path.join(dir, entry.name), base));
|
|
94
|
+
} else if (entry.isFile()) {
|
|
95
|
+
out.push(path.relative(base, path.join(dir, entry.name)).split(path.sep).join("/"));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function hashTree(dirs, base) {
|
|
102
|
+
const files = [];
|
|
103
|
+
for (const d of dirs) files.push(...walkFiles(path.join(base, d), base));
|
|
104
|
+
files.sort();
|
|
105
|
+
const h = crypto.createHash("sha256");
|
|
106
|
+
for (const rel of files) {
|
|
107
|
+
h.update(rel); h.update("\0"); h.update(fs.readFileSync(path.join(base, rel))); h.update("\0");
|
|
108
|
+
}
|
|
109
|
+
return h.digest("hex");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function fileMap(rels, base) {
|
|
113
|
+
const out = {};
|
|
114
|
+
for (const rel of rels) {
|
|
115
|
+
const p = path.join(base, rel);
|
|
116
|
+
if (fs.existsSync(p) && fs.statSync(p).isFile()) out[rel] = sha256File(p);
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function depsDigest(pkgPath) {
|
|
122
|
+
try {
|
|
123
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
124
|
+
const pick = (o) => Object.keys(o || {}).sort().map((k) => `${k}@${o[k]}`).join(",");
|
|
125
|
+
return sha256(`${pick(pkg.dependencies)}|${pick(pkg.devDependencies)}`);
|
|
126
|
+
} catch (_) { return ""; }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function nativeKey() {
|
|
130
|
+
const manifest = {
|
|
131
|
+
v: 1,
|
|
132
|
+
abi: ABI,
|
|
133
|
+
deps: depsDigest(path.join(MOBILE, "package.json")),
|
|
134
|
+
trees: hashTree(NATIVE_TREES, MOBILE),
|
|
135
|
+
files: fileMap(ANCHOR_FILES, MOBILE),
|
|
136
|
+
buildScript: sha256File(path.join(__dirname, "build-apk.sh")),
|
|
137
|
+
};
|
|
138
|
+
return sha256(JSON.stringify(manifest));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function bundleKey() {
|
|
142
|
+
const manifest = {
|
|
143
|
+
v: 1,
|
|
144
|
+
apiUrl: API_URL,
|
|
145
|
+
entry: 1, // bump when the entry resolution changes
|
|
146
|
+
trees: hashTree(JS_TREES, MOBILE),
|
|
147
|
+
files: fileMap(ANCHOR_FILES, MOBILE),
|
|
148
|
+
deps: depsDigest(path.join(MOBILE, "package.json")),
|
|
149
|
+
};
|
|
150
|
+
return sha256(JSON.stringify(manifest));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function fullKey() { return sha256(`${nativeKey()}\n${bundleKey()}`); }
|
|
154
|
+
|
|
155
|
+
function dirs() {
|
|
156
|
+
return {
|
|
157
|
+
finalDir: path.join(CACHE, "apk", fullKey()),
|
|
158
|
+
nativeDir: path.join(CACHE, "native", nativeKey()),
|
|
159
|
+
bundleDir: path.join(CACHE, "bundle", bundleKey()),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function finalApkPath() { return path.join(dirs().finalDir, "app-release.apk"); }
|
|
164
|
+
function baseApkPath() { return path.join(dirs().nativeDir, "base.apk"); }
|
|
165
|
+
|
|
166
|
+
function mkdirp(d) { fs.mkdirSync(d, { recursive: true }); }
|
|
167
|
+
|
|
168
|
+
function atomicCopy(src, dest) {
|
|
169
|
+
mkdirp(path.dirname(dest));
|
|
170
|
+
const tmp = `${dest}.tmp-${process.pid}`;
|
|
171
|
+
fs.copyFileSync(src, tmp);
|
|
172
|
+
fs.renameSync(tmp, dest);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function tool(bin) {
|
|
176
|
+
for (const root of [path.join(SDK, "build-tools")]) {
|
|
177
|
+
if (!fs.existsSync(root)) continue;
|
|
178
|
+
for (const v of fs.readdirSync(root).sort().reverse()) {
|
|
179
|
+
const p = path.join(root, v, bin);
|
|
180
|
+
if (fs.existsSync(p)) return p;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function sh(cmd, args, opts) {
|
|
187
|
+
const r = spawnSync(cmd, args, Object.assign({ encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }, opts));
|
|
188
|
+
if (r.error) return { ok: false, out: "", err: r.error.message, status: -1 };
|
|
189
|
+
return { ok: r.status === 0, out: r.stdout || "", err: r.stderr || "", status: r.status };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function resolveEntry() {
|
|
193
|
+
const r = sh(process.execPath, ["-e", "require('expo/scripts/resolveAppEntry')", MOBILE, "android", "absolute"], { cwd: MOBILE });
|
|
194
|
+
const entry = (r.out || "").trim().split("\n").pop();
|
|
195
|
+
return r.ok && entry ? entry : null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function expoCli() {
|
|
199
|
+
const bin = path.join(MOBILE, "node_modules", ".bin", "expo");
|
|
200
|
+
return fs.existsSync(bin) ? bin : null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* Build the Hermes bundle for the current JS into bundle/<key>/ (atomic). */
|
|
204
|
+
function ensureBundle() {
|
|
205
|
+
const dir = dirs().bundleDir;
|
|
206
|
+
const bundled = path.join(dir, "assets", "index.android.bundle");
|
|
207
|
+
if (fs.existsSync(bundled)) return { ok: true, dir };
|
|
208
|
+
const entry = resolveEntry();
|
|
209
|
+
if (!entry) return { ok: false, err: "could not resolve the app entry" };
|
|
210
|
+
const expo = expoCli();
|
|
211
|
+
if (!expo) return { ok: false, err: "no node_modules/.bin/expo" };
|
|
212
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "agent-e2e-bundle-"));
|
|
213
|
+
mkdirp(path.join(tmp, "assets"));
|
|
214
|
+
const args = [
|
|
215
|
+
"export:embed",
|
|
216
|
+
"--platform", "android",
|
|
217
|
+
"--dev", "false",
|
|
218
|
+
"--entry-file", entry,
|
|
219
|
+
"--bundle-output", path.join(tmp, "assets", "index.android.bundle"),
|
|
220
|
+
"--assets-dest", tmp,
|
|
221
|
+
];
|
|
222
|
+
const env = Object.assign({}, process.env, { EXPO_PUBLIC_API_URL: API_URL });
|
|
223
|
+
// Run Metro through `serve.js run` so the bundle is capped in a cgroup and
|
|
224
|
+
// obeys the machine-wide envelope (it classifies as an "apk build" one-shot).
|
|
225
|
+
// Metro is much smaller than Gradle, but a prewarm must never contend with a
|
|
226
|
+
// live heavy tier; serve.js refuses it there instead.
|
|
227
|
+
const serve = path.join(ROOT, "scripts", "serve.js");
|
|
228
|
+
const shq = (s) => `'${String(s).replace(/'/g, "'\\''")}'`;
|
|
229
|
+
const r = fs.existsSync(serve)
|
|
230
|
+
? sh(process.execPath, [serve, "run", "--name", "apk-bundle", "--mem-max", "2G", "--cmd", [expo, ...args].map(shq).join(" ")], { cwd: MOBILE, env })
|
|
231
|
+
: sh(expo, args, { cwd: MOBILE, env });
|
|
232
|
+
if (!r.ok || !fs.existsSync(path.join(tmp, "assets", "index.android.bundle"))) {
|
|
233
|
+
return { ok: false, err: `expo export:embed failed: ${(r.err || "").slice(-400)}` };
|
|
234
|
+
}
|
|
235
|
+
mkdirp(path.dirname(dir));
|
|
236
|
+
const staging = `${dir}.tmp-${process.pid}`;
|
|
237
|
+
fs.renameSync(tmp, staging);
|
|
238
|
+
fs.renameSync(staging, dir);
|
|
239
|
+
return { ok: true, dir };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/* Resource names present in an APK's resource table (aapt2). */
|
|
243
|
+
function apkResourceNames(apk) {
|
|
244
|
+
const aapt2 = tool("aapt2");
|
|
245
|
+
if (!aapt2) return null;
|
|
246
|
+
const r = sh(aapt2, ["dump", "resources", apk]);
|
|
247
|
+
if (!r.ok) return null;
|
|
248
|
+
const names = new Set();
|
|
249
|
+
for (const m of r.out.matchAll(/(?:drawable|raw)\/([A-Za-z0-9_.]+)/g)) names.add(m[1]);
|
|
250
|
+
return names;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* Resource names the freshly exported bundle will reference: derive from the
|
|
254
|
+
* staged export asset file names (aapt2 lowercases and replaces non-alnum). */
|
|
255
|
+
function stagedResourceNames(bundleDir) {
|
|
256
|
+
const names = new Set();
|
|
257
|
+
if (!fs.existsSync(bundleDir)) return names;
|
|
258
|
+
for (const d of fs.readdirSync(bundleDir)) {
|
|
259
|
+
if (!/^(drawable|raw)/.test(d)) continue;
|
|
260
|
+
const full = path.join(bundleDir, d);
|
|
261
|
+
if (!fs.statSync(full).isDirectory()) continue;
|
|
262
|
+
for (const f of fs.readdirSync(full)) {
|
|
263
|
+
names.add(f.replace(/\.[^.]+$/, "").toLowerCase().replace(/[^a-z0-9_]/g, "_"));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return names;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/* Rewrite the APK replacing assets/index.android.bundle only, via python3's
|
|
270
|
+
* zipfile (no `zip` dependency; preserves every other entry's compression). */
|
|
271
|
+
const PY_REWRITE = `
|
|
272
|
+
import sys, os, zipfile
|
|
273
|
+
base, stage, out, repl = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
|
|
274
|
+
repl = set(repl.split(",")) if repl else set()
|
|
275
|
+
replacements = {}
|
|
276
|
+
for root, _, files in os.walk(stage):
|
|
277
|
+
for f in files:
|
|
278
|
+
p = os.path.join(root, f)
|
|
279
|
+
rel = os.path.relpath(p, stage).replace(os.sep, "/")
|
|
280
|
+
if rel in repl:
|
|
281
|
+
replacements[rel] = p
|
|
282
|
+
zin = zipfile.ZipFile(base, "r")
|
|
283
|
+
zout = zipfile.ZipFile(out, "w")
|
|
284
|
+
for item in zin.infolist():
|
|
285
|
+
n = item.filename
|
|
286
|
+
if n.startswith("META-INF/") and (n.endswith(".RSA") or n.endswith(".SF") or n.endswith(".MF") or n.endswith(".EC")):
|
|
287
|
+
continue
|
|
288
|
+
if n in replacements:
|
|
289
|
+
data = open(replacements[n], "rb").read()
|
|
290
|
+
zi = zipfile.ZipInfo(n, date_time=item.date_time)
|
|
291
|
+
zi.compress_type = item.compress_type
|
|
292
|
+
zi.external_attr = item.external_attr
|
|
293
|
+
zout.writestr(zi, data)
|
|
294
|
+
else:
|
|
295
|
+
zout.writestr(item, zin.read(n))
|
|
296
|
+
zin.close(); zout.close()
|
|
297
|
+
`;
|
|
298
|
+
|
|
299
|
+
function overlay() {
|
|
300
|
+
const base = baseApkPath();
|
|
301
|
+
if (!fs.existsSync(base)) return { ok: false, err: "no native base cached yet" };
|
|
302
|
+
const b = ensureBundle();
|
|
303
|
+
if (!b.ok) return { ok: false, err: b.err };
|
|
304
|
+
|
|
305
|
+
const baseNames = apkResourceNames(base);
|
|
306
|
+
if (!baseNames) return { ok: false, err: "aapt2 unavailable — cannot verify resource compatibility" };
|
|
307
|
+
const staged = stagedResourceNames(b.dir);
|
|
308
|
+
for (const n of staged) {
|
|
309
|
+
if (!baseNames.has(n)) return { ok: false, err: `new boot asset "${n}" not in the native base — full build needed` };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const python = sh("python3", ["-c", "import zipfile"]).ok ? "python3" : null;
|
|
313
|
+
if (!python) return { ok: false, err: "python3/zipfile unavailable — cannot rewrite the APK safely" };
|
|
314
|
+
const zipalign = tool("zipalign");
|
|
315
|
+
const apksigner = tool("apksigner");
|
|
316
|
+
const keystore = path.join(ANDROID, "app", "debug.keystore");
|
|
317
|
+
if (!zipalign || !apksigner || !fs.existsSync(keystore)) return { ok: false, err: "zipalign/apksigner/keystore unavailable" };
|
|
318
|
+
|
|
319
|
+
const work = fs.mkdtempSync(path.join(os.tmpdir(), "agent-e2e-overlay-"));
|
|
320
|
+
const unsigned = path.join(work, "unsigned.apk");
|
|
321
|
+
const aligned = path.join(work, "aligned.apk");
|
|
322
|
+
const signed = path.join(work, "signed.apk");
|
|
323
|
+
const rewrite = sh(python, ["-c", PY_REWRITE, base, b.dir, unsigned, "assets/index.android.bundle"]);
|
|
324
|
+
if (!rewrite.ok) return { ok: false, err: `apk rewrite failed: ${rewrite.err.slice(-300)}` };
|
|
325
|
+
const al = sh(zipalign, ["-f", "-p", "4", unsigned, aligned]);
|
|
326
|
+
if (!al.ok) return { ok: false, err: `zipalign failed: ${al.err.slice(-300)}` };
|
|
327
|
+
const sgn = sh(apksigner, [
|
|
328
|
+
"sign", "--ks", keystore, "--ks-pass", "pass:android", "--key-pass", "pass:android",
|
|
329
|
+
"--ks-key-alias", "androiddebugkey", "--out", signed, aligned,
|
|
330
|
+
]);
|
|
331
|
+
if (!sgn.ok) return { ok: false, err: `apksigner failed: ${sgn.err.slice(-300)}` };
|
|
332
|
+
if (!sh(apksigner, ["verify", "--print-certs", signed]).ok) return { ok: false, err: "apksigner verify failed" };
|
|
333
|
+
if (sh(apksigner, ["verify", signed]).status !== 0) return { ok: false, err: "apksigner verify failed" };
|
|
334
|
+
|
|
335
|
+
atomicCopy(signed, finalApkPath());
|
|
336
|
+
return { ok: true, path: finalApkPath() };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function cmdKey(args) {
|
|
340
|
+
const k = { native: nativeKey(), bundle: bundleKey() };
|
|
341
|
+
k.full = sha256(`${k.native}\n${k.bundle}`);
|
|
342
|
+
if (args.includes("--json")) console.log(JSON.stringify(k, null, 2));
|
|
343
|
+
else console.log(k.full);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function cmdGet() {
|
|
347
|
+
const p = finalApkPath();
|
|
348
|
+
if (fs.existsSync(p)) { console.log(p); return 0; }
|
|
349
|
+
return 1;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function cmdBaseGet() {
|
|
353
|
+
const p = baseApkPath();
|
|
354
|
+
if (fs.existsSync(p)) { console.log(p); return 0; }
|
|
355
|
+
return 1;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function store(src, dest, extra) {
|
|
359
|
+
atomicCopy(src, dest);
|
|
360
|
+
const meta = Object.assign({ storedAt: new Date().toISOString(), bytes: fs.statSync(dest).size }, extra || {});
|
|
361
|
+
fs.writeFileSync(path.join(path.dirname(dest), "meta.json"), JSON.stringify(meta, null, 2));
|
|
362
|
+
return dest;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function cmdPut(args) {
|
|
366
|
+
const src = args[0];
|
|
367
|
+
if (!src || !fs.existsSync(src)) { console.error("apk-cache put: no such APK:", src); return 2; }
|
|
368
|
+
console.log(store(src, finalApkPath()));
|
|
369
|
+
return 0;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function cmdBasePut(args) {
|
|
373
|
+
const src = args[0];
|
|
374
|
+
if (!src || !fs.existsSync(src)) { console.error("apk-cache base-put: no such APK:", src); return 2; }
|
|
375
|
+
const names = apkResourceNames(src);
|
|
376
|
+
console.log(store(src, baseApkPath(), names ? { resourceNames: [...names].sort() } : {}));
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function cmdOverlay() {
|
|
381
|
+
const r = overlay();
|
|
382
|
+
if (!r.ok) { console.error(`apk-cache overlay: ${r.err}`); return 2; }
|
|
383
|
+
console.log(r.path);
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function cmdStatus() {
|
|
388
|
+
const k = { native: nativeKey(), bundle: bundleKey() };
|
|
389
|
+
console.log(JSON.stringify({
|
|
390
|
+
key: k,
|
|
391
|
+
cached: {
|
|
392
|
+
final: fs.existsSync(finalApkPath()),
|
|
393
|
+
nativeBase: fs.existsSync(baseApkPath()),
|
|
394
|
+
bundle: fs.existsSync(path.join(dirs().bundleDir, "assets", "index.android.bundle")),
|
|
395
|
+
},
|
|
396
|
+
cache: CACHE,
|
|
397
|
+
}, null, 2));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function main() {
|
|
401
|
+
const [cmd, ...args] = process.argv.slice(2);
|
|
402
|
+
let code = 0;
|
|
403
|
+
switch (cmd) {
|
|
404
|
+
case "key": cmdKey(args); break;
|
|
405
|
+
case "get": code = cmdGet(); break;
|
|
406
|
+
case "put": code = cmdPut(args); break;
|
|
407
|
+
case "base-get": code = cmdBaseGet(); break;
|
|
408
|
+
case "base-put": code = cmdBasePut(args); break;
|
|
409
|
+
case "overlay": code = cmdOverlay(); break;
|
|
410
|
+
case "status": cmdStatus(); break;
|
|
411
|
+
default:
|
|
412
|
+
console.error("usage: apk-cache.js <key|get|put|base-get|base-put|overlay|status> [apk] [--json]");
|
|
413
|
+
code = 2;
|
|
414
|
+
}
|
|
415
|
+
process.exit(code);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (require.main === module) main();
|
|
419
|
+
|
|
420
|
+
module.exports = { nativeKey, bundleKey, fullKey, hashTree, walkFiles, dirs, finalApkPath, baseApkPath };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/*
|
|
4
|
+
* backend-build-cache — skip a repeated backend build when its inputs are
|
|
5
|
+
* unchanged.
|
|
6
|
+
*
|
|
7
|
+
* `device-up.sh` can run a production backend (`next build` + `next start`)
|
|
8
|
+
* instead of a dev server: it is lower and steadier on memory across the long
|
|
9
|
+
* matrix run. A production build is a heavy one-shot, so paying it on every
|
|
10
|
+
* bring-up would trade a memory win for a slow startup. This module
|
|
11
|
+
* content-addresses the declared inputs and lets `device-up.sh` skip the build
|
|
12
|
+
* when nothing changed.
|
|
13
|
+
*
|
|
14
|
+
* Inputs are the build command plus a project-declared `devBuildCache` list of
|
|
15
|
+
* git pathspec globs (in `local.json`). Resolution goes through `git ls-files`
|
|
16
|
+
* so globs use git's own semantics and ignored trees (`node_modules`, `.next`,
|
|
17
|
+
* `.git`) never enter the hash. A new/untracked file under a glob counts too.
|
|
18
|
+
*
|
|
19
|
+
* Project config (`scripts/qa/mobile-e2e/local.json`, project-owned):
|
|
20
|
+
* devBuildCmd the backend build command (e.g. `npm run build`)
|
|
21
|
+
* devBuildCache globs whose content invalidates the cache
|
|
22
|
+
* (e.g. ["app/**", "lib/**", "next.config.*", "package.json"])
|
|
23
|
+
* devBuildOutput optional artifact a hit must also find present
|
|
24
|
+
* (e.g. ".next/BUILD_ID") — so a deleted build output is a
|
|
25
|
+
* miss, never a skip that leaves `next start` with nothing
|
|
26
|
+
*
|
|
27
|
+
* CLI:
|
|
28
|
+
* backend-build-cache.js key --cmd "<cmd>" print the fingerprint (exit 3
|
|
29
|
+
* when no globs are declared)
|
|
30
|
+
* backend-build-cache.js check --cmd "<cmd>" exit 0 on a cache hit, 1 on a
|
|
31
|
+
* miss (stderr says why)
|
|
32
|
+
* backend-build-cache.js record --cmd "<cmd>" remember the current inputs
|
|
33
|
+
* backend-build-cache.js status human-readable state
|
|
34
|
+
*
|
|
35
|
+
* The cache is a pure accelerator: a miss (or `MOBILE_E2E_DEV_BUILD_FORCE=1`)
|
|
36
|
+
* always rebuilds. A failed build is never recorded.
|
|
37
|
+
*/
|
|
38
|
+
const fs = require("fs");
|
|
39
|
+
const path = require("path");
|
|
40
|
+
const crypto = require("crypto");
|
|
41
|
+
const { spawnSync } = require("child_process");
|
|
42
|
+
|
|
43
|
+
const ROOT = path.resolve(__dirname, "..", "..", "..");
|
|
44
|
+
const LOCAL_CONFIG = path.join(__dirname, "local.json");
|
|
45
|
+
const STATE_REL = path.join(".serve", "mobile-e2e-dev-build.json");
|
|
46
|
+
|
|
47
|
+
function sha256(buf) { return crypto.createHash("sha256").update(buf).digest("hex"); }
|
|
48
|
+
function sha256File(p) { try { return sha256(fs.readFileSync(p)); } catch (_) { return ""; } }
|
|
49
|
+
function stateFile(root) { return path.join(root || ROOT, STATE_REL); }
|
|
50
|
+
|
|
51
|
+
function projectConfig() {
|
|
52
|
+
try { return JSON.parse(fs.readFileSync(LOCAL_CONFIG, "utf8")); } catch (_) { return {}; }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* The declared cache globs, normalized. Absent/empty means "no caching" — the
|
|
56
|
+
* build runs every time rather than risk a stale hit. */
|
|
57
|
+
function configuredGlobs(cfg) {
|
|
58
|
+
const c = cfg || projectConfig();
|
|
59
|
+
const g = c.devBuildCache;
|
|
60
|
+
if (!Array.isArray(g)) return [];
|
|
61
|
+
return g.map((x) => String(x).trim()).filter(Boolean);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* Optional build artifact a cache hit must find present. Empty means the
|
|
65
|
+
* fingerprint alone decides. */
|
|
66
|
+
function configuredOutput(cfg) {
|
|
67
|
+
const c = cfg || projectConfig();
|
|
68
|
+
return typeof c.devBuildOutput === "string" ? c.devBuildOutput.trim() : "";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* Resolve globs to a sorted list of repo-relative files. Returns null when git
|
|
72
|
+
* or a repo is unavailable, so the caller falls back to no cache. */
|
|
73
|
+
function watchedFiles(globs, root) {
|
|
74
|
+
const base = root || ROOT;
|
|
75
|
+
if (!globs || !globs.length) return null;
|
|
76
|
+
const r = spawnSync(
|
|
77
|
+
"git",
|
|
78
|
+
["-C", base, "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", ...globs],
|
|
79
|
+
{ encoding: "buffer", maxBuffer: 64 * 1024 * 1024 }
|
|
80
|
+
);
|
|
81
|
+
if (r.status !== 0 || !r.stdout) return null;
|
|
82
|
+
return r.stdout.toString("utf8").split("\0").filter(Boolean).sort();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Content fingerprint of the declared inputs. Null when caching is disabled or
|
|
86
|
+
* the file set cannot be resolved. */
|
|
87
|
+
function fingerprint(opts) {
|
|
88
|
+
const o = opts || {};
|
|
89
|
+
const root = o.root || ROOT;
|
|
90
|
+
const globs = o.globs != null ? o.globs : configuredGlobs();
|
|
91
|
+
const files = watchedFiles(globs, root);
|
|
92
|
+
if (!files) return null;
|
|
93
|
+
const manifest = {
|
|
94
|
+
v: 1,
|
|
95
|
+
cmd: o.cmd || "",
|
|
96
|
+
files: files.map((rel) => [rel, sha256File(path.join(root, rel))]),
|
|
97
|
+
};
|
|
98
|
+
return sha256(JSON.stringify(manifest));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function readState(root) {
|
|
102
|
+
try { return JSON.parse(fs.readFileSync(stateFile(root), "utf8")); } catch (_) { return null; }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function writeState(state, root) {
|
|
106
|
+
const p = stateFile(root);
|
|
107
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
108
|
+
fs.writeFileSync(p, JSON.stringify(state, null, 2) + "\n", "utf8");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseArgs(argv) {
|
|
112
|
+
const out = { _: [], cmd: "" };
|
|
113
|
+
for (let i = 0; i < argv.length; i++) {
|
|
114
|
+
const a = argv[i];
|
|
115
|
+
if (a === "--cmd") out.cmd = argv[++i] || "";
|
|
116
|
+
else if (a.startsWith("--cmd=")) out.cmd = a.slice("--cmd=".length);
|
|
117
|
+
else out._.push(a);
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function cmdKey(args) {
|
|
123
|
+
const f = fingerprint({ cmd: args.cmd });
|
|
124
|
+
if (!f) {
|
|
125
|
+
console.error("backend-build-cache: no devBuildCache globs declared — not caching");
|
|
126
|
+
return 3;
|
|
127
|
+
}
|
|
128
|
+
console.log(f);
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function cmdCheck(args) {
|
|
133
|
+
const f = fingerprint({ cmd: args.cmd });
|
|
134
|
+
if (!f) {
|
|
135
|
+
console.error("backend-build-cache: no devBuildCache globs declared — not caching (always rebuild)");
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
const st = readState();
|
|
139
|
+
const output = configuredOutput();
|
|
140
|
+
const outputPresent = !output || fs.existsSync(path.join(ROOT, output));
|
|
141
|
+
if (st && st.fingerprint === f && st.cmd === args.cmd && outputPresent) {
|
|
142
|
+
console.log("backend-build-cache: HIT — inputs unchanged");
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
if (st && st.fingerprint === f && st.cmd === args.cmd && !outputPresent) {
|
|
146
|
+
console.log(`backend-build-cache: MISS — recorded build output "${output}" is absent`);
|
|
147
|
+
return 1;
|
|
148
|
+
}
|
|
149
|
+
console.log("backend-build-cache: MISS — inputs changed or first run");
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function cmdRecord(args) {
|
|
154
|
+
const f = fingerprint({ cmd: args.cmd });
|
|
155
|
+
if (!f) {
|
|
156
|
+
console.log("backend-build-cache: no globs declared — not recording");
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
writeState({ fingerprint: f, cmd: args.cmd, at: new Date().toISOString() });
|
|
160
|
+
console.log("backend-build-cache: recorded");
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function cmdStatus() {
|
|
165
|
+
const cfg = projectConfig();
|
|
166
|
+
const globs = configuredGlobs(cfg);
|
|
167
|
+
const output = configuredOutput(cfg);
|
|
168
|
+
const f = fingerprint({ cmd: cfg.devBuildCmd || "", globs });
|
|
169
|
+
const st = readState();
|
|
170
|
+
const outputPresent = !output || fs.existsSync(path.join(ROOT, output));
|
|
171
|
+
console.log(JSON.stringify({
|
|
172
|
+
globs,
|
|
173
|
+
output: output || null,
|
|
174
|
+
outputPresent,
|
|
175
|
+
current: f,
|
|
176
|
+
recorded: st ? { fingerprint: st.fingerprint, cmd: st.cmd, at: st.at } : null,
|
|
177
|
+
hit: !!(f && st && st.fingerprint === f && outputPresent),
|
|
178
|
+
}, null, 2));
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function main() {
|
|
183
|
+
const args = parseArgs(process.argv.slice(2));
|
|
184
|
+
const sub = args._[0];
|
|
185
|
+
let code = 0;
|
|
186
|
+
switch (sub) {
|
|
187
|
+
case "key": code = cmdKey(args); break;
|
|
188
|
+
case "check": code = cmdCheck(args); break;
|
|
189
|
+
case "record": code = cmdRecord(args); break;
|
|
190
|
+
case "status": code = cmdStatus(); break;
|
|
191
|
+
default:
|
|
192
|
+
console.error(
|
|
193
|
+
"usage: backend-build-cache.js <key|check|record|status> [--cmd \"<build command>\"]\n" +
|
|
194
|
+
" (globs come from local.json devBuildCache)"
|
|
195
|
+
);
|
|
196
|
+
code = 2;
|
|
197
|
+
}
|
|
198
|
+
process.exit(code);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (require.main === module) main();
|
|
202
|
+
|
|
203
|
+
module.exports = { fingerprint, watchedFiles, configuredGlobs, configuredOutput, sha256, stateFile };
|