sagacloud 0.3.4 → 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 +114 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -752,12 +752,15 @@ import pc3 from "picocolors";
|
|
|
752
752
|
// src/lib/detect.ts
|
|
753
753
|
import fs2 from "fs";
|
|
754
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
|
+
}
|
|
755
758
|
function detectProject(cwd = process.cwd()) {
|
|
756
759
|
const pkgPath = path2.join(cwd, "package.json");
|
|
757
760
|
if (!fs2.existsSync(pkgPath)) {
|
|
758
|
-
if (
|
|
761
|
+
if (hasPhpEntrypoint(cwd)) {
|
|
759
762
|
return {
|
|
760
|
-
frameworkLabel: "PHP
|
|
763
|
+
frameworkLabel: "PHP Application",
|
|
761
764
|
siteType: "static",
|
|
762
765
|
runtimeVariant: "php",
|
|
763
766
|
needsLocalBuild: false,
|
|
@@ -781,8 +784,20 @@ function detectProject(cwd = process.cwd()) {
|
|
|
781
784
|
const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf8"));
|
|
782
785
|
const deps = { ...pkg.dependencies || {}, ...pkg.devDependencies || {} };
|
|
783
786
|
const scripts = pkg.scripts || {};
|
|
784
|
-
if (deps.express
|
|
785
|
-
|
|
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";
|
|
786
801
|
return {
|
|
787
802
|
frameworkLabel: label,
|
|
788
803
|
siteType: "node",
|
|
@@ -796,7 +811,8 @@ function detectProject(cwd = process.cwd()) {
|
|
|
796
811
|
}
|
|
797
812
|
if (deps.next) {
|
|
798
813
|
const nextCfg = ["next.config.ts", "next.config.mjs", "next.config.js"].map((f) => path2.join(cwd, f)).find((f) => fs2.existsSync(f));
|
|
799
|
-
const
|
|
814
|
+
const nextCfgRaw = nextCfg ? fs2.readFileSync(nextCfg, "utf8") : "";
|
|
815
|
+
const nextCfgTxt = nextCfgRaw.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "");
|
|
800
816
|
const isStaticExport = /output\s*:\s*['"]export['"]/.test(nextCfgTxt);
|
|
801
817
|
if (isStaticExport) {
|
|
802
818
|
return {
|
|
@@ -821,6 +837,18 @@ function detectProject(cwd = process.cwd()) {
|
|
|
821
837
|
port: "3000"
|
|
822
838
|
};
|
|
823
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
|
+
}
|
|
824
852
|
if (deps["@angular/core"] || fs2.existsSync(path2.join(cwd, "angular.json"))) {
|
|
825
853
|
let angOut = "dist";
|
|
826
854
|
try {
|
|
@@ -851,15 +879,38 @@ function detectProject(cwd = process.cwd()) {
|
|
|
851
879
|
port: "80"
|
|
852
880
|
};
|
|
853
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
|
+
}
|
|
854
896
|
if (deps.vite || deps["react-scripts"] || deps.astro) {
|
|
855
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
|
+
}
|
|
856
907
|
return {
|
|
857
908
|
frameworkLabel,
|
|
858
909
|
siteType: "static",
|
|
859
910
|
runtimeVariant: "spa",
|
|
860
911
|
needsLocalBuild: Boolean(scripts.build),
|
|
861
912
|
buildCommand: scripts.build ? "npm run build" : "",
|
|
862
|
-
outputDir:
|
|
913
|
+
outputDir: viteOutDir,
|
|
863
914
|
startCommand: "",
|
|
864
915
|
port: "80"
|
|
865
916
|
};
|
|
@@ -981,6 +1032,18 @@ import ignore from "ignore";
|
|
|
981
1032
|
var ALWAYS_IGNORED = [
|
|
982
1033
|
".git",
|
|
983
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/**",
|
|
984
1047
|
"node_modules",
|
|
985
1048
|
"node_modules/**",
|
|
986
1049
|
".sagacloud",
|
|
@@ -990,7 +1053,27 @@ var ALWAYS_IGNORED = [
|
|
|
990
1053
|
"__MACOSX",
|
|
991
1054
|
"__MACOSX/**",
|
|
992
1055
|
".env",
|
|
1056
|
+
"**/.env",
|
|
993
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",
|
|
994
1077
|
"sagacloud.jsonc",
|
|
995
1078
|
"sagacloud.json",
|
|
996
1079
|
".sagacloudignore"
|
|
@@ -1257,14 +1340,31 @@ function registerDeployCommands(program2) {
|
|
|
1257
1340
|
siteType = link.site_type;
|
|
1258
1341
|
if (link.runtime_variant) runtimeVariant = link.runtime_variant;
|
|
1259
1342
|
}
|
|
1260
|
-
const buildCmd = jsonc?.build_command || detected.buildCommand;
|
|
1261
|
-
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));
|
|
1262
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
|
+
}
|
|
1263
1351
|
console.log(pc3.cyan(`Running local build: ${buildCmd}`));
|
|
1264
1352
|
execSync(buildCmd, { stdio: "inherit", cwd });
|
|
1265
1353
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
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
|
+
}
|
|
1268
1368
|
if (!fs4.existsSync(uploadDir)) {
|
|
1269
1369
|
throw new Error(
|
|
1270
1370
|
`Output directory '${outputRel}' not found. Run your build or specify --dir <path>.`
|
|
@@ -1275,7 +1375,7 @@ function registerDeployCommands(program2) {
|
|
|
1275
1375
|
const archive = await createArchiveFromDirectory(uploadDir, {
|
|
1276
1376
|
extraIgnorePatterns: jsonc?.ignore || [],
|
|
1277
1377
|
includeGitignore: siteType === "node" || path4.resolve(uploadDir) === path4.resolve(cwd),
|
|
1278
|
-
staticSiteFilter: siteType === "static",
|
|
1378
|
+
staticSiteFilter: siteType === "static" && runtimeVariant !== "php",
|
|
1279
1379
|
projectRootDir: cwd
|
|
1280
1380
|
});
|
|
1281
1381
|
spin.stop(
|
|
@@ -1289,9 +1389,10 @@ function registerDeployCommands(program2) {
|
|
|
1289
1389
|
const uploadSpin = p2.spinner();
|
|
1290
1390
|
uploadSpin.start("Uploading bundle to SagaCloud...");
|
|
1291
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;
|
|
1292
1393
|
let uploaded;
|
|
1293
1394
|
try {
|
|
1294
|
-
uploaded = await client.uploadBundle(archive.buffer, zipName,
|
|
1395
|
+
uploaded = await client.uploadBundle(archive.buffer, zipName, bundleMode);
|
|
1295
1396
|
} catch (err) {
|
|
1296
1397
|
uploadSpin.stop("Upload failed");
|
|
1297
1398
|
throw err;
|
|
@@ -2103,7 +2204,7 @@ function registerSkillCommands(program2) {
|
|
|
2103
2204
|
|
|
2104
2205
|
// src/index.ts
|
|
2105
2206
|
var program = new Command();
|
|
2106
|
-
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");
|
|
2107
2208
|
registerAuthCommands(program);
|
|
2108
2209
|
registerProjectCommands(program);
|
|
2109
2210
|
registerDeployCommands(program);
|