@opencrvs/toolkit 2.0.0-rc.eac601e → 2.0.0-rc.ec6b668

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.
Files changed (91) hide show
  1. package/create-countryconfig/index.js +73 -0
  2. package/create-countryconfig/package.json +11 -0
  3. package/dist/application-config/index.js +56 -31
  4. package/dist/cli.js +1860 -346
  5. package/dist/commons/api/router.d.ts +3017 -297
  6. package/dist/commons/application-config/index.d.ts +16 -4
  7. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  8. package/dist/commons/conditionals/validate.d.ts +1 -0
  9. package/dist/commons/events/ActionInput.d.ts +108 -0
  10. package/dist/commons/events/Draft.d.ts +3 -0
  11. package/dist/commons/events/EventIndex.d.ts +1 -0
  12. package/dist/commons/events/EventMetadata.d.ts +1 -0
  13. package/dist/commons/events/FieldConfig.d.ts +10 -0
  14. package/dist/commons/events/locations.d.ts +38 -1
  15. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  16. package/dist/commons/events/scopes.d.ts +24 -1
  17. package/dist/commons/events/state/index.d.ts +2 -1
  18. package/dist/commons/events/utils.d.ts +1 -1
  19. package/dist/conditionals/index.js +37 -7
  20. package/dist/events/index.js +161 -41
  21. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  22. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
  23. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  24. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  25. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  26. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  27. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  28. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -14
  29. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  30. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  31. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  32. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  33. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  34. package/dist/migrations/v2.0/create-events-index.js +1 -2
  35. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +11 -0
  36. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  37. package/dist/migrations/v2.0/delete-infrastructure-directory.js +123 -0
  38. package/dist/migrations/v2.0/index.d.ts +10 -4
  39. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  40. package/dist/migrations/v2.0/index.js +1828 -343
  41. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  42. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +95 -7
  43. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +13 -0
  44. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  45. package/dist/migrations/v2.0/merge-infrastructure-directory.js +222 -0
  46. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  47. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  48. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  49. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  50. package/dist/migrations/v2.0/migrate-scopes.js +55 -32
  51. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  52. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  53. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  54. package/dist/migrations/v2.0/migrate-workqueue-configs.js +143 -63
  55. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  56. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  57. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  58. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  59. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  60. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  61. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  62. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  63. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  64. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  65. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  66. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  67. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  68. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  69. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  70. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  71. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  72. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  73. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  74. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  76. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  77. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  78. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  79. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  80. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  81. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  82. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  83. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/update-package-json.js +105 -0
  85. package/dist/notification/index.js +55 -27
  86. package/dist/scopes/index.d.ts +87 -10
  87. package/dist/scopes/index.js +43 -8
  88. package/opencrvs-toolkit-2.0.0-rc.ec6b668.tgz +0 -0
  89. package/package.json +1 -1
  90. package/tsconfig.tsbuildinfo +1 -1
  91. package/opencrvs-toolkit-2.0.0-rc.eac601e.tgz +0 -0
@@ -19,6 +19,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  });
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.UPSTREAM_BRANCH = exports.UPSTREAM_URL = void 0;
23
+ exports.runGit = runGit;
24
+ exports.tryGit = tryGit;
25
+ exports.assertIsGitRepo = assertIsGitRepo;
22
26
  exports.main = main;
23
27
  /**
24
28
  * Codemod: Replace selected files with their upstream v2.0 versions from
@@ -54,16 +58,15 @@ exports.main = main;
54
58
  * - Requires the country config working directory to be a git repo.
55
59
  */
56
60
  const child_process_1 = require("child_process");
57
- const _1 = require(".");
58
- const UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
59
- // @TODO: This needs to be changed to 'release-v2.0.0' once the branch is created
60
- const UPSTREAM_BRANCH = 'develop';
61
+ exports.UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
62
+ exports.UPSTREAM_BRANCH = 'release-v2.0.0';
61
63
  // Remote name used only for the duration of this codemod. Prefixed to avoid
62
64
  // clashing with remotes the user may have (origin, upstream, etc.).
63
65
  const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
