@korajs/cli 0.3.4 → 0.4.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/dist/index.cjs CHANGED
@@ -350,6 +350,7 @@ function promptConfirm(message, defaultValue = false, options) {
350
350
  resolve3(false);
351
351
  return;
352
352
  }
353
+ ;
353
354
  (options?.output ?? process.stdout).write(" Please answer with y or n\n");
354
355
  ask();
355
356
  });
@@ -542,7 +543,15 @@ function createLogger(options) {
542
543
  }
543
544
 
544
545
  // src/commands/deploy/adapters/adapter.ts
545
- var DEPLOY_PLATFORMS = ["fly", "railway", "aws-ecs", "aws-lightsail", "render", "docker", "kora-cloud"];
546
+ var DEPLOY_PLATFORMS = [
547
+ "fly",
548
+ "railway",
549
+ "aws-ecs",
550
+ "aws-lightsail",
551
+ "render",
552
+ "docker",
553
+ "kora-cloud"
554
+ ];
546
555
  function isDeployPlatform(value) {
547
556
  return DEPLOY_PLATFORMS.includes(value);
548
557
  }
@@ -553,8 +562,8 @@ var import_node_path4 = require("path");
553
562
 
554
563
  // src/commands/deploy/builder/client-builder.ts
555
564
  var import_node_child_process = require("child_process");
556
- var import_promises2 = require("fs/promises");
557
565
  var import_node_fs = require("fs");
566
+ var import_promises2 = require("fs/promises");
558
567
  var import_node_path2 = require("path");
