@pmate/cli 0.21.11 → 0.21.13
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.js +126 -64
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17575,7 +17575,7 @@ var import_node_readline = require("readline");
|
|
|
17575
17575
|
var import_chalk3 = __toESM(require("chalk"));
|
|
17576
17576
|
var ServiceRuntimeRunner = class {
|
|
17577
17577
|
async deploy(service, options = {}) {
|
|
17578
|
-
switch (service
|
|
17578
|
+
switch (this.getType(service)) {
|
|
17579
17579
|
case "vite":
|
|
17580
17580
|
await this.deployVite(service, options);
|
|
17581
17581
|
return;
|
|
@@ -17589,12 +17589,17 @@ var ServiceRuntimeRunner = class {
|
|
|
17589
17589
|
case "python":
|
|
17590
17590
|
await this.deployScriptManaged(service);
|
|
17591
17591
|
return;
|
|
17592
|
+
case "ios":
|
|
17593
|
+
case "android":
|
|
17594
|
+
throw new Error(
|
|
17595
|
+
`Service type "${this.getType(service)}" is registry-only for now; deploy is not supported yet`
|
|
17596
|
+
);
|
|
17592
17597
|
default:
|
|
17593
|
-
throw new Error(`Unsupported
|
|
17598
|
+
throw new Error(`Unsupported service type for deploy: ${this.getType(service)}`);
|
|
17594
17599
|
}
|
|
17595
17600
|
}
|
|
17596
17601
|
async init(service, options = {}) {
|
|
17597
|
-
switch (service
|
|
17602
|
+
switch (this.getType(service)) {
|
|
17598
17603
|
case "vite":
|
|
17599
17604
|
case "static":
|
|
17600
17605
|
await this.initStaticLike(service);
|
|
@@ -17606,8 +17611,13 @@ var ServiceRuntimeRunner = class {
|
|
|
17606
17611
|
case "python":
|
|
17607
17612
|
await this.initServerApp(service, options, { ensurePackageJson: false });
|
|
17608
17613
|
return;
|
|
17614
|
+
case "ios":
|
|
17615
|
+
case "android":
|
|
17616
|
+
throw new Error(
|
|
17617
|
+
`Service type "${this.getType(service)}" is registry-only for now; init is not supported yet`
|
|
17618
|
+
);
|
|
17609
17619
|
default:
|
|
17610
|
-
throw new Error(`Unsupported
|
|
17620
|
+
throw new Error(`Unsupported service type for init: ${this.getType(service)}`);
|
|
17611
17621
|
}
|
|
17612
17622
|
}
|
|
17613
17623
|
async log(service, options = {}) {
|
|
@@ -17677,14 +17687,56 @@ var ServiceRuntimeRunner = class {
|
|
|
17677
17687
|
}
|
|
17678
17688
|
}
|
|
17679
17689
|
}
|
|
17680
|
-
|
|
17681
|
-
return
|
|
17690
|
+
isLegacy(service) {
|
|
17691
|
+
return "runtimeType" in service;
|
|
17692
|
+
}
|
|
17693
|
+
getType(service) {
|
|
17694
|
+
return this.isLegacy(service) ? service.runtimeType : service.type;
|
|
17695
|
+
}
|
|
17696
|
+
getSite(service) {
|
|
17697
|
+
if (!this.isLegacy(service) && service.site) {
|
|
17698
|
+
return service.site;
|
|
17699
|
+
}
|
|
17700
|
+
const deploy = this.isLegacy(service) ? service.deploy ?? {} : {};
|
|
17701
|
+
return {
|
|
17702
|
+
exposeType: "static-site",
|
|
17703
|
+
repository: String(deploy.repository ?? ""),
|
|
17704
|
+
dir: String(deploy.dir ?? ""),
|
|
17705
|
+
bucket: String(deploy.bucket ?? ""),
|
|
17706
|
+
domain: String(deploy.domain ?? ""),
|
|
17707
|
+
...deploy.subdomain ? { subdomain: deploy.subdomain } : {}
|
|
17708
|
+
};
|
|
17709
|
+
}
|
|
17710
|
+
getNetwork(service) {
|
|
17711
|
+
if (!this.isLegacy(service) && service.network) {
|
|
17712
|
+
return service.network;
|
|
17713
|
+
}
|
|
17714
|
+
const deploy = this.isLegacy(service) ? service.deploy ?? {} : {};
|
|
17715
|
+
const exposeType = deploy.port === void 0 ? "internal" : deploy.serviceType === "ws" ? "websocket" : "rest";
|
|
17716
|
+
return {
|
|
17717
|
+
exposeType,
|
|
17718
|
+
repository: String(deploy.repository ?? ""),
|
|
17719
|
+
dir: String(deploy.dir ?? ""),
|
|
17720
|
+
server: String(deploy.server ?? ""),
|
|
17721
|
+
...deploy.port !== void 0 ? { port: Number(deploy.port) } : {},
|
|
17722
|
+
...deploy.domain ? { domain: deploy.domain } : {},
|
|
17723
|
+
...deploy.subdomain ? { subdomain: deploy.subdomain } : {}
|
|
17724
|
+
};
|
|
17725
|
+
}
|
|
17726
|
+
getRunner(service) {
|
|
17727
|
+
if (!this.isLegacy(service) && service.runner) {
|
|
17728
|
+
return service.runner;
|
|
17729
|
+
}
|
|
17730
|
+
const deploy = this.isLegacy(service) ? service.deploy ?? {} : {};
|
|
17731
|
+
return {
|
|
17732
|
+
script: String(deploy.script ?? "")
|
|
17733
|
+
};
|
|
17682
17734
|
}
|
|
17683
17735
|
resolveRepoRoot(service, cwd) {
|
|
17684
17736
|
if (cwd) {
|
|
17685
17737
|
return import_node_path23.default.resolve(process.cwd(), cwd);
|
|
17686
17738
|
}
|
|
17687
|
-
const repository = this.
|
|
17739
|
+
const repository = this.getType(service) === "vite" || this.getType(service) === "static" ? this.getSite(service).repository?.trim() : this.getType(service) === "ios" || this.getType(service) === "android" ? void 0 : this.getNetwork(service).repository?.trim();
|
|
17688
17740
|
if (repository) {
|
|
17689
17741
|
const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
|
|
17690
17742
|
if (repoName) {
|
|
@@ -17698,9 +17750,9 @@ var ServiceRuntimeRunner = class {
|
|
|
17698
17750
|
}
|
|
17699
17751
|
resolveLocalDir(service, cwd) {
|
|
17700
17752
|
const repoRoot = this.resolveRepoRoot(service, cwd);
|
|
17701
|
-
const dir = this.
|
|
17753
|
+
const dir = this.getType(service) === "vite" || this.getType(service) === "static" ? this.getSite(service).dir?.trim() : this.getType(service) === "ios" || this.getType(service) === "android" ? void 0 : this.getNetwork(service).dir?.trim();
|
|
17702
17754
|
if (!dir) {
|
|
17703
|
-
throw new Error(`Missing
|
|
17755
|
+
throw new Error(`Missing service dir for ${service.id}`);
|
|
17704
17756
|
}
|
|
17705
17757
|
return import_node_path23.default.resolve(repoRoot, dir);
|
|
17706
17758
|
}
|
|
@@ -17720,9 +17772,10 @@ var ServiceRuntimeRunner = class {
|
|
|
17720
17772
|
if (!(0, import_node_fs18.existsSync)(distDir)) {
|
|
17721
17773
|
throw new Error(`No dist directory found at ${distDir}`);
|
|
17722
17774
|
}
|
|
17723
|
-
const
|
|
17775
|
+
const site = this.getSite(service);
|
|
17776
|
+
const bucketName = site.bucket?.trim();
|
|
17724
17777
|
if (!bucketName) {
|
|
17725
|
-
throw new Error(`Missing
|
|
17778
|
+
throw new Error(`Missing site.bucket for ${service.id}`);
|
|
17726
17779
|
}
|
|
17727
17780
|
await AliyunService.uploadDirectory(distDir, bucketName);
|
|
17728
17781
|
}
|
|
@@ -17732,29 +17785,30 @@ var ServiceRuntimeRunner = class {
|
|
|
17732
17785
|
if (!(0, import_node_fs18.existsSync)(srcDir)) {
|
|
17733
17786
|
throw new Error(`No src directory found at ${srcDir}`);
|
|
17734
17787
|
}
|
|
17735
|
-
const
|
|
17788
|
+
const site = this.getSite(service);
|
|
17789
|
+
const bucketName = site.bucket?.trim();
|
|
17736
17790
|
if (!bucketName) {
|
|
17737
|
-
throw new Error(`Missing
|
|
17791
|
+
throw new Error(`Missing site.bucket for ${service.id}`);
|
|
17738
17792
|
}
|
|
17739
17793
|
await AliyunService.uploadDirectory(srcDir, bucketName);
|
|
17740
17794
|
}
|
|
17741
17795
|
async deployNode(service) {
|
|
17742
|
-
const
|
|
17743
|
-
const server =
|
|
17744
|
-
const repository =
|
|
17796
|
+
const network = this.getNetwork(service);
|
|
17797
|
+
const server = network.server?.trim();
|
|
17798
|
+
const repository = network.repository?.trim();
|
|
17745
17799
|
if (!server) {
|
|
17746
|
-
throw new Error(`Missing
|
|
17800
|
+
throw new Error(`Missing network.server for ${service.id}`);
|
|
17747
17801
|
}
|
|
17748
17802
|
if (!repository) {
|
|
17749
|
-
throw new Error(`Missing
|
|
17803
|
+
throw new Error(`Missing network.repository for ${service.id}`);
|
|
17750
17804
|
}
|
|
17751
|
-
const port =
|
|
17805
|
+
const port = network.port;
|
|
17752
17806
|
if (port !== void 0 && (!Number.isFinite(port) || port <= 0)) {
|
|
17753
|
-
throw new Error(`Invalid
|
|
17807
|
+
throw new Error(`Invalid network.port for ${service.id}`);
|
|
17754
17808
|
}
|
|
17755
|
-
const appDir =
|
|
17809
|
+
const appDir = network.dir?.trim();
|
|
17756
17810
|
if (!appDir) {
|
|
17757
|
-
throw new Error(`Missing
|
|
17811
|
+
throw new Error(`Missing network.dir for ${service.id}`);
|
|
17758
17812
|
}
|
|
17759
17813
|
const repoDir = this.getRepoDirName(repository);
|
|
17760
17814
|
const repoUrl = this.getRepoUrl(repository);
|
|
@@ -17782,18 +17836,19 @@ var ServiceRuntimeRunner = class {
|
|
|
17782
17836
|
await this.runRemoteCommand(server, command);
|
|
17783
17837
|
}
|
|
17784
17838
|
async deployScriptManaged(service) {
|
|
17785
|
-
const
|
|
17786
|
-
const
|
|
17787
|
-
const
|
|
17788
|
-
const
|
|
17839
|
+
const network = this.getNetwork(service);
|
|
17840
|
+
const runner = this.getRunner(service);
|
|
17841
|
+
const server = network.server?.trim();
|
|
17842
|
+
const repository = network.repository?.trim();
|
|
17843
|
+
const script = runner.script?.trim();
|
|
17789
17844
|
if (!server) {
|
|
17790
|
-
throw new Error(`Missing
|
|
17845
|
+
throw new Error(`Missing network.server for ${service.id}`);
|
|
17791
17846
|
}
|
|
17792
17847
|
if (!repository) {
|
|
17793
|
-
throw new Error(`Missing
|
|
17848
|
+
throw new Error(`Missing network.repository for ${service.id}`);
|
|
17794
17849
|
}
|
|
17795
17850
|
if (!script) {
|
|
17796
|
-
throw new Error(`Missing
|
|
17851
|
+
throw new Error(`Missing runner.script for ${service.id}`);
|
|
17797
17852
|
}
|
|
17798
17853
|
const repoDir = this.getRepoDirName(repository);
|
|
17799
17854
|
const repoUrl = this.getRepoUrl(repository);
|
|
@@ -17812,43 +17867,43 @@ var ServiceRuntimeRunner = class {
|
|
|
17812
17867
|
await this.runRemoteCommand(server, command);
|
|
17813
17868
|
}
|
|
17814
17869
|
async initStaticLike(service) {
|
|
17815
|
-
const
|
|
17816
|
-
const bucketName =
|
|
17817
|
-
const baseDomain =
|
|
17870
|
+
const site = this.getSite(service);
|
|
17871
|
+
const bucketName = site.bucket?.trim();
|
|
17872
|
+
const baseDomain = site.domain?.trim();
|
|
17818
17873
|
if (!bucketName) {
|
|
17819
|
-
throw new Error(`Missing
|
|
17874
|
+
throw new Error(`Missing site.bucket for ${service.id}`);
|
|
17820
17875
|
}
|
|
17821
17876
|
if (!baseDomain) {
|
|
17822
|
-
throw new Error(`Missing
|
|
17877
|
+
throw new Error(`Missing site.domain for ${service.id}`);
|
|
17823
17878
|
}
|
|
17824
17879
|
await setupStaticSiteBucket({
|
|
17825
17880
|
bucketName,
|
|
17826
17881
|
domainName: baseDomain,
|
|
17827
|
-
subdomain:
|
|
17828
|
-
routeType: service
|
|
17882
|
+
subdomain: site.subdomain,
|
|
17883
|
+
routeType: this.getType(service) === "vite" ? "spa" : "spa"
|
|
17829
17884
|
});
|
|
17830
17885
|
}
|
|
17831
17886
|
async initServerApp(service, options, config) {
|
|
17832
|
-
const
|
|
17833
|
-
const subdomain =
|
|
17834
|
-
const port =
|
|
17835
|
-
const server =
|
|
17836
|
-
const
|
|
17887
|
+
const network = this.getNetwork(service);
|
|
17888
|
+
const subdomain = "subdomain" in network ? network.subdomain?.trim() : void 0;
|
|
17889
|
+
const port = network.port;
|
|
17890
|
+
const server = network.server?.trim();
|
|
17891
|
+
const exposeType = network.exposeType;
|
|
17837
17892
|
if (subdomain && port === void 0) {
|
|
17838
|
-
throw new Error(`Missing
|
|
17893
|
+
throw new Error(`Missing network.port for ${service.id} (required when subdomain is set)`);
|
|
17839
17894
|
}
|
|
17840
17895
|
if (subdomain && !server) {
|
|
17841
|
-
throw new Error(`Missing
|
|
17896
|
+
throw new Error(`Missing network.server for ${service.id}`);
|
|
17842
17897
|
}
|
|
17843
|
-
if (
|
|
17844
|
-
throw new Error(`Invalid
|
|
17898
|
+
if (!["rest", "rpc", "websocket", "internal"].includes(exposeType)) {
|
|
17899
|
+
throw new Error(`Invalid network.exposeType for ${service.id}`);
|
|
17845
17900
|
}
|
|
17846
17901
|
if (subdomain) {
|
|
17847
17902
|
const serverAddress = await resolveServerAddress(server);
|
|
17848
|
-
const templateName =
|
|
17903
|
+
const templateName = exposeType === "websocket" ? "nginx.ws.template" : "nginx.rest.template";
|
|
17849
17904
|
const templatePath = this.resolveTemplatePath(templateName);
|
|
17850
17905
|
const template = (0, import_node_fs18.readFileSync)(templatePath, "utf8");
|
|
17851
|
-
const host = `${subdomain}.${
|
|
17906
|
+
const host = `${subdomain}.${("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat"}`;
|
|
17852
17907
|
const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
|
|
17853
17908
|
const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
|
|
17854
17909
|
ui.info(`Uploading nginx config to ${server}`);
|
|
@@ -17856,7 +17911,7 @@ var ServiceRuntimeRunner = class {
|
|
|
17856
17911
|
ui.success(`Uploaded nginx config to ${server}`, remotePath);
|
|
17857
17912
|
await this.reloadNginx(server);
|
|
17858
17913
|
ui.success(`Reloaded nginx on ${server}`);
|
|
17859
|
-
const baseDomain =
|
|
17914
|
+
const baseDomain = ("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat";
|
|
17860
17915
|
const existingA = await AliyunService.getARecordValue(baseDomain, subdomain);
|
|
17861
17916
|
if (existingA) {
|
|
17862
17917
|
if (existingA !== serverAddress) {
|
|
@@ -17899,18 +17954,19 @@ var ServiceRuntimeRunner = class {
|
|
|
17899
17954
|
}
|
|
17900
17955
|
}
|
|
17901
17956
|
async showScriptLogs(service) {
|
|
17902
|
-
const
|
|
17903
|
-
const
|
|
17904
|
-
const
|
|
17905
|
-
const
|
|
17957
|
+
const network = this.getNetwork(service);
|
|
17958
|
+
const runner = this.getRunner(service);
|
|
17959
|
+
const server = network.server?.trim();
|
|
17960
|
+
const repository = network.repository?.trim();
|
|
17961
|
+
const script = runner.script?.trim();
|
|
17906
17962
|
if (!server) {
|
|
17907
|
-
throw new Error(`Missing
|
|
17963
|
+
throw new Error(`Missing network.server for ${service.id}`);
|
|
17908
17964
|
}
|
|
17909
17965
|
if (!repository) {
|
|
17910
|
-
throw new Error(`Missing
|
|
17966
|
+
throw new Error(`Missing network.repository for ${service.id}`);
|
|
17911
17967
|
}
|
|
17912
17968
|
if (!script) {
|
|
17913
|
-
throw new Error(`Missing
|
|
17969
|
+
throw new Error(`Missing runner.script for ${service.id}`);
|
|
17914
17970
|
}
|
|
17915
17971
|
const repoDir = this.getRepoDirName(repository);
|
|
17916
17972
|
const scriptPath = script.startsWith("/") || script.startsWith("./") ? script : `./${script}`;
|
|
@@ -18480,9 +18536,6 @@ var ServiceRegistryClient = class {
|
|
|
18480
18536
|
if (namespace && item.namespace !== namespace) {
|
|
18481
18537
|
return false;
|
|
18482
18538
|
}
|
|
18483
|
-
if (server && item.deploy?.server?.trim() !== server) {
|
|
18484
|
-
return false;
|
|
18485
|
-
}
|
|
18486
18539
|
return true;
|
|
18487
18540
|
});
|
|
18488
18541
|
}
|
|
@@ -18858,12 +18911,20 @@ var ServiceCommandHandler = class {
|
|
|
18858
18911
|
if (!payload || typeof payload !== "object") {
|
|
18859
18912
|
return;
|
|
18860
18913
|
}
|
|
18861
|
-
|
|
18862
|
-
|
|
18863
|
-
|
|
18914
|
+
let serverValue;
|
|
18915
|
+
let portValue;
|
|
18916
|
+
const network = payload.network;
|
|
18917
|
+
if (network && typeof network === "object") {
|
|
18918
|
+
serverValue = network.server;
|
|
18919
|
+
portValue = network.port;
|
|
18920
|
+
} else {
|
|
18921
|
+
const deploy = payload.deploy;
|
|
18922
|
+
if (!deploy || typeof deploy !== "object") {
|
|
18923
|
+
return;
|
|
18924
|
+
}
|
|
18925
|
+
serverValue = deploy.server;
|
|
18926
|
+
portValue = deploy.port;
|
|
18864
18927
|
}
|
|
18865
|
-
const serverValue = deploy.server;
|
|
18866
|
-
const portValue = deploy.port;
|
|
18867
18928
|
const server = typeof serverValue === "string" ? serverValue.trim() : "";
|
|
18868
18929
|
const port = typeof portValue === "number" ? portValue : typeof portValue === "string" && portValue.trim() ? Number(portValue) : void 0;
|
|
18869
18930
|
if (!server || port === void 0 || !Number.isFinite(port)) {
|
|
@@ -18871,7 +18932,8 @@ var ServiceCommandHandler = class {
|
|
|
18871
18932
|
}
|
|
18872
18933
|
const services = await registry.listServices({ server });
|
|
18873
18934
|
const conflict = services.find((service) => {
|
|
18874
|
-
|
|
18935
|
+
const servicePort = "network" in service && service.network && typeof service.network === "object" ? service.network.port : "deploy" in service && service.deploy && typeof service.deploy === "object" ? service.deploy.port : void 0;
|
|
18936
|
+
if (servicePort !== port) {
|
|
18875
18937
|
return false;
|
|
18876
18938
|
}
|
|
18877
18939
|
if (!currentService) {
|