opticore-installer 1.2.58 → 1.2.59

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
@@ -546,9 +546,11 @@ var import_fs4 = __toESM(require("fs"), 1);
546
546
  var SUpdateEnv = class {
547
547
  arg;
548
548
  argumentConnection;
549
- constructor(arg, argumentConnection) {
549
+ dbUrlScheme;
550
+ constructor(arg, argumentConnection, dbUrlScheme) {
550
551
  this.arg = arg;
551
552
  this.argumentConnection = argumentConnection;
553
+ this.dbUrlScheme = dbUrlScheme;
552
554
  this.__init();
553
555
  }
554
556
  /**
@@ -559,6 +561,7 @@ var SUpdateEnv = class {
559
561
  const envFileLines = import_fs4.default.readFileSync("config/env/.env", "utf8").split("\n");
560
562
  this.updateDatabaseSection(envFileLines, this.arg);
561
563
  this.updateArgConnexionSection(envFileLines, this.argumentConnection);
564
+ this.updateDatabaseUrlSection(envFileLines, this.arg, this.dbUrlScheme);
562
565
  import_fs4.default.writeFileSync("config/env/.env", envFileLines.join("\n"));
563
566
  }
564
567
  /**
@@ -614,12 +617,39 @@ var SUpdateEnv = class {
614
617
  envFileLines.splice(insertPosition, 0, `${targetKey}=${argumentConnection}`);
615
618
  }
616
619
  }
620
+ /**
621
+ * Derives DATABASE_URL from the DATA_BASE_* values so both stay consistent.
622
+ * Only touches the file when the DATABASE_URL key already exists there and a scheme
623
+ * (e.g. "postgres", "mysql", "mongodb") is known for the chosen database.
624
+ *
625
+ * @param envFileLines
626
+ * @param arg
627
+ * @param dbUrlScheme
628
+ * @protected
629
+ */
630
+ updateDatabaseUrlSection(envFileLines, arg, dbUrlScheme) {
631
+ if (!dbUrlScheme || !arg?.dbName) {
632
+ return;
633
+ }
634
+ const targetKey = "DATABASE_URL";
635
+ const index = envFileLines.findIndex((line) => {
636
+ const trimmed = line.trim();
637
+ return !trimmed.startsWith("#") && trimmed.split("=")[0] === targetKey;
638
+ });
639
+ if (index === -1) {
640
+ return;
641
+ }
642
+ const user = encodeURIComponent(arg.dbUser ?? "");
643
+ const pwd = encodeURIComponent(arg.dbPwd ?? "");
644
+ const databaseUrl = `${dbUrlScheme}://${user}:${pwd}@${arg.dbHost ?? ""}:${arg.dbPort ?? ""}/${arg.dbName}`;
645
+ envFileLines[index] = `${targetKey}=${databaseUrl}`;
646
+ }
617
647
  };
618
648
 
619
649
  // src/presentations/middlewares/templateProject/templateProject.middleware.ts
620
- var MTemplateProject = async (repoGit, projectPath, currentPath, callback, arg, projectName, argumentConnection) => {
650
+ var MTemplateProject = async (repoGit, projectPath, currentPath, callback, arg, projectName, argumentConnection, dbUrlScheme) => {
621
651
  await SProjectCreation(repoGit, projectPath, currentPath, projectName);
622
- new SUpdateEnv(arg, argumentConnection);
652
+ new SUpdateEnv(arg, argumentConnection, dbUrlScheme);
623
653
  await callback([]);
624
654
  };
625
655
 
@@ -855,7 +885,8 @@ var MSelectDB = async (projectPath, currentPath, projectName) => {
855
885
  async () => await createMySQLDatabase(mysqlParams),
856
886
  envParams,
857
887
  projectName,
858
- CConnectionProperties
888
+ CConnectionProperties,
889
+ "mysql"
859
890
  );
860
891
  break;
861
892
  }
@@ -874,7 +905,9 @@ var MSelectDB = async (projectPath, currentPath, projectName) => {
874
905
  currentPath,
875
906
  async () => await createPostgresDatabase(postgresParams),
876
907
  envParams,
877
- projectName
908
+ projectName,
909
+ void 0,
910
+ "postgres"
878
911
  );
879
912
  break;
880
913
  }
@@ -886,7 +919,9 @@ var MSelectDB = async (projectPath, currentPath, projectName) => {
886
919
  currentPath,
887
920
  async () => await createMongoDatabase(mongoParams),
888
921
  envParams,
889
- projectName
922
+ projectName,
923
+ void 0,
924
+ "mongodb"
890
925
  );
891
926
  break;
892
927
  }
