@pmate/cli 0.45.4 → 0.46.1
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/dist/index.d.ts +6 -1
- package/dist/index.js +799 -576
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -88,7 +88,7 @@ var init_namespacedRef = __esm({
|
|
|
88
88
|
|
|
89
89
|
// src/sessionStore.ts
|
|
90
90
|
function buildSessionStorePath() {
|
|
91
|
-
return process.env.PMATE_SESSION_FILE?.trim() ||
|
|
91
|
+
return process.env.PMATE_SESSION_FILE?.trim() || import_node_path6.default.join(import_node_os5.default.homedir(), ".pmate", "session.json");
|
|
92
92
|
}
|
|
93
93
|
function assertValidAppRef(appRef2) {
|
|
94
94
|
return parseNamespacedRef(appRef2, { entityLabel: "app ref" }).fullId;
|
|
@@ -158,7 +158,7 @@ function loadSessionStore() {
|
|
|
158
158
|
}
|
|
159
159
|
function loadExistingSessionStoreOrEmpty() {
|
|
160
160
|
const sessionPath = buildSessionStorePath();
|
|
161
|
-
if (!(0,
|
|
161
|
+
if (!(0, import_node_fs5.existsSync)(sessionPath)) {
|
|
162
162
|
return {
|
|
163
163
|
version: SESSION_STORE_VERSION,
|
|
164
164
|
activeAppRef: DEFAULT_APP_ID,
|
|
@@ -177,10 +177,10 @@ function loadExistingSessionStoreOrEmpty() {
|
|
|
177
177
|
}
|
|
178
178
|
function loadSessionStoreWithPath() {
|
|
179
179
|
const sessionPath = buildSessionStorePath();
|
|
180
|
-
if (!(0,
|
|
180
|
+
if (!(0, import_node_fs5.existsSync)(sessionPath)) {
|
|
181
181
|
throw new Error(`Missing session file at ${sessionPath}. Run "pmate login" first.`);
|
|
182
182
|
}
|
|
183
|
-
const raw = (0,
|
|
183
|
+
const raw = (0, import_node_fs5.readFileSync)(sessionPath, "utf8");
|
|
184
184
|
const parsed = JSON.parse(raw);
|
|
185
185
|
const store = normalizeStore(parsed);
|
|
186
186
|
return { sessionPath, store };
|
|
@@ -270,12 +270,12 @@ function resolveReadApp(store, options) {
|
|
|
270
270
|
}
|
|
271
271
|
function writeSessionStore(store) {
|
|
272
272
|
const sessionPath = buildSessionStorePath();
|
|
273
|
-
(0,
|
|
274
|
-
(0,
|
|
273
|
+
(0, import_node_fs5.mkdirSync)(import_node_path6.default.dirname(sessionPath), { recursive: true });
|
|
274
|
+
(0, import_node_fs5.writeFileSync)(sessionPath, JSON.stringify(store, null, 2), {
|
|
275
275
|
mode: 384
|
|
276
276
|
});
|
|
277
277
|
try {
|
|
278
|
-
(0,
|
|
278
|
+
(0, import_node_fs5.chmodSync)(sessionPath, 384);
|
|
279
279
|
} catch {
|
|
280
280
|
}
|
|
281
281
|
}
|
|
@@ -285,13 +285,13 @@ function buildMissingSessionMessage(sessionPath, app) {
|
|
|
285
285
|
}
|
|
286
286
|
return `Missing session for app ${app} in ${sessionPath}. Run "pmate login --app ${app}" first.`;
|
|
287
287
|
}
|
|
288
|
-
var
|
|
288
|
+
var import_node_fs5, import_node_os5, import_node_path6, DEFAULT_APP_ID, SESSION_STORE_VERSION;
|
|
289
289
|
var init_sessionStore = __esm({
|
|
290
290
|
"src/sessionStore.ts"() {
|
|
291
291
|
"use strict";
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
292
|
+
import_node_fs5 = require("fs");
|
|
293
|
+
import_node_os5 = __toESM(require("os"));
|
|
294
|
+
import_node_path6 = __toESM(require("path"));
|
|
295
295
|
init_namespacedRef();
|
|
296
296
|
DEFAULT_APP_ID = "pmate:factory";
|
|
297
297
|
SESSION_STORE_VERSION = 4;
|
|
@@ -8823,14 +8823,225 @@ __export(index_exports, {
|
|
|
8823
8823
|
parseCommandArgs: () => parseCommandArgs
|
|
8824
8824
|
});
|
|
8825
8825
|
module.exports = __toCommonJS(index_exports);
|
|
8826
|
-
var
|
|
8827
|
-
var
|
|
8826
|
+
var import_node_fs32 = require("fs");
|
|
8827
|
+
var import_node_path37 = __toESM(require("path"));
|
|
8828
8828
|
|
|
8829
|
-
// src/
|
|
8829
|
+
// src/services/PackageInstaller.ts
|
|
8830
|
+
var import_node_child_process = require("child_process");
|
|
8831
|
+
var import_node_util = require("util");
|
|
8830
8832
|
var import_node_fs = require("fs");
|
|
8831
8833
|
var import_node_os = require("os");
|
|
8834
|
+
var import_node_path = __toESM(require("path"));
|
|
8835
|
+
var run = async (file, args, cwd) => {
|
|
8836
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process.execFile)(file, args, { cwd, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, timeout: 6e5, maxBuffer: 8 * 1024 * 1024 });
|
|
8837
|
+
return stdout.trim();
|
|
8838
|
+
};
|
|
8839
|
+
var semver = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
8840
|
+
var segment = /^[a-z][a-z0-9-]{0,62}$/;
|
|
8841
|
+
var relative = (p) => typeof p === "string" && !!p && !import_node_path.default.isAbsolute(p) && !p.includes("\\") && !p.includes("\0") && !p.split("/").some((x) => !x || x === "..");
|
|
8842
|
+
function packageRef(value) {
|
|
8843
|
+
const parts = value.includes(":") ? value.split(":") : ["pmate", value];
|
|
8844
|
+
if (parts.length !== 2 || parts.some((p) => !segment.test(p))) throw Error("Use a package name or namespace:name");
|
|
8845
|
+
return { namespace: parts[0], name: parts[1], id: parts.join(":") };
|
|
8846
|
+
}
|
|
8847
|
+
function validateInstallMetadata(value, id) {
|
|
8848
|
+
const p = value;
|
|
8849
|
+
if (!p || p.id !== id || p.id !== p.namespace + ":" + p.name || !semver.test(p.version) || !/^[-a-zA-Z0-9_.]+\/[-a-zA-Z0-9_.]+$/.test(p.repository) || !relative(p.directory) || !relative(p.manifest) || !Array.isArray(p.platforms) || !Array.isArray(p.prepare) || p.prepare.length > 20 || !p.bins || typeof p.bins !== "object" || !Object.keys(p.bins).length) throw Error("Invalid package registry metadata");
|
|
8850
|
+
for (const [name, file] of Object.entries(p.bins)) if (!segment.test(name) || !relative(file)) throw Error("Invalid package bin");
|
|
8851
|
+
for (const step of [...p.prepare, ...Object.values(p.lifecycle ?? {})]) if (!step || typeof step.command !== "string" || !step.command || step.command.includes("\0") || !Array.isArray(step.args) || step.args.some((a) => typeof a !== "string" || a.includes("\0")) || step.cwd !== void 0 && !relative(step.cwd)) throw Error("Invalid package command");
|
|
8852
|
+
if (p.lifecycle && !["health,start,status,stop", "drain,health,start,status,stop"].includes(Object.keys(p.lifecycle).sort().join(","))) throw Error("Incomplete package lifecycle");
|
|
8853
|
+
return p;
|
|
8854
|
+
}
|
|
8855
|
+
var PackageInstaller = class {
|
|
8856
|
+
constructor(ports = {}) {
|
|
8857
|
+
this.ports = ports;
|
|
8858
|
+
this.directory = import_node_path.default.join(ports.home ?? (0, import_node_os.homedir)(), ".pmate/packages");
|
|
8859
|
+
this.binDirectory = import_node_path.default.join(ports.home ?? (0, import_node_os.homedir)(), ".local/bin");
|
|
8860
|
+
}
|
|
8861
|
+
execute(file, args, cwd) {
|
|
8862
|
+
return (this.ports.run ?? run)(file, args, cwd);
|
|
8863
|
+
}
|
|
8864
|
+
say(message) {
|
|
8865
|
+
this.ports.progress?.(message);
|
|
8866
|
+
}
|
|
8867
|
+
records() {
|
|
8868
|
+
const file = import_node_path.default.join(this.directory, "installed.json");
|
|
8869
|
+
if (!(0, import_node_fs.existsSync)(file)) return {};
|
|
8870
|
+
const value = JSON.parse((0, import_node_fs.readFileSync)(file, "utf8"));
|
|
8871
|
+
if (value.schemaVersion !== 1 || !value.packages || typeof value.packages !== "object") throw Error("Invalid installed package registry");
|
|
8872
|
+
return value.packages;
|
|
8873
|
+
}
|
|
8874
|
+
save(packages) {
|
|
8875
|
+
const file = import_node_path.default.join(this.directory, "installed.json"), temporary = file + ".tmp-" + process.pid;
|
|
8876
|
+
(0, import_node_fs.writeFileSync)(temporary, JSON.stringify({ schemaVersion: 1, packages }, null, 2) + "\n", { mode: 384 });
|
|
8877
|
+
(0, import_node_fs.renameSync)(temporary, file);
|
|
8878
|
+
}
|
|
8879
|
+
local(root, relativePath) {
|
|
8880
|
+
if (!relative(relativePath)) throw Error("Invalid package path");
|
|
8881
|
+
const file = import_node_path.default.resolve(root, relativePath), base = (0, import_node_fs.realpathSync)(root);
|
|
8882
|
+
if ((0, import_node_fs.realpathSync)(file) !== base && !(0, import_node_fs.realpathSync)(file).startsWith(base + import_node_path.default.sep)) throw Error("Package path escapes repository");
|
|
8883
|
+
return file;
|
|
8884
|
+
}
|
|
8885
|
+
async step(root, step) {
|
|
8886
|
+
const cwd = step.cwd ? this.local(root, step.cwd) : root;
|
|
8887
|
+
return this.execute(step.command, step.args, cwd);
|
|
8888
|
+
}
|
|
8889
|
+
async healthy(root, step) {
|
|
8890
|
+
for (let attempt = 0; attempt < 15; attempt++) {
|
|
8891
|
+
try {
|
|
8892
|
+
const result = JSON.parse(await this.step(root, step));
|
|
8893
|
+
if (result.healthy === true) return;
|
|
8894
|
+
} catch {
|
|
8895
|
+
}
|
|
8896
|
+
if (attempt < 14) await (this.ports.wait ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(2e3);
|
|
8897
|
+
}
|
|
8898
|
+
throw Error("Package did not become healthy after startup");
|
|
8899
|
+
}
|
|
8900
|
+
async metadata(name) {
|
|
8901
|
+
const ref = packageRef(name), url = this.ports.registryUrl ?? "https://apps-api.pmate.chat";
|
|
8902
|
+
const response = await (this.ports.fetch ?? fetch)(url + "/packages/" + ref.namespace + "/" + ref.name, { signal: AbortSignal.timeout(15e3), headers: { "cache-control": "no-cache" }, redirect: "error" });
|
|
8903
|
+
const body = await response.json();
|
|
8904
|
+
if (!response.ok || !body.success) throw Error(body.message ?? "Package registry unavailable");
|
|
8905
|
+
return validateInstallMetadata(body.data, ref.id);
|
|
8906
|
+
}
|
|
8907
|
+
async install(name) {
|
|
8908
|
+
const metadata = await this.metadata(name);
|
|
8909
|
+
if (!metadata.platforms.includes(this.ports.platform ?? process.platform)) throw Error("Package is not supported on this platform");
|
|
8910
|
+
(0, import_node_fs.mkdirSync)(this.directory, { recursive: true, mode: 448 });
|
|
8911
|
+
if ((0, import_node_fs.lstatSync)(this.directory).isSymbolicLink()) throw Error("Package directory must not be a symlink");
|
|
8912
|
+
const lock = import_node_path.default.join(this.directory, "install.lock");
|
|
8913
|
+
try {
|
|
8914
|
+
(0, import_node_fs.mkdirSync)(lock);
|
|
8915
|
+
(0, import_node_fs.writeFileSync)(import_node_path.default.join(lock, "pid"), String(process.pid));
|
|
8916
|
+
} catch {
|
|
8917
|
+
throw Error("Another package installation is running; inspect ~/.pmate/packages/install.lock");
|
|
8918
|
+
}
|
|
8919
|
+
try {
|
|
8920
|
+
return await this.installLocked(metadata);
|
|
8921
|
+
} finally {
|
|
8922
|
+
(0, import_node_fs.rmSync)(lock, { recursive: true, force: true });
|
|
8923
|
+
}
|
|
8924
|
+
}
|
|
8925
|
+
async installLocked(metadata) {
|
|
8926
|
+
const records = this.records(), old = records[metadata.id], root = import_node_path.default.join(this.directory, "repos", ...metadata.repository.split("/"));
|
|
8927
|
+
(0, import_node_fs.mkdirSync)(import_node_path.default.dirname(root), { recursive: true, mode: 448 });
|
|
8928
|
+
if (old && old.root !== root) throw Error("Installed repository location differs; migration required");
|
|
8929
|
+
if ((0, import_node_fs.existsSync)(root)) {
|
|
8930
|
+
if ((0, import_node_fs.lstatSync)(root).isSymbolicLink()) throw Error("Repository directory must not be a symlink");
|
|
8931
|
+
const remote = (await this.execute("git", ["remote", "get-url", "origin"], root)).replace(/\.git$/, "");
|
|
8932
|
+
if (!remote.endsWith("/" + metadata.repository) && !remote.endsWith(":" + metadata.repository)) throw Error("Installed repository origin differs");
|
|
8933
|
+
if (await this.execute("git", ["status", "--porcelain"], root)) throw Error("Installed repository contains local changes; preserve them before updating");
|
|
8934
|
+
}
|
|
8935
|
+
(0, import_node_fs.mkdirSync)(this.binDirectory, { recursive: true });
|
|
8936
|
+
for (const name of Object.keys(metadata.bins)) {
|
|
8937
|
+
const file = import_node_path.default.join(this.binDirectory, name), stat = (0, import_node_fs.lstatSync)(file, { throwIfNoEntry: false });
|
|
8938
|
+
if (stat && (!old?.bins[name] || !stat.isSymbolicLink() || (0, import_node_fs.realpathSync)(file) !== (0, import_node_fs.realpathSync)(old.bins[name]))) throw Error("Refusing to replace unmanaged command: " + name);
|
|
8939
|
+
}
|
|
8940
|
+
if (old?.version === metadata.version && (0, import_node_fs.existsSync)(root)) {
|
|
8941
|
+
const manifest = JSON.parse((0, import_node_fs.readFileSync)(this.local(root, import_node_path.default.posix.join(metadata.directory, metadata.manifest)), "utf8"));
|
|
8942
|
+
if (manifest.version !== old.version) throw Error("Installed manifest does not match the recorded version");
|
|
8943
|
+
for (const [name, file] of Object.entries(old.bins)) if (!(0, import_node_fs.existsSync)(import_node_path.default.join(this.binDirectory, name)) || (0, import_node_fs.realpathSync)(import_node_path.default.join(this.binDirectory, name)) !== (0, import_node_fs.realpathSync)(file)) throw Error("Installed bin is missing or changed: " + name);
|
|
8944
|
+
this.say(metadata.id + " is already installed (" + metadata.version + ")");
|
|
8945
|
+
return { ...old, changed: false };
|
|
8946
|
+
}
|
|
8947
|
+
if (old && old.version.split(".").map(BigInt).some((part, i, parts) => part > BigInt(metadata.version.split(".")[i]) && parts.slice(0, i).every((p, j) => p === BigInt(metadata.version.split(".")[j])))) throw Error("Published package version is older than the installed version");
|
|
8948
|
+
let wasRunning = false, stopped = false;
|
|
8949
|
+
if (old?.definition.lifecycle) {
|
|
8950
|
+
const lifecycle = old.definition.lifecycle, deadline = (this.ports.now ?? Date.now)() + 3e5;
|
|
8951
|
+
let drained = false;
|
|
8952
|
+
try {
|
|
8953
|
+
for (; ; ) {
|
|
8954
|
+
const status = JSON.parse(await this.step(root, lifecycle.status));
|
|
8955
|
+
wasRunning ||= status.running === true;
|
|
8956
|
+
if (!Number.isSafeInteger(status.activeRuns) || status.activeRuns < 0) throw Error("Invalid package lifecycle status");
|
|
8957
|
+
if (wasRunning && !drained && lifecycle.drain) {
|
|
8958
|
+
await this.step(root, lifecycle.drain);
|
|
8959
|
+
drained = true;
|
|
8960
|
+
}
|
|
8961
|
+
if (status.activeRuns === 0) break;
|
|
8962
|
+
if ((this.ports.now ?? Date.now)() >= deadline) throw Error("Active Runs have not finished; installation did not update the old package");
|
|
8963
|
+
this.say("Waiting for active Runs to finish");
|
|
8964
|
+
await (this.ports.wait ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(2e3);
|
|
8965
|
+
}
|
|
8966
|
+
if (wasRunning) {
|
|
8967
|
+
await this.step(root, lifecycle.stop);
|
|
8968
|
+
stopped = true;
|
|
8969
|
+
}
|
|
8970
|
+
} catch (error) {
|
|
8971
|
+
if (drained && !stopped) await this.step(root, lifecycle.start);
|
|
8972
|
+
throw error;
|
|
8973
|
+
}
|
|
8974
|
+
}
|
|
8975
|
+
const previousCommit = (0, import_node_fs.existsSync)(root) ? await this.execute("git", ["rev-parse", "HEAD"], root) : void 0;
|
|
8976
|
+
try {
|
|
8977
|
+
if (!(0, import_node_fs.existsSync)(root)) {
|
|
8978
|
+
this.say("Cloning " + metadata.repository);
|
|
8979
|
+
await this.execute("git", ["clone", "--branch", "main", "https://github.com/" + metadata.repository + ".git", root], import_node_path.default.dirname(root));
|
|
8980
|
+
} else {
|
|
8981
|
+
this.say("Updating " + metadata.repository);
|
|
8982
|
+
await this.execute("git", ["pull", "--ff-only", "origin", "main"], root);
|
|
8983
|
+
}
|
|
8984
|
+
const manifest = JSON.parse((0, import_node_fs.readFileSync)(this.local(root, import_node_path.default.posix.join(metadata.directory, metadata.manifest)), "utf8"));
|
|
8985
|
+
if (manifest.version !== metadata.version) throw Error("Repository component version does not match the published package version");
|
|
8986
|
+
for (const sibling of Object.values(records).filter((p) => p.root === root && p.id !== metadata.id)) {
|
|
8987
|
+
const manifest2 = JSON.parse((0, import_node_fs.readFileSync)(this.local(root, import_node_path.default.posix.join(sibling.directory, sibling.manifest)), "utf8"));
|
|
8988
|
+
if (manifest2.version !== sibling.version) throw Error("Shared repository also requires an update to " + sibling.id);
|
|
8989
|
+
}
|
|
8990
|
+
for (const step of metadata.prepare) {
|
|
8991
|
+
this.say("Preparing " + metadata.id + ": " + step.command);
|
|
8992
|
+
await this.step(root, step);
|
|
8993
|
+
}
|
|
8994
|
+
const bins = {};
|
|
8995
|
+
for (const [name, file] of Object.entries(metadata.bins)) {
|
|
8996
|
+
const target = this.local(root, file);
|
|
8997
|
+
if (!(0, import_node_fs.lstatSync)(target).isFile()) throw Error("Package bin is not a regular file");
|
|
8998
|
+
(0, import_node_fs.chmodSync)(target, 493);
|
|
8999
|
+
bins[name] = target;
|
|
9000
|
+
}
|
|
9001
|
+
const commit = await this.execute("git", ["rev-parse", "HEAD"], root);
|
|
9002
|
+
if (wasRunning && metadata.lifecycle) {
|
|
9003
|
+
await this.step(root, metadata.lifecycle.start);
|
|
9004
|
+
await this.healthy(root, metadata.lifecycle.health);
|
|
9005
|
+
}
|
|
9006
|
+
for (const [name, target] of Object.entries(bins)) {
|
|
9007
|
+
const link = import_node_path.default.join(this.binDirectory, name), temporary = link + ".install-" + process.pid;
|
|
9008
|
+
(0, import_node_fs.symlinkSync)(target, temporary);
|
|
9009
|
+
(0, import_node_fs.renameSync)(temporary, link);
|
|
9010
|
+
}
|
|
9011
|
+
const record = { id: metadata.id, version: metadata.version, root, directory: metadata.directory, manifest: metadata.manifest, bins, metadataRevision: metadata.revision, commit, installedAt: (/* @__PURE__ */ new Date()).toISOString(), definition: metadata };
|
|
9012
|
+
records[metadata.id] = record;
|
|
9013
|
+
this.save(records);
|
|
9014
|
+
this.say("Installed " + metadata.id + " " + metadata.version);
|
|
9015
|
+
return { ...record, changed: true };
|
|
9016
|
+
} catch (error) {
|
|
9017
|
+
if (stopped && old && previousCommit) {
|
|
9018
|
+
try {
|
|
9019
|
+
if (await this.execute("git", ["status", "--porcelain", "--untracked-files=no"], root)) throw Error("Failed upgrade changed tracked files");
|
|
9020
|
+
await this.execute("git", ["checkout", "--detach", previousCommit], root);
|
|
9021
|
+
for (const step of old.definition.prepare) await this.step(root, step);
|
|
9022
|
+
await this.step(root, old.definition.lifecycle.start);
|
|
9023
|
+
await this.healthy(root, old.definition.lifecycle.health);
|
|
9024
|
+
this.say("Upgrade failed; restored the previously installed package " + old.version);
|
|
9025
|
+
} catch {
|
|
9026
|
+
this.say("Upgrade failed and automatic recovery could not complete. Previous commit: " + previousCommit + ". Credentials, data and the installation record were preserved.");
|
|
9027
|
+
}
|
|
9028
|
+
}
|
|
9029
|
+
throw error;
|
|
9030
|
+
}
|
|
9031
|
+
}
|
|
9032
|
+
};
|
|
9033
|
+
|
|
9034
|
+
// src/installCommandParser.ts
|
|
9035
|
+
function parseInstallArgs(args) {
|
|
9036
|
+
if (args.length !== 1 || !args[0] || args[0].startsWith("-")) throw Error("Usage: pmate install <package>");
|
|
9037
|
+
return { type: "install" /* Install */, package: args[0] };
|
|
9038
|
+
}
|
|
9039
|
+
|
|
9040
|
+
// src/managedSession.ts
|
|
9041
|
+
var import_node_fs2 = require("fs");
|
|
9042
|
+
var import_node_os2 = require("os");
|
|
8832
9043
|
var import_node_crypto = require("crypto");
|
|
8833
|
-
var
|
|
9044
|
+
var import_node_path2 = require("path");
|
|
8834
9045
|
async function ensureManagedSession(env = process.env, fetcher = fetch) {
|
|
8835
9046
|
if (env.PMATE_EXPECTED_ACCOUNT_ID && env.HEBO_MEMORY_TOKEN?.trim()) throw Error("Bound Agent CLI cannot use another delegated identity");
|
|
8836
9047
|
if (env.HEBO_MEMORY_TOKEN?.trim()) {
|
|
@@ -8843,19 +9054,19 @@ async function ensureManagedSession(env = process.env, fetcher = fetch) {
|
|
|
8843
9054
|
const pr = await fetcher(`${base}/profiles?app=${encodeURIComponent(app)}&account=${encodeURIComponent(session.identity.accountId)}`, { headers, signal: AbortSignal.timeout(15e3) });
|
|
8844
9055
|
const profiles = await pr.json(), profileId = profiles.data?.[0]?.id;
|
|
8845
9056
|
if (!pr.ok || !profiles.success || !profileId) throw Error("Delegated user profile unavailable");
|
|
8846
|
-
const dir = (0,
|
|
8847
|
-
(0,
|
|
9057
|
+
const dir = (0, import_node_fs2.mkdtempSync)((0, import_node_path2.join)((0, import_node_os2.tmpdir)(), "pmate-delegated-")), file = (0, import_node_path2.join)(dir, "session.json");
|
|
9058
|
+
(0, import_node_fs2.writeFileSync)(file, JSON.stringify({ version: 4, activeAppRef: app, sessions: { [app]: { token, accountId: session.identity.accountId, profileId, issuedAt: session.issuedAt, expiresAt: session.expiresAt, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } } }), { mode: 384 });
|
|
8848
9059
|
env.PMATE_SESSION_FILE = file;
|
|
8849
9060
|
env.PCS_AGENT_SESSION_MANAGED = "0";
|
|
8850
9061
|
process.once("exit", () => {
|
|
8851
|
-
(0,
|
|
9062
|
+
(0, import_node_fs2.rmSync)(dir, { recursive: true, force: true });
|
|
8852
9063
|
});
|
|
8853
9064
|
return;
|
|
8854
9065
|
}
|
|
8855
9066
|
if (env.PCS_AGENT_SESSION_MANAGED !== "1") return;
|
|
8856
9067
|
if (!env.PMATE_SESSION_FILE) throw Error("Managed session file is required");
|
|
8857
9068
|
const source = env.PCS_AGENT_SESSION_SOURCE_FILE ?? env.PMATE_SESSION_FILE;
|
|
8858
|
-
const state = JSON.parse((0,
|
|
9069
|
+
const state = JSON.parse((0, import_node_fs2.readFileSync)(source, "utf8"));
|
|
8859
9070
|
if (!state.refreshKey) throw Error("Managed session refresh key is missing");
|
|
8860
9071
|
const port = Number(env.PMATE_SESSION_REFRESH_PORT ?? env.PCS_AGENT_CONTROL_PORT ?? 39399);
|
|
8861
9072
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw Error("Invalid controller port");
|
|
@@ -8866,12 +9077,12 @@ async function ensureManagedSession(env = process.env, fetcher = fetch) {
|
|
|
8866
9077
|
});
|
|
8867
9078
|
if (!r.ok) throw Error(`Managed session renewal unavailable (${r.status}); retry later`);
|
|
8868
9079
|
if (source !== env.PMATE_SESSION_FILE) {
|
|
8869
|
-
const raw = (0,
|
|
9080
|
+
const raw = (0, import_node_fs2.readFileSync)(source, "utf8"), current = JSON.parse(raw).sessions?.[env.PMATE_SESSION_APP ?? "pmate:factory"];
|
|
8870
9081
|
if (env.PMATE_EXPECTED_ACCOUNT_ID && current?.accountId !== env.PMATE_EXPECTED_ACCOUNT_ID) throw Error("Renewed Agent CLI Account mismatch");
|
|
8871
9082
|
if (env.PMATE_EXPECTED_PROFILE_ID && current?.profileId !== env.PMATE_EXPECTED_PROFILE_ID) throw Error("Renewed Agent CLI Profile mismatch");
|
|
8872
9083
|
const temp = `${env.PMATE_SESSION_FILE}.${(0, import_node_crypto.randomUUID)()}.tmp`;
|
|
8873
|
-
(0,
|
|
8874
|
-
(0,
|
|
9084
|
+
(0, import_node_fs2.writeFileSync)(temp, raw, { mode: 384, flag: "wx" });
|
|
9085
|
+
(0, import_node_fs2.renameSync)(temp, env.PMATE_SESSION_FILE);
|
|
8875
9086
|
}
|
|
8876
9087
|
}
|
|
8877
9088
|
|
|
@@ -8918,12 +9129,12 @@ var ui = {
|
|
|
8918
9129
|
};
|
|
8919
9130
|
|
|
8920
9131
|
// src/commands/ListCommandHandler.ts
|
|
8921
|
-
var
|
|
9132
|
+
var import_node_path4 = __toESM(require("path"));
|
|
8922
9133
|
|
|
8923
9134
|
// src/config.ts
|
|
8924
|
-
var
|
|
8925
|
-
var
|
|
8926
|
-
var
|
|
9135
|
+
var import_node_fs3 = require("fs");
|
|
9136
|
+
var import_node_os3 = __toESM(require("os"));
|
|
9137
|
+
var import_node_path3 = __toESM(require("path"));
|
|
8927
9138
|
var import_ajv = __toESM(require("ajv"));
|
|
8928
9139
|
var import_yaml = __toESM(require("yaml"));
|
|
8929
9140
|
var cachedConfig;
|
|
@@ -9047,11 +9258,11 @@ function loadPmateConfig() {
|
|
|
9047
9258
|
if (cachedConfig !== void 0) {
|
|
9048
9259
|
return cachedConfig ?? {};
|
|
9049
9260
|
}
|
|
9050
|
-
const pmateDir =
|
|
9051
|
-
const yamlPath =
|
|
9261
|
+
const pmateDir = import_node_path3.default.join(import_node_os3.default.homedir(), ".pmate");
|
|
9262
|
+
const yamlPath = import_node_path3.default.join(pmateDir, "config.yaml");
|
|
9052
9263
|
let yamlConfig = null;
|
|
9053
|
-
if ((0,
|
|
9054
|
-
const raw = (0,
|
|
9264
|
+
if ((0, import_node_fs3.existsSync)(yamlPath)) {
|
|
9265
|
+
const raw = (0, import_node_fs3.readFileSync)(yamlPath, "utf8");
|
|
9055
9266
|
try {
|
|
9056
9267
|
const parsed = import_yaml.default.parse(raw);
|
|
9057
9268
|
yamlConfig = validateParsedConfig(parsed, yamlPath);
|
|
@@ -9113,21 +9324,21 @@ ${detail}`);
|
|
|
9113
9324
|
return value;
|
|
9114
9325
|
}
|
|
9115
9326
|
function findRepoConfigPaths(cwd, searchParents) {
|
|
9116
|
-
let current =
|
|
9327
|
+
let current = import_node_path3.default.resolve(cwd);
|
|
9117
9328
|
while (true) {
|
|
9118
|
-
const candidate =
|
|
9119
|
-
if ((0,
|
|
9120
|
-
const localCandidate =
|
|
9329
|
+
const candidate = import_node_path3.default.join(current, ".pmate.yaml");
|
|
9330
|
+
if ((0, import_node_fs3.existsSync)(candidate)) {
|
|
9331
|
+
const localCandidate = import_node_path3.default.join(current, ".pmate.local.yaml");
|
|
9121
9332
|
return {
|
|
9122
9333
|
rootDir: current,
|
|
9123
9334
|
configPath: candidate,
|
|
9124
|
-
localConfigPath: (0,
|
|
9335
|
+
localConfigPath: (0, import_node_fs3.existsSync)(localCandidate) ? localCandidate : void 0
|
|
9125
9336
|
};
|
|
9126
9337
|
}
|
|
9127
9338
|
if (!searchParents) {
|
|
9128
9339
|
return null;
|
|
9129
9340
|
}
|
|
9130
|
-
const parent =
|
|
9341
|
+
const parent = import_node_path3.default.dirname(current);
|
|
9131
9342
|
if (parent === current) {
|
|
9132
9343
|
return null;
|
|
9133
9344
|
}
|
|
@@ -9143,7 +9354,7 @@ function loadMergedRepoYaml(paths) {
|
|
|
9143
9354
|
return mergeRepoConfigValues(base, local);
|
|
9144
9355
|
}
|
|
9145
9356
|
function parseYamlFile(configPath) {
|
|
9146
|
-
const raw = (0,
|
|
9357
|
+
const raw = (0, import_node_fs3.readFileSync)(configPath, "utf8");
|
|
9147
9358
|
try {
|
|
9148
9359
|
return import_yaml.default.parse(raw);
|
|
9149
9360
|
} catch (error) {
|
|
@@ -9298,7 +9509,7 @@ var ListCommandHandler = class {
|
|
|
9298
9509
|
}
|
|
9299
9510
|
}
|
|
9300
9511
|
resolveTargetDir(targetPath) {
|
|
9301
|
-
return targetPath ?
|
|
9512
|
+
return targetPath ? import_node_path4.default.resolve(process.cwd(), targetPath) : process.cwd();
|
|
9302
9513
|
}
|
|
9303
9514
|
loadConfig(targetDir) {
|
|
9304
9515
|
return loadAppConfig(targetDir).config;
|
|
@@ -9306,23 +9517,23 @@ var ListCommandHandler = class {
|
|
|
9306
9517
|
};
|
|
9307
9518
|
|
|
9308
9519
|
// src/commands/LoginCommandHandler.ts
|
|
9309
|
-
var
|
|
9310
|
-
var
|
|
9520
|
+
var import_node_child_process2 = require("child_process");
|
|
9521
|
+
var import_node_path7 = __toESM(require("path"));
|
|
9311
9522
|
var import_node_http = require("http");
|
|
9312
9523
|
var import_promises = require("readline/promises");
|
|
9313
9524
|
|
|
9314
9525
|
// src/accessKeyFile.ts
|
|
9315
|
-
var
|
|
9316
|
-
var
|
|
9317
|
-
var
|
|
9526
|
+
var import_node_fs4 = require("fs");
|
|
9527
|
+
var import_node_os4 = __toESM(require("os"));
|
|
9528
|
+
var import_node_path5 = __toESM(require("path"));
|
|
9318
9529
|
function readAccessKeyFile(filePath, options = {}) {
|
|
9319
9530
|
const absolutePath = resolveFilePath(filePath, options.cwd);
|
|
9320
|
-
if (!(0,
|
|
9531
|
+
if (!(0, import_node_fs4.existsSync)(absolutePath)) {
|
|
9321
9532
|
throw new Error(`Access key file not found: ${absolutePath}`);
|
|
9322
9533
|
}
|
|
9323
9534
|
let parsed;
|
|
9324
9535
|
try {
|
|
9325
|
-
parsed = JSON.parse((0,
|
|
9536
|
+
parsed = JSON.parse((0, import_node_fs4.readFileSync)(absolutePath, "utf8"));
|
|
9326
9537
|
} catch (error) {
|
|
9327
9538
|
const message = error instanceof Error ? error.message : String(error);
|
|
9328
9539
|
throw new Error(`Invalid JSON in ${absolutePath}: ${message}`);
|
|
@@ -9339,10 +9550,10 @@ function readAccessKeyFile(filePath, options = {}) {
|
|
|
9339
9550
|
}
|
|
9340
9551
|
function scanAccessKeyFiles(app) {
|
|
9341
9552
|
const dir = resolveAccessKeyDir(app);
|
|
9342
|
-
if (!(0,
|
|
9553
|
+
if (!(0, import_node_fs4.existsSync)(dir)) {
|
|
9343
9554
|
return [];
|
|
9344
9555
|
}
|
|
9345
|
-
return (0,
|
|
9556
|
+
return (0, import_node_fs4.readdirSync)(dir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".access-key.json")).map((entry) => import_node_path5.default.join(dir, entry.name)).flatMap((filePath) => {
|
|
9346
9557
|
try {
|
|
9347
9558
|
return [{ filePath, key: readAccessKeyFile(filePath, { expectedApp: app }) }];
|
|
9348
9559
|
} catch {
|
|
@@ -9351,13 +9562,13 @@ function scanAccessKeyFiles(app) {
|
|
|
9351
9562
|
}).sort((a, b) => a.key.name.localeCompare(b.key.name) || a.filePath.localeCompare(b.filePath));
|
|
9352
9563
|
}
|
|
9353
9564
|
function resolveAccessKeyDir(app) {
|
|
9354
|
-
return
|
|
9565
|
+
return import_node_path5.default.join(homeDir(), ".pmate", "access-keys", app);
|
|
9355
9566
|
}
|
|
9356
9567
|
function resolveFilePath(filePath, cwd = process.cwd()) {
|
|
9357
|
-
return
|
|
9568
|
+
return import_node_path5.default.isAbsolute(filePath) ? filePath : import_node_path5.default.resolve(cwd, filePath);
|
|
9358
9569
|
}
|
|
9359
9570
|
function homeDir() {
|
|
9360
|
-
return process.env.HOME || process.env.USERPROFILE ||
|
|
9571
|
+
return process.env.HOME || process.env.USERPROFILE || import_node_os4.default.homedir() || process.cwd();
|
|
9361
9572
|
}
|
|
9362
9573
|
function isAccessKeyFile(value) {
|
|
9363
9574
|
if (!value || typeof value !== "object") {
|
|
@@ -9658,7 +9869,7 @@ var LoginCommandHandler = class {
|
|
|
9658
9869
|
key.id?.trim(),
|
|
9659
9870
|
key.namespace?.trim(),
|
|
9660
9871
|
`expires ${key.expiresAt}`,
|
|
9661
|
-
|
|
9872
|
+
import_node_path7.default.relative(process.cwd(), candidate.filePath)
|
|
9662
9873
|
].filter(Boolean);
|
|
9663
9874
|
return parts.join(" / ");
|
|
9664
9875
|
}
|
|
@@ -9857,7 +10068,7 @@ var LoginCommandHandler = class {
|
|
|
9857
10068
|
const platform = process.platform;
|
|
9858
10069
|
const command = platform === "darwin" ? { cmd: "open", args: [url] } : platform === "win32" ? { cmd: "cmd", args: ["/c", "start", "", url] } : { cmd: "xdg-open", args: [url] };
|
|
9859
10070
|
try {
|
|
9860
|
-
const child = (0,
|
|
10071
|
+
const child = (0, import_node_child_process2.spawn)(command.cmd, command.args, {
|
|
9861
10072
|
detached: true,
|
|
9862
10073
|
stdio: "ignore"
|
|
9863
10074
|
});
|
|
@@ -9877,8 +10088,8 @@ var import_openapi_client = require("@alicloud/openapi-client");
|
|
|
9877
10088
|
var import_sts20150401 = __toESM(require("@alicloud/sts20150401"));
|
|
9878
10089
|
var import_ali_oss = __toESM(require("ali-oss"));
|
|
9879
10090
|
var import_node_crypto2 = require("crypto");
|
|
9880
|
-
var
|
|
9881
|
-
var
|
|
10091
|
+
var import_node_fs6 = require("fs");
|
|
10092
|
+
var import_node_path8 = __toESM(require("path"));
|
|
9882
10093
|
|
|
9883
10094
|
// src/certs.ts
|
|
9884
10095
|
var DEFAULT_SSL_CERT_KEY = "pmate-01";
|
|
@@ -10171,7 +10382,7 @@ var AliyunService = class {
|
|
|
10171
10382
|
])
|
|
10172
10383
|
);
|
|
10173
10384
|
for (const filePath of files) {
|
|
10174
|
-
const relativePath =
|
|
10385
|
+
const relativePath = import_node_path8.default.relative(localDir, filePath);
|
|
10175
10386
|
const objectKey = this.toObjectKey(normalizedPrefix, relativePath);
|
|
10176
10387
|
const contentType = this.getContentType(filePath);
|
|
10177
10388
|
const cacheControl = this.getStaticAssetCacheControl(relativePath);
|
|
@@ -10181,7 +10392,7 @@ var AliyunService = class {
|
|
|
10181
10392
|
const options = Object.keys(headers).length > 0 ? { headers } : void 0;
|
|
10182
10393
|
const existing = existingMap.get(objectKey);
|
|
10183
10394
|
if (existing && typeof existing.size === "number" && !cacheControl) {
|
|
10184
|
-
const stat = await
|
|
10395
|
+
const stat = await import_node_fs6.promises.stat(filePath);
|
|
10185
10396
|
if (stat.size === existing.size) {
|
|
10186
10397
|
const etag = this.normalizeEtag(existing.etag);
|
|
10187
10398
|
if (etag && !etag.includes("-")) {
|
|
@@ -10206,7 +10417,7 @@ var AliyunService = class {
|
|
|
10206
10417
|
if (!region) throw new Error("Missing oss.public.region in ~/.pmate/config.yaml.");
|
|
10207
10418
|
if (!accessKeyId) throw new Error("Missing aliyun.ak in ~/.pmate/config.yaml.");
|
|
10208
10419
|
if (!accessKeySecret) throw new Error("Missing aliyun.sk in ~/.pmate/config.yaml.");
|
|
10209
|
-
if (!(0,
|
|
10420
|
+
if (!(0, import_node_fs6.existsSync)(localFile)) {
|
|
10210
10421
|
throw new Error(`File not found: ${localFile}`);
|
|
10211
10422
|
}
|
|
10212
10423
|
const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 });
|
|
@@ -10596,10 +10807,10 @@ var AliyunService = class {
|
|
|
10596
10807
|
}
|
|
10597
10808
|
/** Recursively collect file paths under a directory. */
|
|
10598
10809
|
static async collectFiles(dir) {
|
|
10599
|
-
const entries = await
|
|
10810
|
+
const entries = await import_node_fs6.promises.readdir(dir, { withFileTypes: true });
|
|
10600
10811
|
const files = [];
|
|
10601
10812
|
for (const entry of entries) {
|
|
10602
|
-
const fullPath =
|
|
10813
|
+
const fullPath = import_node_path8.default.join(dir, entry.name);
|
|
10603
10814
|
if (entry.isDirectory()) {
|
|
10604
10815
|
files.push(...await this.collectFiles(fullPath));
|
|
10605
10816
|
} else if (entry.isFile()) {
|
|
@@ -10648,7 +10859,7 @@ var AliyunService = class {
|
|
|
10648
10859
|
static getFileMd5(filePath) {
|
|
10649
10860
|
return new Promise((resolve, reject) => {
|
|
10650
10861
|
const hash = (0, import_node_crypto2.createHash)("md5");
|
|
10651
|
-
const stream = (0,
|
|
10862
|
+
const stream = (0, import_node_fs6.createReadStream)(filePath);
|
|
10652
10863
|
stream.on("data", (chunk) => {
|
|
10653
10864
|
hash.update(chunk);
|
|
10654
10865
|
});
|
|
@@ -10661,17 +10872,17 @@ var AliyunService = class {
|
|
|
10661
10872
|
});
|
|
10662
10873
|
}
|
|
10663
10874
|
static toObjectKey(prefix, relativePath) {
|
|
10664
|
-
const normalizedPath = relativePath.split(
|
|
10875
|
+
const normalizedPath = relativePath.split(import_node_path8.default.sep).join("/");
|
|
10665
10876
|
if (!prefix) {
|
|
10666
10877
|
return normalizedPath;
|
|
10667
10878
|
}
|
|
10668
10879
|
return `${prefix}/${normalizedPath}`;
|
|
10669
10880
|
}
|
|
10670
10881
|
static getContentType(filePath) {
|
|
10671
|
-
if (
|
|
10882
|
+
if (import_node_path8.default.basename(filePath).toLowerCase() === "apple-app-site-association") {
|
|
10672
10883
|
return "application/json";
|
|
10673
10884
|
}
|
|
10674
|
-
const ext =
|
|
10885
|
+
const ext = import_node_path8.default.extname(filePath).toLowerCase();
|
|
10675
10886
|
switch (ext) {
|
|
10676
10887
|
case ".html":
|
|
10677
10888
|
return "text/html";
|
|
@@ -10714,7 +10925,7 @@ var AliyunService = class {
|
|
|
10714
10925
|
}
|
|
10715
10926
|
static getStaticAssetCacheControl(filePath) {
|
|
10716
10927
|
const normalized = filePath.replace(/\\/g, "/");
|
|
10717
|
-
const base =
|
|
10928
|
+
const base = import_node_path8.default.posix.basename(normalized).toLowerCase();
|
|
10718
10929
|
if (base === "index.html" || base === "200.html" || base === "404.html" || base === "latest.json" || base === "apple-app-site-association") {
|
|
10719
10930
|
return "no-cache, no-store, must-revalidate";
|
|
10720
10931
|
}
|
|
@@ -10931,8 +11142,8 @@ var BucketCommandHandler = class {
|
|
|
10931
11142
|
};
|
|
10932
11143
|
|
|
10933
11144
|
// src/commands/DeleteCommandHandler.ts
|
|
10934
|
-
var
|
|
10935
|
-
var
|
|
11145
|
+
var import_node_path9 = __toESM(require("path"));
|
|
11146
|
+
var import_node_child_process3 = require("child_process");
|
|
10936
11147
|
|
|
10937
11148
|
// src/serverAddress.ts
|
|
10938
11149
|
var import_promises2 = require("dns/promises");
|
|
@@ -11055,7 +11266,7 @@ var DeleteCommandHandler = class {
|
|
|
11055
11266
|
removeRemoteConfig(server, remotePath) {
|
|
11056
11267
|
return new Promise((resolve, reject) => {
|
|
11057
11268
|
const target = `pmate@${server}`;
|
|
11058
|
-
const child = (0,
|
|
11269
|
+
const child = (0, import_node_child_process3.spawn)("ssh", [target, "sudo", "rm", "-f", remotePath], {
|
|
11059
11270
|
stdio: ["ignore", "inherit", "inherit"]
|
|
11060
11271
|
});
|
|
11061
11272
|
child.on("error", (error) => {
|
|
@@ -11073,7 +11284,7 @@ var DeleteCommandHandler = class {
|
|
|
11073
11284
|
reloadNginx(server) {
|
|
11074
11285
|
return new Promise((resolve, reject) => {
|
|
11075
11286
|
const target = `pmate@${server}`;
|
|
11076
|
-
const child = (0,
|
|
11287
|
+
const child = (0, import_node_child_process3.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
11077
11288
|
stdio: ["ignore", "inherit", "inherit"]
|
|
11078
11289
|
});
|
|
11079
11290
|
child.on("error", (error) => {
|
|
@@ -11089,17 +11300,17 @@ var DeleteCommandHandler = class {
|
|
|
11089
11300
|
});
|
|
11090
11301
|
}
|
|
11091
11302
|
resolveCwd(target) {
|
|
11092
|
-
return target ?
|
|
11303
|
+
return target ? import_node_path9.default.resolve(process.cwd(), target) : process.cwd();
|
|
11093
11304
|
}
|
|
11094
11305
|
};
|
|
11095
11306
|
|
|
11096
11307
|
// src/commands/DevCommandHandler.ts
|
|
11097
|
-
var
|
|
11098
|
-
var
|
|
11099
|
-
var
|
|
11308
|
+
var import_node_fs7 = require("fs");
|
|
11309
|
+
var import_node_path11 = __toESM(require("path"));
|
|
11310
|
+
var import_node_child_process4 = require("child_process");
|
|
11100
11311
|
|
|
11101
11312
|
// src/appDir.ts
|
|
11102
|
-
var
|
|
11313
|
+
var import_node_path10 = __toESM(require("path"));
|
|
11103
11314
|
function normalizeRelativeDir(input, appName) {
|
|
11104
11315
|
if (typeof input !== "string") {
|
|
11105
11316
|
throw new Error(`Missing dir for ${appName} in .pmate.yaml`);
|
|
@@ -11112,7 +11323,7 @@ function normalizeRelativeDir(input, appName) {
|
|
|
11112
11323
|
if (unixLike.startsWith("/")) {
|
|
11113
11324
|
throw new Error(`Invalid dir for ${appName} in .pmate.yaml: must be relative`);
|
|
11114
11325
|
}
|
|
11115
|
-
const normalized =
|
|
11326
|
+
const normalized = import_node_path10.default.posix.normalize(unixLike);
|
|
11116
11327
|
if (normalized.startsWith("../") || normalized === "..") {
|
|
11117
11328
|
throw new Error(
|
|
11118
11329
|
`Invalid dir for ${appName} in .pmate.yaml: must stay within repo`
|
|
@@ -11121,8 +11332,8 @@ function normalizeRelativeDir(input, appName) {
|
|
|
11121
11332
|
return normalized;
|
|
11122
11333
|
}
|
|
11123
11334
|
function resolveLocalAppDir(repoRoot, appName, dir) {
|
|
11124
|
-
const
|
|
11125
|
-
return
|
|
11335
|
+
const relative2 = normalizeRelativeDir(dir, appName);
|
|
11336
|
+
return import_node_path10.default.resolve(repoRoot, relative2);
|
|
11126
11337
|
}
|
|
11127
11338
|
function resolveRemoteAppDir(appName, dir) {
|
|
11128
11339
|
return normalizeRelativeDir(dir, appName);
|
|
@@ -11145,8 +11356,8 @@ var DevCommandHandler = class {
|
|
|
11145
11356
|
);
|
|
11146
11357
|
}
|
|
11147
11358
|
const appDir = resolveLocalAppDir(cwd, appName, appConfig.dir);
|
|
11148
|
-
const packageJsonPath =
|
|
11149
|
-
if (!(0,
|
|
11359
|
+
const packageJsonPath = import_node_path11.default.join(appDir, "package.json");
|
|
11360
|
+
if (!(0, import_node_fs7.existsSync)(packageJsonPath)) {
|
|
11150
11361
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
11151
11362
|
}
|
|
11152
11363
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -11160,13 +11371,13 @@ var DevCommandHandler = class {
|
|
|
11160
11371
|
await this.runCommand("pnpm", ["--filter", pkgName, "run", "dev"], cwd);
|
|
11161
11372
|
}
|
|
11162
11373
|
resolveCwd(target) {
|
|
11163
|
-
return target ?
|
|
11374
|
+
return target ? import_node_path11.default.resolve(process.cwd(), target) : process.cwd();
|
|
11164
11375
|
}
|
|
11165
11376
|
loadConfig(cwd) {
|
|
11166
11377
|
return loadAppConfig(cwd);
|
|
11167
11378
|
}
|
|
11168
11379
|
loadPackageJson(packageJsonPath) {
|
|
11169
|
-
const raw = (0,
|
|
11380
|
+
const raw = (0, import_node_fs7.readFileSync)(packageJsonPath, "utf8");
|
|
11170
11381
|
const parsed = JSON.parse(raw);
|
|
11171
11382
|
if (!parsed || typeof parsed !== "object") {
|
|
11172
11383
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -11175,7 +11386,7 @@ var DevCommandHandler = class {
|
|
|
11175
11386
|
}
|
|
11176
11387
|
runCommand(command, args, cwd) {
|
|
11177
11388
|
return new Promise((resolve, reject) => {
|
|
11178
|
-
const child = (0,
|
|
11389
|
+
const child = (0, import_node_child_process4.spawn)(command, args, {
|
|
11179
11390
|
cwd,
|
|
11180
11391
|
stdio: "inherit"
|
|
11181
11392
|
});
|
|
@@ -11194,8 +11405,8 @@ var DevCommandHandler = class {
|
|
|
11194
11405
|
};
|
|
11195
11406
|
|
|
11196
11407
|
// src/commands/OssCommandHandler.ts
|
|
11197
|
-
var
|
|
11198
|
-
var
|
|
11408
|
+
var import_node_fs8 = require("fs");
|
|
11409
|
+
var import_node_path12 = __toESM(require("path"));
|
|
11199
11410
|
var PARROT_STATIC_PUBLIC_BASE_URL = "https://parrot-static.pmate.chat";
|
|
11200
11411
|
var OssCommandHandler = class _OssCommandHandler {
|
|
11201
11412
|
static {
|
|
@@ -11213,7 +11424,7 @@ var OssCommandHandler = class _OssCommandHandler {
|
|
|
11213
11424
|
}
|
|
11214
11425
|
return;
|
|
11215
11426
|
}
|
|
11216
|
-
const resolvedFile =
|
|
11427
|
+
const resolvedFile = import_node_path12.default.resolve(process.cwd(), args.filePath);
|
|
11217
11428
|
this.assertFile(resolvedFile);
|
|
11218
11429
|
const objectKey = this.normalizeObjectKey(args.objectKey);
|
|
11219
11430
|
const bucket2 = this.resolveBucket(args.bucket);
|
|
@@ -11224,10 +11435,10 @@ var OssCommandHandler = class _OssCommandHandler {
|
|
|
11224
11435
|
}
|
|
11225
11436
|
}
|
|
11226
11437
|
assertFile(filePath) {
|
|
11227
|
-
if (!(0,
|
|
11438
|
+
if (!(0, import_node_fs8.existsSync)(filePath)) {
|
|
11228
11439
|
throw new Error(`File not found: ${filePath}`);
|
|
11229
11440
|
}
|
|
11230
|
-
const stat = (0,
|
|
11441
|
+
const stat = (0, import_node_fs8.statSync)(filePath);
|
|
11231
11442
|
if (!stat.isFile()) {
|
|
11232
11443
|
throw new Error(`Not a file: ${filePath}`);
|
|
11233
11444
|
}
|
|
@@ -11249,13 +11460,13 @@ var OssCommandHandler = class _OssCommandHandler {
|
|
|
11249
11460
|
};
|
|
11250
11461
|
function buildOssPublicUrl(bucket2, objectKey) {
|
|
11251
11462
|
if (bucket2 !== "parrot-static") return null;
|
|
11252
|
-
const encodedKey = objectKey.split("/").map((
|
|
11463
|
+
const encodedKey = objectKey.split("/").map((segment2) => encodeURIComponent(segment2)).join("/");
|
|
11253
11464
|
return `${PARROT_STATIC_PUBLIC_BASE_URL}/${encodedKey}`;
|
|
11254
11465
|
}
|
|
11255
11466
|
|
|
11256
11467
|
// src/commands/EnvCommandHandler.ts
|
|
11257
|
-
var
|
|
11258
|
-
var
|
|
11468
|
+
var import_node_path13 = __toESM(require("path"));
|
|
11469
|
+
var import_node_child_process5 = require("child_process");
|
|
11259
11470
|
|
|
11260
11471
|
// src/shell.ts
|
|
11261
11472
|
function quoteForBash(command) {
|
|
@@ -11338,8 +11549,8 @@ var EnvCommandHandler = class {
|
|
|
11338
11549
|
ui.success(`Set ${envKey} in .env.local`, appName);
|
|
11339
11550
|
}
|
|
11340
11551
|
async listEnvKeys(server, repoDir, appDir, verbose) {
|
|
11341
|
-
const envLocalPath =
|
|
11342
|
-
const envPath =
|
|
11552
|
+
const envLocalPath = import_node_path13.default.posix.join(appDir, ".env.local");
|
|
11553
|
+
const envPath = import_node_path13.default.posix.join(appDir, ".env");
|
|
11343
11554
|
if (verbose) {
|
|
11344
11555
|
const repoPath = `$HOME/${repoDir}`;
|
|
11345
11556
|
ui.info("Env list target", {
|
|
@@ -11432,8 +11643,8 @@ var EnvCommandHandler = class {
|
|
|
11432
11643
|
}
|
|
11433
11644
|
}
|
|
11434
11645
|
async appendEnvLine(server, repoDir, appDir, envKey, envLine, verbose) {
|
|
11435
|
-
const envLocalPath =
|
|
11436
|
-
const envPath =
|
|
11646
|
+
const envLocalPath = import_node_path13.default.posix.join(appDir, ".env.local");
|
|
11647
|
+
const envPath = import_node_path13.default.posix.join(appDir, ".env");
|
|
11437
11648
|
if (verbose) {
|
|
11438
11649
|
const repoPath = `$HOME/${repoDir}`;
|
|
11439
11650
|
ui.info("Env add target", {
|
|
@@ -11481,8 +11692,8 @@ var EnvCommandHandler = class {
|
|
|
11481
11692
|
await this.runRemoteCommand(server, command);
|
|
11482
11693
|
}
|
|
11483
11694
|
async deleteEnvKey(server, repoDir, appDir, envKey, verbose) {
|
|
11484
|
-
const envLocalPath =
|
|
11485
|
-
const envPath =
|
|
11695
|
+
const envLocalPath = import_node_path13.default.posix.join(appDir, ".env.local");
|
|
11696
|
+
const envPath = import_node_path13.default.posix.join(appDir, ".env");
|
|
11486
11697
|
if (verbose) {
|
|
11487
11698
|
const repoPath = `$HOME/${repoDir}`;
|
|
11488
11699
|
ui.info("Env delete target", {
|
|
@@ -11552,7 +11763,7 @@ var EnvCommandHandler = class {
|
|
|
11552
11763
|
runRemoteCommand(server, command) {
|
|
11553
11764
|
return new Promise((resolve, reject) => {
|
|
11554
11765
|
const target = `pmate@${server}`;
|
|
11555
|
-
const child = (0,
|
|
11766
|
+
const child = (0, import_node_child_process5.spawn)("ssh", buildSshBashArgs(target, command), {
|
|
11556
11767
|
stdio: "inherit"
|
|
11557
11768
|
});
|
|
11558
11769
|
child.on("error", (error) => {
|
|
@@ -11570,7 +11781,7 @@ var EnvCommandHandler = class {
|
|
|
11570
11781
|
runRemoteCommandCapture(server, command) {
|
|
11571
11782
|
return new Promise((resolve, reject) => {
|
|
11572
11783
|
const target = `pmate@${server}`;
|
|
11573
|
-
const child = (0,
|
|
11784
|
+
const child = (0, import_node_child_process5.spawn)("ssh", buildSshBashArgs(target, command), {
|
|
11574
11785
|
stdio: ["ignore", "pipe", "pipe"]
|
|
11575
11786
|
});
|
|
11576
11787
|
let output = "";
|
|
@@ -11619,7 +11830,7 @@ function formatEnvValue(value) {
|
|
|
11619
11830
|
}
|
|
11620
11831
|
|
|
11621
11832
|
// src/commands/PrCommandHandler.ts
|
|
11622
|
-
var
|
|
11833
|
+
var import_node_child_process6 = require("child_process");
|
|
11623
11834
|
var PrCommandHandler = class {
|
|
11624
11835
|
constructor(cwd = process.cwd()) {
|
|
11625
11836
|
this.cwd = cwd;
|
|
@@ -12089,7 +12300,7 @@ ${lines}`;
|
|
|
12089
12300
|
}
|
|
12090
12301
|
run(command, args, quietError = false, env, cwd) {
|
|
12091
12302
|
return new Promise((resolve, reject) => {
|
|
12092
|
-
const child = (0,
|
|
12303
|
+
const child = (0, import_node_child_process6.spawn)(command, args, {
|
|
12093
12304
|
stdio: quietError ? "ignore" : "inherit",
|
|
12094
12305
|
env: env ?? process.env,
|
|
12095
12306
|
cwd: cwd ?? this.cwd
|
|
@@ -12108,7 +12319,7 @@ ${lines}`;
|
|
|
12108
12319
|
}
|
|
12109
12320
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
12110
12321
|
return new Promise((resolve, reject) => {
|
|
12111
|
-
const child = (0,
|
|
12322
|
+
const child = (0, import_node_child_process6.spawn)(command, args, {
|
|
12112
12323
|
stdio: ["ignore", "pipe", "pipe"],
|
|
12113
12324
|
env: env ?? process.env,
|
|
12114
12325
|
cwd: cwd ?? this.cwd
|
|
@@ -12249,8 +12460,8 @@ var CommitCommandHandler = class {
|
|
|
12249
12460
|
};
|
|
12250
12461
|
|
|
12251
12462
|
// src/commands/SummaryCommandHandler.ts
|
|
12252
|
-
var
|
|
12253
|
-
var
|
|
12463
|
+
var import_node_child_process7 = require("child_process");
|
|
12464
|
+
var import_node_path14 = __toESM(require("path"));
|
|
12254
12465
|
var SummaryCommandHandler = class {
|
|
12255
12466
|
async handle(args) {
|
|
12256
12467
|
const cwd = this.resolveCwd(args.cwd);
|
|
@@ -12358,7 +12569,7 @@ var SummaryCommandHandler = class {
|
|
|
12358
12569
|
}
|
|
12359
12570
|
run(command, args, quietError = false, env, cwd) {
|
|
12360
12571
|
return new Promise((resolve, reject) => {
|
|
12361
|
-
const child = (0,
|
|
12572
|
+
const child = (0, import_node_child_process7.spawn)(command, args, {
|
|
12362
12573
|
stdio: quietError ? "ignore" : "inherit",
|
|
12363
12574
|
env: env ?? process.env,
|
|
12364
12575
|
cwd
|
|
@@ -12377,7 +12588,7 @@ var SummaryCommandHandler = class {
|
|
|
12377
12588
|
}
|
|
12378
12589
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
12379
12590
|
return new Promise((resolve, reject) => {
|
|
12380
|
-
const child = (0,
|
|
12591
|
+
const child = (0, import_node_child_process7.spawn)(command, args, {
|
|
12381
12592
|
stdio: ["ignore", "pipe", "pipe"],
|
|
12382
12593
|
env: env ?? process.env,
|
|
12383
12594
|
cwd
|
|
@@ -12435,7 +12646,7 @@ var SummaryCommandHandler = class {
|
|
|
12435
12646
|
return this.runCapture("gh", args, allowFailure, await this.getGhEnv(cwd), cwd);
|
|
12436
12647
|
}
|
|
12437
12648
|
resolveCwd(value) {
|
|
12438
|
-
return value ?
|
|
12649
|
+
return value ? import_node_path14.default.resolve(process.cwd(), value) : process.cwd();
|
|
12439
12650
|
}
|
|
12440
12651
|
};
|
|
12441
12652
|
function truncate2(value, limit) {
|
|
@@ -12447,10 +12658,10 @@ function truncate2(value, limit) {
|
|
|
12447
12658
|
}
|
|
12448
12659
|
|
|
12449
12660
|
// src/commands/LinearCommandHandler.ts
|
|
12450
|
-
var
|
|
12451
|
-
var
|
|
12452
|
-
var
|
|
12453
|
-
var
|
|
12661
|
+
var import_node_child_process8 = require("child_process");
|
|
12662
|
+
var import_node_fs9 = require("fs");
|
|
12663
|
+
var import_node_os6 = __toESM(require("os"));
|
|
12664
|
+
var import_node_path15 = __toESM(require("path"));
|
|
12454
12665
|
var import_promises3 = require("readline/promises");
|
|
12455
12666
|
var import_openai = __toESM(require("openai"));
|
|
12456
12667
|
var import_sdk = require("@linear/sdk");
|
|
@@ -13334,15 +13545,15 @@ var LinearCommandHandler = class {
|
|
|
13334
13545
|
}
|
|
13335
13546
|
}
|
|
13336
13547
|
getLinearSelectionPath() {
|
|
13337
|
-
return
|
|
13548
|
+
return import_node_path15.default.join(import_node_os6.default.homedir(), ".pmate", "linear-selection.json");
|
|
13338
13549
|
}
|
|
13339
13550
|
readCachedLinearSelection(cwd) {
|
|
13340
13551
|
const selectionPath = this.getLinearSelectionPath();
|
|
13341
|
-
if (!(0,
|
|
13552
|
+
if (!(0, import_node_fs9.existsSync)(selectionPath)) {
|
|
13342
13553
|
return void 0;
|
|
13343
13554
|
}
|
|
13344
13555
|
try {
|
|
13345
|
-
const raw = (0,
|
|
13556
|
+
const raw = (0, import_node_fs9.readFileSync)(selectionPath, "utf8").trim();
|
|
13346
13557
|
if (!raw) return void 0;
|
|
13347
13558
|
const parsed = JSON.parse(raw);
|
|
13348
13559
|
const value = parsed[cwd];
|
|
@@ -13353,12 +13564,12 @@ var LinearCommandHandler = class {
|
|
|
13353
13564
|
}
|
|
13354
13565
|
writeCachedLinearSelection(cwd, title) {
|
|
13355
13566
|
const selectionPath = this.getLinearSelectionPath();
|
|
13356
|
-
const dir =
|
|
13357
|
-
(0,
|
|
13567
|
+
const dir = import_node_path15.default.dirname(selectionPath);
|
|
13568
|
+
(0, import_node_fs9.mkdirSync)(dir, { recursive: true });
|
|
13358
13569
|
let data = {};
|
|
13359
|
-
if ((0,
|
|
13570
|
+
if ((0, import_node_fs9.existsSync)(selectionPath)) {
|
|
13360
13571
|
try {
|
|
13361
|
-
const raw = (0,
|
|
13572
|
+
const raw = (0, import_node_fs9.readFileSync)(selectionPath, "utf8").trim();
|
|
13362
13573
|
if (raw) {
|
|
13363
13574
|
data = JSON.parse(raw);
|
|
13364
13575
|
}
|
|
@@ -13367,7 +13578,7 @@ var LinearCommandHandler = class {
|
|
|
13367
13578
|
}
|
|
13368
13579
|
}
|
|
13369
13580
|
data[cwd] = title;
|
|
13370
|
-
(0,
|
|
13581
|
+
(0, import_node_fs9.writeFileSync)(selectionPath, `${JSON.stringify(data, null, 2)}
|
|
13371
13582
|
`, "utf8");
|
|
13372
13583
|
}
|
|
13373
13584
|
async lookupIssue(client, issueRef) {
|
|
@@ -13544,14 +13755,14 @@ var LinearCommandHandler = class {
|
|
|
13544
13755
|
if (process.platform !== "darwin") {
|
|
13545
13756
|
throw new Error("Screenshot capture only supports macOS.");
|
|
13546
13757
|
}
|
|
13547
|
-
const dir = await
|
|
13548
|
-
const filePath =
|
|
13758
|
+
const dir = await import_node_fs9.promises.mkdtemp(import_node_path15.default.join(import_node_os6.default.tmpdir(), "pmate-screenshot-"));
|
|
13759
|
+
const filePath = import_node_path15.default.join(dir, `screenshot-${index}.png`);
|
|
13549
13760
|
try {
|
|
13550
13761
|
const code = await this.run("screencapture", ["-i", "-x", filePath], true);
|
|
13551
13762
|
if (code !== 0) {
|
|
13552
13763
|
throw new Error("Screenshot capture canceled or failed.");
|
|
13553
13764
|
}
|
|
13554
|
-
const buffer = await
|
|
13765
|
+
const buffer = await import_node_fs9.promises.readFile(filePath);
|
|
13555
13766
|
if (buffer.length === 0) {
|
|
13556
13767
|
throw new Error("Screenshot capture produced an empty file.");
|
|
13557
13768
|
}
|
|
@@ -13563,7 +13774,7 @@ var LinearCommandHandler = class {
|
|
|
13563
13774
|
return { buffer, mime, filename: `screenshot-${index}.${extension}` };
|
|
13564
13775
|
} finally {
|
|
13565
13776
|
try {
|
|
13566
|
-
await
|
|
13777
|
+
await import_node_fs9.promises.rm(dir, { recursive: true, force: true });
|
|
13567
13778
|
} catch {
|
|
13568
13779
|
}
|
|
13569
13780
|
}
|
|
@@ -13707,17 +13918,17 @@ var LinearCommandHandler = class {
|
|
|
13707
13918
|
return compact.length > limit ? `${compact.slice(0, limit)}...` : compact;
|
|
13708
13919
|
}
|
|
13709
13920
|
async convertToPng(buffer, ext) {
|
|
13710
|
-
const dir = await
|
|
13711
|
-
const inputPath =
|
|
13712
|
-
const outputPath =
|
|
13921
|
+
const dir = await import_node_fs9.promises.mkdtemp(import_node_path15.default.join(import_node_os6.default.tmpdir(), "pmate-"));
|
|
13922
|
+
const inputPath = import_node_path15.default.join(dir, `clipboard.${ext}`);
|
|
13923
|
+
const outputPath = import_node_path15.default.join(dir, "clipboard.png");
|
|
13713
13924
|
try {
|
|
13714
|
-
await
|
|
13925
|
+
await import_node_fs9.promises.writeFile(inputPath, buffer);
|
|
13715
13926
|
const stderr = await this.runCapture(
|
|
13716
13927
|
"sips",
|
|
13717
13928
|
["-s", "format", "png", inputPath, "--out", outputPath],
|
|
13718
13929
|
true
|
|
13719
13930
|
);
|
|
13720
|
-
const out = await
|
|
13931
|
+
const out = await import_node_fs9.promises.readFile(outputPath);
|
|
13721
13932
|
if (this.detectImageMime(out) !== "image/png") {
|
|
13722
13933
|
throw new Error(
|
|
13723
13934
|
stderr?.trim() ? `Failed to convert clipboard ${ext} to PNG: ${stderr.trim()}` : `Failed to convert clipboard ${ext} to PNG.`
|
|
@@ -13726,14 +13937,14 @@ var LinearCommandHandler = class {
|
|
|
13726
13937
|
return out;
|
|
13727
13938
|
} finally {
|
|
13728
13939
|
try {
|
|
13729
|
-
await
|
|
13940
|
+
await import_node_fs9.promises.rm(dir, { recursive: true, force: true });
|
|
13730
13941
|
} catch {
|
|
13731
13942
|
}
|
|
13732
13943
|
}
|
|
13733
13944
|
}
|
|
13734
13945
|
captureClipboard(preferred) {
|
|
13735
13946
|
return new Promise((resolve, reject) => {
|
|
13736
|
-
const child = (0,
|
|
13947
|
+
const child = (0, import_node_child_process8.spawn)("pbpaste", ["-Prefer", preferred], {
|
|
13737
13948
|
stdio: ["ignore", "pipe", "pipe"]
|
|
13738
13949
|
});
|
|
13739
13950
|
const chunks = [];
|
|
@@ -13943,7 +14154,7 @@ var LinearCommandHandler = class {
|
|
|
13943
14154
|
}
|
|
13944
14155
|
run(command, args, quietError = false, env, cwd) {
|
|
13945
14156
|
return new Promise((resolve, reject) => {
|
|
13946
|
-
const child = (0,
|
|
14157
|
+
const child = (0, import_node_child_process8.spawn)(command, args, {
|
|
13947
14158
|
stdio: quietError ? "ignore" : "inherit",
|
|
13948
14159
|
env: env ?? process.env,
|
|
13949
14160
|
cwd
|
|
@@ -13962,7 +14173,7 @@ var LinearCommandHandler = class {
|
|
|
13962
14173
|
}
|
|
13963
14174
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
13964
14175
|
return new Promise((resolve, reject) => {
|
|
13965
|
-
const child = (0,
|
|
14176
|
+
const child = (0, import_node_child_process8.spawn)(command, args, {
|
|
13966
14177
|
stdio: ["ignore", "pipe", "pipe"],
|
|
13967
14178
|
env: env ?? process.env,
|
|
13968
14179
|
cwd
|
|
@@ -14020,7 +14231,7 @@ var LinearCommandHandler = class {
|
|
|
14020
14231
|
return this.runCapture("gh", args, allowFailure, await this.getGhEnv(cwd), cwd);
|
|
14021
14232
|
}
|
|
14022
14233
|
resolveCwd(value) {
|
|
14023
|
-
return value ?
|
|
14234
|
+
return value ? import_node_path15.default.resolve(process.cwd(), value) : process.cwd();
|
|
14024
14235
|
}
|
|
14025
14236
|
createOpenAiClient() {
|
|
14026
14237
|
const config = loadPmateConfig();
|
|
@@ -14072,8 +14283,8 @@ function sleep2(ms) {
|
|
|
14072
14283
|
}
|
|
14073
14284
|
|
|
14074
14285
|
// src/commands/NotionCommandHandler.ts
|
|
14075
|
-
var
|
|
14076
|
-
var
|
|
14286
|
+
var import_node_fs10 = require("fs");
|
|
14287
|
+
var import_node_path16 = __toESM(require("path"));
|
|
14077
14288
|
|
|
14078
14289
|
// src/services/NotionService.ts
|
|
14079
14290
|
var NotionService = class {
|
|
@@ -14312,9 +14523,9 @@ ${indent}\`\`\``;
|
|
|
14312
14523
|
static richTextToPlain(richText) {
|
|
14313
14524
|
return richText.map((item) => item.plain_text ?? item.text?.content ?? "").join("").trim();
|
|
14314
14525
|
}
|
|
14315
|
-
static async requestJson(
|
|
14526
|
+
static async requestJson(path37, init) {
|
|
14316
14527
|
const token = this.getToken();
|
|
14317
|
-
const response = await fetch(`${this.baseUrl}${
|
|
14528
|
+
const response = await fetch(`${this.baseUrl}${path37}`, {
|
|
14318
14529
|
method: init.method,
|
|
14319
14530
|
headers: {
|
|
14320
14531
|
Authorization: `Bearer ${token}`,
|
|
@@ -14412,16 +14623,16 @@ var NotionCommandHandler = class {
|
|
|
14412
14623
|
if (!args.filePath) {
|
|
14413
14624
|
return "";
|
|
14414
14625
|
}
|
|
14415
|
-
const resolved =
|
|
14416
|
-
return (0,
|
|
14626
|
+
const resolved = import_node_path16.default.resolve(process.cwd(), args.filePath);
|
|
14627
|
+
return (0, import_node_fs10.readFileSync)(resolved, "utf8");
|
|
14417
14628
|
}
|
|
14418
14629
|
};
|
|
14419
14630
|
|
|
14420
14631
|
// src/commands/QrcodeCommandHandler.ts
|
|
14421
|
-
var
|
|
14422
|
-
var
|
|
14423
|
-
var
|
|
14424
|
-
var
|
|
14632
|
+
var import_node_child_process9 = require("child_process");
|
|
14633
|
+
var import_node_fs11 = require("fs");
|
|
14634
|
+
var import_node_os7 = __toESM(require("os"));
|
|
14635
|
+
var import_node_path17 = __toESM(require("path"));
|
|
14425
14636
|
var import_promises4 = require("readline/promises");
|
|
14426
14637
|
var import_jsqr = __toESM(require("jsqr"));
|
|
14427
14638
|
var import_pngjs = require("pngjs");
|
|
@@ -14447,7 +14658,7 @@ var QrcodeCommandHandler = class {
|
|
|
14447
14658
|
ui.success("QR code value:", value);
|
|
14448
14659
|
} finally {
|
|
14449
14660
|
try {
|
|
14450
|
-
await
|
|
14661
|
+
await import_node_fs11.promises.rm(dir, { recursive: true, force: true });
|
|
14451
14662
|
} catch {
|
|
14452
14663
|
}
|
|
14453
14664
|
}
|
|
@@ -14463,13 +14674,13 @@ var QrcodeCommandHandler = class {
|
|
|
14463
14674
|
} finally {
|
|
14464
14675
|
rl.close();
|
|
14465
14676
|
}
|
|
14466
|
-
const dir = await
|
|
14467
|
-
const filePath =
|
|
14677
|
+
const dir = await import_node_fs11.promises.mkdtemp(import_node_path17.default.join(import_node_os7.default.tmpdir(), "pmate-qrcode-"));
|
|
14678
|
+
const filePath = import_node_path17.default.join(dir, "qrcode.png");
|
|
14468
14679
|
const code = await this.run("screencapture", ["-i", "-x", filePath], true);
|
|
14469
14680
|
if (code !== 0) {
|
|
14470
14681
|
throw new Error("Screenshot capture canceled or failed.");
|
|
14471
14682
|
}
|
|
14472
|
-
const buffer = await
|
|
14683
|
+
const buffer = await import_node_fs11.promises.readFile(filePath);
|
|
14473
14684
|
if (buffer.length === 0) {
|
|
14474
14685
|
throw new Error("Screenshot capture produced an empty file.");
|
|
14475
14686
|
}
|
|
@@ -14485,7 +14696,7 @@ var QrcodeCommandHandler = class {
|
|
|
14485
14696
|
async decodeQr(filePath) {
|
|
14486
14697
|
let buffer;
|
|
14487
14698
|
try {
|
|
14488
|
-
buffer = await
|
|
14699
|
+
buffer = await import_node_fs11.promises.readFile(filePath);
|
|
14489
14700
|
} catch {
|
|
14490
14701
|
return null;
|
|
14491
14702
|
}
|
|
@@ -14526,7 +14737,7 @@ var QrcodeCommandHandler = class {
|
|
|
14526
14737
|
}
|
|
14527
14738
|
run(command, args, quietError = false, env, cwd) {
|
|
14528
14739
|
return new Promise((resolve, reject) => {
|
|
14529
|
-
const child = (0,
|
|
14740
|
+
const child = (0, import_node_child_process9.spawn)(command, args, {
|
|
14530
14741
|
stdio: quietError ? "ignore" : "inherit",
|
|
14531
14742
|
env: env ?? process.env,
|
|
14532
14743
|
cwd
|
|
@@ -14743,8 +14954,8 @@ function clampNumber(value, min, max, fallback) {
|
|
|
14743
14954
|
}
|
|
14744
14955
|
|
|
14745
14956
|
// src/commands/QuizCommandHandler.ts
|
|
14746
|
-
var
|
|
14747
|
-
var
|
|
14957
|
+
var import_node_fs12 = require("fs");
|
|
14958
|
+
var import_node_path18 = __toESM(require("path"));
|
|
14748
14959
|
init_sessionStore();
|
|
14749
14960
|
|
|
14750
14961
|
// src/services/QuizService.ts
|
|
@@ -15289,8 +15500,8 @@ var QuizCommandHandler = class {
|
|
|
15289
15500
|
return;
|
|
15290
15501
|
}
|
|
15291
15502
|
if (args.action === "update-meta") {
|
|
15292
|
-
const resolvedFilePath =
|
|
15293
|
-
const metadata = JSON.parse((0,
|
|
15503
|
+
const resolvedFilePath = import_node_path18.default.resolve(process.cwd(), args.filePath);
|
|
15504
|
+
const metadata = JSON.parse((0, import_node_fs12.readFileSync)(resolvedFilePath, "utf8"));
|
|
15294
15505
|
const result = await updateQuizPaperMetadata({
|
|
15295
15506
|
apiBaseUrl,
|
|
15296
15507
|
linkBaseUrl,
|
|
@@ -15302,8 +15513,8 @@ var QuizCommandHandler = class {
|
|
|
15302
15513
|
return;
|
|
15303
15514
|
}
|
|
15304
15515
|
if (args.action === "append-step") {
|
|
15305
|
-
const resolvedFilePath =
|
|
15306
|
-
const step = JSON.parse((0,
|
|
15516
|
+
const resolvedFilePath = import_node_path18.default.resolve(process.cwd(), args.filePath);
|
|
15517
|
+
const step = JSON.parse((0, import_node_fs12.readFileSync)(resolvedFilePath, "utf8"));
|
|
15307
15518
|
const result = await appendQuizPaperStep({
|
|
15308
15519
|
apiBaseUrl,
|
|
15309
15520
|
linkBaseUrl,
|
|
@@ -15316,8 +15527,8 @@ var QuizCommandHandler = class {
|
|
|
15316
15527
|
return;
|
|
15317
15528
|
}
|
|
15318
15529
|
if (args.action === "update-step") {
|
|
15319
|
-
const resolvedFilePath =
|
|
15320
|
-
const step = JSON.parse((0,
|
|
15530
|
+
const resolvedFilePath = import_node_path18.default.resolve(process.cwd(), args.filePath);
|
|
15531
|
+
const step = JSON.parse((0, import_node_fs12.readFileSync)(resolvedFilePath, "utf8"));
|
|
15321
15532
|
step.stepId = args.stepId;
|
|
15322
15533
|
const result = await updateQuizPaperStep({
|
|
15323
15534
|
apiBaseUrl,
|
|
@@ -15380,8 +15591,8 @@ var QuizCommandHandler = class {
|
|
|
15380
15591
|
if (targetIndex < 0) {
|
|
15381
15592
|
throw new Error(`\u672A\u627E\u5230 stepId=${args.stepId}\uFF0C\u65E0\u6CD5\u66F4\u65B0\u8BE5\u9898\u76EE\u3002`);
|
|
15382
15593
|
}
|
|
15383
|
-
const resolvedFilePath =
|
|
15384
|
-
const nextStep = JSON.parse((0,
|
|
15594
|
+
const resolvedFilePath = import_node_path18.default.resolve(process.cwd(), args.filePath);
|
|
15595
|
+
const nextStep = JSON.parse((0, import_node_fs12.readFileSync)(resolvedFilePath, "utf8"));
|
|
15385
15596
|
nextStep.stepId = args.stepId;
|
|
15386
15597
|
const nextSteps = [...basePaper.steps];
|
|
15387
15598
|
nextSteps[targetIndex] = nextStep;
|
|
@@ -15431,9 +15642,9 @@ var QuizCommandHandler = class {
|
|
|
15431
15642
|
};
|
|
15432
15643
|
|
|
15433
15644
|
// src/commands/CollectCommandHandler.ts
|
|
15434
|
-
var
|
|
15435
|
-
var
|
|
15436
|
-
var
|
|
15645
|
+
var import_node_fs14 = require("fs");
|
|
15646
|
+
var import_node_os9 = __toESM(require("os"));
|
|
15647
|
+
var import_node_path20 = __toESM(require("path"));
|
|
15437
15648
|
var import_playwright = require("playwright");
|
|
15438
15649
|
|
|
15439
15650
|
// src/im1BotClient.ts
|
|
@@ -15517,13 +15728,13 @@ var Im1BotClient = class {
|
|
|
15517
15728
|
|
|
15518
15729
|
// src/collectStore.ts
|
|
15519
15730
|
var import_node_crypto4 = require("crypto");
|
|
15520
|
-
var
|
|
15521
|
-
var
|
|
15522
|
-
var
|
|
15731
|
+
var import_node_fs13 = require("fs");
|
|
15732
|
+
var import_node_os8 = __toESM(require("os"));
|
|
15733
|
+
var import_node_path19 = __toESM(require("path"));
|
|
15523
15734
|
function resolveCollectTarget(input) {
|
|
15524
15735
|
const endpoint = input.endpoint ?? (input.source === "cc" ? "http://localhost:9223" : "http://localhost:9222");
|
|
15525
15736
|
const sourceKey = input.source ?? `endpoint-${(0, import_node_crypto4.createHash)("sha1").update(endpoint).digest("hex").slice(0, 8)}`;
|
|
15526
|
-
const rootDir =
|
|
15737
|
+
const rootDir = import_node_path19.default.join(import_node_os8.default.homedir(), ".pmate", "collect", sourceKey);
|
|
15527
15738
|
return { sourceKey, endpoint, rootDir };
|
|
15528
15739
|
}
|
|
15529
15740
|
function toThreadKey(name) {
|
|
@@ -15535,7 +15746,7 @@ function toThreadKey(name) {
|
|
|
15535
15746
|
async function readStoredThread(rootDir, threadKey) {
|
|
15536
15747
|
const filePath = getThreadMetaFilePath(rootDir, threadKey);
|
|
15537
15748
|
try {
|
|
15538
|
-
const raw = await
|
|
15749
|
+
const raw = await import_node_fs13.promises.readFile(filePath, "utf8");
|
|
15539
15750
|
const parsed = JSON.parse(raw);
|
|
15540
15751
|
if ("messages" in parsed && Array.isArray(parsed.messages)) {
|
|
15541
15752
|
return parsed;
|
|
@@ -15553,15 +15764,15 @@ async function writeStoredThread(rootDir, thread) {
|
|
|
15553
15764
|
const metaPath = getThreadMetaFilePath(rootDir, thread.threadKey);
|
|
15554
15765
|
const messagePath = getThreadMessagesFilePath(rootDir, thread.threadKey);
|
|
15555
15766
|
const { messages: messages2, ...meta } = thread;
|
|
15556
|
-
await
|
|
15557
|
-
await
|
|
15767
|
+
await import_node_fs13.promises.mkdir(import_node_path19.default.dirname(metaPath), { recursive: true });
|
|
15768
|
+
await import_node_fs13.promises.writeFile(metaPath, JSON.stringify(meta, null, 2) + "\n", "utf8");
|
|
15558
15769
|
const body = messages2.map((message) => JSON.stringify(message)).join("\n");
|
|
15559
|
-
await
|
|
15770
|
+
await import_node_fs13.promises.writeFile(messagePath, `${body}${body ? "\n" : ""}`, "utf8");
|
|
15560
15771
|
}
|
|
15561
15772
|
async function writeStoredIndex(rootDir, index) {
|
|
15562
|
-
await
|
|
15563
|
-
const filePath =
|
|
15564
|
-
await
|
|
15773
|
+
await import_node_fs13.promises.mkdir(rootDir, { recursive: true });
|
|
15774
|
+
const filePath = import_node_path19.default.join(rootDir, "index.json");
|
|
15775
|
+
await import_node_fs13.promises.writeFile(filePath, JSON.stringify(index, null, 2) + "\n", "utf8");
|
|
15565
15776
|
}
|
|
15566
15777
|
function diffMessages(existing, incoming) {
|
|
15567
15778
|
const seenMessageIds = new Set(
|
|
@@ -15635,7 +15846,7 @@ function joinNormalized(values) {
|
|
|
15635
15846
|
async function readStoredMessages(rootDir, threadKey) {
|
|
15636
15847
|
const filePath = getThreadMessagesFilePath(rootDir, threadKey);
|
|
15637
15848
|
try {
|
|
15638
|
-
const raw = await
|
|
15849
|
+
const raw = await import_node_fs13.promises.readFile(filePath, "utf8");
|
|
15639
15850
|
return raw.split("\n").map((line) => line.trim()).filter(Boolean).map((line) => normalizeStoredMessage(JSON.parse(line)));
|
|
15640
15851
|
} catch {
|
|
15641
15852
|
return [];
|
|
@@ -15644,20 +15855,20 @@ async function readStoredMessages(rootDir, threadKey) {
|
|
|
15644
15855
|
async function readLegacyStoredThread(rootDir, threadKey) {
|
|
15645
15856
|
const filePath = getLegacyThreadFilePath(rootDir, threadKey);
|
|
15646
15857
|
try {
|
|
15647
|
-
const raw = await
|
|
15858
|
+
const raw = await import_node_fs13.promises.readFile(filePath, "utf8");
|
|
15648
15859
|
return JSON.parse(raw);
|
|
15649
15860
|
} catch {
|
|
15650
15861
|
return null;
|
|
15651
15862
|
}
|
|
15652
15863
|
}
|
|
15653
15864
|
function getThreadMetaFilePath(rootDir, threadKey) {
|
|
15654
|
-
return
|
|
15865
|
+
return import_node_path19.default.join(rootDir, "threads", `${threadKey}.json`);
|
|
15655
15866
|
}
|
|
15656
15867
|
function getThreadMessagesFilePath(rootDir, threadKey) {
|
|
15657
|
-
return
|
|
15868
|
+
return import_node_path19.default.join(rootDir, "threads", `${threadKey}.jsonl`);
|
|
15658
15869
|
}
|
|
15659
15870
|
function getLegacyThreadFilePath(rootDir, threadKey) {
|
|
15660
|
-
return
|
|
15871
|
+
return import_node_path19.default.join(rootDir, "threads", `${threadKey}.json`);
|
|
15661
15872
|
}
|
|
15662
15873
|
function normalizeStoredMessage(message) {
|
|
15663
15874
|
return {
|
|
@@ -15673,9 +15884,9 @@ function normalizeStoredMessage(message) {
|
|
|
15673
15884
|
|
|
15674
15885
|
// src/commands/CollectCommandHandler.ts
|
|
15675
15886
|
async function readOutgoingAttachment(filePath) {
|
|
15676
|
-
const resolved =
|
|
15677
|
-
const data = await
|
|
15678
|
-
const extension =
|
|
15887
|
+
const resolved = import_node_path20.default.resolve(filePath);
|
|
15888
|
+
const data = await import_node_fs14.promises.readFile(resolved);
|
|
15889
|
+
const extension = import_node_path20.default.extname(resolved).toLowerCase();
|
|
15679
15890
|
const contentTypes = {
|
|
15680
15891
|
".png": "image/png",
|
|
15681
15892
|
".jpg": "image/jpeg",
|
|
@@ -15690,7 +15901,7 @@ async function readOutgoingAttachment(filePath) {
|
|
|
15690
15901
|
};
|
|
15691
15902
|
return {
|
|
15692
15903
|
base64: data.toString("base64"),
|
|
15693
|
-
fileName:
|
|
15904
|
+
fileName: import_node_path20.default.basename(resolved),
|
|
15694
15905
|
contentType: contentTypes[extension] ?? "application/octet-stream",
|
|
15695
15906
|
size: data.byteLength
|
|
15696
15907
|
};
|
|
@@ -15960,7 +16171,7 @@ var CollectCommandHandler = class {
|
|
|
15960
16171
|
}
|
|
15961
16172
|
async writeSyncReport(rootDir, target, results, failures, syncedAt) {
|
|
15962
16173
|
const syncId = toSyncId(syncedAt);
|
|
15963
|
-
const reportPath =
|
|
16174
|
+
const reportPath = import_node_path20.default.join(rootDir, "syncs", `${syncId}.json`);
|
|
15964
16175
|
const threadReports = results.map((result) => ({
|
|
15965
16176
|
threadKey: result.thread.threadKey,
|
|
15966
16177
|
threadName: result.thread.threadName,
|
|
@@ -15969,8 +16180,8 @@ var CollectCommandHandler = class {
|
|
|
15969
16180
|
addedMessages: result.diff.added,
|
|
15970
16181
|
upgradedMessages: result.diff.upgraded
|
|
15971
16182
|
})).filter((thread) => thread.addedCount > 0 || thread.upgradedCount > 0);
|
|
15972
|
-
await
|
|
15973
|
-
await
|
|
16183
|
+
await import_node_fs14.promises.mkdir(import_node_path20.default.dirname(reportPath), { recursive: true });
|
|
16184
|
+
await import_node_fs14.promises.writeFile(
|
|
15974
16185
|
reportPath,
|
|
15975
16186
|
JSON.stringify(
|
|
15976
16187
|
{
|
|
@@ -16148,19 +16359,19 @@ async function archiveMessageImage(rootDir, attachmentRoot, threadKey, imagePath
|
|
|
16148
16359
|
if (!imagePath || isExternalImageRef(imagePath)) {
|
|
16149
16360
|
return imagePath;
|
|
16150
16361
|
}
|
|
16151
|
-
const normalized =
|
|
16362
|
+
const normalized = import_node_path20.default.posix.normalize(imagePath.replace(/\\/g, "/"));
|
|
16152
16363
|
if (normalized.startsWith("attachments/")) {
|
|
16153
|
-
return
|
|
16364
|
+
return import_node_path20.default.join(rootDir, ...normalized.split("/"));
|
|
16154
16365
|
}
|
|
16155
|
-
if (normalized.startsWith("../") ||
|
|
16366
|
+
if (normalized.startsWith("../") || import_node_path20.default.posix.isAbsolute(normalized)) {
|
|
16156
16367
|
return imagePath;
|
|
16157
16368
|
}
|
|
16158
|
-
const sourcePath =
|
|
16159
|
-
const destinationRelativePath =
|
|
16160
|
-
const destinationPath =
|
|
16369
|
+
const sourcePath = import_node_path20.default.join(attachmentRoot, ...normalized.split("/"));
|
|
16370
|
+
const destinationRelativePath = import_node_path20.default.posix.join("attachments", threadKey, normalized);
|
|
16371
|
+
const destinationPath = import_node_path20.default.join(rootDir, ...destinationRelativePath.split("/"));
|
|
16161
16372
|
try {
|
|
16162
|
-
await
|
|
16163
|
-
await
|
|
16373
|
+
await import_node_fs14.promises.mkdir(import_node_path20.default.dirname(destinationPath), { recursive: true });
|
|
16374
|
+
await import_node_fs14.promises.copyFile(sourcePath, destinationPath);
|
|
16164
16375
|
return destinationPath;
|
|
16165
16376
|
} catch {
|
|
16166
16377
|
return imagePath;
|
|
@@ -16170,7 +16381,7 @@ function resolveLocalAttachmentRoot(sourceKey) {
|
|
|
16170
16381
|
if (sourceKey !== "cc" && sourceKey !== "yelling") {
|
|
16171
16382
|
return null;
|
|
16172
16383
|
}
|
|
16173
|
-
return
|
|
16384
|
+
return import_node_path20.default.join(import_node_os9.default.homedir(), "Library", "Application Support", sourceKey, "attachments.noindex");
|
|
16174
16385
|
}
|
|
16175
16386
|
function isExternalImageRef(imagePath) {
|
|
16176
16387
|
return /^[a-z][a-z0-9+.-]*:/i.test(imagePath);
|
|
@@ -16794,7 +17005,7 @@ function pad2(value) {
|
|
|
16794
17005
|
}
|
|
16795
17006
|
|
|
16796
17007
|
// src/commands/ChatRoomCommandHandler.ts
|
|
16797
|
-
var
|
|
17008
|
+
var import_node_fs15 = require("fs");
|
|
16798
17009
|
var ChatRoomCommandHandler = class {
|
|
16799
17010
|
async handle(args) {
|
|
16800
17011
|
const sdk = await loadChatSdk();
|
|
@@ -16844,8 +17055,8 @@ var ChatRoomCommandHandler = class {
|
|
|
16844
17055
|
const a = await this.connect(sdk, args.botA, args.app, args.hubUrl, args.authBaseUrl);
|
|
16845
17056
|
const b = await this.connect(sdk, args.botB, args.app, args.hubUrl, args.authBaseUrl);
|
|
16846
17057
|
try {
|
|
16847
|
-
const botA = sdk.parsePmateBotKeyJson((0,
|
|
16848
|
-
const botB = sdk.parsePmateBotKeyJson((0,
|
|
17058
|
+
const botA = sdk.parsePmateBotKeyJson((0, import_node_fs15.readFileSync)(args.botA, "utf8"));
|
|
17059
|
+
const botB = sdk.parsePmateBotKeyJson((0, import_node_fs15.readFileSync)(args.botB, "utf8"));
|
|
16849
17060
|
await a.requestFriend({ to: botB.name, message: "smoke friend request" });
|
|
16850
17061
|
await b.acceptFriend({ to: botA.name, message: "smoke friend accept" });
|
|
16851
17062
|
await a.sendDm({ to: botB.name, text: "smoke dm from a" });
|
|
@@ -16864,7 +17075,7 @@ var ChatRoomCommandHandler = class {
|
|
|
16864
17075
|
if (!botPath) {
|
|
16865
17076
|
throw new Error("Missing required option: --bot");
|
|
16866
17077
|
}
|
|
16867
|
-
const botKey = sdk.parsePmateBotKeyJson((0,
|
|
17078
|
+
const botKey = sdk.parsePmateBotKeyJson((0, import_node_fs15.readFileSync)(botPath, "utf8"));
|
|
16868
17079
|
const client = sdk.createChatClient({ appId, botKey, hubUrl, authBaseUrl });
|
|
16869
17080
|
await client.connect();
|
|
16870
17081
|
return client;
|
|
@@ -16876,8 +17087,8 @@ async function loadChatSdk() {
|
|
|
16876
17087
|
}
|
|
16877
17088
|
|
|
16878
17089
|
// src/commands/RegistryResourceCommandHandler.ts
|
|
16879
|
-
var
|
|
16880
|
-
var
|
|
17090
|
+
var import_node_fs16 = require("fs");
|
|
17091
|
+
var import_node_path21 = __toESM(require("path"));
|
|
16881
17092
|
init_sessionStore();
|
|
16882
17093
|
var RegistryResourceCommandHandler = class {
|
|
16883
17094
|
async handle(args) {
|
|
@@ -16912,9 +17123,9 @@ var RegistryResourceCommandHandler = class {
|
|
|
16912
17123
|
}
|
|
16913
17124
|
};
|
|
16914
17125
|
function readJson(filePath) {
|
|
16915
|
-
const absolutePath =
|
|
16916
|
-
if (!(0,
|
|
16917
|
-
return JSON.parse((0,
|
|
17126
|
+
const absolutePath = import_node_path21.default.resolve(process.cwd(), filePath);
|
|
17127
|
+
if (!(0, import_node_fs16.existsSync)(absolutePath)) throw new Error(`JSON file not found: ${absolutePath}`);
|
|
17128
|
+
return JSON.parse((0, import_node_fs16.readFileSync)(absolutePath, "utf8"));
|
|
16918
17129
|
}
|
|
16919
17130
|
async function request(baseUrl2, token, method, pathname, body) {
|
|
16920
17131
|
const response = await fetch(`${baseUrl2}${pathname}`, {
|
|
@@ -16928,8 +17139,8 @@ async function request(baseUrl2, token, method, pathname, body) {
|
|
|
16928
17139
|
}
|
|
16929
17140
|
|
|
16930
17141
|
// src/commands/CallCommandHandler.ts
|
|
16931
|
-
var
|
|
16932
|
-
var
|
|
17142
|
+
var import_node_fs17 = require("fs");
|
|
17143
|
+
var import_node_path22 = __toESM(require("path"));
|
|
16933
17144
|
init_dist2();
|
|
16934
17145
|
init_sessionStore();
|
|
16935
17146
|
var CallCommandHandler = class {
|
|
@@ -16952,8 +17163,8 @@ var CallCommandHandler = class {
|
|
|
16952
17163
|
}
|
|
16953
17164
|
};
|
|
16954
17165
|
async function callWithBinaryFile(hub, functionId, filePath, contentType, timeoutMs) {
|
|
16955
|
-
const absolutePath =
|
|
16956
|
-
if (!(0,
|
|
17166
|
+
const absolutePath = import_node_path22.default.resolve(process.cwd(), filePath);
|
|
17167
|
+
if (!(0, import_node_fs17.existsSync)(absolutePath)) throw new Error(`Binary file not found: ${absolutePath}`);
|
|
16957
17168
|
const mimeType = contentType || inferContentType(absolutePath);
|
|
16958
17169
|
const result = hub.stream({
|
|
16959
17170
|
functionId,
|
|
@@ -16963,7 +17174,7 @@ async function callWithBinaryFile(hub, functionId, filePath, contentType, timeou
|
|
|
16963
17174
|
return result.finish();
|
|
16964
17175
|
}
|
|
16965
17176
|
async function* streamFile(filePath, contentType) {
|
|
16966
|
-
for await (const chunk of (0,
|
|
17177
|
+
for await (const chunk of (0, import_node_fs17.createReadStream)(filePath)) {
|
|
16967
17178
|
yield new Blob([chunk], { type: contentType });
|
|
16968
17179
|
}
|
|
16969
17180
|
}
|
|
@@ -16978,12 +17189,12 @@ function inferContentType(filePath) {
|
|
|
16978
17189
|
".wav": "audio/wav",
|
|
16979
17190
|
".webm": "audio/webm"
|
|
16980
17191
|
};
|
|
16981
|
-
return contentTypes[
|
|
17192
|
+
return contentTypes[import_node_path22.default.extname(filePath).toLowerCase()] || "application/octet-stream";
|
|
16982
17193
|
}
|
|
16983
17194
|
function readJson2(filePath) {
|
|
16984
|
-
const absolutePath =
|
|
16985
|
-
if (!(0,
|
|
16986
|
-
const decoded = JSON.parse((0,
|
|
17195
|
+
const absolutePath = import_node_path22.default.resolve(process.cwd(), filePath);
|
|
17196
|
+
if (!(0, import_node_fs17.existsSync)(absolutePath)) throw new Error(`JSON file not found: ${absolutePath}`);
|
|
17197
|
+
const decoded = JSON.parse((0, import_node_fs17.readFileSync)(absolutePath, "utf8"));
|
|
16987
17198
|
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) {
|
|
16988
17199
|
throw new Error("Call input file must contain a JSON object");
|
|
16989
17200
|
}
|
|
@@ -17019,8 +17230,8 @@ function descriptorPathSegments(descriptor) {
|
|
|
17019
17230
|
return ["chains", normalized.chain, "namespaces", normalized.ns, normalized.kind, normalized.name];
|
|
17020
17231
|
}
|
|
17021
17232
|
function buildPathUrl(baseUrl2, pathSegments, query) {
|
|
17022
|
-
const
|
|
17023
|
-
const url = new URL(
|
|
17233
|
+
const path37 = `/${pathSegments.map((segment2) => encodeURIComponent(segment2)).join("/")}`;
|
|
17234
|
+
const url = new URL(path37, baseUrl2);
|
|
17024
17235
|
if (query) {
|
|
17025
17236
|
for (const [key, value] of Object.entries(query)) {
|
|
17026
17237
|
url.searchParams.set(key, String(value));
|
|
@@ -17370,8 +17581,8 @@ var NsCommandHandler = class {
|
|
|
17370
17581
|
};
|
|
17371
17582
|
|
|
17372
17583
|
// src/commands/StoreCommandHandler.ts
|
|
17373
|
-
var
|
|
17374
|
-
var
|
|
17584
|
+
var import_node_fs18 = require("fs");
|
|
17585
|
+
var import_node_path23 = __toESM(require("path"));
|
|
17375
17586
|
init_sessionStore();
|
|
17376
17587
|
var StoreCommandHandler = class {
|
|
17377
17588
|
async handle(args) {
|
|
@@ -17525,11 +17736,11 @@ var StoreCommandHandler = class {
|
|
|
17525
17736
|
return payload.data ?? [];
|
|
17526
17737
|
}
|
|
17527
17738
|
readJsonFile(filePath) {
|
|
17528
|
-
const absolutePath =
|
|
17529
|
-
if (!(0,
|
|
17739
|
+
const absolutePath = import_node_path23.default.resolve(process.cwd(), filePath);
|
|
17740
|
+
if (!(0, import_node_fs18.existsSync)(absolutePath)) {
|
|
17530
17741
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
17531
17742
|
}
|
|
17532
|
-
const raw = (0,
|
|
17743
|
+
const raw = (0, import_node_fs18.readFileSync)(absolutePath, "utf8");
|
|
17533
17744
|
try {
|
|
17534
17745
|
return JSON.parse(raw);
|
|
17535
17746
|
} catch (error) {
|
|
@@ -17581,14 +17792,14 @@ var StoreCommandHandler = class {
|
|
|
17581
17792
|
};
|
|
17582
17793
|
|
|
17583
17794
|
// src/commands/AppCommandHandler.ts
|
|
17584
|
-
var
|
|
17585
|
-
var
|
|
17795
|
+
var import_node_fs20 = require("fs");
|
|
17796
|
+
var import_node_path25 = __toESM(require("path"));
|
|
17586
17797
|
init_sessionStore();
|
|
17587
17798
|
|
|
17588
17799
|
// src/appIcon.ts
|
|
17589
|
-
var
|
|
17590
|
-
var
|
|
17591
|
-
var
|
|
17800
|
+
var import_node_fs19 = require("fs");
|
|
17801
|
+
var import_node_os10 = __toESM(require("os"));
|
|
17802
|
+
var import_node_path24 = __toESM(require("path"));
|
|
17592
17803
|
var import_sharp = __toESM(require("sharp"));
|
|
17593
17804
|
init_namespacedRef();
|
|
17594
17805
|
var ANDROID_ICON_SPECS = [
|
|
@@ -17693,13 +17904,13 @@ function createAppIconExportPlans(input) {
|
|
|
17693
17904
|
if (!input.outDir) {
|
|
17694
17905
|
throw new Error("App icon preset export requires --out-dir.");
|
|
17695
17906
|
}
|
|
17696
|
-
const outDir =
|
|
17697
|
-
(0,
|
|
17907
|
+
const outDir = import_node_path24.default.resolve(input.cwd, input.outDir);
|
|
17908
|
+
(0, import_node_fs19.mkdirSync)(outDir, { recursive: true });
|
|
17698
17909
|
return specs.map((spec) => ({
|
|
17699
17910
|
width: spec.width,
|
|
17700
17911
|
height: spec.height,
|
|
17701
17912
|
format: "png",
|
|
17702
|
-
outputPath:
|
|
17913
|
+
outputPath: import_node_path24.default.join(
|
|
17703
17914
|
outDir,
|
|
17704
17915
|
`${namespace}-${objectId}-${spec.name}-${spec.width}x${spec.height}.png`
|
|
17705
17916
|
)
|
|
@@ -17712,8 +17923,8 @@ function createAppIconExportPlans(input) {
|
|
|
17712
17923
|
if (!input.output) {
|
|
17713
17924
|
throw new Error("Single-size app icon export requires --output.");
|
|
17714
17925
|
}
|
|
17715
|
-
const resolvedOutput =
|
|
17716
|
-
(0,
|
|
17926
|
+
const resolvedOutput = import_node_path24.default.resolve(input.cwd, input.output);
|
|
17927
|
+
(0, import_node_fs19.mkdirSync)(import_node_path24.default.dirname(resolvedOutput), { recursive: true });
|
|
17717
17928
|
return [
|
|
17718
17929
|
{
|
|
17719
17930
|
width: input.width,
|
|
@@ -17727,7 +17938,7 @@ async function exportAppIcon(icon, plans) {
|
|
|
17727
17938
|
const svg = await resolveAppIconSvg(icon);
|
|
17728
17939
|
for (const plan of plans) {
|
|
17729
17940
|
const bytes = await renderAppIcon(svg, plan.width, plan.height, plan.format);
|
|
17730
|
-
(0,
|
|
17941
|
+
(0, import_node_fs19.writeFileSync)(plan.outputPath, bytes);
|
|
17731
17942
|
}
|
|
17732
17943
|
}
|
|
17733
17944
|
async function renderAppIconVariant(input) {
|
|
@@ -17735,9 +17946,9 @@ async function renderAppIconVariant(input) {
|
|
|
17735
17946
|
const bytes = await renderAppIcon(svg, input.width, input.height, input.format);
|
|
17736
17947
|
let outputPath;
|
|
17737
17948
|
if (input.output) {
|
|
17738
|
-
outputPath =
|
|
17739
|
-
(0,
|
|
17740
|
-
(0,
|
|
17949
|
+
outputPath = import_node_path24.default.resolve(input.cwd, input.output);
|
|
17950
|
+
(0, import_node_fs19.mkdirSync)(import_node_path24.default.dirname(outputPath), { recursive: true });
|
|
17951
|
+
(0, import_node_fs19.writeFileSync)(outputPath, bytes);
|
|
17741
17952
|
}
|
|
17742
17953
|
if (input.name) {
|
|
17743
17954
|
return {
|
|
@@ -17758,7 +17969,7 @@ async function renderAppIconVariant(input) {
|
|
|
17758
17969
|
};
|
|
17759
17970
|
}
|
|
17760
17971
|
async function loadAppIconVariantFile(input) {
|
|
17761
|
-
const absolutePath =
|
|
17972
|
+
const absolutePath = import_node_path24.default.resolve(input.cwd, input.filePath);
|
|
17762
17973
|
const format = inferVariantFormatFromPath(absolutePath);
|
|
17763
17974
|
return {
|
|
17764
17975
|
value: input.name ? await uploadAppIconVariantAsset({
|
|
@@ -17767,7 +17978,7 @@ async function loadAppIconVariantFile(input) {
|
|
|
17767
17978
|
name: input.name,
|
|
17768
17979
|
format,
|
|
17769
17980
|
sourcePath: absolutePath
|
|
17770
|
-
}) : createImageDataUrl((0,
|
|
17981
|
+
}) : createImageDataUrl((0, import_node_fs19.readFileSync)(absolutePath), format),
|
|
17771
17982
|
format,
|
|
17772
17983
|
absolutePath
|
|
17773
17984
|
};
|
|
@@ -17826,7 +18037,7 @@ function shouldAutoGenerateDefaultVariant(icon) {
|
|
|
17826
18037
|
return looksLikeSvgMarkup(icon) || looksLikeSvgUrl(icon);
|
|
17827
18038
|
}
|
|
17828
18039
|
function inferVariantFormatFromPath(filePath) {
|
|
17829
|
-
const ext =
|
|
18040
|
+
const ext = import_node_path24.default.extname(filePath).toLowerCase();
|
|
17830
18041
|
switch (ext) {
|
|
17831
18042
|
case ".png":
|
|
17832
18043
|
return "png";
|
|
@@ -17897,13 +18108,13 @@ async function uploadAppIconVariantAsset(input) {
|
|
|
17897
18108
|
await AliyunService.uploadFile(sourcePath, DEFAULT_APP_ICON_VARIANT_BUCKET, objectKey);
|
|
17898
18109
|
} finally {
|
|
17899
18110
|
if (shouldCleanup) {
|
|
17900
|
-
(0,
|
|
18111
|
+
(0, import_node_fs19.rmSync)(import_node_path24.default.dirname(sourcePath), { recursive: true, force: true });
|
|
17901
18112
|
}
|
|
17902
18113
|
}
|
|
17903
18114
|
return `${DEFAULT_APP_ICON_VARIANT_PUBLIC_BASE_URL}/${objectKey}`;
|
|
17904
18115
|
}
|
|
17905
18116
|
function buildAppIconVariantObjectKey(input) {
|
|
17906
|
-
return
|
|
18117
|
+
return import_node_path24.default.posix.join(
|
|
17907
18118
|
"apps",
|
|
17908
18119
|
`${resolveAppIconAssetStem(input.icon, input.appRef)}-${input.name}.${extensionForIconFormat(input.format)}`
|
|
17909
18120
|
);
|
|
@@ -17912,8 +18123,8 @@ function resolveAppIconAssetStem(icon, appRef2) {
|
|
|
17912
18123
|
if (icon) {
|
|
17913
18124
|
try {
|
|
17914
18125
|
const url = new URL(icon);
|
|
17915
|
-
const ext =
|
|
17916
|
-
const basename =
|
|
18126
|
+
const ext = import_node_path24.default.posix.extname(url.pathname);
|
|
18127
|
+
const basename = import_node_path24.default.posix.basename(url.pathname, ext);
|
|
17917
18128
|
const normalized = sanitizeAppIconAssetStem(basename);
|
|
17918
18129
|
if (normalized) {
|
|
17919
18130
|
return normalized;
|
|
@@ -17942,9 +18153,9 @@ function writeTempAppIconVariantFile(objectKey, format, bytes) {
|
|
|
17942
18153
|
if (!bytes) {
|
|
17943
18154
|
throw new Error("App icon variant upload requires bytes or a source file.");
|
|
17944
18155
|
}
|
|
17945
|
-
const tempDir = (0,
|
|
17946
|
-
const tempPath =
|
|
17947
|
-
(0,
|
|
18156
|
+
const tempDir = (0, import_node_fs19.mkdtempSync)(import_node_path24.default.join(import_node_os10.default.tmpdir(), "pmate-app-icon-"));
|
|
18157
|
+
const tempPath = import_node_path24.default.join(tempDir, import_node_path24.default.basename(objectKey) || `variant.${extensionForIconFormat(format)}`);
|
|
18158
|
+
(0, import_node_fs19.writeFileSync)(tempPath, bytes);
|
|
17948
18159
|
return tempPath;
|
|
17949
18160
|
}
|
|
17950
18161
|
|
|
@@ -18153,10 +18364,10 @@ var AppCommandHandler = class {
|
|
|
18153
18364
|
}
|
|
18154
18365
|
readJsonFile(filePath) {
|
|
18155
18366
|
const absolutePath = this.resolveFilePath(filePath);
|
|
18156
|
-
if (!(0,
|
|
18367
|
+
if (!(0, import_node_fs20.existsSync)(absolutePath)) {
|
|
18157
18368
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
18158
18369
|
}
|
|
18159
|
-
const raw = (0,
|
|
18370
|
+
const raw = (0, import_node_fs20.readFileSync)(absolutePath, "utf8");
|
|
18160
18371
|
try {
|
|
18161
18372
|
return JSON.parse(raw);
|
|
18162
18373
|
} catch (error) {
|
|
@@ -18166,10 +18377,10 @@ var AppCommandHandler = class {
|
|
|
18166
18377
|
}
|
|
18167
18378
|
async preparePayload(filePath, appRef2) {
|
|
18168
18379
|
const absolutePath = this.resolveFilePath(filePath);
|
|
18169
|
-
return prepareAppPayload(this.readJsonFile(filePath),
|
|
18380
|
+
return prepareAppPayload(this.readJsonFile(filePath), import_node_path25.default.dirname(absolutePath), { appRef: appRef2 });
|
|
18170
18381
|
}
|
|
18171
18382
|
resolveFilePath(filePath) {
|
|
18172
|
-
return
|
|
18383
|
+
return import_node_path25.default.resolve(process.cwd(), filePath);
|
|
18173
18384
|
}
|
|
18174
18385
|
async request(baseUrl2, token, method, pathname, body) {
|
|
18175
18386
|
const response = await fetch(`${baseUrl2}${pathname}`, {
|
|
@@ -18289,28 +18500,28 @@ function readNamespaceFromPayload(payload) {
|
|
|
18289
18500
|
}
|
|
18290
18501
|
|
|
18291
18502
|
// src/commands/ServiceCommandHandler.ts
|
|
18292
|
-
var
|
|
18503
|
+
var import_node_fs28 = require("fs");
|
|
18293
18504
|
var import_promises5 = require("fs/promises");
|
|
18294
|
-
var
|
|
18295
|
-
var
|
|
18505
|
+
var import_node_path33 = __toESM(require("path"));
|
|
18506
|
+
var import_node_child_process16 = require("child_process");
|
|
18296
18507
|
var import_promises6 = require("readline/promises");
|
|
18297
18508
|
|
|
18298
18509
|
// src/services/NativeServiceDeploy.ts
|
|
18299
|
-
var
|
|
18300
|
-
var
|
|
18510
|
+
var import_node_path31 = __toESM(require("path"));
|
|
18511
|
+
var import_node_fs26 = require("fs");
|
|
18301
18512
|
|
|
18302
18513
|
// src/electronBuild.ts
|
|
18303
|
-
var
|
|
18304
|
-
var
|
|
18305
|
-
var
|
|
18306
|
-
var
|
|
18514
|
+
var import_node_child_process10 = require("child_process");
|
|
18515
|
+
var import_node_fs22 = require("fs");
|
|
18516
|
+
var import_node_os11 = require("os");
|
|
18517
|
+
var import_node_path27 = __toESM(require("path"));
|
|
18307
18518
|
var import_sharp2 = __toESM(require("sharp"));
|
|
18308
18519
|
|
|
18309
18520
|
// src/desktopRelease.ts
|
|
18310
18521
|
init_sessionStore();
|
|
18311
18522
|
var import_node_crypto5 = require("crypto");
|
|
18312
|
-
var
|
|
18313
|
-
var
|
|
18523
|
+
var import_node_fs21 = require("fs");
|
|
18524
|
+
var import_node_path26 = __toESM(require("path"));
|
|
18314
18525
|
async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
18315
18526
|
const segments = [...app.split(":"), version, platform, arch];
|
|
18316
18527
|
if (app.split(":").length !== 2 || segments.some((s) => !/^[\w.-]+$/.test(s) || s === "." || s === "..")) throw new Error("Invalid desktop release identity");
|
|
@@ -18319,8 +18530,8 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
|
18319
18530
|
const bucket2 = "parrot-static";
|
|
18320
18531
|
const prefix = `desktop/${segments.join("/")}/`;
|
|
18321
18532
|
const url = (key) => `https://parrot-static.pmate.chat/${key.split("/").map(encodeURIComponent).join("/")}`;
|
|
18322
|
-
const artifacts = (0,
|
|
18323
|
-
const bytes = (0,
|
|
18533
|
+
const artifacts = (0, import_node_fs21.readdirSync)(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && (platform === "mac" ? /(?:\.(dmg|zip|blockmap)$|^latest-mac\.yml$)/i : /(?:\.(exe|zip|blockmap)$|^latest\.yml$)/i).test(entry.name)).sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
18534
|
+
const bytes = (0, import_node_fs21.readFileSync)(import_node_path26.default.join(directory, entry.name));
|
|
18324
18535
|
const objectKey = prefix + entry.name;
|
|
18325
18536
|
return { name: entry.name, objectKey, downloadUrl: url(objectKey), sha256: (0, import_node_crypto5.createHash)("sha256").update(bytes).digest("hex"), size: bytes.length };
|
|
18326
18537
|
});
|
|
@@ -18329,7 +18540,7 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
|
18329
18540
|
const existing = await AliyunService.readJsonObject(bucket2, manifestKey);
|
|
18330
18541
|
const release = { schemaVersion: 1, app, version, platform, arch, artifacts };
|
|
18331
18542
|
if (existing !== null && JSON.stringify(existing) !== JSON.stringify(release)) throw new Error("Desktop release already exists with different artifacts; bump the app version");
|
|
18332
|
-
for (const artifact of artifacts) await AliyunService.uploadFile(
|
|
18543
|
+
for (const artifact of artifacts) await AliyunService.uploadFile(import_node_path26.default.join(directory, artifact.name), bucket2, artifact.objectKey);
|
|
18333
18544
|
await AliyunService.uploadJsonObject(bucket2, manifestKey, release);
|
|
18334
18545
|
const base = (process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
18335
18546
|
const response = await fetch(`${base}/versions/${encodeURIComponent(app)}`, {
|
|
@@ -18348,7 +18559,7 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
|
18348
18559
|
var ELECTRON_VERSION = "44.5.1";
|
|
18349
18560
|
var BUILDER_VERSION = "26.15.3";
|
|
18350
18561
|
function readDesktopConfig(file, appId) {
|
|
18351
|
-
const c = JSON.parse((0,
|
|
18562
|
+
const c = JSON.parse((0, import_node_fs22.readFileSync)(file, "utf8"));
|
|
18352
18563
|
if (c.schemaVersion !== 2 || c.app !== appId) throw new Error("Desktop config schemaVersion/app mismatch");
|
|
18353
18564
|
for (const key of ["productName", "bundleId", "version", "icon"]) {
|
|
18354
18565
|
if (typeof c[key] !== "string" || !c[key].trim()) throw new Error(`Missing desktop ${key}`);
|
|
@@ -18374,10 +18585,10 @@ function readDesktopConfig(file, appId) {
|
|
|
18374
18585
|
return c;
|
|
18375
18586
|
}
|
|
18376
18587
|
function repositoryRoot(cwd) {
|
|
18377
|
-
let dir =
|
|
18588
|
+
let dir = import_node_path27.default.resolve(cwd);
|
|
18378
18589
|
while (true) {
|
|
18379
|
-
if ((0,
|
|
18380
|
-
const parent =
|
|
18590
|
+
if ((0, import_node_fs22.existsSync)(import_node_path27.default.join(dir, ".git"))) return dir;
|
|
18591
|
+
const parent = import_node_path27.default.dirname(dir);
|
|
18381
18592
|
if (parent === dir) return void 0;
|
|
18382
18593
|
dir = parent;
|
|
18383
18594
|
}
|
|
@@ -18385,24 +18596,24 @@ function repositoryRoot(cwd) {
|
|
|
18385
18596
|
function resolveDesktopPaths(args, cwd = process.cwd()) {
|
|
18386
18597
|
const root = repositoryRoot(cwd);
|
|
18387
18598
|
const name = args.id.split(":")[1];
|
|
18388
|
-
let file = args.config ?
|
|
18599
|
+
let file = args.config ? import_node_path27.default.resolve(cwd, args.config) : void 0;
|
|
18389
18600
|
if (!file) {
|
|
18390
|
-
let dir =
|
|
18601
|
+
let dir = import_node_path27.default.resolve(cwd);
|
|
18391
18602
|
while (true) {
|
|
18392
|
-
const candidates = [.../* @__PURE__ */ new Set([
|
|
18393
|
-
const matches = candidates.filter((candidate) => (0,
|
|
18603
|
+
const candidates = [.../* @__PURE__ */ new Set([import_node_path27.default.join(dir, "desktop.config.json"), import_node_path27.default.join(dir, "apps", name, "desktop.config.json")])];
|
|
18604
|
+
const matches = candidates.filter((candidate) => (0, import_node_fs22.existsSync)(candidate) && JSON.parse((0, import_node_fs22.readFileSync)(candidate, "utf8")).app === args.id);
|
|
18394
18605
|
if (matches.length > 1) throw new Error("Ambiguous desktop config; specify --config");
|
|
18395
18606
|
if (matches.length === 1) {
|
|
18396
18607
|
file = matches[0];
|
|
18397
18608
|
break;
|
|
18398
18609
|
}
|
|
18399
|
-
const parent =
|
|
18610
|
+
const parent = import_node_path27.default.dirname(dir);
|
|
18400
18611
|
if (dir === root || parent === dir) break;
|
|
18401
18612
|
dir = parent;
|
|
18402
18613
|
}
|
|
18403
18614
|
}
|
|
18404
18615
|
if (!file) throw new Error(`No desktop config for ${args.id}; specify --config`);
|
|
18405
|
-
return { file, output: args.outDir ?
|
|
18616
|
+
return { file, output: args.outDir ? import_node_path27.default.resolve(cwd, args.outDir) : import_node_path27.default.join(root ?? import_node_path27.default.dirname(file), "release", name) };
|
|
18406
18617
|
}
|
|
18407
18618
|
function desktopBuildEnvironment(config, env = process.env) {
|
|
18408
18619
|
return { ...env, ...env.APPLE_KEYCHAIN_PROFILE ? {} : config.notaryProfile ? { APPLE_KEYCHAIN_PROFILE: config.notaryProfile } : {} };
|
|
@@ -18415,7 +18626,7 @@ function requireNotaryCredentials(env) {
|
|
|
18415
18626
|
} else if (env.APPLE_KEYCHAIN_PROFILE) return;
|
|
18416
18627
|
throw new Error("macOS signed builds require complete Apple notarization credentials or APPLE_KEYCHAIN_PROFILE");
|
|
18417
18628
|
}
|
|
18418
|
-
function requireSigningIdentity(env, inspect = () => (0,
|
|
18629
|
+
function requireSigningIdentity(env, inspect = () => (0, import_node_child_process10.execFileSync)("security", ["find-identity", "-v", "-p", "codesigning"], { encoding: "utf8" })) {
|
|
18419
18630
|
if (env.CSC_LINK) return;
|
|
18420
18631
|
if (!inspect().includes("Developer ID Application:")) throw new Error("No Developer ID Application signing identity available");
|
|
18421
18632
|
}
|
|
@@ -18424,20 +18635,20 @@ async function publishVerifiedDesktop(args, artifacts, config, verify = verifyMa
|
|
|
18424
18635
|
if (args.local || args.dir || !args.signed) return void 0;
|
|
18425
18636
|
return upload(artifacts, config.app, config.version, args.platform, args.arch);
|
|
18426
18637
|
}
|
|
18427
|
-
async function verifyMacRelease(artifacts,
|
|
18428
|
-
const apps = (0,
|
|
18638
|
+
async function verifyMacRelease(artifacts, run2 = runBuildCommand, inspect = (app) => (0, import_node_child_process10.spawnSync)("codesign", ["-dv", "--verbose=4", app], { encoding: "utf8" })) {
|
|
18639
|
+
const apps = (0, import_node_fs22.readdirSync)(artifacts, { recursive: true, withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.endsWith(".app")).map((entry) => import_node_path27.default.join(entry.parentPath, entry.name)).filter((file) => !file.slice(0, -4).includes(".app/"));
|
|
18429
18640
|
if (!apps.length) throw new Error("No packaged macOS app found; refusing publication");
|
|
18430
18641
|
for (const app of apps) {
|
|
18431
|
-
await
|
|
18642
|
+
await run2(["codesign", "--verify", "--deep", "--strict", app], artifacts);
|
|
18432
18643
|
const signature = inspect(app);
|
|
18433
18644
|
if (signature.status !== 0 || !signature.stderr.includes("Authority=Developer ID Application:")) throw new Error("Packaged app lacks Developer ID Application signature");
|
|
18434
|
-
await
|
|
18435
|
-
await
|
|
18645
|
+
await run2(["xcrun", "stapler", "validate", app], artifacts);
|
|
18646
|
+
await run2(["spctl", "--assess", "--type", "execute", "--verbose=2", app], artifacts);
|
|
18436
18647
|
}
|
|
18437
18648
|
}
|
|
18438
18649
|
async function runBuildCommand(command, cwd, env = process.env) {
|
|
18439
18650
|
await new Promise((resolve, reject) => {
|
|
18440
|
-
const child = (0,
|
|
18651
|
+
const child = (0, import_node_child_process10.spawn)(command[0], command.slice(1), { cwd, env, stdio: "inherit", shell: false });
|
|
18441
18652
|
child.once("error", reject);
|
|
18442
18653
|
child.once("exit", (code, signal) => code === 0 ? resolve() : reject(new Error(`${command[0]} failed (${signal ?? code})`)));
|
|
18443
18654
|
});
|
|
@@ -18446,19 +18657,19 @@ async function renderTrayIcons(source, output) {
|
|
|
18446
18657
|
const idle = await (0, import_sharp2.default)(source).resize(36, 36, { fit: "contain" }).png().toBuffer();
|
|
18447
18658
|
const gap = Buffer.from('<svg width="36" height="36" xmlns="http://www.w3.org/2000/svg"><circle cx="30" cy="6" r="7" fill="#000"/></svg>');
|
|
18448
18659
|
const dot = Buffer.from('<svg width="36" height="36" xmlns="http://www.w3.org/2000/svg"><circle cx="30" cy="6" r="5" fill="#000"/></svg>');
|
|
18449
|
-
await (0, import_sharp2.default)(idle).toFile(
|
|
18450
|
-
await (0, import_sharp2.default)(idle).composite([{ input: gap, blend: "dest-out" }, { input: dot }]).png().toFile(
|
|
18660
|
+
await (0, import_sharp2.default)(idle).toFile(import_node_path27.default.join(output, "trayTemplate.png"));
|
|
18661
|
+
await (0, import_sharp2.default)(idle).composite([{ input: gap, blend: "dest-out" }, { input: dot }]).png().toFile(import_node_path27.default.join(output, "trayUnreadTemplate.png"));
|
|
18451
18662
|
}
|
|
18452
18663
|
async function buildDesktop(args) {
|
|
18453
18664
|
const { file, output } = resolveDesktopPaths(args);
|
|
18454
18665
|
const c = readDesktopConfig(file, args.id);
|
|
18455
|
-
const base =
|
|
18456
|
-
const icon =
|
|
18666
|
+
const base = import_node_path27.default.dirname(file);
|
|
18667
|
+
const icon = import_node_path27.default.resolve(base, c.icon);
|
|
18457
18668
|
const tray = c.tray && (!c.tray.platforms || c.tray.platforms.includes(args.platform)) ? c.tray : void 0;
|
|
18458
|
-
const trayIcon = tray ?
|
|
18669
|
+
const trayIcon = tray ? import_node_path27.default.resolve(base, tray.icon) : void 0;
|
|
18459
18670
|
const env = desktopBuildEnvironment(c);
|
|
18460
|
-
if (!(0,
|
|
18461
|
-
if (trayIcon && (!(0,
|
|
18671
|
+
if (!(0, import_node_fs22.existsSync)(icon) || !(0, import_node_fs22.statSync)(icon).isFile()) throw new Error(`Desktop icon not found: ${icon}`);
|
|
18672
|
+
if (trayIcon && (!(0, import_node_fs22.existsSync)(trayIcon) || !(0, import_node_fs22.statSync)(trayIcon).isFile())) throw new Error(`Desktop tray icon not found: ${trayIcon}`);
|
|
18462
18673
|
if (!["mac", "win"].includes(args.platform) || !["arm64", "x64"].includes(args.arch)) throw new Error("Supported target: mac|win --arch arm64|x64");
|
|
18463
18674
|
if (args.platform === "mac" && process.platform !== "darwin") throw new Error("macOS desktop packaging requires a macOS build host");
|
|
18464
18675
|
const plan = { config: file, notaryProfile: env.APPLE_KEYCHAIN_PROFILE, app: c.app, productName: c.productName, version: c.version, target: "electron", platform: args.platform, arch: args.arch, contentSource: "remote", origin: c.origin, tray: !!tray, output, electron: ELECTRON_VERSION, builder: BUILDER_VERSION, signed: args.signed };
|
|
@@ -18468,30 +18679,30 @@ async function buildDesktop(args) {
|
|
|
18468
18679
|
requireNotaryCredentials(env);
|
|
18469
18680
|
requireSigningIdentity(env);
|
|
18470
18681
|
}
|
|
18471
|
-
(0,
|
|
18472
|
-
const staging = (0,
|
|
18473
|
-
const appDir =
|
|
18474
|
-
(0,
|
|
18475
|
-
const templateDir =
|
|
18476
|
-
(0,
|
|
18682
|
+
(0, import_node_fs22.mkdirSync)(output, { recursive: true });
|
|
18683
|
+
const staging = (0, import_node_fs22.mkdtempSync)(import_node_path27.default.join(output, ".desktop-build-"));
|
|
18684
|
+
const appDir = import_node_path27.default.join(staging, "app");
|
|
18685
|
+
(0, import_node_fs22.mkdirSync)(appDir);
|
|
18686
|
+
const templateDir = import_node_path27.default.join(__dirname, "templates", "electron");
|
|
18687
|
+
(0, import_node_fs22.cpSync)(templateDir, appDir, { recursive: true });
|
|
18477
18688
|
if (trayIcon) await renderTrayIcons(trayIcon, appDir);
|
|
18478
|
-
(0,
|
|
18479
|
-
(0,
|
|
18689
|
+
(0, import_node_fs22.writeFileSync)(import_node_path27.default.join(appDir, "desktop-config.json"), JSON.stringify({ app: c.app, productName: c.productName, origin: c.origin, authOrigins: c.authOrigins, externalOrigins: c.externalOrigins ?? [], bundleId: c.bundleId, ...tray ? { tray: { closeToTray: tray.closeToTray !== false } } : {} }));
|
|
18690
|
+
(0, import_node_fs22.writeFileSync)(import_node_path27.default.join(appDir, "package.json"), JSON.stringify({ name: c.bundleId.replace(/\./g, "-"), version: c.version, description: `${c.productName} desktop application`, author: "PMate", main: "main.cjs", dependencies: { "@pmate/chat-sdk": "0.11.7", "electron-updater": "6.8.3" } }));
|
|
18480
18691
|
await runBuildCommand(["npm", "install", "--omit=dev", "--no-audit", "--no-fund"], appDir);
|
|
18481
|
-
const cache =
|
|
18482
|
-
(0,
|
|
18692
|
+
const cache = import_node_path27.default.join((0, import_node_os11.homedir)(), ".cache", "pmate", "electron", `${ELECTRON_VERSION}-${BUILDER_VERSION}`);
|
|
18693
|
+
(0, import_node_fs22.mkdirSync)(cache, { recursive: true });
|
|
18483
18694
|
const toolPackage = { name: "pmate-desktop-toolchain", private: true, dependencies: { electron: ELECTRON_VERSION, "electron-builder": BUILDER_VERSION } };
|
|
18484
|
-
if (!(0,
|
|
18485
|
-
(0,
|
|
18486
|
-
await runBuildCommand(["npm", (0,
|
|
18695
|
+
if (!(0, import_node_fs22.existsSync)(import_node_path27.default.join(cache, "node_modules", "electron", "dist", "Electron.app")) || !(0, import_node_fs22.existsSync)(import_node_path27.default.join(cache, "node_modules", "electron-builder", "cli.js"))) {
|
|
18696
|
+
(0, import_node_fs22.writeFileSync)(import_node_path27.default.join(cache, "package.json"), JSON.stringify(toolPackage));
|
|
18697
|
+
await runBuildCommand(["npm", (0, import_node_fs22.existsSync)(import_node_path27.default.join(cache, "package-lock.json")) ? "ci" : "install", "--no-audit", "--no-fund"], cache);
|
|
18487
18698
|
}
|
|
18488
|
-
const entitlements =
|
|
18489
|
-
(0,
|
|
18699
|
+
const entitlements = import_node_path27.default.join(staging, "entitlements.mac.plist");
|
|
18700
|
+
(0, import_node_fs22.writeFileSync)(entitlements, `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.security.cs.allow-jit</key><true/><key>com.apple.security.cs.allow-unsigned-executable-memory</key><true/><key>com.apple.security.cs.disable-library-validation</key><true/><key>com.apple.security.device.audio-input</key><true/></dict></plist>`);
|
|
18490
18701
|
const builderConfig = {
|
|
18491
18702
|
appId: c.bundleId,
|
|
18492
18703
|
productName: c.productName,
|
|
18493
18704
|
electronVersion: ELECTRON_VERSION,
|
|
18494
|
-
directories: { app: appDir, output:
|
|
18705
|
+
directories: { app: appDir, output: import_node_path27.default.join(staging, "artifacts") },
|
|
18495
18706
|
files: ["**/*"],
|
|
18496
18707
|
asar: true,
|
|
18497
18708
|
artifactName: "${productName}-${version}-${arch}.${ext}",
|
|
@@ -18500,36 +18711,36 @@ async function buildDesktop(args) {
|
|
|
18500
18711
|
win: { icon, target: args.dir ? ["dir"] : ["nsis", "zip"], ...args.signed ? {} : { signExecutable: false } },
|
|
18501
18712
|
forceCodeSigning: args.signed
|
|
18502
18713
|
};
|
|
18503
|
-
const configPath =
|
|
18504
|
-
(0,
|
|
18505
|
-
await runBuildCommand([process.execPath,
|
|
18506
|
-
const result = { ...plan, signature: args.signed ? args.platform === "mac" ? "Developer ID signed; notarization and Gatekeeper required before publication" : "configured-signing-required; verify Authenticode before distribution" : args.platform === "mac" ? "ad-hoc; local development" : "unsigned; local development", artifacts:
|
|
18507
|
-
(0,
|
|
18714
|
+
const configPath = import_node_path27.default.join(staging, "builder.json");
|
|
18715
|
+
(0, import_node_fs22.writeFileSync)(configPath, JSON.stringify(builderConfig));
|
|
18716
|
+
await runBuildCommand([process.execPath, import_node_path27.default.join(cache, "node_modules", "electron-builder", "cli.js"), "--config", configPath, args.platform === "mac" ? "--mac" : "--win", `--${args.arch}`, "--publish", "never"], appDir, { ...env, ...args.signed ? {} : { CSC_IDENTITY_AUTO_DISCOVERY: "false" } });
|
|
18717
|
+
const result = { ...plan, signature: args.signed ? args.platform === "mac" ? "Developer ID signed; notarization and Gatekeeper required before publication" : "configured-signing-required; verify Authenticode before distribution" : args.platform === "mac" ? "ad-hoc; local development" : "unsigned; local development", artifacts: import_node_path27.default.join(staging, "artifacts") };
|
|
18718
|
+
(0, import_node_fs22.writeFileSync)(import_node_path27.default.join(staging, "build-report.json"), JSON.stringify(result, null, 2));
|
|
18508
18719
|
const publication = await publishVerifiedDesktop(args, result.artifacts, c);
|
|
18509
|
-
(0,
|
|
18510
|
-
console.log(JSON.stringify({ phase: "complete", report:
|
|
18720
|
+
(0, import_node_fs22.writeFileSync)(import_node_path27.default.join(staging, "build-report.json"), JSON.stringify({ ...result, publication }, null, 2));
|
|
18721
|
+
console.log(JSON.stringify({ phase: "complete", report: import_node_path27.default.join(staging, "build-report.json"), artifacts: result.artifacts, signature: result.signature, publication }, null, 2));
|
|
18511
18722
|
}
|
|
18512
18723
|
|
|
18513
18724
|
// src/services/CurrentRepositoryRoot.ts
|
|
18514
|
-
var
|
|
18725
|
+
var import_node_child_process11 = require("child_process");
|
|
18515
18726
|
function currentRepositoryRoot(repository, cwd = process.cwd()) {
|
|
18516
18727
|
const canonical = (value) => value.trim().replace(/\/+$/, "").replace(/\.git$/i, "").replace(/^.*(?:github\.com[/:])/, "").toLowerCase();
|
|
18517
18728
|
try {
|
|
18518
18729
|
const options = { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] };
|
|
18519
|
-
const origin = (0,
|
|
18730
|
+
const origin = (0, import_node_child_process11.execFileSync)("git", ["remote", "get-url", "origin"], options);
|
|
18520
18731
|
if (canonical(origin) !== canonical(repository)) return void 0;
|
|
18521
|
-
return (0,
|
|
18732
|
+
return (0, import_node_child_process11.execFileSync)("git", ["rev-parse", "--show-toplevel"], options).trim();
|
|
18522
18733
|
} catch {
|
|
18523
18734
|
return void 0;
|
|
18524
18735
|
}
|
|
18525
18736
|
}
|
|
18526
18737
|
|
|
18527
18738
|
// src/services/AndroidApkReleaseService.ts
|
|
18528
|
-
var
|
|
18739
|
+
var import_node_child_process12 = require("child_process");
|
|
18529
18740
|
var import_node_crypto6 = require("crypto");
|
|
18530
|
-
var
|
|
18531
|
-
var
|
|
18532
|
-
var
|
|
18741
|
+
var import_node_fs23 = require("fs");
|
|
18742
|
+
var import_node_os12 = __toESM(require("os"));
|
|
18743
|
+
var import_node_path28 = __toESM(require("path"));
|
|
18533
18744
|
var ANDROID_APK_BUCKET = "parrot-static";
|
|
18534
18745
|
var ANDROID_APK_PUBLIC_BASE_URL = "https://parrot-static.pmate.chat";
|
|
18535
18746
|
var ANDROID_SIGNING_ENV_KEYS = ["ANDROID_KEYSTORE_BASE64", "ANDROID_KEYSTORE_PASSWORD", "ANDROID_KEY_ALIAS", "ANDROID_KEY_PASSWORD", "ANDROID_SIGNING_CERT_SHA256"];
|
|
@@ -18549,9 +18760,9 @@ function verifyAndroidSigningCertificate(output, expected) {
|
|
|
18549
18760
|
async function signAndroidApk(apkPath, signing) {
|
|
18550
18761
|
const tool = findAndroidSdkTool("apksigner");
|
|
18551
18762
|
if (!tool) throw new Error("Android SDK tool not found: apksigner");
|
|
18552
|
-
const tempDir = (0,
|
|
18553
|
-
const keystorePath =
|
|
18554
|
-
const cleanup = () => (0,
|
|
18763
|
+
const tempDir = (0, import_node_fs23.mkdtempSync)(import_node_path28.default.join(import_node_os12.default.tmpdir(), "pmate-apk-signing-"));
|
|
18764
|
+
const keystorePath = import_node_path28.default.join(tempDir, "signing.keystore");
|
|
18765
|
+
const cleanup = () => (0, import_node_fs23.rmSync)(tempDir, { recursive: true, force: true });
|
|
18555
18766
|
const interrupted = () => {
|
|
18556
18767
|
cleanup();
|
|
18557
18768
|
process.exit(130);
|
|
@@ -18559,9 +18770,9 @@ async function signAndroidApk(apkPath, signing) {
|
|
|
18559
18770
|
process.once("SIGINT", interrupted);
|
|
18560
18771
|
process.once("SIGTERM", interrupted);
|
|
18561
18772
|
try {
|
|
18562
|
-
(0,
|
|
18773
|
+
(0, import_node_fs23.writeFileSync)(keystorePath, signing.keystore, { mode: 384 });
|
|
18563
18774
|
await new Promise((resolve, reject) => {
|
|
18564
|
-
const child = (0,
|
|
18775
|
+
const child = (0, import_node_child_process12.spawn)(tool, ["sign", "--ks", keystorePath, "--ks-key-alias", signing.alias, "--ks-pass", "env:PMATE_APK_STORE_PASSWORD", "--key-pass", "env:PMATE_APK_KEY_PASSWORD", apkPath], {
|
|
18565
18776
|
env: { ...process.env, PMATE_APK_STORE_PASSWORD: signing.storePassword, PMATE_APK_KEY_PASSWORD: signing.keyPassword },
|
|
18566
18777
|
stdio: "ignore"
|
|
18567
18778
|
});
|
|
@@ -18610,7 +18821,7 @@ var AndroidApkReleaseService = class {
|
|
|
18610
18821
|
}
|
|
18611
18822
|
const bump = planAndroidProjectVersion(appDir, options.bump, publishedFloor);
|
|
18612
18823
|
const signing = options.variant.toLowerCase() === "release" ? await this.loadSigning(service.id, options.env) : void 0;
|
|
18613
|
-
(0,
|
|
18824
|
+
(0, import_node_fs23.writeFileSync)(bump.filePath, bump.source);
|
|
18614
18825
|
ui.info("Bumped Android version", {
|
|
18615
18826
|
file: bump.filePath,
|
|
18616
18827
|
from: `${bump.previousVersionName} (${bump.previousVersionCode})`,
|
|
@@ -18635,7 +18846,7 @@ var AndroidApkReleaseService = class {
|
|
|
18635
18846
|
ui.warn("Overwriting existing APK object", { objectKey, etag: existing.etag, size: existing.size });
|
|
18636
18847
|
}
|
|
18637
18848
|
const sha256 = await sha256File(apkPath);
|
|
18638
|
-
const size = (0,
|
|
18849
|
+
const size = (0, import_node_fs23.statSync)(apkPath).size;
|
|
18639
18850
|
const artifact = {
|
|
18640
18851
|
serviceId: service.id,
|
|
18641
18852
|
env: options.env,
|
|
@@ -18685,17 +18896,17 @@ var AndroidApkReleaseService = class {
|
|
|
18685
18896
|
minimumVersionCode: options.minimumVersionCode
|
|
18686
18897
|
});
|
|
18687
18898
|
const objectKeys = androidUpdateManifestKeys(service);
|
|
18688
|
-
const tempDir = (0,
|
|
18689
|
-
const manifestPath =
|
|
18899
|
+
const tempDir = (0, import_node_fs23.mkdtempSync)(import_node_path28.default.join(import_node_os12.default.tmpdir(), "pmate-apk-latest-"));
|
|
18900
|
+
const manifestPath = import_node_path28.default.join(tempDir, "latest.json");
|
|
18690
18901
|
try {
|
|
18691
|
-
(0,
|
|
18902
|
+
(0, import_node_fs23.writeFileSync)(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
18692
18903
|
`);
|
|
18693
18904
|
for (const objectKey of objectKeys) {
|
|
18694
18905
|
await AliyunService.uploadFile(manifestPath, ANDROID_APK_BUCKET, objectKey);
|
|
18695
18906
|
ui.success(`Published Android update manifest ${ANDROID_APK_PUBLIC_BASE_URL}/${objectKey}`);
|
|
18696
18907
|
}
|
|
18697
18908
|
} finally {
|
|
18698
|
-
(0,
|
|
18909
|
+
(0, import_node_fs23.rmSync)(tempDir, { recursive: true, force: true });
|
|
18699
18910
|
}
|
|
18700
18911
|
}
|
|
18701
18912
|
async list(service, options) {
|
|
@@ -18712,7 +18923,7 @@ var AndroidApkReleaseService = class {
|
|
|
18712
18923
|
const prefix = `apks/${identity.namespace}/${identity.name}`;
|
|
18713
18924
|
const objects = await AliyunService.listObjects(ANDROID_APK_BUCKET, prefix);
|
|
18714
18925
|
return objects.filter((item) => item.name.endsWith(".apk")).map((item) => {
|
|
18715
|
-
const versionName =
|
|
18926
|
+
const versionName = import_node_path28.default.basename(item.name, ".apk");
|
|
18716
18927
|
return {
|
|
18717
18928
|
serviceId,
|
|
18718
18929
|
env: options.env ?? "unknown",
|
|
@@ -18735,7 +18946,7 @@ var AndroidApkReleaseService = class {
|
|
|
18735
18946
|
}
|
|
18736
18947
|
}
|
|
18737
18948
|
resolveRepoRoot(service, cwd) {
|
|
18738
|
-
if (cwd) return
|
|
18949
|
+
if (cwd) return import_node_path28.default.resolve(process.cwd(), cwd);
|
|
18739
18950
|
const repository = this.getRepository(service);
|
|
18740
18951
|
if (repository) {
|
|
18741
18952
|
return resolveRepositoryLocalRoot(repository);
|
|
@@ -18747,8 +18958,8 @@ var AndroidApkReleaseService = class {
|
|
|
18747
18958
|
if (!dir) {
|
|
18748
18959
|
throw new Error(`Missing dir for android service ${service.id}`);
|
|
18749
18960
|
}
|
|
18750
|
-
const appDir =
|
|
18751
|
-
if (!(0,
|
|
18961
|
+
const appDir = import_node_path28.default.resolve(repoRoot, dir);
|
|
18962
|
+
if (!(0, import_node_fs23.existsSync)(appDir)) {
|
|
18752
18963
|
throw new Error(`Android app dir not found: ${appDir}`);
|
|
18753
18964
|
}
|
|
18754
18965
|
return appDir;
|
|
@@ -18764,11 +18975,11 @@ var AndroidApkReleaseService = class {
|
|
|
18764
18975
|
return void 0;
|
|
18765
18976
|
}
|
|
18766
18977
|
async runGradleAssembleAndFindApk(repoRoot, appDir, variant) {
|
|
18767
|
-
const gradlew = [
|
|
18978
|
+
const gradlew = [import_node_path28.default.join(appDir, "gradlew"), import_node_path28.default.join(repoRoot, "gradlew")].find((candidate) => (0, import_node_fs23.existsSync)(candidate));
|
|
18768
18979
|
if (!gradlew) {
|
|
18769
18980
|
throw new Error(`Gradle wrapper not found in ${appDir} or ${repoRoot}`);
|
|
18770
18981
|
}
|
|
18771
|
-
const gradleCwd =
|
|
18982
|
+
const gradleCwd = import_node_path28.default.dirname(gradlew);
|
|
18772
18983
|
const normalizedVariant = variant.toLowerCase();
|
|
18773
18984
|
const taskSuffix = `assemble${capitalize(normalizedVariant)}`;
|
|
18774
18985
|
const tasks = [`:app:${taskSuffix}`, taskSuffix];
|
|
@@ -18884,7 +19095,7 @@ function resolveRepositoryLocalRoot(repository) {
|
|
|
18884
19095
|
if (!repoName) {
|
|
18885
19096
|
throw new Error(`Invalid repository: ${repository}`);
|
|
18886
19097
|
}
|
|
18887
|
-
return
|
|
19098
|
+
return import_node_path28.default.join(import_node_os12.default.homedir(), "dev", "pmate", repoName);
|
|
18888
19099
|
}
|
|
18889
19100
|
function bumpAndroidGradleVersionText(source, bump) {
|
|
18890
19101
|
const versionNameMatch = source.match(/(^\s*versionName\s+["'])([^"']+)(["']\s*$)/m) ?? source.match(/(^\s*versionName\s*=\s*["'])([^"']+)(["']\s*$)/m);
|
|
@@ -18940,14 +19151,14 @@ function parseGradleOutputMetadata(source, apkFileName) {
|
|
|
18940
19151
|
}
|
|
18941
19152
|
function planAndroidProjectVersion(appDir, bump, publishedFloor = 0) {
|
|
18942
19153
|
const candidates = [
|
|
18943
|
-
|
|
18944
|
-
|
|
18945
|
-
|
|
18946
|
-
|
|
19154
|
+
import_node_path28.default.join(appDir, "app", "build.gradle.kts"),
|
|
19155
|
+
import_node_path28.default.join(appDir, "app", "build.gradle"),
|
|
19156
|
+
import_node_path28.default.join(appDir, "build.gradle.kts"),
|
|
19157
|
+
import_node_path28.default.join(appDir, "build.gradle")
|
|
18947
19158
|
];
|
|
18948
19159
|
for (const candidate of candidates) {
|
|
18949
|
-
if (!(0,
|
|
18950
|
-
const result = bumpAndroidGradleVersionText((0,
|
|
19160
|
+
if (!(0, import_node_fs23.existsSync)(candidate)) continue;
|
|
19161
|
+
const result = bumpAndroidGradleVersionText((0, import_node_fs23.readFileSync)(candidate, "utf8"), bump);
|
|
18951
19162
|
if (!Number.isSafeInteger(result.versionCode) || result.versionCode <= publishedFloor) throw new Error(`Android source is behind published versionCode ${publishedFloor}; update the checkout before releasing`);
|
|
18952
19163
|
return { filePath: candidate, ...result };
|
|
18953
19164
|
}
|
|
@@ -18955,31 +19166,31 @@ function planAndroidProjectVersion(appDir, bump, publishedFloor = 0) {
|
|
|
18955
19166
|
}
|
|
18956
19167
|
function findLatestApk(repoRoot, appDir, variant) {
|
|
18957
19168
|
const dirs = [
|
|
18958
|
-
|
|
18959
|
-
|
|
18960
|
-
|
|
19169
|
+
import_node_path28.default.join(appDir, "app", "build", "outputs", "apk", variant),
|
|
19170
|
+
import_node_path28.default.join(appDir, "build", "outputs", "apk", variant),
|
|
19171
|
+
import_node_path28.default.join(repoRoot, "app", "build", "outputs", "apk", variant)
|
|
18961
19172
|
];
|
|
18962
19173
|
const files = dirs.flatMap((dir) => listApks(dir));
|
|
18963
19174
|
if (files.length === 0) {
|
|
18964
19175
|
throw new Error(`Cannot find APK output for variant ${variant}`);
|
|
18965
19176
|
}
|
|
18966
|
-
files.sort((a, b) => (0,
|
|
19177
|
+
files.sort((a, b) => (0, import_node_fs23.statSync)(b).mtimeMs - (0, import_node_fs23.statSync)(a).mtimeMs);
|
|
18967
19178
|
return files[0];
|
|
18968
19179
|
}
|
|
18969
19180
|
function readGradleOutputMetadata(apkPath) {
|
|
18970
|
-
const metadataPath =
|
|
18971
|
-
if (!(0,
|
|
19181
|
+
const metadataPath = import_node_path28.default.join(import_node_path28.default.dirname(apkPath), "output-metadata.json");
|
|
19182
|
+
if (!(0, import_node_fs23.existsSync)(metadataPath)) {
|
|
18972
19183
|
throw new Error(`Gradle output metadata not found: ${metadataPath}`);
|
|
18973
19184
|
}
|
|
18974
|
-
return parseGradleOutputMetadata((0,
|
|
19185
|
+
return parseGradleOutputMetadata((0, import_node_fs23.readFileSync)(metadataPath, "utf8"), import_node_path28.default.basename(apkPath));
|
|
18975
19186
|
}
|
|
18976
19187
|
function listApks(dir) {
|
|
18977
|
-
if (!(0,
|
|
18978
|
-
return (0,
|
|
19188
|
+
if (!(0, import_node_fs23.existsSync)(dir)) return [];
|
|
19189
|
+
return (0, import_node_fs23.readdirSync)(dir).filter((entry) => entry.endsWith(".apk")).map((entry) => import_node_path28.default.join(dir, entry)).filter((entry) => (0, import_node_fs23.statSync)(entry).isFile());
|
|
18979
19190
|
}
|
|
18980
19191
|
function runCommand(command, args, cwd) {
|
|
18981
19192
|
return new Promise((resolve, reject) => {
|
|
18982
|
-
const child = (0,
|
|
19193
|
+
const child = (0, import_node_child_process12.spawn)(command, args, { cwd, stdio: "inherit" });
|
|
18983
19194
|
child.on("error", reject);
|
|
18984
19195
|
child.on("close", (code) => {
|
|
18985
19196
|
if (code === 0) resolve();
|
|
@@ -18989,7 +19200,7 @@ function runCommand(command, args, cwd) {
|
|
|
18989
19200
|
}
|
|
18990
19201
|
function runCommandCapture(command, args, cwd) {
|
|
18991
19202
|
return new Promise((resolve, reject) => {
|
|
18992
|
-
const child = (0,
|
|
19203
|
+
const child = (0, import_node_child_process12.spawn)(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
18993
19204
|
const chunks = [];
|
|
18994
19205
|
const errorChunks = [];
|
|
18995
19206
|
child.stdout?.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
@@ -19009,26 +19220,26 @@ async function runAndroidSdkToolCapture(toolName, args) {
|
|
|
19009
19220
|
return runCommandCapture(toolPath, args);
|
|
19010
19221
|
}
|
|
19011
19222
|
function findAndroidSdkTool(toolName) {
|
|
19012
|
-
const sdkRoots = [process.env.ANDROID_HOME, process.env.ANDROID_SDK_ROOT].filter((item) => Boolean(item)).map((item) =>
|
|
19223
|
+
const sdkRoots = [process.env.ANDROID_HOME, process.env.ANDROID_SDK_ROOT].filter((item) => Boolean(item)).map((item) => import_node_path28.default.resolve(item));
|
|
19013
19224
|
for (const sdkRoot of sdkRoots) {
|
|
19014
|
-
const candidates = toolName === "aapt" || toolName === "apksigner" ? listVersionedToolCandidates(
|
|
19015
|
-
|
|
19016
|
-
...listVersionedToolCandidates(
|
|
19017
|
-
|
|
19225
|
+
const candidates = toolName === "aapt" || toolName === "apksigner" ? listVersionedToolCandidates(import_node_path28.default.join(sdkRoot, "build-tools"), toolName) : [
|
|
19226
|
+
import_node_path28.default.join(sdkRoot, "cmdline-tools", "latest", "bin", toolName),
|
|
19227
|
+
...listVersionedToolCandidates(import_node_path28.default.join(sdkRoot, "cmdline-tools"), import_node_path28.default.join("bin", toolName)),
|
|
19228
|
+
import_node_path28.default.join(sdkRoot, "tools", "bin", toolName)
|
|
19018
19229
|
];
|
|
19019
|
-
const match = candidates.find((candidate) => (0,
|
|
19230
|
+
const match = candidates.find((candidate) => (0, import_node_fs23.existsSync)(candidate));
|
|
19020
19231
|
if (match) return match;
|
|
19021
19232
|
}
|
|
19022
19233
|
return void 0;
|
|
19023
19234
|
}
|
|
19024
19235
|
function listVersionedToolCandidates(parentDir, relativeToolPath) {
|
|
19025
|
-
if (!(0,
|
|
19026
|
-
return (0,
|
|
19236
|
+
if (!(0, import_node_fs23.existsSync)(parentDir)) return [];
|
|
19237
|
+
return (0, import_node_fs23.readdirSync)(parentDir).map((entry) => import_node_path28.default.join(parentDir, entry)).filter((entry) => (0, import_node_fs23.statSync)(entry).isDirectory()).sort((a, b) => import_node_path28.default.basename(b).localeCompare(import_node_path28.default.basename(a), void 0, { numeric: true })).map((entry) => import_node_path28.default.join(entry, relativeToolPath));
|
|
19027
19238
|
}
|
|
19028
19239
|
function sha256File(filePath) {
|
|
19029
19240
|
return new Promise((resolve, reject) => {
|
|
19030
19241
|
const hash = (0, import_node_crypto6.createHash)("sha256");
|
|
19031
|
-
const stream = (0,
|
|
19242
|
+
const stream = (0, import_node_fs23.createReadStream)(filePath);
|
|
19032
19243
|
stream.on("data", (chunk) => hash.update(chunk));
|
|
19033
19244
|
stream.on("error", reject);
|
|
19034
19245
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -19045,22 +19256,22 @@ function capitalize(value) {
|
|
|
19045
19256
|
}
|
|
19046
19257
|
|
|
19047
19258
|
// src/services/HarmonyReleaseService.ts
|
|
19048
|
-
var
|
|
19259
|
+
var import_node_child_process13 = require("child_process");
|
|
19049
19260
|
var import_node_crypto7 = require("crypto");
|
|
19050
|
-
var
|
|
19051
|
-
var
|
|
19052
|
-
var
|
|
19261
|
+
var import_node_fs24 = require("fs");
|
|
19262
|
+
var import_node_os13 = __toESM(require("os"));
|
|
19263
|
+
var import_node_path29 = __toESM(require("path"));
|
|
19053
19264
|
var import_json5 = __toESM(require("json5"));
|
|
19054
19265
|
var HARMONY_SIGNING_KEYS = ["HARMONY_KEYSTORE_BASE64", "HARMONY_CERTIFICATE_BASE64", "HARMONY_PROFILE_BASE64", "HARMONY_STORE_PASSWORD", "HARMONY_KEY_ALIAS", "HARMONY_KEY_PASSWORD"];
|
|
19055
19266
|
var bucket = "parrot-static";
|
|
19056
19267
|
var baseUrl = "https://parrot-static.pmate.chat";
|
|
19057
19268
|
var inside = (parent, child) => {
|
|
19058
|
-
const rel =
|
|
19059
|
-
return !rel || !rel.startsWith(`..${
|
|
19269
|
+
const rel = import_node_path29.default.relative(parent, child);
|
|
19270
|
+
return !rel || !rel.startsWith(`..${import_node_path29.default.sep}`) && rel !== ".." && !import_node_path29.default.isAbsolute(rel);
|
|
19060
19271
|
};
|
|
19061
|
-
var readJson5 = (file) => import_json5.default.parse((0,
|
|
19272
|
+
var readJson5 = (file) => import_json5.default.parse((0, import_node_fs24.readFileSync)(file, "utf8"));
|
|
19062
19273
|
function readHarmonyVersion(appDir, expected) {
|
|
19063
|
-
const app = readJson5(
|
|
19274
|
+
const app = readJson5(import_node_path29.default.join(appDir, "AppScope/app.json5")).app;
|
|
19064
19275
|
if (!app || app.bundleName !== expected) throw new Error("HarmonyOS bundleName does not match service.mobile.bundleName");
|
|
19065
19276
|
if (!/^\d+\.\d+\.\d+$/.test(app.versionName ?? "") || !Number.isSafeInteger(app.versionCode) || app.versionCode <= 0) throw new Error("HarmonyOS source requires a stable versionName and positive integer versionCode");
|
|
19066
19277
|
return { bundleName: app.bundleName, versionName: app.versionName, versionCode: app.versionCode };
|
|
@@ -19071,25 +19282,25 @@ function stageHarmonySources(repoRoot, appDir, target) {
|
|
|
19071
19282
|
const copy = (source) => {
|
|
19072
19283
|
if (!inside(repoRoot, source)) throw new Error("HarmonyOS local dependencies must stay inside the repository");
|
|
19073
19284
|
if (copied.some((dir) => inside(dir, source))) return;
|
|
19074
|
-
if (!(0,
|
|
19075
|
-
if (!inside((0,
|
|
19076
|
-
const dest =
|
|
19077
|
-
(0,
|
|
19078
|
-
if ((0,
|
|
19079
|
-
const name =
|
|
19285
|
+
if (!(0, import_node_fs24.existsSync)(source) || !(0, import_node_fs24.lstatSync)(source).isDirectory() || (0, import_node_fs24.lstatSync)(source).isSymbolicLink()) throw new Error("Invalid HarmonyOS source dependency");
|
|
19286
|
+
if (!inside((0, import_node_fs24.realpathSync)(repoRoot), (0, import_node_fs24.realpathSync)(source))) throw new Error("HarmonyOS local dependencies must stay inside the repository");
|
|
19287
|
+
const dest = import_node_path29.default.join(target, import_node_path29.default.relative(repoRoot, source));
|
|
19288
|
+
(0, import_node_fs24.cpSync)(source, dest, { recursive: true, filter: (file) => {
|
|
19289
|
+
if ((0, import_node_fs24.lstatSync)(file).isSymbolicLink()) throw new Error("HarmonyOS source symlinks are not supported");
|
|
19290
|
+
const name = import_node_path29.default.basename(file);
|
|
19080
19291
|
return !excluded.has(name) && !name.startsWith(".env") && !/\.(p12|pfx|p7b|keystore|jks|key|pem|cer)$/i.test(name);
|
|
19081
19292
|
} });
|
|
19082
19293
|
copied.push(source);
|
|
19083
19294
|
const inspect = (dir) => {
|
|
19084
|
-
for (const entry of (0,
|
|
19085
|
-
const file =
|
|
19295
|
+
for (const entry of (0, import_node_fs24.readdirSync)(dir, { withFileTypes: true })) {
|
|
19296
|
+
const file = import_node_path29.default.join(dir, entry.name);
|
|
19086
19297
|
if (entry.isDirectory()) inspect(file);
|
|
19087
19298
|
else if (entry.name === "oh-package.json5") {
|
|
19088
19299
|
const manifest = readJson5(file);
|
|
19089
19300
|
for (const value of Object.values({ ...manifest.dependencies, ...manifest.devDependencies })) {
|
|
19090
19301
|
if (typeof value !== "string" || !value.startsWith("file:")) continue;
|
|
19091
|
-
const original =
|
|
19092
|
-
copy(
|
|
19302
|
+
const original = import_node_path29.default.join(repoRoot, import_node_path29.default.relative(target, import_node_path29.default.dirname(file)));
|
|
19303
|
+
copy(import_node_path29.default.resolve(original, value.slice(5)));
|
|
19093
19304
|
}
|
|
19094
19305
|
}
|
|
19095
19306
|
}
|
|
@@ -19097,19 +19308,19 @@ function stageHarmonySources(repoRoot, appDir, target) {
|
|
|
19097
19308
|
inspect(dest);
|
|
19098
19309
|
};
|
|
19099
19310
|
copy(appDir);
|
|
19100
|
-
const profile = readJson5(
|
|
19311
|
+
const profile = readJson5(import_node_path29.default.join(appDir, "build-profile.json5"));
|
|
19101
19312
|
for (const module2 of profile.modules ?? []) {
|
|
19102
19313
|
if (typeof module2.srcPath !== "string") throw new Error("Invalid HarmonyOS module srcPath");
|
|
19103
|
-
copy(
|
|
19314
|
+
copy(import_node_path29.default.resolve(appDir, module2.srcPath));
|
|
19104
19315
|
}
|
|
19105
|
-
return
|
|
19316
|
+
return import_node_path29.default.join(target, import_node_path29.default.relative(repoRoot, appDir));
|
|
19106
19317
|
}
|
|
19107
19318
|
function executable(value) {
|
|
19108
|
-
const candidates = value.includes(
|
|
19319
|
+
const candidates = value.includes(import_node_path29.default.sep) ? [import_node_path29.default.resolve(value)] : (process.env.PATH ?? "").split(import_node_path29.default.delimiter).map((dir) => import_node_path29.default.join(dir, value));
|
|
19109
19320
|
for (const file of candidates) {
|
|
19110
19321
|
try {
|
|
19111
|
-
(0,
|
|
19112
|
-
if ((0,
|
|
19322
|
+
(0, import_node_fs24.accessSync)(file, import_node_fs24.constants.X_OK);
|
|
19323
|
+
if ((0, import_node_fs24.lstatSync)(file).isFile() || (0, import_node_fs24.lstatSync)(file).isSymbolicLink()) return file;
|
|
19113
19324
|
} catch {
|
|
19114
19325
|
}
|
|
19115
19326
|
}
|
|
@@ -19118,14 +19329,14 @@ function executable(value) {
|
|
|
19118
19329
|
function findHarmonyTools() {
|
|
19119
19330
|
if (!["darwin", "linux"].includes(process.platform)) throw new Error("HarmonyOS release scripts require macOS or Linux");
|
|
19120
19331
|
const home = "/Applications/DevEco-Studio.app/Contents";
|
|
19121
|
-
const sdk =
|
|
19122
|
-
if (!(0,
|
|
19332
|
+
const sdk = import_node_path29.default.resolve(process.env.DEVECO_SDK_HOME ?? `${home}/sdk`);
|
|
19333
|
+
if (!(0, import_node_fs24.existsSync)(sdk)) throw new Error("HarmonyOS SDK not found; install DevEco Studio or set DEVECO_SDK_HOME");
|
|
19123
19334
|
const tools = { sdk, ohpm: executable(process.env.OHPM_BIN ?? `${home}/tools/ohpm/bin/ohpm`), hvigor: executable(process.env.HVIGORW_BIN ?? `${home}/tools/hvigor/bin/hvigorw`), node: executable(process.env.NODE_BIN ?? process.execPath), java: executable(process.env.JAVA_BIN ?? "java"), signer: process.env.HAP_SIGN_TOOL ?? "" };
|
|
19124
19335
|
if (!tools.signer) {
|
|
19125
19336
|
const jars = [];
|
|
19126
19337
|
const scan = (dir) => {
|
|
19127
|
-
for (const entry of (0,
|
|
19128
|
-
const file =
|
|
19338
|
+
for (const entry of (0, import_node_fs24.readdirSync)(dir, { withFileTypes: true })) {
|
|
19339
|
+
const file = import_node_path29.default.join(dir, entry.name);
|
|
19129
19340
|
if (entry.isDirectory()) scan(file);
|
|
19130
19341
|
else if (entry.isFile() && entry.name === "hap-sign-tool.jar") jars.push(file);
|
|
19131
19342
|
}
|
|
@@ -19134,18 +19345,18 @@ function findHarmonyTools() {
|
|
|
19134
19345
|
if (jars.length !== 1) throw new Error("Set HAP_SIGN_TOOL to the intended hap-sign-tool.jar");
|
|
19135
19346
|
tools.signer = jars[0];
|
|
19136
19347
|
}
|
|
19137
|
-
tools.signer =
|
|
19138
|
-
if (!(0,
|
|
19348
|
+
tools.signer = import_node_path29.default.resolve(tools.signer);
|
|
19349
|
+
if (!(0, import_node_fs24.existsSync)(tools.signer)) throw new Error("HAP_SIGN_TOOL does not exist");
|
|
19139
19350
|
executable("bash");
|
|
19140
19351
|
executable("unzip");
|
|
19141
19352
|
return tools;
|
|
19142
19353
|
}
|
|
19143
19354
|
var runHarmonyCommand = async (command, args, options) => {
|
|
19144
|
-
const log = (0,
|
|
19145
|
-
const output = options.output ? (0,
|
|
19355
|
+
const log = (0, import_node_fs24.openSync)(options.log, "a", 384);
|
|
19356
|
+
const output = options.output ? (0, import_node_fs24.openSync)(options.output, "w", 384) : void 0;
|
|
19146
19357
|
try {
|
|
19147
19358
|
return await new Promise((resolve, reject) => {
|
|
19148
|
-
const child = (0,
|
|
19359
|
+
const child = (0, import_node_child_process13.spawn)(command, args, { cwd: options.cwd, env: options.env, detached: process.platform !== "win32", stdio: ["ignore", output ?? (options.capture ? "pipe" : log), log] });
|
|
19149
19360
|
let text = "", oversized = false;
|
|
19150
19361
|
child.stdout?.on("data", (chunk) => {
|
|
19151
19362
|
if (Buffer.byteLength(text) + chunk.length > 1024 * 1024) {
|
|
@@ -19168,16 +19379,16 @@ var runHarmonyCommand = async (command, args, options) => {
|
|
|
19168
19379
|
};
|
|
19169
19380
|
child.once("error", () => {
|
|
19170
19381
|
clean();
|
|
19171
|
-
reject(new Error(`Cannot run ${
|
|
19382
|
+
reject(new Error(`Cannot run ${import_node_path29.default.basename(command)}; see ${options.log}`));
|
|
19172
19383
|
});
|
|
19173
19384
|
child.once("close", (code) => {
|
|
19174
19385
|
clean();
|
|
19175
|
-
code === 0 && !oversized ? resolve(text) : reject(new Error(`HarmonyOS ${
|
|
19386
|
+
code === 0 && !oversized ? resolve(text) : reject(new Error(`HarmonyOS ${import_node_path29.default.basename(command)} failed (${code}); see ${options.log}`));
|
|
19176
19387
|
});
|
|
19177
19388
|
});
|
|
19178
19389
|
} finally {
|
|
19179
|
-
(0,
|
|
19180
|
-
if (output !== void 0) (0,
|
|
19390
|
+
(0, import_node_fs24.closeSync)(log);
|
|
19391
|
+
if (output !== void 0) (0, import_node_fs24.closeSync)(output);
|
|
19181
19392
|
}
|
|
19182
19393
|
};
|
|
19183
19394
|
function signingMaterial(values) {
|
|
@@ -19221,14 +19432,14 @@ var HarmonyReleaseService = class {
|
|
|
19221
19432
|
if (!("type" in service) || service.type !== "harmonyos" || !service.mobile || !("bundleName" in service.mobile)) throw new Error("HarmonyOS requires service.mobile.bundleName");
|
|
19222
19433
|
if (service.appIds?.length !== 1) throw new Error("HarmonyOS service requires exactly one appIds application identity");
|
|
19223
19434
|
const application = service.appIds[0];
|
|
19224
|
-
const root = options.cwd ?
|
|
19435
|
+
const root = options.cwd ? import_node_path29.default.resolve(options.cwd) : resolveRepositoryLocalRoot(service.repository ?? service.mobile.repository ?? "");
|
|
19225
19436
|
const dir = service.dir ?? service.mobile.dir;
|
|
19226
19437
|
if (!dir) throw new Error("HarmonyOS service requires a source directory");
|
|
19227
|
-
const appDir =
|
|
19438
|
+
const appDir = import_node_path29.default.resolve(root, dir);
|
|
19228
19439
|
if (!inside(root, appDir)) throw new Error("HarmonyOS source must stay inside the repository");
|
|
19229
19440
|
const version = readHarmonyVersion(appDir, service.mobile.bundleName);
|
|
19230
19441
|
const script = service.build?.script ?? "scripts/build-release.sh";
|
|
19231
|
-
if (
|
|
19442
|
+
if (import_node_path29.default.isAbsolute(script) || !inside(appDir, import_node_path29.default.resolve(appDir, script)) || (!(0, import_node_fs24.existsSync)(import_node_path29.default.resolve(appDir, script)) || !(0, import_node_fs24.lstatSync)(import_node_path29.default.resolve(appDir, script)).isFile())) throw new Error("HarmonyOS build.script must name an existing script inside the application");
|
|
19232
19443
|
const prefix = `harmony/${service.namespace}/${service.name}`;
|
|
19233
19444
|
if (![service.namespace, service.name].every((v) => /^[\w-]+$/.test(v))) throw new Error("Invalid HarmonyOS service identity");
|
|
19234
19445
|
const releasePrefix = `${prefix}/${version.versionName}/${version.versionCode}/`;
|
|
@@ -19246,67 +19457,67 @@ var HarmonyReleaseService = class {
|
|
|
19246
19457
|
if (!this.registry) throw new Error("HarmonyOS signing requires the service environment registry");
|
|
19247
19458
|
const { values } = await this.registry.resolveEnv(service.id, { stage: "prod", includeSecretValue: true, includeHost: false });
|
|
19248
19459
|
const material = signingMaterial(values);
|
|
19249
|
-
const outputBase = options.outDir ?
|
|
19460
|
+
const outputBase = options.outDir ? import_node_path29.default.resolve(options.outDir) : import_node_path29.default.join(import_node_os13.default.homedir(), ".pmate/harmony-builds", service.namespace, service.name);
|
|
19250
19461
|
if (inside(appDir, outputBase)) throw new Error("HarmonyOS output must be outside the application source directory");
|
|
19251
|
-
(0,
|
|
19252
|
-
const output = (0,
|
|
19253
|
-
(0,
|
|
19254
|
-
const temp = (0,
|
|
19462
|
+
(0, import_node_fs24.mkdirSync)(outputBase, { recursive: true, mode: 448 });
|
|
19463
|
+
const output = (0, import_node_fs24.mkdtempSync)(import_node_path29.default.join(outputBase, `release-${version.versionCode}-`)), log = import_node_path29.default.join(output, "build.log");
|
|
19464
|
+
(0, import_node_fs24.writeFileSync)(log, "", { mode: 384 });
|
|
19465
|
+
const temp = (0, import_node_fs24.mkdtempSync)(import_node_path29.default.join(import_node_os13.default.tmpdir(), "pmate-harmony-")), run2 = this.deps.run ?? runHarmonyCommand;
|
|
19255
19466
|
let artifacts = [];
|
|
19256
19467
|
try {
|
|
19257
|
-
const staged = stageHarmonySources(root, appDir,
|
|
19258
|
-
for (const
|
|
19259
|
-
const file =
|
|
19260
|
-
(0,
|
|
19261
|
-
}
|
|
19262
|
-
const keys =
|
|
19263
|
-
(0,
|
|
19264
|
-
for (const [name, bytes] of [["release.p12", material.keystore], ["release.cer", material.certificate], ["release.p7b", material.profile]]) (0,
|
|
19468
|
+
const staged = stageHarmonySources(root, appDir, import_node_path29.default.join(temp, "checkout"));
|
|
19469
|
+
for (const relative2 of ["build-profile.json5", "AppScope/app.json5"]) {
|
|
19470
|
+
const file = import_node_path29.default.join(staged, relative2);
|
|
19471
|
+
(0, import_node_fs24.writeFileSync)(file, JSON.stringify(readJson5(file), null, 2));
|
|
19472
|
+
}
|
|
19473
|
+
const keys = import_node_path29.default.join(temp, "signing");
|
|
19474
|
+
(0, import_node_fs24.mkdirSync)(keys, { mode: 448 });
|
|
19475
|
+
for (const [name, bytes] of [["release.p12", material.keystore], ["release.cer", material.certificate], ["release.p7b", material.profile]]) (0, import_node_fs24.writeFileSync)(import_node_path29.default.join(keys, name), bytes, { mode: 384 });
|
|
19265
19476
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith("HARMONY_")));
|
|
19266
|
-
Object.assign(env, { DEVECO_SDK_HOME: tools.sdk, OHPM_BIN: tools.ohpm, HVIGORW_BIN: tools.hvigor, NODE_BIN: tools.node, JAVA_BIN: tools.java, HAP_SIGN_TOOL: tools.signer, HARMONY_KEYSTORE_FILE:
|
|
19477
|
+
Object.assign(env, { DEVECO_SDK_HOME: tools.sdk, OHPM_BIN: tools.ohpm, HVIGORW_BIN: tools.hvigor, NODE_BIN: tools.node, JAVA_BIN: tools.java, HAP_SIGN_TOOL: tools.signer, HARMONY_KEYSTORE_FILE: import_node_path29.default.join(keys, "release.p12"), HARMONY_CERTIFICATE_FILE: import_node_path29.default.join(keys, "release.cer"), HARMONY_PROFILE_FILE: import_node_path29.default.join(keys, "release.p7b"), HARMONY_STORE_PASSWORD: values.HARMONY_STORE_PASSWORD, HARMONY_KEY_ALIAS: values.HARMONY_KEY_ALIAS, HARMONY_KEY_PASSWORD: values.HARMONY_KEY_PASSWORD, HARMONY_VERSION_NAME: version.versionName, HARMONY_VERSION_CODE: String(version.versionCode), HARMONY_RELEASE_DRY_RUN: "0" });
|
|
19267
19478
|
const opts = { cwd: staged, env, log };
|
|
19268
|
-
await
|
|
19269
|
-
const dist =
|
|
19270
|
-
const files = (0,
|
|
19479
|
+
await run2("bash", [import_node_path29.default.resolve(staged, script)], opts);
|
|
19480
|
+
const dist = import_node_path29.default.join(staged, "dist");
|
|
19481
|
+
const files = (0, import_node_fs24.readdirSync)(dist, { withFileTypes: true }).filter((e) => e.isFile() && /\.(app|hap)$/.test(e.name)).map((e) => import_node_path29.default.join(dist, e.name));
|
|
19271
19482
|
if (files.length !== 2 || files.filter((f) => f.endsWith(".app")).length !== 1 || files.filter((f) => f.endsWith(".hap")).length !== 1) throw new Error("HarmonyOS build must produce exactly one signed APP and one signed HAP");
|
|
19272
19483
|
const check = async (file, inspectMetadata) => {
|
|
19273
|
-
const id = (0, import_node_crypto7.createHash)("sha256").update(file).digest("hex").slice(0, 16), cert =
|
|
19274
|
-
await
|
|
19275
|
-
if (new import_node_crypto7.X509Certificate((0,
|
|
19276
|
-
if (inspectMetadata) assertHarmonyMetadata(JSON.parse(await
|
|
19484
|
+
const id = (0, import_node_crypto7.createHash)("sha256").update(file).digest("hex").slice(0, 16), cert = import_node_path29.default.join(temp, `${id}.cer`);
|
|
19485
|
+
await run2(tools.java, ["-jar", tools.signer, "verify-app", "-inFile", file, "-outCertChain", cert, "-outProfile", import_node_path29.default.join(temp, `${id}.p7b`)], opts);
|
|
19486
|
+
if (new import_node_crypto7.X509Certificate((0, import_node_fs24.readFileSync)(cert)).fingerprint256.replace(/:/g, "") !== material.fingerprint) throw new Error("HarmonyOS signer certificate does not match service certificate");
|
|
19487
|
+
if (inspectMetadata) assertHarmonyMetadata(JSON.parse(await run2("unzip", ["-p", file, "module.json"], { ...opts, capture: true })), version);
|
|
19277
19488
|
};
|
|
19278
19489
|
for (const file of files) {
|
|
19279
19490
|
await check(file, file.endsWith(".hap"));
|
|
19280
19491
|
if (file.endsWith(".app")) {
|
|
19281
|
-
const names = (await
|
|
19492
|
+
const names = (await run2("unzip", ["-Z1", file], { ...opts, capture: true })).split(/\r?\n/).filter((name) => /\.(hap|hsp)$/.test(name));
|
|
19282
19493
|
if (!names.length) throw new Error("HarmonyOS APP contains no package modules");
|
|
19283
19494
|
for (const [index, name] of names.entries()) {
|
|
19284
19495
|
if (name.startsWith("/") || name.includes("\\") || name.split("/").includes("..")) throw new Error("Unsafe HarmonyOS archive member");
|
|
19285
|
-
const embedded =
|
|
19286
|
-
await
|
|
19496
|
+
const embedded = import_node_path29.default.join(temp, `module-${index}${import_node_path29.default.extname(name)}`);
|
|
19497
|
+
await run2("unzip", ["-p", file, name], { ...opts, output: embedded });
|
|
19287
19498
|
await check(embedded, true);
|
|
19288
19499
|
}
|
|
19289
19500
|
}
|
|
19290
19501
|
}
|
|
19291
19502
|
artifacts = [];
|
|
19292
19503
|
for (const file of files) {
|
|
19293
|
-
const name =
|
|
19504
|
+
const name = import_node_path29.default.basename(file);
|
|
19294
19505
|
if (!/^[A-Za-z0-9._-]+\.(app|hap)$/.test(name)) throw new Error("Invalid HarmonyOS artifact filename");
|
|
19295
|
-
const size = (0,
|
|
19506
|
+
const size = (0, import_node_fs24.statSync)(file).size;
|
|
19296
19507
|
if (!size) throw new Error("Empty HarmonyOS artifact");
|
|
19297
|
-
const target =
|
|
19298
|
-
(0,
|
|
19508
|
+
const target = import_node_path29.default.join(output, name);
|
|
19509
|
+
(0, import_node_fs24.cpSync)(file, target);
|
|
19299
19510
|
const hash = (0, import_node_crypto7.createHash)("sha256");
|
|
19300
|
-
for await (const chunk of (0,
|
|
19301
|
-
artifacts.push({ name, type:
|
|
19511
|
+
for await (const chunk of (0, import_node_fs24.createReadStream)(target)) hash.update(chunk);
|
|
19512
|
+
artifacts.push({ name, type: import_node_path29.default.extname(name).slice(1), objectKey: releasePrefix + name, downloadUrl: `${baseUrl}/${releasePrefix}${name}`, sha256: hash.digest("hex"), size });
|
|
19302
19513
|
}
|
|
19303
19514
|
} finally {
|
|
19304
|
-
(0,
|
|
19515
|
+
(0, import_node_fs24.rmSync)(temp, { recursive: true, force: true });
|
|
19305
19516
|
}
|
|
19306
19517
|
if (options.local) return { ...plan, status: "local", output, log, artifacts };
|
|
19307
19518
|
let revision;
|
|
19308
19519
|
try {
|
|
19309
|
-
revision = (0,
|
|
19520
|
+
revision = (0, import_node_child_process13.execFileSync)("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
19310
19521
|
} catch {
|
|
19311
19522
|
}
|
|
19312
19523
|
const manifest = { schemaVersion: 1, serviceId: service.id, app: application, platform: "harmonyos", distribution: "oss", appGallerySubmitted: false, ...version, signature: "verified", certificateSha256: material.fingerprint, sourceRevision: revision, artifacts, publishedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -19316,21 +19527,21 @@ var HarmonyReleaseService = class {
|
|
|
19316
19527
|
if (latest && (latest.serviceId !== service.id || latest.app !== application || latest.bundleName !== version.bundleName || latest.schemaVersion !== 1 || latest.platform !== "harmonyos" || latest.signature !== "verified" || !Number.isSafeInteger(latest.versionCode) || latest.versionCode <= 0)) throw new Error("Invalid existing HarmonyOS update manifest");
|
|
19317
19528
|
if (latest && latest.versionCode >= version.versionCode) throw new Error("A same or newer HarmonyOS release was published during the build; latest is unchanged");
|
|
19318
19529
|
if (await read(bucket, `${releasePrefix}release.json`) !== null || (await (this.deps.list ?? AliyunService.listObjects)(bucket, releasePrefix)).length) throw new Error("HarmonyOS release already exists; published objects are immutable");
|
|
19319
|
-
for (const artifact of artifacts) await upload(
|
|
19530
|
+
for (const artifact of artifacts) await upload(import_node_path29.default.join(output, artifact.name), bucket, artifact.objectKey, { "x-oss-forbid-overwrite": "true" });
|
|
19320
19531
|
await uploadJson(bucket, `${releasePrefix}release.json`, manifest, { "x-oss-forbid-overwrite": "true" });
|
|
19321
19532
|
await uploadJson(bucket, `${prefix}/latest.json`, manifest);
|
|
19322
19533
|
});
|
|
19323
|
-
(0,
|
|
19534
|
+
(0, import_node_fs24.writeFileSync)(import_node_path29.default.join(output, "release.json"), JSON.stringify(manifest, null, 2));
|
|
19324
19535
|
return { ...plan, status: "published", output, log, signature: "verified", artifacts };
|
|
19325
19536
|
}
|
|
19326
19537
|
};
|
|
19327
19538
|
|
|
19328
19539
|
// src/services/IosBuildService.ts
|
|
19329
|
-
var
|
|
19540
|
+
var import_node_child_process14 = require("child_process");
|
|
19330
19541
|
var import_node_crypto8 = require("crypto");
|
|
19331
|
-
var
|
|
19332
|
-
var
|
|
19333
|
-
var
|
|
19542
|
+
var import_node_fs25 = require("fs");
|
|
19543
|
+
var import_node_os14 = __toESM(require("os"));
|
|
19544
|
+
var import_node_path30 = __toESM(require("path"));
|
|
19334
19545
|
function iosBuildInteger(value) {
|
|
19335
19546
|
if (!/^(0|[1-9]\d*)$/.test(String(value)) || !Number.isSafeInteger(Number(value))) {
|
|
19336
19547
|
throw new Error(`iOS Build must be a non-negative safe integer: ${String(value)}`);
|
|
@@ -19339,13 +19550,13 @@ function iosBuildInteger(value) {
|
|
|
19339
19550
|
}
|
|
19340
19551
|
async function runXcode(args, cwd, logPath) {
|
|
19341
19552
|
return new Promise((resolve, reject) => {
|
|
19342
|
-
const child = (0,
|
|
19553
|
+
const child = (0, import_node_child_process14.spawn)("xcodebuild", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
19343
19554
|
let output = "";
|
|
19344
19555
|
child.stdout.on("data", (chunk) => {
|
|
19345
19556
|
if (args.includes("-json") || args.includes("-version")) output += chunk.toString();
|
|
19346
|
-
(0,
|
|
19557
|
+
(0, import_node_fs25.appendFileSync)(logPath, chunk);
|
|
19347
19558
|
});
|
|
19348
|
-
child.stderr.on("data", (chunk) => (0,
|
|
19559
|
+
child.stderr.on("data", (chunk) => (0, import_node_fs25.appendFileSync)(logPath, chunk));
|
|
19349
19560
|
child.on("error", reject);
|
|
19350
19561
|
child.on("close", (code) => code === 0 ? resolve(output) : reject(new Error(`xcodebuild failed (${code}); see ${logPath}`)));
|
|
19351
19562
|
});
|
|
@@ -19364,23 +19575,23 @@ var IosBuildService = class {
|
|
|
19364
19575
|
const repository = service.repository ?? service.mobile?.repository;
|
|
19365
19576
|
const dir = service.dir ?? service.mobile?.dir;
|
|
19366
19577
|
if (!dir || !repository && !options.cwd) throw new Error("iOS service requires repository and dir, or --cwd and dir");
|
|
19367
|
-
const repoRoot = options.cwd ?
|
|
19368
|
-
const appDir =
|
|
19369
|
-
if (!(0,
|
|
19578
|
+
const repoRoot = options.cwd ? import_node_path30.default.resolve(options.cwd) : resolveRepositoryLocalRoot(repository);
|
|
19579
|
+
const appDir = import_node_path30.default.resolve(repoRoot, dir);
|
|
19580
|
+
if (!(0, import_node_fs25.existsSync)(appDir)) throw new Error(`iOS app dir not found: ${appDir}`);
|
|
19370
19581
|
const explicit = options.project ?? options.workspace;
|
|
19371
|
-
const candidates = explicit ? [
|
|
19372
|
-
if (candidates.length !== 1 || !(0,
|
|
19582
|
+
const candidates = explicit ? [import_node_path30.default.resolve(appDir, explicit)] : (0, import_node_fs25.readdirSync)(appDir).filter((name) => /\.(xcodeproj|xcworkspace)$/.test(name)).map((name) => import_node_path30.default.join(appDir, name));
|
|
19583
|
+
if (candidates.length !== 1 || !(0, import_node_fs25.existsSync)(candidates[0])) throw new Error("Specify exactly one existing --project or --workspace; project discovery is ambiguous or empty");
|
|
19373
19584
|
const project = candidates[0];
|
|
19374
|
-
const expectedExtension = options.workspace ? ".xcworkspace" : options.project ? ".xcodeproj" :
|
|
19375
|
-
if (![".xcodeproj", ".xcworkspace"].includes(expectedExtension) ||
|
|
19376
|
-
const root = this.deps.stateRoot ??
|
|
19377
|
-
(0,
|
|
19378
|
-
const preflightLog =
|
|
19379
|
-
const
|
|
19380
|
-
await
|
|
19585
|
+
const expectedExtension = options.workspace ? ".xcworkspace" : options.project ? ".xcodeproj" : import_node_path30.default.extname(project);
|
|
19586
|
+
if (![".xcodeproj", ".xcworkspace"].includes(expectedExtension) || import_node_path30.default.extname(project) !== expectedExtension) throw new Error("Invalid Xcode project/workspace extension");
|
|
19587
|
+
const root = this.deps.stateRoot ?? import_node_path30.default.join(import_node_os14.default.homedir(), ".pmate", "ios-builds");
|
|
19588
|
+
(0, import_node_fs25.mkdirSync)(root, { recursive: true, mode: 448 });
|
|
19589
|
+
const preflightLog = import_node_path30.default.join(root, `preflight-${process.pid}-${Date.now()}.log`);
|
|
19590
|
+
const run2 = this.deps.run ?? runXcode;
|
|
19591
|
+
await run2(["-version"], appDir, preflightLog);
|
|
19381
19592
|
const common2 = [expectedExtension === ".xcworkspace" ? "-workspace" : "-project", project, "-scheme", options.scheme, "-configuration", "Release", "-destination", "generic/platform=iOS"];
|
|
19382
19593
|
if (options.team) common2.push(`DEVELOPMENT_TEAM=${options.team}`);
|
|
19383
|
-
const settings = JSON.parse(await
|
|
19594
|
+
const settings = JSON.parse(await run2([...common2, "-showBuildSettings", "-json"], appDir, preflightLog));
|
|
19384
19595
|
const apps = settings.filter((item) => item.buildSettings.PRODUCT_TYPE === "com.apple.product-type.application");
|
|
19385
19596
|
if (apps.length !== 1) throw new Error("Scheme must contain exactly one application target");
|
|
19386
19597
|
const cfg = apps[0].buildSettings;
|
|
@@ -19391,18 +19602,18 @@ var IosBuildService = class {
|
|
|
19391
19602
|
if (service.mobile && "bundleId" in service.mobile && service.mobile.bundleId !== bundleId) throw new Error("Service bundle ID does not match application target");
|
|
19392
19603
|
const currentBuild = iosBuildInteger(cfg.CURRENT_PROJECT_VERSION);
|
|
19393
19604
|
const key = (0, import_node_crypto8.createHash)("sha256").update(bundleId).digest("hex");
|
|
19394
|
-
const statePath =
|
|
19395
|
-
const lockPath =
|
|
19605
|
+
const statePath = import_node_path30.default.join(root, `${key}.json`);
|
|
19606
|
+
const lockPath = import_node_path30.default.join(root, `${key}.lock`);
|
|
19396
19607
|
let lock;
|
|
19397
19608
|
try {
|
|
19398
|
-
lock = (0,
|
|
19609
|
+
lock = (0, import_node_fs25.openSync)(lockPath, "wx", 384);
|
|
19399
19610
|
} catch (error) {
|
|
19400
19611
|
if (error.code === "EEXIST") throw new Error(`iOS build already locked: ${lockPath}. Remove only after confirming no build is running.`);
|
|
19401
19612
|
throw error;
|
|
19402
19613
|
}
|
|
19403
19614
|
try {
|
|
19404
|
-
(0,
|
|
19405
|
-
const previous = (0,
|
|
19615
|
+
(0, import_node_fs25.writeFileSync)(lock, JSON.stringify({ pid: process.pid, bundleId }));
|
|
19616
|
+
const previous = (0, import_node_fs25.existsSync)(statePath) ? JSON.parse((0, import_node_fs25.readFileSync)(statePath, "utf8")) : void 0;
|
|
19406
19617
|
if (previous && previous.bundleId !== bundleId) throw new Error("iOS build state bundle ID mismatch");
|
|
19407
19618
|
const buildsByVersion = { ...previous?.buildsByVersion };
|
|
19408
19619
|
if (previous) buildsByVersion[previous.version] = Math.max(buildsByVersion[previous.version] ?? 0, iosBuildInteger(previous.build));
|
|
@@ -19410,52 +19621,52 @@ var IosBuildService = class {
|
|
|
19410
19621
|
if (priorBuild === void 0 && options.lastBuild === void 0) throw new Error("First build for this marketing version requires --last-build <highest Apple build for this version>; use 0 only for a new version. Import again after external uploads or changing machines.");
|
|
19411
19622
|
const build = Math.max(currentBuild, priorBuild ?? 0, options.lastBuild ?? 0) + 1;
|
|
19412
19623
|
iosBuildInteger(build);
|
|
19413
|
-
const buildDir =
|
|
19414
|
-
(0,
|
|
19415
|
-
const archivePath =
|
|
19416
|
-
const logPath =
|
|
19624
|
+
const buildDir = import_node_path30.default.join(root, key, `${version}-${build}`);
|
|
19625
|
+
(0, import_node_fs25.mkdirSync)(buildDir, { recursive: true, mode: 448 });
|
|
19626
|
+
const archivePath = import_node_path30.default.join(buildDir, "App.xcarchive");
|
|
19627
|
+
const logPath = import_node_path30.default.join(buildDir, "build.log");
|
|
19417
19628
|
buildsByVersion[version] = build;
|
|
19418
19629
|
const state = { bundleId, version, build, buildsByVersion, status: "reserved", archivePath, logPath };
|
|
19419
19630
|
const persist = () => {
|
|
19420
19631
|
const temp = `${statePath}.${process.pid}.tmp`;
|
|
19421
|
-
(0,
|
|
19422
|
-
(0,
|
|
19632
|
+
(0, import_node_fs25.writeFileSync)(temp, JSON.stringify(state, null, 2) + "\n", { mode: 384 });
|
|
19633
|
+
(0, import_node_fs25.renameSync)(temp, statePath);
|
|
19423
19634
|
};
|
|
19424
19635
|
persist();
|
|
19425
|
-
(0,
|
|
19636
|
+
(0, import_node_fs25.writeFileSync)(logPath, `Service ${service.id}: ${bundleId} ${version} (${build})
|
|
19426
19637
|
Preflight log: ${preflightLog}
|
|
19427
19638
|
`, { mode: 384 });
|
|
19428
19639
|
try {
|
|
19429
|
-
await
|
|
19430
|
-
const applications =
|
|
19431
|
-
const builtApps = (0,
|
|
19640
|
+
await run2([...common2, `CURRENT_PROJECT_VERSION=${build}`, `MARKETING_VERSION=${version}`, "-archivePath", archivePath, "-derivedDataPath", import_node_path30.default.join(buildDir, "DerivedData"), "-allowProvisioningUpdates", "archive"], appDir, logPath);
|
|
19641
|
+
const applications = import_node_path30.default.join(archivePath, "Products", "Applications");
|
|
19642
|
+
const builtApps = (0, import_node_fs25.readdirSync)(applications).filter((name) => name.endsWith(".app"));
|
|
19432
19643
|
if (builtApps.length !== 1) throw new Error("Archive must contain exactly one application");
|
|
19433
|
-
const plist = (0,
|
|
19644
|
+
const plist = (0, import_node_fs25.readFileSync)(import_node_path30.default.join(applications, builtApps[0], "Info.plist"));
|
|
19434
19645
|
const info = await (this.deps.readPlist ?? readPlist)(plist);
|
|
19435
19646
|
if (info.CFBundleIdentifier !== bundleId || info.CFBundleShortVersionString !== version || String(info.CFBundleVersion) !== String(build)) throw new Error("Archive metadata does not match requested bundle, version and Build; upload stopped");
|
|
19436
|
-
const exportPlist =
|
|
19437
|
-
(0,
|
|
19438
|
-
await
|
|
19647
|
+
const exportPlist = import_node_path30.default.join(buildDir, "ExportOptions.plist");
|
|
19648
|
+
(0, import_node_fs25.writeFileSync)(exportPlist, `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>method</key><string>app-store-connect</string><key>destination</key><string>upload</string><key>teamID</key><string>${team}</string><key>signingStyle</key><string>automatic</string><key>manageAppVersionAndBuildNumber</key><false/><key>uploadSymbols</key><true/></dict></plist>`);
|
|
19649
|
+
await run2(["-exportArchive", "-archivePath", archivePath, "-exportOptionsPlist", exportPlist, "-exportPath", import_node_path30.default.join(buildDir, "export"), "-allowProvisioningUpdates"], appDir, logPath);
|
|
19439
19650
|
state.status = "uploaded-processing";
|
|
19440
19651
|
persist();
|
|
19441
19652
|
return { serviceId: service.id, bundleId, version, build, status: "uploaded-processing", archivePath, logPath };
|
|
19442
19653
|
} catch (error) {
|
|
19443
19654
|
state.status = "failed";
|
|
19444
19655
|
persist();
|
|
19445
|
-
(0,
|
|
19656
|
+
(0, import_node_fs25.appendFileSync)(logPath, `
|
|
19446
19657
|
${String(error)}
|
|
19447
19658
|
`);
|
|
19448
19659
|
throw new Error(`iOS Build ${build} failed; sequence reserved. See ${logPath}. ${String(error)}`);
|
|
19449
19660
|
}
|
|
19450
19661
|
} finally {
|
|
19451
|
-
(0,
|
|
19452
|
-
(0,
|
|
19662
|
+
(0, import_node_fs25.closeSync)(lock);
|
|
19663
|
+
(0, import_node_fs25.unlinkSync)(lockPath);
|
|
19453
19664
|
}
|
|
19454
19665
|
}
|
|
19455
19666
|
};
|
|
19456
19667
|
async function readPlist(input) {
|
|
19457
19668
|
return new Promise((resolve, reject) => {
|
|
19458
|
-
const child = (0,
|
|
19669
|
+
const child = (0, import_node_child_process14.spawn)("plutil", ["-convert", "json", "-o", "-", "--", "-"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
19459
19670
|
let output = "";
|
|
19460
19671
|
let error = "";
|
|
19461
19672
|
child.stdout.on("data", (chunk) => {
|
|
@@ -19501,9 +19712,9 @@ var NativeServiceDeploy = class {
|
|
|
19501
19712
|
const repository = service.repository ?? service.mobile?.repository;
|
|
19502
19713
|
const dir = service.dir ?? service.mobile?.dir;
|
|
19503
19714
|
if (!dir || !repository && !args.cwd) throw new Error("Native service requires repository and dir");
|
|
19504
|
-
const root = args.cwd ?
|
|
19505
|
-
const appDir =
|
|
19506
|
-
if (!(0,
|
|
19715
|
+
const root = args.cwd ? import_node_path31.default.resolve(args.cwd) : resolveRepositoryLocalRoot(repository);
|
|
19716
|
+
const appDir = import_node_path31.default.resolve(root, dir);
|
|
19717
|
+
if (!(0, import_node_fs26.existsSync)(appDir)) throw new Error(`Service source directory not found: ${appDir}`);
|
|
19507
19718
|
const settings = service.build ?? {};
|
|
19508
19719
|
if (service.type === "harmonyos") {
|
|
19509
19720
|
rejectNativeOverrides(args, ["dryRun", "local", "outDir"]);
|
|
@@ -19537,10 +19748,10 @@ var NativeServiceDeploy = class {
|
|
|
19537
19748
|
const options2 = {
|
|
19538
19749
|
id: app,
|
|
19539
19750
|
target: "electron",
|
|
19540
|
-
config: args.config ?
|
|
19751
|
+
config: args.config ? import_node_path31.default.resolve(args.config) : import_node_path31.default.resolve(appDir, settings.config ?? "desktop.config.json"),
|
|
19541
19752
|
platform: args.platform ?? settings.platform ?? (process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : process.platform),
|
|
19542
19753
|
arch: args.arch ?? settings.arch ?? process.arch,
|
|
19543
|
-
outDir: args.outDir ?
|
|
19754
|
+
outDir: args.outDir ? import_node_path31.default.resolve(args.outDir) : import_node_path31.default.join(root, "release", service.name),
|
|
19544
19755
|
signed: !args.unsigned,
|
|
19545
19756
|
dir: !!args.dir,
|
|
19546
19757
|
dryRun: !!args.dryRun,
|
|
@@ -19653,10 +19864,10 @@ async function requestDeveloperLogTool(tool, params, fetcher = fetch, delegate)
|
|
|
19653
19864
|
}
|
|
19654
19865
|
|
|
19655
19866
|
// src/services/ServiceRuntimeRunner.ts
|
|
19656
|
-
var
|
|
19657
|
-
var
|
|
19658
|
-
var
|
|
19659
|
-
var
|
|
19867
|
+
var import_node_fs27 = require("fs");
|
|
19868
|
+
var import_node_os15 = __toESM(require("os"));
|
|
19869
|
+
var import_node_path32 = __toESM(require("path"));
|
|
19870
|
+
var import_node_child_process15 = require("child_process");
|
|
19660
19871
|
var import_node_readline = require("readline");
|
|
19661
19872
|
var import_chalk3 = __toESM(require("chalk"));
|
|
19662
19873
|
var import_dotenv = require("dotenv");
|
|
@@ -20155,7 +20366,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20155
20366
|
}
|
|
20156
20367
|
resolveRepoRoot(service, cwd) {
|
|
20157
20368
|
if (cwd) {
|
|
20158
|
-
return
|
|
20369
|
+
return import_node_path32.default.resolve(process.cwd(), cwd);
|
|
20159
20370
|
}
|
|
20160
20371
|
const repository = this.getType(service) === "vite" || this.getType(service) === "static" ? this.getRepoStaticSite(service).repository.trim() : this.getType(service) === "fc" ? this.getFc(service).repository?.trim() : this.getType(service) === "ios" || this.getType(service) === "android" ? void 0 : this.getNetwork(service).repository?.trim();
|
|
20161
20372
|
if (repository) {
|
|
@@ -20163,8 +20374,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20163
20374
|
if (selected) return selected;
|
|
20164
20375
|
const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
|
|
20165
20376
|
if (repoName) {
|
|
20166
|
-
const candidate =
|
|
20167
|
-
if ((0,
|
|
20377
|
+
const candidate = import_node_path32.default.join(import_node_os15.default.homedir(), "dev", "pmate", repoName);
|
|
20378
|
+
if ((0, import_node_fs27.existsSync)(candidate)) {
|
|
20168
20379
|
return candidate;
|
|
20169
20380
|
}
|
|
20170
20381
|
}
|
|
@@ -20177,15 +20388,15 @@ var ServiceRuntimeRunner = class {
|
|
|
20177
20388
|
if (!dir) {
|
|
20178
20389
|
throw new Error(`Missing service dir for ${service.id}`);
|
|
20179
20390
|
}
|
|
20180
|
-
return
|
|
20391
|
+
return import_node_path32.default.resolve(repoRoot, dir);
|
|
20181
20392
|
}
|
|
20182
20393
|
async deployVite(service, options) {
|
|
20183
20394
|
this.assertDeployableStaticSite(service);
|
|
20184
20395
|
const repoRoot = this.resolveViteDeployRoot(service);
|
|
20185
20396
|
await this.checkoutViteMain(service, repoRoot);
|
|
20186
20397
|
const appDir = this.resolveLocalDir(service, repoRoot);
|
|
20187
|
-
const packageJsonPath =
|
|
20188
|
-
if (!(0,
|
|
20398
|
+
const packageJsonPath = import_node_path32.default.join(appDir, "package.json");
|
|
20399
|
+
if (!(0, import_node_fs27.existsSync)(packageJsonPath)) {
|
|
20189
20400
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20190
20401
|
}
|
|
20191
20402
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -20200,8 +20411,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20200
20411
|
repoRoot,
|
|
20201
20412
|
buildEnv
|
|
20202
20413
|
);
|
|
20203
|
-
const distDir =
|
|
20204
|
-
if (!(0,
|
|
20414
|
+
const distDir = import_node_path32.default.join(appDir, "dist");
|
|
20415
|
+
if (!(0, import_node_fs27.existsSync)(distDir)) {
|
|
20205
20416
|
throw new Error(`No dist directory found at ${distDir}`);
|
|
20206
20417
|
}
|
|
20207
20418
|
const site = this.getSite(service);
|
|
@@ -20216,7 +20427,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20216
20427
|
if (!/^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\/[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/.test(repository)) {
|
|
20217
20428
|
throw new Error(`Invalid repository: ${repository}; expected owner/name`);
|
|
20218
20429
|
}
|
|
20219
|
-
return
|
|
20430
|
+
return import_node_path32.default.join(import_node_os15.default.homedir(), ".pmate", "service-deploy", "repos", repository.toLowerCase());
|
|
20220
20431
|
}
|
|
20221
20432
|
async checkoutViteMain(service, repoRoot) {
|
|
20222
20433
|
const repository = this.getRepoStaticSite(service).repository;
|
|
@@ -20228,9 +20439,9 @@ var ServiceRuntimeRunner = class {
|
|
|
20228
20439
|
gitEnv.GIT_CONFIG_KEY_0 = "http.https://github.com/.extraheader";
|
|
20229
20440
|
gitEnv.GIT_CONFIG_VALUE_0 = `Authorization: Basic ${Buffer.from(`x-access-token:${token}`).toString("base64")}`;
|
|
20230
20441
|
}
|
|
20231
|
-
if (!(0,
|
|
20232
|
-
(0,
|
|
20233
|
-
await this.runCommandWithEnv("git", ["clone", "--branch", "main", "--single-branch", "--", repoUrl, repoRoot],
|
|
20442
|
+
if (!(0, import_node_fs27.existsSync)(repoRoot)) {
|
|
20443
|
+
(0, import_node_fs27.mkdirSync)(import_node_path32.default.dirname(repoRoot), { recursive: true });
|
|
20444
|
+
await this.runCommandWithEnv("git", ["clone", "--branch", "main", "--single-branch", "--", repoUrl, repoRoot], import_node_path32.default.dirname(repoRoot), gitEnv);
|
|
20234
20445
|
}
|
|
20235
20446
|
ui.info(`Deployment checkout: ${repoRoot}`);
|
|
20236
20447
|
ui.info(`Updating ${repository} to latest main for Vite deployment`);
|
|
@@ -20260,8 +20471,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20260
20471
|
async deployStatic(service, options) {
|
|
20261
20472
|
this.assertDeployableStaticSite(service);
|
|
20262
20473
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20263
|
-
const srcDir =
|
|
20264
|
-
if (!(0,
|
|
20474
|
+
const srcDir = import_node_path32.default.join(appDir, "src");
|
|
20475
|
+
if (!(0, import_node_fs27.existsSync)(srcDir)) {
|
|
20265
20476
|
throw new Error(`No src directory found at ${srcDir}`);
|
|
20266
20477
|
}
|
|
20267
20478
|
const site = this.getSite(service);
|
|
@@ -20295,8 +20506,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20295
20506
|
this.validateFcConfig(service, fc);
|
|
20296
20507
|
const repoRoot = this.resolveRepoRoot(service, options.cwd);
|
|
20297
20508
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20298
|
-
const packageJsonPath =
|
|
20299
|
-
if (!(0,
|
|
20509
|
+
const packageJsonPath = import_node_path32.default.join(appDir, "package.json");
|
|
20510
|
+
if (!(0, import_node_fs27.existsSync)(packageJsonPath)) {
|
|
20300
20511
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20301
20512
|
}
|
|
20302
20513
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -20349,15 +20560,15 @@ var ServiceRuntimeRunner = class {
|
|
|
20349
20560
|
const repoRoot = this.resolveRepoRoot(service, options.cwd);
|
|
20350
20561
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20351
20562
|
await this.ensurePnpmWorkspaceRoot(repoRoot);
|
|
20352
|
-
const configPath =
|
|
20353
|
-
if (!(0,
|
|
20563
|
+
const configPath = import_node_path32.default.join(appDir, fc.configFile ?? "s.yaml");
|
|
20564
|
+
if (!(0, import_node_fs27.existsSync)(configPath)) {
|
|
20354
20565
|
throw new Error(`Missing FC config file at ${configPath}`);
|
|
20355
20566
|
}
|
|
20356
|
-
const packageJsonPath =
|
|
20357
|
-
if (!(0,
|
|
20567
|
+
const packageJsonPath = import_node_path32.default.join(appDir, "package.json");
|
|
20568
|
+
if (!(0, import_node_fs27.existsSync)(packageJsonPath)) {
|
|
20358
20569
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20359
20570
|
}
|
|
20360
|
-
const rawConfig = (0,
|
|
20571
|
+
const rawConfig = (0, import_node_fs27.readFileSync)(configPath, "utf8");
|
|
20361
20572
|
if (!rawConfig.includes(fc.functionName)) {
|
|
20362
20573
|
throw new Error(`FC config ${configPath} does not mention functionName ${fc.functionName}`);
|
|
20363
20574
|
}
|
|
@@ -20647,7 +20858,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20647
20858
|
const serverAddress = await resolveServerAddress(server);
|
|
20648
20859
|
const templateName = exposeType === "websocket" ? "nginx.ws.template" : exposeType === "mixed" ? "nginx.mixed.template" : "nginx.rest.template";
|
|
20649
20860
|
const templatePath = this.resolveTemplatePath(templateName);
|
|
20650
|
-
const template = (0,
|
|
20861
|
+
const template = (0, import_node_fs27.readFileSync)(templatePath, "utf8");
|
|
20651
20862
|
const host = `${subdomain}.${("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat"}`;
|
|
20652
20863
|
const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
|
|
20653
20864
|
const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
|
|
@@ -20679,11 +20890,11 @@ var ServiceRuntimeRunner = class {
|
|
|
20679
20890
|
}
|
|
20680
20891
|
if (config.ensurePackageJson) {
|
|
20681
20892
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20682
|
-
const packageJsonPath =
|
|
20683
|
-
if (!(0,
|
|
20893
|
+
const packageJsonPath = import_node_path32.default.join(appDir, "package.json");
|
|
20894
|
+
if (!(0, import_node_fs27.existsSync)(packageJsonPath)) {
|
|
20684
20895
|
throw new Error(`Missing package.json at ${packageJsonPath}`);
|
|
20685
20896
|
}
|
|
20686
|
-
const pkgStat = (0,
|
|
20897
|
+
const pkgStat = (0, import_node_fs27.statSync)(packageJsonPath);
|
|
20687
20898
|
if (!pkgStat.isFile()) {
|
|
20688
20899
|
throw new Error(`package.json is not a file at ${packageJsonPath}`);
|
|
20689
20900
|
}
|
|
@@ -21094,13 +21305,13 @@ var ServiceRuntimeRunner = class {
|
|
|
21094
21305
|
return tokens;
|
|
21095
21306
|
}
|
|
21096
21307
|
readPathValue(source, pathExpr) {
|
|
21097
|
-
const
|
|
21308
|
+
const path37 = pathExpr.split(".").map((segment2) => segment2.trim()).filter(Boolean);
|
|
21098
21309
|
let cursor = source;
|
|
21099
|
-
for (const
|
|
21310
|
+
for (const segment2 of path37) {
|
|
21100
21311
|
if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
|
|
21101
21312
|
return void 0;
|
|
21102
21313
|
}
|
|
21103
|
-
cursor = cursor[
|
|
21314
|
+
cursor = cursor[segment2];
|
|
21104
21315
|
}
|
|
21105
21316
|
return cursor;
|
|
21106
21317
|
}
|
|
@@ -21139,12 +21350,12 @@ var ServiceRuntimeRunner = class {
|
|
|
21139
21350
|
}
|
|
21140
21351
|
resolveTemplatePath(templateName) {
|
|
21141
21352
|
const candidates = [
|
|
21142
|
-
|
|
21143
|
-
|
|
21144
|
-
|
|
21353
|
+
import_node_path32.default.join(__dirname, "..", "templates", templateName),
|
|
21354
|
+
import_node_path32.default.join(__dirname, "..", "src", "templates", templateName),
|
|
21355
|
+
import_node_path32.default.join(__dirname, "templates", templateName)
|
|
21145
21356
|
];
|
|
21146
21357
|
for (const candidate of candidates) {
|
|
21147
|
-
if ((0,
|
|
21358
|
+
if ((0, import_node_fs27.existsSync)(candidate)) {
|
|
21148
21359
|
return candidate;
|
|
21149
21360
|
}
|
|
21150
21361
|
}
|
|
@@ -21153,7 +21364,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21153
21364
|
writeRemoteConfig(server, content, remotePath) {
|
|
21154
21365
|
return new Promise((resolve, reject) => {
|
|
21155
21366
|
const target = `pmate@${server}`;
|
|
21156
|
-
const child = (0,
|
|
21367
|
+
const child = (0, import_node_child_process15.spawn)("ssh", [target, "sudo", "tee", remotePath], {
|
|
21157
21368
|
stdio: ["pipe", "inherit", "inherit"]
|
|
21158
21369
|
});
|
|
21159
21370
|
child.on("error", reject);
|
|
@@ -21168,7 +21379,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21168
21379
|
reloadNginx(server) {
|
|
21169
21380
|
return new Promise((resolve, reject) => {
|
|
21170
21381
|
const target = `pmate@${server}`;
|
|
21171
|
-
const child = (0,
|
|
21382
|
+
const child = (0, import_node_child_process15.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
21172
21383
|
stdio: ["ignore", "inherit", "inherit"]
|
|
21173
21384
|
});
|
|
21174
21385
|
child.on("error", reject);
|
|
@@ -21176,7 +21387,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21176
21387
|
});
|
|
21177
21388
|
}
|
|
21178
21389
|
loadPackageJson(packageJsonPath) {
|
|
21179
|
-
const raw = (0,
|
|
21390
|
+
const raw = (0, import_node_fs27.readFileSync)(packageJsonPath, "utf8");
|
|
21180
21391
|
const parsed = JSON.parse(raw);
|
|
21181
21392
|
if (!parsed || typeof parsed !== "object") {
|
|
21182
21393
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -21185,7 +21396,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21185
21396
|
}
|
|
21186
21397
|
writePackageJson(packageJsonPath, data) {
|
|
21187
21398
|
const serialized = JSON.stringify(data, null, 2);
|
|
21188
|
-
(0,
|
|
21399
|
+
(0, import_node_fs27.writeFileSync)(packageJsonPath, `${serialized}
|
|
21189
21400
|
`, "utf8");
|
|
21190
21401
|
}
|
|
21191
21402
|
validateFcConfig(service, fc) {
|
|
@@ -21212,8 +21423,8 @@ var ServiceRuntimeRunner = class {
|
|
|
21212
21423
|
}
|
|
21213
21424
|
}
|
|
21214
21425
|
async ensurePnpmWorkspaceRoot(repoRoot) {
|
|
21215
|
-
const workspacePath =
|
|
21216
|
-
if (!(0,
|
|
21426
|
+
const workspacePath = import_node_path32.default.join(repoRoot, "pnpm-workspace.yaml");
|
|
21427
|
+
if (!(0, import_node_fs27.existsSync)(workspacePath)) {
|
|
21217
21428
|
throw new Error(`Missing pnpm-workspace.yaml at ${workspacePath}`);
|
|
21218
21429
|
}
|
|
21219
21430
|
}
|
|
@@ -21287,16 +21498,16 @@ var ServiceRuntimeRunner = class {
|
|
|
21287
21498
|
if (!privateKeyPath) {
|
|
21288
21499
|
throw new Error("Missing ssl.prv in ~/.pmate/config.yaml.");
|
|
21289
21500
|
}
|
|
21290
|
-
if (!(0,
|
|
21501
|
+
if (!(0, import_node_fs27.existsSync)(certificatePath)) {
|
|
21291
21502
|
throw new Error(`SSL certificate file not found: ${certificatePath}`);
|
|
21292
21503
|
}
|
|
21293
|
-
if (!(0,
|
|
21504
|
+
if (!(0, import_node_fs27.existsSync)(privateKeyPath)) {
|
|
21294
21505
|
throw new Error(`SSL private key file not found: ${privateKeyPath}`);
|
|
21295
21506
|
}
|
|
21296
21507
|
return {
|
|
21297
21508
|
certName: host,
|
|
21298
|
-
certificate: (0,
|
|
21299
|
-
privateKey: (0,
|
|
21509
|
+
certificate: (0, import_node_fs27.readFileSync)(certificatePath, "utf8"),
|
|
21510
|
+
privateKey: (0, import_node_fs27.readFileSync)(privateKeyPath, "utf8")
|
|
21300
21511
|
};
|
|
21301
21512
|
}
|
|
21302
21513
|
resolveFcProtocol(fc, certConfig) {
|
|
@@ -21355,7 +21566,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21355
21566
|
}
|
|
21356
21567
|
runCommandWithEnv(command, args, cwd, env) {
|
|
21357
21568
|
return new Promise((resolve, reject) => {
|
|
21358
|
-
const child = (0,
|
|
21569
|
+
const child = (0, import_node_child_process15.spawn)(command, args, {
|
|
21359
21570
|
cwd,
|
|
21360
21571
|
stdio: "inherit",
|
|
21361
21572
|
env: { ...process.env, ...env ?? {} }
|
|
@@ -21366,7 +21577,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21366
21577
|
}
|
|
21367
21578
|
runShellCommand(command, cwd, env) {
|
|
21368
21579
|
return new Promise((resolve, reject) => {
|
|
21369
|
-
const child = (0,
|
|
21580
|
+
const child = (0, import_node_child_process15.spawn)(command, [], {
|
|
21370
21581
|
cwd,
|
|
21371
21582
|
stdio: "inherit",
|
|
21372
21583
|
shell: true,
|
|
@@ -21377,12 +21588,12 @@ var ServiceRuntimeRunner = class {
|
|
|
21377
21588
|
});
|
|
21378
21589
|
}
|
|
21379
21590
|
runRemoteCommand(server, command) {
|
|
21380
|
-
if (server === "local") return this.runCommandWithEnv("bash", ["-c", command],
|
|
21591
|
+
if (server === "local") return this.runCommandWithEnv("bash", ["-c", command], import_node_os15.default.homedir());
|
|
21381
21592
|
return new Promise((resolve, reject) => {
|
|
21382
21593
|
const target = `pmate@${server}`;
|
|
21383
|
-
const child = (0,
|
|
21594
|
+
const child = (0, import_node_child_process15.spawn)("ssh", [target, "bash -ls"], { stdio: ["pipe", "inherit", "inherit"] });
|
|
21384
21595
|
child.stdin.on("error", reject);
|
|
21385
|
-
child.stdin.end(`${command}
|
|
21596
|
+
child.stdin.end(`${remoteGitAuthorization(command, process.env.PMATE_DEPLOY_GIT_TOKEN)}
|
|
21386
21597
|
`);
|
|
21387
21598
|
child.on("error", reject);
|
|
21388
21599
|
child.on("close", (code) => code === 0 ? resolve() : reject(new Error(`ssh to ${server} exited with code ${code}`)));
|
|
@@ -21435,6 +21646,12 @@ function parseServiceRef(serviceId) {
|
|
|
21435
21646
|
}
|
|
21436
21647
|
return { namespace, name };
|
|
21437
21648
|
}
|
|
21649
|
+
function remoteGitAuthorization(command, token) {
|
|
21650
|
+
if (!token) return command;
|
|
21651
|
+
const header = "AUTHORIZATION: basic " + Buffer.from("x-access-token:" + token).toString("base64");
|
|
21652
|
+
const values = { GIT_CONFIG_COUNT: "3", GIT_CONFIG_KEY_0: "url.https://github.com/.insteadOf", GIT_CONFIG_VALUE_0: "git@github.com:", GIT_CONFIG_KEY_1: "url.https://github.com/.insteadOf", GIT_CONFIG_VALUE_1: "git@ramroll:", GIT_CONFIG_KEY_2: "http.https://github.com/.extraHeader", GIT_CONFIG_VALUE_2: header };
|
|
21653
|
+
return Object.entries(values).map(([key, value]) => "export " + key + "=" + shellQuote2(value)).join("\n") + "\n" + command;
|
|
21654
|
+
}
|
|
21438
21655
|
|
|
21439
21656
|
// src/commands/ServiceCommandHandler.ts
|
|
21440
21657
|
init_namespacedRef();
|
|
@@ -21770,7 +21987,7 @@ var ServiceCommandHandler = class {
|
|
|
21770
21987
|
format: "dotenv"
|
|
21771
21988
|
}
|
|
21772
21989
|
);
|
|
21773
|
-
const outputPath =
|
|
21990
|
+
const outputPath = import_node_path33.default.resolve(process.cwd(), args.output);
|
|
21774
21991
|
await (0, import_promises5.writeFile)(outputPath, payload.content, "utf8");
|
|
21775
21992
|
ui.success(`Wrote env file for ${args.appId} to ${outputPath}`);
|
|
21776
21993
|
this.renderJson({ ...payload, output: outputPath }, args.json);
|
|
@@ -21997,11 +22214,11 @@ var ServiceCommandHandler = class {
|
|
|
21997
22214
|
return (baseUrl2 || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
21998
22215
|
}
|
|
21999
22216
|
readJsonFile(filePath) {
|
|
22000
|
-
const absolutePath =
|
|
22001
|
-
if (!(0,
|
|
22217
|
+
const absolutePath = import_node_path33.default.resolve(process.cwd(), filePath);
|
|
22218
|
+
if (!(0, import_node_fs28.existsSync)(absolutePath)) {
|
|
22002
22219
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
22003
22220
|
}
|
|
22004
|
-
const raw = (0,
|
|
22221
|
+
const raw = (0, import_node_fs28.readFileSync)(absolutePath, "utf8");
|
|
22005
22222
|
try {
|
|
22006
22223
|
return JSON.parse(raw);
|
|
22007
22224
|
} catch (error) {
|
|
@@ -22525,7 +22742,7 @@ var ServiceCommandHandler = class {
|
|
|
22525
22742
|
removeRemoteConfig(server, remotePath) {
|
|
22526
22743
|
return new Promise((resolve, reject) => {
|
|
22527
22744
|
const target = `pmate@${server}`;
|
|
22528
|
-
const child = (0,
|
|
22745
|
+
const child = (0, import_node_child_process16.spawn)("ssh", [target, "sudo", "rm", "-f", remotePath], {
|
|
22529
22746
|
stdio: ["ignore", "inherit", "inherit"]
|
|
22530
22747
|
});
|
|
22531
22748
|
child.on("error", (error) => {
|
|
@@ -22543,7 +22760,7 @@ var ServiceCommandHandler = class {
|
|
|
22543
22760
|
reloadNginx(server) {
|
|
22544
22761
|
return new Promise((resolve, reject) => {
|
|
22545
22762
|
const target = `pmate@${server}`;
|
|
22546
|
-
const child = (0,
|
|
22763
|
+
const child = (0, import_node_child_process16.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
22547
22764
|
stdio: ["ignore", "inherit", "inherit"]
|
|
22548
22765
|
});
|
|
22549
22766
|
child.on("error", (error) => {
|
|
@@ -22616,9 +22833,9 @@ function sleep3(ms) {
|
|
|
22616
22833
|
}
|
|
22617
22834
|
|
|
22618
22835
|
// src/commands/VercelCommandHandler.ts
|
|
22619
|
-
var
|
|
22620
|
-
var
|
|
22621
|
-
var execFileAsync = (0,
|
|
22836
|
+
var import_node_child_process17 = require("child_process");
|
|
22837
|
+
var import_node_util2 = require("util");
|
|
22838
|
+
var execFileAsync = (0, import_node_util2.promisify)(import_node_child_process17.execFile);
|
|
22622
22839
|
function parseDeploymentTimestamp(deployment) {
|
|
22623
22840
|
const candidates = [deployment.createdAt, deployment.readyAt, deployment.ready];
|
|
22624
22841
|
for (const value of candidates) {
|
|
@@ -22727,8 +22944,8 @@ var RoleCommandHandler = class {
|
|
|
22727
22944
|
async handle(args) {
|
|
22728
22945
|
const token = readRequiredSession({ preferredApp: DEFAULT_APP_ID }).token;
|
|
22729
22946
|
const base = (args.baseUrl || process.env.PMATE_AUTH_API_BASE_URL || process.env.AUTH_API_BASE_URL || "https://auth-api-v2.pmate.chat").replace(/\/+$/, "");
|
|
22730
|
-
const request2 = async (method,
|
|
22731
|
-
const response = await fetch(base +
|
|
22947
|
+
const request2 = async (method, path37, body) => {
|
|
22948
|
+
const response = await fetch(base + path37, { method, redirect: "error", signal: AbortSignal.timeout(3e4), headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
|
|
22732
22949
|
const payload = await response.json().catch(() => null);
|
|
22733
22950
|
if (!response.ok || !payload?.success) throw new Error(payload?.message || `Request failed with status ${response.status}`);
|
|
22734
22951
|
return payload.data;
|
|
@@ -22762,9 +22979,9 @@ var RoleCommandHandler = class {
|
|
|
22762
22979
|
};
|
|
22763
22980
|
|
|
22764
22981
|
// src/commands/AccountCommandHandler.ts
|
|
22765
|
-
var
|
|
22982
|
+
var import_node_fs29 = require("fs");
|
|
22766
22983
|
var import_node_crypto9 = require("crypto");
|
|
22767
|
-
var
|
|
22984
|
+
var import_node_path34 = __toESM(require("path"));
|
|
22768
22985
|
init_sessionStore();
|
|
22769
22986
|
var AccountCommandHandler = class {
|
|
22770
22987
|
async handle(args) {
|
|
@@ -22772,9 +22989,9 @@ var AccountCommandHandler = class {
|
|
|
22772
22989
|
case "bot-keygen": {
|
|
22773
22990
|
const keyFile = this.generateBotKeyFile(args.app, args.name);
|
|
22774
22991
|
const outPath = args.out ? this.resolveFilePath(args.out) : this.resolveDefaultBotKeyPath(args.app, args.name);
|
|
22775
|
-
(0,
|
|
22776
|
-
(0,
|
|
22777
|
-
(0,
|
|
22992
|
+
(0, import_node_fs29.mkdirSync)(import_node_path34.default.dirname(outPath), { recursive: true });
|
|
22993
|
+
(0, import_node_fs29.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
22994
|
+
(0, import_node_fs29.chmodSync)(outPath, 384);
|
|
22778
22995
|
if (!args.json) {
|
|
22779
22996
|
ui.success(`Bot key saved to ${outPath}`);
|
|
22780
22997
|
}
|
|
@@ -23379,10 +23596,10 @@ var AccountCommandHandler = class {
|
|
|
23379
23596
|
throw new Error("Missing visible apps input");
|
|
23380
23597
|
}
|
|
23381
23598
|
const absolutePath = this.resolveFilePath(args.filePath);
|
|
23382
|
-
if (!(0,
|
|
23599
|
+
if (!(0, import_node_fs29.existsSync)(absolutePath)) {
|
|
23383
23600
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23384
23601
|
}
|
|
23385
|
-
const raw = (0,
|
|
23602
|
+
const raw = (0, import_node_fs29.readFileSync)(absolutePath, "utf8");
|
|
23386
23603
|
let parsed;
|
|
23387
23604
|
try {
|
|
23388
23605
|
parsed = JSON.parse(raw);
|
|
@@ -23396,13 +23613,13 @@ var AccountCommandHandler = class {
|
|
|
23396
23613
|
return parsed;
|
|
23397
23614
|
}
|
|
23398
23615
|
resolveFilePath(filePath) {
|
|
23399
|
-
return
|
|
23616
|
+
return import_node_path34.default.resolve(process.cwd(), filePath);
|
|
23400
23617
|
}
|
|
23401
23618
|
resolveDefaultBotKeyPath(app, name) {
|
|
23402
|
-
return
|
|
23619
|
+
return import_node_path34.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
|
|
23403
23620
|
}
|
|
23404
23621
|
resolveDefaultAccessKeyPath(app, name) {
|
|
23405
|
-
return
|
|
23622
|
+
return import_node_path34.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
|
|
23406
23623
|
}
|
|
23407
23624
|
homeDir() {
|
|
23408
23625
|
return process.env.HOME || process.env.USERPROFILE || process.cwd();
|
|
@@ -23422,14 +23639,14 @@ var AccountCommandHandler = class {
|
|
|
23422
23639
|
}
|
|
23423
23640
|
renameDefaultBotKeyFile(app, name, newName) {
|
|
23424
23641
|
const oldPath = this.resolveDefaultBotKeyPath(app, name);
|
|
23425
|
-
if (!(0,
|
|
23642
|
+
if (!(0, import_node_fs29.existsSync)(oldPath)) {
|
|
23426
23643
|
return void 0;
|
|
23427
23644
|
}
|
|
23428
23645
|
const keyFile = this.readBotKeyFile(oldPath, app, name);
|
|
23429
23646
|
const newPath = this.resolveDefaultBotKeyPath(app, newName);
|
|
23430
|
-
(0,
|
|
23431
|
-
(0,
|
|
23432
|
-
(0,
|
|
23647
|
+
(0, import_node_fs29.mkdirSync)(import_node_path34.default.dirname(newPath), { recursive: true, mode: 448 });
|
|
23648
|
+
(0, import_node_fs29.writeFileSync)(newPath, JSON.stringify({ ...keyFile, name: newName }, null, 2));
|
|
23649
|
+
(0, import_node_fs29.chmodSync)(newPath, 384);
|
|
23433
23650
|
return newPath;
|
|
23434
23651
|
}
|
|
23435
23652
|
readBotKeyFile(filePath, expectedApp, expectedName) {
|
|
@@ -23437,10 +23654,10 @@ var AccountCommandHandler = class {
|
|
|
23437
23654
|
throw new Error("Missing bot key file");
|
|
23438
23655
|
}
|
|
23439
23656
|
const absolutePath = this.resolveFilePath(filePath);
|
|
23440
|
-
if (!(0,
|
|
23657
|
+
if (!(0, import_node_fs29.existsSync)(absolutePath)) {
|
|
23441
23658
|
throw new Error(`Bot key file not found: ${absolutePath}`);
|
|
23442
23659
|
}
|
|
23443
|
-
const parsed = JSON.parse((0,
|
|
23660
|
+
const parsed = JSON.parse((0, import_node_fs29.readFileSync)(absolutePath, "utf8"));
|
|
23444
23661
|
if (parsed.type !== "pmate-bot-key" || parsed.version !== 1 || parsed.algorithm !== "ed25519" || !parsed.publicKey || !parsed.privateKey) {
|
|
23445
23662
|
throw new Error(`Invalid PMate bot key file: ${absolutePath}`);
|
|
23446
23663
|
}
|
|
@@ -23457,10 +23674,10 @@ var AccountCommandHandler = class {
|
|
|
23457
23674
|
throw new Error("Missing access key file");
|
|
23458
23675
|
}
|
|
23459
23676
|
const absolutePath = this.resolveFilePath(filePath);
|
|
23460
|
-
if (!(0,
|
|
23677
|
+
if (!(0, import_node_fs29.existsSync)(absolutePath)) {
|
|
23461
23678
|
throw new Error(`Access key file not found: ${absolutePath}`);
|
|
23462
23679
|
}
|
|
23463
|
-
const parsed = JSON.parse((0,
|
|
23680
|
+
const parsed = JSON.parse((0, import_node_fs29.readFileSync)(absolutePath, "utf8"));
|
|
23464
23681
|
if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
|
|
23465
23682
|
throw new Error(`Invalid PMate access key file: ${absolutePath}`);
|
|
23466
23683
|
}
|
|
@@ -23482,9 +23699,9 @@ var AccountCommandHandler = class {
|
|
|
23482
23699
|
createdAt: result.key.createdAt
|
|
23483
23700
|
};
|
|
23484
23701
|
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
|
|
23485
|
-
(0,
|
|
23486
|
-
(0,
|
|
23487
|
-
(0,
|
|
23702
|
+
(0, import_node_fs29.mkdirSync)(import_node_path34.default.dirname(outPath), { recursive: true });
|
|
23703
|
+
(0, import_node_fs29.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
23704
|
+
(0, import_node_fs29.chmodSync)(outPath, 384);
|
|
23488
23705
|
}
|
|
23489
23706
|
renderAccessKeyCreateResult(result, asJson, out) {
|
|
23490
23707
|
if (asJson) {
|
|
@@ -23565,12 +23782,12 @@ var AccountCommandHandler = class {
|
|
|
23565
23782
|
}
|
|
23566
23783
|
};
|
|
23567
23784
|
function encodePathSegment2(value) {
|
|
23568
|
-
return value.split("/").map((
|
|
23785
|
+
return value.split("/").map((segment2) => encodeURIComponent(segment2)).join("/");
|
|
23569
23786
|
}
|
|
23570
23787
|
|
|
23571
23788
|
// src/commands/OrgCommandHandler.ts
|
|
23572
|
-
var
|
|
23573
|
-
var
|
|
23789
|
+
var import_node_fs30 = require("fs");
|
|
23790
|
+
var import_node_path35 = __toESM(require("path"));
|
|
23574
23791
|
init_sessionStore();
|
|
23575
23792
|
var OrgCommandHandler = class {
|
|
23576
23793
|
async handle(args) {
|
|
@@ -23740,11 +23957,11 @@ var OrgCommandHandler = class {
|
|
|
23740
23957
|
if (!filePath) {
|
|
23741
23958
|
throw new Error(`Missing ${itemLabel} input`);
|
|
23742
23959
|
}
|
|
23743
|
-
const absolutePath =
|
|
23744
|
-
if (!(0,
|
|
23960
|
+
const absolutePath = import_node_path35.default.resolve(process.cwd(), filePath);
|
|
23961
|
+
if (!(0, import_node_fs30.existsSync)(absolutePath)) {
|
|
23745
23962
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23746
23963
|
}
|
|
23747
|
-
const raw = (0,
|
|
23964
|
+
const raw = (0, import_node_fs30.readFileSync)(absolutePath, "utf8");
|
|
23748
23965
|
let parsed;
|
|
23749
23966
|
try {
|
|
23750
23967
|
parsed = JSON.parse(raw);
|
|
@@ -23811,14 +24028,14 @@ var OrgCommandHandler = class {
|
|
|
23811
24028
|
}
|
|
23812
24029
|
};
|
|
23813
24030
|
function encodePathSegment3(value) {
|
|
23814
|
-
return value.split("/").map((
|
|
24031
|
+
return value.split("/").map((segment2) => encodeURIComponent(segment2)).join("/");
|
|
23815
24032
|
}
|
|
23816
24033
|
|
|
23817
24034
|
// src/commands/HostCommandHandler.ts
|
|
23818
|
-
var
|
|
23819
|
-
var
|
|
23820
|
-
var
|
|
23821
|
-
var
|
|
24035
|
+
var import_node_fs31 = require("fs");
|
|
24036
|
+
var import_node_os16 = require("os");
|
|
24037
|
+
var import_node_path36 = __toESM(require("path"));
|
|
24038
|
+
var import_node_child_process18 = require("child_process");
|
|
23822
24039
|
var BLOCK_START = "# >>> pmate host env >>>";
|
|
23823
24040
|
var BLOCK_END = "# <<< pmate host env <<<";
|
|
23824
24041
|
var PROFILE_BLOCK = `${BLOCK_START}
|
|
@@ -23830,7 +24047,7 @@ fi
|
|
|
23830
24047
|
${BLOCK_END}`;
|
|
23831
24048
|
var HostCommandHandler = class {
|
|
23832
24049
|
async handle(args) {
|
|
23833
|
-
const hostId = normalizeHostId(args.host ?? process.env.PMATE_HOST_ID ?? (0,
|
|
24050
|
+
const hostId = normalizeHostId(args.host ?? process.env.PMATE_HOST_ID ?? (0, import_node_os16.hostname)());
|
|
23834
24051
|
const client = new ServiceRegistryClient(args.baseUrl);
|
|
23835
24052
|
if (args.action === "env-list") {
|
|
23836
24053
|
const items = await client.listHostEnv(hostId);
|
|
@@ -23861,7 +24078,7 @@ async function applyHostEnvRemote(host, values) {
|
|
|
23861
24078
|
const content = serializeHostEnv(values);
|
|
23862
24079
|
const script = buildRemoteApplyScript(Buffer.from(content, "utf8").toString("base64"));
|
|
23863
24080
|
await new Promise((resolve, reject) => {
|
|
23864
|
-
const child = (0,
|
|
24081
|
+
const child = (0, import_node_child_process18.spawn)("ssh", [target, "bash -s"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
23865
24082
|
let stdout = "";
|
|
23866
24083
|
let stderr = "";
|
|
23867
24084
|
child.stdout.on("data", (chunk) => {
|
|
@@ -27039,7 +27256,7 @@ function requireValue10(tokens, option) {
|
|
|
27039
27256
|
|
|
27040
27257
|
// src/index.ts
|
|
27041
27258
|
var pkg = JSON.parse(
|
|
27042
|
-
(0,
|
|
27259
|
+
(0, import_node_fs32.readFileSync)(import_node_path37.default.resolve(__dirname, "..", "package.json"), "utf8")
|
|
27043
27260
|
);
|
|
27044
27261
|
var HELP_TEXT = [
|
|
27045
27262
|
import_chalk4.default.bold(`pmate v${pkg.version}`),
|
|
@@ -27211,6 +27428,7 @@ var HELP_TEXT = [
|
|
|
27211
27428
|
` ${import_chalk4.default.gray(" icon add <ns:objectId> <name> (--size <w>x<h>|--<w>x<h>) [--format <png|webp|svg|ico>] [--output <path>] [--force] [--base-url <url>] [--json]")}`,
|
|
27212
27429
|
` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
27213
27430
|
` ${import_chalk4.default.gray(" default base URL: https://apps-api.pmate.chat")}`,
|
|
27431
|
+
` ${import_chalk4.default.cyan("install")} Install or update a managed source package: pmate install <package>`,
|
|
27214
27432
|
` ${import_chalk4.default.cyan("service")} Manage service registry entries via apps-api`,
|
|
27215
27433
|
" deploy <ns:service> [--env prod] [--cwd <repo>] [--dry-run] [--local] [--unsigned] [--platform mac|win] [--arch arm64|x64] [--config <file>] [--out-dir <dir>] [--scheme <name>] [--team <id>] [--variant release|debug] [--bump patch|minor|major]",
|
|
27216
27434
|
` ${import_chalk4.default.gray(" list [--namespace <ns>] [--repo <owner/name|https://github.com/owner/name>] [--server <name>] [--base-url <url>] [--json]")}`,
|
|
@@ -27413,6 +27631,7 @@ function parseCommandArgs(args) {
|
|
|
27413
27631
|
if (args.rest[0] === "service") {
|
|
27414
27632
|
return parseServiceArgs(args.rest.slice(1));
|
|
27415
27633
|
}
|
|
27634
|
+
if (args.rest[0] === "install") return parseInstallArgs(args.rest.slice(1));
|
|
27416
27635
|
if (args.rest[0] === "host") {
|
|
27417
27636
|
return parseHostArgs(args.rest.slice(1));
|
|
27418
27637
|
}
|
|
@@ -28974,6 +29193,10 @@ async function main() {
|
|
|
28974
29193
|
}
|
|
28975
29194
|
const commandArgs = parseCommandArgs(args);
|
|
28976
29195
|
switch (commandArgs.type) {
|
|
29196
|
+
case "install" /* Install */: {
|
|
29197
|
+
await new PackageInstaller({ progress: (message) => ui.plain(message) }).install(commandArgs.package);
|
|
29198
|
+
return;
|
|
29199
|
+
}
|
|
28977
29200
|
case "list" /* List */: {
|
|
28978
29201
|
const handler = new ListCommandHandler();
|
|
28979
29202
|
handler.handle(commandArgs);
|