64
66
  const FILES_TO_CHECKOUT = [
65
- 'infrastructure/postgres/setup-analytics.sh',
66
- 'src/analytics/analytics.ts'
67
+ 'src/analytics/analytics.ts',
68
+ 'Dockerfile',
69
+ 'Dockerfile.assets'
67
70
  ];
68
71
  // ─── Git helpers ─────────────────────────────────────────────────────────────
69
72
  /**
@@ -75,7 +78,7 @@ const FILES_TO_CHECKOUT = [
75
78
  */
76
79
  function runGit(args, { silent = false } = {}) {
77
80
  return (0, child_process_1.execFileSync)('git', args, {
78
- cwd: (0, _1.getCwd)(),
81
+ cwd: process.cwd(),
79
82
  encoding: 'utf8',
80
83
  stdio: silent ? ['ignore', 'pipe', 'pipe'] : ['ignore', 'pipe', 'inherit']
81
84
  });
@@ -96,22 +99,22 @@ function tryGit(args) {
96
99
  }
97
100
  function assertIsGitRepo() {
98
101
  if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
99
- throw new Error(`checkout-upstream-files: ${(0, _1.getCwd)()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
102
+ throw new Error(`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
100
103
  }
101
104
  }
102
105
  // ─── Entry point ─────────────────────────────────────────────────────────────
103
106
  function main() {
104
107
  return __awaiter(this, void 0, void 0, function* () {
105
- console.log(`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...\n`);
108
+ console.log(`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${exports.UPSTREAM_URL}@${exports.UPSTREAM_BRANCH}...\n`);
106
109
  assertIsGitRepo();
107
110
  // Best-effort cleanup of a stale temp remote from a previous aborted run.
108
111
  tryGit(['remote', 'remove', TEMP_REMOTE]);
109
112
  try {
110
- console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${UPSTREAM_URL}`);
111
- runGit(['remote', 'add', TEMP_REMOTE, UPSTREAM_URL], { silent: true });
112
- console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
113
- runGit(['fetch', '--depth=1', TEMP_REMOTE, UPSTREAM_BRANCH]);
114
- const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
113
+ console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${exports.UPSTREAM_URL}`);
114
+ runGit(['remote', 'add', TEMP_REMOTE, exports.UPSTREAM_URL], { silent: true });
115
+ console.log(` Fetching ${TEMP_REMOTE}/${exports.UPSTREAM_BRANCH} (depth 1)...`);
116
+ runGit(['fetch', '--depth=1', TEMP_REMOTE, exports.UPSTREAM_BRANCH]);
117
+ const ref = `${TEMP_REMOTE}/${exports.UPSTREAM_BRANCH}`;
115
118
  const missing = [];
116
119
  let checkedOut = 0;
117
120
  for (const file of FILES_TO_CHECKOUT) {
@@ -1 +1 @@
1
- {"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AAyuBA,wBAAsB,IAAI,kBAyPzB"}
1
+ {"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AAuuBA,wBAAsB,IAAI,kBAyPzB"}
@@ -87,7 +87,6 @@ exports.main = main;
87
87
  const fs = __importStar(require("fs"));
88
88
  const ts_morph_1 = require("ts-morph");
89
89
  const path_1 = __importDefault(require("path"));
90
- const _1 = require(".");
91
90
  // ─── Schema-valid keys per config type ───────────────────────────────────────
92
91
  const CLIENT_VALID_KEYS = new Set([
93
92
  'COUNTRY',
@@ -634,8 +633,8 @@ function ensureJoinImport(sf) {
634
633
  function main() {
635
634
  return __awaiter(this, void 0, void 0, function* () {
636
635
  var _a;
637
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
638
- const relCwd = (fp) => path_1.default.relative((0, _1.getCwd)(), fp);
636
+ const srcDir = path_1.default.join(process.cwd(), 'src');
637
+ const relCwd = (fp) => path_1.default.relative(process.cwd(), fp);
639
638
  // ── Phase 1: Convert JS config files to TypeScript ────────────────────────
640
639
  console.log('Phase 1: Converting JS config files to TypeScript...\n');
641
640
  let convertedCount = 0;
@@ -741,7 +740,7 @@ function main() {
741
740
  if (/\bjoin\s*\(/.test(adjustedValue)) {
742
741
  ensureJoinImport(sf);
743
742
  }
744
- console.log(` Inlined applicationConfig.${accessPath.join('.')} → ${adjustedValue} in ${path_1.default.relative((0, _1.getCwd)(), sf.getFilePath())}`);
743
+ console.log(` Inlined applicationConfig.${accessPath.join('.')} → ${adjustedValue} in ${path_1.default.relative(process.cwd(), sf.getFilePath())}`);
745
744
  filesToSaveAfterInlining.add(sf);
746
745
  madeReplacement = true;
747
746
  break; // restart — tree has changed
@@ -752,7 +751,7 @@ function main() {
752
751
  // Persist files that received inline replacements
753
752
  for (const sf of Array.from(filesToSaveAfterInlining)) {
754
753
  yield sf.save();
755
- console.log(` Saved (inlined): ${path_1.default.relative((0, _1.getCwd)(), sf.getFilePath())}`);
754
+ console.log(` Saved (inlined): ${path_1.default.relative(process.cwd(), sf.getFilePath())}`);
756
755
  }
757
756
  // Remove in reverse order to avoid index shifting
758
757
  for (const prop of [...propsToRemove].reverse()) {
@@ -1 +1 @@
1
- {"version":3,"file":"convert-paragraph-to-heading.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-paragraph-to-heading.ts"],"names":[],"mappings":"AAwJA,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"convert-paragraph-to-heading.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-paragraph-to-heading.ts"],"names":[],"mappings":"AAsJA,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -42,7 +42,6 @@ exports.main = main;
42
42
  */
43
43
  const ts_morph_1 = require("ts-morph");
44
44
  const path_1 = __importDefault(require("path"));
45
- const _1 = require(".");
46
45
  const FIELD_TYPE_ENUM_NAME = 'FieldType';
47
46
  const PARAGRAPH_MEMBER_NAME = 'PARAGRAPH';
48
47
  const HEADING_MEMBER_NAME = 'HEADING';
@@ -112,18 +111,18 @@ function processFile(filePath, project) {
112
111
  const result = transformParagraphField(obj);
113
112
  if (result === 'converted-to-heading') {
114
113
  changedCount++;
115
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`);
114
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`);
116
115
  }
117
116
  else if (result === 'removed-font-variant') {
118
117
  changedCount++;
119
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`);
118
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`);
120
119
  }
121
120
  }
122
121
  return changedCount;
123
122
  }
124
123
  function main() {
125
124
  return __awaiter(this, void 0, void 0, function* () {
126
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
125
+ const srcDir = path_1.default.join(process.cwd(), 'src');
127
126
  console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}\n`);
128
127
  const project = new ts_morph_1.Project({
129
128
  tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
@@ -152,7 +151,7 @@ function main() {
152
151
  for (const filePath of modifiedFiles) {
153
152
  const sourceFile = project.getSourceFileOrThrow(filePath);
154
153
  yield sourceFile.save();
155
- console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
154
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
156
155
  }
157
156
  console.log(`\nDone. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
158
157
  });
@@ -1 +1 @@
1
- {"version":3,"file":"create-events-index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/create-events-index.ts"],"names":[],"mappings":"AAqTA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAmEnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"create-events-index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/create-events-index.ts"],"names":[],"mappings":"AAmTA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAmEnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -63,7 +63,6 @@ exports.main = main;
63
63
  const ts_morph_1 = require("ts-morph");
64
64
  const fs_1 = __importDefault(require("fs"));
65
65
  const path_1 = __importDefault(require("path"));
66
- const _1 = require(".");
67
66
  const DEFINE_CONFIG_NAME = 'defineConfig';
68
67
  const HANDLER_FUNCTION_NAMES = new Set([
69
68
  'getCustomEventsHandler',
@@ -274,7 +273,7 @@ function modifyHandler(sourceFile, exportNames) {
274
273
  // ─── Entry point ─────────────────────────────────────────────────────────────
275
274
  function main() {
276
275
  return __awaiter(this, void 0, void 0, function* () {
277
- const cwd = (0, _1.getCwd)();
276
+ const cwd = process.cwd();
278
277
  const srcDir = path_1.default.join(cwd, 'src');
279
278
  console.log(`Scanning for defineConfig event exports in: ${srcDir}\n`);
280
279
  const project = new ts_morph_1.Project({
@@ -0,0 +1,11 @@
1
+ interface DeleteInfrastructureOptions {
2
+ /**
3
+ * Top-level entries directly under `infrastructure/` to preserve. Names
4
+ * match against the basename of each entry (file or directory). When
5
+ * empty (the default), the whole `infrastructure/` directory is deleted.
6
+ */
7
+ keep?: string[];
8
+ }
9
+ declare function main({ keep }?: DeleteInfrastructureOptions): Promise<void>;
10
+ export { main };
11
+ //# sourceMappingURL=delete-infrastructure-directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/delete-infrastructure-directory.ts"],"names":[],"mappings":"AAoDA,UAAU,2BAA2B;IACnC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,iBAAe,IAAI,CAAC,EAClB,IAAS,EACV,GAAE,2BAAgC,GAAG,OAAO,CAAC,IAAI,CAAC,CA4FlD;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.main = main;
23
+ /**
24
+ * Codemod: Remove the local `infrastructure/` directory.
25
+ *
26
+ * Used by the v1.9 → v2.0 upgrade when the country config does NOT deploy
27
+ * via Docker Swarm. In that case the `infrastructure/` directory shipped
28
+ * with opencrvs-countryconfig is no longer needed and can be removed.
29
+ *
30
+ * Some non-Swarm deployments still need a small subset of
31
+ * `infrastructure/` (e.g. `postgres/` and `metabase/`). Pass `keep` to
32
+ * preserve those top-level subdirectories — everything else under
33
+ * `infrastructure/` is deleted, and the kept subdirectories can then be
34
+ * refreshed from upstream by `merge-infrastructure-directory.ts` with the
35
+ * matching `subdirs` option.
36
+ *
37
+ * Usage:
38
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/delete-infrastructure-directory.ts
39
+ *
40
+ * What it does:
41
+ * 1. Stages deletion of all tracked files under `infrastructure/` via
42
+ * `git rm -rf --ignore-unmatch -- <path>`. This both removes the
43
+ * files from the working tree and records the deletion in the
44
+ * index, so it shows up in the upgrade commit alongside the other
45
+ * codemod changes. When `keep` is provided, deletion is scoped to
46
+ * the top-level entries that are NOT in `keep`.
47
+ * 2. Cleans up any untracked files / empty directory that `git rm` left
48
+ * behind, so the deleted paths are fully gone from the working tree.
49
+ *
50
+ * Caveats:
51
+ * - Destructive: any local edits to deleted paths are lost. Run on a
52
+ * clean working tree (or after committing your local changes).
53
+ * - If `infrastructure/` doesn't exist, this codemod is a no-op.
54
+ * - Requires git to be installed and the country config working directory
55
+ * to be a git repo.
56
+ */
57
+ const fs_1 = require("fs");
58
+ const path_1 = require("path");
59
+ const checkout_upstream_files_1 = require("./checkout-upstream-files");
60
+ const INFRASTRUCTURE_DIR = 'infrastructure';
61
+ function main() {
62
+ return __awaiter(this, arguments, void 0, function* ({ keep = [] } = {}) {
63
+ const fullPath = (0, path_1.join)(process.cwd(), INFRASTRUCTURE_DIR);
64
+ if (!(0, fs_1.existsSync)(fullPath)) {
65
+ console.log(`'${INFRASTRUCTURE_DIR}/' not found in ${process.cwd()} — nothing to delete.`);
66
+ return;
67
+ }
68
+ (0, checkout_upstream_files_1.assertIsGitRepo)();
69
+ // ─── Whole-directory delete (legacy behavior) ────────────────────────
70
+ if (keep.length === 0) {
71
+ console.log(`Deleting '${INFRASTRUCTURE_DIR}/'...\n`);
72
+ // `git rm -rf --ignore-unmatch` removes tracked files (working tree +
73
+ // index) and is a no-op for paths with no tracked entries, so it's
74
+ // safe to run even when `infrastructure/` exists only as untracked
75
+ // files.
76
+ (0, checkout_upstream_files_1.runGit)(['rm', '-rf', '--ignore-unmatch', '--', `${INFRASTRUCTURE_DIR}/`], {
77
+ silent: true
78
+ });
79
+ console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR}/'.`);
80
+ // `git rm` leaves untracked files (and any now-empty directory) on
81
+ // disk; remove whatever's left so the path is fully gone.
82
+ if ((0, fs_1.existsSync)(fullPath)) {
83
+ (0, fs_1.rmSync)(fullPath, { recursive: true, force: true });
84
+ console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR}/'.`);
85
+ }
86
+ console.log(`\n Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR}/'`);
87
+ return;
88
+ }
89
+ // ─── Selective delete: keep listed top-level entries ─────────────────
90
+ const keepSet = new Set(keep);
91
+ console.log(`Deleting contents of '${INFRASTRUCTURE_DIR}/' except: ${[...keepSet]
92
+ .map((name) => `'${name}'`)
93
+ .join(', ')}\n`);
94
+ const topLevelEntries = (0, fs_1.readdirSync)(fullPath, { withFileTypes: true });
95
+ let deleted = 0;
96
+ for (const entry of topLevelEntries) {
97
+ if (keepSet.has(entry.name)) {
98
+ console.log(` Keeping '${INFRASTRUCTURE_DIR}/${entry.name}'.`);
99
+ continue;
100
+ }
101
+ // Append a trailing slash for directories so git treats it as a tree
102
+ // pathspec (matches the recursive behavior of `git rm -rf`).
103
+ const relPath = `${INFRASTRUCTURE_DIR}/${entry.name}${entry.isDirectory() ? '/' : ''}`;
104
+ (0, checkout_upstream_files_1.runGit)(['rm', '-rf', '--ignore-unmatch', '--', relPath], { silent: true });
105
+ const fullEntryPath = (0, path_1.join)(fullPath, entry.name);
106
+ if ((0, fs_1.existsSync)(fullEntryPath)) {
107
+ (0, fs_1.rmSync)(fullEntryPath, { recursive: true, force: true });
108
+ }
109
+ console.log(` Deleted '${relPath}'.`);
110
+ deleted++;
111
+ }
112
+ // Note any requested keeps that weren't actually present, so the dev
113
+ // notices typos / missing directories.
114
+ const presentNames = new Set(topLevelEntries.map((e) => e.name));
115
+ const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
116
+ if (missingKeeps.length > 0) {
117
+ console.warn(` [warn] Requested to keep ${missingKeeps
118
+ .map((n) => `'${n}'`)
119
+ .join(', ')} but they don't exist under '${INFRASTRUCTURE_DIR}/'.`);
120
+ }
121
+ console.log(`\n Done. Deleted ${deleted} top-level entr${deleted === 1 ? 'y' : 'ies'}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR}/'`);
122
+ });
123
+ }
@@ -1,7 +1,13 @@
1
- export declare function getCwd(): string;
2
1
  /**
3
- * Run the upgrade process for a given country config directory.
4
- * @param ccwd - The country config working directory.
2
+ * Run the upgrade process for the country config in the current working
3
+ * directory.
4
+ *
5
+ * @param dockerSwarm - When true, the local `infrastructure/` directory is
6
+ * merged with upstream changes in its entirety (Docker Swarm deployments
7
+ * still need it all). When false (the default), everything under
8
+ * `infrastructure/` is deleted EXCEPT the subdirectories listed in
9
+ * `NON_SWARM_INFRA_SUBDIRS`, and those preserved subdirectories are then
10
+ * merged with upstream.
5
11
  */
6
- export declare function runUpgrade(ccwd: string | undefined): Promise<void>;
12
+ export declare function runUpgrade(dockerSwarm: boolean): Promise<void>;
7
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA+BA,wBAAgB,MAAM,WAMrB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,iBA8BxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA6CA;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAgCpD"}