@opencrvs/toolkit 2.0.0-rc.a26ae04 → 2.0.0-rc.a3c1fd8

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 (29) 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 +5 -3
  4. package/dist/cli.js +192 -96
  5. package/dist/commons/api/router.d.ts +20 -20
  6. package/dist/commons/conditionals/conditionals.d.ts +3 -3
  7. package/dist/commons/events/FieldConfig.d.ts +5 -0
  8. package/dist/conditionals/index.js +5 -3
  9. package/dist/events/index.js +5 -3
  10. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  11. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  12. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -2
  13. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +9 -1
  14. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
  15. package/dist/migrations/v2.0/delete-infrastructure-directory.js +66 -20
  16. package/dist/migrations/v2.0/index.d.ts +5 -3
  17. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  18. package/dist/migrations/v2.0/index.js +192 -96
  19. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +11 -1
  20. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
  21. package/dist/migrations/v2.0/merge-infrastructure-directory.js +17 -16
  22. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  23. package/dist/migrations/v2.0/migrate-workqueue-configs.js +140 -59
  24. package/dist/notification/index.js +5 -3
  25. package/dist/scopes/index.d.ts +6 -1
  26. package/dist/scopes/index.js +5 -3
  27. package/opencrvs-toolkit-2.0.0-rc.a3c1fd8.tgz +0 -0
  28. package/package.json +1 -1
  29. package/opencrvs-toolkit-2.0.0-rc.a26ae04.tgz +0 -0
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ /*
4
+ * This Source Code Form is subject to the terms of the Mozilla Public
5
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
+ *
8
+ * OpenCRVS is also distributed under the terms of the Civil Registration
9
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
10
+ *
11
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
12
+ */
13
+
14
+ const { execSync } = require('child_process')
15
+ const path = require('path')
16
+ const fs = require('fs')
17
+
18
+ const REPO_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git'
19
+
20
+ const projectName = process.argv[2]
21
+
22
+ if (!projectName) {
23
+ console.error(
24
+ 'Please specify a project name:\n\n npm create @opencrvs/countryconfig <project-name>\n'
25
+ )
26
+ process.exit(1)
27
+ }
28
+
29
+ const targetDir = path.resolve(process.cwd(), projectName)
30
+
31
+ if (fs.existsSync(targetDir)) {
32
+ console.error(`Error: Directory "${projectName}" already exists.`)
33
+ process.exit(1)
34
+ }
35
+
36
+ console.log(`\nScaffolding OpenCRVS country config in ./${projectName}...\n`)
37
+
38
+ try {
39
+ execSync(`git clone --depth 1 ${REPO_URL} ${projectName}`, {
40
+ stdio: 'inherit'
41
+ })
42
+ } catch (err) {
43
+ console.error('Failed to clone the repository:', err.message)
44
+ process.exit(1)
45
+ }
46
+
47
+ try {
48
+ fs.rmSync(path.join(targetDir, '.git'), { recursive: true, force: true })
49
+ } catch (err) {
50
+ console.error('Failed to remove .git directory:', err.message)
51
+ process.exit(1)
52
+ }
53
+
54
+ const pkgPath = path.join(targetDir, 'package.json')
55
+ if (fs.existsSync(pkgPath)) {
56
+ try {
57
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
58
+ pkg.name = projectName
59
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
60
+ } catch (err) {
61
+ console.error('Failed to update package.json:', err.message)
62
+ process.exit(1)
63
+ }
64
+ } else {
65
+ console.warn(
66
+ `Warning: No package.json found in the cloned repository. Project name was not updated.`
67
+ )
68
+ }
69
+
70
+ console.log(`\nDone! To get started:\n`)
71
+ console.log(` cd ${projectName}`)
72
+ console.log(` git init`)
73
+ console.log(` npm install\n`)
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@opencrvs/create-countryconfig",
3
+ "version": "1.0.0",
4
+ "description": "Scaffold a new OpenCRVS country configuration",
5
+ "bin": {
6
+ "create-countryconfig": "./index.js"
7
+ },
8
+ "files": ["index.js"],
9
+ "keywords": ["opencrvs", "countryconfig", "create"],
10
+ "license": "MPL-2.0"
11
+ }
@@ -772,12 +772,14 @@ var SystemScopeType = z11.enum([
772
772
  "organisation.read-locations",
773
773
  "user.read",
774
774
  "user.create",
775
- "user.edit"
775
+ "user.edit",
776
+ "user.search"
776
777
  ]);
