mirror of
https://github.com/zgs225/cliproxy-plugin-commandcode.git
synced 2026-09-26 03:32:50 +08:00
build: pagecheck as standalone node script (inline escaping was fragile)
This commit is contained in:
@@ -7,15 +7,22 @@ else
|
|||||||
TARGET := commandcode.so
|
TARGET := commandcode.so
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: all build test clean lint
|
.PHONY: all build test clean lint pagecheck
|
||||||
|
|
||||||
all: build
|
all: build pagecheck
|
||||||
|
|
||||||
build:
|
build:
|
||||||
CGO_ENABLED=1 go build -buildmode=c-shared -o $(TARGET) main.go
|
CGO_ENABLED=1 go build -buildmode=c-shared -o $(TARGET) main.go
|
||||||
|
|
||||||
|
# Extract embedded JS from quota_page.go and syntax-check it with node.
|
||||||
|
# Guards against parse-time SyntaxErrors (e.g. duplicate const) that break
|
||||||
|
# the whole resource page; Go substring tests cannot catch these.
|
||||||
|
pagecheck:
|
||||||
|
@node scripts/pagecheck.js
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -v -race ./...
|
go test -v -race ./...
|
||||||
|
$(MAKE) pagecheck
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f commandcode.dylib commandcode.so commandcode.dll commandcode.h
|
rm -f commandcode.dylib commandcode.so commandcode.dll commandcode.h
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// pagecheck: syntax-check the embedded quota page JS (guards against
|
||||||
|
// parse-time SyntaxErrors like duplicate const that break the whole page).
|
||||||
|
const fs = require("fs");
|
||||||
|
const src = fs.readFileSync("plugin/quota_page.go", "utf8");
|
||||||
|
const m = src.match(/const QuotaPageHTML = `([\s\S]*)`/);
|
||||||
|
if (!m) {
|
||||||
|
console.error("pagecheck: QuotaPageHTML not found");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
const js = [...m[1].matchAll(/<script>([\s\S]*?)<\/script>/g)]
|
||||||
|
.map((x) => x[1])
|
||||||
|
.join("\n");
|
||||||
|
if (!js.trim()) {
|
||||||
|
console.error("pagecheck: no <script> content found");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
new Function(js);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("pagecheck: embedded JS SyntaxError:", e.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
console.log("pagecheck: embedded JS syntax OK");
|
||||||
Reference in New Issue
Block a user