package/dist/index.js CHANGED
@@ -523,9 +523,11 @@ import fs4 from "fs";
523
523
  var SUpdateEnv = class {
524
524
  arg;
525
525
  argumentConnection;
526
- constructor(arg, argumentConnection) {
526
+ dbUrlScheme;
527
+ constructor(arg, argumentConnection, dbUrlScheme) {
527
528
  this.arg = arg;
528
529
  this.argumentConnection = argumentConnection;
530
+ this.dbUrlScheme = dbUrlScheme;
529
531
  this.__init();
530
532
  }
531
533
  /**
@@ -536,6 +538,7 @@ var SUpdateEnv = class {
536
538
  const envFileLines = fs4.readFileSync("config/env/.env", "utf8").split("\n");
537
539
  this.updateDatabaseSection(envFileLines, this.arg);
538
540
  this.updateArgConnexionSection(envFileLines, this.argumentConnection);
541
+ this.updateDatabaseUrlSection(envFileLines, this.arg, this.dbUrlScheme);
539
542
  fs4.writeFileSync("config/env/.env", envFileLines.join("\n"));
540
543
  }
541
544
  /**
@@ -591,12 +594,39 @@ var SUpdateEnv = class {
591
594
  envFileLines.splice(insertPosition, 0, `${targetKey}=${argumentConnection}`);
592
595
  }
593
596
  }
597
+ /**
598
+ * Derives DATABASE_URL from the DATA_BASE_* values so both stay consistent.
599
+ * Only touches the file when the DATABASE_URL key already exists there and a scheme
600
+ * (e.g. "postgres", "mysql", "mongodb") is known for the chosen database.
601
+ *
602
+ * @param envFileLines
603
+ * @param arg
604
+ * @param dbUrlScheme
605
+ * @protected
606
+ */
607
+ updateDatabaseUrlSection(envFileLines, arg, dbUrlScheme) {
608
+ if (!dbUrlScheme || !arg?.dbName) {
609
+ return;
610
+ }
611
+ const targetKey = "DATABASE_URL";
612
+ const index = envFileLines.findIndex((line) => {
613
+ const trimmed = line.trim();
614
+ return !trimmed.startsWith("#") && trimmed.split("=")[0] === targetKey;
615
+ });
616
+ if (index === -1) {
617
+ return;
618
+ }
619
+ const user = encodeURIComponent(arg.dbUser ?? "");
620
+ const pwd = encodeURIComponent(arg.dbPwd ?? "");
621
+ const databaseUrl = `${dbUrlScheme}://${user}:${pwd}@${arg.dbHost ?? ""}:${arg.dbPort ?? ""}/${arg.dbName}`;
622
+ envFileLines[index] = `${targetKey}=${databaseUrl}`;
623
+ }
594
624
  };
595
625
 
596
626
  // src/presentations/middlewares/templateProject/templateProject.middleware.ts
597
- var MTemplateProject = async (repoGit, projectPath, currentPath, callback, arg, projectName, argumentConnection) => {
627
+ var MTemplateProject = async (repoGit, projectPath, currentPath, callback, arg, projectName, argumentConnection, dbUrlScheme) => {
598
628
  await SProjectCreation(repoGit, projectPath, currentPath, projectName);
599
- new SUpdateEnv(arg, argumentConnection);
629
+ new SUpdateEnv(arg, argumentConnection, dbUrlScheme);
600
630
  await callback([]);
601
631
  };
602
632
 
@@ -832,7 +862,8 @@ var MSelectDB = async (projectPath, currentPath, projectName) => {
832
862
  async () => await createMySQLDatabase(mysqlParams),
833
863
  envParams,
834
864
  projectName,
835
- CConnectionProperties
865
+ CConnectionProperties,
866
+ "mysql"
836
867
  );
837
868
  break;
838
869
  }
@@ -851,7 +882,9 @@ var MSelectDB = async (projectPath, currentPath, projectName) => {
851
882
  currentPath,
852
883
  async () => await createPostgresDatabase(postgresParams),
853
884
  envParams,
854
- projectName
885
+ projectName,
886
+ void 0,
887
+ "postgres"
855
888
  );
856
889
  break;
857
890
  }
@@ -863,7 +896,9 @@ var MSelectDB = async (projectPath, currentPath, projectName) => {
863
896
  currentPath,
864
897
  async () => await createMongoDatabase(mongoParams),
865
898
  envParams,
866
- projectName
899
+ projectName,
900
+ void 0,
901
+ "mongodb"
867
902
  );
868
903
  break;
869
904
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opticore-installer",
3
- "version": "1.2.58",
3
+ "version": "1.2.59",
4
4
  "description": "opticore framework installer",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",