@opencrvs/toolkit 2.1.1-rc.52250d8 → 2.1.1

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/cli.js CHANGED
@@ -32,13 +32,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
32
32
 
33
33
  // src/environment/paths.ts
34
34
  function getEnvironmentInventoryPath(environment) {
35
- return (0, import_path12.join)("environments", environment, INVENTORY_FILE_NAME);
35
+ return (0, import_path11.join)("environments", environment, INVENTORY_FILE_NAME);
36
36
  }
37
37
  function findOldInventoryFiles() {
38
- return glob.sync((0, import_path12.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
38
+ return glob.sync((0, import_path11.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
39
39
  }
40
40
  function getEnvironmentNameFromOldInventoryPath(filePath) {
41
- return (0, import_path12.basename)(filePath, ".yml");
41
+ return (0, import_path11.basename)(filePath, ".yml");
42
42
  }
43
43
  function assertNoOldInventoryLayout() {
44
44
  if (findOldInventoryFiles().length === 0) {
@@ -51,13 +51,13 @@ function assertNoOldInventoryLayout() {
51
51
  ].join(" ")
52
52
  );
53
53
  }
54
- var import_path12, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
54
+ var import_path11, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
55
55
  var init_paths = __esm({
56
56
  "src/environment/paths.ts"() {
57
57
  "use strict";
58
- import_path12 = require("path");
58
+ import_path11 = require("path");
59
59
  glob = __toESM(require("glob"));
60
- OLD_INVENTORY_DIR = (0, import_path12.join)(
60
+ OLD_INVENTORY_DIR = (0, import_path11.join)(
61
61
  "infrastructure",
62
62
  "server-setup",
63
63
  "inventory"
@@ -499,13 +499,6 @@ var init_derived_variables = __esm({
499
499
  valueType: "VARIABLE",
500
500
  type: "disabled",
501
501
  scope: "ENVIRONMENT"
502
- },
503
- {
504
- name: "TWO_FA_ENABLED",
505
- valueLabel: "TWO_FA_ENABLED",
506
- valueType: "VARIABLE",
507
- type: "disabled",
508
- scope: "ENVIRONMENT"
509
502
  }
510
503
  ];
511
504
  }
@@ -525,7 +518,7 @@ function findExistingValue(name, type, scope, existingValues) {
525
518
  );
526
519
  }
527
520
  function readYamlFile(filePath) {
528
- const fileContent = import_fs10.default.readFileSync(filePath, "utf8");
521
+ const fileContent = import_fs9.default.readFileSync(filePath, "utf8");
529
522
  return yaml.load(fileContent);
530
523
  }
531
524
  function writeYamlFile(filePath, data) {
@@ -538,16 +531,16 @@ function writeYamlFile(filePath, data) {
538
531
  noRefs: true,
539
532
  sortKeys: false
540
533
  });
541
- import_fs10.default.writeFileSync(filePath, yamlContent, "utf8");
534
+ import_fs9.default.writeFileSync(filePath, yamlContent, "utf8");
542
535
  } catch (error3) {
543
536
  throw new Error(`Failed to write inventory file: ${error3}`);
544
537
  }
545
538
  }
546
- var import_fs10, yaml;
539
+ var import_fs9, yaml;
547
540
  var init_utils = __esm({
548
541
  "src/environment/utils.ts"() {
549
542
  "use strict";
550
- import_fs10 = __toESM(require("fs"));
543
+ import_fs9 = __toESM(require("fs"));
551
544
  yaml = __toESM(require("js-yaml"));
552
545
  }
553
546
  });
@@ -596,29 +589,29 @@ function extractWorkerNodes(data) {
596
589
  return worker_hosts;
597
590
  }
598
591
  function copyChartsValues(env, values) {
599
- const srcDir = import_path13.default.resolve(__dirname, "templates", "charts-values");
600
- const destDir = import_path13.default.resolve(process.cwd(), "environments", env);
601
- import_fs11.default.mkdirSync(destDir, { recursive: true });
592
+ const srcDir = import_path12.default.resolve(__dirname, "templates", "charts-values");
593
+ const destDir = import_path12.default.resolve(process.cwd(), "environments", env);
594
+ import_fs10.default.mkdirSync(destDir, { recursive: true });
602
595
  values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
603
596
  values["static_ssl"] = values["traefik_mode"] === "static_ssl";
604
597
  values["opencrvs_environment"] = env;
605
598
  function copyRecursive(src, dest) {
606
- const stat = import_fs11.default.statSync(src);
599
+ const stat = import_fs10.default.statSync(src);
607
600
  if (stat.isDirectory()) {
608
- import_fs11.default.mkdirSync(dest, { recursive: true });
609
- for (const item of import_fs11.default.readdirSync(src)) {
610
- copyRecursive(import_path13.default.join(src, item), import_path13.default.join(dest, item));
601
+ import_fs10.default.mkdirSync(dest, { recursive: true });
602
+ for (const item of import_fs10.default.readdirSync(src)) {
603
+ copyRecursive(import_path12.default.join(src, item), import_path12.default.join(dest, item));
611
604
  }
612
605
  } else {
613
- const content = import_fs11.default.readFileSync(src, "utf8");
606
+ const content = import_fs10.default.readFileSync(src, "utf8");
614
607
  const template = import_handlebars.default.compile(content);
615
608
  const updated = template(values);
616
609
  const isOverridesFile = dest.endsWith("override.yaml");
617
- if (isOverridesFile && import_fs11.default.existsSync(dest)) {
610
+ if (isOverridesFile && import_fs10.default.existsSync(dest)) {
618
611
  log(` \u21B7 Skipped existing overrides file: ${dest}`);
619
612
  return;
620
613
  }
621
- import_fs11.default.writeFileSync(dest, updated, "utf8");
614
+ import_fs10.default.writeFileSync(dest, updated, "utf8");
622
615
  log(` \u2713 Created: ${dest}`);
623
616
  }
624
617
  }
@@ -629,29 +622,29 @@ function copyChartsValues(env, values) {
629
622
  `);
630
623
  }
631
624
  function generateInventory(env, values) {
632
- const templatePath = import_path13.default.join(
625
+ const templatePath = import_path12.default.join(
633
626
  __dirname,
634
627
  "templates",
635
628
  "inventory",
636
629
  "inventory.template.yml"
637
630
  );
638
- const outputPath = import_path13.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
639
- const templateFile = import_fs11.default.readFileSync(templatePath, "utf-8");
631
+ const outputPath = import_path12.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
632
+ const templateFile = import_fs10.default.readFileSync(templatePath, "utf-8");
640
633
  const template = import_handlebars.default.compile(templateFile);
641
634
  values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
642
635
  const updated = template(values);
643
- import_fs11.default.mkdirSync(import_path13.default.dirname(outputPath), { recursive: true });
644
- import_fs11.default.writeFileSync(outputPath, updated);
636
+ import_fs10.default.mkdirSync(import_path12.default.dirname(outputPath), { recursive: true });
637
+ import_fs10.default.writeFileSync(outputPath, updated);
645
638
  log(`
646
639
  \u2705 Generated inventory file at ${outputPath}
647
640
  `);
648
641
  }
649
- var import_fs11, import_path13, import_handlebars;
642
+ var import_fs10, import_path12, import_handlebars;
650
643
  var init_templates = __esm({
651
644
  "src/environment/templates.ts"() {
652
645
  "use strict";
653
- import_fs11 = __toESM(require("fs"));
654
- import_path13 = __toESM(require("path"));
646
+ import_fs10 = __toESM(require("fs"));
647
+ import_path12 = __toESM(require("path"));
655
648
  init_logger();
656
649
  init_paths();
657
650
  import_handlebars = __toESM(require("handlebars"));
@@ -682,16 +675,16 @@ var update_workflows_exports = {};
682
675
  __export(update_workflows_exports, {
683
676
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
684
677
  });
685
- function isDirectory(path15) {
678
+ function isDirectory(path14) {
686
679
  try {
687
- return (0, import_fs12.statSync)(path15).isDirectory();
680
+ return (0, import_fs11.statSync)(path14).isDirectory();
688
681
  } catch {
689
682
  return false;
690
683
  }
691
684
  }
692
685
  async function extractInfrastructureNames() {
693
- const files = glob2.sync((0, import_path14.join)("environments", "*", INVENTORY_FILE_NAME));
694
- const infraEnvironments = files.map((file) => (0, import_path14.basename)((0, import_path14.dirname)(file)));
686
+ const files = glob2.sync((0, import_path13.join)("environments", "*", INVENTORY_FILE_NAME));
687
+ const infraEnvironments = files.map((file) => (0, import_path13.basename)((0, import_path13.dirname)(file)));
695
688
  if (infraEnvironments.length === 0) {
696
689
  console.log(
697
690
  `\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
@@ -704,9 +697,9 @@ async function extractInfrastructureNames() {
704
697
  async function extractEnvironmentNames() {
705
698
  const entries = await (0, import_promises.readdir)("environments");
706
699
  const environments = entries.filter((entry) => {
707
- const environmentPath = (0, import_path14.join)("environments", entry);
708
- const opencrvsServicesPath = (0, import_path14.join)(environmentPath, "opencrvs-services");
709
- return isDirectory(environmentPath) && (0, import_fs12.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
700
+ const environmentPath = (0, import_path13.join)("environments", entry);
701
+ const opencrvsServicesPath = (0, import_path13.join)(environmentPath, "opencrvs-services");
702
+ return isDirectory(environmentPath) && (0, import_fs11.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
710
703
  });
711
704
  if (environments.length === 0) {
712
705
  console.log(
@@ -731,12 +724,12 @@ function updateOptionsInYaml(content, envList) {
731
724
  async function updateWorkflows(envList, config) {
732
725
  const { workflows } = config;
733
726
  for (const workflowPath of workflows) {
734
- if (!(0, import_fs12.existsSync)(workflowPath)) {
727
+ if (!(0, import_fs11.existsSync)(workflowPath)) {
735
728
  log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
736
729
  continue;
737
730
  }
738
731
  try {
739
- const fileContents = (0, import_fs12.readFileSync)(workflowPath, "utf8");
732
+ const fileContents = (0, import_fs11.readFileSync)(workflowPath, "utf8");
740
733
  const workflowData = yaml2.load(fileContents);
741
734
  if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
742
735
  throw new Error(
@@ -744,7 +737,7 @@ async function updateWorkflows(envList, config) {
744
737
  );
745
738
  }
746
739
  const updatedContent = updateOptionsInYaml(fileContents, envList);
747
- (0, import_fs12.writeFileSync)(workflowPath, updatedContent, "utf8");
740
+ (0, import_fs11.writeFileSync)(workflowPath, updatedContent, "utf8");
748
741
  log(` \u2713 Successfully updated ${workflowPath}`);
749
742
  } catch (error3) {
750
743
  console.error(
@@ -798,13 +791,13 @@ async function updateWorkflowEnvironments() {
798
791
  process.exit(1);
799
792
  }
800
793
  }
801
- var import_promises, import_fs12, import_path14, glob2, yaml2;
794
+ var import_promises, import_fs11, import_path13, glob2, yaml2;
802
795
  var init_update_workflows = __esm({
803
796
  "src/environment/update-workflows.ts"() {
804
797
  "use strict";
805
798
  import_promises = require("fs/promises");
806
- import_fs12 = require("fs");
807
- import_path14 = require("path");
799
+ import_fs11 = require("fs");
800
+ import_path13 = require("path");
808
801
  glob2 = __toESM(require("glob"));
809
802
  yaml2 = __toESM(require("js-yaml"));
810
803
  init_logger();
@@ -1100,14 +1093,13 @@ var init_questions = __esm({
1100
1093
  {
1101
1094
  name: "diskSpace",
1102
1095
  type: "text",
1103
- message: [
1104
- "How much disk space should be reserved for OpenCRVS data on each node? (e.g. 200g)",
1105
- "A fixed-size encrypted volume of this size is created on every node and cannot be resized later.",
1106
- import_kleur2.default.red("DO NOT USE ALL DISK SPACE FOR OPENCRVS!"),
1107
- "Each node needs this much free space on its root partition, plus 50g or 10% of this size, whichever is larger."
1108
- ].join("\n"),
1096
+ message: `What is the amount of diskspace that should be dedicated to OpenCRVS data and will become the size of an encrypted cryptfs data directory.
1097
+
1098
+ ${import_kleur2.default.red("DO NOT USE ALL DISKSPACE FOR OPENCRVS!")}
1099
+
1100
+ Leave at least 50g available for OS use.`,
1109
1101
  valueType: "VARIABLE",
1110
- validate: (value) => /^\d+g$/i.test(value.trim()) || "Enter a size in gigabytes, e.g. 200g",
1102
+ validate: notEmpty,
1111
1103
  valueLabel: "DISK_SPACE",
1112
1104
  initial: process.env.DISK_SPACE || "200g",
1113
1105
  scope: "ENVIRONMENT"
@@ -1394,7 +1386,7 @@ function getCurrentUsername() {
1394
1386
  }
1395
1387
  function getCurrentUserSSHKeys() {
1396
1388
  const homeDir = os.homedir();
1397
- const sshDir = path12.join(homeDir, ".ssh");
1389
+ const sshDir = path11.join(homeDir, ".ssh");
1398
1390
  const keys = [];
1399
1391
  const keyFiles = [
1400
1392
  "id_rsa.pub",
@@ -1403,7 +1395,7 @@ function getCurrentUserSSHKeys() {
1403
1395
  "id_dsa.pub"
1404
1396
  ];
1405
1397
  for (const keyFile of keyFiles) {
1406
- const keyPath = path12.join(sshDir, keyFile);
1398
+ const keyPath = path11.join(sshDir, keyFile);
1407
1399
  try {
1408
1400
  if (fs3.existsSync(keyPath)) {
1409
1401
  const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
@@ -1744,13 +1736,13 @@ async function manageUsers(inventoryPath) {
1744
1736
  }
1745
1737
  return users;
1746
1738
  }
1747
- var os, fs3, path12, input2, select2, confirm, editor, checkbox;
1739
+ var os, fs3, path11, input2, select2, confirm, editor, checkbox;
1748
1740
  var init_manage_users = __esm({
1749
1741
  "src/environment/manage-users.ts"() {
1750
1742
  "use strict";
1751
1743
  os = __toESM(require("os"));
1752
1744
  fs3 = __toESM(require("fs"));
1753
- path12 = __toESM(require("path"));
1745
+ path11 = __toESM(require("path"));
1754
1746
  init_logger();
1755
1747
  init_utils();
1756
1748
  init_templates();
@@ -1998,6 +1990,16 @@ async function runSetupEnvironment() {
1998
1990
  ]
1999
1991
  });
2000
1992
  }
1993
+ log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
1994
+ const two_fa_enabled = await confirm2({
1995
+ message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
1996
+ default: process.env.TWO_FA_ENABLED ? process.env.TWO_FA_ENABLED === "true" : environment_type === "production"
1997
+ });
1998
+ if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
1999
+ warn(
2000
+ "2FA is disabled on a production-like environment. Logins will accept the fixed test code 000000, exposing real citizen data. Only do this if you know what you are doing."
2001
+ );
2002
+ }
2001
2003
  const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
2002
2004
  if (!environment) {
2003
2005
  process.exit(1);
@@ -2061,23 +2063,6 @@ async function runSetupEnvironment() {
2061
2063
  );
2062
2064
  await promptAndStoreAnswer(githubOtherQuestions, existingValues);
2063
2065
  }
2064
- log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
2065
- const existingTwoFaEnabled = findExistingValue(
2066
- "TWO_FA_ENABLED",
2067
- "VARIABLE",
2068
- "ENVIRONMENT",
2069
- existingValues
2070
- );
2071
- const twoFaDefault = process.env.TWO_FA_ENABLED || existingTwoFaEnabled?.value;
2072
- const two_fa_enabled = await confirm2({
2073
- message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
2074
- default: twoFaDefault ? twoFaDefault === "true" : environment_type === "production"
2075
- });
2076
- if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
2077
- warn(
2078
- "2FA is disabled on a production-like environment. Logins will accept the fixed test code 000000, exposing real citizen data. Only do this if you know what you are doing."
2079
- );
2080
- }
2081
2066
  log("\n", import_kleur4.default.bold().underline("Docker Hub"));
2082
2067
  await promptAndStoreAnswer(dockerhubQuestions, existingValues);
2083
2068
  log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
@@ -2333,14 +2318,6 @@ async function runSetupEnvironment() {
2333
2318
  ),
2334
2319
  scope: "ENVIRONMENT"
2335
2320
  });
2336
- derivedUpdates.push({
2337
- name: "TWO_FA_ENABLED",
2338
- type: "VARIABLE",
2339
- didExist: existingTwoFaEnabled,
2340
- // Always stored, so the next run defaults to the current answer
2341
- value: two_fa_enabled ? "true" : "false",
2342
- scope: "ENVIRONMENT"
2343
- });
2344
2321
  derivedUpdates.push(...ssl_answers);
2345
2322
  if (configureBackup) {
2346
2323
  derivedUpdates.push({
@@ -2983,17 +2960,17 @@ __export(upgrade_exports, {
2983
2960
  upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2984
2961
  });
2985
2962
  function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2986
- if (!(0, import_fs13.existsSync)(sourcePath)) {
2963
+ if (!(0, import_fs12.existsSync)(sourcePath)) {
2987
2964
  return false;
2988
2965
  }
2989
- if ((0, import_fs13.existsSync)(destinationPath)) {
2966
+ if ((0, import_fs12.existsSync)(destinationPath)) {
2990
2967
  warn(
2991
2968
  `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2992
2969
  );
2993
2970
  return false;
2994
2971
  }
2995
- (0, import_fs13.mkdirSync)((0, import_path15.dirname)(destinationPath), { recursive: true });
2996
- (0, import_fs13.renameSync)(sourcePath, destinationPath);
2972
+ (0, import_fs12.mkdirSync)((0, import_path14.dirname)(destinationPath), { recursive: true });
2973
+ (0, import_fs12.renameSync)(sourcePath, destinationPath);
2997
2974
  log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2998
2975
  return true;
2999
2976
  }
@@ -3013,8 +2990,8 @@ function migrateInventoryFiles() {
3013
2990
  ) || didMoveInventory;
3014
2991
  }
3015
2992
  try {
3016
- if ((0, import_fs13.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs13.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
3017
- (0, import_fs13.rmdirSync)(OLD_INVENTORY_DIR);
2993
+ if ((0, import_fs12.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs12.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2994
+ (0, import_fs12.rmdirSync)(OLD_INVENTORY_DIR);
3018
2995
  log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
3019
2996
  }
3020
2997
  } catch {
@@ -3032,12 +3009,12 @@ async function upgradeEnvironmentLayout() {
3032
3009
  }
3033
3010
  log("\nCommit changes into git after upgrade");
3034
3011
  }
3035
- var import_fs13, import_path15, import_kleur5;
3012
+ var import_fs12, import_path14, import_kleur5;
3036
3013
  var init_upgrade = __esm({
3037
3014
  "src/environment/upgrade.ts"() {
3038
3015
  "use strict";
3039
- import_fs13 = require("fs");
3040
- import_path15 = require("path");
3016
+ import_fs12 = require("fs");
3017
+ import_path14 = require("path");
3041
3018
  import_kleur5 = __toESM(require("kleur"));
3042
3019
  init_logger();
3043
3020
  init_paths();
@@ -3063,7 +3040,7 @@ async function selectInventoryFile(dirPath = "./environments") {
3063
3040
  return null;
3064
3041
  }
3065
3042
  const environments = fs4.readdirSync(dirPath).filter((entry) => {
3066
- const filePath = path13.join(dirPath, entry);
3043
+ const filePath = path12.join(dirPath, entry);
3067
3044
  return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
3068
3045
  }).sort();
3069
3046
  if (environments.length === 0) {
@@ -3091,12 +3068,12 @@ async function manageEnvironmentUsers() {
3091
3068
  }
3092
3069
  await manageUsers(inventory_file);
3093
3070
  }
3094
- var fs4, path13, import_kleur6;
3071
+ var fs4, path12, import_kleur6;
3095
3072
  var init_users = __esm({
3096
3073
  "src/environment/users.ts"() {
3097
3074
  "use strict";
3098
3075
  fs4 = __toESM(require("fs"));
3099
- path13 = __toESM(require("path"));
3076
+ path12 = __toESM(require("path"));
3100
3077
  import_kleur6 = __toESM(require("kleur"));
3101
3078
  init_manage_users();
3102
3079
  init_logger();
@@ -3106,11 +3083,11 @@ var init_users = __esm({
3106
3083
 
3107
3084
  // src/environment/swarm-to-k8s.ts
3108
3085
  var swarm_to_k8s_exports = {};
3109
- var path14, import_kleur7, import_core2;
3086
+ var path13, import_kleur7, import_core2;
3110
3087
  var init_swarm_to_k8s = __esm({
3111
3088
  "src/environment/swarm-to-k8s.ts"() {
3112
3089
  "use strict";
3113
- path14 = __toESM(require("path"));
3090
+ path13 = __toESM(require("path"));
3114
3091
  import_kleur7 = __toESM(require("kleur"));
3115
3092
  init_logger();
3116
3093
  init_utils();
@@ -3162,7 +3139,7 @@ var init_swarm_to_k8s = __esm({
3162
3139
  );
3163
3140
  process.exit(1);
3164
3141
  }
3165
- const ansible_inventory = path14.join(old_inventory_path, environment + ".yml");
3142
+ const ansible_inventory = path13.join(old_inventory_path, environment + ".yml");
3166
3143
  const data = readYamlFile(ansible_inventory);
3167
3144
  log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
3168
3145
  const master = dockerManagerFirst(data) || "";
@@ -3505,20 +3482,20 @@ function idOf(line2) {
3505
3482
  const comma = line2.indexOf(",");
3506
3483
  return comma === -1 ? line2 : line2.slice(0, comma);
3507
3484
  }
3508
- function readCsvFile(path15) {
3509
- if (!(0, import_fs.existsSync)(path15)) {
3485
+ function readCsvFile(path14) {
3486
+ if (!(0, import_fs.existsSync)(path14)) {
3510
3487
  return void 0;
3511
3488
  }
3512
- const contents = (0, import_fs.readFileSync)(path15, "utf8");
3489
+ const contents = (0, import_fs.readFileSync)(path14, "utf8");
3513
3490
  const newline = contents.includes("\r\n") ? "\r\n" : "\n";
3514
3491
  const trailingNewline = /\r?\n$/.test(contents);
3515
3492
  const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
3516
3493
  const body = lines.slice(1).filter((line2) => line2 !== "");
3517
3494
  return { header: lines[0], body, newline, trailingNewline };
3518
3495
  }
3519
- function writeCsvFile(path15, file) {
3496
+ function writeCsvFile(path14, file) {
3520
3497
  (0, import_fs.writeFileSync)(
3521
- path15,
3498
+ path14,
3522
3499
  [file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
3523
3500
  );
3524
3501
  }
@@ -5159,71 +5136,9 @@ async function main7() {
5159
5136
  }
5160
5137
  }
5161
5138
 
5162
- // src/migrations/v2.1/remove-typings-from-dockerfile.ts
5163
- var import_fs8 = require("fs");
5164
- var import_path9 = __toESM(require("path"));
5165
- var DOCKERFILE = "Dockerfile";
5166
- var TYPINGS_PATH = /^(?:\.\/)?typings(?:\/.*)?$/;
5167
- var continues = (line2) => !/^\s*#/.test(line2) && /\\[ \t]*\r?\n?$/.test(line2);
5168
- function contextSources(line2, continued) {
5169
- const [instruction, ...args2] = line2.split(/[\s"',[\]]+/).filter(Boolean);
5170
- if (!/^(?:COPY|ADD)$/i.test(instruction) || args2.some((arg) => arg.startsWith("--from"))) {
5171
- return [];
5172
- }
5173
- const paths = args2.filter((arg) => arg !== "\\" && !arg.startsWith("--"));
5174
- return continued ? paths : paths.slice(0, -1);
5175
- }
5176
- function removeTypingsCopy(dockerfile) {
5177
- const kept = [];
5178
- const removed = [];
5179
- const unresolved = [];
5180
- let previousCarriesOn = false;
5181
- const lines = dockerfile.match(/[^\n]*\n|[^\n]+$/g) ?? [];
5182
- for (const line2 of lines) {
5183
- const startsInstruction = !previousCarriesOn;
5184
- const carriesOn = continues(line2);
5185
- previousCarriesOn = carriesOn;
5186
- const sources = startsInstruction ? contextSources(line2, carriesOn) : [];
5187
- if (!sources.some((source) => TYPINGS_PATH.test(source))) {
5188
- kept.push(line2);
5189
- } else if (sources.length === 1 && !carriesOn) {
5190
- removed.push(line2.trim());
5191
- } else {
5192
- kept.push(line2);
5193
- unresolved.push(line2.trim());
5194
- }
5195
- }
5196
- return { contents: kept.join(""), removed, unresolved };
5197
- }
5198
- function removeTypingsFromDockerfile(cwd) {
5199
- const dockerfilePath = import_path9.default.join(cwd, DOCKERFILE);
5200
- if (!(0, import_fs8.existsSync)(dockerfilePath)) return;
5201
- const { contents, removed, unresolved } = removeTypingsCopy(
5202
- (0, import_fs8.readFileSync)(dockerfilePath, "utf8")
5203
- );
5204
- if (removed.length === 0 && unresolved.length === 0) return;
5205
- console.log("\nUpdating the Dockerfile...\n");
5206
- if (removed.length > 0) {
5207
- (0, import_fs8.writeFileSync)(dockerfilePath, contents);
5208
- }
5209
- for (const instruction of removed) {
5210
- console.log(
5211
- ` \u2713 ${DOCKERFILE}: removed '${instruction}', the Tiltfile no longer sends typings/ to the image build`
5212
- );
5213
- }
5214
- for (const instruction of unresolved) {
5215
- console.warn(
5216
- ` \u26A0\uFE0F ${DOCKERFILE} still copies from typings/ ('${instruction}'), which the Tiltfile no longer sends to the image build; remove it by hand`
5217
- );
5218
- }
5219
- }
5220
- async function main8() {
5221
- removeTypingsFromDockerfile(process.cwd());
5222
- }
5223
-
5224
5139
  // src/migrations/v2.1/rename-trigger-paths.ts
5225
5140
  var import_ts_morph5 = require("ts-morph");
5226
- var import_path10 = __toESM(require("path"));
5141
+ var import_path9 = __toESM(require("path"));
5227
5142
  var PATH_PREFIX_RENAMES = {
5228
5143
  "/triggers/user/": "/trigger/user/",
5229
5144
  "/triggers/system/": "/trigger/system/"
@@ -5281,7 +5196,7 @@ function processFile2(filePath, project) {
5281
5196
  const sourceFile = project.getSourceFile(filePath);
5282
5197
  if (!sourceFile) return 0;
5283
5198
  let renamedCount = 0;
5284
- const relPath = import_path10.default.relative(process.cwd(), filePath);
5199
+ const relPath = import_path9.default.relative(process.cwd(), filePath);
5285
5200
  const candidates = sourceFile.getDescendantsOfKind(
5286
5201
  import_ts_morph5.SyntaxKind.ObjectLiteralExpression
5287
5202
  );
@@ -5298,7 +5213,7 @@ function processFile2(filePath, project) {
5298
5213
  function warnAboutStalePaths(sourceFiles) {
5299
5214
  const stale = [];
5300
5215
  for (const sourceFile of sourceFiles) {
5301
- const relPath = import_path10.default.relative(process.cwd(), sourceFile.getFilePath());
5216
+ const relPath = import_path9.default.relative(process.cwd(), sourceFile.getFilePath());
5302
5217
  const lines = sourceFile.getFullText().split("\n");
5303
5218
  lines.forEach((line2, index) => {
5304
5219
  if (line2.includes(STALE_PREFIX)) {
@@ -5313,8 +5228,8 @@ WARNING: ${stale.length} remaining '${STALE_PREFIX}' reference(s) need to be ren
5313
5228
  );
5314
5229
  console.log(stale.join("\n"));
5315
5230
  }
5316
- async function main9() {
5317
- const srcDir = import_path10.default.join(process.cwd(), "src");
5231
+ async function main8() {
5232
+ const srcDir = import_path9.default.join(process.cwd(), "src");
5318
5233
  console.log(`Scanning for Hapi route configs in: ${srcDir}
5319
5234
  `);
5320
5235
  console.log("Active path renames:");
@@ -5323,7 +5238,7 @@ async function main9() {
5323
5238
  }
5324
5239
  console.log();
5325
5240
  const project = new import_ts_morph5.Project({
5326
- tsConfigFilePath: import_path10.default.resolve(srcDir, "../tsconfig.json"),
5241
+ tsConfigFilePath: import_path9.default.resolve(srcDir, "../tsconfig.json"),
5327
5242
  skipAddingFilesFromTsConfig: false
5328
5243
  });
5329
5244
  const sourceFiles = project.getSourceFiles().filter((sf) => {
@@ -5350,7 +5265,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
5350
5265
  for (const filePath of modifiedFiles) {
5351
5266
  const sourceFile = project.getSourceFileOrThrow(filePath);
5352
5267
  await sourceFile.save();
5353
- console.log(` Saved: ${import_path10.default.relative(process.cwd(), filePath)}`);
5268
+ console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
5354
5269
  }
5355
5270
  console.log(`
5356
5271
  Done. Renamed ${totalRenamed} route path(s).`);
@@ -5359,21 +5274,21 @@ Done. Renamed ${totalRenamed} route path(s).`);
5359
5274
  }
5360
5275
 
5361
5276
  // src/migrations/v2.1/upgrade-tilt.ts
5362
- var import_fs9 = require("fs");
5363
- var import_path11 = __toESM(require("path"));
5277
+ var import_fs8 = require("fs");
5278
+ var import_path10 = __toESM(require("path"));
5364
5279
  var COUNTRY_OWNED_DIR = "tilt/helm/";
5365
5280
  var CHARTS_CHECKOUT_DIR = ".opencrvs-core-charts";
5366
5281
  var IMAGE_NAME_PATTERN = /^countryconfig_image_name\s*=\s*(["'])(.*?)\1/m;
5367
5282
  function writeIfChanged(cwd, relativePath, contents, mode) {
5368
- const target = import_path11.default.join(cwd, relativePath);
5369
- const existed = (0, import_fs9.existsSync)(target);
5370
- if (existed && (0, import_fs9.readFileSync)(target, "utf8") === contents) {
5283
+ const target = import_path10.default.join(cwd, relativePath);
5284
+ const existed = (0, import_fs8.existsSync)(target);
5285
+ if (existed && (0, import_fs8.readFileSync)(target, "utf8") === contents) {
5371
5286
  return "unchanged";
5372
5287
  }
5373
- (0, import_fs9.mkdirSync)(import_path11.default.dirname(target), { recursive: true });
5374
- (0, import_fs9.writeFileSync)(target, contents);
5288
+ (0, import_fs8.mkdirSync)(import_path10.default.dirname(target), { recursive: true });
5289
+ (0, import_fs8.writeFileSync)(target, contents);
5375
5290
  if (mode !== void 0) {
5376
- (0, import_fs9.chmodSync)(target, mode & 511);
5291
+ (0, import_fs8.chmodSync)(target, mode & 511);
5377
5292
  }
5378
5293
  return existed ? "updated" : "created";
5379
5294
  }
@@ -5403,29 +5318,29 @@ function withIgnoreEntry(contents, line2) {
5403
5318
  `;
5404
5319
  }
5405
5320
  function ensureIgnored(cwd, file, line2) {
5406
- const target = import_path11.default.join(cwd, file);
5407
- const contents = (0, import_fs9.existsSync)(target) ? (0, import_fs9.readFileSync)(target, "utf8") : "";
5321
+ const target = import_path10.default.join(cwd, file);
5322
+ const contents = (0, import_fs8.existsSync)(target) ? (0, import_fs8.readFileSync)(target, "utf8") : "";
5408
5323
  report(file, writeIfChanged(cwd, file, withIgnoreEntry(contents, line2)));
5409
5324
  }
5410
5325
  function upgradeTilt(cwd, templateDir) {
5411
- const tiltfilePath = import_path11.default.join(cwd, "Tiltfile");
5412
- const existingTiltfile = (0, import_fs9.existsSync)(tiltfilePath) ? (0, import_fs9.readFileSync)(tiltfilePath, "utf8") : void 0;
5326
+ const tiltfilePath = import_path10.default.join(cwd, "Tiltfile");
5327
+ const existingTiltfile = (0, import_fs8.existsSync)(tiltfilePath) ? (0, import_fs8.readFileSync)(tiltfilePath, "utf8") : void 0;
5413
5328
  report(
5414
5329
  "Tiltfile",
5415
5330
  writeIfChanged(
5416
5331
  cwd,
5417
5332
  "Tiltfile",
5418
5333
  renderTiltfile(
5419
- (0, import_fs9.readFileSync)(import_path11.default.join(templateDir, "Tiltfile"), "utf8"),
5334
+ (0, import_fs8.readFileSync)(import_path10.default.join(templateDir, "Tiltfile"), "utf8"),
5420
5335
  existingTiltfile
5421
5336
  )
5422
5337
  )
5423
5338
  );
5424
5339
  const templateFiles = listFiles(templateDir, "tilt");
5425
5340
  for (const file of templateFiles) {
5426
- const source = import_path11.default.join(templateDir, file);
5341
+ const source = import_path10.default.join(templateDir, file);
5427
5342
  const countryOwned = file.startsWith(COUNTRY_OWNED_DIR);
5428
- if (countryOwned && (0, import_fs9.existsSync)(import_path11.default.join(cwd, file))) {
5343
+ if (countryOwned && (0, import_fs8.existsSync)(import_path10.default.join(cwd, file))) {
5429
5344
  continue;
5430
5345
  }
5431
5346
  report(
@@ -5433,8 +5348,8 @@ function upgradeTilt(cwd, templateDir) {
5433
5348
  writeIfChanged(
5434
5349
  cwd,
5435
5350
  file,
5436
- (0, import_fs9.readFileSync)(source, "utf8"),
5437
- (0, import_fs9.statSync)(source).mode
5351
+ (0, import_fs8.readFileSync)(source, "utf8"),
5352
+ (0, import_fs8.statSync)(source).mode
5438
5353
  )
5439
5354
  );
5440
5355
  }
@@ -5454,7 +5369,7 @@ function upgradeTilt(cwd, templateDir) {
5454
5369
  );
5455
5370
  }
5456
5371
  }
5457
- async function main10() {
5372
+ async function main9() {
5458
5373
  console.log("Upgrading the local Tilt setup...\n");
5459
5374
  upgradeTilt(process.cwd(), findTemplateDir());
5460
5375
  console.log(
@@ -5465,20 +5380,19 @@ async function main10() {
5465
5380
  // src/migrations/v2.1/index.ts
5466
5381
  async function runUpgrade(dockerSwarm) {
5467
5382
  await main();
5468
- await main9();
5383
+ await main8();
5469
5384
  await main2();
5470
5385
  await main3();
5471
5386
  await main7();
5472
5387
  await main6();
5473
5388
  await main5(dockerSwarm);
5474
- await main10();
5475
- await main8();
5389
+ await main9();
5476
5390
  await main4();
5477
5391
  }
5478
5392
 
5479
5393
  // src/environment/index.ts
5480
- var import_fs14 = require("fs");
5481
- var import_path16 = require("path");
5394
+ var import_fs13 = require("fs");
5395
+ var import_path15 = require("path");
5482
5396
  init_paths();
5483
5397
  var REQUIRED_REPOSITORY_DIRECTORIES = [
5484
5398
  ".github/workflows",
@@ -5489,7 +5403,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
5489
5403
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
5490
5404
  (directory) => {
5491
5405
  try {
5492
- return !(0, import_fs14.statSync)((0, import_path16.resolve)(repositoryRoot, directory)).isDirectory();
5406
+ return !(0, import_fs13.statSync)((0, import_path15.resolve)(repositoryRoot, directory)).isDirectory();
5493
5407
  } catch {
5494
5408
  return true;
5495
5409
  }
@@ -5816,8 +5730,8 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
5816
5730
  console.log(line(ok, endpointLabel(check), detail));
5817
5731
  }
5818
5732
  {
5819
- const path15 = `/fonts/${PROBE_SEGMENT}.ttf`;
5820
- const status = await requestStatus(`${baseUrl}${path15}`, "GET");
5733
+ const path14 = `/fonts/${PROBE_SEGMENT}.ttf`;
5734
+ const status = await requestStatus(`${baseUrl}${path14}`, "GET");
5821
5735
  const ok = status === 200 || status === 404;
5822
5736
  if (!ok) {
5823
5737
  failures++;
@@ -5832,7 +5746,7 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
5832
5746
  } else {
5833
5747
  detail = `${describeStatus(status)} \u2014 unexpected`;
5834
5748
  }
5835
- console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path15}`)}`, detail));
5749
+ console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path14}`)}`, detail));
5836
5750
  }
5837
5751
  console.log();
5838
5752
  console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
@@ -5970,7 +5884,7 @@ Options:
5970
5884
  'assets/' (default).
5971
5885
  -h, --help Show this message.
5972
5886
  `.trim();
5973
- function main11() {
5887
+ function main10() {
5974
5888
  const command = args[0];
5975
5889
  if (!command || command === "--help" || command === "-h") {
5976
5890
  console.log(USAGE);
@@ -6091,4 +6005,4 @@ async function handleVerifyEndpoints() {
6091
6005
  process.exit(1);
6092
6006
  }
6093
6007
  }
6094
- main11();
6008
+ main10();