@pmate/cli 0.38.6 → 0.40.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/README.md +18 -5
- package/dist/index.d.ts +14 -26
- package/dist/index.js +398 -313
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8818,8 +8818,8 @@ __export(index_exports, {
|
|
|
8818
8818
|
parseCommandArgs: () => parseCommandArgs
|
|
8819
8819
|
});
|
|
8820
8820
|
module.exports = __toCommonJS(index_exports);
|
|
8821
|
-
var
|
|
8822
|
-
var
|
|
8821
|
+
var import_node_fs30 = require("fs");
|
|
8822
|
+
var import_node_path35 = __toESM(require("path"));
|
|
8823
8823
|
|
|
8824
8824
|
// src/managedSession.ts
|
|
8825
8825
|
var import_node_fs = require("fs");
|
|
@@ -14267,9 +14267,9 @@ ${indent}\`\`\``;
|
|
|
14267
14267
|
static richTextToPlain(richText) {
|
|
14268
14268
|
return richText.map((item) => item.plain_text ?? item.text?.content ?? "").join("").trim();
|
|
14269
14269
|
}
|
|
14270
|
-
static async requestJson(
|
|
14270
|
+
static async requestJson(path35, init) {
|
|
14271
14271
|
const token = this.getToken();
|
|
14272
|
-
const response = await fetch(`${this.baseUrl}${
|
|
14272
|
+
const response = await fetch(`${this.baseUrl}${path35}`, {
|
|
14273
14273
|
method: init.method,
|
|
14274
14274
|
headers: {
|
|
14275
14275
|
Authorization: `Bearer ${token}`,
|
|
@@ -16974,8 +16974,8 @@ function descriptorPathSegments(descriptor) {
|
|
|
16974
16974
|
return ["chains", normalized.chain, "namespaces", normalized.ns, normalized.kind, normalized.name];
|
|
16975
16975
|
}
|
|
16976
16976
|
function buildPathUrl(baseUrl, pathSegments, query) {
|
|
16977
|
-
const
|
|
16978
|
-
const url = new URL(
|
|
16977
|
+
const path35 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
|
|
16978
|
+
const url = new URL(path35, baseUrl);
|
|
16979
16979
|
if (query) {
|
|
16980
16980
|
for (const [key, value] of Object.entries(query)) {
|
|
16981
16981
|
url.searchParams.set(key, String(value));
|
|
@@ -17535,140 +17535,15 @@ var StoreCommandHandler = class {
|
|
|
17535
17535
|
}
|
|
17536
17536
|
};
|
|
17537
17537
|
|
|
17538
|
-
// src/
|
|
17539
|
-
var import_node_child_process9 = require("child_process");
|
|
17538
|
+
// src/commands/AppCommandHandler.ts
|
|
17540
17539
|
var import_node_fs19 = require("fs");
|
|
17541
|
-
var import_node_os9 = require("os");
|
|
17542
17540
|
var import_node_path24 = __toESM(require("path"));
|
|
17543
|
-
|
|
17544
|
-
// src/desktopRelease.ts
|
|
17545
|
-
init_sessionStore();
|
|
17546
|
-
var import_node_crypto4 = require("crypto");
|
|
17547
|
-
var import_node_fs18 = require("fs");
|
|
17548
|
-
var import_node_path23 = __toESM(require("path"));
|
|
17549
|
-
async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
17550
|
-
const segments = [...app.split(":"), version, platform, arch];
|
|
17551
|
-
if (app.split(":").length !== 2 || segments.some((s) => !/^[\w.-]+$/.test(s) || s === "." || s === "..")) throw new Error("Invalid desktop release identity");
|
|
17552
|
-
if (!["mac", "win"].includes(platform) || !["arm64", "x64"].includes(arch) || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version)) throw new Error("Desktop publication requires a stable version and supported target");
|
|
17553
|
-
const { token } = readRequiredSession({ preferredApp: DEFAULT_APP_ID });
|
|
17554
|
-
const bucket = "parrot-static";
|
|
17555
|
-
const prefix = `desktop/${segments.join("/")}/`;
|
|
17556
|
-
const url = (key) => `https://parrot-static.pmate.chat/${key.split("/").map(encodeURIComponent).join("/")}`;
|
|
17557
|
-
const artifacts = (0, import_node_fs18.readdirSync)(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && (platform === "mac" ? /\.(dmg|zip)$/i : /\.(exe|zip)$/i).test(entry.name)).sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
17558
|
-
const bytes = (0, import_node_fs18.readFileSync)(import_node_path23.default.join(directory, entry.name));
|
|
17559
|
-
const objectKey = prefix + entry.name;
|
|
17560
|
-
return { name: entry.name, objectKey, downloadUrl: url(objectKey), sha256: (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex"), size: bytes.length };
|
|
17561
|
-
});
|
|
17562
|
-
if (!artifacts.length) throw new Error("No desktop installers found to publish");
|
|
17563
|
-
const manifestKey = prefix + "release.json";
|
|
17564
|
-
const existing = await AliyunService.readJsonObject(bucket, manifestKey);
|
|
17565
|
-
const release = { schemaVersion: 1, app, version, platform, arch, artifacts };
|
|
17566
|
-
if (existing !== null && JSON.stringify(existing) !== JSON.stringify(release)) throw new Error("Desktop release already exists with different artifacts; bump the app version");
|
|
17567
|
-
for (const artifact of artifacts) await AliyunService.uploadFile(import_node_path23.default.join(directory, artifact.name), bucket, artifact.objectKey);
|
|
17568
|
-
await AliyunService.uploadJsonObject(bucket, manifestKey, release);
|
|
17569
|
-
const base = (process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
17570
|
-
const response = await fetch(`${base}/versions/${encodeURIComponent(app)}`, {
|
|
17571
|
-
method: "POST",
|
|
17572
|
-
headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
|
|
17573
|
-
body: JSON.stringify({ version, platform, arch, manifestUrl: url(manifestKey) }),
|
|
17574
|
-
signal: AbortSignal.timeout(3e4),
|
|
17575
|
-
redirect: "error"
|
|
17576
|
-
});
|
|
17577
|
-
const result = await response.json();
|
|
17578
|
-
if (!response.ok || result.success !== true) throw new Error(`Installers uploaded but version registration failed: ${result.message || response.status}. Retry this release before announcing it.`);
|
|
17579
|
-
return { bucket, manifestUrl: url(manifestKey), downloads: artifacts };
|
|
17580
|
-
}
|
|
17581
|
-
|
|
17582
|
-
// src/electronBuild.ts
|
|
17583
|
-
var ELECTRON_VERSION = "44.5.1";
|
|
17584
|
-
var BUILDER_VERSION = "26.15.3";
|
|
17585
|
-
function readDesktopConfig(file, appId) {
|
|
17586
|
-
const c = JSON.parse((0, import_node_fs19.readFileSync)(file, "utf8"));
|
|
17587
|
-
if (c.schemaVersion !== 2 || c.app !== appId) throw new Error("Desktop config schemaVersion/app mismatch");
|
|
17588
|
-
for (const key of ["productName", "bundleId", "version", "icon"]) {
|
|
17589
|
-
if (typeof c[key] !== "string" || !c[key].trim()) throw new Error(`Missing desktop ${key}`);
|
|
17590
|
-
}
|
|
17591
|
-
if (!/^[a-zA-Z][\w-]*(\.[a-zA-Z][\w-]*)+$/.test(c.bundleId)) throw new Error("Invalid desktop bundleId");
|
|
17592
|
-
if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(c.version)) throw new Error("Invalid desktop version");
|
|
17593
|
-
const origin = (value) => {
|
|
17594
|
-
const url = new URL(value);
|
|
17595
|
-
if (url.protocol !== "https:" || url.origin !== value || url.username || url.password) throw new Error("Desktop origins must be exact HTTPS origins, without paths or credentials");
|
|
17596
|
-
};
|
|
17597
|
-
origin(c.origin);
|
|
17598
|
-
if (!Array.isArray(c.authOrigins)) throw new Error("authOrigins must be an array");
|
|
17599
|
-
c.authOrigins.forEach(origin);
|
|
17600
|
-
if (c.externalOrigins !== void 0 && !Array.isArray(c.externalOrigins)) throw new Error("externalOrigins must be an array");
|
|
17601
|
-
c.externalOrigins?.forEach(origin);
|
|
17602
|
-
if ("web" in c) throw new Error("Remote desktop builds do not accept web build configuration; remove web");
|
|
17603
|
-
return c;
|
|
17604
|
-
}
|
|
17605
|
-
async function runBuildCommand(command, cwd, env = process.env) {
|
|
17606
|
-
await new Promise((resolve, reject) => {
|
|
17607
|
-
const child = (0, import_node_child_process9.spawn)(command[0], command.slice(1), { cwd, env, stdio: "inherit", shell: false });
|
|
17608
|
-
child.once("error", reject);
|
|
17609
|
-
child.once("exit", (code, signal) => code === 0 ? resolve() : reject(new Error(`${command[0]} failed (${signal ?? code})`)));
|
|
17610
|
-
});
|
|
17611
|
-
}
|
|
17612
|
-
async function buildDesktop(args) {
|
|
17613
|
-
const file = import_node_path24.default.resolve(args.config);
|
|
17614
|
-
const c = readDesktopConfig(file, args.id);
|
|
17615
|
-
const base = import_node_path24.default.dirname(file);
|
|
17616
|
-
const icon = import_node_path24.default.resolve(base, c.icon);
|
|
17617
|
-
const output = import_node_path24.default.resolve(args.outDir);
|
|
17618
|
-
if (!(0, import_node_fs19.existsSync)(icon) || !(0, import_node_fs19.statSync)(icon).isFile()) throw new Error(`Desktop icon not found: ${icon}`);
|
|
17619
|
-
if (!["mac", "win"].includes(args.platform) || !["arm64", "x64"].includes(args.arch)) throw new Error("Supported target: mac|win --arch arm64|x64");
|
|
17620
|
-
if (args.platform === "mac" && process.platform !== "darwin") throw new Error("macOS desktop packaging requires a macOS build host");
|
|
17621
|
-
const plan = { app: c.app, productName: c.productName, version: c.version, target: args.platform, arch: args.arch, contentSource: "remote", origin: c.origin, output, electron: ELECTRON_VERSION, builder: BUILDER_VERSION, signed: args.signed };
|
|
17622
|
-
console.log(JSON.stringify({ phase: "plan", ...plan }, null, 2));
|
|
17623
|
-
if (args.dryRun) return;
|
|
17624
|
-
(0, import_node_fs19.mkdirSync)(output, { recursive: true });
|
|
17625
|
-
const staging = (0, import_node_fs19.mkdtempSync)(import_node_path24.default.join(output, ".desktop-build-"));
|
|
17626
|
-
const appDir = import_node_path24.default.join(staging, "app");
|
|
17627
|
-
(0, import_node_fs19.mkdirSync)(appDir);
|
|
17628
|
-
const templateDir = import_node_path24.default.join(__dirname, "templates", "electron");
|
|
17629
|
-
(0, import_node_fs19.cpSync)(templateDir, appDir, { recursive: true });
|
|
17630
|
-
(0, import_node_fs19.writeFileSync)(import_node_path24.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 }));
|
|
17631
|
-
(0, import_node_fs19.writeFileSync)(import_node_path24.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" } }));
|
|
17632
|
-
await runBuildCommand(["npm", "install", "--omit=dev", "--no-audit", "--no-fund"], appDir);
|
|
17633
|
-
const cache = import_node_path24.default.join((0, import_node_os9.homedir)(), ".cache", "pmate", "electron", `${ELECTRON_VERSION}-${BUILDER_VERSION}`);
|
|
17634
|
-
(0, import_node_fs19.mkdirSync)(cache, { recursive: true });
|
|
17635
|
-
const toolPackage = { name: "pmate-desktop-toolchain", private: true, dependencies: { electron: ELECTRON_VERSION, "electron-builder": BUILDER_VERSION } };
|
|
17636
|
-
if (!(0, import_node_fs19.existsSync)(import_node_path24.default.join(cache, "node_modules", "electron", "dist", "Electron.app")) || !(0, import_node_fs19.existsSync)(import_node_path24.default.join(cache, "node_modules", "electron-builder", "cli.js"))) {
|
|
17637
|
-
(0, import_node_fs19.writeFileSync)(import_node_path24.default.join(cache, "package.json"), JSON.stringify(toolPackage));
|
|
17638
|
-
await runBuildCommand(["npm", (0, import_node_fs19.existsSync)(import_node_path24.default.join(cache, "package-lock.json")) ? "ci" : "install", "--no-audit", "--no-fund"], cache);
|
|
17639
|
-
}
|
|
17640
|
-
const builderConfig = {
|
|
17641
|
-
appId: c.bundleId,
|
|
17642
|
-
productName: c.productName,
|
|
17643
|
-
electronVersion: ELECTRON_VERSION,
|
|
17644
|
-
directories: { app: appDir, output: import_node_path24.default.join(staging, "artifacts") },
|
|
17645
|
-
files: ["**/*"],
|
|
17646
|
-
asar: true,
|
|
17647
|
-
artifactName: "${productName}-${version}-${arch}.${ext}",
|
|
17648
|
-
publish: [{ provider: "generic", url: `https://parrot-static.pmate.chat/desktop/${c.app.split(":").map(encodeURIComponent).join("/")}/${c.version}/${args.platform}/${args.arch}/` }],
|
|
17649
|
-
mac: { icon, target: args.dir ? ["dir"] : ["dmg", "zip"], category: "public.app-category.social-networking", hardenedRuntime: args.signed, extendInfo: { NSMicrophoneUsageDescription: `${c.productName} uses your microphone for voice calls and voice messages.` }, ...args.signed ? {} : { identity: "-", notarize: false } },
|
|
17650
|
-
win: { icon, target: args.dir ? ["dir"] : ["nsis", "zip"], ...args.signed ? {} : { signExecutable: false } },
|
|
17651
|
-
forceCodeSigning: args.signed
|
|
17652
|
-
};
|
|
17653
|
-
const configPath = import_node_path24.default.join(staging, "builder.json");
|
|
17654
|
-
(0, import_node_fs19.writeFileSync)(configPath, JSON.stringify(builderConfig));
|
|
17655
|
-
await runBuildCommand([process.execPath, import_node_path24.default.join(cache, "node_modules", "electron-builder", "cli.js"), "--config", configPath, args.platform === "mac" ? "--mac" : "--win", `--${args.arch}`, "--publish", "never"], appDir, { ...process.env, ...args.signed ? {} : { CSC_IDENTITY_AUTO_DISCOVERY: "false" } });
|
|
17656
|
-
const result = { ...plan, signature: args.signed ? args.platform === "mac" ? "configured-signing-required; verify notarization before distribution" : "configured-signing-required; verify Authenticode before distribution" : args.platform === "mac" ? "ad-hoc; local development" : "unsigned; local development", artifacts: import_node_path24.default.join(staging, "artifacts") };
|
|
17657
|
-
(0, import_node_fs19.writeFileSync)(import_node_path24.default.join(staging, "build-report.json"), JSON.stringify(result, null, 2));
|
|
17658
|
-
const publication = args.dir ? void 0 : await uploadDesktopArtifacts(result.artifacts, c.app, c.version, args.platform, args.arch);
|
|
17659
|
-
(0, import_node_fs19.writeFileSync)(import_node_path24.default.join(staging, "build-report.json"), JSON.stringify({ ...result, publication }, null, 2));
|
|
17660
|
-
console.log(JSON.stringify({ phase: "complete", report: import_node_path24.default.join(staging, "build-report.json"), artifacts: result.artifacts, signature: result.signature, publication }, null, 2));
|
|
17661
|
-
}
|
|
17662
|
-
|
|
17663
|
-
// src/commands/AppCommandHandler.ts
|
|
17664
|
-
var import_node_fs21 = require("fs");
|
|
17665
|
-
var import_node_path26 = __toESM(require("path"));
|
|
17666
17541
|
init_sessionStore();
|
|
17667
17542
|
|
|
17668
17543
|
// src/appIcon.ts
|
|
17669
|
-
var
|
|
17670
|
-
var
|
|
17671
|
-
var
|
|
17544
|
+
var import_node_fs18 = require("fs");
|
|
17545
|
+
var import_node_os9 = __toESM(require("os"));
|
|
17546
|
+
var import_node_path23 = __toESM(require("path"));
|
|
17672
17547
|
var import_sharp = __toESM(require("sharp"));
|
|
17673
17548
|
init_namespacedRef();
|
|
17674
17549
|
var ANDROID_ICON_SPECS = [
|
|
@@ -17773,13 +17648,13 @@ function createAppIconExportPlans(input) {
|
|
|
17773
17648
|
if (!input.outDir) {
|
|
17774
17649
|
throw new Error("App icon preset export requires --out-dir.");
|
|
17775
17650
|
}
|
|
17776
|
-
const outDir =
|
|
17777
|
-
(0,
|
|
17651
|
+
const outDir = import_node_path23.default.resolve(input.cwd, input.outDir);
|
|
17652
|
+
(0, import_node_fs18.mkdirSync)(outDir, { recursive: true });
|
|
17778
17653
|
return specs.map((spec) => ({
|
|
17779
17654
|
width: spec.width,
|
|
17780
17655
|
height: spec.height,
|
|
17781
17656
|
format: "png",
|
|
17782
|
-
outputPath:
|
|
17657
|
+
outputPath: import_node_path23.default.join(
|
|
17783
17658
|
outDir,
|
|
17784
17659
|
`${namespace}-${objectId}-${spec.name}-${spec.width}x${spec.height}.png`
|
|
17785
17660
|
)
|
|
@@ -17792,8 +17667,8 @@ function createAppIconExportPlans(input) {
|
|
|
17792
17667
|
if (!input.output) {
|
|
17793
17668
|
throw new Error("Single-size app icon export requires --output.");
|
|
17794
17669
|
}
|
|
17795
|
-
const resolvedOutput =
|
|
17796
|
-
(0,
|
|
17670
|
+
const resolvedOutput = import_node_path23.default.resolve(input.cwd, input.output);
|
|
17671
|
+
(0, import_node_fs18.mkdirSync)(import_node_path23.default.dirname(resolvedOutput), { recursive: true });
|
|
17797
17672
|
return [
|
|
17798
17673
|
{
|
|
17799
17674
|
width: input.width,
|
|
@@ -17807,7 +17682,7 @@ async function exportAppIcon(icon, plans) {
|
|
|
17807
17682
|
const svg = await resolveAppIconSvg(icon);
|
|
17808
17683
|
for (const plan of plans) {
|
|
17809
17684
|
const bytes = await renderAppIcon(svg, plan.width, plan.height, plan.format);
|
|
17810
|
-
(0,
|
|
17685
|
+
(0, import_node_fs18.writeFileSync)(plan.outputPath, bytes);
|
|
17811
17686
|
}
|
|
17812
17687
|
}
|
|
17813
17688
|
async function renderAppIconVariant(input) {
|
|
@@ -17815,9 +17690,9 @@ async function renderAppIconVariant(input) {
|
|
|
17815
17690
|
const bytes = await renderAppIcon(svg, input.width, input.height, input.format);
|
|
17816
17691
|
let outputPath;
|
|
17817
17692
|
if (input.output) {
|
|
17818
|
-
outputPath =
|
|
17819
|
-
(0,
|
|
17820
|
-
(0,
|
|
17693
|
+
outputPath = import_node_path23.default.resolve(input.cwd, input.output);
|
|
17694
|
+
(0, import_node_fs18.mkdirSync)(import_node_path23.default.dirname(outputPath), { recursive: true });
|
|
17695
|
+
(0, import_node_fs18.writeFileSync)(outputPath, bytes);
|
|
17821
17696
|
}
|
|
17822
17697
|
if (input.name) {
|
|
17823
17698
|
return {
|
|
@@ -17838,7 +17713,7 @@ async function renderAppIconVariant(input) {
|
|
|
17838
17713
|
};
|
|
17839
17714
|
}
|
|
17840
17715
|
async function loadAppIconVariantFile(input) {
|
|
17841
|
-
const absolutePath =
|
|
17716
|
+
const absolutePath = import_node_path23.default.resolve(input.cwd, input.filePath);
|
|
17842
17717
|
const format = inferVariantFormatFromPath(absolutePath);
|
|
17843
17718
|
return {
|
|
17844
17719
|
value: input.name ? await uploadAppIconVariantAsset({
|
|
@@ -17847,7 +17722,7 @@ async function loadAppIconVariantFile(input) {
|
|
|
17847
17722
|
name: input.name,
|
|
17848
17723
|
format,
|
|
17849
17724
|
sourcePath: absolutePath
|
|
17850
|
-
}) : createImageDataUrl((0,
|
|
17725
|
+
}) : createImageDataUrl((0, import_node_fs18.readFileSync)(absolutePath), format),
|
|
17851
17726
|
format,
|
|
17852
17727
|
absolutePath
|
|
17853
17728
|
};
|
|
@@ -17906,7 +17781,7 @@ function shouldAutoGenerateDefaultVariant(icon) {
|
|
|
17906
17781
|
return looksLikeSvgMarkup(icon) || looksLikeSvgUrl(icon);
|
|
17907
17782
|
}
|
|
17908
17783
|
function inferVariantFormatFromPath(filePath) {
|
|
17909
|
-
const ext =
|
|
17784
|
+
const ext = import_node_path23.default.extname(filePath).toLowerCase();
|
|
17910
17785
|
switch (ext) {
|
|
17911
17786
|
case ".png":
|
|
17912
17787
|
return "png";
|
|
@@ -17977,13 +17852,13 @@ async function uploadAppIconVariantAsset(input) {
|
|
|
17977
17852
|
await AliyunService.uploadFile(sourcePath, DEFAULT_APP_ICON_VARIANT_BUCKET, objectKey);
|
|
17978
17853
|
} finally {
|
|
17979
17854
|
if (shouldCleanup) {
|
|
17980
|
-
(0,
|
|
17855
|
+
(0, import_node_fs18.rmSync)(import_node_path23.default.dirname(sourcePath), { recursive: true, force: true });
|
|
17981
17856
|
}
|
|
17982
17857
|
}
|
|
17983
17858
|
return `${DEFAULT_APP_ICON_VARIANT_PUBLIC_BASE_URL}/${objectKey}`;
|
|
17984
17859
|
}
|
|
17985
17860
|
function buildAppIconVariantObjectKey(input) {
|
|
17986
|
-
return
|
|
17861
|
+
return import_node_path23.default.posix.join(
|
|
17987
17862
|
"apps",
|
|
17988
17863
|
`${resolveAppIconAssetStem(input.icon, input.appRef)}-${input.name}.${extensionForIconFormat(input.format)}`
|
|
17989
17864
|
);
|
|
@@ -17992,8 +17867,8 @@ function resolveAppIconAssetStem(icon, appRef2) {
|
|
|
17992
17867
|
if (icon) {
|
|
17993
17868
|
try {
|
|
17994
17869
|
const url = new URL(icon);
|
|
17995
|
-
const ext =
|
|
17996
|
-
const basename =
|
|
17870
|
+
const ext = import_node_path23.default.posix.extname(url.pathname);
|
|
17871
|
+
const basename = import_node_path23.default.posix.basename(url.pathname, ext);
|
|
17997
17872
|
const normalized = sanitizeAppIconAssetStem(basename);
|
|
17998
17873
|
if (normalized) {
|
|
17999
17874
|
return normalized;
|
|
@@ -18022,9 +17897,9 @@ function writeTempAppIconVariantFile(objectKey, format, bytes) {
|
|
|
18022
17897
|
if (!bytes) {
|
|
18023
17898
|
throw new Error("App icon variant upload requires bytes or a source file.");
|
|
18024
17899
|
}
|
|
18025
|
-
const tempDir = (0,
|
|
18026
|
-
const tempPath =
|
|
18027
|
-
(0,
|
|
17900
|
+
const tempDir = (0, import_node_fs18.mkdtempSync)(import_node_path23.default.join(import_node_os9.default.tmpdir(), "pmate-app-icon-"));
|
|
17901
|
+
const tempPath = import_node_path23.default.join(tempDir, import_node_path23.default.basename(objectKey) || `variant.${extensionForIconFormat(format)}`);
|
|
17902
|
+
(0, import_node_fs18.writeFileSync)(tempPath, bytes);
|
|
18028
17903
|
return tempPath;
|
|
18029
17904
|
}
|
|
18030
17905
|
|
|
@@ -18032,7 +17907,6 @@ function writeTempAppIconVariantFile(objectKey, format, bytes) {
|
|
|
18032
17907
|
init_namespacedRef();
|
|
18033
17908
|
var AppCommandHandler = class {
|
|
18034
17909
|
async handle(args) {
|
|
18035
|
-
if (args.action === "build") return buildDesktop(args);
|
|
18036
17910
|
const token = this.readToken();
|
|
18037
17911
|
const baseUrl = this.resolveBaseUrl(args.baseUrl);
|
|
18038
17912
|
switch (args.action) {
|
|
@@ -18234,10 +18108,10 @@ var AppCommandHandler = class {
|
|
|
18234
18108
|
}
|
|
18235
18109
|
readJsonFile(filePath) {
|
|
18236
18110
|
const absolutePath = this.resolveFilePath(filePath);
|
|
18237
|
-
if (!(0,
|
|
18111
|
+
if (!(0, import_node_fs19.existsSync)(absolutePath)) {
|
|
18238
18112
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
18239
18113
|
}
|
|
18240
|
-
const raw = (0,
|
|
18114
|
+
const raw = (0, import_node_fs19.readFileSync)(absolutePath, "utf8");
|
|
18241
18115
|
try {
|
|
18242
18116
|
return JSON.parse(raw);
|
|
18243
18117
|
} catch (error) {
|
|
@@ -18247,10 +18121,10 @@ var AppCommandHandler = class {
|
|
|
18247
18121
|
}
|
|
18248
18122
|
async preparePayload(filePath, appRef2) {
|
|
18249
18123
|
const absolutePath = this.resolveFilePath(filePath);
|
|
18250
|
-
return prepareAppPayload(this.readJsonFile(filePath),
|
|
18124
|
+
return prepareAppPayload(this.readJsonFile(filePath), import_node_path24.default.dirname(absolutePath), { appRef: appRef2 });
|
|
18251
18125
|
}
|
|
18252
18126
|
resolveFilePath(filePath) {
|
|
18253
|
-
return
|
|
18127
|
+
return import_node_path24.default.resolve(process.cwd(), filePath);
|
|
18254
18128
|
}
|
|
18255
18129
|
async request(baseUrl, token, method, pathname, body) {
|
|
18256
18130
|
const response = await fetch(`${baseUrl}${pathname}`, {
|
|
@@ -18370,18 +18244,207 @@ function readNamespaceFromPayload(payload) {
|
|
|
18370
18244
|
}
|
|
18371
18245
|
|
|
18372
18246
|
// src/commands/ServiceCommandHandler.ts
|
|
18373
|
-
var
|
|
18247
|
+
var import_node_fs26 = require("fs");
|
|
18374
18248
|
var import_promises5 = require("fs/promises");
|
|
18375
|
-
var
|
|
18249
|
+
var import_node_path31 = __toESM(require("path"));
|
|
18376
18250
|
var import_node_child_process13 = require("child_process");
|
|
18377
18251
|
var import_promises6 = require("readline/promises");
|
|
18378
18252
|
|
|
18379
|
-
// src/services/
|
|
18380
|
-
var
|
|
18381
|
-
var
|
|
18382
|
-
|
|
18383
|
-
|
|
18384
|
-
var
|
|
18253
|
+
// src/services/NativeServiceDeploy.ts
|
|
18254
|
+
var import_node_path29 = __toESM(require("path"));
|
|
18255
|
+
var import_node_fs24 = require("fs");
|
|
18256
|
+
|
|
18257
|
+
// src/electronBuild.ts
|
|
18258
|
+
var import_node_child_process9 = require("child_process");
|
|
18259
|
+
var import_node_fs21 = require("fs");
|
|
18260
|
+
var import_node_os10 = require("os");
|
|
18261
|
+
var import_node_path26 = __toESM(require("path"));
|
|
18262
|
+
|
|
18263
|
+
// src/desktopRelease.ts
|
|
18264
|
+
init_sessionStore();
|
|
18265
|
+
var import_node_crypto4 = require("crypto");
|
|
18266
|
+
var import_node_fs20 = require("fs");
|
|
18267
|
+
var import_node_path25 = __toESM(require("path"));
|
|
18268
|
+
async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
18269
|
+
const segments = [...app.split(":"), version, platform, arch];
|
|
18270
|
+
if (app.split(":").length !== 2 || segments.some((s) => !/^[\w.-]+$/.test(s) || s === "." || s === "..")) throw new Error("Invalid desktop release identity");
|
|
18271
|
+
if (!["mac", "win"].includes(platform) || !["arm64", "x64"].includes(arch) || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version)) throw new Error("Desktop publication requires a stable version and supported target");
|
|
18272
|
+
const { token } = readRequiredSession({ preferredApp: DEFAULT_APP_ID });
|
|
18273
|
+
const bucket = "parrot-static";
|
|
18274
|
+
const prefix = `desktop/${segments.join("/")}/`;
|
|
18275
|
+
const url = (key) => `https://parrot-static.pmate.chat/${key.split("/").map(encodeURIComponent).join("/")}`;
|
|
18276
|
+
const artifacts = (0, import_node_fs20.readdirSync)(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && (platform === "mac" ? /\.(dmg|zip)$/i : /\.(exe|zip)$/i).test(entry.name)).sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
18277
|
+
const bytes = (0, import_node_fs20.readFileSync)(import_node_path25.default.join(directory, entry.name));
|
|
18278
|
+
const objectKey = prefix + entry.name;
|
|
18279
|
+
return { name: entry.name, objectKey, downloadUrl: url(objectKey), sha256: (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex"), size: bytes.length };
|
|
18280
|
+
});
|
|
18281
|
+
if (!artifacts.length) throw new Error("No desktop installers found to publish");
|
|
18282
|
+
const manifestKey = prefix + "release.json";
|
|
18283
|
+
const existing = await AliyunService.readJsonObject(bucket, manifestKey);
|
|
18284
|
+
const release = { schemaVersion: 1, app, version, platform, arch, artifacts };
|
|
18285
|
+
if (existing !== null && JSON.stringify(existing) !== JSON.stringify(release)) throw new Error("Desktop release already exists with different artifacts; bump the app version");
|
|
18286
|
+
for (const artifact of artifacts) await AliyunService.uploadFile(import_node_path25.default.join(directory, artifact.name), bucket, artifact.objectKey);
|
|
18287
|
+
await AliyunService.uploadJsonObject(bucket, manifestKey, release);
|
|
18288
|
+
const base = (process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
18289
|
+
const response = await fetch(`${base}/versions/${encodeURIComponent(app)}`, {
|
|
18290
|
+
method: "POST",
|
|
18291
|
+
headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
|
|
18292
|
+
body: JSON.stringify({ version, platform, arch, manifestUrl: url(manifestKey) }),
|
|
18293
|
+
signal: AbortSignal.timeout(3e4),
|
|
18294
|
+
redirect: "error"
|
|
18295
|
+
});
|
|
18296
|
+
const result = await response.json();
|
|
18297
|
+
if (!response.ok || result.success !== true) throw new Error(`Installers uploaded but version registration failed: ${result.message || response.status}. Retry this release before announcing it.`);
|
|
18298
|
+
return { bucket, manifestUrl: url(manifestKey), downloads: artifacts };
|
|
18299
|
+
}
|
|
18300
|
+
|
|
18301
|
+
// src/electronBuild.ts
|
|
18302
|
+
var ELECTRON_VERSION = "44.5.1";
|
|
18303
|
+
var BUILDER_VERSION = "26.15.3";
|
|
18304
|
+
function readDesktopConfig(file, appId) {
|
|
18305
|
+
const c = JSON.parse((0, import_node_fs21.readFileSync)(file, "utf8"));
|
|
18306
|
+
if (c.schemaVersion !== 2 || c.app !== appId) throw new Error("Desktop config schemaVersion/app mismatch");
|
|
18307
|
+
for (const key of ["productName", "bundleId", "version", "icon"]) {
|
|
18308
|
+
if (typeof c[key] !== "string" || !c[key].trim()) throw new Error(`Missing desktop ${key}`);
|
|
18309
|
+
}
|
|
18310
|
+
if (!/^[a-zA-Z][\w-]*(\.[a-zA-Z][\w-]*)+$/.test(c.bundleId)) throw new Error("Invalid desktop bundleId");
|
|
18311
|
+
if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(c.version)) throw new Error("Invalid desktop version");
|
|
18312
|
+
const origin = (value) => {
|
|
18313
|
+
const url = new URL(value);
|
|
18314
|
+
if (url.protocol !== "https:" || url.origin !== value || url.username || url.password) throw new Error("Desktop origins must be exact HTTPS origins, without paths or credentials");
|
|
18315
|
+
};
|
|
18316
|
+
origin(c.origin);
|
|
18317
|
+
if (!Array.isArray(c.authOrigins)) throw new Error("authOrigins must be an array");
|
|
18318
|
+
c.authOrigins.forEach(origin);
|
|
18319
|
+
if (c.externalOrigins !== void 0 && !Array.isArray(c.externalOrigins)) throw new Error("externalOrigins must be an array");
|
|
18320
|
+
c.externalOrigins?.forEach(origin);
|
|
18321
|
+
if (c.notaryProfile !== void 0 && (typeof c.notaryProfile !== "string" || !c.notaryProfile.trim())) throw new Error("Invalid notaryProfile");
|
|
18322
|
+
if ("web" in c) throw new Error("Remote desktop builds do not accept web build configuration; remove web");
|
|
18323
|
+
return c;
|
|
18324
|
+
}
|
|
18325
|
+
function repositoryRoot(cwd) {
|
|
18326
|
+
let dir = import_node_path26.default.resolve(cwd);
|
|
18327
|
+
while (true) {
|
|
18328
|
+
if ((0, import_node_fs21.existsSync)(import_node_path26.default.join(dir, ".git"))) return dir;
|
|
18329
|
+
const parent = import_node_path26.default.dirname(dir);
|
|
18330
|
+
if (parent === dir) return void 0;
|
|
18331
|
+
dir = parent;
|
|
18332
|
+
}
|
|
18333
|
+
}
|
|
18334
|
+
function resolveDesktopPaths(args, cwd = process.cwd()) {
|
|
18335
|
+
const root = repositoryRoot(cwd);
|
|
18336
|
+
const name = args.id.split(":")[1];
|
|
18337
|
+
let file = args.config ? import_node_path26.default.resolve(cwd, args.config) : void 0;
|
|
18338
|
+
if (!file) {
|
|
18339
|
+
let dir = import_node_path26.default.resolve(cwd);
|
|
18340
|
+
while (true) {
|
|
18341
|
+
const candidates = [.../* @__PURE__ */ new Set([import_node_path26.default.join(dir, "desktop.config.json"), import_node_path26.default.join(dir, "apps", name, "desktop.config.json")])];
|
|
18342
|
+
const matches = candidates.filter((candidate) => (0, import_node_fs21.existsSync)(candidate) && JSON.parse((0, import_node_fs21.readFileSync)(candidate, "utf8")).app === args.id);
|
|
18343
|
+
if (matches.length > 1) throw new Error("Ambiguous desktop config; specify --config");
|
|
18344
|
+
if (matches.length === 1) {
|
|
18345
|
+
file = matches[0];
|
|
18346
|
+
break;
|
|
18347
|
+
}
|
|
18348
|
+
const parent = import_node_path26.default.dirname(dir);
|
|
18349
|
+
if (dir === root || parent === dir) break;
|
|
18350
|
+
dir = parent;
|
|
18351
|
+
}
|
|
18352
|
+
}
|
|
18353
|
+
if (!file) throw new Error(`No desktop config for ${args.id}; specify --config`);
|
|
18354
|
+
return { file, output: args.outDir ? import_node_path26.default.resolve(cwd, args.outDir) : import_node_path26.default.join(root ?? import_node_path26.default.dirname(file), "release", name) };
|
|
18355
|
+
}
|
|
18356
|
+
function desktopBuildEnvironment(config, env = process.env) {
|
|
18357
|
+
return { ...env, ...env.APPLE_KEYCHAIN_PROFILE ? {} : config.notaryProfile ? { APPLE_KEYCHAIN_PROFILE: config.notaryProfile } : {} };
|
|
18358
|
+
}
|
|
18359
|
+
function requireNotaryCredentials(env) {
|
|
18360
|
+
if (env.APPLE_ID || env.APPLE_APP_SPECIFIC_PASSWORD) {
|
|
18361
|
+
if (env.APPLE_ID && env.APPLE_APP_SPECIFIC_PASSWORD && env.APPLE_TEAM_ID) return;
|
|
18362
|
+
} else if (env.APPLE_API_KEY || env.APPLE_API_KEY_ID || env.APPLE_API_ISSUER) {
|
|
18363
|
+
if (env.APPLE_API_KEY && env.APPLE_API_KEY_ID && env.APPLE_API_ISSUER) return;
|
|
18364
|
+
} else if (env.APPLE_KEYCHAIN_PROFILE) return;
|
|
18365
|
+
throw new Error("macOS signed builds require complete Apple notarization credentials or APPLE_KEYCHAIN_PROFILE");
|
|
18366
|
+
}
|
|
18367
|
+
function requireSigningIdentity(env, inspect = () => (0, import_node_child_process9.execFileSync)("security", ["find-identity", "-v", "-p", "codesigning"], { encoding: "utf8" })) {
|
|
18368
|
+
if (env.CSC_LINK) return;
|
|
18369
|
+
if (!inspect().includes("Developer ID Application:")) throw new Error("No Developer ID Application signing identity available");
|
|
18370
|
+
}
|
|
18371
|
+
async function publishVerifiedDesktop(args, artifacts, config, verify = verifyMacRelease, upload = uploadDesktopArtifacts) {
|
|
18372
|
+
if (args.signed && args.platform === "mac") await verify(artifacts);
|
|
18373
|
+
if (args.local || args.dir || !args.signed) return void 0;
|
|
18374
|
+
return upload(artifacts, config.app, config.version, args.platform, args.arch);
|
|
18375
|
+
}
|
|
18376
|
+
async function verifyMacRelease(artifacts, run = runBuildCommand, inspect = (app) => (0, import_node_child_process9.spawnSync)("codesign", ["-dv", "--verbose=4", app], { encoding: "utf8" })) {
|
|
18377
|
+
const apps = (0, import_node_fs21.readdirSync)(artifacts, { recursive: true, withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.endsWith(".app")).map((entry) => import_node_path26.default.join(entry.parentPath, entry.name)).filter((file) => !file.slice(0, -4).includes(".app/"));
|
|
18378
|
+
if (!apps.length) throw new Error("No packaged macOS app found; refusing publication");
|
|
18379
|
+
for (const app of apps) {
|
|
18380
|
+
await run(["codesign", "--verify", "--deep", "--strict", app], artifacts);
|
|
18381
|
+
const signature = inspect(app);
|
|
18382
|
+
if (signature.status !== 0 || !signature.stderr.includes("Authority=Developer ID Application:")) throw new Error("Packaged app lacks Developer ID Application signature");
|
|
18383
|
+
await run(["xcrun", "stapler", "validate", app], artifacts);
|
|
18384
|
+
await run(["spctl", "--assess", "--type", "execute", "--verbose=2", app], artifacts);
|
|
18385
|
+
}
|
|
18386
|
+
}
|
|
18387
|
+
async function runBuildCommand(command, cwd, env = process.env) {
|
|
18388
|
+
await new Promise((resolve, reject) => {
|
|
18389
|
+
const child = (0, import_node_child_process9.spawn)(command[0], command.slice(1), { cwd, env, stdio: "inherit", shell: false });
|
|
18390
|
+
child.once("error", reject);
|
|
18391
|
+
child.once("exit", (code, signal) => code === 0 ? resolve() : reject(new Error(`${command[0]} failed (${signal ?? code})`)));
|
|
18392
|
+
});
|
|
18393
|
+
}
|
|
18394
|
+
async function buildDesktop(args) {
|
|
18395
|
+
const { file, output } = resolveDesktopPaths(args);
|
|
18396
|
+
const c = readDesktopConfig(file, args.id);
|
|
18397
|
+
const base = import_node_path26.default.dirname(file);
|
|
18398
|
+
const icon = import_node_path26.default.resolve(base, c.icon);
|
|
18399
|
+
const env = desktopBuildEnvironment(c);
|
|
18400
|
+
if (!(0, import_node_fs21.existsSync)(icon) || !(0, import_node_fs21.statSync)(icon).isFile()) throw new Error(`Desktop icon not found: ${icon}`);
|
|
18401
|
+
if (!["mac", "win"].includes(args.platform) || !["arm64", "x64"].includes(args.arch)) throw new Error("Supported target: mac|win --arch arm64|x64");
|
|
18402
|
+
if (args.platform === "mac" && process.platform !== "darwin") throw new Error("macOS desktop packaging requires a macOS build host");
|
|
18403
|
+
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, output, electron: ELECTRON_VERSION, builder: BUILDER_VERSION, signed: args.signed };
|
|
18404
|
+
console.log(JSON.stringify({ phase: "plan", ...plan }, null, 2));
|
|
18405
|
+
if (args.dryRun) return;
|
|
18406
|
+
if (args.signed && args.platform === "mac") {
|
|
18407
|
+
requireNotaryCredentials(env);
|
|
18408
|
+
requireSigningIdentity(env);
|
|
18409
|
+
}
|
|
18410
|
+
(0, import_node_fs21.mkdirSync)(output, { recursive: true });
|
|
18411
|
+
const staging = (0, import_node_fs21.mkdtempSync)(import_node_path26.default.join(output, ".desktop-build-"));
|
|
18412
|
+
const appDir = import_node_path26.default.join(staging, "app");
|
|
18413
|
+
(0, import_node_fs21.mkdirSync)(appDir);
|
|
18414
|
+
const templateDir = import_node_path26.default.join(__dirname, "templates", "electron");
|
|
18415
|
+
(0, import_node_fs21.cpSync)(templateDir, appDir, { recursive: true });
|
|
18416
|
+
(0, import_node_fs21.writeFileSync)(import_node_path26.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 }));
|
|
18417
|
+
(0, import_node_fs21.writeFileSync)(import_node_path26.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" } }));
|
|
18418
|
+
await runBuildCommand(["npm", "install", "--omit=dev", "--no-audit", "--no-fund"], appDir);
|
|
18419
|
+
const cache = import_node_path26.default.join((0, import_node_os10.homedir)(), ".cache", "pmate", "electron", `${ELECTRON_VERSION}-${BUILDER_VERSION}`);
|
|
18420
|
+
(0, import_node_fs21.mkdirSync)(cache, { recursive: true });
|
|
18421
|
+
const toolPackage = { name: "pmate-desktop-toolchain", private: true, dependencies: { electron: ELECTRON_VERSION, "electron-builder": BUILDER_VERSION } };
|
|
18422
|
+
if (!(0, import_node_fs21.existsSync)(import_node_path26.default.join(cache, "node_modules", "electron", "dist", "Electron.app")) || !(0, import_node_fs21.existsSync)(import_node_path26.default.join(cache, "node_modules", "electron-builder", "cli.js"))) {
|
|
18423
|
+
(0, import_node_fs21.writeFileSync)(import_node_path26.default.join(cache, "package.json"), JSON.stringify(toolPackage));
|
|
18424
|
+
await runBuildCommand(["npm", (0, import_node_fs21.existsSync)(import_node_path26.default.join(cache, "package-lock.json")) ? "ci" : "install", "--no-audit", "--no-fund"], cache);
|
|
18425
|
+
}
|
|
18426
|
+
const builderConfig = {
|
|
18427
|
+
appId: c.bundleId,
|
|
18428
|
+
productName: c.productName,
|
|
18429
|
+
electronVersion: ELECTRON_VERSION,
|
|
18430
|
+
directories: { app: appDir, output: import_node_path26.default.join(staging, "artifacts") },
|
|
18431
|
+
files: ["**/*"],
|
|
18432
|
+
asar: true,
|
|
18433
|
+
artifactName: "${productName}-${version}-${arch}.${ext}",
|
|
18434
|
+
publish: [{ provider: "generic", url: `https://parrot-static.pmate.chat/desktop/${c.app.split(":").map(encodeURIComponent).join("/")}/${c.version}/${args.platform}/${args.arch}/` }],
|
|
18435
|
+
mac: { icon, target: args.dir ? ["dir"] : ["dmg", "zip"], category: "public.app-category.social-networking", hardenedRuntime: args.signed, extendInfo: { NSMicrophoneUsageDescription: `${c.productName} uses your microphone for voice calls and voice messages.` }, ...args.signed ? {} : { identity: "-", notarize: false } },
|
|
18436
|
+
win: { icon, target: args.dir ? ["dir"] : ["nsis", "zip"], ...args.signed ? {} : { signExecutable: false } },
|
|
18437
|
+
forceCodeSigning: args.signed
|
|
18438
|
+
};
|
|
18439
|
+
const configPath = import_node_path26.default.join(staging, "builder.json");
|
|
18440
|
+
(0, import_node_fs21.writeFileSync)(configPath, JSON.stringify(builderConfig));
|
|
18441
|
+
await runBuildCommand([process.execPath, import_node_path26.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" } });
|
|
18442
|
+
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_path26.default.join(staging, "artifacts") };
|
|
18443
|
+
(0, import_node_fs21.writeFileSync)(import_node_path26.default.join(staging, "build-report.json"), JSON.stringify(result, null, 2));
|
|
18444
|
+
const publication = await publishVerifiedDesktop(args, result.artifacts, c);
|
|
18445
|
+
(0, import_node_fs21.writeFileSync)(import_node_path26.default.join(staging, "build-report.json"), JSON.stringify({ ...result, publication }, null, 2));
|
|
18446
|
+
console.log(JSON.stringify({ phase: "complete", report: import_node_path26.default.join(staging, "build-report.json"), artifacts: result.artifacts, signature: result.signature, publication }, null, 2));
|
|
18447
|
+
}
|
|
18385
18448
|
|
|
18386
18449
|
// src/services/AndroidApkReleaseService.ts
|
|
18387
18450
|
var import_node_child_process10 = require("child_process");
|
|
@@ -18874,6 +18937,11 @@ function capitalize(value) {
|
|
|
18874
18937
|
}
|
|
18875
18938
|
|
|
18876
18939
|
// src/services/IosBuildService.ts
|
|
18940
|
+
var import_node_child_process11 = require("child_process");
|
|
18941
|
+
var import_node_crypto6 = require("crypto");
|
|
18942
|
+
var import_node_fs23 = require("fs");
|
|
18943
|
+
var import_node_os12 = __toESM(require("os"));
|
|
18944
|
+
var import_node_path28 = __toESM(require("path"));
|
|
18877
18945
|
function iosBuildInteger(value) {
|
|
18878
18946
|
if (!/^(0|[1-9]\d*)$/.test(String(value)) || !Number.isSafeInteger(Number(value))) {
|
|
18879
18947
|
throw new Error(`iOS Build must be a non-negative safe integer: ${String(value)}`);
|
|
@@ -19024,6 +19092,64 @@ async function readPlist(input) {
|
|
|
19024
19092
|
});
|
|
19025
19093
|
}
|
|
19026
19094
|
|
|
19095
|
+
// src/services/NativeServiceDeploy.ts
|
|
19096
|
+
var electronKeys = ["config", "platform", "arch", "outDir", "unsigned", "signed", "dir"];
|
|
19097
|
+
var iosKeys = ["scheme", "team", "project", "workspace", "lastBuild"];
|
|
19098
|
+
function rejectNativeOverrides(args, allowed = []) {
|
|
19099
|
+
for (const key of [...electronKeys, ...iosKeys, "local", "dryRun"]) {
|
|
19100
|
+
if (args[key] !== void 0 && !allowed.includes(key)) throw new Error(`--${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)} is not supported for this service type`);
|
|
19101
|
+
}
|
|
19102
|
+
}
|
|
19103
|
+
var NativeServiceDeploy = class {
|
|
19104
|
+
constructor(deps = { desktop: buildDesktop, ios: new IosBuildService() }) {
|
|
19105
|
+
this.deps = deps;
|
|
19106
|
+
}
|
|
19107
|
+
async deploy(service, args) {
|
|
19108
|
+
if (!("type" in service) || !["electron", "ios"].includes(service.type)) throw new Error("Native deployment requires an electron or ios service");
|
|
19109
|
+
if ((args.env ?? "prod") !== "prod") throw new Error("Native deployment currently supports only --env prod");
|
|
19110
|
+
const repository = service.repository ?? service.mobile?.repository;
|
|
19111
|
+
const dir = service.dir ?? service.mobile?.dir;
|
|
19112
|
+
if (!dir || !repository && !args.cwd) throw new Error("Native service requires repository and dir");
|
|
19113
|
+
const root = args.cwd ? import_node_path29.default.resolve(args.cwd) : resolveRepositoryLocalRoot(repository);
|
|
19114
|
+
const appDir = import_node_path29.default.resolve(root, dir);
|
|
19115
|
+
if (!(0, import_node_fs24.existsSync)(appDir)) throw new Error(`Service source directory not found: ${appDir}`);
|
|
19116
|
+
const settings = service.build ?? {};
|
|
19117
|
+
if (service.type === "electron") {
|
|
19118
|
+
rejectNativeOverrides(args, [...electronKeys, "local", "dryRun"]);
|
|
19119
|
+
if (service.appIds?.length !== 1) throw new Error("Electron service requires exactly one appIds application identity");
|
|
19120
|
+
const app = service.appIds[0];
|
|
19121
|
+
const options2 = {
|
|
19122
|
+
id: app,
|
|
19123
|
+
target: "electron",
|
|
19124
|
+
config: args.config ? import_node_path29.default.resolve(args.config) : import_node_path29.default.resolve(appDir, settings.config ?? "desktop.config.json"),
|
|
19125
|
+
platform: args.platform ?? settings.platform ?? (process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : process.platform),
|
|
19126
|
+
arch: args.arch ?? settings.arch ?? process.arch,
|
|
19127
|
+
outDir: args.outDir ? import_node_path29.default.resolve(args.outDir) : import_node_path29.default.join(root, "release", service.name),
|
|
19128
|
+
signed: !args.unsigned,
|
|
19129
|
+
dir: !!args.dir,
|
|
19130
|
+
dryRun: !!args.dryRun,
|
|
19131
|
+
local: !!args.local,
|
|
19132
|
+
json: args.json
|
|
19133
|
+
};
|
|
19134
|
+
await this.deps.desktop(options2);
|
|
19135
|
+
return { serviceId: service.id, appId: app, status: args.dryRun ? "dry-run" : args.local ? "local" : "published", platform: options2.platform, arch: options2.arch, output: options2.outDir };
|
|
19136
|
+
}
|
|
19137
|
+
rejectNativeOverrides(args, [...iosKeys, "dryRun"]);
|
|
19138
|
+
const options = {
|
|
19139
|
+
cwd: root,
|
|
19140
|
+
scheme: args.scheme ?? settings.scheme ?? "",
|
|
19141
|
+
team: args.team ?? settings.team,
|
|
19142
|
+
project: args.project ?? (args.workspace ? void 0 : settings.project),
|
|
19143
|
+
workspace: args.workspace ?? (args.project ? void 0 : settings.workspace),
|
|
19144
|
+
lastBuild: args.lastBuild
|
|
19145
|
+
};
|
|
19146
|
+
if (!options.scheme.trim()) throw new Error("iOS service requires build.scheme; update the service configuration or pass --scheme");
|
|
19147
|
+
if (options.project && options.workspace) throw new Error("Use only one project or workspace");
|
|
19148
|
+
if (args.dryRun) return { serviceId: service.id, status: "dry-run", type: "ios", appDir, ...options };
|
|
19149
|
+
return { ...await this.deps.ios.build(service, options) };
|
|
19150
|
+
}
|
|
19151
|
+
};
|
|
19152
|
+
|
|
19027
19153
|
// src/services/DeveloperLogsClient.ts
|
|
19028
19154
|
init_sessionStore();
|
|
19029
19155
|
init_namespacedRef();
|
|
@@ -19111,9 +19237,9 @@ async function requestDeveloperLogTool(tool, params, fetcher = fetch, delegate)
|
|
|
19111
19237
|
}
|
|
19112
19238
|
|
|
19113
19239
|
// src/services/ServiceRuntimeRunner.ts
|
|
19114
|
-
var
|
|
19240
|
+
var import_node_fs25 = require("fs");
|
|
19115
19241
|
var import_node_os13 = __toESM(require("os"));
|
|
19116
|
-
var
|
|
19242
|
+
var import_node_path30 = __toESM(require("path"));
|
|
19117
19243
|
var import_node_child_process12 = require("child_process");
|
|
19118
19244
|
var import_node_readline = require("readline");
|
|
19119
19245
|
var import_chalk3 = __toESM(require("chalk"));
|
|
@@ -19613,14 +19739,14 @@ var ServiceRuntimeRunner = class {
|
|
|
19613
19739
|
}
|
|
19614
19740
|
resolveRepoRoot(service, cwd) {
|
|
19615
19741
|
if (cwd) {
|
|
19616
|
-
return
|
|
19742
|
+
return import_node_path30.default.resolve(process.cwd(), cwd);
|
|
19617
19743
|
}
|
|
19618
19744
|
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();
|
|
19619
19745
|
if (repository) {
|
|
19620
19746
|
const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
|
|
19621
19747
|
if (repoName) {
|
|
19622
|
-
const candidate =
|
|
19623
|
-
if ((0,
|
|
19748
|
+
const candidate = import_node_path30.default.join(import_node_os13.default.homedir(), "dev", "pmate", repoName);
|
|
19749
|
+
if ((0, import_node_fs25.existsSync)(candidate)) {
|
|
19624
19750
|
return candidate;
|
|
19625
19751
|
}
|
|
19626
19752
|
}
|
|
@@ -19633,13 +19759,13 @@ var ServiceRuntimeRunner = class {
|
|
|
19633
19759
|
if (!dir) {
|
|
19634
19760
|
throw new Error(`Missing service dir for ${service.id}`);
|
|
19635
19761
|
}
|
|
19636
|
-
return
|
|
19762
|
+
return import_node_path30.default.resolve(repoRoot, dir);
|
|
19637
19763
|
}
|
|
19638
19764
|
async deployVite(service, options) {
|
|
19639
19765
|
this.assertDeployableStaticSite(service);
|
|
19640
19766
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
19641
|
-
const packageJsonPath =
|
|
19642
|
-
if (!(0,
|
|
19767
|
+
const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
|
|
19768
|
+
if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
|
|
19643
19769
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
19644
19770
|
}
|
|
19645
19771
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -19654,8 +19780,8 @@ var ServiceRuntimeRunner = class {
|
|
|
19654
19780
|
this.resolveRepoRoot(service, options.cwd),
|
|
19655
19781
|
buildEnv
|
|
19656
19782
|
);
|
|
19657
|
-
const distDir =
|
|
19658
|
-
if (!(0,
|
|
19783
|
+
const distDir = import_node_path30.default.join(appDir, "dist");
|
|
19784
|
+
if (!(0, import_node_fs25.existsSync)(distDir)) {
|
|
19659
19785
|
throw new Error(`No dist directory found at ${distDir}`);
|
|
19660
19786
|
}
|
|
19661
19787
|
const site = this.getSite(service);
|
|
@@ -19668,8 +19794,8 @@ var ServiceRuntimeRunner = class {
|
|
|
19668
19794
|
async deployStatic(service, options) {
|
|
19669
19795
|
this.assertDeployableStaticSite(service);
|
|
19670
19796
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
19671
|
-
const srcDir =
|
|
19672
|
-
if (!(0,
|
|
19797
|
+
const srcDir = import_node_path30.default.join(appDir, "src");
|
|
19798
|
+
if (!(0, import_node_fs25.existsSync)(srcDir)) {
|
|
19673
19799
|
throw new Error(`No src directory found at ${srcDir}`);
|
|
19674
19800
|
}
|
|
19675
19801
|
const site = this.getSite(service);
|
|
@@ -19703,8 +19829,8 @@ var ServiceRuntimeRunner = class {
|
|
|
19703
19829
|
this.validateFcConfig(service, fc);
|
|
19704
19830
|
const repoRoot = this.resolveRepoRoot(service, options.cwd);
|
|
19705
19831
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
19706
|
-
const packageJsonPath =
|
|
19707
|
-
if (!(0,
|
|
19832
|
+
const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
|
|
19833
|
+
if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
|
|
19708
19834
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
19709
19835
|
}
|
|
19710
19836
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -19757,15 +19883,15 @@ var ServiceRuntimeRunner = class {
|
|
|
19757
19883
|
const repoRoot = this.resolveRepoRoot(service, options.cwd);
|
|
19758
19884
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
19759
19885
|
await this.ensurePnpmWorkspaceRoot(repoRoot);
|
|
19760
|
-
const configPath =
|
|
19761
|
-
if (!(0,
|
|
19886
|
+
const configPath = import_node_path30.default.join(appDir, fc.configFile ?? "s.yaml");
|
|
19887
|
+
if (!(0, import_node_fs25.existsSync)(configPath)) {
|
|
19762
19888
|
throw new Error(`Missing FC config file at ${configPath}`);
|
|
19763
19889
|
}
|
|
19764
|
-
const packageJsonPath =
|
|
19765
|
-
if (!(0,
|
|
19890
|
+
const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
|
|
19891
|
+
if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
|
|
19766
19892
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
19767
19893
|
}
|
|
19768
|
-
const rawConfig = (0,
|
|
19894
|
+
const rawConfig = (0, import_node_fs25.readFileSync)(configPath, "utf8");
|
|
19769
19895
|
if (!rawConfig.includes(fc.functionName)) {
|
|
19770
19896
|
throw new Error(`FC config ${configPath} does not mention functionName ${fc.functionName}`);
|
|
19771
19897
|
}
|
|
@@ -20055,7 +20181,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20055
20181
|
const serverAddress = await resolveServerAddress(server);
|
|
20056
20182
|
const templateName = exposeType === "websocket" ? "nginx.ws.template" : exposeType === "mixed" ? "nginx.mixed.template" : "nginx.rest.template";
|
|
20057
20183
|
const templatePath = this.resolveTemplatePath(templateName);
|
|
20058
|
-
const template = (0,
|
|
20184
|
+
const template = (0, import_node_fs25.readFileSync)(templatePath, "utf8");
|
|
20059
20185
|
const host = `${subdomain}.${("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat"}`;
|
|
20060
20186
|
const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
|
|
20061
20187
|
const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
|
|
@@ -20087,11 +20213,11 @@ var ServiceRuntimeRunner = class {
|
|
|
20087
20213
|
}
|
|
20088
20214
|
if (config.ensurePackageJson) {
|
|
20089
20215
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20090
|
-
const packageJsonPath =
|
|
20091
|
-
if (!(0,
|
|
20216
|
+
const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
|
|
20217
|
+
if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
|
|
20092
20218
|
throw new Error(`Missing package.json at ${packageJsonPath}`);
|
|
20093
20219
|
}
|
|
20094
|
-
const pkgStat = (0,
|
|
20220
|
+
const pkgStat = (0, import_node_fs25.statSync)(packageJsonPath);
|
|
20095
20221
|
if (!pkgStat.isFile()) {
|
|
20096
20222
|
throw new Error(`package.json is not a file at ${packageJsonPath}`);
|
|
20097
20223
|
}
|
|
@@ -20502,9 +20628,9 @@ var ServiceRuntimeRunner = class {
|
|
|
20502
20628
|
return tokens;
|
|
20503
20629
|
}
|
|
20504
20630
|
readPathValue(source, pathExpr) {
|
|
20505
|
-
const
|
|
20631
|
+
const path35 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
|
|
20506
20632
|
let cursor = source;
|
|
20507
|
-
for (const segment of
|
|
20633
|
+
for (const segment of path35) {
|
|
20508
20634
|
if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
|
|
20509
20635
|
return void 0;
|
|
20510
20636
|
}
|
|
@@ -20547,12 +20673,12 @@ var ServiceRuntimeRunner = class {
|
|
|
20547
20673
|
}
|
|
20548
20674
|
resolveTemplatePath(templateName) {
|
|
20549
20675
|
const candidates = [
|
|
20550
|
-
|
|
20551
|
-
|
|
20552
|
-
|
|
20676
|
+
import_node_path30.default.join(__dirname, "..", "templates", templateName),
|
|
20677
|
+
import_node_path30.default.join(__dirname, "..", "src", "templates", templateName),
|
|
20678
|
+
import_node_path30.default.join(__dirname, "templates", templateName)
|
|
20553
20679
|
];
|
|
20554
20680
|
for (const candidate of candidates) {
|
|
20555
|
-
if ((0,
|
|
20681
|
+
if ((0, import_node_fs25.existsSync)(candidate)) {
|
|
20556
20682
|
return candidate;
|
|
20557
20683
|
}
|
|
20558
20684
|
}
|
|
@@ -20584,7 +20710,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20584
20710
|
});
|
|
20585
20711
|
}
|
|
20586
20712
|
loadPackageJson(packageJsonPath) {
|
|
20587
|
-
const raw = (0,
|
|
20713
|
+
const raw = (0, import_node_fs25.readFileSync)(packageJsonPath, "utf8");
|
|
20588
20714
|
const parsed = JSON.parse(raw);
|
|
20589
20715
|
if (!parsed || typeof parsed !== "object") {
|
|
20590
20716
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -20593,7 +20719,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20593
20719
|
}
|
|
20594
20720
|
writePackageJson(packageJsonPath, data) {
|
|
20595
20721
|
const serialized = JSON.stringify(data, null, 2);
|
|
20596
|
-
(0,
|
|
20722
|
+
(0, import_node_fs25.writeFileSync)(packageJsonPath, `${serialized}
|
|
20597
20723
|
`, "utf8");
|
|
20598
20724
|
}
|
|
20599
20725
|
validateFcConfig(service, fc) {
|
|
@@ -20620,8 +20746,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20620
20746
|
}
|
|
20621
20747
|
}
|
|
20622
20748
|
async ensurePnpmWorkspaceRoot(repoRoot) {
|
|
20623
|
-
const workspacePath =
|
|
20624
|
-
if (!(0,
|
|
20749
|
+
const workspacePath = import_node_path30.default.join(repoRoot, "pnpm-workspace.yaml");
|
|
20750
|
+
if (!(0, import_node_fs25.existsSync)(workspacePath)) {
|
|
20625
20751
|
throw new Error(`Missing pnpm-workspace.yaml at ${workspacePath}`);
|
|
20626
20752
|
}
|
|
20627
20753
|
}
|
|
@@ -20695,16 +20821,16 @@ var ServiceRuntimeRunner = class {
|
|
|
20695
20821
|
if (!privateKeyPath) {
|
|
20696
20822
|
throw new Error("Missing ssl.prv in ~/.pmate/config.yaml.");
|
|
20697
20823
|
}
|
|
20698
|
-
if (!(0,
|
|
20824
|
+
if (!(0, import_node_fs25.existsSync)(certificatePath)) {
|
|
20699
20825
|
throw new Error(`SSL certificate file not found: ${certificatePath}`);
|
|
20700
20826
|
}
|
|
20701
|
-
if (!(0,
|
|
20827
|
+
if (!(0, import_node_fs25.existsSync)(privateKeyPath)) {
|
|
20702
20828
|
throw new Error(`SSL private key file not found: ${privateKeyPath}`);
|
|
20703
20829
|
}
|
|
20704
20830
|
return {
|
|
20705
20831
|
certName: host,
|
|
20706
|
-
certificate: (0,
|
|
20707
|
-
privateKey: (0,
|
|
20832
|
+
certificate: (0, import_node_fs25.readFileSync)(certificatePath, "utf8"),
|
|
20833
|
+
privateKey: (0, import_node_fs25.readFileSync)(privateKeyPath, "utf8")
|
|
20708
20834
|
};
|
|
20709
20835
|
}
|
|
20710
20836
|
resolveFcProtocol(fc, certConfig) {
|
|
@@ -21009,6 +21135,18 @@ var ServiceCommandHandler = class {
|
|
|
21009
21135
|
}
|
|
21010
21136
|
case "deploy": {
|
|
21011
21137
|
const record = await registry.getService(args.namespace, args.name);
|
|
21138
|
+
if ("type" in record && (record.type === "electron" || record.type === "ios")) {
|
|
21139
|
+
try {
|
|
21140
|
+
const result = await new NativeServiceDeploy().deploy(record, args);
|
|
21141
|
+
if (!args.dryRun && !args.local) await this.appendDeployHistory(registry, record.id, args.env ?? "prod", "success", String(result.status));
|
|
21142
|
+
this.renderJson(result, true);
|
|
21143
|
+
} catch (error) {
|
|
21144
|
+
if (!args.dryRun && !args.local) await this.appendDeployHistory(registry, record.id, args.env ?? "prod", "failed", error instanceof Error ? error.message : String(error));
|
|
21145
|
+
throw error;
|
|
21146
|
+
}
|
|
21147
|
+
return;
|
|
21148
|
+
}
|
|
21149
|
+
rejectNativeOverrides(args);
|
|
21012
21150
|
const service = await this.materializeServiceEnv(registry, record, args.env);
|
|
21013
21151
|
try {
|
|
21014
21152
|
await runtime.deploy(service, { envName: args.env, ...args.cwd ? { cwd: args.cwd } : {} });
|
|
@@ -21079,16 +21217,6 @@ var ServiceCommandHandler = class {
|
|
|
21079
21217
|
);
|
|
21080
21218
|
return;
|
|
21081
21219
|
}
|
|
21082
|
-
case "ios-build": {
|
|
21083
|
-
const record = await registry.getService(args.namespace, args.name);
|
|
21084
|
-
const result = await new IosBuildService().build(record, args);
|
|
21085
|
-
if (args.json) this.renderJson(result, true);
|
|
21086
|
-
else {
|
|
21087
|
-
ui.success(`Uploaded iOS ${result.version} (${result.build}); Apple processing, TestFlight availability not yet verified`);
|
|
21088
|
-
this.renderJson(result, true);
|
|
21089
|
-
}
|
|
21090
|
-
return;
|
|
21091
|
-
}
|
|
21092
21220
|
case "apk-release": {
|
|
21093
21221
|
const record = await registry.getService(args.namespace, args.name);
|
|
21094
21222
|
const apkRelease = new AndroidApkReleaseService(registry);
|
|
@@ -21191,7 +21319,7 @@ var ServiceCommandHandler = class {
|
|
|
21191
21319
|
format: "dotenv"
|
|
21192
21320
|
}
|
|
21193
21321
|
);
|
|
21194
|
-
const outputPath =
|
|
21322
|
+
const outputPath = import_node_path31.default.resolve(process.cwd(), args.output);
|
|
21195
21323
|
await (0, import_promises5.writeFile)(outputPath, payload.content, "utf8");
|
|
21196
21324
|
ui.success(`Wrote env file for ${args.appId} to ${outputPath}`);
|
|
21197
21325
|
this.renderJson({ ...payload, output: outputPath }, args.json);
|
|
@@ -21417,11 +21545,11 @@ var ServiceCommandHandler = class {
|
|
|
21417
21545
|
return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
21418
21546
|
}
|
|
21419
21547
|
readJsonFile(filePath) {
|
|
21420
|
-
const absolutePath =
|
|
21421
|
-
if (!(0,
|
|
21548
|
+
const absolutePath = import_node_path31.default.resolve(process.cwd(), filePath);
|
|
21549
|
+
if (!(0, import_node_fs26.existsSync)(absolutePath)) {
|
|
21422
21550
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
21423
21551
|
}
|
|
21424
|
-
const raw = (0,
|
|
21552
|
+
const raw = (0, import_node_fs26.readFileSync)(absolutePath, "utf8");
|
|
21425
21553
|
try {
|
|
21426
21554
|
return JSON.parse(raw);
|
|
21427
21555
|
} catch (error) {
|
|
@@ -22229,9 +22357,9 @@ var RoleCommandHandler = class {
|
|
|
22229
22357
|
};
|
|
22230
22358
|
|
|
22231
22359
|
// src/commands/AccountCommandHandler.ts
|
|
22232
|
-
var
|
|
22360
|
+
var import_node_fs27 = require("fs");
|
|
22233
22361
|
var import_node_crypto7 = require("crypto");
|
|
22234
|
-
var
|
|
22362
|
+
var import_node_path32 = __toESM(require("path"));
|
|
22235
22363
|
init_sessionStore();
|
|
22236
22364
|
var AccountCommandHandler = class {
|
|
22237
22365
|
async handle(args) {
|
|
@@ -22239,9 +22367,9 @@ var AccountCommandHandler = class {
|
|
|
22239
22367
|
case "bot-keygen": {
|
|
22240
22368
|
const keyFile = this.generateBotKeyFile(args.app, args.name);
|
|
22241
22369
|
const outPath = args.out ? this.resolveFilePath(args.out) : this.resolveDefaultBotKeyPath(args.app, args.name);
|
|
22242
|
-
(0,
|
|
22243
|
-
(0,
|
|
22244
|
-
(0,
|
|
22370
|
+
(0, import_node_fs27.mkdirSync)(import_node_path32.default.dirname(outPath), { recursive: true });
|
|
22371
|
+
(0, import_node_fs27.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
22372
|
+
(0, import_node_fs27.chmodSync)(outPath, 384);
|
|
22245
22373
|
if (!args.json) {
|
|
22246
22374
|
ui.success(`Bot key saved to ${outPath}`);
|
|
22247
22375
|
}
|
|
@@ -22801,10 +22929,10 @@ var AccountCommandHandler = class {
|
|
|
22801
22929
|
throw new Error("Missing visible apps input");
|
|
22802
22930
|
}
|
|
22803
22931
|
const absolutePath = this.resolveFilePath(args.filePath);
|
|
22804
|
-
if (!(0,
|
|
22932
|
+
if (!(0, import_node_fs27.existsSync)(absolutePath)) {
|
|
22805
22933
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
22806
22934
|
}
|
|
22807
|
-
const raw = (0,
|
|
22935
|
+
const raw = (0, import_node_fs27.readFileSync)(absolutePath, "utf8");
|
|
22808
22936
|
let parsed;
|
|
22809
22937
|
try {
|
|
22810
22938
|
parsed = JSON.parse(raw);
|
|
@@ -22818,13 +22946,13 @@ var AccountCommandHandler = class {
|
|
|
22818
22946
|
return parsed;
|
|
22819
22947
|
}
|
|
22820
22948
|
resolveFilePath(filePath) {
|
|
22821
|
-
return
|
|
22949
|
+
return import_node_path32.default.resolve(process.cwd(), filePath);
|
|
22822
22950
|
}
|
|
22823
22951
|
resolveDefaultBotKeyPath(app, name) {
|
|
22824
|
-
return
|
|
22952
|
+
return import_node_path32.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
|
|
22825
22953
|
}
|
|
22826
22954
|
resolveDefaultAccessKeyPath(app, name) {
|
|
22827
|
-
return
|
|
22955
|
+
return import_node_path32.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
|
|
22828
22956
|
}
|
|
22829
22957
|
homeDir() {
|
|
22830
22958
|
return process.env.HOME || process.env.USERPROFILE || process.cwd();
|
|
@@ -22844,14 +22972,14 @@ var AccountCommandHandler = class {
|
|
|
22844
22972
|
}
|
|
22845
22973
|
renameDefaultBotKeyFile(app, name, newName) {
|
|
22846
22974
|
const oldPath = this.resolveDefaultBotKeyPath(app, name);
|
|
22847
|
-
if (!(0,
|
|
22975
|
+
if (!(0, import_node_fs27.existsSync)(oldPath)) {
|
|
22848
22976
|
return void 0;
|
|
22849
22977
|
}
|
|
22850
22978
|
const keyFile = this.readBotKeyFile(oldPath, app, name);
|
|
22851
22979
|
const newPath = this.resolveDefaultBotKeyPath(app, newName);
|
|
22852
|
-
(0,
|
|
22853
|
-
(0,
|
|
22854
|
-
(0,
|
|
22980
|
+
(0, import_node_fs27.mkdirSync)(import_node_path32.default.dirname(newPath), { recursive: true, mode: 448 });
|
|
22981
|
+
(0, import_node_fs27.writeFileSync)(newPath, JSON.stringify({ ...keyFile, name: newName }, null, 2));
|
|
22982
|
+
(0, import_node_fs27.chmodSync)(newPath, 384);
|
|
22855
22983
|
return newPath;
|
|
22856
22984
|
}
|
|
22857
22985
|
readBotKeyFile(filePath, expectedApp, expectedName) {
|
|
@@ -22859,10 +22987,10 @@ var AccountCommandHandler = class {
|
|
|
22859
22987
|
throw new Error("Missing bot key file");
|
|
22860
22988
|
}
|
|
22861
22989
|
const absolutePath = this.resolveFilePath(filePath);
|
|
22862
|
-
if (!(0,
|
|
22990
|
+
if (!(0, import_node_fs27.existsSync)(absolutePath)) {
|
|
22863
22991
|
throw new Error(`Bot key file not found: ${absolutePath}`);
|
|
22864
22992
|
}
|
|
22865
|
-
const parsed = JSON.parse((0,
|
|
22993
|
+
const parsed = JSON.parse((0, import_node_fs27.readFileSync)(absolutePath, "utf8"));
|
|
22866
22994
|
if (parsed.type !== "pmate-bot-key" || parsed.version !== 1 || parsed.algorithm !== "ed25519" || !parsed.publicKey || !parsed.privateKey) {
|
|
22867
22995
|
throw new Error(`Invalid PMate bot key file: ${absolutePath}`);
|
|
22868
22996
|
}
|
|
@@ -22879,10 +23007,10 @@ var AccountCommandHandler = class {
|
|
|
22879
23007
|
throw new Error("Missing access key file");
|
|
22880
23008
|
}
|
|
22881
23009
|
const absolutePath = this.resolveFilePath(filePath);
|
|
22882
|
-
if (!(0,
|
|
23010
|
+
if (!(0, import_node_fs27.existsSync)(absolutePath)) {
|
|
22883
23011
|
throw new Error(`Access key file not found: ${absolutePath}`);
|
|
22884
23012
|
}
|
|
22885
|
-
const parsed = JSON.parse((0,
|
|
23013
|
+
const parsed = JSON.parse((0, import_node_fs27.readFileSync)(absolutePath, "utf8"));
|
|
22886
23014
|
if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
|
|
22887
23015
|
throw new Error(`Invalid PMate access key file: ${absolutePath}`);
|
|
22888
23016
|
}
|
|
@@ -22904,9 +23032,9 @@ var AccountCommandHandler = class {
|
|
|
22904
23032
|
createdAt: result.key.createdAt
|
|
22905
23033
|
};
|
|
22906
23034
|
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
|
|
22907
|
-
(0,
|
|
22908
|
-
(0,
|
|
22909
|
-
(0,
|
|
23035
|
+
(0, import_node_fs27.mkdirSync)(import_node_path32.default.dirname(outPath), { recursive: true });
|
|
23036
|
+
(0, import_node_fs27.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
23037
|
+
(0, import_node_fs27.chmodSync)(outPath, 384);
|
|
22910
23038
|
}
|
|
22911
23039
|
renderAccessKeyCreateResult(result, asJson, out) {
|
|
22912
23040
|
if (asJson) {
|
|
@@ -22991,8 +23119,8 @@ function encodePathSegment2(value) {
|
|
|
22991
23119
|
}
|
|
22992
23120
|
|
|
22993
23121
|
// src/commands/OrgCommandHandler.ts
|
|
22994
|
-
var
|
|
22995
|
-
var
|
|
23122
|
+
var import_node_fs28 = require("fs");
|
|
23123
|
+
var import_node_path33 = __toESM(require("path"));
|
|
22996
23124
|
init_sessionStore();
|
|
22997
23125
|
var OrgCommandHandler = class {
|
|
22998
23126
|
async handle(args) {
|
|
@@ -23162,11 +23290,11 @@ var OrgCommandHandler = class {
|
|
|
23162
23290
|
if (!filePath) {
|
|
23163
23291
|
throw new Error(`Missing ${itemLabel} input`);
|
|
23164
23292
|
}
|
|
23165
|
-
const absolutePath =
|
|
23166
|
-
if (!(0,
|
|
23293
|
+
const absolutePath = import_node_path33.default.resolve(process.cwd(), filePath);
|
|
23294
|
+
if (!(0, import_node_fs28.existsSync)(absolutePath)) {
|
|
23167
23295
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23168
23296
|
}
|
|
23169
|
-
const raw = (0,
|
|
23297
|
+
const raw = (0, import_node_fs28.readFileSync)(absolutePath, "utf8");
|
|
23170
23298
|
let parsed;
|
|
23171
23299
|
try {
|
|
23172
23300
|
parsed = JSON.parse(raw);
|
|
@@ -23237,9 +23365,9 @@ function encodePathSegment3(value) {
|
|
|
23237
23365
|
}
|
|
23238
23366
|
|
|
23239
23367
|
// src/commands/HostCommandHandler.ts
|
|
23240
|
-
var
|
|
23368
|
+
var import_node_fs29 = require("fs");
|
|
23241
23369
|
var import_node_os14 = require("os");
|
|
23242
|
-
var
|
|
23370
|
+
var import_node_path34 = __toESM(require("path"));
|
|
23243
23371
|
var import_node_child_process15 = require("child_process");
|
|
23244
23372
|
var BLOCK_START = "# >>> pmate host env >>>";
|
|
23245
23373
|
var BLOCK_END = "# <<< pmate host env <<<";
|
|
@@ -23746,26 +23874,7 @@ function parseAppArgs(tokens) {
|
|
|
23746
23874
|
if (!action) {
|
|
23747
23875
|
throw new Error("Missing app action. Use: app list|get|view|create|update|rename|move|icon|delete");
|
|
23748
23876
|
}
|
|
23749
|
-
if (action === "build")
|
|
23750
|
-
const id = parseNamespacedRef(rest.shift() ?? "", { entityLabel: "app ref" }).fullId;
|
|
23751
|
-
const options = {};
|
|
23752
|
-
const switches = /* @__PURE__ */ new Set();
|
|
23753
|
-
while (rest.length) {
|
|
23754
|
-
const key = rest.shift();
|
|
23755
|
-
if (["--dry-run", "--signed", "--dir", "--json"].includes(key)) {
|
|
23756
|
-
if (switches.has(key)) throw new Error(`Duplicate option: ${key}`);
|
|
23757
|
-
switches.add(key);
|
|
23758
|
-
} else if (["--target", "--config", "--platform", "--arch", "--out-dir"].includes(key)) {
|
|
23759
|
-
if (options[key]) throw new Error(`Duplicate option: ${key}`);
|
|
23760
|
-
options[key] = requireValue3(rest, key);
|
|
23761
|
-
} else throw new Error(`Unknown app build option: ${key}`);
|
|
23762
|
-
}
|
|
23763
|
-
if (options["--target"] !== "electron" || !options["--config"]) throw new Error("Use app build <ns:app> --target electron --config <file>");
|
|
23764
|
-
const platform = options["--platform"] ?? (process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : process.platform);
|
|
23765
|
-
const arch = options["--arch"] ?? process.arch;
|
|
23766
|
-
if (!["mac", "win"].includes(platform) || !["arm64", "x64"].includes(arch)) throw new Error("Supported target: --platform mac|win --arch arm64|x64");
|
|
23767
|
-
return { type: "app" /* App */, action, id, target: "electron", config: options["--config"], platform, arch, outDir: options["--out-dir"] ?? "release/desktop", dryRun: switches.has("--dry-run"), signed: switches.has("--signed"), dir: switches.has("--dir"), json: switches.has("--json") };
|
|
23768
|
-
}
|
|
23877
|
+
if (action === "build") throw new Error("app build was removed; register an electron service and use pmate service deploy <ns:service>");
|
|
23769
23878
|
let baseUrl;
|
|
23770
23879
|
let json = false;
|
|
23771
23880
|
const takeSharedOptions4 = () => {
|
|
@@ -24328,7 +24437,7 @@ function parseServiceArgs(tokens) {
|
|
|
24328
24437
|
json
|
|
24329
24438
|
};
|
|
24330
24439
|
}
|
|
24331
|
-
if (action === "ios")
|
|
24440
|
+
if (action === "ios") throw new Error("service ios build was removed; use pmate service deploy <ns:ios-service>");
|
|
24332
24441
|
if (action === "apk") {
|
|
24333
24442
|
return parseServiceApkArgs(rest, { baseUrl, json });
|
|
24334
24443
|
}
|
|
@@ -24337,6 +24446,9 @@ function parseServiceArgs(tokens) {
|
|
|
24337
24446
|
if (!ref || ref.startsWith("-")) {
|
|
24338
24447
|
throw new Error(`Usage: service ${action} <ns:objectId> [--base-url <url>] [--json]`);
|
|
24339
24448
|
}
|
|
24449
|
+
const native = {};
|
|
24450
|
+
const buildValues = ["--config", "--platform", "--arch", "--out-dir", "--scheme", "--team", "--project", "--workspace", "--last-build"];
|
|
24451
|
+
const buildFlags = ["--dry-run", "--local", "--unsigned", "--signed", "--dir"];
|
|
24340
24452
|
let cwd;
|
|
24341
24453
|
let page = 0;
|
|
24342
24454
|
let app;
|
|
@@ -24348,6 +24460,13 @@ function parseServiceArgs(tokens) {
|
|
|
24348
24460
|
let env;
|
|
24349
24461
|
while (rest.length > 0) {
|
|
24350
24462
|
const token = rest.shift();
|
|
24463
|
+
if (buildValues.includes(token) || buildFlags.includes(token)) {
|
|
24464
|
+
if (action !== "deploy") throw new Error(`Unknown service ${action} option: ${token}`);
|
|
24465
|
+
const key = token.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
24466
|
+
if (native[key] !== void 0) throw new Error(`Duplicate option: ${token}`);
|
|
24467
|
+
native[key] = buildFlags.includes(token) ? true : requireValue4(rest, token);
|
|
24468
|
+
continue;
|
|
24469
|
+
}
|
|
24351
24470
|
switch (token) {
|
|
24352
24471
|
case "--category": {
|
|
24353
24472
|
if (action !== "log") throw new Error(`Unknown service ${action} option: ${token}`);
|
|
@@ -24434,8 +24553,17 @@ function parseServiceArgs(tokens) {
|
|
|
24434
24553
|
return { type: "service" /* Service */, action, namespace, name, env, page, baseUrl, json };
|
|
24435
24554
|
}
|
|
24436
24555
|
if (action === "deploy" || action === "stop") {
|
|
24556
|
+
if (native.signed && native.unsigned) throw new Error("--signed and --unsigned cannot be combined");
|
|
24557
|
+
if ((native.unsigned || native.dir) && !native.local) throw new Error("Use --local with --unsigned or --dir; deploy otherwise publishes a release");
|
|
24558
|
+
if (native.platform && !["mac", "win"].includes(String(native.platform))) throw new Error("Supported platform: mac|win");
|
|
24559
|
+
if (native.arch && !["arm64", "x64"].includes(String(native.arch))) throw new Error("Supported architecture: arm64|x64");
|
|
24560
|
+
if (native.project && native.workspace) throw new Error("Use only one of --project or --workspace");
|
|
24561
|
+
if (native.lastBuild !== void 0) {
|
|
24562
|
+
if (!/^(0|[1-9]\d*)$/.test(String(native.lastBuild)) || !Number.isSafeInteger(Number(native.lastBuild))) throw new Error("--last-build must be a non-negative safe integer");
|
|
24563
|
+
native.lastBuild = Number(native.lastBuild);
|
|
24564
|
+
}
|
|
24437
24565
|
if (action === "deploy") env ??= "prod";
|
|
24438
|
-
return { type: "service" /* Service */, action, namespace, name, env, ...cwd ? { cwd } : {}, baseUrl, json };
|
|
24566
|
+
return { type: "service" /* Service */, action, namespace, name, env, ...cwd ? { cwd } : {}, ...native, baseUrl, json };
|
|
24439
24567
|
}
|
|
24440
24568
|
if (action === "init") {
|
|
24441
24569
|
if (!env) {
|
|
@@ -25098,48 +25226,6 @@ function parseServiceEnvArgs(appId, tokens) {
|
|
|
25098
25226
|
}
|
|
25099
25227
|
throw new Error(`Unknown service env action: ${action}`);
|
|
25100
25228
|
}
|
|
25101
|
-
function parseServiceIosArgs(tokens) {
|
|
25102
|
-
const rest = [...tokens];
|
|
25103
|
-
if (rest.shift() !== "build") throw new Error("Usage: service ios build <ns:service> --scheme <scheme>");
|
|
25104
|
-
const ref = rest.shift();
|
|
25105
|
-
if (!ref || ref.startsWith("-")) throw new Error("Missing iOS service ref");
|
|
25106
|
-
const parsed = parseNamespacedRef(ref, { entityLabel: "service ref" });
|
|
25107
|
-
const values = {};
|
|
25108
|
-
let json = false;
|
|
25109
|
-
const allowed = ["--scheme", "--project", "--workspace", "--team", "--cwd", "--last-build", "--base-url"];
|
|
25110
|
-
while (rest.length) {
|
|
25111
|
-
const token = rest.shift();
|
|
25112
|
-
if (token === "--json") {
|
|
25113
|
-
json = true;
|
|
25114
|
-
continue;
|
|
25115
|
-
}
|
|
25116
|
-
if (!allowed.includes(token)) throw new Error(`Unknown service ios build option: ${token}`);
|
|
25117
|
-
if (values[token] !== void 0) throw new Error(`Duplicate option: ${token}`);
|
|
25118
|
-
values[token] = requireValue4(rest, token);
|
|
25119
|
-
}
|
|
25120
|
-
if (!values["--scheme"]) throw new Error("An explicit --scheme is required");
|
|
25121
|
-
if (values["--project"] && values["--workspace"]) throw new Error("Use only one of --project or --workspace");
|
|
25122
|
-
let lastBuild;
|
|
25123
|
-
if (values["--last-build"] !== void 0) {
|
|
25124
|
-
const value = values["--last-build"];
|
|
25125
|
-
if (!/^(0|[1-9]\d*)$/.test(value) || !Number.isSafeInteger(Number(value))) throw new Error("--last-build must be a non-negative safe integer");
|
|
25126
|
-
lastBuild = Number(value);
|
|
25127
|
-
}
|
|
25128
|
-
return {
|
|
25129
|
-
type: "service" /* Service */,
|
|
25130
|
-
action: "ios-build",
|
|
25131
|
-
namespace: parsed.namespace,
|
|
25132
|
-
name: parsed.objectId,
|
|
25133
|
-
scheme: values["--scheme"],
|
|
25134
|
-
project: values["--project"],
|
|
25135
|
-
workspace: values["--workspace"],
|
|
25136
|
-
team: values["--team"],
|
|
25137
|
-
cwd: values["--cwd"],
|
|
25138
|
-
lastBuild,
|
|
25139
|
-
baseUrl: values["--base-url"],
|
|
25140
|
-
json
|
|
25141
|
-
};
|
|
25142
|
-
}
|
|
25143
25229
|
|
|
25144
25230
|
// src/logsCommandParser.ts
|
|
25145
25231
|
init_namespacedRef();
|
|
@@ -26608,7 +26694,7 @@ function requireValue11(tokens, option) {
|
|
|
26608
26694
|
|
|
26609
26695
|
// src/index.ts
|
|
26610
26696
|
var pkg = JSON.parse(
|
|
26611
|
-
(0,
|
|
26697
|
+
(0, import_node_fs30.readFileSync)(import_node_path35.default.resolve(__dirname, "..", "package.json"), "utf8")
|
|
26612
26698
|
);
|
|
26613
26699
|
var HELP_TEXT = [
|
|
26614
26700
|
import_chalk4.default.bold(`pmate v${pkg.version}`),
|
|
@@ -26757,7 +26843,6 @@ var HELP_TEXT = [
|
|
|
26757
26843
|
` ${import_chalk4.default.gray(" kv list|get|exists|set|delete <name> [options]")}`,
|
|
26758
26844
|
` ${import_chalk4.default.gray(" defaults: chain=pmate namespace=pmate env base URLs from BLOCKCHAIN_BASE_URL / INDEXER_BASE_URL")}`,
|
|
26759
26845
|
` ${import_chalk4.default.cyan("app")} Manage app registry entries via apps-api`,
|
|
26760
|
-
` ${import_chalk4.default.gray(" build <ns:app> --target electron --config <file> [--platform mac] [--arch arm64|x64] [--out-dir <dir>] [--dir] [--dry-run] [--signed]")}`,
|
|
26761
26846
|
` ${import_chalk4.default.gray(" list [--ns <namespace>] [--all] [--base-url <url>] [--json]")}`,
|
|
26762
26847
|
` ${import_chalk4.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
26763
26848
|
` ${import_chalk4.default.gray(" view <ns:objectId> [--base-url <url>]")}`,
|
|
@@ -26773,7 +26858,7 @@ var HELP_TEXT = [
|
|
|
26773
26858
|
` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
26774
26859
|
` ${import_chalk4.default.gray(" default base URL: https://apps-api.pmate.chat")}`,
|
|
26775
26860
|
` ${import_chalk4.default.cyan("service")} Manage service registry entries via apps-api`,
|
|
26776
|
-
"
|
|
26861
|
+
" 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>]",
|
|
26777
26862
|
` ${import_chalk4.default.gray(" list [--namespace <ns>] [--repo <owner/name|https://github.com/owner/name>] [--server <name>] [--base-url <url>] [--json]")}`,
|
|
26778
26863
|
` ${import_chalk4.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
26779
26864
|
` ${import_chalk4.default.gray(" view <ns:objectId> [--base-url <url>]")}`,
|