559
568
  async function buildClient(options) {
560
569
  const viteEntryPoint = await resolveProjectBinaryEntryPoint(options.projectRoot, "vite", "vite");
@@ -712,37 +721,46 @@ var AwsEcsAdapter = class {
712
721
  };
713
722
  const region = config.region ?? "us-east-1";
714
723
  const repoName = `kora/${config.appName}`;
715
- const createRepo = await this.runner.run("aws", [
716
- "ecr",
717
- "create-repository",
718
- "--repository-name",
719
- repoName,
720
- "--region",
721
- region,
722
- "--image-scanning-configuration",
723
- "scanOnPush=true"
724
- ], config.projectRoot);
724
+ const createRepo = await this.runner.run(
725
+ "aws",
726
+ [
727
+ "ecr",
728
+ "create-repository",
729
+ "--repository-name",
730
+ repoName,
731
+ "--region",
732
+ region,
733
+ "--image-scanning-configuration",
734
+ "scanOnPush=true"
735
+ ],
736
+ config.projectRoot
737
+ );
725
738
  if (createRepo.exitCode !== 0 && !createRepo.stderr.includes("RepositoryAlreadyExistsException")) {
726
739
  throw new Error(`Failed to create ECR repository: ${createRepo.stderr}`);
727
740
  }
728
- const identity = await this.runner.run("aws", ["sts", "get-caller-identity", "--query", "Account", "--output", "text"], config.projectRoot);
741
+ const identity = await this.runner.run(
742
+ "aws",
743
+ ["sts", "get-caller-identity", "--query", "Account", "--output", "text"],
744
+ config.projectRoot
745
+ );
729
746
  const accountId = identity.stdout.trim();
730
- await this.runner.run("aws", [
731
- "ecs",
732
- "create-cluster",
733
- "--cluster-name",
734
- config.appName,
735
- "--region",
736
- region
737
- ], config.projectRoot);
738
- await this.runner.run("aws", [
739
- "logs",
740
- "create-log-group",
741
- "--log-group-name",
742
- `/ecs/${config.appName}`,
743
- "--region",
744
- region
745
- ], config.projectRoot);
747
+ await this.runner.run(
748
+ "aws",
749
+ ["ecs", "create-cluster", "--cluster-name", config.appName, "--region", region],
750
+ config.projectRoot
751
+ );
752
+ await this.runner.run(
753
+ "aws",
754
+ [
755
+ "logs",
756
+ "create-log-group",
757
+ "--log-group-name",
758
+ `/ecs/${config.appName}`,
759
+ "--region",
760
+ region
761
+ ],
762
+ config.projectRoot
763
+ );
746
764
  return {
747
765
  applicationId: `${accountId}.dkr.ecr.${region}.amazonaws.com/${repoName}`,
748
766
  databaseId: null,
@@ -775,50 +793,42 @@ var AwsEcsAdapter = class {
775
793
  const context = this.requireContext();
776
794
  const region = context.region ?? "us-east-1";
777
795
  const repoName = `kora/${context.appName}`;
778
- const loginPassword = await this.runner.run("aws", [
779
- "ecr",
780
- "get-login-password",
781
- "--region",
782
- region
783
- ], context.projectRoot);
796
+ const loginPassword = await this.runner.run(
797
+ "aws",
798
+ ["ecr", "get-login-password", "--region", region],
799
+ context.projectRoot
800
+ );
784
801
  if (loginPassword.exitCode !== 0) {
785
802
  throw new Error(`ECR login failed: ${loginPassword.stderr}`);
786
803
  }
787
- const identity = await this.runner.run("aws", [
788
- "sts",
789
- "get-caller-identity",
790
- "--query",
791
- "Account",
792
- "--output",
793
- "text"
794
- ], context.projectRoot);
804
+ const identity = await this.runner.run(
805
+ "aws",
806
+ ["sts", "get-caller-identity", "--query", "Account", "--output", "text"],
807
+ context.projectRoot
808
+ );
795
809
  const accountId = identity.stdout.trim();
796
810
  const ecrUri = `${accountId}.dkr.ecr.${region}.amazonaws.com`;
797
811
  const imageUri = `${ecrUri}/${repoName}:latest`;
798
- const dockerLogin = await this.runner.run("docker", [
799
- "login",
800
- "--username",
801
- "AWS",
802
- "--password-stdin",
803
- ecrUri
804
- ], artifacts.deployDirectory);
812
+ const dockerLogin = await this.runner.run(
813
+ "docker",
814
+ ["login", "--username", "AWS", "--password-stdin", ecrUri],
815
+ artifacts.deployDirectory
816
+ );
805
817
  this.logger.step("Building Docker image...");
806
- const dockerBuild = await this.runner.run("docker", [
807
- "build",
808
- "--platform",
809
- "linux/amd64",
810
- "-t",
811
- imageUri,
812
- "."
813
- ], artifacts.deployDirectory);
818
+ const dockerBuild = await this.runner.run(
819
+ "docker",
820
+ ["build", "--platform", "linux/amd64", "-t", imageUri, "."],
821
+ artifacts.deployDirectory
822
+ );
814
823
  if (dockerBuild.exitCode !== 0) {
815
824
  throw new Error(`Docker build failed: ${dockerBuild.stderr}`);
816
825
  }
817
826
  this.logger.step("Pushing image to ECR...");
818
- const dockerPush = await this.runner.run("docker", [
819
- "push",
820
- imageUri
821
- ], artifacts.deployDirectory);
827
+ const dockerPush = await this.runner.run(
828
+ "docker",
829
+ ["push", imageUri],
830
+ artifacts.deployDirectory
831
+ );
822
832
  if (dockerPush.exitCode !== 0) {
823
833
  throw new Error(`Docker push failed: ${dockerPush.stderr}`);
824
834
  }
@@ -829,52 +839,55 @@ var AwsEcsAdapter = class {
829
839
  cpu: "256",
830
840
  memory: "512",
831
841
  executionRoleArn: `arn:aws:iam::${accountId}:role/ecsTaskExecutionRole`,
832
- containerDefinitions: [{
833
- name: context.appName,
834
- image: imageUri,
835
- essential: true,
836
- portMappings: [{ containerPort: 3001, protocol: "tcp" }],
837
- logConfiguration: {
838
- logDriver: "awslogs",
839
- options: {
840
- "awslogs-group": `/ecs/${context.appName}`,
841
- "awslogs-region": region,
842
- "awslogs-stream-prefix": "ecs"
842
+ containerDefinitions: [
843
+ {
844
+ name: context.appName,
845
+ image: imageUri,
846
+ essential: true,
847
+ portMappings: [{ containerPort: 3001, protocol: "tcp" }],
848
+ logConfiguration: {
849
+ logDriver: "awslogs",
850
+ options: {
851
+ "awslogs-group": `/ecs/${context.appName}`,
852
+ "awslogs-region": region,
853
+ "awslogs-stream-prefix": "ecs"
854
+ }
855
+ },
856
+ healthCheck: {
857
+ command: ["CMD-SHELL", "curl -f http://localhost:3001/health || exit 1"],
858
+ interval: 30,
859
+ timeout: 5,
860
+ retries: 3,
861
+ startPeriod: 60
843
862
  }
844
- },
845
- healthCheck: {
846
- command: ["CMD-SHELL", "curl -f http://localhost:3001/health || exit 1"],
847
- interval: 30,
848
- timeout: 5,
849
- retries: 3,
850
- startPeriod: 60
851
863
  }
852
- }]
864
+ ]
853
865
  });
854
- const registerTask = await this.runner.run("aws", [
855
- "ecs",
856
- "register-task-definition",
857
- "--cli-input-json",
858
- taskDef,
859
- "--region",
860
- region
861
- ], context.projectRoot);
866
+ const registerTask = await this.runner.run(
867
+ "aws",
868
+ ["ecs", "register-task-definition", "--cli-input-json", taskDef, "--region", region],
869
+ context.projectRoot
870
+ );
862
871
  if (registerTask.exitCode !== 0) {
863
872
  throw new Error(`Task definition registration failed: ${registerTask.stderr}`);
864
873
  }
865
- const updateService = await this.runner.run("aws", [
866
- "ecs",
867
- "update-service",
868
- "--cluster",
869
- context.appName,
870
- "--service",
871
- context.appName,
872
- "--task-definition",
873
- context.appName,
874
- "--force-new-deployment",
875
- "--region",
876
- region
877
- ], context.projectRoot);
874
+ const updateService = await this.runner.run(
875
+ "aws",
876
+ [
877
+ "ecs",
878
+ "update-service",
879
+ "--cluster",
880
+ context.appName,
881
+ "--service",
882
+ context.appName,
883
+ "--task-definition",
884
+ context.appName,
885
+ "--force-new-deployment",
886
+ "--region",
887
+ region
888
+ ],
889
+ context.projectRoot
890
+ );
878
891
  const deploymentId = (/* @__PURE__ */ new Date()).toISOString();
879
892
  if (updateService.exitCode !== 0) {
880
893
  this.logger.step("Service not found, creating new service...");
@@ -899,19 +912,23 @@ var AwsEcsAdapter = class {
899
912
  async rollback(deploymentId) {
900
913
  const context = this.requireContext();
901
914
  const region = context.region ?? "us-east-1";
902
- const result = await this.runner.run("aws", [
903
- "ecs",
904
- "update-service",
905
- "--cluster",
906
- context.appName,
907
- "--service",
908
- context.appName,
909
- "--task-definition",
910
- `${context.appName}:${deploymentId}`,
911
- "--force-new-deployment",
912
- "--region",
913
- region
914
- ], context.projectRoot);
915
+ const result = await this.runner.run(
916
+ "aws",
917
+ [
918
+ "ecs",
919
+ "update-service",
920
+ "--cluster",
921
+ context.appName,
922
+ "--service",
923
+ context.appName,
924
+ "--task-definition",
925
+ `${context.appName}:${deploymentId}`,
926
+ "--force-new-deployment",
927
+ "--region",
928
+ region
929
+ ],
930
+ context.projectRoot
931
+ );
915
932
  if (result.exitCode !== 0) {
916
933
  throw new Error(`ECS rollback failed: ${result.stderr}`);
917
934
  }
@@ -954,16 +971,20 @@ var AwsEcsAdapter = class {
954
971
  async status() {
955
972
  const context = this.requireContext();
956
973
  const region = context.region ?? "us-east-1";
957
- const result = await this.runner.run("aws", [
958
- "ecs",
959
- "describe-services",
960
- "--cluster",
961
- context.appName,
962
- "--services",
963
- context.appName,
964
- "--region",
965
- region
966
- ], context.projectRoot);
974
+ const result = await this.runner.run(
975
+ "aws",
976
+ [
977
+ "ecs",
978
+ "describe-services",
979
+ "--cluster",
980
+ context.appName,
981
+ "--services",
982
+ context.appName,
983
+ "--region",
984
+ region
985
+ ],
986
+ context.projectRoot
987
+ );
967
988
  if (result.exitCode !== 0) {
968
989
  return { state: "failed", message: result.stderr };
969
990
  }
@@ -1072,18 +1093,22 @@ var AwsLightsailAdapter = class {
1072
1093
  };
1073
1094
  const region = config.region ?? "us-east-1";
1074
1095
  const serviceName = sanitizeLightsailName(config.appName);
1075
- const createService = await this.runner.run("aws", [
1076
- "lightsail",
1077
- "create-container-service",
1078
- "--service-name",
1079
- serviceName,
1080
- "--power",
1081
- "nano",
1082
- "--scale",
1083
- "1",
1084
- "--region",
1085
- region
1086
- ], config.projectRoot);
1096
+ const createService = await this.runner.run(
1097
+ "aws",
1098
+ [
1099
+ "lightsail",
1100
+ "create-container-service",
1101
+ "--service-name",
1102
+ serviceName,
1103
+ "--power",
1104
+ "nano",
1105
+ "--scale",
1106
+ "1",
1107
+ "--region",
1108
+ region
1109
+ ],
1110
+ config.projectRoot
1111
+ );
1087
1112
  if (createService.exitCode !== 0 && !createService.stderr.includes("already exists")) {
1088
1113
  throw new Error(`Failed to create Lightsail container service: ${createService.stderr}`);
1089
1114
  }
@@ -1121,30 +1146,31 @@ var AwsLightsailAdapter = class {
1121
1146
  const serviceName = sanitizeLightsailName(context.appName);
1122
1147
  const imageTag = `${serviceName}:latest`;
1123
1148
  this.logger.step("Building Docker image...");
1124
- const dockerBuild = await this.runner.run("docker", [
1125
- "build",
1126
- "--platform",
1127
- "linux/amd64",
1128
- "-t",
1129
- imageTag,
1130
- "."
1131
- ], artifacts.deployDirectory);
1149
+ const dockerBuild = await this.runner.run(
1150
+ "docker",
1151
+ ["build", "--platform", "linux/amd64", "-t", imageTag, "."],
1152
+ artifacts.deployDirectory
1153
+ );
1132
1154
  if (dockerBuild.exitCode !== 0) {
1133
1155
  throw new Error(`Docker build failed: ${dockerBuild.stderr}`);
1134
1156
  }
1135
1157
  this.logger.step("Pushing image to Lightsail...");
1136
- const pushImage = await this.runner.run("aws", [
1137
- "lightsail",
1138
- "push-container-image",
1139
- "--service-name",
1140
- serviceName,
1141
- "--label",
1142
- "latest",
1143
- "--image",
1144
- imageTag,
1145
- "--region",
1146
- region
1147
- ], artifacts.deployDirectory);
1158
+ const pushImage = await this.runner.run(
1159
+ "aws",
1160
+ [
1161
+ "lightsail",
1162
+ "push-container-image",
1163
+ "--service-name",
1164
+ serviceName,
1165
+ "--label",
1166
+ "latest",
1167
+ "--image",
1168
+ imageTag,
1169
+ "--region",
1170
+ region
1171
+ ],
1172
+ artifacts.deployDirectory
1173
+ );
1148
1174
  if (pushImage.exitCode !== 0) {
1149
1175
  throw new Error(`Lightsail image push failed: ${pushImage.stderr}`);
1150
1176
  }
@@ -1175,29 +1201,30 @@ var AwsLightsailAdapter = class {
1175
1201
  unhealthyThreshold: 3
1176
1202
  }
1177
1203
  });
1178
- const createDeploy = await this.runner.run("aws", [
1179
- "lightsail",
1180
- "create-container-service-deployment",
1181
- "--service-name",
1182
- serviceName,
1183
- "--containers",
1184
- containers,
1185
- "--public-endpoint",
1186
- publicEndpoint,
1187
- "--region",
1188
- region
1189
- ], context.projectRoot);
1204
+ const createDeploy = await this.runner.run(
1205
+ "aws",
1206
+ [
1207
+ "lightsail",
1208
+ "create-container-service-deployment",
1209
+ "--service-name",
1210
+ serviceName,
1211
+ "--containers",
1212
+ containers,
1213
+ "--public-endpoint",
1214
+ publicEndpoint,
1215
+ "--region",
1216
+ region
1217
+ ],
1218
+ context.projectRoot
1219
+ );
1190
1220
  if (createDeploy.exitCode !== 0) {
1191
1221
  throw new Error(`Lightsail deployment failed: ${createDeploy.stderr}`);
1192
1222
  }
1193
- const serviceInfo = await this.runner.run("aws", [
1194
- "lightsail",
1195
- "get-container-services",
1196
- "--service-name",
1197
- serviceName,
1198
- "--region",
1199
- region
1200
- ], context.projectRoot);
1223
+ const serviceInfo = await this.runner.run(
1224
+ "aws",
1225
+ ["lightsail", "get-container-services", "--service-name", serviceName, "--region", region],
1226
+ context.projectRoot
1227
+ );
1201
1228
  const rawUrl = parseLightsailUrl(serviceInfo.stdout) ?? `https://${serviceName}.${region}.cs.amazonlightsail.com`;
1202
1229
  const serviceUrl = rawUrl.replace(/\/+$/, "");
1203
1230
  const deploymentId = (/* @__PURE__ */ new Date()).toISOString();
@@ -1211,14 +1238,18 @@ var AwsLightsailAdapter = class {
1211
1238
  const context = this.requireContext();
1212
1239
  const region = context.region ?? "us-east-1";
1213
1240
  const serviceName = sanitizeLightsailName(context.appName);
1214
- const deployments = await this.runner.run("aws", [
1215
- "lightsail",
1216
- "get-container-service-deployments",
1217
- "--service-name",
1218
- serviceName,
1219
- "--region",
1220
- region
1221
- ], context.projectRoot);
1241
+ const deployments = await this.runner.run(
1242
+ "aws",
1243
+ [
1244
+ "lightsail",
1245
+ "get-container-service-deployments",
1246
+ "--service-name",
1247
+ serviceName,
1248
+ "--region",
1249
+ region
1250
+ ],
1251
+ context.projectRoot
1252
+ );
1222
1253
  if (deployments.exitCode !== 0) {
1223
1254
  throw new Error(`Lightsail rollback failed: ${deployments.stderr}`);
1224
1255
  }
@@ -1226,18 +1257,22 @@ var AwsLightsailAdapter = class {
1226
1257
  if (!previousDeployment) {
1227
1258
  throw new Error("No previous deployment found to rollback to.");
1228
1259
  }
1229
- const redeploy = await this.runner.run("aws", [
1230
- "lightsail",
1231
- "create-container-service-deployment",
1232
- "--service-name",
1233
- serviceName,
1234
- "--containers",
1235
- JSON.stringify(previousDeployment.containers),
1236
- "--public-endpoint",
1237
- JSON.stringify(previousDeployment.publicEndpoint),
1238
- "--region",
1239
- region
1240
- ], context.projectRoot);
1260
+ const redeploy = await this.runner.run(
1261
+ "aws",
1262
+ [
1263
+ "lightsail",
1264
+ "create-container-service-deployment",
1265
+ "--service-name",
1266
+ serviceName,
1267
+ "--containers",
1268
+ JSON.stringify(previousDeployment.containers),
1269
+ "--public-endpoint",
1270
+ JSON.stringify(previousDeployment.publicEndpoint),
1271
+ "--region",
1272
+ region
1273
+ ],
1274
+ context.projectRoot
1275
+ );
1241
1276
  if (redeploy.exitCode !== 0) {
1242
1277
  throw new Error(`Lightsail rollback deployment failed: ${redeploy.stderr}`);
1243
1278
  }
@@ -1284,14 +1319,11 @@ var AwsLightsailAdapter = class {
1284
1319
  const context = this.requireContext();
1285
1320
  const region = context.region ?? "us-east-1";
1286
1321
  const serviceName = sanitizeLightsailName(context.appName);
1287
- const result = await this.runner.run("aws", [
1288
- "lightsail",
1289
- "get-container-services",
1290
- "--service-name",
1291
- serviceName,
1292
- "--region",
1293
- region
1294
- ], context.projectRoot);
1322
+ const result = await this.runner.run(
1323
+ "aws",
1324
+ ["lightsail", "get-container-services", "--service-name", serviceName, "--region", region],
1325
+ context.projectRoot
1326
+ );
1295
1327
  if (result.exitCode !== 0) {
1296
1328
  return { state: "failed", message: result.stderr };
1297
1329
  }
@@ -1356,12 +1388,7 @@ ${error.message}` });
1356
1388
  });
1357
1389
  }
1358
1390
  };
1359
- var PASSTHROUGH_ENV_VARS = [
1360
- "DATABASE_URL",
1361
- "AUTH_SECRET",
1362
- "PUBLIC_URL",
1363
- "NODE_ENV"
1364
- ];
1391
+ var PASSTHROUGH_ENV_VARS = ["DATABASE_URL", "AUTH_SECRET", "PUBLIC_URL", "NODE_ENV"];
1365
1392
  function sanitizeLightsailName(name) {
1366
1393
  return name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-{2,}/g, "-").replace(/^-|-$/g, "").slice(0, 255) || "kora-app";
1367
1394
  }
@@ -2240,7 +2267,8 @@ function generateDeployPackageJson(nativeDependencies) {
2240
2267
  type: "module",
2241
2268
  dependencies: nativeDependencies
2242
2269
  };
2243
- return JSON.stringify(pkg, null, 2) + "\n";
2270
+ return `${JSON.stringify(pkg, null, 2)}
2271
+ `;
2244
2272
  }
2245
2273
  function generateDockerIgnore() {
2246
2274
  return [
@@ -2572,7 +2600,7 @@ var deployCommand = (0, import_citty.defineCommand)({
2572
2600
  nativeDependencies: {
2573
2601
  "better-sqlite3": "^11.0.0",
2574
2602
  "drizzle-orm": "^0.45.2",
2575
- "postgres": "^3.4.0"
2603
+ postgres: "^3.4.0"
2576
2604
  }
2577
2605
  });
2578
2606
  await writeDockerIgnoreArtifact(deployDirectory);
@@ -2881,7 +2909,9 @@ async function resolveCreatePreferencesFlow(params) {
2881
2909
  }
2882
2910
  if (flags.db !== void 0) {
2883
2911
  if (!isDatabaseValue(flags.db)) {
2884
- throw new Error(`Invalid --db value "${flags.db}". Expected one of: none, sqlite, postgres.`);
2912
+ throw new Error(
2913
+ `Invalid --db value "${flags.db}". Expected one of: none, sqlite, postgres.`
2914
+ );
2885
2915
  }
2886
2916
  effective.db = flags.db;
2887
2917
  } else if (!effective.sync) {