777
778
  var UserScopeType = SystemScopeType.extract([
778
779
  "user.read",
779
780
  "user.create",
780
- "user.edit"
781
+ "user.edit",
782
+ "user.search"
781
783
  ]);
782
784
  var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
783
785
  var UserScopeV2 = z11.discriminatedUnion("type", [
@@ -786,7 +788,7 @@ var UserScopeV2 = z11.discriminatedUnion("type", [
786
788
  options: AllUserScopeOptions.optional()
787
789
  }),
788
790
  z11.object({
789
- type: UserScopeType.extract(["user.read"]),
791
+ type: UserScopeType.extract(["user.read", "user.search"]),
790
792
  options: AccessLevelOptions.optional()
791
793
  })
792
794
  ]);
package/dist/cli.js CHANGED
@@ -2296,12 +2296,14 @@ var SystemScopeType = z3.enum([
2296
2296
  "organisation.read-locations",
2297
2297
  "user.read",
2298
2298
  "user.create",
2299
- "user.edit"
2299
+ "user.edit",
2300
+ "user.search"
2300
2301
  ]);
2301
2302
  var UserScopeType = SystemScopeType.extract([
2302
2303
  "user.read",
2303
2304
  "user.create",
2304
- "user.edit"
2305
+ "user.edit",
2306
+ "user.search"
2305
2307
  ]);
2306
2308
  var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
2307
2309
  var UserScopeV2 = z3.discriminatedUnion("type", [
@@ -2310,7 +2312,7 @@ var UserScopeV2 = z3.discriminatedUnion("type", [
2310
2312
  options: AllUserScopeOptions.optional()
2311
2313
  }),
2312
2314
  z3.object({
2313
- type: UserScopeType.extract(["user.read"]),
2315
+ type: UserScopeType.extract(["user.read", "user.search"]),
2314
2316
  options: AccessLevelOptions.optional()
2315
2317
  })
2316
2318
  ]);
@@ -3672,6 +3674,10 @@ var ACTION_PROPERTY_NAME2 = "action";
3672
3674
  var CONDITIONALS_PROPERTY_NAME = "conditionals";
3673
3675
  var TYPE_PROPERTY_NAME7 = "type";
3674
3676
  var SLUG_PROPERTY_NAME = "slug";
3677
+ var READ_ACTION_TYPE = "READ";
3678
+ var ACTION_TYPE_IMPORT_NAME = "ActionType";
3679
+ var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
3680
+ var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
3675
3681
  var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
3676
3682
  "READ",
3677
3683
  "DELETE",
@@ -3719,91 +3725,137 @@ function isUnsupportedActionType(action) {
3719
3725
  }
3720
3726
  return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
3721
3727
  }
