@pmate/cli 0.24.12 → 0.24.14

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 CHANGED
@@ -902,7 +902,7 @@ type ServiceCommandArgs = {
902
902
  json: boolean;
903
903
  } | {
904
904
  type: Command.Service;
905
- action: "deploy";
905
+ action: "deploy" | "stop";
906
906
  namespace: string;
907
907
  name: string;
908
908
  baseUrl?: string;
package/dist/index.js CHANGED
@@ -18055,6 +18055,24 @@ var ServiceRuntimeRunner = class {
18055
18055
  throw new Error(`Unsupported service type for deploy: ${this.getType(service)}`);
18056
18056
  }
18057
18057
  }
18058
+ async stop(service) {
18059
+ switch (this.getType(service)) {
18060
+ case "rust":
18061
+ case "python":
18062
+ await this.stopScriptManaged(service);
18063
+ return;
18064
+ case "node":
18065
+ throw new Error("service stop is only supported for script-managed python/rust services for now");
18066
+ case "vite":
18067
+ case "static":
18068
+ case "fc":
18069
+ case "ios":
18070
+ case "android":
18071
+ throw new Error(`Service type "${this.getType(service)}" does not support stop`);
18072
+ default:
18073
+ throw new Error(`Unsupported service type for stop: ${this.getType(service)}`);
18074
+ }
18075
+ }
18058
18076
  async init(service, options = {}) {
18059
18077
  switch (this.getType(service)) {
18060
18078
  case "vite":
@@ -18490,6 +18508,32 @@ var ServiceRuntimeRunner = class {
18490
18508
  ].join(" && ");
18491
18509
  await this.runRemoteCommand(server, command);
18492
18510
  }
18511
+ async stopScriptManaged(service) {
18512
+ const network = this.getNetwork(service);
18513
+ const runner = this.getRunner(service);
18514
+ const server = network.server?.trim();
18515
+ const repository = network.repository?.trim();
18516
+ const script = runner.script?.trim();
18517
+ if (!server) {
18518
+ throw new Error(`Missing network.server for ${service.id}`);
18519
+ }
18520
+ if (!repository) {
18521
+ throw new Error(`Missing network.repository for ${service.id}`);
18522
+ }
18523
+ if (!script) {
18524
+ throw new Error(`Missing runner.script for ${service.id}`);
18525
+ }
18526
+ const repoDir = this.getRepoDirName(repository);
18527
+ const scriptPath = script.startsWith("/") || script.startsWith("./") ? script : `./${script}`;
18528
+ const command = [
18529
+ `cd "$HOME"`,
18530
+ `cd "${repoDir}"`,
18531
+ `if [ -f ~/.profile ]; then . ~/.profile; fi`,
18532
+ `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi`,
18533
+ `"${scriptPath}" stop`
18534
+ ].join(" && ");
18535
+ await this.runRemoteCommand(server, command);
18536
+ }
18493
18537
  async initStaticLike(service) {
18494
18538
  const site = this.getSite(service);
18495
18539
  const bucketName = site.bucket?.trim();
@@ -19411,6 +19455,11 @@ var ServiceCommandHandler = class {
19411
19455
  await runtime.deploy(record);
19412
19456
  return;
19413
19457
  }
19458
+ case "stop": {
19459
+ const record = await registry.getService(args.namespace, args.name);
19460
+ await runtime.stop(record);
19461
+ return;
19462
+ }
19414
19463
  case "init": {
19415
19464
  const record = await registry.getService(args.namespace, args.name);
19416
19465
  await runtime.init(record, { cwd: args.cwd });
@@ -19930,15 +19979,14 @@ var AccountCommandHandler = class {
19930
19979
  switch (args.action) {
19931
19980
  case "bot-keygen": {
19932
19981
  const keyFile = this.generateBotKeyFile(args.app, args.name);
19933
- if (args.out) {
19934
- const outPath = this.resolveFilePath(args.out);
19935
- (0, import_node_fs20.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
19936
- (0, import_node_fs20.chmodSync)(outPath, 384);
19937
- if (!args.json) {
19938
- ui.success(`Bot key saved to ${outPath}`);
19939
- }
19982
+ const outPath = args.out ? this.resolveFilePath(args.out) : this.resolveDefaultBotKeyPath(args.app, args.name);
19983
+ (0, import_node_fs20.mkdirSync)(import_node_path24.default.dirname(outPath), { recursive: true });
19984
+ (0, import_node_fs20.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
19985
+ (0, import_node_fs20.chmodSync)(outPath, 384);
19986
+ if (!args.json) {
19987
+ ui.success(`Bot key saved to ${outPath}`);
19940
19988
  }
19941
- if (args.json || !args.out) {
19989
+ if (args.json) {
19942
19990
  ui.plain(JSON.stringify(keyFile, null, 2));
19943
19991
  }
19944
19992
  return;
@@ -20397,6 +20445,12 @@ var AccountCommandHandler = class {
20397
20445
  resolveFilePath(filePath) {
20398
20446
  return import_node_path24.default.resolve(process.cwd(), filePath);
20399
20447
  }
20448
+ resolveDefaultBotKeyPath(app, name) {
20449
+ return import_node_path24.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
20450
+ }
20451
+ homeDir() {
20452
+ return process.env.HOME || process.env.USERPROFILE || process.cwd();
20453
+ }
20400
20454
  generateBotKeyFile(app, name) {
20401
20455
  const { publicKey, privateKey } = (0, import_node_crypto4.generateKeyPairSync)("ed25519");
20402
20456
  return {
@@ -21974,7 +22028,7 @@ function parseServiceArgs(tokens) {
21974
22028
  }
21975
22029
  const action = rawAction === "view" ? "view" : rawAction;
21976
22030
  if (!action) {
21977
- throw new Error("Missing service action. Use: service list|get|view|create|update|rename|delete");
22031
+ throw new Error("Missing service action. Use: service list|get|view|create|update|rename|delete|deploy|stop|init|log");
21978
22032
  }
21979
22033
  let baseUrl;
21980
22034
  let json = false;
@@ -22031,7 +22085,7 @@ function parseServiceArgs(tokens) {
22031
22085
  json
22032
22086
  };
22033
22087
  }
22034
- if (action === "get" || action === "delete" || action === "deploy" || action === "init" || action === "log") {
22088
+ if (action === "get" || action === "delete" || action === "deploy" || action === "stop" || action === "init" || action === "log") {
22035
22089
  const ref = rest.shift();
22036
22090
  if (!ref || ref.startsWith("-")) {
22037
22091
  throw new Error(`Usage: service ${action} <ns:objectId> [--base-url <url>] [--json]`);
@@ -22079,7 +22133,7 @@ function parseServiceArgs(tokens) {
22079
22133
  if (action === "log") {
22080
22134
  return { type: "service" /* Service */, action, namespace, name, baseUrl, json, page, history, search, follow };
22081
22135
  }
22082
- if (action === "deploy") {
22136
+ if (action === "deploy" || action === "stop") {
22083
22137
  return { type: "service" /* Service */, action, namespace, name, baseUrl, json };
22084
22138
  }
22085
22139
  if (action === "init") {
@@ -23737,6 +23791,7 @@ var HELP_TEXT = [
23737
23791
  ` ${import_chalk4.default.gray(" move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]")}`,
23738
23792
  ` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
23739
23793
  ` ${import_chalk4.default.gray(" deploy <ns:objectId> [--base-url <url>]")}`,
23794
+ ` ${import_chalk4.default.gray(" stop <ns:objectId> [--base-url <url>]")}`,
23740
23795
  ` ${import_chalk4.default.gray(" init <ns:objectId> [--cwd <dir>] [--base-url <url>]")}`,
23741
23796
  ` ${import_chalk4.default.gray(" log <ns:objectId> [--page <n>] [--history] [--search <keyword>] [--follow|-f] [--base-url <url>]")}`,
23742
23797
  ` ${import_chalk4.default.gray(" default base URL: https://apps-api.pmate.chat")}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.24.12",
3
+ "version": "0.24.14",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {