sagacloud 0.3.3 → 0.3.5
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 +128 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -71,6 +71,7 @@ function getAuthFilePath() {
|
|
|
71
71
|
function readAuthProfile() {
|
|
72
72
|
const envToken = (process.env.SAGACLOUD_TOKEN || "").trim();
|
|
73
73
|
const envUrl = (process.env.SAGACLOUD_API_URL || "").trim().replace(/\/+$/, "");
|
|
74
|
+
const envPanelUrl = (process.env.SAGACLOUD_PANEL_URL || "").trim().replace(/\/+$/, "");
|
|
74
75
|
let disk = null;
|
|
75
76
|
const fp = getAuthFilePath();
|
|
76
77
|
if (fs.existsSync(fp)) {
|
|
@@ -79,7 +80,8 @@ function readAuthProfile() {
|
|
|
79
80
|
if (parsed?.token) {
|
|
80
81
|
disk = {
|
|
81
82
|
...parsed,
|
|
82
|
-
apiUrl: (parsed.apiUrl || DEFAULT_API_BASE_URL).replace(/\/+$/, "")
|
|
83
|
+
apiUrl: (parsed.apiUrl || DEFAULT_API_BASE_URL).replace(/\/+$/, ""),
|
|
84
|
+
panelUrl: (parsed.panelUrl || DEFAULT_PANEL_BASE_URL).replace(/\/+$/, "")
|
|
83
85
|
};
|
|
84
86
|
}
|
|
85
87
|
} catch {
|
|
@@ -90,14 +92,18 @@ function readAuthProfile() {
|
|
|
90
92
|
return {
|
|
91
93
|
token: envToken,
|
|
92
94
|
apiUrl: envUrl || disk?.apiUrl || DEFAULT_API_BASE_URL,
|
|
93
|
-
panelUrl: disk?.panelUrl || DEFAULT_PANEL_BASE_URL,
|
|
95
|
+
panelUrl: envPanelUrl || disk?.panelUrl || DEFAULT_PANEL_BASE_URL,
|
|
94
96
|
user: disk?.user,
|
|
95
97
|
tenant: disk?.tenant,
|
|
96
98
|
tenantName: disk?.tenantName
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
|
-
if (disk && envUrl) {
|
|
100
|
-
return {
|
|
101
|
+
if (disk && (envUrl || envPanelUrl)) {
|
|
102
|
+
return {
|
|
103
|
+
...disk,
|
|
104
|
+
apiUrl: envUrl || disk.apiUrl,
|
|
105
|
+
panelUrl: envPanelUrl || disk.panelUrl
|
|
106
|
+
};
|
|
101
107
|
}
|
|
102
108
|
return disk;
|
|
103
109
|
}
|
|
@@ -513,11 +519,11 @@ function renderCallbackHtml(opts) {
|
|
|
513
519
|
</html>`;
|
|
514
520
|
}
|
|
515
521
|
function registerAuthCommands(program2) {
|
|
516
|
-
program2.command("login").description("Authenticate CLI via browser approval, manual code paste, or --token").option("--token <token>", "Store an existing sc_live_... API token directly").option("--manual", "Prompt to paste an authorization code or token instead of waiting for 127.0.0.1 callback", false).option("--no-browser", "Do not launch a local browser automatically").option("--url <apiUrl>", "SagaCloud API base URL
|
|
517
|
-
const apiUrl = (opts.url || DEFAULT_API_BASE_URL).replace(/\/+$/, "");
|
|
518
|
-
const panelBase = (opts.panelUrl || DEFAULT_PANEL_BASE_URL).replace(/\/+$/, "");
|
|
522
|
+
program2.command("login").description("Authenticate CLI via browser approval, manual code paste, or --token").option("--token <token>", "Store an existing sc_live_... API token directly").option("--manual", "Prompt to paste an authorization code or token instead of waiting for 127.0.0.1 callback", false).option("--no-browser", "Do not launch a local browser automatically").option("--url <apiUrl>", "SagaCloud API base URL (or set SAGACLOUD_API_URL)").option("--panel-url <panelUrl>", "SagaCloud Dashboard URL for browser login (or set SAGACLOUD_PANEL_URL)").action(async (opts) => {
|
|
523
|
+
const apiUrl = (opts.url || process.env.SAGACLOUD_API_URL || DEFAULT_API_BASE_URL).trim().replace(/\/+$/, "");
|
|
524
|
+
const panelBase = (opts.panelUrl || process.env.SAGACLOUD_PANEL_URL || DEFAULT_PANEL_BASE_URL).trim().replace(/\/+$/, "");
|
|
519
525
|
if (opts.token) {
|
|
520
|
-
await authenticateWithToken(opts.token, apiUrl,
|
|
526
|
+
await authenticateWithToken(opts.token, apiUrl, panelBase);
|
|
521
527
|
return;
|
|
522
528
|
}
|
|
523
529
|
if (opts.manual) {
|
|
@@ -746,12 +752,15 @@ import pc3 from "picocolors";
|
|
|
746
752
|
// src/lib/detect.ts
|
|
747
753
|
import fs2 from "fs";
|
|
748
754
|
import path2 from "path";
|
|
755
|
+
function hasPhpEntrypoint(cwd) {
|
|
756
|
+
return fs2.existsSync(path2.join(cwd, "composer.json")) || fs2.existsSync(path2.join(cwd, "index.php")) || fs2.existsSync(path2.join(cwd, "public", "index.php")) || fs2.existsSync(path2.join(cwd, "www", "index.php")) || fs2.existsSync(path2.join(cwd, "web", "index.php"));
|
|
757
|
+
}
|
|
749
758
|
function detectProject(cwd = process.cwd()) {
|
|
750
759
|
const pkgPath = path2.join(cwd, "package.json");
|
|
751
760
|
if (!fs2.existsSync(pkgPath)) {
|
|
752
|
-
if (
|
|
761
|
+
if (hasPhpEntrypoint(cwd)) {
|
|
753
762
|
return {
|
|
754
|
-
frameworkLabel: "PHP
|
|
763
|
+
frameworkLabel: "PHP Application",
|
|
755
764
|
siteType: "static",
|
|
756
765
|
runtimeVariant: "php",
|
|
757
766
|
needsLocalBuild: false,
|
|
@@ -775,8 +784,20 @@ function detectProject(cwd = process.cwd()) {
|
|
|
775
784
|
const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf8"));
|
|
776
785
|
const deps = { ...pkg.dependencies || {}, ...pkg.devDependencies || {} };
|
|
777
786
|
const scripts = pkg.scripts || {};
|
|
778
|
-
if (deps.express
|
|
779
|
-
|
|
787
|
+
if (hasPhpEntrypoint(cwd) && !deps.next && !deps.nuxt && !deps.express && !deps.fastify && !deps["@nestjs/core"]) {
|
|
788
|
+
return {
|
|
789
|
+
frameworkLabel: "PHP Application",
|
|
790
|
+
siteType: "static",
|
|
791
|
+
runtimeVariant: "php",
|
|
792
|
+
needsLocalBuild: false,
|
|
793
|
+
buildCommand: "",
|
|
794
|
+
outputDir: ".",
|
|
795
|
+
startCommand: "",
|
|
796
|
+
port: "80"
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
if (deps.express || deps.fastify || deps["@nestjs/core"] || deps.hono || deps.koa || deps["@adonisjs/core"] || deps["@feathersjs/feathers"] || deps["@loopback/core"]) {
|
|
800
|
+
const label = deps["@nestjs/core"] ? "NestJS Backend" : deps["@adonisjs/core"] ? "AdonisJS Backend" : deps["@feathersjs/feathers"] ? "FeathersJS Backend" : deps["@loopback/core"] ? "LoopBack Backend" : deps.fastify ? "Fastify Node Server" : deps.hono ? "Hono Node Server" : "Express Node.js Server";
|
|
780
801
|
return {
|
|
781
802
|
frameworkLabel: label,
|
|
782
803
|
siteType: "node",
|
|
@@ -790,7 +811,8 @@ function detectProject(cwd = process.cwd()) {
|
|
|
790
811
|
}
|
|
791
812
|
if (deps.next) {
|
|
792
813
|
const nextCfg = ["next.config.ts", "next.config.mjs", "next.config.js"].map((f) => path2.join(cwd, f)).find((f) => fs2.existsSync(f));
|
|
793
|
-
const
|
|
814
|
+
const nextCfgRaw = nextCfg ? fs2.readFileSync(nextCfg, "utf8") : "";
|
|
815
|
+
const nextCfgTxt = nextCfgRaw.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "");
|
|
794
816
|
const isStaticExport = /output\s*:\s*['"]export['"]/.test(nextCfgTxt);
|
|
795
817
|
if (isStaticExport) {
|
|
796
818
|
return {
|
|
@@ -815,6 +837,18 @@ function detectProject(cwd = process.cwd()) {
|
|
|
815
837
|
port: "3000"
|
|
816
838
|
};
|
|
817
839
|
}
|
|
840
|
+
if (deps.nuxt) {
|
|
841
|
+
return {
|
|
842
|
+
frameworkLabel: "Nuxt Web App",
|
|
843
|
+
siteType: "node",
|
|
844
|
+
runtimeVariant: "node",
|
|
845
|
+
needsLocalBuild: false,
|
|
846
|
+
buildCommand: scripts.build ? "npm run build" : "npm run build",
|
|
847
|
+
outputDir: "",
|
|
848
|
+
startCommand: scripts.start ? "npm start" : "node .output/server/index.mjs",
|
|
849
|
+
port: "3000"
|
|
850
|
+
};
|
|
851
|
+
}
|
|
818
852
|
if (deps["@angular/core"] || fs2.existsSync(path2.join(cwd, "angular.json"))) {
|
|
819
853
|
let angOut = "dist";
|
|
820
854
|
try {
|
|
@@ -845,15 +879,38 @@ function detectProject(cwd = process.cwd()) {
|
|
|
845
879
|
port: "80"
|
|
846
880
|
};
|
|
847
881
|
}
|
|
882
|
+
if (deps["@11ty/eleventy"] || deps.hexo || deps.gatsby || deps["@docusaurus/core"]) {
|
|
883
|
+
const label = deps["@11ty/eleventy"] ? "Eleventy (11ty) Static Site" : deps.hexo ? "Hexo Static Site" : deps.gatsby ? "Gatsby Static Site" : "Docusaurus Static Site";
|
|
884
|
+
const outputDir = deps["@11ty/eleventy"] ? "_site" : deps["@docusaurus/core"] ? "build" : "public";
|
|
885
|
+
return {
|
|
886
|
+
frameworkLabel: label,
|
|
887
|
+
siteType: "static",
|
|
888
|
+
runtimeVariant: "html",
|
|
889
|
+
needsLocalBuild: Boolean(scripts.build),
|
|
890
|
+
buildCommand: scripts.build ? "npm run build" : "",
|
|
891
|
+
outputDir,
|
|
892
|
+
startCommand: "",
|
|
893
|
+
port: "80"
|
|
894
|
+
};
|
|
895
|
+
}
|
|
848
896
|
if (deps.vite || deps["react-scripts"] || deps.astro) {
|
|
849
897
|
const frameworkLabel = deps.astro ? "Astro Static Site" : deps.vue ? "Vue / Vite SPA" : deps["react-scripts"] ? "React (CRA) SPA" : "React / Vite SPA";
|
|
898
|
+
let viteOutDir = deps["react-scripts"] ? "build" : "dist";
|
|
899
|
+
if (deps.vite) {
|
|
900
|
+
const viteCfg = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].map((f) => path2.join(cwd, f)).find((f) => fs2.existsSync(f));
|
|
901
|
+
if (viteCfg) {
|
|
902
|
+
const cfgText = fs2.readFileSync(viteCfg, "utf8");
|
|
903
|
+
const m = cfgText.match(/outDir\s*:\s*['"]([^'"]+)['"]/);
|
|
904
|
+
if (m?.[1]) viteOutDir = m[1];
|
|
905
|
+
}
|
|
906
|
+
}
|
|
850
907
|
return {
|
|
851
908
|
frameworkLabel,
|
|
852
909
|
siteType: "static",
|
|
853
910
|
runtimeVariant: "spa",
|
|
854
911
|
needsLocalBuild: Boolean(scripts.build),
|
|
855
912
|
buildCommand: scripts.build ? "npm run build" : "",
|
|
856
|
-
outputDir:
|
|
913
|
+
outputDir: viteOutDir,
|
|
857
914
|
startCommand: "",
|
|
858
915
|
port: "80"
|
|
859
916
|
};
|
|
@@ -975,6 +1032,18 @@ import ignore from "ignore";
|
|
|
975
1032
|
var ALWAYS_IGNORED = [
|
|
976
1033
|
".git",
|
|
977
1034
|
".git/**",
|
|
1035
|
+
".github",
|
|
1036
|
+
".github/**",
|
|
1037
|
+
".agents",
|
|
1038
|
+
".agents/**",
|
|
1039
|
+
".vscode",
|
|
1040
|
+
".vscode/**",
|
|
1041
|
+
".idea",
|
|
1042
|
+
".idea/**",
|
|
1043
|
+
".husky",
|
|
1044
|
+
".husky/**",
|
|
1045
|
+
".circleci",
|
|
1046
|
+
".circleci/**",
|
|
978
1047
|
"node_modules",
|
|
979
1048
|
"node_modules/**",
|
|
980
1049
|
".sagacloud",
|
|
@@ -984,7 +1053,27 @@ var ALWAYS_IGNORED = [
|
|
|
984
1053
|
"__MACOSX",
|
|
985
1054
|
"__MACOSX/**",
|
|
986
1055
|
".env",
|
|
1056
|
+
"**/.env",
|
|
987
1057
|
".env.*",
|
|
1058
|
+
"**/.env.*",
|
|
1059
|
+
".editorconfig",
|
|
1060
|
+
".gitattributes",
|
|
1061
|
+
".gitkeep",
|
|
1062
|
+
"**/.gitkeep",
|
|
1063
|
+
".keep",
|
|
1064
|
+
"**/.keep",
|
|
1065
|
+
".browserslistrc",
|
|
1066
|
+
".prettierrc",
|
|
1067
|
+
".prettierrc.*",
|
|
1068
|
+
".prettierignore",
|
|
1069
|
+
".eslintrc",
|
|
1070
|
+
".eslintrc.*",
|
|
1071
|
+
".eslintignore",
|
|
1072
|
+
".stylelintrc",
|
|
1073
|
+
".stylelintrc.*",
|
|
1074
|
+
".babelrc",
|
|
1075
|
+
".babelrc.*",
|
|
1076
|
+
".dockerignore",
|
|
988
1077
|
"sagacloud.jsonc",
|
|
989
1078
|
"sagacloud.json",
|
|
990
1079
|
".sagacloudignore"
|
|
@@ -1251,14 +1340,31 @@ function registerDeployCommands(program2) {
|
|
|
1251
1340
|
siteType = link.site_type;
|
|
1252
1341
|
if (link.runtime_variant) runtimeVariant = link.runtime_variant;
|
|
1253
1342
|
}
|
|
1254
|
-
const buildCmd = jsonc?.build_command || detected.buildCommand;
|
|
1255
|
-
const shouldRunLocalBuild = siteType === "static" && !opts.dir && opts.build !== false && (Boolean(opts.build) || detected.needsLocalBuild || Boolean(jsonc?.build_command));
|
|
1343
|
+
const buildCmd = runtimeVariant === "php" ? jsonc?.build_command || "" : jsonc?.build_command || detected.buildCommand;
|
|
1344
|
+
const shouldRunLocalBuild = siteType === "static" && !opts.dir && opts.build !== false && (runtimeVariant === "php" ? Boolean(opts.build) || Boolean(jsonc?.build_command) : Boolean(opts.build) || detected.needsLocalBuild || Boolean(jsonc?.build_command));
|
|
1256
1345
|
if (shouldRunLocalBuild && buildCmd) {
|
|
1346
|
+
if (fs4.existsSync(path4.join(cwd, "package.json")) && !fs4.existsSync(path4.join(cwd, "node_modules"))) {
|
|
1347
|
+
console.log(pc3.cyan("Installing local dependencies before build..."));
|
|
1348
|
+
const installCmd = fs4.existsSync(path4.join(cwd, "package-lock.json")) ? "npm ci || npm install --legacy-peer-deps" : "npm install --legacy-peer-deps";
|
|
1349
|
+
execSync(installCmd, { stdio: "inherit", cwd });
|
|
1350
|
+
}
|
|
1257
1351
|
console.log(pc3.cyan(`Running local build: ${buildCmd}`));
|
|
1258
1352
|
execSync(buildCmd, { stdio: "inherit", cwd });
|
|
1259
1353
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1354
|
+
let outputRel = opts.dir || jsonc?.output_dir || link?.output_dir || detected.outputDir || ".";
|
|
1355
|
+
let uploadDir = siteType === "node" ? cwd : path4.resolve(cwd, outputRel);
|
|
1356
|
+
const hasStaticEntry = (dirPath) => fs4.existsSync(path4.join(dirPath, "index.html")) || fs4.existsSync(path4.join(dirPath, "index.php"));
|
|
1357
|
+
if (siteType === "static" && runtimeVariant !== "php" && !opts.dir && (!fs4.existsSync(uploadDir) || !hasStaticEntry(uploadDir))) {
|
|
1358
|
+
const candidates = ["dist", "build", "out", "_site", "public", ".output/public", "www"];
|
|
1359
|
+
const matchedCandidate = candidates.find((cand) => {
|
|
1360
|
+
const full = path4.resolve(cwd, cand);
|
|
1361
|
+
return fs4.existsSync(full) && fs4.statSync(full).isDirectory() && hasStaticEntry(full);
|
|
1362
|
+
});
|
|
1363
|
+
if (matchedCandidate) {
|
|
1364
|
+
outputRel = matchedCandidate;
|
|
1365
|
+
uploadDir = path4.resolve(cwd, matchedCandidate);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1262
1368
|
if (!fs4.existsSync(uploadDir)) {
|
|
1263
1369
|
throw new Error(
|
|
1264
1370
|
`Output directory '${outputRel}' not found. Run your build or specify --dir <path>.`
|
|
@@ -1269,7 +1375,7 @@ function registerDeployCommands(program2) {
|
|
|
1269
1375
|
const archive = await createArchiveFromDirectory(uploadDir, {
|
|
1270
1376
|
extraIgnorePatterns: jsonc?.ignore || [],
|
|
1271
1377
|
includeGitignore: siteType === "node" || path4.resolve(uploadDir) === path4.resolve(cwd),
|
|
1272
|
-
staticSiteFilter: siteType === "static",
|
|
1378
|
+
staticSiteFilter: siteType === "static" && runtimeVariant !== "php",
|
|
1273
1379
|
projectRootDir: cwd
|
|
1274
1380
|
});
|
|
1275
1381
|
spin.stop(
|
|
@@ -1283,9 +1389,10 @@ function registerDeployCommands(program2) {
|
|
|
1283
1389
|
const uploadSpin = p2.spinner();
|
|
1284
1390
|
uploadSpin.start("Uploading bundle to SagaCloud...");
|
|
1285
1391
|
const zipName = `${(jsonc?.app_name || jsonc?.name || path4.basename(cwd) || "bundle").replace(/[^a-z0-9-]+/gi, "-")}.zip`;
|
|
1392
|
+
const bundleMode = runtimeVariant === "php" ? "php" : siteType;
|
|
1286
1393
|
let uploaded;
|
|
1287
1394
|
try {
|
|
1288
|
-
uploaded = await client.uploadBundle(archive.buffer, zipName,
|
|
1395
|
+
uploaded = await client.uploadBundle(archive.buffer, zipName, bundleMode);
|
|
1289
1396
|
} catch (err) {
|
|
1290
1397
|
uploadSpin.stop("Upload failed");
|
|
1291
1398
|
throw err;
|
|
@@ -2097,7 +2204,7 @@ function registerSkillCommands(program2) {
|
|
|
2097
2204
|
|
|
2098
2205
|
// src/index.ts
|
|
2099
2206
|
var program = new Command();
|
|
2100
|
-
program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.3.
|
|
2207
|
+
program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.3.5");
|
|
2101
2208
|
registerAuthCommands(program);
|
|
2102
2209
|
registerProjectCommands(program);
|
|
2103
2210
|
registerDeployCommands(program);
|