3722
- function migrateWorkqueueActions(workqueue, relPath) {
3723
- const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
3724
- if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
3725
- return 0;
3726
- }
3727
- const actionsInitializer = actionsProperty.getInitializer();
3728
- if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
3729
- return 0;
3728
+ function ensureValidAction(workqueue, relPath) {
3729
+ const workqueueLabel = getWorkqueueLabel(workqueue);
3730
+ const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3731
+ if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
3732
+ const initializer = actionProperty.getInitializer();
3733
+ if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
3734
+ if (!isUnsupportedActionType(initializer)) {
3735
+ return { changed: false, usedReadFallback: false };
3736
+ }
3737
+ actionProperty.set({
3738
+ name: ACTION_PROPERTY_NAME2,
3739
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
3740
+ });
3741
+ console.log(
3742
+ ` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
3743
+ );
3744
+ return { changed: true, usedReadFallback: true };
3745
+ }
3730
3746
  }
3747
+ workqueue.addPropertyAssignment({
3748
+ name: ACTION_PROPERTY_NAME2,
3749
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
3750
+ });
3751
+ console.log(
3752
+ ` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
3753
+ );
3754
+ return { changed: true, usedReadFallback: true };
3755
+ }
3756
+ function migrateWorkqueueActions(workqueue, relPath) {
3731
3757
  const workqueueLabel = getWorkqueueLabel(workqueue);
3732
- const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3733
- if (existingActionProperty) {
3734
- if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
3735
- const existingActionInitializer = existingActionProperty.getInitializer();
3736
- if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
3737
- const conditionalsProperty2 = existingActionInitializer.getProperty(
3738
- CONDITIONALS_PROPERTY_NAME
3758
+ const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
3759
+ let actionsArrayMigrated = false;
3760
+ if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
3761
+ const actionsInitializer = actionsProperty.getInitializer();
3762
+ if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
3763
+ const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3764
+ if (existingActionProperty) {
3765
+ if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
3766
+ const existingActionInitializer = existingActionProperty.getInitializer();
3767
+ if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
3768
+ const conditionalsProperty = existingActionInitializer.getProperty(
3769
+ CONDITIONALS_PROPERTY_NAME
3770
+ );
3771
+ if (conditionalsProperty) {
3772
+ conditionalsProperty.remove();
3773
+ console.log(
3774
+ ` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
3775
+ );
3776
+ }
3777
+ }
3778
+ }
3779
+ actionsProperty.remove();
3780
+ console.log(
3781
+ ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
3782
+ );
3783
+ actionsArrayMigrated = true;
3784
+ } else {
3785
+ const actionCandidates = actionsInitializer.getElements().filter(
3786
+ (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
3739
3787
  );
3740
- if (conditionalsProperty2) {
3741
- conditionalsProperty2.remove();
3788
+ if (actionCandidates.length === 0) {
3789
+ actionsProperty.remove();
3742
3790
  console.log(
3743
- ` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
3791
+ ` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
3744
3792
  );
3745
- }
3746
- if (isUnsupportedActionType(existingActionInitializer)) {
3747
- existingActionProperty.remove();
3748
- console.log(
3749
- ` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
3793
+ actionsArrayMigrated = true;
3794
+ } else {
3795
+ if (actionCandidates.length > 1) {
3796
+ const droppedCount = actionCandidates.length - 1;
3797
+ console.warn(
3798
+ ` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
3799
+ );
3800
+ }
3801
+ const conditionalsProperty = actionCandidates[0].getProperty(
3802
+ CONDITIONALS_PROPERTY_NAME
3750
3803
  );
3804
+ if (conditionalsProperty) {
3805
+ conditionalsProperty.remove();
3806
+ console.log(
3807
+ ` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
3808
+ );
3809
+ }
3810
+ if (isUnsupportedActionType(actionCandidates[0])) {
3811
+ actionsProperty.remove();
3812
+ console.log(
3813
+ ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
3814
+ );
3815
+ actionsArrayMigrated = true;
3816
+ } else {
3817
+ const firstActionText = actionCandidates[0].getText();
3818
+ workqueue.addPropertyAssignment({
3819
+ name: ACTION_PROPERTY_NAME2,
3820
+ initializer: firstActionText
3821
+ });
3822
+ actionsProperty.remove();
3823
+ console.log(
3824
+ ` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
3825
+ );
3826
+ actionsArrayMigrated = true;
3827
+ }
3751
3828
  }
3752
3829
  }
3753
3830
  }
3754
- actionsProperty.remove();
3755
- console.log(
3756
- ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
3757
- );
3758
- return 1;
3759
- }
3760
- const actionCandidates = actionsInitializer.getElements().filter(
3761
- (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
3762
- );
3763
- if (actionCandidates.length === 0) {
3764
- actionsProperty.remove();
3765
- console.log(
3766
- ` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
3767
- );
3768
- return 1;
3769
3831
  }
3770
- if (actionCandidates.length > 1) {
3771
- const droppedCount = actionCandidates.length - 1;
3772
- console.warn(
3773
- ` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
3774
- );
3775
- }
3776
- const conditionalsProperty = actionCandidates[0].getProperty(
3777
- CONDITIONALS_PROPERTY_NAME
3832
+ const fallback = ensureValidAction(workqueue, relPath);
3833
+ return {
3834
+ changed: actionsArrayMigrated || fallback.changed,
3835
+ usedReadFallback: fallback.usedReadFallback
3836
+ };
3837
+ }
3838
+ function ensureActionTypeImport(sourceFile) {
3839
+ const existingImport = sourceFile.getImportDeclaration(
3840
+ (decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
3778
3841
  );
3779
- if (conditionalsProperty) {
3780
- conditionalsProperty.remove();
3781
- console.log(
3782
- ` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
3783
- );
3784
- }
3785
- if (isUnsupportedActionType(actionCandidates[0])) {
3786
- actionsProperty.remove();
3787
- console.log(
3788
- ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
3789
- );
3790
- return 1;
3842
+ if (existingImport) {
3843
+ const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
3844
+ if (!alreadyImported) {
3845
+ existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
3846
+ }
3847
+ return;
3791
3848
  }
3792
- const firstActionText = actionCandidates[0].getText();
3793
- workqueue.addPropertyAssignment({
3794
- name: ACTION_PROPERTY_NAME2,
3795
- initializer: firstActionText
3849
+ sourceFile.addImportDeclaration({
3850
+ moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
3851
+ namedImports: [ACTION_TYPE_IMPORT_NAME]
3796
3852
  });
3797
- actionsProperty.remove();
3798
- console.log(
3799
- ` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
3800
- );
3801
- return 1;
3802
3853
  }
3803
3854
  function processFile13(filePath, project) {
3804
3855
  const sourceFile = project.getSourceFile(filePath);
3805
3856
  if (!sourceFile) return 0;
3806
3857
  let migratedWorkqueues = 0;
3858
+ let needsActionTypeImport = false;
3807
3859
  const relPath = import_path18.default.relative(process.cwd(), filePath);
3808
3860
  const callExpressions = sourceFile.getDescendantsOfKind(
3809
3861
  import_ts_morph17.SyntaxKind.CallExpression
@@ -3819,9 +3871,14 @@ function processFile13(filePath, project) {
3819
3871
  if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
3820
3872
  for (const element of workqueuesArg.getElements()) {
3821
3873
  if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
3822
- migratedWorkqueues += migrateWorkqueueActions(element, relPath);
3874
+ const result = migrateWorkqueueActions(element, relPath);
3875
+ if (result.changed) migratedWorkqueues++;
3876
+ if (result.usedReadFallback) needsActionTypeImport = true;
3823
3877
  }
3824
3878
  }
3879
+ if (needsActionTypeImport) {
3880
+ ensureActionTypeImport(sourceFile);
3881
+ }
3825
3882
  return migratedWorkqueues;
3826
3883
  }
3827
3884
  async function main18() {
@@ -4156,7 +4213,7 @@ Saved ${handlerRelPath}.`);
4156
4213
  // src/migrations/v2.0/checkout-upstream-files.ts
4157
4214
  var import_child_process = require("child_process");
4158
4215
  var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
4159
- var UPSTREAM_BRANCH = "develop";
4216
+ var UPSTREAM_BRANCH = "release-v2.0.0";
4160
4217
  var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
4161
4218
  var FILES_TO_CHECKOUT = [
4162
4219
  "src/analytics/analytics.ts",
@@ -4706,9 +4763,13 @@ function gitShowBytes(ref, path23) {
4706
4763
  return null;
4707
4764
  }
4708
4765
  }
4709
- async function main25() {
4766
+ async function main25({
4767
+ subdirs = []
4768
+ } = {}) {
4769
+ const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
4770
+ const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
4710
4771
  console.log(
4711
- `Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4772
+ `Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4712
4773
  `
4713
4774
  );
4714
4775
  assertIsGitRepo();
@@ -4723,20 +4784,12 @@ async function main25() {
4723
4784
  const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
4724
4785
  const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
4725
4786
  const upstreamFiles = runGit(
4726
- [
4727
- "ls-tree",
4728
- "-r",
4729
- "--name-only",
4730
- "-z",
4731
- ref,
4732
- "--",
4733
- `${INFRASTRUCTURE_DIR}/`
4734
- ],
4787
+ ["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
4735
4788
  { silent: true }
4736
4789
  ).split("\0").filter(Boolean);
4737
4790
  if (upstreamFiles.length === 0) {
4738
4791
  console.log(
4739
- ` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
4792
+ ` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
4740
4793
  );
4741
4794
  return;
4742
4795
  }
@@ -4811,7 +4864,9 @@ async function main25() {
4811
4864
  var import_fs6 = require("fs");
4812
4865
  var import_path25 = require("path");
4813
4866
  var INFRASTRUCTURE_DIR2 = "infrastructure";
4814
- async function main26() {
4867
+ async function main26({
4868
+ keep = []
4869
+ } = {}) {
4815
4870
  const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
4816
4871
  if (!(0, import_fs6.existsSync)(fullPath)) {
4817
4872
  console.log(
@@ -4819,24 +4874,64 @@ async function main26() {
4819
4874
  );
4820
4875
  return;
4821
4876
  }
4822
- console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4823
- `);
4824
4877
  assertIsGitRepo();
4825
- runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4826
- silent: true
4827
- });
4828
- console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4829
- if ((0, import_fs6.existsSync)(fullPath)) {
4830
- (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4831
- console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4878
+ if (keep.length === 0) {
4879
+ console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4880
+ `);
4881
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4882
+ silent: true
4883
+ });
4884
+ console.log(
4885
+ ` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
4886
+ );
4887
+ if ((0, import_fs6.existsSync)(fullPath)) {
4888
+ (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4889
+ console.log(
4890
+ ` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
4891
+ );
4892
+ }
4893
+ console.log(
4894
+ `
4895
+ Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4896
+ );
4897
+ return;
4898
+ }
4899
+ const keepSet = new Set(keep);
4900
+ console.log(
4901
+ `Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
4902
+ `
4903
+ );
4904
+ const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
4905
+ let deleted = 0;
4906
+ for (const entry of topLevelEntries) {
4907
+ if (keepSet.has(entry.name)) {
4908
+ console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
4909
+ continue;
4910
+ }
4911
+ const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
4912
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
4913
+ const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
4914
+ if ((0, import_fs6.existsSync)(fullEntryPath)) {
4915
+ (0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
4916
+ }
4917
+ console.log(` Deleted '${relPath}'.`);
4918
+ deleted++;
4919
+ }
4920
+ const presentNames = new Set(topLevelEntries.map((e) => e.name));
4921
+ const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
4922
+ if (missingKeeps.length > 0) {
4923
+ console.warn(
4924
+ ` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
4925
+ );
4832
4926
  }
4833
4927
  console.log(
4834
4928
  `
4835
- Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4929
+ Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4836
4930
  );
4837
4931
  }
4838
4932
 
4839
4933
  // src/migrations/v2.0/index.ts
4934
+ var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
4840
4935
  async function runUpgrade(dockerSwarm) {
4841
4936
  await main18();
4842
4937
  await main();
@@ -4865,7 +4960,8 @@ async function runUpgrade(dockerSwarm) {
4865
4960
  if (dockerSwarm) {
4866
4961
  await main25();
4867
4962
  } else {
4868
- await main26();
4963
+ await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
4964
+ await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
4869
4965
  }
4870
4966
  }
4871
4967