@pmate/cli 0.45.4 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -1
- package/dist/index.js +790 -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,216 @@ __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 metadata(name) {
|
|
8890
|
+
const ref = packageRef(name), url = this.ports.registryUrl ?? "https://apps-api.pmate.chat";
|
|
8891
|
+
const response = await (this.ports.fetch ?? fetch)(url + "/packages/" + ref.namespace + "/" + ref.name, { signal: AbortSignal.timeout(15e3), headers: { "cache-control": "no-cache" }, redirect: "error" });
|
|
8892
|
+
const body = await response.json();
|
|
8893
|
+
if (!response.ok || !body.success) throw Error(body.message ?? "Package registry unavailable");
|
|
8894
|
+
return validateInstallMetadata(body.data, ref.id);
|
|
8895
|
+
}
|
|
8896
|
+
async install(name) {
|
|
8897
|
+
const metadata = await this.metadata(name);
|
|
8898
|
+
if (!metadata.platforms.includes(this.ports.platform ?? process.platform)) throw Error("Package is not supported on this platform");
|
|
8899
|
+
(0, import_node_fs.mkdirSync)(this.directory, { recursive: true, mode: 448 });
|
|
8900
|
+
if ((0, import_node_fs.lstatSync)(this.directory).isSymbolicLink()) throw Error("Package directory must not be a symlink");
|
|
8901
|
+
const lock = import_node_path.default.join(this.directory, "install.lock");
|
|
8902
|
+
try {
|
|
8903
|
+
(0, import_node_fs.mkdirSync)(lock);
|
|
8904
|
+
(0, import_node_fs.writeFileSync)(import_node_path.default.join(lock, "pid"), String(process.pid));
|
|
8905
|
+
} catch {
|
|
8906
|
+
throw Error("Another package installation is running; inspect ~/.pmate/packages/install.lock");
|
|
8907
|
+
}
|
|
8908
|
+
try {
|
|
8909
|
+
return await this.installLocked(metadata);
|
|
8910
|
+
} finally {
|
|
8911
|
+
(0, import_node_fs.rmSync)(lock, { recursive: true, force: true });
|
|
8912
|
+
}
|
|
8913
|
+
}
|
|
8914
|
+
async installLocked(metadata) {
|
|
8915
|
+
const records = this.records(), old = records[metadata.id], root = import_node_path.default.join(this.directory, "repos", ...metadata.repository.split("/"));
|
|
8916
|
+
(0, import_node_fs.mkdirSync)(import_node_path.default.dirname(root), { recursive: true, mode: 448 });
|
|
8917
|
+
if (old && old.root !== root) throw Error("Installed repository location differs; migration required");
|
|
8918
|
+
if ((0, import_node_fs.existsSync)(root)) {
|
|
8919
|
+
if ((0, import_node_fs.lstatSync)(root).isSymbolicLink()) throw Error("Repository directory must not be a symlink");
|
|
8920
|
+
const remote = (await this.execute("git", ["remote", "get-url", "origin"], root)).replace(/\.git$/, "");
|
|
8921
|
+
if (!remote.endsWith("/" + metadata.repository) && !remote.endsWith(":" + metadata.repository)) throw Error("Installed repository origin differs");
|
|
8922
|
+
if (await this.execute("git", ["status", "--porcelain"], root)) throw Error("Installed repository contains local changes; preserve them before updating");
|
|
8923
|
+
}
|
|
8924
|
+
(0, import_node_fs.mkdirSync)(this.binDirectory, { recursive: true });
|
|
8925
|
+
for (const name of Object.keys(metadata.bins)) {
|
|
8926
|
+
const file = import_node_path.default.join(this.binDirectory, name), stat = (0, import_node_fs.lstatSync)(file, { throwIfNoEntry: false });
|
|
8927
|
+
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);
|
|
8928
|
+
}
|
|
8929
|
+
if (old?.version === metadata.version && (0, import_node_fs.existsSync)(root)) {
|
|
8930
|
+
const manifest = JSON.parse((0, import_node_fs.readFileSync)(this.local(root, import_node_path.default.posix.join(metadata.directory, metadata.manifest)), "utf8"));
|
|
8931
|
+
if (manifest.version !== old.version) throw Error("Installed manifest does not match the recorded version");
|
|
8932
|
+
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);
|
|
8933
|
+
this.say(metadata.id + " is already installed (" + metadata.version + ")");
|
|
8934
|
+
return { ...old, changed: false };
|
|
8935
|
+
}
|
|
8936
|
+
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");
|
|
8937
|
+
let wasRunning = false, stopped = false;
|
|
8938
|
+
if (old?.definition.lifecycle) {
|
|
8939
|
+
const lifecycle = old.definition.lifecycle, deadline = (this.ports.now ?? Date.now)() + 3e5;
|
|
8940
|
+
let drained = false;
|
|
8941
|
+
try {
|
|
8942
|
+
for (; ; ) {
|
|
8943
|
+
const status = JSON.parse(await this.step(root, lifecycle.status));
|
|
8944
|
+
wasRunning ||= status.running === true;
|
|
8945
|
+
if (!Number.isSafeInteger(status.activeRuns) || status.activeRuns < 0) throw Error("Invalid package lifecycle status");
|
|
8946
|
+
if (wasRunning && !drained && lifecycle.drain) {
|
|
8947
|
+
await this.step(root, lifecycle.drain);
|
|
8948
|
+
drained = true;
|
|
8949
|
+
}
|
|
8950
|
+
if (status.activeRuns === 0) break;
|
|
8951
|
+
if ((this.ports.now ?? Date.now)() >= deadline) throw Error("Active Runs have not finished; installation did not update the old package");
|
|
8952
|
+
this.say("Waiting for active Runs to finish");
|
|
8953
|
+
await (this.ports.wait ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(2e3);
|
|
8954
|
+
}
|
|
8955
|
+
if (wasRunning) {
|
|
8956
|
+
await this.step(root, lifecycle.stop);
|
|
8957
|
+
stopped = true;
|
|
8958
|
+
}
|
|
8959
|
+
} catch (error) {
|
|
8960
|
+
if (drained && !stopped) await this.step(root, lifecycle.start);
|
|
8961
|
+
throw error;
|
|
8962
|
+
}
|
|
8963
|
+
}
|
|
8964
|
+
const previousCommit = (0, import_node_fs.existsSync)(root) ? await this.execute("git", ["rev-parse", "HEAD"], root) : void 0;
|
|
8965
|
+
try {
|
|
8966
|
+
if (!(0, import_node_fs.existsSync)(root)) {
|
|
8967
|
+
this.say("Cloning " + metadata.repository);
|
|
8968
|
+
await this.execute("git", ["clone", "--branch", "main", "https://github.com/" + metadata.repository + ".git", root], import_node_path.default.dirname(root));
|
|
8969
|
+
} else {
|
|
8970
|
+
this.say("Updating " + metadata.repository);
|
|
8971
|
+
await this.execute("git", ["pull", "--ff-only", "origin", "main"], root);
|
|
8972
|
+
}
|
|
8973
|
+
const manifest = JSON.parse((0, import_node_fs.readFileSync)(this.local(root, import_node_path.default.posix.join(metadata.directory, metadata.manifest)), "utf8"));
|
|
8974
|
+
if (manifest.version !== metadata.version) throw Error("Repository component version does not match the published package version");
|
|
8975
|
+
for (const sibling of Object.values(records).filter((p) => p.root === root && p.id !== metadata.id)) {
|
|
8976
|
+
const manifest2 = JSON.parse((0, import_node_fs.readFileSync)(this.local(root, import_node_path.default.posix.join(sibling.directory, sibling.manifest)), "utf8"));
|
|
8977
|
+
if (manifest2.version !== sibling.version) throw Error("Shared repository also requires an update to " + sibling.id);
|
|
8978
|
+
}
|
|
8979
|
+
for (const step of metadata.prepare) {
|
|
8980
|
+
this.say("Preparing " + metadata.id + ": " + step.command);
|
|
8981
|
+
await this.step(root, step);
|
|
8982
|
+
}
|
|
8983
|
+
const bins = {};
|
|
8984
|
+
for (const [name, file] of Object.entries(metadata.bins)) {
|
|
8985
|
+
const target = this.local(root, file);
|
|
8986
|
+
if (!(0, import_node_fs.lstatSync)(target).isFile()) throw Error("Package bin is not a regular file");
|
|
8987
|
+
(0, import_node_fs.chmodSync)(target, 493);
|
|
8988
|
+
bins[name] = target;
|
|
8989
|
+
}
|
|
8990
|
+
const commit = await this.execute("git", ["rev-parse", "HEAD"], root);
|
|
8991
|
+
if (wasRunning && metadata.lifecycle) {
|
|
8992
|
+
await this.step(root, metadata.lifecycle.start);
|
|
8993
|
+
const health = JSON.parse(await this.step(root, metadata.lifecycle.health));
|
|
8994
|
+
if (health.healthy !== true) throw Error("Updated package failed its health check");
|
|
8995
|
+
}
|
|
8996
|
+
for (const [name, target] of Object.entries(bins)) {
|
|
8997
|
+
const link = import_node_path.default.join(this.binDirectory, name), temporary = link + ".install-" + process.pid;
|
|
8998
|
+
(0, import_node_fs.symlinkSync)(target, temporary);
|
|
8999
|
+
(0, import_node_fs.renameSync)(temporary, link);
|
|
9000
|
+
}
|
|
9001
|
+
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 };
|
|
9002
|
+
records[metadata.id] = record;
|
|
9003
|
+
this.save(records);
|
|
9004
|
+
this.say("Installed " + metadata.id + " " + metadata.version);
|
|
9005
|
+
return { ...record, changed: true };
|
|
9006
|
+
} catch (error) {
|
|
9007
|
+
if (stopped && old && previousCommit) {
|
|
9008
|
+
try {
|
|
9009
|
+
if (await this.execute("git", ["status", "--porcelain", "--untracked-files=no"], root)) throw Error("Failed upgrade changed tracked files");
|
|
9010
|
+
await this.execute("git", ["checkout", "--detach", previousCommit], root);
|
|
9011
|
+
for (const step of old.definition.prepare) await this.step(root, step);
|
|
9012
|
+
await this.step(root, old.definition.lifecycle.start);
|
|
9013
|
+
const health = JSON.parse(await this.step(root, old.definition.lifecycle.health));
|
|
9014
|
+
if (health.healthy !== true) throw Error("Previous package health check failed");
|
|
9015
|
+
this.say("Upgrade failed; restored the previously installed package " + old.version);
|
|
9016
|
+
} catch {
|
|
9017
|
+
this.say("Upgrade failed and automatic recovery could not complete. Previous commit: " + previousCommit + ". Credentials, data and the installation record were preserved.");
|
|
9018
|
+
}
|
|
9019
|
+
}
|
|
9020
|
+
throw error;
|
|
9021
|
+
}
|
|
9022
|
+
}
|
|
9023
|
+
};
|
|
9024
|
+
|
|
9025
|
+
// src/installCommandParser.ts
|
|
9026
|
+
function parseInstallArgs(args) {
|
|
9027
|
+
if (args.length !== 1 || !args[0] || args[0].startsWith("-")) throw Error("Usage: pmate install <package>");
|
|
9028
|
+
return { type: "install" /* Install */, package: args[0] };
|
|
9029
|
+
}
|
|
9030
|
+
|
|
9031
|
+
// src/managedSession.ts
|
|
9032
|
+
var import_node_fs2 = require("fs");
|
|
9033
|
+
var import_node_os2 = require("os");
|
|
8832
9034
|
var import_node_crypto = require("crypto");
|
|
8833
|
-
var
|
|
9035
|
+
var import_node_path2 = require("path");
|
|
8834
9036
|
async function ensureManagedSession(env = process.env, fetcher = fetch) {
|
|
8835
9037
|
if (env.PMATE_EXPECTED_ACCOUNT_ID && env.HEBO_MEMORY_TOKEN?.trim()) throw Error("Bound Agent CLI cannot use another delegated identity");
|
|
8836
9038
|
if (env.HEBO_MEMORY_TOKEN?.trim()) {
|
|
@@ -8843,19 +9045,19 @@ async function ensureManagedSession(env = process.env, fetcher = fetch) {
|
|
|
8843
9045
|
const pr = await fetcher(`${base}/profiles?app=${encodeURIComponent(app)}&account=${encodeURIComponent(session.identity.accountId)}`, { headers, signal: AbortSignal.timeout(15e3) });
|
|
8844
9046
|
const profiles = await pr.json(), profileId = profiles.data?.[0]?.id;
|
|
8845
9047
|
if (!pr.ok || !profiles.success || !profileId) throw Error("Delegated user profile unavailable");
|
|
8846
|
-
const dir = (0,
|
|
8847
|
-
(0,
|
|
9048
|
+
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");
|
|
9049
|
+
(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
9050
|
env.PMATE_SESSION_FILE = file;
|
|
8849
9051
|
env.PCS_AGENT_SESSION_MANAGED = "0";
|
|
8850
9052
|
process.once("exit", () => {
|
|
8851
|
-
(0,
|
|
9053
|
+
(0, import_node_fs2.rmSync)(dir, { recursive: true, force: true });
|
|
8852
9054
|
});
|
|
8853
9055
|
return;
|
|
8854
9056
|
}
|
|
8855
9057
|
if (env.PCS_AGENT_SESSION_MANAGED !== "1") return;
|
|
8856
9058
|
if (!env.PMATE_SESSION_FILE) throw Error("Managed session file is required");
|
|
8857
9059
|
const source = env.PCS_AGENT_SESSION_SOURCE_FILE ?? env.PMATE_SESSION_FILE;
|
|
8858
|
-
const state = JSON.parse((0,
|
|
9060
|
+
const state = JSON.parse((0, import_node_fs2.readFileSync)(source, "utf8"));
|
|
8859
9061
|
if (!state.refreshKey) throw Error("Managed session refresh key is missing");
|
|
8860
9062
|
const port = Number(env.PMATE_SESSION_REFRESH_PORT ?? env.PCS_AGENT_CONTROL_PORT ?? 39399);
|
|
8861
9063
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw Error("Invalid controller port");
|
|
@@ -8866,12 +9068,12 @@ async function ensureManagedSession(env = process.env, fetcher = fetch) {
|
|
|
8866
9068
|
});
|
|
8867
9069
|
if (!r.ok) throw Error(`Managed session renewal unavailable (${r.status}); retry later`);
|
|
8868
9070
|
if (source !== env.PMATE_SESSION_FILE) {
|
|
8869
|
-
const raw = (0,
|
|
9071
|
+
const raw = (0, import_node_fs2.readFileSync)(source, "utf8"), current = JSON.parse(raw).sessions?.[env.PMATE_SESSION_APP ?? "pmate:factory"];
|
|
8870
9072
|
if (env.PMATE_EXPECTED_ACCOUNT_ID && current?.accountId !== env.PMATE_EXPECTED_ACCOUNT_ID) throw Error("Renewed Agent CLI Account mismatch");
|
|
8871
9073
|
if (env.PMATE_EXPECTED_PROFILE_ID && current?.profileId !== env.PMATE_EXPECTED_PROFILE_ID) throw Error("Renewed Agent CLI Profile mismatch");
|
|
8872
9074
|
const temp = `${env.PMATE_SESSION_FILE}.${(0, import_node_crypto.randomUUID)()}.tmp`;
|
|
8873
|
-
(0,
|
|
8874
|
-
(0,
|
|
9075
|
+
(0, import_node_fs2.writeFileSync)(temp, raw, { mode: 384, flag: "wx" });
|
|
9076
|
+
(0, import_node_fs2.renameSync)(temp, env.PMATE_SESSION_FILE);
|
|
8875
9077
|
}
|
|
8876
9078
|
}
|
|
8877
9079
|
|
|
@@ -8918,12 +9120,12 @@ var ui = {
|
|
|
8918
9120
|
};
|
|
8919
9121
|
|
|
8920
9122
|
// src/commands/ListCommandHandler.ts
|
|
8921
|
-
var
|
|
9123
|
+
var import_node_path4 = __toESM(require("path"));
|
|
8922
9124
|
|
|
8923
9125
|
// src/config.ts
|
|
8924
|
-
var
|
|
8925
|
-
var
|
|
8926
|
-
var
|
|
9126
|
+
var import_node_fs3 = require("fs");
|
|
9127
|
+
var import_node_os3 = __toESM(require("os"));
|
|
9128
|
+
var import_node_path3 = __toESM(require("path"));
|
|
8927
9129
|
var import_ajv = __toESM(require("ajv"));
|
|
8928
9130
|
var import_yaml = __toESM(require("yaml"));
|
|
8929
9131
|
var cachedConfig;
|
|
@@ -9047,11 +9249,11 @@ function loadPmateConfig() {
|
|
|
9047
9249
|
if (cachedConfig !== void 0) {
|
|
9048
9250
|
return cachedConfig ?? {};
|
|
9049
9251
|
}
|
|
9050
|
-
const pmateDir =
|
|
9051
|
-
const yamlPath =
|
|
9252
|
+
const pmateDir = import_node_path3.default.join(import_node_os3.default.homedir(), ".pmate");
|
|
9253
|
+
const yamlPath = import_node_path3.default.join(pmateDir, "config.yaml");
|
|
9052
9254
|
let yamlConfig = null;
|
|
9053
|
-
if ((0,
|
|
9054
|
-
const raw = (0,
|
|
9255
|
+
if ((0, import_node_fs3.existsSync)(yamlPath)) {
|
|
9256
|
+
const raw = (0, import_node_fs3.readFileSync)(yamlPath, "utf8");
|
|
9055
9257
|
try {
|
|
9056
9258
|
const parsed = import_yaml.default.parse(raw);
|
|
9057
9259
|
yamlConfig = validateParsedConfig(parsed, yamlPath);
|
|
@@ -9113,21 +9315,21 @@ ${detail}`);
|
|
|
9113
9315
|
return value;
|
|
9114
9316
|
}
|
|
9115
9317
|
function findRepoConfigPaths(cwd, searchParents) {
|
|
9116
|
-
let current =
|
|
9318
|
+
let current = import_node_path3.default.resolve(cwd);
|
|
9117
9319
|
while (true) {
|
|
9118
|
-
const candidate =
|
|
9119
|
-
if ((0,
|
|
9120
|
-
const localCandidate =
|
|
9320
|
+
const candidate = import_node_path3.default.join(current, ".pmate.yaml");
|
|
9321
|
+
if ((0, import_node_fs3.existsSync)(candidate)) {
|
|
9322
|
+
const localCandidate = import_node_path3.default.join(current, ".pmate.local.yaml");
|
|
9121
9323
|
return {
|
|
9122
9324
|
rootDir: current,
|
|
9123
9325
|
configPath: candidate,
|
|
9124
|
-
localConfigPath: (0,
|
|
9326
|
+
localConfigPath: (0, import_node_fs3.existsSync)(localCandidate) ? localCandidate : void 0
|
|
9125
9327
|
};
|
|
9126
9328
|
}
|
|
9127
9329
|
if (!searchParents) {
|
|
9128
9330
|
return null;
|
|
9129
9331
|
}
|
|
9130
|
-
const parent =
|
|
9332
|
+
const parent = import_node_path3.default.dirname(current);
|
|
9131
9333
|
if (parent === current) {
|
|
9132
9334
|
return null;
|
|
9133
9335
|
}
|
|
@@ -9143,7 +9345,7 @@ function loadMergedRepoYaml(paths) {
|
|
|
9143
9345
|
return mergeRepoConfigValues(base, local);
|
|
9144
9346
|
}
|
|
9145
9347
|
function parseYamlFile(configPath) {
|
|
9146
|
-
const raw = (0,
|
|
9348
|
+
const raw = (0, import_node_fs3.readFileSync)(configPath, "utf8");
|
|
9147
9349
|
try {
|
|
9148
9350
|
return import_yaml.default.parse(raw);
|
|
9149
9351
|
} catch (error) {
|
|
@@ -9298,7 +9500,7 @@ var ListCommandHandler = class {
|
|
|
9298
9500
|
}
|
|
9299
9501
|
}
|
|
9300
9502
|
resolveTargetDir(targetPath) {
|
|
9301
|
-
return targetPath ?
|
|
9503
|
+
return targetPath ? import_node_path4.default.resolve(process.cwd(), targetPath) : process.cwd();
|
|
9302
9504
|
}
|
|
9303
9505
|
loadConfig(targetDir) {
|
|
9304
9506
|
return loadAppConfig(targetDir).config;
|
|
@@ -9306,23 +9508,23 @@ var ListCommandHandler = class {
|
|
|
9306
9508
|
};
|
|
9307
9509
|
|
|
9308
9510
|
// src/commands/LoginCommandHandler.ts
|
|
9309
|
-
var
|
|
9310
|
-
var
|
|
9511
|
+
var import_node_child_process2 = require("child_process");
|
|
9512
|
+
var import_node_path7 = __toESM(require("path"));
|
|
9311
9513
|
var import_node_http = require("http");
|
|
9312
9514
|
var import_promises = require("readline/promises");
|
|
9313
9515
|
|
|
9314
9516
|
// src/accessKeyFile.ts
|
|
9315
|
-
var
|
|
9316
|
-
var
|
|
9317
|
-
var
|
|
9517
|
+
var import_node_fs4 = require("fs");
|
|
9518
|
+
var import_node_os4 = __toESM(require("os"));
|
|
9519
|
+
var import_node_path5 = __toESM(require("path"));
|
|
9318
9520
|
function readAccessKeyFile(filePath, options = {}) {
|
|
9319
9521
|
const absolutePath = resolveFilePath(filePath, options.cwd);
|
|
9320
|
-
if (!(0,
|
|
9522
|
+
if (!(0, import_node_fs4.existsSync)(absolutePath)) {
|
|
9321
9523
|
throw new Error(`Access key file not found: ${absolutePath}`);
|
|
9322
9524
|
}
|
|
9323
9525
|
let parsed;
|
|
9324
9526
|
try {
|
|
9325
|
-
parsed = JSON.parse((0,
|
|
9527
|
+
parsed = JSON.parse((0, import_node_fs4.readFileSync)(absolutePath, "utf8"));
|
|
9326
9528
|
} catch (error) {
|
|
9327
9529
|
const message = error instanceof Error ? error.message : String(error);
|
|
9328
9530
|
throw new Error(`Invalid JSON in ${absolutePath}: ${message}`);
|
|
@@ -9339,10 +9541,10 @@ function readAccessKeyFile(filePath, options = {}) {
|
|
|
9339
9541
|
}
|
|
9340
9542
|
function scanAccessKeyFiles(app) {
|
|
9341
9543
|
const dir = resolveAccessKeyDir(app);
|
|
9342
|
-
if (!(0,
|
|
9544
|
+
if (!(0, import_node_fs4.existsSync)(dir)) {
|
|
9343
9545
|
return [];
|
|
9344
9546
|
}
|
|
9345
|
-
return (0,
|
|
9547
|
+
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
9548
|
try {
|
|
9347
9549
|
return [{ filePath, key: readAccessKeyFile(filePath, { expectedApp: app }) }];
|
|
9348
9550
|
} catch {
|
|
@@ -9351,13 +9553,13 @@ function scanAccessKeyFiles(app) {
|
|
|
9351
9553
|
}).sort((a, b) => a.key.name.localeCompare(b.key.name) || a.filePath.localeCompare(b.filePath));
|
|
9352
9554
|
}
|
|
9353
9555
|
function resolveAccessKeyDir(app) {
|
|
9354
|
-
return
|
|
9556
|
+
return import_node_path5.default.join(homeDir(), ".pmate", "access-keys", app);
|
|
9355
9557
|
}
|
|
9356
9558
|
function resolveFilePath(filePath, cwd = process.cwd()) {
|
|
9357
|
-
return
|
|
9559
|
+
return import_node_path5.default.isAbsolute(filePath) ? filePath : import_node_path5.default.resolve(cwd, filePath);
|
|
9358
9560
|
}
|
|
9359
9561
|
function homeDir() {
|
|
9360
|
-
return process.env.HOME || process.env.USERPROFILE ||
|
|
9562
|
+
return process.env.HOME || process.env.USERPROFILE || import_node_os4.default.homedir() || process.cwd();
|
|
9361
9563
|
}
|
|
9362
9564
|
function isAccessKeyFile(value) {
|
|
9363
9565
|
if (!value || typeof value !== "object") {
|
|
@@ -9658,7 +9860,7 @@ var LoginCommandHandler = class {
|
|
|
9658
9860
|
key.id?.trim(),
|
|
9659
9861
|
key.namespace?.trim(),
|
|
9660
9862
|
`expires ${key.expiresAt}`,
|
|
9661
|
-
|
|
9863
|
+
import_node_path7.default.relative(process.cwd(), candidate.filePath)
|
|
9662
9864
|
].filter(Boolean);
|
|
9663
9865
|
return parts.join(" / ");
|
|
9664
9866
|
}
|
|
@@ -9857,7 +10059,7 @@ var LoginCommandHandler = class {
|
|
|
9857
10059
|
const platform = process.platform;
|
|
9858
10060
|
const command = platform === "darwin" ? { cmd: "open", args: [url] } : platform === "win32" ? { cmd: "cmd", args: ["/c", "start", "", url] } : { cmd: "xdg-open", args: [url] };
|
|
9859
10061
|
try {
|
|
9860
|
-
const child = (0,
|
|
10062
|
+
const child = (0, import_node_child_process2.spawn)(command.cmd, command.args, {
|
|
9861
10063
|
detached: true,
|
|
9862
10064
|
stdio: "ignore"
|
|
9863
10065
|
});
|
|
@@ -9877,8 +10079,8 @@ var import_openapi_client = require("@alicloud/openapi-client");
|
|
|
9877
10079
|
var import_sts20150401 = __toESM(require("@alicloud/sts20150401"));
|
|
9878
10080
|
var import_ali_oss = __toESM(require("ali-oss"));
|
|
9879
10081
|
var import_node_crypto2 = require("crypto");
|
|
9880
|
-
var
|
|
9881
|
-
var
|
|
10082
|
+
var import_node_fs6 = require("fs");
|
|
10083
|
+
var import_node_path8 = __toESM(require("path"));
|
|
9882
10084
|
|
|
9883
10085
|
// src/certs.ts
|
|
9884
10086
|
var DEFAULT_SSL_CERT_KEY = "pmate-01";
|
|
@@ -10171,7 +10373,7 @@ var AliyunService = class {
|
|
|
10171
10373
|
])
|
|
10172
10374
|
);
|
|
10173
10375
|
for (const filePath of files) {
|
|
10174
|
-
const relativePath =
|
|
10376
|
+
const relativePath = import_node_path8.default.relative(localDir, filePath);
|
|
10175
10377
|
const objectKey = this.toObjectKey(normalizedPrefix, relativePath);
|
|
10176
10378
|
const contentType = this.getContentType(filePath);
|
|
10177
10379
|
const cacheControl = this.getStaticAssetCacheControl(relativePath);
|
|
@@ -10181,7 +10383,7 @@ var AliyunService = class {
|
|
|
10181
10383
|
const options = Object.keys(headers).length > 0 ? { headers } : void 0;
|
|
10182
10384
|
const existing = existingMap.get(objectKey);
|
|
10183
10385
|
if (existing && typeof existing.size === "number" && !cacheControl) {
|
|
10184
|
-
const stat = await
|
|
10386
|
+
const stat = await import_node_fs6.promises.stat(filePath);
|
|
10185
10387
|
if (stat.size === existing.size) {
|
|
10186
10388
|
const etag = this.normalizeEtag(existing.etag);
|
|
10187
10389
|
if (etag && !etag.includes("-")) {
|
|
@@ -10206,7 +10408,7 @@ var AliyunService = class {
|
|
|
10206
10408
|
if (!region) throw new Error("Missing oss.public.region in ~/.pmate/config.yaml.");
|
|
10207
10409
|
if (!accessKeyId) throw new Error("Missing aliyun.ak in ~/.pmate/config.yaml.");
|
|
10208
10410
|
if (!accessKeySecret) throw new Error("Missing aliyun.sk in ~/.pmate/config.yaml.");
|
|
10209
|
-
if (!(0,
|
|
10411
|
+
if (!(0, import_node_fs6.existsSync)(localFile)) {
|
|
10210
10412
|
throw new Error(`File not found: ${localFile}`);
|
|
10211
10413
|
}
|
|
10212
10414
|
const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 });
|
|
@@ -10596,10 +10798,10 @@ var AliyunService = class {
|
|
|
10596
10798
|
}
|
|
10597
10799
|
/** Recursively collect file paths under a directory. */
|
|
10598
10800
|
static async collectFiles(dir) {
|
|
10599
|
-
const entries = await
|
|
10801
|
+
const entries = await import_node_fs6.promises.readdir(dir, { withFileTypes: true });
|
|
10600
10802
|
const files = [];
|
|
10601
10803
|
for (const entry of entries) {
|
|
10602
|
-
const fullPath =
|
|
10804
|
+
const fullPath = import_node_path8.default.join(dir, entry.name);
|
|
10603
10805
|
if (entry.isDirectory()) {
|
|
10604
10806
|
files.push(...await this.collectFiles(fullPath));
|
|
10605
10807
|
} else if (entry.isFile()) {
|
|
@@ -10648,7 +10850,7 @@ var AliyunService = class {
|
|
|
10648
10850
|
static getFileMd5(filePath) {
|
|
10649
10851
|
return new Promise((resolve, reject) => {
|
|
10650
10852
|
const hash = (0, import_node_crypto2.createHash)("md5");
|
|
10651
|
-
const stream = (0,
|
|
10853
|
+
const stream = (0, import_node_fs6.createReadStream)(filePath);
|
|
10652
10854
|
stream.on("data", (chunk) => {
|
|
10653
10855
|
hash.update(chunk);
|
|
10654
10856
|
});
|
|
@@ -10661,17 +10863,17 @@ var AliyunService = class {
|
|
|
10661
10863
|
});
|
|
10662
10864
|
}
|
|
10663
10865
|
static toObjectKey(prefix, relativePath) {
|
|
10664
|
-
const normalizedPath = relativePath.split(
|
|
10866
|
+
const normalizedPath = relativePath.split(import_node_path8.default.sep).join("/");
|
|
10665
10867
|
if (!prefix) {
|
|
10666
10868
|
return normalizedPath;
|
|
10667
10869
|
}
|
|
10668
10870
|
return `${prefix}/${normalizedPath}`;
|
|
10669
10871
|
}
|
|
10670
10872
|
static getContentType(filePath) {
|
|
10671
|
-
if (
|
|
10873
|
+
if (import_node_path8.default.basename(filePath).toLowerCase() === "apple-app-site-association") {
|
|
10672
10874
|
return "application/json";
|
|
10673
10875
|
}
|
|
10674
|
-
const ext =
|
|
10876
|
+
const ext = import_node_path8.default.extname(filePath).toLowerCase();
|
|
10675
10877
|
switch (ext) {
|
|
10676
10878
|
case ".html":
|
|
10677
10879
|
return "text/html";
|
|
@@ -10714,7 +10916,7 @@ var AliyunService = class {
|
|
|
10714
10916
|
}
|
|
10715
10917
|
static getStaticAssetCacheControl(filePath) {
|
|
10716
10918
|
const normalized = filePath.replace(/\\/g, "/");
|
|
10717
|
-
const base =
|
|
10919
|
+
const base = import_node_path8.default.posix.basename(normalized).toLowerCase();
|
|
10718
10920
|
if (base === "index.html" || base === "200.html" || base === "404.html" || base === "latest.json" || base === "apple-app-site-association") {
|
|
10719
10921
|
return "no-cache, no-store, must-revalidate";
|
|
10720
10922
|
}
|
|
@@ -10931,8 +11133,8 @@ var BucketCommandHandler = class {
|
|
|
10931
11133
|
};
|
|
10932
11134
|
|
|
10933
11135
|
// src/commands/DeleteCommandHandler.ts
|
|
10934
|
-
var
|
|
10935
|
-
var
|
|
11136
|
+
var import_node_path9 = __toESM(require("path"));
|
|
11137
|
+
var import_node_child_process3 = require("child_process");
|
|
10936
11138
|
|
|
10937
11139
|
// src/serverAddress.ts
|
|
10938
11140
|
var import_promises2 = require("dns/promises");
|
|
@@ -11055,7 +11257,7 @@ var DeleteCommandHandler = class {
|
|
|
11055
11257
|
removeRemoteConfig(server, remotePath) {
|
|
11056
11258
|
return new Promise((resolve, reject) => {
|
|
11057
11259
|
const target = `pmate@${server}`;
|
|
11058
|
-
const child = (0,
|
|
11260
|
+
const child = (0, import_node_child_process3.spawn)("ssh", [target, "sudo", "rm", "-f", remotePath], {
|
|
11059
11261
|
stdio: ["ignore", "inherit", "inherit"]
|
|
11060
11262
|
});
|
|
11061
11263
|
child.on("error", (error) => {
|
|
@@ -11073,7 +11275,7 @@ var DeleteCommandHandler = class {
|
|
|
11073
11275
|
reloadNginx(server) {
|
|
11074
11276
|
return new Promise((resolve, reject) => {
|
|
11075
11277
|
const target = `pmate@${server}`;
|
|
11076
|
-
const child = (0,
|
|
11278
|
+
const child = (0, import_node_child_process3.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
11077
11279
|
stdio: ["ignore", "inherit", "inherit"]
|
|
11078
11280
|
});
|
|
11079
11281
|
child.on("error", (error) => {
|
|
@@ -11089,17 +11291,17 @@ var DeleteCommandHandler = class {
|
|
|
11089
11291
|
});
|
|
11090
11292
|
}
|
|
11091
11293
|
resolveCwd(target) {
|
|
11092
|
-
return target ?
|
|
11294
|
+
return target ? import_node_path9.default.resolve(process.cwd(), target) : process.cwd();
|
|
11093
11295
|
}
|
|
11094
11296
|
};
|
|
11095
11297
|
|
|
11096
11298
|
// src/commands/DevCommandHandler.ts
|
|
11097
|
-
var
|
|
11098
|
-
var
|
|
11099
|
-
var
|
|
11299
|
+
var import_node_fs7 = require("fs");
|
|
11300
|
+
var import_node_path11 = __toESM(require("path"));
|
|
11301
|
+
var import_node_child_process4 = require("child_process");
|
|
11100
11302
|
|
|
11101
11303
|
// src/appDir.ts
|
|
11102
|
-
var
|
|
11304
|
+
var import_node_path10 = __toESM(require("path"));
|
|
11103
11305
|
function normalizeRelativeDir(input, appName) {
|
|
11104
11306
|
if (typeof input !== "string") {
|
|
11105
11307
|
throw new Error(`Missing dir for ${appName} in .pmate.yaml`);
|
|
@@ -11112,7 +11314,7 @@ function normalizeRelativeDir(input, appName) {
|
|
|
11112
11314
|
if (unixLike.startsWith("/")) {
|
|
11113
11315
|
throw new Error(`Invalid dir for ${appName} in .pmate.yaml: must be relative`);
|
|
11114
11316
|
}
|
|
11115
|
-
const normalized =
|
|
11317
|
+
const normalized = import_node_path10.default.posix.normalize(unixLike);
|
|
11116
11318
|
if (normalized.startsWith("../") || normalized === "..") {
|
|
11117
11319
|
throw new Error(
|
|
11118
11320
|
`Invalid dir for ${appName} in .pmate.yaml: must stay within repo`
|
|
@@ -11121,8 +11323,8 @@ function normalizeRelativeDir(input, appName) {
|
|
|
11121
11323
|
return normalized;
|
|
11122
11324
|
}
|
|
11123
11325
|
function resolveLocalAppDir(repoRoot, appName, dir) {
|
|
11124
|
-
const
|
|
11125
|
-
return
|
|
11326
|
+
const relative2 = normalizeRelativeDir(dir, appName);
|
|
11327
|
+
return import_node_path10.default.resolve(repoRoot, relative2);
|
|
11126
11328
|
}
|
|
11127
11329
|
function resolveRemoteAppDir(appName, dir) {
|
|
11128
11330
|
return normalizeRelativeDir(dir, appName);
|
|
@@ -11145,8 +11347,8 @@ var DevCommandHandler = class {
|
|
|
11145
11347
|
);
|
|
11146
11348
|
}
|
|
11147
11349
|
const appDir = resolveLocalAppDir(cwd, appName, appConfig.dir);
|
|
11148
|
-
const packageJsonPath =
|
|
11149
|
-
if (!(0,
|
|
11350
|
+
const packageJsonPath = import_node_path11.default.join(appDir, "package.json");
|
|
11351
|
+
if (!(0, import_node_fs7.existsSync)(packageJsonPath)) {
|
|
11150
11352
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
11151
11353
|
}
|
|
11152
11354
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -11160,13 +11362,13 @@ var DevCommandHandler = class {
|
|
|
11160
11362
|
await this.runCommand("pnpm", ["--filter", pkgName, "run", "dev"], cwd);
|
|
11161
11363
|
}
|
|
11162
11364
|
resolveCwd(target) {
|
|
11163
|
-
return target ?
|
|
11365
|
+
return target ? import_node_path11.default.resolve(process.cwd(), target) : process.cwd();
|
|
11164
11366
|
}
|
|
11165
11367
|
loadConfig(cwd) {
|
|
11166
11368
|
return loadAppConfig(cwd);
|
|
11167
11369
|
}
|
|
11168
11370
|
loadPackageJson(packageJsonPath) {
|
|
11169
|
-
const raw = (0,
|
|
11371
|
+
const raw = (0, import_node_fs7.readFileSync)(packageJsonPath, "utf8");
|
|
11170
11372
|
const parsed = JSON.parse(raw);
|
|
11171
11373
|
if (!parsed || typeof parsed !== "object") {
|
|
11172
11374
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -11175,7 +11377,7 @@ var DevCommandHandler = class {
|
|
|
11175
11377
|
}
|
|
11176
11378
|
runCommand(command, args, cwd) {
|
|
11177
11379
|
return new Promise((resolve, reject) => {
|
|
11178
|
-
const child = (0,
|
|
11380
|
+
const child = (0, import_node_child_process4.spawn)(command, args, {
|
|
11179
11381
|
cwd,
|
|
11180
11382
|
stdio: "inherit"
|
|
11181
11383
|
});
|
|
@@ -11194,8 +11396,8 @@ var DevCommandHandler = class {
|
|
|
11194
11396
|
};
|
|
11195
11397
|
|
|
11196
11398
|
// src/commands/OssCommandHandler.ts
|
|
11197
|
-
var
|
|
11198
|
-
var
|
|
11399
|
+
var import_node_fs8 = require("fs");
|
|
11400
|
+
var import_node_path12 = __toESM(require("path"));
|
|
11199
11401
|
var PARROT_STATIC_PUBLIC_BASE_URL = "https://parrot-static.pmate.chat";
|
|
11200
11402
|
var OssCommandHandler = class _OssCommandHandler {
|
|
11201
11403
|
static {
|
|
@@ -11213,7 +11415,7 @@ var OssCommandHandler = class _OssCommandHandler {
|
|
|
11213
11415
|
}
|
|
11214
11416
|
return;
|
|
11215
11417
|
}
|
|
11216
|
-
const resolvedFile =
|
|
11418
|
+
const resolvedFile = import_node_path12.default.resolve(process.cwd(), args.filePath);
|
|
11217
11419
|
this.assertFile(resolvedFile);
|
|
11218
11420
|
const objectKey = this.normalizeObjectKey(args.objectKey);
|
|
11219
11421
|
const bucket2 = this.resolveBucket(args.bucket);
|
|
@@ -11224,10 +11426,10 @@ var OssCommandHandler = class _OssCommandHandler {
|
|
|
11224
11426
|
}
|
|
11225
11427
|
}
|
|
11226
11428
|
assertFile(filePath) {
|
|
11227
|
-
if (!(0,
|
|
11429
|
+
if (!(0, import_node_fs8.existsSync)(filePath)) {
|
|
11228
11430
|
throw new Error(`File not found: ${filePath}`);
|
|
11229
11431
|
}
|
|
11230
|
-
const stat = (0,
|
|
11432
|
+
const stat = (0, import_node_fs8.statSync)(filePath);
|
|
11231
11433
|
if (!stat.isFile()) {
|
|
11232
11434
|
throw new Error(`Not a file: ${filePath}`);
|
|
11233
11435
|
}
|
|
@@ -11249,13 +11451,13 @@ var OssCommandHandler = class _OssCommandHandler {
|
|
|
11249
11451
|
};
|
|
11250
11452
|
function buildOssPublicUrl(bucket2, objectKey) {
|
|
11251
11453
|
if (bucket2 !== "parrot-static") return null;
|
|
11252
|
-
const encodedKey = objectKey.split("/").map((
|
|
11454
|
+
const encodedKey = objectKey.split("/").map((segment2) => encodeURIComponent(segment2)).join("/");
|
|
11253
11455
|
return `${PARROT_STATIC_PUBLIC_BASE_URL}/${encodedKey}`;
|
|
11254
11456
|
}
|
|
11255
11457
|
|
|
11256
11458
|
// src/commands/EnvCommandHandler.ts
|
|
11257
|
-
var
|
|
11258
|
-
var
|
|
11459
|
+
var import_node_path13 = __toESM(require("path"));
|
|
11460
|
+
var import_node_child_process5 = require("child_process");
|
|
11259
11461
|
|
|
11260
11462
|
// src/shell.ts
|
|
11261
11463
|
function quoteForBash(command) {
|
|
@@ -11338,8 +11540,8 @@ var EnvCommandHandler = class {
|
|
|
11338
11540
|
ui.success(`Set ${envKey} in .env.local`, appName);
|
|
11339
11541
|
}
|
|
11340
11542
|
async listEnvKeys(server, repoDir, appDir, verbose) {
|
|
11341
|
-
const envLocalPath =
|
|
11342
|
-
const envPath =
|
|
11543
|
+
const envLocalPath = import_node_path13.default.posix.join(appDir, ".env.local");
|
|
11544
|
+
const envPath = import_node_path13.default.posix.join(appDir, ".env");
|
|
11343
11545
|
if (verbose) {
|
|
11344
11546
|
const repoPath = `$HOME/${repoDir}`;
|
|
11345
11547
|
ui.info("Env list target", {
|
|
@@ -11432,8 +11634,8 @@ var EnvCommandHandler = class {
|
|
|
11432
11634
|
}
|
|
11433
11635
|
}
|
|
11434
11636
|
async appendEnvLine(server, repoDir, appDir, envKey, envLine, verbose) {
|
|
11435
|
-
const envLocalPath =
|
|
11436
|
-
const envPath =
|
|
11637
|
+
const envLocalPath = import_node_path13.default.posix.join(appDir, ".env.local");
|
|
11638
|
+
const envPath = import_node_path13.default.posix.join(appDir, ".env");
|
|
11437
11639
|
if (verbose) {
|
|
11438
11640
|
const repoPath = `$HOME/${repoDir}`;
|
|
11439
11641
|
ui.info("Env add target", {
|
|
@@ -11481,8 +11683,8 @@ var EnvCommandHandler = class {
|
|
|
11481
11683
|
await this.runRemoteCommand(server, command);
|
|
11482
11684
|
}
|
|
11483
11685
|
async deleteEnvKey(server, repoDir, appDir, envKey, verbose) {
|
|
11484
|
-
const envLocalPath =
|
|
11485
|
-
const envPath =
|
|
11686
|
+
const envLocalPath = import_node_path13.default.posix.join(appDir, ".env.local");
|
|
11687
|
+
const envPath = import_node_path13.default.posix.join(appDir, ".env");
|
|
11486
11688
|
if (verbose) {
|
|
11487
11689
|
const repoPath = `$HOME/${repoDir}`;
|
|
11488
11690
|
ui.info("Env delete target", {
|
|
@@ -11552,7 +11754,7 @@ var EnvCommandHandler = class {
|
|
|
11552
11754
|
runRemoteCommand(server, command) {
|
|
11553
11755
|
return new Promise((resolve, reject) => {
|
|
11554
11756
|
const target = `pmate@${server}`;
|
|
11555
|
-
const child = (0,
|
|
11757
|
+
const child = (0, import_node_child_process5.spawn)("ssh", buildSshBashArgs(target, command), {
|
|
11556
11758
|
stdio: "inherit"
|
|
11557
11759
|
});
|
|
11558
11760
|
child.on("error", (error) => {
|
|
@@ -11570,7 +11772,7 @@ var EnvCommandHandler = class {
|
|
|
11570
11772
|
runRemoteCommandCapture(server, command) {
|
|
11571
11773
|
return new Promise((resolve, reject) => {
|
|
11572
11774
|
const target = `pmate@${server}`;
|
|
11573
|
-
const child = (0,
|
|
11775
|
+
const child = (0, import_node_child_process5.spawn)("ssh", buildSshBashArgs(target, command), {
|
|
11574
11776
|
stdio: ["ignore", "pipe", "pipe"]
|
|
11575
11777
|
});
|
|
11576
11778
|
let output = "";
|
|
@@ -11619,7 +11821,7 @@ function formatEnvValue(value) {
|
|
|
11619
11821
|
}
|
|
11620
11822
|
|
|
11621
11823
|
// src/commands/PrCommandHandler.ts
|
|
11622
|
-
var
|
|
11824
|
+
var import_node_child_process6 = require("child_process");
|
|
11623
11825
|
var PrCommandHandler = class {
|
|
11624
11826
|
constructor(cwd = process.cwd()) {
|
|
11625
11827
|
this.cwd = cwd;
|
|
@@ -12089,7 +12291,7 @@ ${lines}`;
|
|
|
12089
12291
|
}
|
|
12090
12292
|
run(command, args, quietError = false, env, cwd) {
|
|
12091
12293
|
return new Promise((resolve, reject) => {
|
|
12092
|
-
const child = (0,
|
|
12294
|
+
const child = (0, import_node_child_process6.spawn)(command, args, {
|
|
12093
12295
|
stdio: quietError ? "ignore" : "inherit",
|
|
12094
12296
|
env: env ?? process.env,
|
|
12095
12297
|
cwd: cwd ?? this.cwd
|
|
@@ -12108,7 +12310,7 @@ ${lines}`;
|
|
|
12108
12310
|
}
|
|
12109
12311
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
12110
12312
|
return new Promise((resolve, reject) => {
|
|
12111
|
-
const child = (0,
|
|
12313
|
+
const child = (0, import_node_child_process6.spawn)(command, args, {
|
|
12112
12314
|
stdio: ["ignore", "pipe", "pipe"],
|
|
12113
12315
|
env: env ?? process.env,
|
|
12114
12316
|
cwd: cwd ?? this.cwd
|
|
@@ -12249,8 +12451,8 @@ var CommitCommandHandler = class {
|
|
|
12249
12451
|
};
|
|
12250
12452
|
|
|
12251
12453
|
// src/commands/SummaryCommandHandler.ts
|
|
12252
|
-
var
|
|
12253
|
-
var
|
|
12454
|
+
var import_node_child_process7 = require("child_process");
|
|
12455
|
+
var import_node_path14 = __toESM(require("path"));
|
|
12254
12456
|
var SummaryCommandHandler = class {
|
|
12255
12457
|
async handle(args) {
|
|
12256
12458
|
const cwd = this.resolveCwd(args.cwd);
|
|
@@ -12358,7 +12560,7 @@ var SummaryCommandHandler = class {
|
|
|
12358
12560
|
}
|
|
12359
12561
|
run(command, args, quietError = false, env, cwd) {
|
|
12360
12562
|
return new Promise((resolve, reject) => {
|
|
12361
|
-
const child = (0,
|
|
12563
|
+
const child = (0, import_node_child_process7.spawn)(command, args, {
|
|
12362
12564
|
stdio: quietError ? "ignore" : "inherit",
|
|
12363
12565
|
env: env ?? process.env,
|
|
12364
12566
|
cwd
|
|
@@ -12377,7 +12579,7 @@ var SummaryCommandHandler = class {
|
|
|
12377
12579
|
}
|
|
12378
12580
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
12379
12581
|
return new Promise((resolve, reject) => {
|
|
12380
|
-
const child = (0,
|
|
12582
|
+
const child = (0, import_node_child_process7.spawn)(command, args, {
|
|
12381
12583
|
stdio: ["ignore", "pipe", "pipe"],
|
|
12382
12584
|
env: env ?? process.env,
|
|
12383
12585
|
cwd
|
|
@@ -12435,7 +12637,7 @@ var SummaryCommandHandler = class {
|
|
|
12435
12637
|
return this.runCapture("gh", args, allowFailure, await this.getGhEnv(cwd), cwd);
|
|
12436
12638
|
}
|
|
12437
12639
|
resolveCwd(value) {
|
|
12438
|
-
return value ?
|
|
12640
|
+
return value ? import_node_path14.default.resolve(process.cwd(), value) : process.cwd();
|
|
12439
12641
|
}
|
|
12440
12642
|
};
|
|
12441
12643
|
function truncate2(value, limit) {
|
|
@@ -12447,10 +12649,10 @@ function truncate2(value, limit) {
|
|
|
12447
12649
|
}
|
|
12448
12650
|
|
|
12449
12651
|
// src/commands/LinearCommandHandler.ts
|
|
12450
|
-
var
|
|
12451
|
-
var
|
|
12452
|
-
var
|
|
12453
|
-
var
|
|
12652
|
+
var import_node_child_process8 = require("child_process");
|
|
12653
|
+
var import_node_fs9 = require("fs");
|
|
12654
|
+
var import_node_os6 = __toESM(require("os"));
|
|
12655
|
+
var import_node_path15 = __toESM(require("path"));
|
|
12454
12656
|
var import_promises3 = require("readline/promises");
|
|
12455
12657
|
var import_openai = __toESM(require("openai"));
|
|
12456
12658
|
var import_sdk = require("@linear/sdk");
|
|
@@ -13334,15 +13536,15 @@ var LinearCommandHandler = class {
|
|
|
13334
13536
|
}
|
|
13335
13537
|
}
|
|
13336
13538
|
getLinearSelectionPath() {
|
|
13337
|
-
return
|
|
13539
|
+
return import_node_path15.default.join(import_node_os6.default.homedir(), ".pmate", "linear-selection.json");
|
|
13338
13540
|
}
|
|
13339
13541
|
readCachedLinearSelection(cwd) {
|
|
13340
13542
|
const selectionPath = this.getLinearSelectionPath();
|
|
13341
|
-
if (!(0,
|
|
13543
|
+
if (!(0, import_node_fs9.existsSync)(selectionPath)) {
|
|
13342
13544
|
return void 0;
|
|
13343
13545
|
}
|
|
13344
13546
|
try {
|
|
13345
|
-
const raw = (0,
|
|
13547
|
+
const raw = (0, import_node_fs9.readFileSync)(selectionPath, "utf8").trim();
|
|
13346
13548
|
if (!raw) return void 0;
|
|
13347
13549
|
const parsed = JSON.parse(raw);
|
|
13348
13550
|
const value = parsed[cwd];
|
|
@@ -13353,12 +13555,12 @@ var LinearCommandHandler = class {
|
|
|
13353
13555
|
}
|
|
13354
13556
|
writeCachedLinearSelection(cwd, title) {
|
|
13355
13557
|
const selectionPath = this.getLinearSelectionPath();
|
|
13356
|
-
const dir =
|
|
13357
|
-
(0,
|
|
13558
|
+
const dir = import_node_path15.default.dirname(selectionPath);
|
|
13559
|
+
(0, import_node_fs9.mkdirSync)(dir, { recursive: true });
|
|
13358
13560
|
let data = {};
|
|
13359
|
-
if ((0,
|
|
13561
|
+
if ((0, import_node_fs9.existsSync)(selectionPath)) {
|
|
13360
13562
|
try {
|
|
13361
|
-
const raw = (0,
|
|
13563
|
+
const raw = (0, import_node_fs9.readFileSync)(selectionPath, "utf8").trim();
|
|
13362
13564
|
if (raw) {
|
|
13363
13565
|
data = JSON.parse(raw);
|
|
13364
13566
|
}
|
|
@@ -13367,7 +13569,7 @@ var LinearCommandHandler = class {
|
|
|
13367
13569
|
}
|
|
13368
13570
|
}
|
|
13369
13571
|
data[cwd] = title;
|
|
13370
|
-
(0,
|
|
13572
|
+
(0, import_node_fs9.writeFileSync)(selectionPath, `${JSON.stringify(data, null, 2)}
|
|
13371
13573
|
`, "utf8");
|
|
13372
13574
|
}
|
|
13373
13575
|
async lookupIssue(client, issueRef) {
|
|
@@ -13544,14 +13746,14 @@ var LinearCommandHandler = class {
|
|
|
13544
13746
|
if (process.platform !== "darwin") {
|
|
13545
13747
|
throw new Error("Screenshot capture only supports macOS.");
|
|
13546
13748
|
}
|
|
13547
|
-
const dir = await
|
|
13548
|
-
const filePath =
|
|
13749
|
+
const dir = await import_node_fs9.promises.mkdtemp(import_node_path15.default.join(import_node_os6.default.tmpdir(), "pmate-screenshot-"));
|
|
13750
|
+
const filePath = import_node_path15.default.join(dir, `screenshot-${index}.png`);
|
|
13549
13751
|
try {
|
|
13550
13752
|
const code = await this.run("screencapture", ["-i", "-x", filePath], true);
|
|
13551
13753
|
if (code !== 0) {
|
|
13552
13754
|
throw new Error("Screenshot capture canceled or failed.");
|
|
13553
13755
|
}
|
|
13554
|
-
const buffer = await
|
|
13756
|
+
const buffer = await import_node_fs9.promises.readFile(filePath);
|
|
13555
13757
|
if (buffer.length === 0) {
|
|
13556
13758
|
throw new Error("Screenshot capture produced an empty file.");
|
|
13557
13759
|
}
|
|
@@ -13563,7 +13765,7 @@ var LinearCommandHandler = class {
|
|
|
13563
13765
|
return { buffer, mime, filename: `screenshot-${index}.${extension}` };
|
|
13564
13766
|
} finally {
|
|
13565
13767
|
try {
|
|
13566
|
-
await
|
|
13768
|
+
await import_node_fs9.promises.rm(dir, { recursive: true, force: true });
|
|
13567
13769
|
} catch {
|
|
13568
13770
|
}
|
|
13569
13771
|
}
|
|
@@ -13707,17 +13909,17 @@ var LinearCommandHandler = class {
|
|
|
13707
13909
|
return compact.length > limit ? `${compact.slice(0, limit)}...` : compact;
|
|
13708
13910
|
}
|
|
13709
13911
|
async convertToPng(buffer, ext) {
|
|
13710
|
-
const dir = await
|
|
13711
|
-
const inputPath =
|
|
13712
|
-
const outputPath =
|
|
13912
|
+
const dir = await import_node_fs9.promises.mkdtemp(import_node_path15.default.join(import_node_os6.default.tmpdir(), "pmate-"));
|
|
13913
|
+
const inputPath = import_node_path15.default.join(dir, `clipboard.${ext}`);
|
|
13914
|
+
const outputPath = import_node_path15.default.join(dir, "clipboard.png");
|
|
13713
13915
|
try {
|
|
13714
|
-
await
|
|
13916
|
+
await import_node_fs9.promises.writeFile(inputPath, buffer);
|
|
13715
13917
|
const stderr = await this.runCapture(
|
|
13716
13918
|
"sips",
|
|
13717
13919
|
["-s", "format", "png", inputPath, "--out", outputPath],
|
|
13718
13920
|
true
|
|
13719
13921
|
);
|
|
13720
|
-
const out = await
|
|
13922
|
+
const out = await import_node_fs9.promises.readFile(outputPath);
|
|
13721
13923
|
if (this.detectImageMime(out) !== "image/png") {
|
|
13722
13924
|
throw new Error(
|
|
13723
13925
|
stderr?.trim() ? `Failed to convert clipboard ${ext} to PNG: ${stderr.trim()}` : `Failed to convert clipboard ${ext} to PNG.`
|
|
@@ -13726,14 +13928,14 @@ var LinearCommandHandler = class {
|
|
|
13726
13928
|
return out;
|
|
13727
13929
|
} finally {
|
|
13728
13930
|
try {
|
|
13729
|
-
await
|
|
13931
|
+
await import_node_fs9.promises.rm(dir, { recursive: true, force: true });
|
|
13730
13932
|
} catch {
|
|
13731
13933
|
}
|
|
13732
13934
|
}
|
|
13733
13935
|
}
|
|
13734
13936
|
captureClipboard(preferred) {
|
|
13735
13937
|
return new Promise((resolve, reject) => {
|
|
13736
|
-
const child = (0,
|
|
13938
|
+
const child = (0, import_node_child_process8.spawn)("pbpaste", ["-Prefer", preferred], {
|
|
13737
13939
|
stdio: ["ignore", "pipe", "pipe"]
|
|
13738
13940
|
});
|
|
13739
13941
|
const chunks = [];
|
|
@@ -13943,7 +14145,7 @@ var LinearCommandHandler = class {
|
|
|
13943
14145
|
}
|
|
13944
14146
|
run(command, args, quietError = false, env, cwd) {
|
|
13945
14147
|
return new Promise((resolve, reject) => {
|
|
13946
|
-
const child = (0,
|
|
14148
|
+
const child = (0, import_node_child_process8.spawn)(command, args, {
|
|
13947
14149
|
stdio: quietError ? "ignore" : "inherit",
|
|
13948
14150
|
env: env ?? process.env,
|
|
13949
14151
|
cwd
|
|
@@ -13962,7 +14164,7 @@ var LinearCommandHandler = class {
|
|
|
13962
14164
|
}
|
|
13963
14165
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
13964
14166
|
return new Promise((resolve, reject) => {
|
|
13965
|
-
const child = (0,
|
|
14167
|
+
const child = (0, import_node_child_process8.spawn)(command, args, {
|
|
13966
14168
|
stdio: ["ignore", "pipe", "pipe"],
|
|
13967
14169
|
env: env ?? process.env,
|
|
13968
14170
|
cwd
|
|
@@ -14020,7 +14222,7 @@ var LinearCommandHandler = class {
|
|
|
14020
14222
|
return this.runCapture("gh", args, allowFailure, await this.getGhEnv(cwd), cwd);
|
|
14021
14223
|
}
|
|
14022
14224
|
resolveCwd(value) {
|
|
14023
|
-
return value ?
|
|
14225
|
+
return value ? import_node_path15.default.resolve(process.cwd(), value) : process.cwd();
|
|
14024
14226
|
}
|
|
14025
14227
|
createOpenAiClient() {
|
|
14026
14228
|
const config = loadPmateConfig();
|
|
@@ -14072,8 +14274,8 @@ function sleep2(ms) {
|
|
|
14072
14274
|
}
|
|
14073
14275
|
|
|
14074
14276
|
// src/commands/NotionCommandHandler.ts
|
|
14075
|
-
var
|
|
14076
|
-
var
|
|
14277
|
+
var import_node_fs10 = require("fs");
|
|
14278
|
+
var import_node_path16 = __toESM(require("path"));
|
|
14077
14279
|
|
|
14078
14280
|
// src/services/NotionService.ts
|
|
14079
14281
|
var NotionService = class {
|
|
@@ -14312,9 +14514,9 @@ ${indent}\`\`\``;
|
|
|
14312
14514
|
static richTextToPlain(richText) {
|
|
14313
14515
|
return richText.map((item) => item.plain_text ?? item.text?.content ?? "").join("").trim();
|
|
14314
14516
|
}
|
|
14315
|
-
static async requestJson(
|
|
14517
|
+
static async requestJson(path37, init) {
|
|
14316
14518
|
const token = this.getToken();
|
|
14317
|
-
const response = await fetch(`${this.baseUrl}${
|
|
14519
|
+
const response = await fetch(`${this.baseUrl}${path37}`, {
|
|
14318
14520
|
method: init.method,
|
|
14319
14521
|
headers: {
|
|
14320
14522
|
Authorization: `Bearer ${token}`,
|
|
@@ -14412,16 +14614,16 @@ var NotionCommandHandler = class {
|
|
|
14412
14614
|
if (!args.filePath) {
|
|
14413
14615
|
return "";
|
|
14414
14616
|
}
|
|
14415
|
-
const resolved =
|
|
14416
|
-
return (0,
|
|
14617
|
+
const resolved = import_node_path16.default.resolve(process.cwd(), args.filePath);
|
|
14618
|
+
return (0, import_node_fs10.readFileSync)(resolved, "utf8");
|
|
14417
14619
|
}
|
|
14418
14620
|
};
|
|
14419
14621
|
|
|
14420
14622
|
// src/commands/QrcodeCommandHandler.ts
|
|
14421
|
-
var
|
|
14422
|
-
var
|
|
14423
|
-
var
|
|
14424
|
-
var
|
|
14623
|
+
var import_node_child_process9 = require("child_process");
|
|
14624
|
+
var import_node_fs11 = require("fs");
|
|
14625
|
+
var import_node_os7 = __toESM(require("os"));
|
|
14626
|
+
var import_node_path17 = __toESM(require("path"));
|
|
14425
14627
|
var import_promises4 = require("readline/promises");
|
|
14426
14628
|
var import_jsqr = __toESM(require("jsqr"));
|
|
14427
14629
|
var import_pngjs = require("pngjs");
|
|
@@ -14447,7 +14649,7 @@ var QrcodeCommandHandler = class {
|
|
|
14447
14649
|
ui.success("QR code value:", value);
|
|
14448
14650
|
} finally {
|
|
14449
14651
|
try {
|
|
14450
|
-
await
|
|
14652
|
+
await import_node_fs11.promises.rm(dir, { recursive: true, force: true });
|
|
14451
14653
|
} catch {
|
|
14452
14654
|
}
|
|
14453
14655
|
}
|
|
@@ -14463,13 +14665,13 @@ var QrcodeCommandHandler = class {
|
|
|
14463
14665
|
} finally {
|
|
14464
14666
|
rl.close();
|
|
14465
14667
|
}
|
|
14466
|
-
const dir = await
|
|
14467
|
-
const filePath =
|
|
14668
|
+
const dir = await import_node_fs11.promises.mkdtemp(import_node_path17.default.join(import_node_os7.default.tmpdir(), "pmate-qrcode-"));
|
|
14669
|
+
const filePath = import_node_path17.default.join(dir, "qrcode.png");
|
|
14468
14670
|
const code = await this.run("screencapture", ["-i", "-x", filePath], true);
|
|
14469
14671
|
if (code !== 0) {
|
|
14470
14672
|
throw new Error("Screenshot capture canceled or failed.");
|
|
14471
14673
|
}
|
|
14472
|
-
const buffer = await
|
|
14674
|
+
const buffer = await import_node_fs11.promises.readFile(filePath);
|
|
14473
14675
|
if (buffer.length === 0) {
|
|
14474
14676
|
throw new Error("Screenshot capture produced an empty file.");
|
|
14475
14677
|
}
|
|
@@ -14485,7 +14687,7 @@ var QrcodeCommandHandler = class {
|
|
|
14485
14687
|
async decodeQr(filePath) {
|
|
14486
14688
|
let buffer;
|
|
14487
14689
|
try {
|
|
14488
|
-
buffer = await
|
|
14690
|
+
buffer = await import_node_fs11.promises.readFile(filePath);
|
|
14489
14691
|
} catch {
|
|
14490
14692
|
return null;
|
|
14491
14693
|
}
|
|
@@ -14526,7 +14728,7 @@ var QrcodeCommandHandler = class {
|
|
|
14526
14728
|
}
|
|
14527
14729
|
run(command, args, quietError = false, env, cwd) {
|
|
14528
14730
|
return new Promise((resolve, reject) => {
|
|
14529
|
-
const child = (0,
|
|
14731
|
+
const child = (0, import_node_child_process9.spawn)(command, args, {
|
|
14530
14732
|
stdio: quietError ? "ignore" : "inherit",
|
|
14531
14733
|
env: env ?? process.env,
|
|
14532
14734
|
cwd
|
|
@@ -14743,8 +14945,8 @@ function clampNumber(value, min, max, fallback) {
|
|
|
14743
14945
|
}
|
|
14744
14946
|
|
|
14745
14947
|
// src/commands/QuizCommandHandler.ts
|
|
14746
|
-
var
|
|
14747
|
-
var
|
|
14948
|
+
var import_node_fs12 = require("fs");
|
|
14949
|
+
var import_node_path18 = __toESM(require("path"));
|
|
14748
14950
|
init_sessionStore();
|
|
14749
14951
|
|
|
14750
14952
|
// src/services/QuizService.ts
|
|
@@ -15289,8 +15491,8 @@ var QuizCommandHandler = class {
|
|
|
15289
15491
|
return;
|
|
15290
15492
|
}
|
|
15291
15493
|
if (args.action === "update-meta") {
|
|
15292
|
-
const resolvedFilePath =
|
|
15293
|
-
const metadata = JSON.parse((0,
|
|
15494
|
+
const resolvedFilePath = import_node_path18.default.resolve(process.cwd(), args.filePath);
|
|
15495
|
+
const metadata = JSON.parse((0, import_node_fs12.readFileSync)(resolvedFilePath, "utf8"));
|
|
15294
15496
|
const result = await updateQuizPaperMetadata({
|
|
15295
15497
|
apiBaseUrl,
|
|
15296
15498
|
linkBaseUrl,
|
|
@@ -15302,8 +15504,8 @@ var QuizCommandHandler = class {
|
|
|
15302
15504
|
return;
|
|
15303
15505
|
}
|
|
15304
15506
|
if (args.action === "append-step") {
|
|
15305
|
-
const resolvedFilePath =
|
|
15306
|
-
const step = JSON.parse((0,
|
|
15507
|
+
const resolvedFilePath = import_node_path18.default.resolve(process.cwd(), args.filePath);
|
|
15508
|
+
const step = JSON.parse((0, import_node_fs12.readFileSync)(resolvedFilePath, "utf8"));
|
|
15307
15509
|
const result = await appendQuizPaperStep({
|
|
15308
15510
|
apiBaseUrl,
|
|
15309
15511
|
linkBaseUrl,
|
|
@@ -15316,8 +15518,8 @@ var QuizCommandHandler = class {
|
|
|
15316
15518
|
return;
|
|
15317
15519
|
}
|
|
15318
15520
|
if (args.action === "update-step") {
|
|
15319
|
-
const resolvedFilePath =
|
|
15320
|
-
const step = JSON.parse((0,
|
|
15521
|
+
const resolvedFilePath = import_node_path18.default.resolve(process.cwd(), args.filePath);
|
|
15522
|
+
const step = JSON.parse((0, import_node_fs12.readFileSync)(resolvedFilePath, "utf8"));
|
|
15321
15523
|
step.stepId = args.stepId;
|
|
15322
15524
|
const result = await updateQuizPaperStep({
|
|
15323
15525
|
apiBaseUrl,
|
|
@@ -15380,8 +15582,8 @@ var QuizCommandHandler = class {
|
|
|
15380
15582
|
if (targetIndex < 0) {
|
|
15381
15583
|
throw new Error(`\u672A\u627E\u5230 stepId=${args.stepId}\uFF0C\u65E0\u6CD5\u66F4\u65B0\u8BE5\u9898\u76EE\u3002`);
|
|
15382
15584
|
}
|
|
15383
|
-
const resolvedFilePath =
|
|
15384
|
-
const nextStep = JSON.parse((0,
|
|
15585
|
+
const resolvedFilePath = import_node_path18.default.resolve(process.cwd(), args.filePath);
|
|
15586
|
+
const nextStep = JSON.parse((0, import_node_fs12.readFileSync)(resolvedFilePath, "utf8"));
|
|
15385
15587
|
nextStep.stepId = args.stepId;
|
|
15386
15588
|
const nextSteps = [...basePaper.steps];
|
|
15387
15589
|
nextSteps[targetIndex] = nextStep;
|
|
@@ -15431,9 +15633,9 @@ var QuizCommandHandler = class {
|
|
|
15431
15633
|
};
|
|
15432
15634
|
|
|
15433
15635
|
// src/commands/CollectCommandHandler.ts
|
|
15434
|
-
var
|
|
15435
|
-
var
|
|
15436
|
-
var
|
|
15636
|
+
var import_node_fs14 = require("fs");
|
|
15637
|
+
var import_node_os9 = __toESM(require("os"));
|
|
15638
|
+
var import_node_path20 = __toESM(require("path"));
|
|
15437
15639
|
var import_playwright = require("playwright");
|
|
15438
15640
|
|
|
15439
15641
|
// src/im1BotClient.ts
|
|
@@ -15517,13 +15719,13 @@ var Im1BotClient = class {
|
|
|
15517
15719
|
|
|
15518
15720
|
// src/collectStore.ts
|
|
15519
15721
|
var import_node_crypto4 = require("crypto");
|
|
15520
|
-
var
|
|
15521
|
-
var
|
|
15522
|
-
var
|
|
15722
|
+
var import_node_fs13 = require("fs");
|
|
15723
|
+
var import_node_os8 = __toESM(require("os"));
|
|
15724
|
+
var import_node_path19 = __toESM(require("path"));
|
|
15523
15725
|
function resolveCollectTarget(input) {
|
|
15524
15726
|
const endpoint = input.endpoint ?? (input.source === "cc" ? "http://localhost:9223" : "http://localhost:9222");
|
|
15525
15727
|
const sourceKey = input.source ?? `endpoint-${(0, import_node_crypto4.createHash)("sha1").update(endpoint).digest("hex").slice(0, 8)}`;
|
|
15526
|
-
const rootDir =
|
|
15728
|
+
const rootDir = import_node_path19.default.join(import_node_os8.default.homedir(), ".pmate", "collect", sourceKey);
|
|
15527
15729
|
return { sourceKey, endpoint, rootDir };
|
|
15528
15730
|
}
|
|
15529
15731
|
function toThreadKey(name) {
|
|
@@ -15535,7 +15737,7 @@ function toThreadKey(name) {
|
|
|
15535
15737
|
async function readStoredThread(rootDir, threadKey) {
|
|
15536
15738
|
const filePath = getThreadMetaFilePath(rootDir, threadKey);
|
|
15537
15739
|
try {
|
|
15538
|
-
const raw = await
|
|
15740
|
+
const raw = await import_node_fs13.promises.readFile(filePath, "utf8");
|
|
15539
15741
|
const parsed = JSON.parse(raw);
|
|
15540
15742
|
if ("messages" in parsed && Array.isArray(parsed.messages)) {
|
|
15541
15743
|
return parsed;
|
|
@@ -15553,15 +15755,15 @@ async function writeStoredThread(rootDir, thread) {
|
|
|
15553
15755
|
const metaPath = getThreadMetaFilePath(rootDir, thread.threadKey);
|
|
15554
15756
|
const messagePath = getThreadMessagesFilePath(rootDir, thread.threadKey);
|
|
15555
15757
|
const { messages: messages2, ...meta } = thread;
|
|
15556
|
-
await
|
|
15557
|
-
await
|
|
15758
|
+
await import_node_fs13.promises.mkdir(import_node_path19.default.dirname(metaPath), { recursive: true });
|
|
15759
|
+
await import_node_fs13.promises.writeFile(metaPath, JSON.stringify(meta, null, 2) + "\n", "utf8");
|
|
15558
15760
|
const body = messages2.map((message) => JSON.stringify(message)).join("\n");
|
|
15559
|
-
await
|
|
15761
|
+
await import_node_fs13.promises.writeFile(messagePath, `${body}${body ? "\n" : ""}`, "utf8");
|
|
15560
15762
|
}
|
|
15561
15763
|
async function writeStoredIndex(rootDir, index) {
|
|
15562
|
-
await
|
|
15563
|
-
const filePath =
|
|
15564
|
-
await
|
|
15764
|
+
await import_node_fs13.promises.mkdir(rootDir, { recursive: true });
|
|
15765
|
+
const filePath = import_node_path19.default.join(rootDir, "index.json");
|
|
15766
|
+
await import_node_fs13.promises.writeFile(filePath, JSON.stringify(index, null, 2) + "\n", "utf8");
|
|
15565
15767
|
}
|
|
15566
15768
|
function diffMessages(existing, incoming) {
|
|
15567
15769
|
const seenMessageIds = new Set(
|
|
@@ -15635,7 +15837,7 @@ function joinNormalized(values) {
|
|
|
15635
15837
|
async function readStoredMessages(rootDir, threadKey) {
|
|
15636
15838
|
const filePath = getThreadMessagesFilePath(rootDir, threadKey);
|
|
15637
15839
|
try {
|
|
15638
|
-
const raw = await
|
|
15840
|
+
const raw = await import_node_fs13.promises.readFile(filePath, "utf8");
|
|
15639
15841
|
return raw.split("\n").map((line) => line.trim()).filter(Boolean).map((line) => normalizeStoredMessage(JSON.parse(line)));
|
|
15640
15842
|
} catch {
|
|
15641
15843
|
return [];
|
|
@@ -15644,20 +15846,20 @@ async function readStoredMessages(rootDir, threadKey) {
|
|
|
15644
15846
|
async function readLegacyStoredThread(rootDir, threadKey) {
|
|
15645
15847
|
const filePath = getLegacyThreadFilePath(rootDir, threadKey);
|
|
15646
15848
|
try {
|
|
15647
|
-
const raw = await
|
|
15849
|
+
const raw = await import_node_fs13.promises.readFile(filePath, "utf8");
|
|
15648
15850
|
return JSON.parse(raw);
|
|
15649
15851
|
} catch {
|
|
15650
15852
|
return null;
|
|
15651
15853
|
}
|
|
15652
15854
|
}
|
|
15653
15855
|
function getThreadMetaFilePath(rootDir, threadKey) {
|
|
15654
|
-
return
|
|
15856
|
+
return import_node_path19.default.join(rootDir, "threads", `${threadKey}.json`);
|
|
15655
15857
|
}
|
|
15656
15858
|
function getThreadMessagesFilePath(rootDir, threadKey) {
|
|
15657
|
-
return
|
|
15859
|
+
return import_node_path19.default.join(rootDir, "threads", `${threadKey}.jsonl`);
|
|
15658
15860
|
}
|
|
15659
15861
|
function getLegacyThreadFilePath(rootDir, threadKey) {
|
|
15660
|
-
return
|
|
15862
|
+
return import_node_path19.default.join(rootDir, "threads", `${threadKey}.json`);
|
|
15661
15863
|
}
|
|
15662
15864
|
function normalizeStoredMessage(message) {
|
|
15663
15865
|
return {
|
|
@@ -15673,9 +15875,9 @@ function normalizeStoredMessage(message) {
|
|
|
15673
15875
|
|
|
15674
15876
|
// src/commands/CollectCommandHandler.ts
|
|
15675
15877
|
async function readOutgoingAttachment(filePath) {
|
|
15676
|
-
const resolved =
|
|
15677
|
-
const data = await
|
|
15678
|
-
const extension =
|
|
15878
|
+
const resolved = import_node_path20.default.resolve(filePath);
|
|
15879
|
+
const data = await import_node_fs14.promises.readFile(resolved);
|
|
15880
|
+
const extension = import_node_path20.default.extname(resolved).toLowerCase();
|
|
15679
15881
|
const contentTypes = {
|
|
15680
15882
|
".png": "image/png",
|
|
15681
15883
|
".jpg": "image/jpeg",
|
|
@@ -15690,7 +15892,7 @@ async function readOutgoingAttachment(filePath) {
|
|
|
15690
15892
|
};
|
|
15691
15893
|
return {
|
|
15692
15894
|
base64: data.toString("base64"),
|
|
15693
|
-
fileName:
|
|
15895
|
+
fileName: import_node_path20.default.basename(resolved),
|
|
15694
15896
|
contentType: contentTypes[extension] ?? "application/octet-stream",
|
|
15695
15897
|
size: data.byteLength
|
|
15696
15898
|
};
|
|
@@ -15960,7 +16162,7 @@ var CollectCommandHandler = class {
|
|
|
15960
16162
|
}
|
|
15961
16163
|
async writeSyncReport(rootDir, target, results, failures, syncedAt) {
|
|
15962
16164
|
const syncId = toSyncId(syncedAt);
|
|
15963
|
-
const reportPath =
|
|
16165
|
+
const reportPath = import_node_path20.default.join(rootDir, "syncs", `${syncId}.json`);
|
|
15964
16166
|
const threadReports = results.map((result) => ({
|
|
15965
16167
|
threadKey: result.thread.threadKey,
|
|
15966
16168
|
threadName: result.thread.threadName,
|
|
@@ -15969,8 +16171,8 @@ var CollectCommandHandler = class {
|
|
|
15969
16171
|
addedMessages: result.diff.added,
|
|
15970
16172
|
upgradedMessages: result.diff.upgraded
|
|
15971
16173
|
})).filter((thread) => thread.addedCount > 0 || thread.upgradedCount > 0);
|
|
15972
|
-
await
|
|
15973
|
-
await
|
|
16174
|
+
await import_node_fs14.promises.mkdir(import_node_path20.default.dirname(reportPath), { recursive: true });
|
|
16175
|
+
await import_node_fs14.promises.writeFile(
|
|
15974
16176
|
reportPath,
|
|
15975
16177
|
JSON.stringify(
|
|
15976
16178
|
{
|
|
@@ -16148,19 +16350,19 @@ async function archiveMessageImage(rootDir, attachmentRoot, threadKey, imagePath
|
|
|
16148
16350
|
if (!imagePath || isExternalImageRef(imagePath)) {
|
|
16149
16351
|
return imagePath;
|
|
16150
16352
|
}
|
|
16151
|
-
const normalized =
|
|
16353
|
+
const normalized = import_node_path20.default.posix.normalize(imagePath.replace(/\\/g, "/"));
|
|
16152
16354
|
if (normalized.startsWith("attachments/")) {
|
|
16153
|
-
return
|
|
16355
|
+
return import_node_path20.default.join(rootDir, ...normalized.split("/"));
|
|
16154
16356
|
}
|
|
16155
|
-
if (normalized.startsWith("../") ||
|
|
16357
|
+
if (normalized.startsWith("../") || import_node_path20.default.posix.isAbsolute(normalized)) {
|
|
16156
16358
|
return imagePath;
|
|
16157
16359
|
}
|
|
16158
|
-
const sourcePath =
|
|
16159
|
-
const destinationRelativePath =
|
|
16160
|
-
const destinationPath =
|
|
16360
|
+
const sourcePath = import_node_path20.default.join(attachmentRoot, ...normalized.split("/"));
|
|
16361
|
+
const destinationRelativePath = import_node_path20.default.posix.join("attachments", threadKey, normalized);
|
|
16362
|
+
const destinationPath = import_node_path20.default.join(rootDir, ...destinationRelativePath.split("/"));
|
|
16161
16363
|
try {
|
|
16162
|
-
await
|
|
16163
|
-
await
|
|
16364
|
+
await import_node_fs14.promises.mkdir(import_node_path20.default.dirname(destinationPath), { recursive: true });
|
|
16365
|
+
await import_node_fs14.promises.copyFile(sourcePath, destinationPath);
|
|
16164
16366
|
return destinationPath;
|
|
16165
16367
|
} catch {
|
|
16166
16368
|
return imagePath;
|
|
@@ -16170,7 +16372,7 @@ function resolveLocalAttachmentRoot(sourceKey) {
|
|
|
16170
16372
|
if (sourceKey !== "cc" && sourceKey !== "yelling") {
|
|
16171
16373
|
return null;
|
|
16172
16374
|
}
|
|
16173
|
-
return
|
|
16375
|
+
return import_node_path20.default.join(import_node_os9.default.homedir(), "Library", "Application Support", sourceKey, "attachments.noindex");
|
|
16174
16376
|
}
|
|
16175
16377
|
function isExternalImageRef(imagePath) {
|
|
16176
16378
|
return /^[a-z][a-z0-9+.-]*:/i.test(imagePath);
|
|
@@ -16794,7 +16996,7 @@ function pad2(value) {
|
|
|
16794
16996
|
}
|
|
16795
16997
|
|
|
16796
16998
|
// src/commands/ChatRoomCommandHandler.ts
|
|
16797
|
-
var
|
|
16999
|
+
var import_node_fs15 = require("fs");
|
|
16798
17000
|
var ChatRoomCommandHandler = class {
|
|
16799
17001
|
async handle(args) {
|
|
16800
17002
|
const sdk = await loadChatSdk();
|
|
@@ -16844,8 +17046,8 @@ var ChatRoomCommandHandler = class {
|
|
|
16844
17046
|
const a = await this.connect(sdk, args.botA, args.app, args.hubUrl, args.authBaseUrl);
|
|
16845
17047
|
const b = await this.connect(sdk, args.botB, args.app, args.hubUrl, args.authBaseUrl);
|
|
16846
17048
|
try {
|
|
16847
|
-
const botA = sdk.parsePmateBotKeyJson((0,
|
|
16848
|
-
const botB = sdk.parsePmateBotKeyJson((0,
|
|
17049
|
+
const botA = sdk.parsePmateBotKeyJson((0, import_node_fs15.readFileSync)(args.botA, "utf8"));
|
|
17050
|
+
const botB = sdk.parsePmateBotKeyJson((0, import_node_fs15.readFileSync)(args.botB, "utf8"));
|
|
16849
17051
|
await a.requestFriend({ to: botB.name, message: "smoke friend request" });
|
|
16850
17052
|
await b.acceptFriend({ to: botA.name, message: "smoke friend accept" });
|
|
16851
17053
|
await a.sendDm({ to: botB.name, text: "smoke dm from a" });
|
|
@@ -16864,7 +17066,7 @@ var ChatRoomCommandHandler = class {
|
|
|
16864
17066
|
if (!botPath) {
|
|
16865
17067
|
throw new Error("Missing required option: --bot");
|
|
16866
17068
|
}
|
|
16867
|
-
const botKey = sdk.parsePmateBotKeyJson((0,
|
|
17069
|
+
const botKey = sdk.parsePmateBotKeyJson((0, import_node_fs15.readFileSync)(botPath, "utf8"));
|
|
16868
17070
|
const client = sdk.createChatClient({ appId, botKey, hubUrl, authBaseUrl });
|
|
16869
17071
|
await client.connect();
|
|
16870
17072
|
return client;
|
|
@@ -16876,8 +17078,8 @@ async function loadChatSdk() {
|
|
|
16876
17078
|
}
|
|
16877
17079
|
|
|
16878
17080
|
// src/commands/RegistryResourceCommandHandler.ts
|
|
16879
|
-
var
|
|
16880
|
-
var
|
|
17081
|
+
var import_node_fs16 = require("fs");
|
|
17082
|
+
var import_node_path21 = __toESM(require("path"));
|
|
16881
17083
|
init_sessionStore();
|
|
16882
17084
|
var RegistryResourceCommandHandler = class {
|
|
16883
17085
|
async handle(args) {
|
|
@@ -16912,9 +17114,9 @@ var RegistryResourceCommandHandler = class {
|
|
|
16912
17114
|
}
|
|
16913
17115
|
};
|
|
16914
17116
|
function readJson(filePath) {
|
|
16915
|
-
const absolutePath =
|
|
16916
|
-
if (!(0,
|
|
16917
|
-
return JSON.parse((0,
|
|
17117
|
+
const absolutePath = import_node_path21.default.resolve(process.cwd(), filePath);
|
|
17118
|
+
if (!(0, import_node_fs16.existsSync)(absolutePath)) throw new Error(`JSON file not found: ${absolutePath}`);
|
|
17119
|
+
return JSON.parse((0, import_node_fs16.readFileSync)(absolutePath, "utf8"));
|
|
16918
17120
|
}
|
|
16919
17121
|
async function request(baseUrl2, token, method, pathname, body) {
|
|
16920
17122
|
const response = await fetch(`${baseUrl2}${pathname}`, {
|
|
@@ -16928,8 +17130,8 @@ async function request(baseUrl2, token, method, pathname, body) {
|
|
|
16928
17130
|
}
|
|
16929
17131
|
|
|
16930
17132
|
// src/commands/CallCommandHandler.ts
|
|
16931
|
-
var
|
|
16932
|
-
var
|
|
17133
|
+
var import_node_fs17 = require("fs");
|
|
17134
|
+
var import_node_path22 = __toESM(require("path"));
|
|
16933
17135
|
init_dist2();
|
|
16934
17136
|
init_sessionStore();
|
|
16935
17137
|
var CallCommandHandler = class {
|
|
@@ -16952,8 +17154,8 @@ var CallCommandHandler = class {
|
|
|
16952
17154
|
}
|
|
16953
17155
|
};
|
|
16954
17156
|
async function callWithBinaryFile(hub, functionId, filePath, contentType, timeoutMs) {
|
|
16955
|
-
const absolutePath =
|
|
16956
|
-
if (!(0,
|
|
17157
|
+
const absolutePath = import_node_path22.default.resolve(process.cwd(), filePath);
|
|
17158
|
+
if (!(0, import_node_fs17.existsSync)(absolutePath)) throw new Error(`Binary file not found: ${absolutePath}`);
|
|
16957
17159
|
const mimeType = contentType || inferContentType(absolutePath);
|
|
16958
17160
|
const result = hub.stream({
|
|
16959
17161
|
functionId,
|
|
@@ -16963,7 +17165,7 @@ async function callWithBinaryFile(hub, functionId, filePath, contentType, timeou
|
|
|
16963
17165
|
return result.finish();
|
|
16964
17166
|
}
|
|
16965
17167
|
async function* streamFile(filePath, contentType) {
|
|
16966
|
-
for await (const chunk of (0,
|
|
17168
|
+
for await (const chunk of (0, import_node_fs17.createReadStream)(filePath)) {
|
|
16967
17169
|
yield new Blob([chunk], { type: contentType });
|
|
16968
17170
|
}
|
|
16969
17171
|
}
|
|
@@ -16978,12 +17180,12 @@ function inferContentType(filePath) {
|
|
|
16978
17180
|
".wav": "audio/wav",
|
|
16979
17181
|
".webm": "audio/webm"
|
|
16980
17182
|
};
|
|
16981
|
-
return contentTypes[
|
|
17183
|
+
return contentTypes[import_node_path22.default.extname(filePath).toLowerCase()] || "application/octet-stream";
|
|
16982
17184
|
}
|
|
16983
17185
|
function readJson2(filePath) {
|
|
16984
|
-
const absolutePath =
|
|
16985
|
-
if (!(0,
|
|
16986
|
-
const decoded = JSON.parse((0,
|
|
17186
|
+
const absolutePath = import_node_path22.default.resolve(process.cwd(), filePath);
|
|
17187
|
+
if (!(0, import_node_fs17.existsSync)(absolutePath)) throw new Error(`JSON file not found: ${absolutePath}`);
|
|
17188
|
+
const decoded = JSON.parse((0, import_node_fs17.readFileSync)(absolutePath, "utf8"));
|
|
16987
17189
|
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) {
|
|
16988
17190
|
throw new Error("Call input file must contain a JSON object");
|
|
16989
17191
|
}
|
|
@@ -17019,8 +17221,8 @@ function descriptorPathSegments(descriptor) {
|
|
|
17019
17221
|
return ["chains", normalized.chain, "namespaces", normalized.ns, normalized.kind, normalized.name];
|
|
17020
17222
|
}
|
|
17021
17223
|
function buildPathUrl(baseUrl2, pathSegments, query) {
|
|
17022
|
-
const
|
|
17023
|
-
const url = new URL(
|
|
17224
|
+
const path37 = `/${pathSegments.map((segment2) => encodeURIComponent(segment2)).join("/")}`;
|
|
17225
|
+
const url = new URL(path37, baseUrl2);
|
|
17024
17226
|
if (query) {
|
|
17025
17227
|
for (const [key, value] of Object.entries(query)) {
|
|
17026
17228
|
url.searchParams.set(key, String(value));
|
|
@@ -17370,8 +17572,8 @@ var NsCommandHandler = class {
|
|
|
17370
17572
|
};
|
|
17371
17573
|
|
|
17372
17574
|
// src/commands/StoreCommandHandler.ts
|
|
17373
|
-
var
|
|
17374
|
-
var
|
|
17575
|
+
var import_node_fs18 = require("fs");
|
|
17576
|
+
var import_node_path23 = __toESM(require("path"));
|
|
17375
17577
|
init_sessionStore();
|
|
17376
17578
|
var StoreCommandHandler = class {
|
|
17377
17579
|
async handle(args) {
|
|
@@ -17525,11 +17727,11 @@ var StoreCommandHandler = class {
|
|
|
17525
17727
|
return payload.data ?? [];
|
|
17526
17728
|
}
|
|
17527
17729
|
readJsonFile(filePath) {
|
|
17528
|
-
const absolutePath =
|
|
17529
|
-
if (!(0,
|
|
17730
|
+
const absolutePath = import_node_path23.default.resolve(process.cwd(), filePath);
|
|
17731
|
+
if (!(0, import_node_fs18.existsSync)(absolutePath)) {
|
|
17530
17732
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
17531
17733
|
}
|
|
17532
|
-
const raw = (0,
|
|
17734
|
+
const raw = (0, import_node_fs18.readFileSync)(absolutePath, "utf8");
|
|
17533
17735
|
try {
|
|
17534
17736
|
return JSON.parse(raw);
|
|
17535
17737
|
} catch (error) {
|
|
@@ -17581,14 +17783,14 @@ var StoreCommandHandler = class {
|
|
|
17581
17783
|
};
|
|
17582
17784
|
|
|
17583
17785
|
// src/commands/AppCommandHandler.ts
|
|
17584
|
-
var
|
|
17585
|
-
var
|
|
17786
|
+
var import_node_fs20 = require("fs");
|
|
17787
|
+
var import_node_path25 = __toESM(require("path"));
|
|
17586
17788
|
init_sessionStore();
|
|
17587
17789
|
|
|
17588
17790
|
// src/appIcon.ts
|
|
17589
|
-
var
|
|
17590
|
-
var
|
|
17591
|
-
var
|
|
17791
|
+
var import_node_fs19 = require("fs");
|
|
17792
|
+
var import_node_os10 = __toESM(require("os"));
|
|
17793
|
+
var import_node_path24 = __toESM(require("path"));
|
|
17592
17794
|
var import_sharp = __toESM(require("sharp"));
|
|
17593
17795
|
init_namespacedRef();
|
|
17594
17796
|
var ANDROID_ICON_SPECS = [
|
|
@@ -17693,13 +17895,13 @@ function createAppIconExportPlans(input) {
|
|
|
17693
17895
|
if (!input.outDir) {
|
|
17694
17896
|
throw new Error("App icon preset export requires --out-dir.");
|
|
17695
17897
|
}
|
|
17696
|
-
const outDir =
|
|
17697
|
-
(0,
|
|
17898
|
+
const outDir = import_node_path24.default.resolve(input.cwd, input.outDir);
|
|
17899
|
+
(0, import_node_fs19.mkdirSync)(outDir, { recursive: true });
|
|
17698
17900
|
return specs.map((spec) => ({
|
|
17699
17901
|
width: spec.width,
|
|
17700
17902
|
height: spec.height,
|
|
17701
17903
|
format: "png",
|
|
17702
|
-
outputPath:
|
|
17904
|
+
outputPath: import_node_path24.default.join(
|
|
17703
17905
|
outDir,
|
|
17704
17906
|
`${namespace}-${objectId}-${spec.name}-${spec.width}x${spec.height}.png`
|
|
17705
17907
|
)
|
|
@@ -17712,8 +17914,8 @@ function createAppIconExportPlans(input) {
|
|
|
17712
17914
|
if (!input.output) {
|
|
17713
17915
|
throw new Error("Single-size app icon export requires --output.");
|
|
17714
17916
|
}
|
|
17715
|
-
const resolvedOutput =
|
|
17716
|
-
(0,
|
|
17917
|
+
const resolvedOutput = import_node_path24.default.resolve(input.cwd, input.output);
|
|
17918
|
+
(0, import_node_fs19.mkdirSync)(import_node_path24.default.dirname(resolvedOutput), { recursive: true });
|
|
17717
17919
|
return [
|
|
17718
17920
|
{
|
|
17719
17921
|
width: input.width,
|
|
@@ -17727,7 +17929,7 @@ async function exportAppIcon(icon, plans) {
|
|
|
17727
17929
|
const svg = await resolveAppIconSvg(icon);
|
|
17728
17930
|
for (const plan of plans) {
|
|
17729
17931
|
const bytes = await renderAppIcon(svg, plan.width, plan.height, plan.format);
|
|
17730
|
-
(0,
|
|
17932
|
+
(0, import_node_fs19.writeFileSync)(plan.outputPath, bytes);
|
|
17731
17933
|
}
|
|
17732
17934
|
}
|
|
17733
17935
|
async function renderAppIconVariant(input) {
|
|
@@ -17735,9 +17937,9 @@ async function renderAppIconVariant(input) {
|
|
|
17735
17937
|
const bytes = await renderAppIcon(svg, input.width, input.height, input.format);
|
|
17736
17938
|
let outputPath;
|
|
17737
17939
|
if (input.output) {
|
|
17738
|
-
outputPath =
|
|
17739
|
-
(0,
|
|
17740
|
-
(0,
|
|
17940
|
+
outputPath = import_node_path24.default.resolve(input.cwd, input.output);
|
|
17941
|
+
(0, import_node_fs19.mkdirSync)(import_node_path24.default.dirname(outputPath), { recursive: true });
|
|
17942
|
+
(0, import_node_fs19.writeFileSync)(outputPath, bytes);
|
|
17741
17943
|
}
|
|
17742
17944
|
if (input.name) {
|
|
17743
17945
|
return {
|
|
@@ -17758,7 +17960,7 @@ async function renderAppIconVariant(input) {
|
|
|
17758
17960
|
};
|
|
17759
17961
|
}
|
|
17760
17962
|
async function loadAppIconVariantFile(input) {
|
|
17761
|
-
const absolutePath =
|
|
17963
|
+
const absolutePath = import_node_path24.default.resolve(input.cwd, input.filePath);
|
|
17762
17964
|
const format = inferVariantFormatFromPath(absolutePath);
|
|
17763
17965
|
return {
|
|
17764
17966
|
value: input.name ? await uploadAppIconVariantAsset({
|
|
@@ -17767,7 +17969,7 @@ async function loadAppIconVariantFile(input) {
|
|
|
17767
17969
|
name: input.name,
|
|
17768
17970
|
format,
|
|
17769
17971
|
sourcePath: absolutePath
|
|
17770
|
-
}) : createImageDataUrl((0,
|
|
17972
|
+
}) : createImageDataUrl((0, import_node_fs19.readFileSync)(absolutePath), format),
|
|
17771
17973
|
format,
|
|
17772
17974
|
absolutePath
|
|
17773
17975
|
};
|
|
@@ -17826,7 +18028,7 @@ function shouldAutoGenerateDefaultVariant(icon) {
|
|
|
17826
18028
|
return looksLikeSvgMarkup(icon) || looksLikeSvgUrl(icon);
|
|
17827
18029
|
}
|
|
17828
18030
|
function inferVariantFormatFromPath(filePath) {
|
|
17829
|
-
const ext =
|
|
18031
|
+
const ext = import_node_path24.default.extname(filePath).toLowerCase();
|
|
17830
18032
|
switch (ext) {
|
|
17831
18033
|
case ".png":
|
|
17832
18034
|
return "png";
|
|
@@ -17897,13 +18099,13 @@ async function uploadAppIconVariantAsset(input) {
|
|
|
17897
18099
|
await AliyunService.uploadFile(sourcePath, DEFAULT_APP_ICON_VARIANT_BUCKET, objectKey);
|
|
17898
18100
|
} finally {
|
|
17899
18101
|
if (shouldCleanup) {
|
|
17900
|
-
(0,
|
|
18102
|
+
(0, import_node_fs19.rmSync)(import_node_path24.default.dirname(sourcePath), { recursive: true, force: true });
|
|
17901
18103
|
}
|
|
17902
18104
|
}
|
|
17903
18105
|
return `${DEFAULT_APP_ICON_VARIANT_PUBLIC_BASE_URL}/${objectKey}`;
|
|
17904
18106
|
}
|
|
17905
18107
|
function buildAppIconVariantObjectKey(input) {
|
|
17906
|
-
return
|
|
18108
|
+
return import_node_path24.default.posix.join(
|
|
17907
18109
|
"apps",
|
|
17908
18110
|
`${resolveAppIconAssetStem(input.icon, input.appRef)}-${input.name}.${extensionForIconFormat(input.format)}`
|
|
17909
18111
|
);
|
|
@@ -17912,8 +18114,8 @@ function resolveAppIconAssetStem(icon, appRef2) {
|
|
|
17912
18114
|
if (icon) {
|
|
17913
18115
|
try {
|
|
17914
18116
|
const url = new URL(icon);
|
|
17915
|
-
const ext =
|
|
17916
|
-
const basename =
|
|
18117
|
+
const ext = import_node_path24.default.posix.extname(url.pathname);
|
|
18118
|
+
const basename = import_node_path24.default.posix.basename(url.pathname, ext);
|
|
17917
18119
|
const normalized = sanitizeAppIconAssetStem(basename);
|
|
17918
18120
|
if (normalized) {
|
|
17919
18121
|
return normalized;
|
|
@@ -17942,9 +18144,9 @@ function writeTempAppIconVariantFile(objectKey, format, bytes) {
|
|
|
17942
18144
|
if (!bytes) {
|
|
17943
18145
|
throw new Error("App icon variant upload requires bytes or a source file.");
|
|
17944
18146
|
}
|
|
17945
|
-
const tempDir = (0,
|
|
17946
|
-
const tempPath =
|
|
17947
|
-
(0,
|
|
18147
|
+
const tempDir = (0, import_node_fs19.mkdtempSync)(import_node_path24.default.join(import_node_os10.default.tmpdir(), "pmate-app-icon-"));
|
|
18148
|
+
const tempPath = import_node_path24.default.join(tempDir, import_node_path24.default.basename(objectKey) || `variant.${extensionForIconFormat(format)}`);
|
|
18149
|
+
(0, import_node_fs19.writeFileSync)(tempPath, bytes);
|
|
17948
18150
|
return tempPath;
|
|
17949
18151
|
}
|
|
17950
18152
|
|
|
@@ -18153,10 +18355,10 @@ var AppCommandHandler = class {
|
|
|
18153
18355
|
}
|
|
18154
18356
|
readJsonFile(filePath) {
|
|
18155
18357
|
const absolutePath = this.resolveFilePath(filePath);
|
|
18156
|
-
if (!(0,
|
|
18358
|
+
if (!(0, import_node_fs20.existsSync)(absolutePath)) {
|
|
18157
18359
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
18158
18360
|
}
|
|
18159
|
-
const raw = (0,
|
|
18361
|
+
const raw = (0, import_node_fs20.readFileSync)(absolutePath, "utf8");
|
|
18160
18362
|
try {
|
|
18161
18363
|
return JSON.parse(raw);
|
|
18162
18364
|
} catch (error) {
|
|
@@ -18166,10 +18368,10 @@ var AppCommandHandler = class {
|
|
|
18166
18368
|
}
|
|
18167
18369
|
async preparePayload(filePath, appRef2) {
|
|
18168
18370
|
const absolutePath = this.resolveFilePath(filePath);
|
|
18169
|
-
return prepareAppPayload(this.readJsonFile(filePath),
|
|
18371
|
+
return prepareAppPayload(this.readJsonFile(filePath), import_node_path25.default.dirname(absolutePath), { appRef: appRef2 });
|
|
18170
18372
|
}
|
|
18171
18373
|
resolveFilePath(filePath) {
|
|
18172
|
-
return
|
|
18374
|
+
return import_node_path25.default.resolve(process.cwd(), filePath);
|
|
18173
18375
|
}
|
|
18174
18376
|
async request(baseUrl2, token, method, pathname, body) {
|
|
18175
18377
|
const response = await fetch(`${baseUrl2}${pathname}`, {
|
|
@@ -18289,28 +18491,28 @@ function readNamespaceFromPayload(payload) {
|
|
|
18289
18491
|
}
|
|
18290
18492
|
|
|
18291
18493
|
// src/commands/ServiceCommandHandler.ts
|
|
18292
|
-
var
|
|
18494
|
+
var import_node_fs28 = require("fs");
|
|
18293
18495
|
var import_promises5 = require("fs/promises");
|
|
18294
|
-
var
|
|
18295
|
-
var
|
|
18496
|
+
var import_node_path33 = __toESM(require("path"));
|
|
18497
|
+
var import_node_child_process16 = require("child_process");
|
|
18296
18498
|
var import_promises6 = require("readline/promises");
|
|
18297
18499
|
|
|
18298
18500
|
// src/services/NativeServiceDeploy.ts
|
|
18299
|
-
var
|
|
18300
|
-
var
|
|
18501
|
+
var import_node_path31 = __toESM(require("path"));
|
|
18502
|
+
var import_node_fs26 = require("fs");
|
|
18301
18503
|
|
|
18302
18504
|
// src/electronBuild.ts
|
|
18303
|
-
var
|
|
18304
|
-
var
|
|
18305
|
-
var
|
|
18306
|
-
var
|
|
18505
|
+
var import_node_child_process10 = require("child_process");
|
|
18506
|
+
var import_node_fs22 = require("fs");
|
|
18507
|
+
var import_node_os11 = require("os");
|
|
18508
|
+
var import_node_path27 = __toESM(require("path"));
|
|
18307
18509
|
var import_sharp2 = __toESM(require("sharp"));
|
|
18308
18510
|
|
|
18309
18511
|
// src/desktopRelease.ts
|
|
18310
18512
|
init_sessionStore();
|
|
18311
18513
|
var import_node_crypto5 = require("crypto");
|
|
18312
|
-
var
|
|
18313
|
-
var
|
|
18514
|
+
var import_node_fs21 = require("fs");
|
|
18515
|
+
var import_node_path26 = __toESM(require("path"));
|
|
18314
18516
|
async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
18315
18517
|
const segments = [...app.split(":"), version, platform, arch];
|
|
18316
18518
|
if (app.split(":").length !== 2 || segments.some((s) => !/^[\w.-]+$/.test(s) || s === "." || s === "..")) throw new Error("Invalid desktop release identity");
|
|
@@ -18319,8 +18521,8 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
|
18319
18521
|
const bucket2 = "parrot-static";
|
|
18320
18522
|
const prefix = `desktop/${segments.join("/")}/`;
|
|
18321
18523
|
const url = (key) => `https://parrot-static.pmate.chat/${key.split("/").map(encodeURIComponent).join("/")}`;
|
|
18322
|
-
const artifacts = (0,
|
|
18323
|
-
const bytes = (0,
|
|
18524
|
+
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) => {
|
|
18525
|
+
const bytes = (0, import_node_fs21.readFileSync)(import_node_path26.default.join(directory, entry.name));
|
|
18324
18526
|
const objectKey = prefix + entry.name;
|
|
18325
18527
|
return { name: entry.name, objectKey, downloadUrl: url(objectKey), sha256: (0, import_node_crypto5.createHash)("sha256").update(bytes).digest("hex"), size: bytes.length };
|
|
18326
18528
|
});
|
|
@@ -18329,7 +18531,7 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
|
18329
18531
|
const existing = await AliyunService.readJsonObject(bucket2, manifestKey);
|
|
18330
18532
|
const release = { schemaVersion: 1, app, version, platform, arch, artifacts };
|
|
18331
18533
|
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(
|
|
18534
|
+
for (const artifact of artifacts) await AliyunService.uploadFile(import_node_path26.default.join(directory, artifact.name), bucket2, artifact.objectKey);
|
|
18333
18535
|
await AliyunService.uploadJsonObject(bucket2, manifestKey, release);
|
|
18334
18536
|
const base = (process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
18335
18537
|
const response = await fetch(`${base}/versions/${encodeURIComponent(app)}`, {
|
|
@@ -18348,7 +18550,7 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
|
18348
18550
|
var ELECTRON_VERSION = "44.5.1";
|
|
18349
18551
|
var BUILDER_VERSION = "26.15.3";
|
|
18350
18552
|
function readDesktopConfig(file, appId) {
|
|
18351
|
-
const c = JSON.parse((0,
|
|
18553
|
+
const c = JSON.parse((0, import_node_fs22.readFileSync)(file, "utf8"));
|
|
18352
18554
|
if (c.schemaVersion !== 2 || c.app !== appId) throw new Error("Desktop config schemaVersion/app mismatch");
|
|
18353
18555
|
for (const key of ["productName", "bundleId", "version", "icon"]) {
|
|
18354
18556
|
if (typeof c[key] !== "string" || !c[key].trim()) throw new Error(`Missing desktop ${key}`);
|
|
@@ -18374,10 +18576,10 @@ function readDesktopConfig(file, appId) {
|
|
|
18374
18576
|
return c;
|
|
18375
18577
|
}
|
|
18376
18578
|
function repositoryRoot(cwd) {
|
|
18377
|
-
let dir =
|
|
18579
|
+
let dir = import_node_path27.default.resolve(cwd);
|
|
18378
18580
|
while (true) {
|
|
18379
|
-
if ((0,
|
|
18380
|
-
const parent =
|
|
18581
|
+
if ((0, import_node_fs22.existsSync)(import_node_path27.default.join(dir, ".git"))) return dir;
|
|
18582
|
+
const parent = import_node_path27.default.dirname(dir);
|
|
18381
18583
|
if (parent === dir) return void 0;
|
|
18382
18584
|
dir = parent;
|
|
18383
18585
|
}
|
|
@@ -18385,24 +18587,24 @@ function repositoryRoot(cwd) {
|
|
|
18385
18587
|
function resolveDesktopPaths(args, cwd = process.cwd()) {
|
|
18386
18588
|
const root = repositoryRoot(cwd);
|
|
18387
18589
|
const name = args.id.split(":")[1];
|
|
18388
|
-
let file = args.config ?
|
|
18590
|
+
let file = args.config ? import_node_path27.default.resolve(cwd, args.config) : void 0;
|
|
18389
18591
|
if (!file) {
|
|
18390
|
-
let dir =
|
|
18592
|
+
let dir = import_node_path27.default.resolve(cwd);
|
|
18391
18593
|
while (true) {
|
|
18392
|
-
const candidates = [.../* @__PURE__ */ new Set([
|
|
18393
|
-
const matches = candidates.filter((candidate) => (0,
|
|
18594
|
+
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")])];
|
|
18595
|
+
const matches = candidates.filter((candidate) => (0, import_node_fs22.existsSync)(candidate) && JSON.parse((0, import_node_fs22.readFileSync)(candidate, "utf8")).app === args.id);
|
|
18394
18596
|
if (matches.length > 1) throw new Error("Ambiguous desktop config; specify --config");
|
|
18395
18597
|
if (matches.length === 1) {
|
|
18396
18598
|
file = matches[0];
|
|
18397
18599
|
break;
|
|
18398
18600
|
}
|
|
18399
|
-
const parent =
|
|
18601
|
+
const parent = import_node_path27.default.dirname(dir);
|
|
18400
18602
|
if (dir === root || parent === dir) break;
|
|
18401
18603
|
dir = parent;
|
|
18402
18604
|
}
|
|
18403
18605
|
}
|
|
18404
18606
|
if (!file) throw new Error(`No desktop config for ${args.id}; specify --config`);
|
|
18405
|
-
return { file, output: args.outDir ?
|
|
18607
|
+
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
18608
|
}
|
|
18407
18609
|
function desktopBuildEnvironment(config, env = process.env) {
|
|
18408
18610
|
return { ...env, ...env.APPLE_KEYCHAIN_PROFILE ? {} : config.notaryProfile ? { APPLE_KEYCHAIN_PROFILE: config.notaryProfile } : {} };
|
|
@@ -18415,7 +18617,7 @@ function requireNotaryCredentials(env) {
|
|
|
18415
18617
|
} else if (env.APPLE_KEYCHAIN_PROFILE) return;
|
|
18416
18618
|
throw new Error("macOS signed builds require complete Apple notarization credentials or APPLE_KEYCHAIN_PROFILE");
|
|
18417
18619
|
}
|
|
18418
|
-
function requireSigningIdentity(env, inspect = () => (0,
|
|
18620
|
+
function requireSigningIdentity(env, inspect = () => (0, import_node_child_process10.execFileSync)("security", ["find-identity", "-v", "-p", "codesigning"], { encoding: "utf8" })) {
|
|
18419
18621
|
if (env.CSC_LINK) return;
|
|
18420
18622
|
if (!inspect().includes("Developer ID Application:")) throw new Error("No Developer ID Application signing identity available");
|
|
18421
18623
|
}
|
|
@@ -18424,20 +18626,20 @@ async function publishVerifiedDesktop(args, artifacts, config, verify = verifyMa
|
|
|
18424
18626
|
if (args.local || args.dir || !args.signed) return void 0;
|
|
18425
18627
|
return upload(artifacts, config.app, config.version, args.platform, args.arch);
|
|
18426
18628
|
}
|
|
18427
|
-
async function verifyMacRelease(artifacts,
|
|
18428
|
-
const apps = (0,
|
|
18629
|
+
async function verifyMacRelease(artifacts, run2 = runBuildCommand, inspect = (app) => (0, import_node_child_process10.spawnSync)("codesign", ["-dv", "--verbose=4", app], { encoding: "utf8" })) {
|
|
18630
|
+
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
18631
|
if (!apps.length) throw new Error("No packaged macOS app found; refusing publication");
|
|
18430
18632
|
for (const app of apps) {
|
|
18431
|
-
await
|
|
18633
|
+
await run2(["codesign", "--verify", "--deep", "--strict", app], artifacts);
|
|
18432
18634
|
const signature = inspect(app);
|
|
18433
18635
|
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
|
|
18636
|
+
await run2(["xcrun", "stapler", "validate", app], artifacts);
|
|
18637
|
+
await run2(["spctl", "--assess", "--type", "execute", "--verbose=2", app], artifacts);
|
|
18436
18638
|
}
|
|
18437
18639
|
}
|
|
18438
18640
|
async function runBuildCommand(command, cwd, env = process.env) {
|
|
18439
18641
|
await new Promise((resolve, reject) => {
|
|
18440
|
-
const child = (0,
|
|
18642
|
+
const child = (0, import_node_child_process10.spawn)(command[0], command.slice(1), { cwd, env, stdio: "inherit", shell: false });
|
|
18441
18643
|
child.once("error", reject);
|
|
18442
18644
|
child.once("exit", (code, signal) => code === 0 ? resolve() : reject(new Error(`${command[0]} failed (${signal ?? code})`)));
|
|
18443
18645
|
});
|
|
@@ -18446,19 +18648,19 @@ async function renderTrayIcons(source, output) {
|
|
|
18446
18648
|
const idle = await (0, import_sharp2.default)(source).resize(36, 36, { fit: "contain" }).png().toBuffer();
|
|
18447
18649
|
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
18650
|
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(
|
|
18651
|
+
await (0, import_sharp2.default)(idle).toFile(import_node_path27.default.join(output, "trayTemplate.png"));
|
|
18652
|
+
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
18653
|
}
|
|
18452
18654
|
async function buildDesktop(args) {
|
|
18453
18655
|
const { file, output } = resolveDesktopPaths(args);
|
|
18454
18656
|
const c = readDesktopConfig(file, args.id);
|
|
18455
|
-
const base =
|
|
18456
|
-
const icon =
|
|
18657
|
+
const base = import_node_path27.default.dirname(file);
|
|
18658
|
+
const icon = import_node_path27.default.resolve(base, c.icon);
|
|
18457
18659
|
const tray = c.tray && (!c.tray.platforms || c.tray.platforms.includes(args.platform)) ? c.tray : void 0;
|
|
18458
|
-
const trayIcon = tray ?
|
|
18660
|
+
const trayIcon = tray ? import_node_path27.default.resolve(base, tray.icon) : void 0;
|
|
18459
18661
|
const env = desktopBuildEnvironment(c);
|
|
18460
|
-
if (!(0,
|
|
18461
|
-
if (trayIcon && (!(0,
|
|
18662
|
+
if (!(0, import_node_fs22.existsSync)(icon) || !(0, import_node_fs22.statSync)(icon).isFile()) throw new Error(`Desktop icon not found: ${icon}`);
|
|
18663
|
+
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
18664
|
if (!["mac", "win"].includes(args.platform) || !["arm64", "x64"].includes(args.arch)) throw new Error("Supported target: mac|win --arch arm64|x64");
|
|
18463
18665
|
if (args.platform === "mac" && process.platform !== "darwin") throw new Error("macOS desktop packaging requires a macOS build host");
|
|
18464
18666
|
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 +18670,30 @@ async function buildDesktop(args) {
|
|
|
18468
18670
|
requireNotaryCredentials(env);
|
|
18469
18671
|
requireSigningIdentity(env);
|
|
18470
18672
|
}
|
|
18471
|
-
(0,
|
|
18472
|
-
const staging = (0,
|
|
18473
|
-
const appDir =
|
|
18474
|
-
(0,
|
|
18475
|
-
const templateDir =
|
|
18476
|
-
(0,
|
|
18673
|
+
(0, import_node_fs22.mkdirSync)(output, { recursive: true });
|
|
18674
|
+
const staging = (0, import_node_fs22.mkdtempSync)(import_node_path27.default.join(output, ".desktop-build-"));
|
|
18675
|
+
const appDir = import_node_path27.default.join(staging, "app");
|
|
18676
|
+
(0, import_node_fs22.mkdirSync)(appDir);
|
|
18677
|
+
const templateDir = import_node_path27.default.join(__dirname, "templates", "electron");
|
|
18678
|
+
(0, import_node_fs22.cpSync)(templateDir, appDir, { recursive: true });
|
|
18477
18679
|
if (trayIcon) await renderTrayIcons(trayIcon, appDir);
|
|
18478
|
-
(0,
|
|
18479
|
-
(0,
|
|
18680
|
+
(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 } } : {} }));
|
|
18681
|
+
(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
18682
|
await runBuildCommand(["npm", "install", "--omit=dev", "--no-audit", "--no-fund"], appDir);
|
|
18481
|
-
const cache =
|
|
18482
|
-
(0,
|
|
18683
|
+
const cache = import_node_path27.default.join((0, import_node_os11.homedir)(), ".cache", "pmate", "electron", `${ELECTRON_VERSION}-${BUILDER_VERSION}`);
|
|
18684
|
+
(0, import_node_fs22.mkdirSync)(cache, { recursive: true });
|
|
18483
18685
|
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,
|
|
18686
|
+
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"))) {
|
|
18687
|
+
(0, import_node_fs22.writeFileSync)(import_node_path27.default.join(cache, "package.json"), JSON.stringify(toolPackage));
|
|
18688
|
+
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
18689
|
}
|
|
18488
|
-
const entitlements =
|
|
18489
|
-
(0,
|
|
18690
|
+
const entitlements = import_node_path27.default.join(staging, "entitlements.mac.plist");
|
|
18691
|
+
(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
18692
|
const builderConfig = {
|
|
18491
18693
|
appId: c.bundleId,
|
|
18492
18694
|
productName: c.productName,
|
|
18493
18695
|
electronVersion: ELECTRON_VERSION,
|
|
18494
|
-
directories: { app: appDir, output:
|
|
18696
|
+
directories: { app: appDir, output: import_node_path27.default.join(staging, "artifacts") },
|
|
18495
18697
|
files: ["**/*"],
|
|
18496
18698
|
asar: true,
|
|
18497
18699
|
artifactName: "${productName}-${version}-${arch}.${ext}",
|
|
@@ -18500,36 +18702,36 @@ async function buildDesktop(args) {
|
|
|
18500
18702
|
win: { icon, target: args.dir ? ["dir"] : ["nsis", "zip"], ...args.signed ? {} : { signExecutable: false } },
|
|
18501
18703
|
forceCodeSigning: args.signed
|
|
18502
18704
|
};
|
|
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,
|
|
18705
|
+
const configPath = import_node_path27.default.join(staging, "builder.json");
|
|
18706
|
+
(0, import_node_fs22.writeFileSync)(configPath, JSON.stringify(builderConfig));
|
|
18707
|
+
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" } });
|
|
18708
|
+
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") };
|
|
18709
|
+
(0, import_node_fs22.writeFileSync)(import_node_path27.default.join(staging, "build-report.json"), JSON.stringify(result, null, 2));
|
|
18508
18710
|
const publication = await publishVerifiedDesktop(args, result.artifacts, c);
|
|
18509
|
-
(0,
|
|
18510
|
-
console.log(JSON.stringify({ phase: "complete", report:
|
|
18711
|
+
(0, import_node_fs22.writeFileSync)(import_node_path27.default.join(staging, "build-report.json"), JSON.stringify({ ...result, publication }, null, 2));
|
|
18712
|
+
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
18713
|
}
|
|
18512
18714
|
|
|
18513
18715
|
// src/services/CurrentRepositoryRoot.ts
|
|
18514
|
-
var
|
|
18716
|
+
var import_node_child_process11 = require("child_process");
|
|
18515
18717
|
function currentRepositoryRoot(repository, cwd = process.cwd()) {
|
|
18516
18718
|
const canonical = (value) => value.trim().replace(/\/+$/, "").replace(/\.git$/i, "").replace(/^.*(?:github\.com[/:])/, "").toLowerCase();
|
|
18517
18719
|
try {
|
|
18518
18720
|
const options = { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] };
|
|
18519
|
-
const origin = (0,
|
|
18721
|
+
const origin = (0, import_node_child_process11.execFileSync)("git", ["remote", "get-url", "origin"], options);
|
|
18520
18722
|
if (canonical(origin) !== canonical(repository)) return void 0;
|
|
18521
|
-
return (0,
|
|
18723
|
+
return (0, import_node_child_process11.execFileSync)("git", ["rev-parse", "--show-toplevel"], options).trim();
|
|
18522
18724
|
} catch {
|
|
18523
18725
|
return void 0;
|
|
18524
18726
|
}
|
|
18525
18727
|
}
|
|
18526
18728
|
|
|
18527
18729
|
// src/services/AndroidApkReleaseService.ts
|
|
18528
|
-
var
|
|
18730
|
+
var import_node_child_process12 = require("child_process");
|
|
18529
18731
|
var import_node_crypto6 = require("crypto");
|
|
18530
|
-
var
|
|
18531
|
-
var
|
|
18532
|
-
var
|
|
18732
|
+
var import_node_fs23 = require("fs");
|
|
18733
|
+
var import_node_os12 = __toESM(require("os"));
|
|
18734
|
+
var import_node_path28 = __toESM(require("path"));
|
|
18533
18735
|
var ANDROID_APK_BUCKET = "parrot-static";
|
|
18534
18736
|
var ANDROID_APK_PUBLIC_BASE_URL = "https://parrot-static.pmate.chat";
|
|
18535
18737
|
var ANDROID_SIGNING_ENV_KEYS = ["ANDROID_KEYSTORE_BASE64", "ANDROID_KEYSTORE_PASSWORD", "ANDROID_KEY_ALIAS", "ANDROID_KEY_PASSWORD", "ANDROID_SIGNING_CERT_SHA256"];
|
|
@@ -18549,9 +18751,9 @@ function verifyAndroidSigningCertificate(output, expected) {
|
|
|
18549
18751
|
async function signAndroidApk(apkPath, signing) {
|
|
18550
18752
|
const tool = findAndroidSdkTool("apksigner");
|
|
18551
18753
|
if (!tool) throw new Error("Android SDK tool not found: apksigner");
|
|
18552
|
-
const tempDir = (0,
|
|
18553
|
-
const keystorePath =
|
|
18554
|
-
const cleanup = () => (0,
|
|
18754
|
+
const tempDir = (0, import_node_fs23.mkdtempSync)(import_node_path28.default.join(import_node_os12.default.tmpdir(), "pmate-apk-signing-"));
|
|
18755
|
+
const keystorePath = import_node_path28.default.join(tempDir, "signing.keystore");
|
|
18756
|
+
const cleanup = () => (0, import_node_fs23.rmSync)(tempDir, { recursive: true, force: true });
|
|
18555
18757
|
const interrupted = () => {
|
|
18556
18758
|
cleanup();
|
|
18557
18759
|
process.exit(130);
|
|
@@ -18559,9 +18761,9 @@ async function signAndroidApk(apkPath, signing) {
|
|
|
18559
18761
|
process.once("SIGINT", interrupted);
|
|
18560
18762
|
process.once("SIGTERM", interrupted);
|
|
18561
18763
|
try {
|
|
18562
|
-
(0,
|
|
18764
|
+
(0, import_node_fs23.writeFileSync)(keystorePath, signing.keystore, { mode: 384 });
|
|
18563
18765
|
await new Promise((resolve, reject) => {
|
|
18564
|
-
const child = (0,
|
|
18766
|
+
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
18767
|
env: { ...process.env, PMATE_APK_STORE_PASSWORD: signing.storePassword, PMATE_APK_KEY_PASSWORD: signing.keyPassword },
|
|
18566
18768
|
stdio: "ignore"
|
|
18567
18769
|
});
|
|
@@ -18610,7 +18812,7 @@ var AndroidApkReleaseService = class {
|
|
|
18610
18812
|
}
|
|
18611
18813
|
const bump = planAndroidProjectVersion(appDir, options.bump, publishedFloor);
|
|
18612
18814
|
const signing = options.variant.toLowerCase() === "release" ? await this.loadSigning(service.id, options.env) : void 0;
|
|
18613
|
-
(0,
|
|
18815
|
+
(0, import_node_fs23.writeFileSync)(bump.filePath, bump.source);
|
|
18614
18816
|
ui.info("Bumped Android version", {
|
|
18615
18817
|
file: bump.filePath,
|
|
18616
18818
|
from: `${bump.previousVersionName} (${bump.previousVersionCode})`,
|
|
@@ -18635,7 +18837,7 @@ var AndroidApkReleaseService = class {
|
|
|
18635
18837
|
ui.warn("Overwriting existing APK object", { objectKey, etag: existing.etag, size: existing.size });
|
|
18636
18838
|
}
|
|
18637
18839
|
const sha256 = await sha256File(apkPath);
|
|
18638
|
-
const size = (0,
|
|
18840
|
+
const size = (0, import_node_fs23.statSync)(apkPath).size;
|
|
18639
18841
|
const artifact = {
|
|
18640
18842
|
serviceId: service.id,
|
|
18641
18843
|
env: options.env,
|
|
@@ -18685,17 +18887,17 @@ var AndroidApkReleaseService = class {
|
|
|
18685
18887
|
minimumVersionCode: options.minimumVersionCode
|
|
18686
18888
|
});
|
|
18687
18889
|
const objectKeys = androidUpdateManifestKeys(service);
|
|
18688
|
-
const tempDir = (0,
|
|
18689
|
-
const manifestPath =
|
|
18890
|
+
const tempDir = (0, import_node_fs23.mkdtempSync)(import_node_path28.default.join(import_node_os12.default.tmpdir(), "pmate-apk-latest-"));
|
|
18891
|
+
const manifestPath = import_node_path28.default.join(tempDir, "latest.json");
|
|
18690
18892
|
try {
|
|
18691
|
-
(0,
|
|
18893
|
+
(0, import_node_fs23.writeFileSync)(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
18692
18894
|
`);
|
|
18693
18895
|
for (const objectKey of objectKeys) {
|
|
18694
18896
|
await AliyunService.uploadFile(manifestPath, ANDROID_APK_BUCKET, objectKey);
|
|
18695
18897
|
ui.success(`Published Android update manifest ${ANDROID_APK_PUBLIC_BASE_URL}/${objectKey}`);
|
|
18696
18898
|
}
|
|
18697
18899
|
} finally {
|
|
18698
|
-
(0,
|
|
18900
|
+
(0, import_node_fs23.rmSync)(tempDir, { recursive: true, force: true });
|
|
18699
18901
|
}
|
|
18700
18902
|
}
|
|
18701
18903
|
async list(service, options) {
|
|
@@ -18712,7 +18914,7 @@ var AndroidApkReleaseService = class {
|
|
|
18712
18914
|
const prefix = `apks/${identity.namespace}/${identity.name}`;
|
|
18713
18915
|
const objects = await AliyunService.listObjects(ANDROID_APK_BUCKET, prefix);
|
|
18714
18916
|
return objects.filter((item) => item.name.endsWith(".apk")).map((item) => {
|
|
18715
|
-
const versionName =
|
|
18917
|
+
const versionName = import_node_path28.default.basename(item.name, ".apk");
|
|
18716
18918
|
return {
|
|
18717
18919
|
serviceId,
|
|
18718
18920
|
env: options.env ?? "unknown",
|
|
@@ -18735,7 +18937,7 @@ var AndroidApkReleaseService = class {
|
|
|
18735
18937
|
}
|
|
18736
18938
|
}
|
|
18737
18939
|
resolveRepoRoot(service, cwd) {
|
|
18738
|
-
if (cwd) return
|
|
18940
|
+
if (cwd) return import_node_path28.default.resolve(process.cwd(), cwd);
|
|
18739
18941
|
const repository = this.getRepository(service);
|
|
18740
18942
|
if (repository) {
|
|
18741
18943
|
return resolveRepositoryLocalRoot(repository);
|
|
@@ -18747,8 +18949,8 @@ var AndroidApkReleaseService = class {
|
|
|
18747
18949
|
if (!dir) {
|
|
18748
18950
|
throw new Error(`Missing dir for android service ${service.id}`);
|
|
18749
18951
|
}
|
|
18750
|
-
const appDir =
|
|
18751
|
-
if (!(0,
|
|
18952
|
+
const appDir = import_node_path28.default.resolve(repoRoot, dir);
|
|
18953
|
+
if (!(0, import_node_fs23.existsSync)(appDir)) {
|
|
18752
18954
|
throw new Error(`Android app dir not found: ${appDir}`);
|
|
18753
18955
|
}
|
|
18754
18956
|
return appDir;
|
|
@@ -18764,11 +18966,11 @@ var AndroidApkReleaseService = class {
|
|
|
18764
18966
|
return void 0;
|
|
18765
18967
|
}
|
|
18766
18968
|
async runGradleAssembleAndFindApk(repoRoot, appDir, variant) {
|
|
18767
|
-
const gradlew = [
|
|
18969
|
+
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
18970
|
if (!gradlew) {
|
|
18769
18971
|
throw new Error(`Gradle wrapper not found in ${appDir} or ${repoRoot}`);
|
|
18770
18972
|
}
|
|
18771
|
-
const gradleCwd =
|
|
18973
|
+
const gradleCwd = import_node_path28.default.dirname(gradlew);
|
|
18772
18974
|
const normalizedVariant = variant.toLowerCase();
|
|
18773
18975
|
const taskSuffix = `assemble${capitalize(normalizedVariant)}`;
|
|
18774
18976
|
const tasks = [`:app:${taskSuffix}`, taskSuffix];
|
|
@@ -18884,7 +19086,7 @@ function resolveRepositoryLocalRoot(repository) {
|
|
|
18884
19086
|
if (!repoName) {
|
|
18885
19087
|
throw new Error(`Invalid repository: ${repository}`);
|
|
18886
19088
|
}
|
|
18887
|
-
return
|
|
19089
|
+
return import_node_path28.default.join(import_node_os12.default.homedir(), "dev", "pmate", repoName);
|
|
18888
19090
|
}
|
|
18889
19091
|
function bumpAndroidGradleVersionText(source, bump) {
|
|
18890
19092
|
const versionNameMatch = source.match(/(^\s*versionName\s+["'])([^"']+)(["']\s*$)/m) ?? source.match(/(^\s*versionName\s*=\s*["'])([^"']+)(["']\s*$)/m);
|
|
@@ -18940,14 +19142,14 @@ function parseGradleOutputMetadata(source, apkFileName) {
|
|
|
18940
19142
|
}
|
|
18941
19143
|
function planAndroidProjectVersion(appDir, bump, publishedFloor = 0) {
|
|
18942
19144
|
const candidates = [
|
|
18943
|
-
|
|
18944
|
-
|
|
18945
|
-
|
|
18946
|
-
|
|
19145
|
+
import_node_path28.default.join(appDir, "app", "build.gradle.kts"),
|
|
19146
|
+
import_node_path28.default.join(appDir, "app", "build.gradle"),
|
|
19147
|
+
import_node_path28.default.join(appDir, "build.gradle.kts"),
|
|
19148
|
+
import_node_path28.default.join(appDir, "build.gradle")
|
|
18947
19149
|
];
|
|
18948
19150
|
for (const candidate of candidates) {
|
|
18949
|
-
if (!(0,
|
|
18950
|
-
const result = bumpAndroidGradleVersionText((0,
|
|
19151
|
+
if (!(0, import_node_fs23.existsSync)(candidate)) continue;
|
|
19152
|
+
const result = bumpAndroidGradleVersionText((0, import_node_fs23.readFileSync)(candidate, "utf8"), bump);
|
|
18951
19153
|
if (!Number.isSafeInteger(result.versionCode) || result.versionCode <= publishedFloor) throw new Error(`Android source is behind published versionCode ${publishedFloor}; update the checkout before releasing`);
|
|
18952
19154
|
return { filePath: candidate, ...result };
|
|
18953
19155
|
}
|
|
@@ -18955,31 +19157,31 @@ function planAndroidProjectVersion(appDir, bump, publishedFloor = 0) {
|
|
|
18955
19157
|
}
|
|
18956
19158
|
function findLatestApk(repoRoot, appDir, variant) {
|
|
18957
19159
|
const dirs = [
|
|
18958
|
-
|
|
18959
|
-
|
|
18960
|
-
|
|
19160
|
+
import_node_path28.default.join(appDir, "app", "build", "outputs", "apk", variant),
|
|
19161
|
+
import_node_path28.default.join(appDir, "build", "outputs", "apk", variant),
|
|
19162
|
+
import_node_path28.default.join(repoRoot, "app", "build", "outputs", "apk", variant)
|
|
18961
19163
|
];
|
|
18962
19164
|
const files = dirs.flatMap((dir) => listApks(dir));
|
|
18963
19165
|
if (files.length === 0) {
|
|
18964
19166
|
throw new Error(`Cannot find APK output for variant ${variant}`);
|
|
18965
19167
|
}
|
|
18966
|
-
files.sort((a, b) => (0,
|
|
19168
|
+
files.sort((a, b) => (0, import_node_fs23.statSync)(b).mtimeMs - (0, import_node_fs23.statSync)(a).mtimeMs);
|
|
18967
19169
|
return files[0];
|
|
18968
19170
|
}
|
|
18969
19171
|
function readGradleOutputMetadata(apkPath) {
|
|
18970
|
-
const metadataPath =
|
|
18971
|
-
if (!(0,
|
|
19172
|
+
const metadataPath = import_node_path28.default.join(import_node_path28.default.dirname(apkPath), "output-metadata.json");
|
|
19173
|
+
if (!(0, import_node_fs23.existsSync)(metadataPath)) {
|
|
18972
19174
|
throw new Error(`Gradle output metadata not found: ${metadataPath}`);
|
|
18973
19175
|
}
|
|
18974
|
-
return parseGradleOutputMetadata((0,
|
|
19176
|
+
return parseGradleOutputMetadata((0, import_node_fs23.readFileSync)(metadataPath, "utf8"), import_node_path28.default.basename(apkPath));
|
|
18975
19177
|
}
|
|
18976
19178
|
function listApks(dir) {
|
|
18977
|
-
if (!(0,
|
|
18978
|
-
return (0,
|
|
19179
|
+
if (!(0, import_node_fs23.existsSync)(dir)) return [];
|
|
19180
|
+
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
19181
|
}
|
|
18980
19182
|
function runCommand(command, args, cwd) {
|
|
18981
19183
|
return new Promise((resolve, reject) => {
|
|
18982
|
-
const child = (0,
|
|
19184
|
+
const child = (0, import_node_child_process12.spawn)(command, args, { cwd, stdio: "inherit" });
|
|
18983
19185
|
child.on("error", reject);
|
|
18984
19186
|
child.on("close", (code) => {
|
|
18985
19187
|
if (code === 0) resolve();
|
|
@@ -18989,7 +19191,7 @@ function runCommand(command, args, cwd) {
|
|
|
18989
19191
|
}
|
|
18990
19192
|
function runCommandCapture(command, args, cwd) {
|
|
18991
19193
|
return new Promise((resolve, reject) => {
|
|
18992
|
-
const child = (0,
|
|
19194
|
+
const child = (0, import_node_child_process12.spawn)(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
18993
19195
|
const chunks = [];
|
|
18994
19196
|
const errorChunks = [];
|
|
18995
19197
|
child.stdout?.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
@@ -19009,26 +19211,26 @@ async function runAndroidSdkToolCapture(toolName, args) {
|
|
|
19009
19211
|
return runCommandCapture(toolPath, args);
|
|
19010
19212
|
}
|
|
19011
19213
|
function findAndroidSdkTool(toolName) {
|
|
19012
|
-
const sdkRoots = [process.env.ANDROID_HOME, process.env.ANDROID_SDK_ROOT].filter((item) => Boolean(item)).map((item) =>
|
|
19214
|
+
const sdkRoots = [process.env.ANDROID_HOME, process.env.ANDROID_SDK_ROOT].filter((item) => Boolean(item)).map((item) => import_node_path28.default.resolve(item));
|
|
19013
19215
|
for (const sdkRoot of sdkRoots) {
|
|
19014
|
-
const candidates = toolName === "aapt" || toolName === "apksigner" ? listVersionedToolCandidates(
|
|
19015
|
-
|
|
19016
|
-
...listVersionedToolCandidates(
|
|
19017
|
-
|
|
19216
|
+
const candidates = toolName === "aapt" || toolName === "apksigner" ? listVersionedToolCandidates(import_node_path28.default.join(sdkRoot, "build-tools"), toolName) : [
|
|
19217
|
+
import_node_path28.default.join(sdkRoot, "cmdline-tools", "latest", "bin", toolName),
|
|
19218
|
+
...listVersionedToolCandidates(import_node_path28.default.join(sdkRoot, "cmdline-tools"), import_node_path28.default.join("bin", toolName)),
|
|
19219
|
+
import_node_path28.default.join(sdkRoot, "tools", "bin", toolName)
|
|
19018
19220
|
];
|
|
19019
|
-
const match = candidates.find((candidate) => (0,
|
|
19221
|
+
const match = candidates.find((candidate) => (0, import_node_fs23.existsSync)(candidate));
|
|
19020
19222
|
if (match) return match;
|
|
19021
19223
|
}
|
|
19022
19224
|
return void 0;
|
|
19023
19225
|
}
|
|
19024
19226
|
function listVersionedToolCandidates(parentDir, relativeToolPath) {
|
|
19025
|
-
if (!(0,
|
|
19026
|
-
return (0,
|
|
19227
|
+
if (!(0, import_node_fs23.existsSync)(parentDir)) return [];
|
|
19228
|
+
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
19229
|
}
|
|
19028
19230
|
function sha256File(filePath) {
|
|
19029
19231
|
return new Promise((resolve, reject) => {
|
|
19030
19232
|
const hash = (0, import_node_crypto6.createHash)("sha256");
|
|
19031
|
-
const stream = (0,
|
|
19233
|
+
const stream = (0, import_node_fs23.createReadStream)(filePath);
|
|
19032
19234
|
stream.on("data", (chunk) => hash.update(chunk));
|
|
19033
19235
|
stream.on("error", reject);
|
|
19034
19236
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -19045,22 +19247,22 @@ function capitalize(value) {
|
|
|
19045
19247
|
}
|
|
19046
19248
|
|
|
19047
19249
|
// src/services/HarmonyReleaseService.ts
|
|
19048
|
-
var
|
|
19250
|
+
var import_node_child_process13 = require("child_process");
|
|
19049
19251
|
var import_node_crypto7 = require("crypto");
|
|
19050
|
-
var
|
|
19051
|
-
var
|
|
19052
|
-
var
|
|
19252
|
+
var import_node_fs24 = require("fs");
|
|
19253
|
+
var import_node_os13 = __toESM(require("os"));
|
|
19254
|
+
var import_node_path29 = __toESM(require("path"));
|
|
19053
19255
|
var import_json5 = __toESM(require("json5"));
|
|
19054
19256
|
var HARMONY_SIGNING_KEYS = ["HARMONY_KEYSTORE_BASE64", "HARMONY_CERTIFICATE_BASE64", "HARMONY_PROFILE_BASE64", "HARMONY_STORE_PASSWORD", "HARMONY_KEY_ALIAS", "HARMONY_KEY_PASSWORD"];
|
|
19055
19257
|
var bucket = "parrot-static";
|
|
19056
19258
|
var baseUrl = "https://parrot-static.pmate.chat";
|
|
19057
19259
|
var inside = (parent, child) => {
|
|
19058
|
-
const rel =
|
|
19059
|
-
return !rel || !rel.startsWith(`..${
|
|
19260
|
+
const rel = import_node_path29.default.relative(parent, child);
|
|
19261
|
+
return !rel || !rel.startsWith(`..${import_node_path29.default.sep}`) && rel !== ".." && !import_node_path29.default.isAbsolute(rel);
|
|
19060
19262
|
};
|
|
19061
|
-
var readJson5 = (file) => import_json5.default.parse((0,
|
|
19263
|
+
var readJson5 = (file) => import_json5.default.parse((0, import_node_fs24.readFileSync)(file, "utf8"));
|
|
19062
19264
|
function readHarmonyVersion(appDir, expected) {
|
|
19063
|
-
const app = readJson5(
|
|
19265
|
+
const app = readJson5(import_node_path29.default.join(appDir, "AppScope/app.json5")).app;
|
|
19064
19266
|
if (!app || app.bundleName !== expected) throw new Error("HarmonyOS bundleName does not match service.mobile.bundleName");
|
|
19065
19267
|
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
19268
|
return { bundleName: app.bundleName, versionName: app.versionName, versionCode: app.versionCode };
|
|
@@ -19071,25 +19273,25 @@ function stageHarmonySources(repoRoot, appDir, target) {
|
|
|
19071
19273
|
const copy = (source) => {
|
|
19072
19274
|
if (!inside(repoRoot, source)) throw new Error("HarmonyOS local dependencies must stay inside the repository");
|
|
19073
19275
|
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 =
|
|
19276
|
+
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");
|
|
19277
|
+
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");
|
|
19278
|
+
const dest = import_node_path29.default.join(target, import_node_path29.default.relative(repoRoot, source));
|
|
19279
|
+
(0, import_node_fs24.cpSync)(source, dest, { recursive: true, filter: (file) => {
|
|
19280
|
+
if ((0, import_node_fs24.lstatSync)(file).isSymbolicLink()) throw new Error("HarmonyOS source symlinks are not supported");
|
|
19281
|
+
const name = import_node_path29.default.basename(file);
|
|
19080
19282
|
return !excluded.has(name) && !name.startsWith(".env") && !/\.(p12|pfx|p7b|keystore|jks|key|pem|cer)$/i.test(name);
|
|
19081
19283
|
} });
|
|
19082
19284
|
copied.push(source);
|
|
19083
19285
|
const inspect = (dir) => {
|
|
19084
|
-
for (const entry of (0,
|
|
19085
|
-
const file =
|
|
19286
|
+
for (const entry of (0, import_node_fs24.readdirSync)(dir, { withFileTypes: true })) {
|
|
19287
|
+
const file = import_node_path29.default.join(dir, entry.name);
|
|
19086
19288
|
if (entry.isDirectory()) inspect(file);
|
|
19087
19289
|
else if (entry.name === "oh-package.json5") {
|
|
19088
19290
|
const manifest = readJson5(file);
|
|
19089
19291
|
for (const value of Object.values({ ...manifest.dependencies, ...manifest.devDependencies })) {
|
|
19090
19292
|
if (typeof value !== "string" || !value.startsWith("file:")) continue;
|
|
19091
|
-
const original =
|
|
19092
|
-
copy(
|
|
19293
|
+
const original = import_node_path29.default.join(repoRoot, import_node_path29.default.relative(target, import_node_path29.default.dirname(file)));
|
|
19294
|
+
copy(import_node_path29.default.resolve(original, value.slice(5)));
|
|
19093
19295
|
}
|
|
19094
19296
|
}
|
|
19095
19297
|
}
|
|
@@ -19097,19 +19299,19 @@ function stageHarmonySources(repoRoot, appDir, target) {
|
|
|
19097
19299
|
inspect(dest);
|
|
19098
19300
|
};
|
|
19099
19301
|
copy(appDir);
|
|
19100
|
-
const profile = readJson5(
|
|
19302
|
+
const profile = readJson5(import_node_path29.default.join(appDir, "build-profile.json5"));
|
|
19101
19303
|
for (const module2 of profile.modules ?? []) {
|
|
19102
19304
|
if (typeof module2.srcPath !== "string") throw new Error("Invalid HarmonyOS module srcPath");
|
|
19103
|
-
copy(
|
|
19305
|
+
copy(import_node_path29.default.resolve(appDir, module2.srcPath));
|
|
19104
19306
|
}
|
|
19105
|
-
return
|
|
19307
|
+
return import_node_path29.default.join(target, import_node_path29.default.relative(repoRoot, appDir));
|
|
19106
19308
|
}
|
|
19107
19309
|
function executable(value) {
|
|
19108
|
-
const candidates = value.includes(
|
|
19310
|
+
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
19311
|
for (const file of candidates) {
|
|
19110
19312
|
try {
|
|
19111
|
-
(0,
|
|
19112
|
-
if ((0,
|
|
19313
|
+
(0, import_node_fs24.accessSync)(file, import_node_fs24.constants.X_OK);
|
|
19314
|
+
if ((0, import_node_fs24.lstatSync)(file).isFile() || (0, import_node_fs24.lstatSync)(file).isSymbolicLink()) return file;
|
|
19113
19315
|
} catch {
|
|
19114
19316
|
}
|
|
19115
19317
|
}
|
|
@@ -19118,14 +19320,14 @@ function executable(value) {
|
|
|
19118
19320
|
function findHarmonyTools() {
|
|
19119
19321
|
if (!["darwin", "linux"].includes(process.platform)) throw new Error("HarmonyOS release scripts require macOS or Linux");
|
|
19120
19322
|
const home = "/Applications/DevEco-Studio.app/Contents";
|
|
19121
|
-
const sdk =
|
|
19122
|
-
if (!(0,
|
|
19323
|
+
const sdk = import_node_path29.default.resolve(process.env.DEVECO_SDK_HOME ?? `${home}/sdk`);
|
|
19324
|
+
if (!(0, import_node_fs24.existsSync)(sdk)) throw new Error("HarmonyOS SDK not found; install DevEco Studio or set DEVECO_SDK_HOME");
|
|
19123
19325
|
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
19326
|
if (!tools.signer) {
|
|
19125
19327
|
const jars = [];
|
|
19126
19328
|
const scan = (dir) => {
|
|
19127
|
-
for (const entry of (0,
|
|
19128
|
-
const file =
|
|
19329
|
+
for (const entry of (0, import_node_fs24.readdirSync)(dir, { withFileTypes: true })) {
|
|
19330
|
+
const file = import_node_path29.default.join(dir, entry.name);
|
|
19129
19331
|
if (entry.isDirectory()) scan(file);
|
|
19130
19332
|
else if (entry.isFile() && entry.name === "hap-sign-tool.jar") jars.push(file);
|
|
19131
19333
|
}
|
|
@@ -19134,18 +19336,18 @@ function findHarmonyTools() {
|
|
|
19134
19336
|
if (jars.length !== 1) throw new Error("Set HAP_SIGN_TOOL to the intended hap-sign-tool.jar");
|
|
19135
19337
|
tools.signer = jars[0];
|
|
19136
19338
|
}
|
|
19137
|
-
tools.signer =
|
|
19138
|
-
if (!(0,
|
|
19339
|
+
tools.signer = import_node_path29.default.resolve(tools.signer);
|
|
19340
|
+
if (!(0, import_node_fs24.existsSync)(tools.signer)) throw new Error("HAP_SIGN_TOOL does not exist");
|
|
19139
19341
|
executable("bash");
|
|
19140
19342
|
executable("unzip");
|
|
19141
19343
|
return tools;
|
|
19142
19344
|
}
|
|
19143
19345
|
var runHarmonyCommand = async (command, args, options) => {
|
|
19144
|
-
const log = (0,
|
|
19145
|
-
const output = options.output ? (0,
|
|
19346
|
+
const log = (0, import_node_fs24.openSync)(options.log, "a", 384);
|
|
19347
|
+
const output = options.output ? (0, import_node_fs24.openSync)(options.output, "w", 384) : void 0;
|
|
19146
19348
|
try {
|
|
19147
19349
|
return await new Promise((resolve, reject) => {
|
|
19148
|
-
const child = (0,
|
|
19350
|
+
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
19351
|
let text = "", oversized = false;
|
|
19150
19352
|
child.stdout?.on("data", (chunk) => {
|
|
19151
19353
|
if (Buffer.byteLength(text) + chunk.length > 1024 * 1024) {
|
|
@@ -19168,16 +19370,16 @@ var runHarmonyCommand = async (command, args, options) => {
|
|
|
19168
19370
|
};
|
|
19169
19371
|
child.once("error", () => {
|
|
19170
19372
|
clean();
|
|
19171
|
-
reject(new Error(`Cannot run ${
|
|
19373
|
+
reject(new Error(`Cannot run ${import_node_path29.default.basename(command)}; see ${options.log}`));
|
|
19172
19374
|
});
|
|
19173
19375
|
child.once("close", (code) => {
|
|
19174
19376
|
clean();
|
|
19175
|
-
code === 0 && !oversized ? resolve(text) : reject(new Error(`HarmonyOS ${
|
|
19377
|
+
code === 0 && !oversized ? resolve(text) : reject(new Error(`HarmonyOS ${import_node_path29.default.basename(command)} failed (${code}); see ${options.log}`));
|
|
19176
19378
|
});
|
|
19177
19379
|
});
|
|
19178
19380
|
} finally {
|
|
19179
|
-
(0,
|
|
19180
|
-
if (output !== void 0) (0,
|
|
19381
|
+
(0, import_node_fs24.closeSync)(log);
|
|
19382
|
+
if (output !== void 0) (0, import_node_fs24.closeSync)(output);
|
|
19181
19383
|
}
|
|
19182
19384
|
};
|
|
19183
19385
|
function signingMaterial(values) {
|
|
@@ -19221,14 +19423,14 @@ var HarmonyReleaseService = class {
|
|
|
19221
19423
|
if (!("type" in service) || service.type !== "harmonyos" || !service.mobile || !("bundleName" in service.mobile)) throw new Error("HarmonyOS requires service.mobile.bundleName");
|
|
19222
19424
|
if (service.appIds?.length !== 1) throw new Error("HarmonyOS service requires exactly one appIds application identity");
|
|
19223
19425
|
const application = service.appIds[0];
|
|
19224
|
-
const root = options.cwd ?
|
|
19426
|
+
const root = options.cwd ? import_node_path29.default.resolve(options.cwd) : resolveRepositoryLocalRoot(service.repository ?? service.mobile.repository ?? "");
|
|
19225
19427
|
const dir = service.dir ?? service.mobile.dir;
|
|
19226
19428
|
if (!dir) throw new Error("HarmonyOS service requires a source directory");
|
|
19227
|
-
const appDir =
|
|
19429
|
+
const appDir = import_node_path29.default.resolve(root, dir);
|
|
19228
19430
|
if (!inside(root, appDir)) throw new Error("HarmonyOS source must stay inside the repository");
|
|
19229
19431
|
const version = readHarmonyVersion(appDir, service.mobile.bundleName);
|
|
19230
19432
|
const script = service.build?.script ?? "scripts/build-release.sh";
|
|
19231
|
-
if (
|
|
19433
|
+
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
19434
|
const prefix = `harmony/${service.namespace}/${service.name}`;
|
|
19233
19435
|
if (![service.namespace, service.name].every((v) => /^[\w-]+$/.test(v))) throw new Error("Invalid HarmonyOS service identity");
|
|
19234
19436
|
const releasePrefix = `${prefix}/${version.versionName}/${version.versionCode}/`;
|
|
@@ -19246,67 +19448,67 @@ var HarmonyReleaseService = class {
|
|
|
19246
19448
|
if (!this.registry) throw new Error("HarmonyOS signing requires the service environment registry");
|
|
19247
19449
|
const { values } = await this.registry.resolveEnv(service.id, { stage: "prod", includeSecretValue: true, includeHost: false });
|
|
19248
19450
|
const material = signingMaterial(values);
|
|
19249
|
-
const outputBase = options.outDir ?
|
|
19451
|
+
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
19452
|
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,
|
|
19453
|
+
(0, import_node_fs24.mkdirSync)(outputBase, { recursive: true, mode: 448 });
|
|
19454
|
+
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");
|
|
19455
|
+
(0, import_node_fs24.writeFileSync)(log, "", { mode: 384 });
|
|
19456
|
+
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
19457
|
let artifacts = [];
|
|
19256
19458
|
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,
|
|
19459
|
+
const staged = stageHarmonySources(root, appDir, import_node_path29.default.join(temp, "checkout"));
|
|
19460
|
+
for (const relative2 of ["build-profile.json5", "AppScope/app.json5"]) {
|
|
19461
|
+
const file = import_node_path29.default.join(staged, relative2);
|
|
19462
|
+
(0, import_node_fs24.writeFileSync)(file, JSON.stringify(readJson5(file), null, 2));
|
|
19463
|
+
}
|
|
19464
|
+
const keys = import_node_path29.default.join(temp, "signing");
|
|
19465
|
+
(0, import_node_fs24.mkdirSync)(keys, { mode: 448 });
|
|
19466
|
+
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
19467
|
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:
|
|
19468
|
+
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
19469
|
const opts = { cwd: staged, env, log };
|
|
19268
|
-
await
|
|
19269
|
-
const dist =
|
|
19270
|
-
const files = (0,
|
|
19470
|
+
await run2("bash", [import_node_path29.default.resolve(staged, script)], opts);
|
|
19471
|
+
const dist = import_node_path29.default.join(staged, "dist");
|
|
19472
|
+
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
19473
|
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
19474
|
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
|
|
19475
|
+
const id = (0, import_node_crypto7.createHash)("sha256").update(file).digest("hex").slice(0, 16), cert = import_node_path29.default.join(temp, `${id}.cer`);
|
|
19476
|
+
await run2(tools.java, ["-jar", tools.signer, "verify-app", "-inFile", file, "-outCertChain", cert, "-outProfile", import_node_path29.default.join(temp, `${id}.p7b`)], opts);
|
|
19477
|
+
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");
|
|
19478
|
+
if (inspectMetadata) assertHarmonyMetadata(JSON.parse(await run2("unzip", ["-p", file, "module.json"], { ...opts, capture: true })), version);
|
|
19277
19479
|
};
|
|
19278
19480
|
for (const file of files) {
|
|
19279
19481
|
await check(file, file.endsWith(".hap"));
|
|
19280
19482
|
if (file.endsWith(".app")) {
|
|
19281
|
-
const names = (await
|
|
19483
|
+
const names = (await run2("unzip", ["-Z1", file], { ...opts, capture: true })).split(/\r?\n/).filter((name) => /\.(hap|hsp)$/.test(name));
|
|
19282
19484
|
if (!names.length) throw new Error("HarmonyOS APP contains no package modules");
|
|
19283
19485
|
for (const [index, name] of names.entries()) {
|
|
19284
19486
|
if (name.startsWith("/") || name.includes("\\") || name.split("/").includes("..")) throw new Error("Unsafe HarmonyOS archive member");
|
|
19285
|
-
const embedded =
|
|
19286
|
-
await
|
|
19487
|
+
const embedded = import_node_path29.default.join(temp, `module-${index}${import_node_path29.default.extname(name)}`);
|
|
19488
|
+
await run2("unzip", ["-p", file, name], { ...opts, output: embedded });
|
|
19287
19489
|
await check(embedded, true);
|
|
19288
19490
|
}
|
|
19289
19491
|
}
|
|
19290
19492
|
}
|
|
19291
19493
|
artifacts = [];
|
|
19292
19494
|
for (const file of files) {
|
|
19293
|
-
const name =
|
|
19495
|
+
const name = import_node_path29.default.basename(file);
|
|
19294
19496
|
if (!/^[A-Za-z0-9._-]+\.(app|hap)$/.test(name)) throw new Error("Invalid HarmonyOS artifact filename");
|
|
19295
|
-
const size = (0,
|
|
19497
|
+
const size = (0, import_node_fs24.statSync)(file).size;
|
|
19296
19498
|
if (!size) throw new Error("Empty HarmonyOS artifact");
|
|
19297
|
-
const target =
|
|
19298
|
-
(0,
|
|
19499
|
+
const target = import_node_path29.default.join(output, name);
|
|
19500
|
+
(0, import_node_fs24.cpSync)(file, target);
|
|
19299
19501
|
const hash = (0, import_node_crypto7.createHash)("sha256");
|
|
19300
|
-
for await (const chunk of (0,
|
|
19301
|
-
artifacts.push({ name, type:
|
|
19502
|
+
for await (const chunk of (0, import_node_fs24.createReadStream)(target)) hash.update(chunk);
|
|
19503
|
+
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
19504
|
}
|
|
19303
19505
|
} finally {
|
|
19304
|
-
(0,
|
|
19506
|
+
(0, import_node_fs24.rmSync)(temp, { recursive: true, force: true });
|
|
19305
19507
|
}
|
|
19306
19508
|
if (options.local) return { ...plan, status: "local", output, log, artifacts };
|
|
19307
19509
|
let revision;
|
|
19308
19510
|
try {
|
|
19309
|
-
revision = (0,
|
|
19511
|
+
revision = (0, import_node_child_process13.execFileSync)("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
19310
19512
|
} catch {
|
|
19311
19513
|
}
|
|
19312
19514
|
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 +19518,21 @@ var HarmonyReleaseService = class {
|
|
|
19316
19518
|
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
19519
|
if (latest && latest.versionCode >= version.versionCode) throw new Error("A same or newer HarmonyOS release was published during the build; latest is unchanged");
|
|
19318
19520
|
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(
|
|
19521
|
+
for (const artifact of artifacts) await upload(import_node_path29.default.join(output, artifact.name), bucket, artifact.objectKey, { "x-oss-forbid-overwrite": "true" });
|
|
19320
19522
|
await uploadJson(bucket, `${releasePrefix}release.json`, manifest, { "x-oss-forbid-overwrite": "true" });
|
|
19321
19523
|
await uploadJson(bucket, `${prefix}/latest.json`, manifest);
|
|
19322
19524
|
});
|
|
19323
|
-
(0,
|
|
19525
|
+
(0, import_node_fs24.writeFileSync)(import_node_path29.default.join(output, "release.json"), JSON.stringify(manifest, null, 2));
|
|
19324
19526
|
return { ...plan, status: "published", output, log, signature: "verified", artifacts };
|
|
19325
19527
|
}
|
|
19326
19528
|
};
|
|
19327
19529
|
|
|
19328
19530
|
// src/services/IosBuildService.ts
|
|
19329
|
-
var
|
|
19531
|
+
var import_node_child_process14 = require("child_process");
|
|
19330
19532
|
var import_node_crypto8 = require("crypto");
|
|
19331
|
-
var
|
|
19332
|
-
var
|
|
19333
|
-
var
|
|
19533
|
+
var import_node_fs25 = require("fs");
|
|
19534
|
+
var import_node_os14 = __toESM(require("os"));
|
|
19535
|
+
var import_node_path30 = __toESM(require("path"));
|
|
19334
19536
|
function iosBuildInteger(value) {
|
|
19335
19537
|
if (!/^(0|[1-9]\d*)$/.test(String(value)) || !Number.isSafeInteger(Number(value))) {
|
|
19336
19538
|
throw new Error(`iOS Build must be a non-negative safe integer: ${String(value)}`);
|
|
@@ -19339,13 +19541,13 @@ function iosBuildInteger(value) {
|
|
|
19339
19541
|
}
|
|
19340
19542
|
async function runXcode(args, cwd, logPath) {
|
|
19341
19543
|
return new Promise((resolve, reject) => {
|
|
19342
|
-
const child = (0,
|
|
19544
|
+
const child = (0, import_node_child_process14.spawn)("xcodebuild", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
19343
19545
|
let output = "";
|
|
19344
19546
|
child.stdout.on("data", (chunk) => {
|
|
19345
19547
|
if (args.includes("-json") || args.includes("-version")) output += chunk.toString();
|
|
19346
|
-
(0,
|
|
19548
|
+
(0, import_node_fs25.appendFileSync)(logPath, chunk);
|
|
19347
19549
|
});
|
|
19348
|
-
child.stderr.on("data", (chunk) => (0,
|
|
19550
|
+
child.stderr.on("data", (chunk) => (0, import_node_fs25.appendFileSync)(logPath, chunk));
|
|
19349
19551
|
child.on("error", reject);
|
|
19350
19552
|
child.on("close", (code) => code === 0 ? resolve(output) : reject(new Error(`xcodebuild failed (${code}); see ${logPath}`)));
|
|
19351
19553
|
});
|
|
@@ -19364,23 +19566,23 @@ var IosBuildService = class {
|
|
|
19364
19566
|
const repository = service.repository ?? service.mobile?.repository;
|
|
19365
19567
|
const dir = service.dir ?? service.mobile?.dir;
|
|
19366
19568
|
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,
|
|
19569
|
+
const repoRoot = options.cwd ? import_node_path30.default.resolve(options.cwd) : resolveRepositoryLocalRoot(repository);
|
|
19570
|
+
const appDir = import_node_path30.default.resolve(repoRoot, dir);
|
|
19571
|
+
if (!(0, import_node_fs25.existsSync)(appDir)) throw new Error(`iOS app dir not found: ${appDir}`);
|
|
19370
19572
|
const explicit = options.project ?? options.workspace;
|
|
19371
|
-
const candidates = explicit ? [
|
|
19372
|
-
if (candidates.length !== 1 || !(0,
|
|
19573
|
+
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));
|
|
19574
|
+
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
19575
|
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
|
|
19576
|
+
const expectedExtension = options.workspace ? ".xcworkspace" : options.project ? ".xcodeproj" : import_node_path30.default.extname(project);
|
|
19577
|
+
if (![".xcodeproj", ".xcworkspace"].includes(expectedExtension) || import_node_path30.default.extname(project) !== expectedExtension) throw new Error("Invalid Xcode project/workspace extension");
|
|
19578
|
+
const root = this.deps.stateRoot ?? import_node_path30.default.join(import_node_os14.default.homedir(), ".pmate", "ios-builds");
|
|
19579
|
+
(0, import_node_fs25.mkdirSync)(root, { recursive: true, mode: 448 });
|
|
19580
|
+
const preflightLog = import_node_path30.default.join(root, `preflight-${process.pid}-${Date.now()}.log`);
|
|
19581
|
+
const run2 = this.deps.run ?? runXcode;
|
|
19582
|
+
await run2(["-version"], appDir, preflightLog);
|
|
19381
19583
|
const common2 = [expectedExtension === ".xcworkspace" ? "-workspace" : "-project", project, "-scheme", options.scheme, "-configuration", "Release", "-destination", "generic/platform=iOS"];
|
|
19382
19584
|
if (options.team) common2.push(`DEVELOPMENT_TEAM=${options.team}`);
|
|
19383
|
-
const settings = JSON.parse(await
|
|
19585
|
+
const settings = JSON.parse(await run2([...common2, "-showBuildSettings", "-json"], appDir, preflightLog));
|
|
19384
19586
|
const apps = settings.filter((item) => item.buildSettings.PRODUCT_TYPE === "com.apple.product-type.application");
|
|
19385
19587
|
if (apps.length !== 1) throw new Error("Scheme must contain exactly one application target");
|
|
19386
19588
|
const cfg = apps[0].buildSettings;
|
|
@@ -19391,18 +19593,18 @@ var IosBuildService = class {
|
|
|
19391
19593
|
if (service.mobile && "bundleId" in service.mobile && service.mobile.bundleId !== bundleId) throw new Error("Service bundle ID does not match application target");
|
|
19392
19594
|
const currentBuild = iosBuildInteger(cfg.CURRENT_PROJECT_VERSION);
|
|
19393
19595
|
const key = (0, import_node_crypto8.createHash)("sha256").update(bundleId).digest("hex");
|
|
19394
|
-
const statePath =
|
|
19395
|
-
const lockPath =
|
|
19596
|
+
const statePath = import_node_path30.default.join(root, `${key}.json`);
|
|
19597
|
+
const lockPath = import_node_path30.default.join(root, `${key}.lock`);
|
|
19396
19598
|
let lock;
|
|
19397
19599
|
try {
|
|
19398
|
-
lock = (0,
|
|
19600
|
+
lock = (0, import_node_fs25.openSync)(lockPath, "wx", 384);
|
|
19399
19601
|
} catch (error) {
|
|
19400
19602
|
if (error.code === "EEXIST") throw new Error(`iOS build already locked: ${lockPath}. Remove only after confirming no build is running.`);
|
|
19401
19603
|
throw error;
|
|
19402
19604
|
}
|
|
19403
19605
|
try {
|
|
19404
|
-
(0,
|
|
19405
|
-
const previous = (0,
|
|
19606
|
+
(0, import_node_fs25.writeFileSync)(lock, JSON.stringify({ pid: process.pid, bundleId }));
|
|
19607
|
+
const previous = (0, import_node_fs25.existsSync)(statePath) ? JSON.parse((0, import_node_fs25.readFileSync)(statePath, "utf8")) : void 0;
|
|
19406
19608
|
if (previous && previous.bundleId !== bundleId) throw new Error("iOS build state bundle ID mismatch");
|
|
19407
19609
|
const buildsByVersion = { ...previous?.buildsByVersion };
|
|
19408
19610
|
if (previous) buildsByVersion[previous.version] = Math.max(buildsByVersion[previous.version] ?? 0, iosBuildInteger(previous.build));
|
|
@@ -19410,52 +19612,52 @@ var IosBuildService = class {
|
|
|
19410
19612
|
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
19613
|
const build = Math.max(currentBuild, priorBuild ?? 0, options.lastBuild ?? 0) + 1;
|
|
19412
19614
|
iosBuildInteger(build);
|
|
19413
|
-
const buildDir =
|
|
19414
|
-
(0,
|
|
19415
|
-
const archivePath =
|
|
19416
|
-
const logPath =
|
|
19615
|
+
const buildDir = import_node_path30.default.join(root, key, `${version}-${build}`);
|
|
19616
|
+
(0, import_node_fs25.mkdirSync)(buildDir, { recursive: true, mode: 448 });
|
|
19617
|
+
const archivePath = import_node_path30.default.join(buildDir, "App.xcarchive");
|
|
19618
|
+
const logPath = import_node_path30.default.join(buildDir, "build.log");
|
|
19417
19619
|
buildsByVersion[version] = build;
|
|
19418
19620
|
const state = { bundleId, version, build, buildsByVersion, status: "reserved", archivePath, logPath };
|
|
19419
19621
|
const persist = () => {
|
|
19420
19622
|
const temp = `${statePath}.${process.pid}.tmp`;
|
|
19421
|
-
(0,
|
|
19422
|
-
(0,
|
|
19623
|
+
(0, import_node_fs25.writeFileSync)(temp, JSON.stringify(state, null, 2) + "\n", { mode: 384 });
|
|
19624
|
+
(0, import_node_fs25.renameSync)(temp, statePath);
|
|
19423
19625
|
};
|
|
19424
19626
|
persist();
|
|
19425
|
-
(0,
|
|
19627
|
+
(0, import_node_fs25.writeFileSync)(logPath, `Service ${service.id}: ${bundleId} ${version} (${build})
|
|
19426
19628
|
Preflight log: ${preflightLog}
|
|
19427
19629
|
`, { mode: 384 });
|
|
19428
19630
|
try {
|
|
19429
|
-
await
|
|
19430
|
-
const applications =
|
|
19431
|
-
const builtApps = (0,
|
|
19631
|
+
await run2([...common2, `CURRENT_PROJECT_VERSION=${build}`, `MARKETING_VERSION=${version}`, "-archivePath", archivePath, "-derivedDataPath", import_node_path30.default.join(buildDir, "DerivedData"), "-allowProvisioningUpdates", "archive"], appDir, logPath);
|
|
19632
|
+
const applications = import_node_path30.default.join(archivePath, "Products", "Applications");
|
|
19633
|
+
const builtApps = (0, import_node_fs25.readdirSync)(applications).filter((name) => name.endsWith(".app"));
|
|
19432
19634
|
if (builtApps.length !== 1) throw new Error("Archive must contain exactly one application");
|
|
19433
|
-
const plist = (0,
|
|
19635
|
+
const plist = (0, import_node_fs25.readFileSync)(import_node_path30.default.join(applications, builtApps[0], "Info.plist"));
|
|
19434
19636
|
const info = await (this.deps.readPlist ?? readPlist)(plist);
|
|
19435
19637
|
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
|
|
19638
|
+
const exportPlist = import_node_path30.default.join(buildDir, "ExportOptions.plist");
|
|
19639
|
+
(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>`);
|
|
19640
|
+
await run2(["-exportArchive", "-archivePath", archivePath, "-exportOptionsPlist", exportPlist, "-exportPath", import_node_path30.default.join(buildDir, "export"), "-allowProvisioningUpdates"], appDir, logPath);
|
|
19439
19641
|
state.status = "uploaded-processing";
|
|
19440
19642
|
persist();
|
|
19441
19643
|
return { serviceId: service.id, bundleId, version, build, status: "uploaded-processing", archivePath, logPath };
|
|
19442
19644
|
} catch (error) {
|
|
19443
19645
|
state.status = "failed";
|
|
19444
19646
|
persist();
|
|
19445
|
-
(0,
|
|
19647
|
+
(0, import_node_fs25.appendFileSync)(logPath, `
|
|
19446
19648
|
${String(error)}
|
|
19447
19649
|
`);
|
|
19448
19650
|
throw new Error(`iOS Build ${build} failed; sequence reserved. See ${logPath}. ${String(error)}`);
|
|
19449
19651
|
}
|
|
19450
19652
|
} finally {
|
|
19451
|
-
(0,
|
|
19452
|
-
(0,
|
|
19653
|
+
(0, import_node_fs25.closeSync)(lock);
|
|
19654
|
+
(0, import_node_fs25.unlinkSync)(lockPath);
|
|
19453
19655
|
}
|
|
19454
19656
|
}
|
|
19455
19657
|
};
|
|
19456
19658
|
async function readPlist(input) {
|
|
19457
19659
|
return new Promise((resolve, reject) => {
|
|
19458
|
-
const child = (0,
|
|
19660
|
+
const child = (0, import_node_child_process14.spawn)("plutil", ["-convert", "json", "-o", "-", "--", "-"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
19459
19661
|
let output = "";
|
|
19460
19662
|
let error = "";
|
|
19461
19663
|
child.stdout.on("data", (chunk) => {
|
|
@@ -19501,9 +19703,9 @@ var NativeServiceDeploy = class {
|
|
|
19501
19703
|
const repository = service.repository ?? service.mobile?.repository;
|
|
19502
19704
|
const dir = service.dir ?? service.mobile?.dir;
|
|
19503
19705
|
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,
|
|
19706
|
+
const root = args.cwd ? import_node_path31.default.resolve(args.cwd) : resolveRepositoryLocalRoot(repository);
|
|
19707
|
+
const appDir = import_node_path31.default.resolve(root, dir);
|
|
19708
|
+
if (!(0, import_node_fs26.existsSync)(appDir)) throw new Error(`Service source directory not found: ${appDir}`);
|
|
19507
19709
|
const settings = service.build ?? {};
|
|
19508
19710
|
if (service.type === "harmonyos") {
|
|
19509
19711
|
rejectNativeOverrides(args, ["dryRun", "local", "outDir"]);
|
|
@@ -19537,10 +19739,10 @@ var NativeServiceDeploy = class {
|
|
|
19537
19739
|
const options2 = {
|
|
19538
19740
|
id: app,
|
|
19539
19741
|
target: "electron",
|
|
19540
|
-
config: args.config ?
|
|
19742
|
+
config: args.config ? import_node_path31.default.resolve(args.config) : import_node_path31.default.resolve(appDir, settings.config ?? "desktop.config.json"),
|
|
19541
19743
|
platform: args.platform ?? settings.platform ?? (process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : process.platform),
|
|
19542
19744
|
arch: args.arch ?? settings.arch ?? process.arch,
|
|
19543
|
-
outDir: args.outDir ?
|
|
19745
|
+
outDir: args.outDir ? import_node_path31.default.resolve(args.outDir) : import_node_path31.default.join(root, "release", service.name),
|
|
19544
19746
|
signed: !args.unsigned,
|
|
19545
19747
|
dir: !!args.dir,
|
|
19546
19748
|
dryRun: !!args.dryRun,
|
|
@@ -19653,10 +19855,10 @@ async function requestDeveloperLogTool(tool, params, fetcher = fetch, delegate)
|
|
|
19653
19855
|
}
|
|
19654
19856
|
|
|
19655
19857
|
// src/services/ServiceRuntimeRunner.ts
|
|
19656
|
-
var
|
|
19657
|
-
var
|
|
19658
|
-
var
|
|
19659
|
-
var
|
|
19858
|
+
var import_node_fs27 = require("fs");
|
|
19859
|
+
var import_node_os15 = __toESM(require("os"));
|
|
19860
|
+
var import_node_path32 = __toESM(require("path"));
|
|
19861
|
+
var import_node_child_process15 = require("child_process");
|
|
19660
19862
|
var import_node_readline = require("readline");
|
|
19661
19863
|
var import_chalk3 = __toESM(require("chalk"));
|
|
19662
19864
|
var import_dotenv = require("dotenv");
|
|
@@ -20155,7 +20357,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20155
20357
|
}
|
|
20156
20358
|
resolveRepoRoot(service, cwd) {
|
|
20157
20359
|
if (cwd) {
|
|
20158
|
-
return
|
|
20360
|
+
return import_node_path32.default.resolve(process.cwd(), cwd);
|
|
20159
20361
|
}
|
|
20160
20362
|
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
20363
|
if (repository) {
|
|
@@ -20163,8 +20365,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20163
20365
|
if (selected) return selected;
|
|
20164
20366
|
const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
|
|
20165
20367
|
if (repoName) {
|
|
20166
|
-
const candidate =
|
|
20167
|
-
if ((0,
|
|
20368
|
+
const candidate = import_node_path32.default.join(import_node_os15.default.homedir(), "dev", "pmate", repoName);
|
|
20369
|
+
if ((0, import_node_fs27.existsSync)(candidate)) {
|
|
20168
20370
|
return candidate;
|
|
20169
20371
|
}
|
|
20170
20372
|
}
|
|
@@ -20177,15 +20379,15 @@ var ServiceRuntimeRunner = class {
|
|
|
20177
20379
|
if (!dir) {
|
|
20178
20380
|
throw new Error(`Missing service dir for ${service.id}`);
|
|
20179
20381
|
}
|
|
20180
|
-
return
|
|
20382
|
+
return import_node_path32.default.resolve(repoRoot, dir);
|
|
20181
20383
|
}
|
|
20182
20384
|
async deployVite(service, options) {
|
|
20183
20385
|
this.assertDeployableStaticSite(service);
|
|
20184
20386
|
const repoRoot = this.resolveViteDeployRoot(service);
|
|
20185
20387
|
await this.checkoutViteMain(service, repoRoot);
|
|
20186
20388
|
const appDir = this.resolveLocalDir(service, repoRoot);
|
|
20187
|
-
const packageJsonPath =
|
|
20188
|
-
if (!(0,
|
|
20389
|
+
const packageJsonPath = import_node_path32.default.join(appDir, "package.json");
|
|
20390
|
+
if (!(0, import_node_fs27.existsSync)(packageJsonPath)) {
|
|
20189
20391
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20190
20392
|
}
|
|
20191
20393
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -20200,8 +20402,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20200
20402
|
repoRoot,
|
|
20201
20403
|
buildEnv
|
|
20202
20404
|
);
|
|
20203
|
-
const distDir =
|
|
20204
|
-
if (!(0,
|
|
20405
|
+
const distDir = import_node_path32.default.join(appDir, "dist");
|
|
20406
|
+
if (!(0, import_node_fs27.existsSync)(distDir)) {
|
|
20205
20407
|
throw new Error(`No dist directory found at ${distDir}`);
|
|
20206
20408
|
}
|
|
20207
20409
|
const site = this.getSite(service);
|
|
@@ -20216,7 +20418,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20216
20418
|
if (!/^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\/[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/.test(repository)) {
|
|
20217
20419
|
throw new Error(`Invalid repository: ${repository}; expected owner/name`);
|
|
20218
20420
|
}
|
|
20219
|
-
return
|
|
20421
|
+
return import_node_path32.default.join(import_node_os15.default.homedir(), ".pmate", "service-deploy", "repos", repository.toLowerCase());
|
|
20220
20422
|
}
|
|
20221
20423
|
async checkoutViteMain(service, repoRoot) {
|
|
20222
20424
|
const repository = this.getRepoStaticSite(service).repository;
|
|
@@ -20228,9 +20430,9 @@ var ServiceRuntimeRunner = class {
|
|
|
20228
20430
|
gitEnv.GIT_CONFIG_KEY_0 = "http.https://github.com/.extraheader";
|
|
20229
20431
|
gitEnv.GIT_CONFIG_VALUE_0 = `Authorization: Basic ${Buffer.from(`x-access-token:${token}`).toString("base64")}`;
|
|
20230
20432
|
}
|
|
20231
|
-
if (!(0,
|
|
20232
|
-
(0,
|
|
20233
|
-
await this.runCommandWithEnv("git", ["clone", "--branch", "main", "--single-branch", "--", repoUrl, repoRoot],
|
|
20433
|
+
if (!(0, import_node_fs27.existsSync)(repoRoot)) {
|
|
20434
|
+
(0, import_node_fs27.mkdirSync)(import_node_path32.default.dirname(repoRoot), { recursive: true });
|
|
20435
|
+
await this.runCommandWithEnv("git", ["clone", "--branch", "main", "--single-branch", "--", repoUrl, repoRoot], import_node_path32.default.dirname(repoRoot), gitEnv);
|
|
20234
20436
|
}
|
|
20235
20437
|
ui.info(`Deployment checkout: ${repoRoot}`);
|
|
20236
20438
|
ui.info(`Updating ${repository} to latest main for Vite deployment`);
|
|
@@ -20260,8 +20462,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20260
20462
|
async deployStatic(service, options) {
|
|
20261
20463
|
this.assertDeployableStaticSite(service);
|
|
20262
20464
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20263
|
-
const srcDir =
|
|
20264
|
-
if (!(0,
|
|
20465
|
+
const srcDir = import_node_path32.default.join(appDir, "src");
|
|
20466
|
+
if (!(0, import_node_fs27.existsSync)(srcDir)) {
|
|
20265
20467
|
throw new Error(`No src directory found at ${srcDir}`);
|
|
20266
20468
|
}
|
|
20267
20469
|
const site = this.getSite(service);
|
|
@@ -20295,8 +20497,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20295
20497
|
this.validateFcConfig(service, fc);
|
|
20296
20498
|
const repoRoot = this.resolveRepoRoot(service, options.cwd);
|
|
20297
20499
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20298
|
-
const packageJsonPath =
|
|
20299
|
-
if (!(0,
|
|
20500
|
+
const packageJsonPath = import_node_path32.default.join(appDir, "package.json");
|
|
20501
|
+
if (!(0, import_node_fs27.existsSync)(packageJsonPath)) {
|
|
20300
20502
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20301
20503
|
}
|
|
20302
20504
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -20349,15 +20551,15 @@ var ServiceRuntimeRunner = class {
|
|
|
20349
20551
|
const repoRoot = this.resolveRepoRoot(service, options.cwd);
|
|
20350
20552
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20351
20553
|
await this.ensurePnpmWorkspaceRoot(repoRoot);
|
|
20352
|
-
const configPath =
|
|
20353
|
-
if (!(0,
|
|
20554
|
+
const configPath = import_node_path32.default.join(appDir, fc.configFile ?? "s.yaml");
|
|
20555
|
+
if (!(0, import_node_fs27.existsSync)(configPath)) {
|
|
20354
20556
|
throw new Error(`Missing FC config file at ${configPath}`);
|
|
20355
20557
|
}
|
|
20356
|
-
const packageJsonPath =
|
|
20357
|
-
if (!(0,
|
|
20558
|
+
const packageJsonPath = import_node_path32.default.join(appDir, "package.json");
|
|
20559
|
+
if (!(0, import_node_fs27.existsSync)(packageJsonPath)) {
|
|
20358
20560
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20359
20561
|
}
|
|
20360
|
-
const rawConfig = (0,
|
|
20562
|
+
const rawConfig = (0, import_node_fs27.readFileSync)(configPath, "utf8");
|
|
20361
20563
|
if (!rawConfig.includes(fc.functionName)) {
|
|
20362
20564
|
throw new Error(`FC config ${configPath} does not mention functionName ${fc.functionName}`);
|
|
20363
20565
|
}
|
|
@@ -20647,7 +20849,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20647
20849
|
const serverAddress = await resolveServerAddress(server);
|
|
20648
20850
|
const templateName = exposeType === "websocket" ? "nginx.ws.template" : exposeType === "mixed" ? "nginx.mixed.template" : "nginx.rest.template";
|
|
20649
20851
|
const templatePath = this.resolveTemplatePath(templateName);
|
|
20650
|
-
const template = (0,
|
|
20852
|
+
const template = (0, import_node_fs27.readFileSync)(templatePath, "utf8");
|
|
20651
20853
|
const host = `${subdomain}.${("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat"}`;
|
|
20652
20854
|
const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
|
|
20653
20855
|
const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
|
|
@@ -20679,11 +20881,11 @@ var ServiceRuntimeRunner = class {
|
|
|
20679
20881
|
}
|
|
20680
20882
|
if (config.ensurePackageJson) {
|
|
20681
20883
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20682
|
-
const packageJsonPath =
|
|
20683
|
-
if (!(0,
|
|
20884
|
+
const packageJsonPath = import_node_path32.default.join(appDir, "package.json");
|
|
20885
|
+
if (!(0, import_node_fs27.existsSync)(packageJsonPath)) {
|
|
20684
20886
|
throw new Error(`Missing package.json at ${packageJsonPath}`);
|
|
20685
20887
|
}
|
|
20686
|
-
const pkgStat = (0,
|
|
20888
|
+
const pkgStat = (0, import_node_fs27.statSync)(packageJsonPath);
|
|
20687
20889
|
if (!pkgStat.isFile()) {
|
|
20688
20890
|
throw new Error(`package.json is not a file at ${packageJsonPath}`);
|
|
20689
20891
|
}
|
|
@@ -21094,13 +21296,13 @@ var ServiceRuntimeRunner = class {
|
|
|
21094
21296
|
return tokens;
|
|
21095
21297
|
}
|
|
21096
21298
|
readPathValue(source, pathExpr) {
|
|
21097
|
-
const
|
|
21299
|
+
const path37 = pathExpr.split(".").map((segment2) => segment2.trim()).filter(Boolean);
|
|
21098
21300
|
let cursor = source;
|
|
21099
|
-
for (const
|
|
21301
|
+
for (const segment2 of path37) {
|
|
21100
21302
|
if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
|
|
21101
21303
|
return void 0;
|
|
21102
21304
|
}
|
|
21103
|
-
cursor = cursor[
|
|
21305
|
+
cursor = cursor[segment2];
|
|
21104
21306
|
}
|
|
21105
21307
|
return cursor;
|
|
21106
21308
|
}
|
|
@@ -21139,12 +21341,12 @@ var ServiceRuntimeRunner = class {
|
|
|
21139
21341
|
}
|
|
21140
21342
|
resolveTemplatePath(templateName) {
|
|
21141
21343
|
const candidates = [
|
|
21142
|
-
|
|
21143
|
-
|
|
21144
|
-
|
|
21344
|
+
import_node_path32.default.join(__dirname, "..", "templates", templateName),
|
|
21345
|
+
import_node_path32.default.join(__dirname, "..", "src", "templates", templateName),
|
|
21346
|
+
import_node_path32.default.join(__dirname, "templates", templateName)
|
|
21145
21347
|
];
|
|
21146
21348
|
for (const candidate of candidates) {
|
|
21147
|
-
if ((0,
|
|
21349
|
+
if ((0, import_node_fs27.existsSync)(candidate)) {
|
|
21148
21350
|
return candidate;
|
|
21149
21351
|
}
|
|
21150
21352
|
}
|
|
@@ -21153,7 +21355,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21153
21355
|
writeRemoteConfig(server, content, remotePath) {
|
|
21154
21356
|
return new Promise((resolve, reject) => {
|
|
21155
21357
|
const target = `pmate@${server}`;
|
|
21156
|
-
const child = (0,
|
|
21358
|
+
const child = (0, import_node_child_process15.spawn)("ssh", [target, "sudo", "tee", remotePath], {
|
|
21157
21359
|
stdio: ["pipe", "inherit", "inherit"]
|
|
21158
21360
|
});
|
|
21159
21361
|
child.on("error", reject);
|
|
@@ -21168,7 +21370,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21168
21370
|
reloadNginx(server) {
|
|
21169
21371
|
return new Promise((resolve, reject) => {
|
|
21170
21372
|
const target = `pmate@${server}`;
|
|
21171
|
-
const child = (0,
|
|
21373
|
+
const child = (0, import_node_child_process15.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
21172
21374
|
stdio: ["ignore", "inherit", "inherit"]
|
|
21173
21375
|
});
|
|
21174
21376
|
child.on("error", reject);
|
|
@@ -21176,7 +21378,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21176
21378
|
});
|
|
21177
21379
|
}
|
|
21178
21380
|
loadPackageJson(packageJsonPath) {
|
|
21179
|
-
const raw = (0,
|
|
21381
|
+
const raw = (0, import_node_fs27.readFileSync)(packageJsonPath, "utf8");
|
|
21180
21382
|
const parsed = JSON.parse(raw);
|
|
21181
21383
|
if (!parsed || typeof parsed !== "object") {
|
|
21182
21384
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -21185,7 +21387,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21185
21387
|
}
|
|
21186
21388
|
writePackageJson(packageJsonPath, data) {
|
|
21187
21389
|
const serialized = JSON.stringify(data, null, 2);
|
|
21188
|
-
(0,
|
|
21390
|
+
(0, import_node_fs27.writeFileSync)(packageJsonPath, `${serialized}
|
|
21189
21391
|
`, "utf8");
|
|
21190
21392
|
}
|
|
21191
21393
|
validateFcConfig(service, fc) {
|
|
@@ -21212,8 +21414,8 @@ var ServiceRuntimeRunner = class {
|
|
|
21212
21414
|
}
|
|
21213
21415
|
}
|
|
21214
21416
|
async ensurePnpmWorkspaceRoot(repoRoot) {
|
|
21215
|
-
const workspacePath =
|
|
21216
|
-
if (!(0,
|
|
21417
|
+
const workspacePath = import_node_path32.default.join(repoRoot, "pnpm-workspace.yaml");
|
|
21418
|
+
if (!(0, import_node_fs27.existsSync)(workspacePath)) {
|
|
21217
21419
|
throw new Error(`Missing pnpm-workspace.yaml at ${workspacePath}`);
|
|
21218
21420
|
}
|
|
21219
21421
|
}
|
|
@@ -21287,16 +21489,16 @@ var ServiceRuntimeRunner = class {
|
|
|
21287
21489
|
if (!privateKeyPath) {
|
|
21288
21490
|
throw new Error("Missing ssl.prv in ~/.pmate/config.yaml.");
|
|
21289
21491
|
}
|
|
21290
|
-
if (!(0,
|
|
21492
|
+
if (!(0, import_node_fs27.existsSync)(certificatePath)) {
|
|
21291
21493
|
throw new Error(`SSL certificate file not found: ${certificatePath}`);
|
|
21292
21494
|
}
|
|
21293
|
-
if (!(0,
|
|
21495
|
+
if (!(0, import_node_fs27.existsSync)(privateKeyPath)) {
|
|
21294
21496
|
throw new Error(`SSL private key file not found: ${privateKeyPath}`);
|
|
21295
21497
|
}
|
|
21296
21498
|
return {
|
|
21297
21499
|
certName: host,
|
|
21298
|
-
certificate: (0,
|
|
21299
|
-
privateKey: (0,
|
|
21500
|
+
certificate: (0, import_node_fs27.readFileSync)(certificatePath, "utf8"),
|
|
21501
|
+
privateKey: (0, import_node_fs27.readFileSync)(privateKeyPath, "utf8")
|
|
21300
21502
|
};
|
|
21301
21503
|
}
|
|
21302
21504
|
resolveFcProtocol(fc, certConfig) {
|
|
@@ -21355,7 +21557,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21355
21557
|
}
|
|
21356
21558
|
runCommandWithEnv(command, args, cwd, env) {
|
|
21357
21559
|
return new Promise((resolve, reject) => {
|
|
21358
|
-
const child = (0,
|
|
21560
|
+
const child = (0, import_node_child_process15.spawn)(command, args, {
|
|
21359
21561
|
cwd,
|
|
21360
21562
|
stdio: "inherit",
|
|
21361
21563
|
env: { ...process.env, ...env ?? {} }
|
|
@@ -21366,7 +21568,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21366
21568
|
}
|
|
21367
21569
|
runShellCommand(command, cwd, env) {
|
|
21368
21570
|
return new Promise((resolve, reject) => {
|
|
21369
|
-
const child = (0,
|
|
21571
|
+
const child = (0, import_node_child_process15.spawn)(command, [], {
|
|
21370
21572
|
cwd,
|
|
21371
21573
|
stdio: "inherit",
|
|
21372
21574
|
shell: true,
|
|
@@ -21377,12 +21579,12 @@ var ServiceRuntimeRunner = class {
|
|
|
21377
21579
|
});
|
|
21378
21580
|
}
|
|
21379
21581
|
runRemoteCommand(server, command) {
|
|
21380
|
-
if (server === "local") return this.runCommandWithEnv("bash", ["-c", command],
|
|
21582
|
+
if (server === "local") return this.runCommandWithEnv("bash", ["-c", command], import_node_os15.default.homedir());
|
|
21381
21583
|
return new Promise((resolve, reject) => {
|
|
21382
21584
|
const target = `pmate@${server}`;
|
|
21383
|
-
const child = (0,
|
|
21585
|
+
const child = (0, import_node_child_process15.spawn)("ssh", [target, "bash -ls"], { stdio: ["pipe", "inherit", "inherit"] });
|
|
21384
21586
|
child.stdin.on("error", reject);
|
|
21385
|
-
child.stdin.end(`${command}
|
|
21587
|
+
child.stdin.end(`${remoteGitAuthorization(command, process.env.PMATE_DEPLOY_GIT_TOKEN)}
|
|
21386
21588
|
`);
|
|
21387
21589
|
child.on("error", reject);
|
|
21388
21590
|
child.on("close", (code) => code === 0 ? resolve() : reject(new Error(`ssh to ${server} exited with code ${code}`)));
|
|
@@ -21435,6 +21637,12 @@ function parseServiceRef(serviceId) {
|
|
|
21435
21637
|
}
|
|
21436
21638
|
return { namespace, name };
|
|
21437
21639
|
}
|
|
21640
|
+
function remoteGitAuthorization(command, token) {
|
|
21641
|
+
if (!token) return command;
|
|
21642
|
+
const header = "AUTHORIZATION: basic " + Buffer.from("x-access-token:" + token).toString("base64");
|
|
21643
|
+
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 };
|
|
21644
|
+
return Object.entries(values).map(([key, value]) => "export " + key + "=" + shellQuote2(value)).join("\n") + "\n" + command;
|
|
21645
|
+
}
|
|
21438
21646
|
|
|
21439
21647
|
// src/commands/ServiceCommandHandler.ts
|
|
21440
21648
|
init_namespacedRef();
|
|
@@ -21770,7 +21978,7 @@ var ServiceCommandHandler = class {
|
|
|
21770
21978
|
format: "dotenv"
|
|
21771
21979
|
}
|
|
21772
21980
|
);
|
|
21773
|
-
const outputPath =
|
|
21981
|
+
const outputPath = import_node_path33.default.resolve(process.cwd(), args.output);
|
|
21774
21982
|
await (0, import_promises5.writeFile)(outputPath, payload.content, "utf8");
|
|
21775
21983
|
ui.success(`Wrote env file for ${args.appId} to ${outputPath}`);
|
|
21776
21984
|
this.renderJson({ ...payload, output: outputPath }, args.json);
|
|
@@ -21997,11 +22205,11 @@ var ServiceCommandHandler = class {
|
|
|
21997
22205
|
return (baseUrl2 || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
21998
22206
|
}
|
|
21999
22207
|
readJsonFile(filePath) {
|
|
22000
|
-
const absolutePath =
|
|
22001
|
-
if (!(0,
|
|
22208
|
+
const absolutePath = import_node_path33.default.resolve(process.cwd(), filePath);
|
|
22209
|
+
if (!(0, import_node_fs28.existsSync)(absolutePath)) {
|
|
22002
22210
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
22003
22211
|
}
|
|
22004
|
-
const raw = (0,
|
|
22212
|
+
const raw = (0, import_node_fs28.readFileSync)(absolutePath, "utf8");
|
|
22005
22213
|
try {
|
|
22006
22214
|
return JSON.parse(raw);
|
|
22007
22215
|
} catch (error) {
|
|
@@ -22525,7 +22733,7 @@ var ServiceCommandHandler = class {
|
|
|
22525
22733
|
removeRemoteConfig(server, remotePath) {
|
|
22526
22734
|
return new Promise((resolve, reject) => {
|
|
22527
22735
|
const target = `pmate@${server}`;
|
|
22528
|
-
const child = (0,
|
|
22736
|
+
const child = (0, import_node_child_process16.spawn)("ssh", [target, "sudo", "rm", "-f", remotePath], {
|
|
22529
22737
|
stdio: ["ignore", "inherit", "inherit"]
|
|
22530
22738
|
});
|
|
22531
22739
|
child.on("error", (error) => {
|
|
@@ -22543,7 +22751,7 @@ var ServiceCommandHandler = class {
|
|
|
22543
22751
|
reloadNginx(server) {
|
|
22544
22752
|
return new Promise((resolve, reject) => {
|
|
22545
22753
|
const target = `pmate@${server}`;
|
|
22546
|
-
const child = (0,
|
|
22754
|
+
const child = (0, import_node_child_process16.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
22547
22755
|
stdio: ["ignore", "inherit", "inherit"]
|
|
22548
22756
|
});
|
|
22549
22757
|
child.on("error", (error) => {
|
|
@@ -22616,9 +22824,9 @@ function sleep3(ms) {
|
|
|
22616
22824
|
}
|
|
22617
22825
|
|
|
22618
22826
|
// src/commands/VercelCommandHandler.ts
|
|
22619
|
-
var
|
|
22620
|
-
var
|
|
22621
|
-
var execFileAsync = (0,
|
|
22827
|
+
var import_node_child_process17 = require("child_process");
|
|
22828
|
+
var import_node_util2 = require("util");
|
|
22829
|
+
var execFileAsync = (0, import_node_util2.promisify)(import_node_child_process17.execFile);
|
|
22622
22830
|
function parseDeploymentTimestamp(deployment) {
|
|
22623
22831
|
const candidates = [deployment.createdAt, deployment.readyAt, deployment.ready];
|
|
22624
22832
|
for (const value of candidates) {
|
|
@@ -22727,8 +22935,8 @@ var RoleCommandHandler = class {
|
|
|
22727
22935
|
async handle(args) {
|
|
22728
22936
|
const token = readRequiredSession({ preferredApp: DEFAULT_APP_ID }).token;
|
|
22729
22937
|
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 +
|
|
22938
|
+
const request2 = async (method, path37, body) => {
|
|
22939
|
+
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
22940
|
const payload = await response.json().catch(() => null);
|
|
22733
22941
|
if (!response.ok || !payload?.success) throw new Error(payload?.message || `Request failed with status ${response.status}`);
|
|
22734
22942
|
return payload.data;
|
|
@@ -22762,9 +22970,9 @@ var RoleCommandHandler = class {
|
|
|
22762
22970
|
};
|
|
22763
22971
|
|
|
22764
22972
|
// src/commands/AccountCommandHandler.ts
|
|
22765
|
-
var
|
|
22973
|
+
var import_node_fs29 = require("fs");
|
|
22766
22974
|
var import_node_crypto9 = require("crypto");
|
|
22767
|
-
var
|
|
22975
|
+
var import_node_path34 = __toESM(require("path"));
|
|
22768
22976
|
init_sessionStore();
|
|
22769
22977
|
var AccountCommandHandler = class {
|
|
22770
22978
|
async handle(args) {
|
|
@@ -22772,9 +22980,9 @@ var AccountCommandHandler = class {
|
|
|
22772
22980
|
case "bot-keygen": {
|
|
22773
22981
|
const keyFile = this.generateBotKeyFile(args.app, args.name);
|
|
22774
22982
|
const outPath = args.out ? this.resolveFilePath(args.out) : this.resolveDefaultBotKeyPath(args.app, args.name);
|
|
22775
|
-
(0,
|
|
22776
|
-
(0,
|
|
22777
|
-
(0,
|
|
22983
|
+
(0, import_node_fs29.mkdirSync)(import_node_path34.default.dirname(outPath), { recursive: true });
|
|
22984
|
+
(0, import_node_fs29.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
22985
|
+
(0, import_node_fs29.chmodSync)(outPath, 384);
|
|
22778
22986
|
if (!args.json) {
|
|
22779
22987
|
ui.success(`Bot key saved to ${outPath}`);
|
|
22780
22988
|
}
|
|
@@ -23379,10 +23587,10 @@ var AccountCommandHandler = class {
|
|
|
23379
23587
|
throw new Error("Missing visible apps input");
|
|
23380
23588
|
}
|
|
23381
23589
|
const absolutePath = this.resolveFilePath(args.filePath);
|
|
23382
|
-
if (!(0,
|
|
23590
|
+
if (!(0, import_node_fs29.existsSync)(absolutePath)) {
|
|
23383
23591
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23384
23592
|
}
|
|
23385
|
-
const raw = (0,
|
|
23593
|
+
const raw = (0, import_node_fs29.readFileSync)(absolutePath, "utf8");
|
|
23386
23594
|
let parsed;
|
|
23387
23595
|
try {
|
|
23388
23596
|
parsed = JSON.parse(raw);
|
|
@@ -23396,13 +23604,13 @@ var AccountCommandHandler = class {
|
|
|
23396
23604
|
return parsed;
|
|
23397
23605
|
}
|
|
23398
23606
|
resolveFilePath(filePath) {
|
|
23399
|
-
return
|
|
23607
|
+
return import_node_path34.default.resolve(process.cwd(), filePath);
|
|
23400
23608
|
}
|
|
23401
23609
|
resolveDefaultBotKeyPath(app, name) {
|
|
23402
|
-
return
|
|
23610
|
+
return import_node_path34.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
|
|
23403
23611
|
}
|
|
23404
23612
|
resolveDefaultAccessKeyPath(app, name) {
|
|
23405
|
-
return
|
|
23613
|
+
return import_node_path34.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
|
|
23406
23614
|
}
|
|
23407
23615
|
homeDir() {
|
|
23408
23616
|
return process.env.HOME || process.env.USERPROFILE || process.cwd();
|
|
@@ -23422,14 +23630,14 @@ var AccountCommandHandler = class {
|
|
|
23422
23630
|
}
|
|
23423
23631
|
renameDefaultBotKeyFile(app, name, newName) {
|
|
23424
23632
|
const oldPath = this.resolveDefaultBotKeyPath(app, name);
|
|
23425
|
-
if (!(0,
|
|
23633
|
+
if (!(0, import_node_fs29.existsSync)(oldPath)) {
|
|
23426
23634
|
return void 0;
|
|
23427
23635
|
}
|
|
23428
23636
|
const keyFile = this.readBotKeyFile(oldPath, app, name);
|
|
23429
23637
|
const newPath = this.resolveDefaultBotKeyPath(app, newName);
|
|
23430
|
-
(0,
|
|
23431
|
-
(0,
|
|
23432
|
-
(0,
|
|
23638
|
+
(0, import_node_fs29.mkdirSync)(import_node_path34.default.dirname(newPath), { recursive: true, mode: 448 });
|
|
23639
|
+
(0, import_node_fs29.writeFileSync)(newPath, JSON.stringify({ ...keyFile, name: newName }, null, 2));
|
|
23640
|
+
(0, import_node_fs29.chmodSync)(newPath, 384);
|
|
23433
23641
|
return newPath;
|
|
23434
23642
|
}
|
|
23435
23643
|
readBotKeyFile(filePath, expectedApp, expectedName) {
|
|
@@ -23437,10 +23645,10 @@ var AccountCommandHandler = class {
|
|
|
23437
23645
|
throw new Error("Missing bot key file");
|
|
23438
23646
|
}
|
|
23439
23647
|
const absolutePath = this.resolveFilePath(filePath);
|
|
23440
|
-
if (!(0,
|
|
23648
|
+
if (!(0, import_node_fs29.existsSync)(absolutePath)) {
|
|
23441
23649
|
throw new Error(`Bot key file not found: ${absolutePath}`);
|
|
23442
23650
|
}
|
|
23443
|
-
const parsed = JSON.parse((0,
|
|
23651
|
+
const parsed = JSON.parse((0, import_node_fs29.readFileSync)(absolutePath, "utf8"));
|
|
23444
23652
|
if (parsed.type !== "pmate-bot-key" || parsed.version !== 1 || parsed.algorithm !== "ed25519" || !parsed.publicKey || !parsed.privateKey) {
|
|
23445
23653
|
throw new Error(`Invalid PMate bot key file: ${absolutePath}`);
|
|
23446
23654
|
}
|
|
@@ -23457,10 +23665,10 @@ var AccountCommandHandler = class {
|
|
|
23457
23665
|
throw new Error("Missing access key file");
|
|
23458
23666
|
}
|
|
23459
23667
|
const absolutePath = this.resolveFilePath(filePath);
|
|
23460
|
-
if (!(0,
|
|
23668
|
+
if (!(0, import_node_fs29.existsSync)(absolutePath)) {
|
|
23461
23669
|
throw new Error(`Access key file not found: ${absolutePath}`);
|
|
23462
23670
|
}
|
|
23463
|
-
const parsed = JSON.parse((0,
|
|
23671
|
+
const parsed = JSON.parse((0, import_node_fs29.readFileSync)(absolutePath, "utf8"));
|
|
23464
23672
|
if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
|
|
23465
23673
|
throw new Error(`Invalid PMate access key file: ${absolutePath}`);
|
|
23466
23674
|
}
|
|
@@ -23482,9 +23690,9 @@ var AccountCommandHandler = class {
|
|
|
23482
23690
|
createdAt: result.key.createdAt
|
|
23483
23691
|
};
|
|
23484
23692
|
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
|
|
23485
|
-
(0,
|
|
23486
|
-
(0,
|
|
23487
|
-
(0,
|
|
23693
|
+
(0, import_node_fs29.mkdirSync)(import_node_path34.default.dirname(outPath), { recursive: true });
|
|
23694
|
+
(0, import_node_fs29.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
23695
|
+
(0, import_node_fs29.chmodSync)(outPath, 384);
|
|
23488
23696
|
}
|
|
23489
23697
|
renderAccessKeyCreateResult(result, asJson, out) {
|
|
23490
23698
|
if (asJson) {
|
|
@@ -23565,12 +23773,12 @@ var AccountCommandHandler = class {
|
|
|
23565
23773
|
}
|
|
23566
23774
|
};
|
|
23567
23775
|
function encodePathSegment2(value) {
|
|
23568
|
-
return value.split("/").map((
|
|
23776
|
+
return value.split("/").map((segment2) => encodeURIComponent(segment2)).join("/");
|
|
23569
23777
|
}
|
|
23570
23778
|
|
|
23571
23779
|
// src/commands/OrgCommandHandler.ts
|
|
23572
|
-
var
|
|
23573
|
-
var
|
|
23780
|
+
var import_node_fs30 = require("fs");
|
|
23781
|
+
var import_node_path35 = __toESM(require("path"));
|
|
23574
23782
|
init_sessionStore();
|
|
23575
23783
|
var OrgCommandHandler = class {
|
|
23576
23784
|
async handle(args) {
|
|
@@ -23740,11 +23948,11 @@ var OrgCommandHandler = class {
|
|
|
23740
23948
|
if (!filePath) {
|
|
23741
23949
|
throw new Error(`Missing ${itemLabel} input`);
|
|
23742
23950
|
}
|
|
23743
|
-
const absolutePath =
|
|
23744
|
-
if (!(0,
|
|
23951
|
+
const absolutePath = import_node_path35.default.resolve(process.cwd(), filePath);
|
|
23952
|
+
if (!(0, import_node_fs30.existsSync)(absolutePath)) {
|
|
23745
23953
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23746
23954
|
}
|
|
23747
|
-
const raw = (0,
|
|
23955
|
+
const raw = (0, import_node_fs30.readFileSync)(absolutePath, "utf8");
|
|
23748
23956
|
let parsed;
|
|
23749
23957
|
try {
|
|
23750
23958
|
parsed = JSON.parse(raw);
|
|
@@ -23811,14 +24019,14 @@ var OrgCommandHandler = class {
|
|
|
23811
24019
|
}
|
|
23812
24020
|
};
|
|
23813
24021
|
function encodePathSegment3(value) {
|
|
23814
|
-
return value.split("/").map((
|
|
24022
|
+
return value.split("/").map((segment2) => encodeURIComponent(segment2)).join("/");
|
|
23815
24023
|
}
|
|
23816
24024
|
|
|
23817
24025
|
// src/commands/HostCommandHandler.ts
|
|
23818
|
-
var
|
|
23819
|
-
var
|
|
23820
|
-
var
|
|
23821
|
-
var
|
|
24026
|
+
var import_node_fs31 = require("fs");
|
|
24027
|
+
var import_node_os16 = require("os");
|
|
24028
|
+
var import_node_path36 = __toESM(require("path"));
|
|
24029
|
+
var import_node_child_process18 = require("child_process");
|
|
23822
24030
|
var BLOCK_START = "# >>> pmate host env >>>";
|
|
23823
24031
|
var BLOCK_END = "# <<< pmate host env <<<";
|
|
23824
24032
|
var PROFILE_BLOCK = `${BLOCK_START}
|
|
@@ -23830,7 +24038,7 @@ fi
|
|
|
23830
24038
|
${BLOCK_END}`;
|
|
23831
24039
|
var HostCommandHandler = class {
|
|
23832
24040
|
async handle(args) {
|
|
23833
|
-
const hostId = normalizeHostId(args.host ?? process.env.PMATE_HOST_ID ?? (0,
|
|
24041
|
+
const hostId = normalizeHostId(args.host ?? process.env.PMATE_HOST_ID ?? (0, import_node_os16.hostname)());
|
|
23834
24042
|
const client = new ServiceRegistryClient(args.baseUrl);
|
|
23835
24043
|
if (args.action === "env-list") {
|
|
23836
24044
|
const items = await client.listHostEnv(hostId);
|
|
@@ -23861,7 +24069,7 @@ async function applyHostEnvRemote(host, values) {
|
|
|
23861
24069
|
const content = serializeHostEnv(values);
|
|
23862
24070
|
const script = buildRemoteApplyScript(Buffer.from(content, "utf8").toString("base64"));
|
|
23863
24071
|
await new Promise((resolve, reject) => {
|
|
23864
|
-
const child = (0,
|
|
24072
|
+
const child = (0, import_node_child_process18.spawn)("ssh", [target, "bash -s"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
23865
24073
|
let stdout = "";
|
|
23866
24074
|
let stderr = "";
|
|
23867
24075
|
child.stdout.on("data", (chunk) => {
|
|
@@ -27039,7 +27247,7 @@ function requireValue10(tokens, option) {
|
|
|
27039
27247
|
|
|
27040
27248
|
// src/index.ts
|
|
27041
27249
|
var pkg = JSON.parse(
|
|
27042
|
-
(0,
|
|
27250
|
+
(0, import_node_fs32.readFileSync)(import_node_path37.default.resolve(__dirname, "..", "package.json"), "utf8")
|
|
27043
27251
|
);
|
|
27044
27252
|
var HELP_TEXT = [
|
|
27045
27253
|
import_chalk4.default.bold(`pmate v${pkg.version}`),
|
|
@@ -27211,6 +27419,7 @@ var HELP_TEXT = [
|
|
|
27211
27419
|
` ${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
27420
|
` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
27213
27421
|
` ${import_chalk4.default.gray(" default base URL: https://apps-api.pmate.chat")}`,
|
|
27422
|
+
` ${import_chalk4.default.cyan("install")} Install or update a managed source package: pmate install <package>`,
|
|
27214
27423
|
` ${import_chalk4.default.cyan("service")} Manage service registry entries via apps-api`,
|
|
27215
27424
|
" 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
27425
|
` ${import_chalk4.default.gray(" list [--namespace <ns>] [--repo <owner/name|https://github.com/owner/name>] [--server <name>] [--base-url <url>] [--json]")}`,
|
|
@@ -27413,6 +27622,7 @@ function parseCommandArgs(args) {
|
|
|
27413
27622
|
if (args.rest[0] === "service") {
|
|
27414
27623
|
return parseServiceArgs(args.rest.slice(1));
|
|
27415
27624
|
}
|
|
27625
|
+
if (args.rest[0] === "install") return parseInstallArgs(args.rest.slice(1));
|
|
27416
27626
|
if (args.rest[0] === "host") {
|
|
27417
27627
|
return parseHostArgs(args.rest.slice(1));
|
|
27418
27628
|
}
|
|
@@ -28974,6 +29184,10 @@ async function main() {
|
|
|
28974
29184
|
}
|
|
28975
29185
|
const commandArgs = parseCommandArgs(args);
|
|
28976
29186
|
switch (commandArgs.type) {
|
|
29187
|
+
case "install" /* Install */: {
|
|
29188
|
+
await new PackageInstaller({ progress: (message) => ui.plain(message) }).install(commandArgs.package);
|
|
29189
|
+
return;
|
|
29190
|
+
}
|
|
28977
29191
|
case "list" /* List */: {
|
|
28978
29192
|
const handler = new ListCommandHandler();
|
|
28979
29193
|
handler.handle(commandArgs);
|