@opencrvs/toolkit 2.0.0-rc.2625051 → 2.0.0-rc.2e68bac
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/application-config/index.js +4 -4
- package/dist/cli.js +1417 -167
- package/dist/commons/api/router.d.ts +55 -54
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +17 -13
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
- package/dist/migrations/v2.0/create-events-index.js +1 -2
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
- package/dist/migrations/v2.0/index.d.ts +8 -4
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +1385 -164
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +5 -6
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +6 -7
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +3 -4
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-api-paths.js +3 -4
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
- package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
- package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
- package/dist/migrations/v2.0/update-package-json.js +105 -0
- package/opencrvs-toolkit-2.0.0-rc.2e68bac.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.2625051.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -91,7 +91,7 @@ function processFile(filePath, project) {
|
|
|
91
91
|
if (wasRemoved) {
|
|
92
92
|
removedCount++;
|
|
93
93
|
console.log(
|
|
94
|
-
` [${import_path.default.relative(
|
|
94
|
+
` [${import_path.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -99,7 +99,7 @@ function processFile(filePath, project) {
|
|
|
99
99
|
return removedCount;
|
|
100
100
|
}
|
|
101
101
|
async function main() {
|
|
102
|
-
const srcDir = import_path.default.join(
|
|
102
|
+
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
103
103
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
104
104
|
`);
|
|
105
105
|
const project = new import_ts_morph.Project({
|
|
@@ -135,7 +135,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
135
135
|
for (const filePath of modifiedFiles) {
|
|
136
136
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
137
137
|
await sourceFile.save();
|
|
138
|
-
console.log(` Saved: ${import_path.default.relative(
|
|
138
|
+
console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
|
|
139
139
|
}
|
|
140
140
|
console.log(
|
|
141
141
|
`
|
|
@@ -338,7 +338,7 @@ function processFile2(filePath, project) {
|
|
|
338
338
|
const eventType = resolveEventType(configArg);
|
|
339
339
|
if (!eventType) {
|
|
340
340
|
console.warn(
|
|
341
|
-
` [${import_path2.default.relative(
|
|
341
|
+
` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
342
342
|
);
|
|
343
343
|
}
|
|
344
344
|
let fileNeedsImports = false;
|
|
@@ -354,7 +354,7 @@ function processFile2(filePath, project) {
|
|
|
354
354
|
fileNeedsImports = true;
|
|
355
355
|
configHadValidateAction = true;
|
|
356
356
|
console.log(
|
|
357
|
-
` [${import_path2.default.relative(
|
|
357
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
358
358
|
);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
@@ -375,7 +375,7 @@ function processFile2(filePath, project) {
|
|
|
375
375
|
]`
|
|
376
376
|
});
|
|
377
377
|
console.log(
|
|
378
|
-
` [${import_path2.default.relative(
|
|
378
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
379
379
|
);
|
|
380
380
|
}
|
|
381
381
|
if (fileNeedsImports) {
|
|
@@ -385,7 +385,7 @@ function processFile2(filePath, project) {
|
|
|
385
385
|
return transformedCount;
|
|
386
386
|
}
|
|
387
387
|
async function main2() {
|
|
388
|
-
const srcDir = import_path2.default.join(
|
|
388
|
+
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
389
389
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
390
390
|
`);
|
|
391
391
|
const project = new import_ts_morph2.Project({
|
|
@@ -420,7 +420,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
420
420
|
for (const filePath of modifiedFiles) {
|
|
421
421
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
422
422
|
await sourceFile.save();
|
|
423
|
-
console.log(` Saved: ${import_path2.default.relative(
|
|
423
|
+
console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
|
|
424
424
|
}
|
|
425
425
|
console.log(
|
|
426
426
|
`
|
|
@@ -491,14 +491,14 @@ function processFile3(filePath, project) {
|
|
|
491
491
|
actionsInitializer.removeElement(index);
|
|
492
492
|
removedCount++;
|
|
493
493
|
console.log(
|
|
494
|
-
` [${import_path3.default.relative(
|
|
494
|
+
` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
495
495
|
);
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
498
|
return removedCount;
|
|
499
499
|
}
|
|
500
500
|
async function main3() {
|
|
501
|
-
const srcDir = import_path3.default.join(
|
|
501
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
502
502
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
503
503
|
`);
|
|
504
504
|
const project = new import_ts_morph3.Project({
|
|
@@ -533,7 +533,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
533
533
|
for (const filePath of modifiedFiles) {
|
|
534
534
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
535
535
|
await sourceFile.save();
|
|
536
|
-
console.log(` Saved: ${import_path3.default.relative(
|
|
536
|
+
console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
|
|
537
537
|
}
|
|
538
538
|
console.log(
|
|
539
539
|
`
|
|
@@ -607,19 +607,19 @@ function processFile4(filePath, project) {
|
|
|
607
607
|
if (result === "converted-to-heading") {
|
|
608
608
|
changedCount++;
|
|
609
609
|
console.log(
|
|
610
|
-
` [${import_path4.default.relative(
|
|
610
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
611
611
|
);
|
|
612
612
|
} else if (result === "removed-font-variant") {
|
|
613
613
|
changedCount++;
|
|
614
614
|
console.log(
|
|
615
|
-
` [${import_path4.default.relative(
|
|
615
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
616
616
|
);
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
return changedCount;
|
|
620
620
|
}
|
|
621
621
|
async function main4() {
|
|
622
|
-
const srcDir = import_path4.default.join(
|
|
622
|
+
const srcDir = import_path4.default.join(process.cwd(), "src");
|
|
623
623
|
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
624
624
|
`);
|
|
625
625
|
const project = new import_ts_morph4.Project({
|
|
@@ -653,7 +653,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
653
653
|
for (const filePath of modifiedFiles) {
|
|
654
654
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
655
655
|
await sourceFile.save();
|
|
656
|
-
console.log(` Saved: ${import_path4.default.relative(
|
|
656
|
+
console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
|
|
657
657
|
}
|
|
658
658
|
console.log(`
|
|
659
659
|
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
@@ -803,7 +803,7 @@ function processFile5(filePath, project) {
|
|
|
803
803
|
if (changed > 0) {
|
|
804
804
|
migratedCount += changed;
|
|
805
805
|
console.log(
|
|
806
|
-
` [${import_path5.default.relative(
|
|
806
|
+
` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
807
807
|
);
|
|
808
808
|
}
|
|
809
809
|
}
|
|
@@ -811,7 +811,7 @@ function processFile5(filePath, project) {
|
|
|
811
811
|
return migratedCount;
|
|
812
812
|
}
|
|
813
813
|
async function main5() {
|
|
814
|
-
const srcDir = import_path5.default.join(
|
|
814
|
+
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
815
815
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
816
816
|
`);
|
|
817
817
|
const project = new import_ts_morph5.Project({
|
|
@@ -845,7 +845,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
845
845
|
for (const filePath of modifiedFiles) {
|
|
846
846
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
847
847
|
await sourceFile.save();
|
|
848
|
-
console.log(` Saved: ${import_path5.default.relative(
|
|
848
|
+
console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
|
|
849
849
|
}
|
|
850
850
|
console.log(
|
|
851
851
|
`
|
|
@@ -863,20 +863,23 @@ var ACTION_PROPERTY_NAME = "action";
|
|
|
863
863
|
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
864
864
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
865
865
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
866
|
+
var ID_PROPERTY_NAME = "id";
|
|
866
867
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
867
868
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
868
869
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
869
870
|
var REGISTER_TYPE = "REGISTER";
|
|
870
871
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
871
|
-
|
|
872
|
+
function flagDefinitionInitializer(eventType) {
|
|
873
|
+
return `{
|
|
872
874
|
id: '${FLAG_ID}',
|
|
873
875
|
label: {
|
|
874
|
-
id: 'event.
|
|
876
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
875
877
|
defaultMessage: 'Pending first certificate issuance',
|
|
876
878
|
description: 'Flag label for first certificate issuance'
|
|
877
879
|
},
|
|
878
880
|
requiresAction: true
|
|
879
881
|
}`;
|
|
882
|
+
}
|
|
880
883
|
function isActionOfType(obj, typeName) {
|
|
881
884
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
882
885
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -890,18 +893,20 @@ function isActionOfType(obj, typeName) {
|
|
|
890
893
|
}
|
|
891
894
|
return false;
|
|
892
895
|
}
|
|
893
|
-
function
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
896
|
+
function getEventType(configArg) {
|
|
897
|
+
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME]) {
|
|
898
|
+
const prop = configArg.getProperty(propName);
|
|
899
|
+
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
900
|
+
const initializer = prop.getInitializer();
|
|
901
|
+
if (!initializer) continue;
|
|
902
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
903
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
904
|
+
}
|
|
905
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
906
|
+
return initializer.getName().toLowerCase();
|
|
907
|
+
}
|
|
903
908
|
}
|
|
904
|
-
return
|
|
909
|
+
return null;
|
|
905
910
|
}
|
|
906
911
|
function hasElementWithId(array3, id) {
|
|
907
912
|
for (const el of array3.getElements()) {
|
|
@@ -915,13 +920,14 @@ function hasElementWithId(array3, id) {
|
|
|
915
920
|
}
|
|
916
921
|
return false;
|
|
917
922
|
}
|
|
918
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
923
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
924
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
919
925
|
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME2);
|
|
920
926
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
921
927
|
const flagsInit = flagsProp.getInitializer();
|
|
922
928
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
923
929
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
924
|
-
flagsInit.addElement(
|
|
930
|
+
flagsInit.addElement(initializer);
|
|
925
931
|
return true;
|
|
926
932
|
}
|
|
927
933
|
return false;
|
|
@@ -929,7 +935,7 @@ function ensureTopLevelFlagDefinition(configArg) {
|
|
|
929
935
|
configArg.addPropertyAssignment({
|
|
930
936
|
name: FLAGS_PROPERTY_NAME2,
|
|
931
937
|
initializer: `[
|
|
932
|
-
${
|
|
938
|
+
${initializer}
|
|
933
939
|
]`
|
|
934
940
|
});
|
|
935
941
|
return true;
|
|
@@ -952,11 +958,13 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
952
958
|
});
|
|
953
959
|
return true;
|
|
954
960
|
}
|
|
955
|
-
function
|
|
961
|
+
function processConfig(configArg, eventType, relPath) {
|
|
956
962
|
let changes = 0;
|
|
957
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
963
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
958
964
|
changes++;
|
|
959
|
-
console.log(
|
|
965
|
+
console.log(
|
|
966
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
967
|
+
);
|
|
960
968
|
}
|
|
961
969
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
962
970
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -970,7 +978,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
970
978
|
if (ensureActionOperationFlag(element, "add")) {
|
|
971
979
|
changes++;
|
|
972
980
|
console.log(
|
|
973
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
981
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
974
982
|
);
|
|
975
983
|
}
|
|
976
984
|
}
|
|
@@ -978,7 +986,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
978
986
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
979
987
|
changes++;
|
|
980
988
|
console.log(
|
|
981
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
989
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
982
990
|
);
|
|
983
991
|
}
|
|
984
992
|
}
|
|
@@ -1063,7 +1071,7 @@ function processFile6(filePath, project) {
|
|
|
1063
1071
|
const sourceFile = project.getSourceFile(filePath);
|
|
1064
1072
|
if (!sourceFile) return 0;
|
|
1065
1073
|
let totalChanges = 0;
|
|
1066
|
-
const relPath = import_path6.default.relative(
|
|
1074
|
+
const relPath = import_path6.default.relative(process.cwd(), filePath);
|
|
1067
1075
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1068
1076
|
import_ts_morph6.SyntaxKind.CallExpression
|
|
1069
1077
|
);
|
|
@@ -1076,8 +1084,9 @@ function processFile6(filePath, project) {
|
|
|
1076
1084
|
if (args2.length === 0) continue;
|
|
1077
1085
|
const configArg = args2[0];
|
|
1078
1086
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1079
|
-
|
|
1080
|
-
|
|
1087
|
+
const eventType = getEventType(configArg);
|
|
1088
|
+
if (!eventType) continue;
|
|
1089
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1081
1090
|
}
|
|
1082
1091
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1083
1092
|
const args2 = call.getArguments();
|
|
@@ -1104,9 +1113,9 @@ function processFile6(filePath, project) {
|
|
|
1104
1113
|
return totalChanges;
|
|
1105
1114
|
}
|
|
1106
1115
|
async function main6() {
|
|
1107
|
-
const srcDir = import_path6.default.join(
|
|
1116
|
+
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1108
1117
|
console.log(
|
|
1109
|
-
`Scanning for
|
|
1118
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1110
1119
|
`
|
|
1111
1120
|
);
|
|
1112
1121
|
const project = new import_ts_morph6.Project({
|
|
@@ -1131,7 +1140,7 @@ async function main6() {
|
|
|
1131
1140
|
}
|
|
1132
1141
|
if (modifiedFiles.length === 0) {
|
|
1133
1142
|
console.log(
|
|
1134
|
-
"No
|
|
1143
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1135
1144
|
);
|
|
1136
1145
|
return;
|
|
1137
1146
|
}
|
|
@@ -1140,7 +1149,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1140
1149
|
for (const filePath of modifiedFiles) {
|
|
1141
1150
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1142
1151
|
await sourceFile.save();
|
|
1143
|
-
console.log(` Saved: ${import_path6.default.relative(
|
|
1152
|
+
console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
|
|
1144
1153
|
}
|
|
1145
1154
|
console.log(
|
|
1146
1155
|
`
|
|
@@ -1177,14 +1186,14 @@ function processFile7(filePath, project) {
|
|
|
1177
1186
|
array3.removeElement(index);
|
|
1178
1187
|
removedCount++;
|
|
1179
1188
|
console.log(
|
|
1180
|
-
` [${import_path7.default.relative(
|
|
1189
|
+
` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1181
1190
|
);
|
|
1182
1191
|
}
|
|
1183
1192
|
}
|
|
1184
1193
|
return removedCount;
|
|
1185
1194
|
}
|
|
1186
1195
|
async function main7() {
|
|
1187
|
-
const srcDir = import_path7.default.join(
|
|
1196
|
+
const srcDir = import_path7.default.join(process.cwd(), "src");
|
|
1188
1197
|
console.log(
|
|
1189
1198
|
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1190
1199
|
`
|
|
@@ -1220,7 +1229,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1220
1229
|
for (const filePath of modifiedFiles) {
|
|
1221
1230
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1222
1231
|
await sourceFile.save();
|
|
1223
|
-
console.log(` Saved: ${import_path7.default.relative(
|
|
1232
|
+
console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
|
|
1224
1233
|
}
|
|
1225
1234
|
console.log(
|
|
1226
1235
|
`
|
|
@@ -1278,13 +1287,13 @@ function processFile8(filePath, project) {
|
|
|
1278
1287
|
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1279
1288
|
renamedCount++;
|
|
1280
1289
|
console.log(
|
|
1281
|
-
` [${import_path8.default.relative(
|
|
1290
|
+
` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1282
1291
|
);
|
|
1283
1292
|
}
|
|
1284
1293
|
return renamedCount;
|
|
1285
1294
|
}
|
|
1286
1295
|
async function main8() {
|
|
1287
|
-
const srcDir = import_path8.default.join(
|
|
1296
|
+
const srcDir = import_path8.default.join(process.cwd(), "src");
|
|
1288
1297
|
console.log(
|
|
1289
1298
|
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1290
1299
|
`
|
|
@@ -1320,7 +1329,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1320
1329
|
for (const filePath of modifiedFiles) {
|
|
1321
1330
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1322
1331
|
await sourceFile.save();
|
|
1323
|
-
console.log(` Saved: ${import_path8.default.relative(
|
|
1332
|
+
console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
|
|
1324
1333
|
}
|
|
1325
1334
|
console.log(
|
|
1326
1335
|
`
|
|
@@ -1387,7 +1396,7 @@ function processFile9(filePath, project) {
|
|
|
1387
1396
|
const sourceFile = project.getSourceFile(filePath);
|
|
1388
1397
|
if (!sourceFile) return 0;
|
|
1389
1398
|
let renamedCount = 0;
|
|
1390
|
-
const relPath = import_path9.default.relative(
|
|
1399
|
+
const relPath = import_path9.default.relative(process.cwd(), filePath);
|
|
1391
1400
|
const candidates = sourceFile.getDescendantsOfKind(
|
|
1392
1401
|
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1393
1402
|
);
|
|
@@ -1402,7 +1411,7 @@ function processFile9(filePath, project) {
|
|
|
1402
1411
|
return renamedCount;
|
|
1403
1412
|
}
|
|
1404
1413
|
async function main9() {
|
|
1405
|
-
const srcDir = import_path9.default.join(
|
|
1414
|
+
const srcDir = import_path9.default.join(process.cwd(), "src");
|
|
1406
1415
|
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1407
1416
|
`);
|
|
1408
1417
|
console.log("Active path renames:");
|
|
@@ -1439,7 +1448,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1439
1448
|
for (const filePath of modifiedFiles) {
|
|
1440
1449
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1441
1450
|
await sourceFile.save();
|
|
1442
|
-
console.log(` Saved: ${import_path9.default.relative(
|
|
1451
|
+
console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
|
|
1443
1452
|
}
|
|
1444
1453
|
console.log(`
|
|
1445
1454
|
Done. Renamed ${totalRenamed} route path(s).`);
|
|
@@ -1813,9 +1822,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1813
1822
|
}
|
|
1814
1823
|
return replacedCount;
|
|
1815
1824
|
}
|
|
1816
|
-
function resolveConfigChain(configObj,
|
|
1825
|
+
function resolveConfigChain(configObj, path23) {
|
|
1817
1826
|
let current = configObj;
|
|
1818
|
-
for (const key of
|
|
1827
|
+
for (const key of path23) {
|
|
1819
1828
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1820
1829
|
const prop = current.getProperty(key);
|
|
1821
1830
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1860,8 +1869,8 @@ function ensureJoinImport(sf) {
|
|
|
1860
1869
|
});
|
|
1861
1870
|
}
|
|
1862
1871
|
async function main10() {
|
|
1863
|
-
const srcDir = import_path10.default.join(
|
|
1864
|
-
const relCwd = (fp) => import_path10.default.relative(
|
|
1872
|
+
const srcDir = import_path10.default.join(process.cwd(), "src");
|
|
1873
|
+
const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
|
|
1865
1874
|
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1866
1875
|
let convertedCount = 0;
|
|
1867
1876
|
for (const group of CONFIG_GROUPS) {
|
|
@@ -1949,7 +1958,7 @@ async function main10() {
|
|
|
1949
1958
|
ensureJoinImport(sf);
|
|
1950
1959
|
}
|
|
1951
1960
|
console.log(
|
|
1952
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(
|
|
1961
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1953
1962
|
);
|
|
1954
1963
|
filesToSaveAfterInlining.add(sf);
|
|
1955
1964
|
madeReplacement = true;
|
|
@@ -1961,7 +1970,7 @@ async function main10() {
|
|
|
1961
1970
|
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
1962
1971
|
await sf.save();
|
|
1963
1972
|
console.log(
|
|
1964
|
-
` Saved (inlined): ${import_path10.default.relative(
|
|
1973
|
+
` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1965
1974
|
);
|
|
1966
1975
|
}
|
|
1967
1976
|
for (const prop of [...propsToRemove].reverse()) {
|
|
@@ -2606,7 +2615,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2606
2615
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2607
2616
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2608
2617
|
console.warn(
|
|
2609
|
-
` [${import_path11.default.relative(
|
|
2618
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2610
2619
|
);
|
|
2611
2620
|
initializer.removeElement(index);
|
|
2612
2621
|
removedCount++;
|
|
@@ -2615,7 +2624,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2615
2624
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2616
2625
|
if (!legacyScope) {
|
|
2617
2626
|
console.warn(
|
|
2618
|
-
` [${import_path11.default.relative(
|
|
2627
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2619
2628
|
);
|
|
2620
2629
|
continue;
|
|
2621
2630
|
}
|
|
@@ -2624,7 +2633,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2624
2633
|
const scope = decodeScope(migratedScope);
|
|
2625
2634
|
if (!scope) {
|
|
2626
2635
|
console.warn(
|
|
2627
|
-
` [${import_path11.default.relative(
|
|
2636
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2628
2637
|
);
|
|
2629
2638
|
continue;
|
|
2630
2639
|
}
|
|
@@ -2632,14 +2641,14 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2632
2641
|
migratedCount++;
|
|
2633
2642
|
} catch (error) {
|
|
2634
2643
|
console.warn(
|
|
2635
|
-
` [${import_path11.default.relative(
|
|
2644
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2636
2645
|
);
|
|
2637
2646
|
}
|
|
2638
2647
|
}
|
|
2639
2648
|
}
|
|
2640
2649
|
if (removedCount > 0) {
|
|
2641
2650
|
console.log(
|
|
2642
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(
|
|
2651
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
|
|
2643
2652
|
);
|
|
2644
2653
|
}
|
|
2645
2654
|
return { migratedCount, removedCount };
|
|
@@ -2761,9 +2770,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
|
2761
2770
|
return removed;
|
|
2762
2771
|
}
|
|
2763
2772
|
async function main11() {
|
|
2764
|
-
const
|
|
2765
|
-
const srcDir = import_path11.default.join(
|
|
2766
|
-
const rolesFilePath = import_path11.default.join(
|
|
2773
|
+
const cwd = process.cwd();
|
|
2774
|
+
const srcDir = import_path11.default.join(cwd, "src");
|
|
2775
|
+
const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
|
|
2767
2776
|
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2768
2777
|
const project = new import_ts_morph11.Project({
|
|
2769
2778
|
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -2827,13 +2836,13 @@ function processFile10(filePath, project) {
|
|
|
2827
2836
|
decl.remove();
|
|
2828
2837
|
}
|
|
2829
2838
|
console.log(
|
|
2830
|
-
` [${import_path12.default.relative(
|
|
2839
|
+
` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2831
2840
|
);
|
|
2832
2841
|
}
|
|
2833
2842
|
return removedCount;
|
|
2834
2843
|
}
|
|
2835
2844
|
async function main12() {
|
|
2836
|
-
const srcDir = import_path12.default.join(
|
|
2845
|
+
const srcDir = import_path12.default.join(process.cwd(), "src");
|
|
2837
2846
|
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2838
2847
|
`);
|
|
2839
2848
|
const project = new import_ts_morph12.Project({
|
|
@@ -2864,15 +2873,738 @@ async function main12() {
|
|
|
2864
2873
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2865
2874
|
for (const filePath of modifiedFiles) {
|
|
2866
2875
|
await project.getSourceFileOrThrow(filePath).save();
|
|
2867
|
-
console.log(` Saved: ${import_path12.default.relative(
|
|
2876
|
+
console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
|
|
2868
2877
|
}
|
|
2869
2878
|
console.log(`
|
|
2870
2879
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2871
2880
|
}
|
|
2872
2881
|
|
|
2873
|
-
// src/migrations/v2.0/
|
|
2874
|
-
var import_ts_morph13 = require("ts-morph");
|
|
2882
|
+
// src/migrations/v2.0/remove-unused-environment-variables.ts
|
|
2875
2883
|
var import_path13 = __toESM(require("path"));
|
|
2884
|
+
var import_ts_morph13 = require("ts-morph");
|
|
2885
|
+
var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
|
|
2886
|
+
"APPLICATION_CONFIG_URL",
|
|
2887
|
+
"FHIR_URL",
|
|
2888
|
+
"CONFIRM_REGISTRATION_URL"
|
|
2889
|
+
]);
|
|
2890
|
+
var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
|
|
2891
|
+
var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
|
|
2892
|
+
function cleanEnvironmentFile(project, filePath) {
|
|
2893
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2894
|
+
if (!sourceFile) return [];
|
|
2895
|
+
const removed = [];
|
|
2896
|
+
const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
|
|
2897
|
+
const expr = call.getExpression();
|
|
2898
|
+
return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
|
|
2899
|
+
});
|
|
2900
|
+
if (!cleanEnvCall) return removed;
|
|
2901
|
+
const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
|
|
2902
|
+
if (!schemaArg) return removed;
|
|
2903
|
+
for (const name of UNUSED_ENV_VARS) {
|
|
2904
|
+
const prop = schemaArg.getProperty(name);
|
|
2905
|
+
if (!prop) continue;
|
|
2906
|
+
if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
2907
|
+
prop.remove();
|
|
2908
|
+
removed.push(name);
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
return removed;
|
|
2912
|
+
}
|
|
2913
|
+
function extractEnvAccess(initText) {
|
|
2914
|
+
if (!initText) return null;
|
|
2915
|
+
const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
|
|
2916
|
+
return match ? match[1] : null;
|
|
2917
|
+
}
|
|
2918
|
+
function cleanConstantsFile(project, filePath) {
|
|
2919
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2920
|
+
if (!sourceFile) return [];
|
|
2921
|
+
const removed = [];
|
|
2922
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2923
|
+
const declarations = [...stmt.getDeclarations()];
|
|
2924
|
+
const declarationsToRemove = declarations.filter((decl) => {
|
|
2925
|
+
const name = decl.getName();
|
|
2926
|
+
const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
|
|
2927
|
+
return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
|
|
2928
|
+
});
|
|
2929
|
+
if (declarationsToRemove.length === 0) continue;
|
|
2930
|
+
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
2931
|
+
removed.push(...namesToRemove);
|
|
2932
|
+
if (declarationsToRemove.length === declarations.length) {
|
|
2933
|
+
stmt.remove();
|
|
2934
|
+
} else {
|
|
2935
|
+
for (const decl of declarationsToRemove) {
|
|
2936
|
+
decl.remove();
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
return removed;
|
|
2941
|
+
}
|
|
2942
|
+
async function main13() {
|
|
2943
|
+
const project = new import_ts_morph13.Project({
|
|
2944
|
+
tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
|
|
2945
|
+
skipAddingFilesFromTsConfig: false
|
|
2946
|
+
});
|
|
2947
|
+
console.log(
|
|
2948
|
+
`Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
|
|
2949
|
+
`
|
|
2950
|
+
);
|
|
2951
|
+
const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
|
|
2952
|
+
const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
|
|
2953
|
+
const envRemoved = cleanEnvironmentFile(project, envFilePath);
|
|
2954
|
+
if (envRemoved.length > 0) {
|
|
2955
|
+
await project.getSourceFileOrThrow(envFilePath).save();
|
|
2956
|
+
console.log(
|
|
2957
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
|
|
2958
|
+
);
|
|
2959
|
+
} else if (project.getSourceFile(envFilePath)) {
|
|
2960
|
+
console.log(
|
|
2961
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
|
|
2962
|
+
);
|
|
2963
|
+
} else {
|
|
2964
|
+
console.log(
|
|
2965
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
|
|
2966
|
+
);
|
|
2967
|
+
}
|
|
2968
|
+
const constsRemoved = cleanConstantsFile(project, constsFilePath);
|
|
2969
|
+
if (constsRemoved.length > 0) {
|
|
2970
|
+
await project.getSourceFileOrThrow(constsFilePath).save();
|
|
2971
|
+
console.log(
|
|
2972
|
+
` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
|
|
2973
|
+
);
|
|
2974
|
+
} else if (project.getSourceFile(constsFilePath)) {
|
|
2975
|
+
console.log(
|
|
2976
|
+
` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
|
|
2977
|
+
);
|
|
2978
|
+
} else {
|
|
2979
|
+
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
|
|
2980
|
+
}
|
|
2981
|
+
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
2982
|
+
console.log("\nNothing to do.");
|
|
2983
|
+
return;
|
|
2984
|
+
}
|
|
2985
|
+
console.log(
|
|
2986
|
+
`
|
|
2987
|
+
Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
|
|
2988
|
+
);
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
// src/migrations/v2.0/remove-fhir-url-helpers.ts
|
|
2992
|
+
var import_path14 = __toESM(require("path"));
|
|
2993
|
+
var import_ts_morph14 = require("ts-morph");
|
|
2994
|
+
var FHIR_IMPORT = "FHIR_URL";
|
|
2995
|
+
var HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
2996
|
+
"getFromFhir",
|
|
2997
|
+
"updateResourceFromHearth",
|
|
2998
|
+
"updateResourceInHearth"
|
|
2999
|
+
]);
|
|
3000
|
+
function removeHelpers(sourceFilePath, project) {
|
|
3001
|
+
const sourceFile = project.getSourceFile(sourceFilePath);
|
|
3002
|
+
if (!sourceFile) {
|
|
3003
|
+
return {
|
|
3004
|
+
removedHelpers: [],
|
|
3005
|
+
removedImportCount: 0,
|
|
3006
|
+
remainingFhirReferences: 0
|
|
3007
|
+
};
|
|
3008
|
+
}
|
|
3009
|
+
const removedHelpers = [];
|
|
3010
|
+
let removedImportCount = 0;
|
|
3011
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
3012
|
+
const name = fn.getName();
|
|
3013
|
+
if (!name || !HELPER_NAMES.has(name)) continue;
|
|
3014
|
+
removedHelpers.push(name);
|
|
3015
|
+
fn.remove();
|
|
3016
|
+
}
|
|
3017
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
3018
|
+
const declarations = [...stmt.getDeclarations()];
|
|
3019
|
+
const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
|
|
3020
|
+
if (toRemove.length === 0) continue;
|
|
3021
|
+
removedHelpers.push(...toRemove.map((decl) => decl.getName()));
|
|
3022
|
+
if (toRemove.length === declarations.length) {
|
|
3023
|
+
stmt.remove();
|
|
3024
|
+
} else {
|
|
3025
|
+
for (const decl of toRemove) decl.remove();
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3029
|
+
const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
|
|
3030
|
+
if (matches.length === 0) continue;
|
|
3031
|
+
for (const named of matches) {
|
|
3032
|
+
named.remove();
|
|
3033
|
+
removedImportCount++;
|
|
3034
|
+
}
|
|
3035
|
+
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
3036
|
+
const hasDefaultImport = !!decl.getDefaultImport();
|
|
3037
|
+
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
3038
|
+
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
3039
|
+
decl.remove();
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
const remainingFhirReferences = sourceFile.getDescendantsOfKind(import_ts_morph14.SyntaxKind.Identifier).filter((id) => id.getText() === FHIR_IMPORT).filter((id) => !id.getFirstAncestorByKind(import_ts_morph14.SyntaxKind.ImportDeclaration)).length;
|
|
3043
|
+
return { removedHelpers, removedImportCount, remainingFhirReferences };
|
|
3044
|
+
}
|
|
3045
|
+
async function main14() {
|
|
3046
|
+
const project = new import_ts_morph14.Project({
|
|
3047
|
+
tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3048
|
+
skipAddingFilesFromTsConfig: false
|
|
3049
|
+
});
|
|
3050
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3051
|
+
const fp = sf.getFilePath();
|
|
3052
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3053
|
+
});
|
|
3054
|
+
console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
|
|
3055
|
+
`);
|
|
3056
|
+
let totalRemovedImports = 0;
|
|
3057
|
+
let totalRemovedHelpers = 0;
|
|
3058
|
+
const modifiedFiles = [];
|
|
3059
|
+
const warnings = [];
|
|
3060
|
+
for (const sourceFile of sourceFiles) {
|
|
3061
|
+
const filePath = sourceFile.getFilePath();
|
|
3062
|
+
const rel = import_path14.default.relative(process.cwd(), filePath);
|
|
3063
|
+
const result = removeHelpers(filePath, project);
|
|
3064
|
+
const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
|
|
3065
|
+
if (changed) {
|
|
3066
|
+
modifiedFiles.push(filePath);
|
|
3067
|
+
totalRemovedImports += result.removedImportCount;
|
|
3068
|
+
totalRemovedHelpers += result.removedHelpers.length;
|
|
3069
|
+
if (result.removedHelpers.length > 0) {
|
|
3070
|
+
console.log(
|
|
3071
|
+
` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
|
|
3072
|
+
);
|
|
3073
|
+
}
|
|
3074
|
+
if (result.removedImportCount > 0) {
|
|
3075
|
+
console.log(
|
|
3076
|
+
` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
|
|
3077
|
+
);
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
if (result.remainingFhirReferences > 0) {
|
|
3081
|
+
warnings.push(
|
|
3082
|
+
`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
|
|
3083
|
+
);
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
if (modifiedFiles.length === 0 && warnings.length === 0) {
|
|
3087
|
+
console.log("No FHIR_URL imports/helpers found. Nothing to do.");
|
|
3088
|
+
return;
|
|
3089
|
+
}
|
|
3090
|
+
if (modifiedFiles.length > 0) {
|
|
3091
|
+
console.log(`
|
|
3092
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3093
|
+
for (const filePath of modifiedFiles) {
|
|
3094
|
+
await project.getSourceFileOrThrow(filePath).save();
|
|
3095
|
+
console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
if (warnings.length > 0) {
|
|
3099
|
+
console.warn(
|
|
3100
|
+
`
|
|
3101
|
+
WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
|
|
3102
|
+
` + warnings.map((line) => ` - ${line}`).join("\n")
|
|
3103
|
+
);
|
|
3104
|
+
}
|
|
3105
|
+
console.log(
|
|
3106
|
+
`
|
|
3107
|
+
Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
|
|
3108
|
+
);
|
|
3109
|
+
}
|
|
3110
|
+
|
|
3111
|
+
// src/migrations/v2.0/migrate-application-config-url.ts
|
|
3112
|
+
var import_path15 = __toESM(require("path"));
|
|
3113
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3114
|
+
var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
|
|
3115
|
+
var REPLACEMENT_IDENTIFIER = "applicationConfig";
|
|
3116
|
+
var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
|
|
3117
|
+
var FUNCTION_LIKE_KINDS = [
|
|
3118
|
+
import_ts_morph15.SyntaxKind.FunctionDeclaration,
|
|
3119
|
+
import_ts_morph15.SyntaxKind.FunctionExpression,
|
|
3120
|
+
import_ts_morph15.SyntaxKind.ArrowFunction,
|
|
3121
|
+
import_ts_morph15.SyntaxKind.MethodDeclaration
|
|
3122
|
+
];
|
|
3123
|
+
function describeFunction(node) {
|
|
3124
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3125
|
+
return node.getName() ?? "<anonymous>";
|
|
3126
|
+
}
|
|
3127
|
+
const parent = node.getParent();
|
|
3128
|
+
if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
|
|
3129
|
+
return parent.getName();
|
|
3130
|
+
}
|
|
3131
|
+
if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
|
|
3132
|
+
return parent.getName();
|
|
3133
|
+
}
|
|
3134
|
+
if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
|
|
3135
|
+
return node.getNameNode()?.getText() ?? "<anonymous>";
|
|
3136
|
+
}
|
|
3137
|
+
return "<anonymous>";
|
|
3138
|
+
}
|
|
3139
|
+
function hasBlockBody(node) {
|
|
3140
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3141
|
+
return node.getBody() !== void 0;
|
|
3142
|
+
}
|
|
3143
|
+
if (import_ts_morph15.Node.isArrowFunction(node)) {
|
|
3144
|
+
return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
|
|
3145
|
+
}
|
|
3146
|
+
return false;
|
|
3147
|
+
}
|
|
3148
|
+
function isConfigFetcher(node) {
|
|
3149
|
+
let referencesTarget = false;
|
|
3150
|
+
let callsFetch = false;
|
|
3151
|
+
for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
|
|
3152
|
+
const text = id.getText();
|
|
3153
|
+
if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
|
|
3154
|
+
if (!callsFetch && text === "fetch") {
|
|
3155
|
+
const parent = id.getParent();
|
|
3156
|
+
if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
|
|
3157
|
+
callsFetch = true;
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
if (referencesTarget && callsFetch) return true;
|
|
3161
|
+
}
|
|
3162
|
+
return false;
|
|
3163
|
+
}
|
|
3164
|
+
function processFile11(sourceFile) {
|
|
3165
|
+
const importsWithTarget = sourceFile.getImportDeclarations().filter(
|
|
3166
|
+
(decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
|
|
3167
|
+
);
|
|
3168
|
+
if (importsWithTarget.length === 0) {
|
|
3169
|
+
return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
|
|
3170
|
+
}
|
|
3171
|
+
const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
|
|
3172
|
+
const parent = id.getParent();
|
|
3173
|
+
const kind = parent.getKind();
|
|
3174
|
+
return kind === import_ts_morph15.SyntaxKind.VariableDeclaration || kind === import_ts_morph15.SyntaxKind.FunctionDeclaration || kind === import_ts_morph15.SyntaxKind.ClassDeclaration || kind === import_ts_morph15.SyntaxKind.Parameter;
|
|
3175
|
+
});
|
|
3176
|
+
if (collidingLocals.length > 0) {
|
|
3177
|
+
return {
|
|
3178
|
+
changed: false,
|
|
3179
|
+
rewrittenFunctions: [],
|
|
3180
|
+
renamedReferences: 0,
|
|
3181
|
+
skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3184
|
+
const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
|
|
3185
|
+
(kind) => sourceFile.getDescendantsOfKind(kind)
|
|
3186
|
+
);
|
|
3187
|
+
candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
|
|
3188
|
+
const rewrittenFunctions = [];
|
|
3189
|
+
const rewrittenSet = /* @__PURE__ */ new Set();
|
|
3190
|
+
for (const fn of candidateFunctions) {
|
|
3191
|
+
if (!hasBlockBody(fn)) continue;
|
|
3192
|
+
if (!isConfigFetcher(fn)) continue;
|
|
3193
|
+
let inRewrittenAncestor = false;
|
|
3194
|
+
let cursor = fn.getParent();
|
|
3195
|
+
while (cursor) {
|
|
3196
|
+
if (rewrittenSet.has(cursor)) {
|
|
3197
|
+
inRewrittenAncestor = true;
|
|
3198
|
+
break;
|
|
3199
|
+
}
|
|
3200
|
+
cursor = cursor.getParent();
|
|
3201
|
+
}
|
|
3202
|
+
if (inRewrittenAncestor) continue;
|
|
3203
|
+
const start = fn.getStart();
|
|
3204
|
+
const line = sourceFile.getLineAndColumnAtPos(start).line;
|
|
3205
|
+
const name = describeFunction(fn);
|
|
3206
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(fn) || import_ts_morph15.Node.isFunctionExpression(fn) || import_ts_morph15.Node.isMethodDeclaration(fn) || import_ts_morph15.Node.isArrowFunction(fn)) {
|
|
3207
|
+
fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
|
|
3208
|
+
}
|
|
3209
|
+
rewrittenFunctions.push({ name, line });
|
|
3210
|
+
rewrittenSet.add(fn);
|
|
3211
|
+
}
|
|
3212
|
+
for (const decl of importsWithTarget) {
|
|
3213
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
|
|
3214
|
+
targetNamed?.remove();
|
|
3215
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3216
|
+
if (isNowEmpty) decl.remove();
|
|
3217
|
+
}
|
|
3218
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3219
|
+
(decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
|
|
3220
|
+
);
|
|
3221
|
+
if (existing) {
|
|
3222
|
+
const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
|
|
3223
|
+
if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
|
|
3224
|
+
} else {
|
|
3225
|
+
sourceFile.addImportDeclaration({
|
|
3226
|
+
moduleSpecifier: REPLACEMENT_MODULE,
|
|
3227
|
+
namedImports: [REPLACEMENT_IDENTIFIER]
|
|
3228
|
+
});
|
|
3229
|
+
}
|
|
3230
|
+
const renameTargets = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === TARGET_IDENTIFIER).filter((id) => !id.getFirstAncestorByKind(import_ts_morph15.SyntaxKind.ImportDeclaration)).filter((id) => {
|
|
3231
|
+
const parent = id.getParent();
|
|
3232
|
+
const parentKind = parent.getKind();
|
|
3233
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
|
|
3234
|
+
const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
|
|
3235
|
+
if (pae.getNameNode() === id) return false;
|
|
3236
|
+
}
|
|
3237
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
|
|
3238
|
+
const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
|
|
3239
|
+
if (pa.getNameNode() === id) return false;
|
|
3240
|
+
}
|
|
3241
|
+
if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
|
|
3242
|
+
return false;
|
|
3243
|
+
}
|
|
3244
|
+
return true;
|
|
3245
|
+
}).sort((a, b) => b.getPos() - a.getPos());
|
|
3246
|
+
for (const id of renameTargets) {
|
|
3247
|
+
id.replaceWithText(REPLACEMENT_IDENTIFIER);
|
|
3248
|
+
}
|
|
3249
|
+
return {
|
|
3250
|
+
changed: true,
|
|
3251
|
+
rewrittenFunctions,
|
|
3252
|
+
renamedReferences: renameTargets.length
|
|
3253
|
+
};
|
|
3254
|
+
}
|
|
3255
|
+
async function main15() {
|
|
3256
|
+
const project = new import_ts_morph15.Project({
|
|
3257
|
+
tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3258
|
+
skipAddingFilesFromTsConfig: false
|
|
3259
|
+
});
|
|
3260
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3261
|
+
const fp = sf.getFilePath();
|
|
3262
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3263
|
+
});
|
|
3264
|
+
console.log(
|
|
3265
|
+
`Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
|
|
3266
|
+
`
|
|
3267
|
+
);
|
|
3268
|
+
let changedFiles = 0;
|
|
3269
|
+
let totalRewrittenFunctions = 0;
|
|
3270
|
+
let totalRenamedReferences = 0;
|
|
3271
|
+
const skipped = [];
|
|
3272
|
+
for (const sourceFile of sourceFiles) {
|
|
3273
|
+
const filePath = sourceFile.getFilePath();
|
|
3274
|
+
const rel = import_path15.default.relative(process.cwd(), filePath);
|
|
3275
|
+
const result = processFile11(sourceFile);
|
|
3276
|
+
if (result.skippedReason) {
|
|
3277
|
+
skipped.push(`${rel} (${result.skippedReason})`);
|
|
3278
|
+
continue;
|
|
3279
|
+
}
|
|
3280
|
+
if (!result.changed) continue;
|
|
3281
|
+
await sourceFile.save();
|
|
3282
|
+
changedFiles++;
|
|
3283
|
+
totalRewrittenFunctions += result.rewrittenFunctions.length;
|
|
3284
|
+
totalRenamedReferences += result.renamedReferences;
|
|
3285
|
+
for (const fn of result.rewrittenFunctions) {
|
|
3286
|
+
console.log(
|
|
3287
|
+
` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
|
|
3288
|
+
);
|
|
3289
|
+
}
|
|
3290
|
+
if (result.renamedReferences > 0) {
|
|
3291
|
+
console.log(
|
|
3292
|
+
` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
|
|
3293
|
+
);
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
if (skipped.length > 0) {
|
|
3297
|
+
console.warn(
|
|
3298
|
+
`
|
|
3299
|
+
${skipped.length} file(s) skipped:
|
|
3300
|
+
` + skipped.map((s) => ` - ${s}`).join("\n")
|
|
3301
|
+
);
|
|
3302
|
+
}
|
|
3303
|
+
if (changedFiles === 0) {
|
|
3304
|
+
console.log(`
|
|
3305
|
+
No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
|
|
3306
|
+
return;
|
|
3307
|
+
}
|
|
3308
|
+
console.log(
|
|
3309
|
+
`
|
|
3310
|
+
Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
|
|
3311
|
+
);
|
|
3312
|
+
if (totalRewrittenFunctions > 0) {
|
|
3313
|
+
console.log(
|
|
3314
|
+
`NOTE: rewriting fetch functions discards any custom logic that lived inside them. Review the diff and re-apply any country-specific adjustments on top of '${REPLACEMENT_IDENTIFIER}'.`
|
|
3315
|
+
);
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3319
|
+
// src/migrations/v2.0/remove-old-statistics-service.ts
|
|
3320
|
+
var import_path16 = __toESM(require("path"));
|
|
3321
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3322
|
+
var ROUTE_PATH = "/statistics";
|
|
3323
|
+
var HANDLER_NAME = "statisticsHandler";
|
|
3324
|
+
function isStatisticsRouteObject(obj) {
|
|
3325
|
+
const pathProp = obj.getProperty("path");
|
|
3326
|
+
if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
|
|
3327
|
+
const init = pathProp.getInitializer();
|
|
3328
|
+
if (!init) return false;
|
|
3329
|
+
if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
3330
|
+
return init.getLiteralValue() === ROUTE_PATH;
|
|
3331
|
+
}
|
|
3332
|
+
return false;
|
|
3333
|
+
}
|
|
3334
|
+
function removeStatisticsRoutes(sourceFile) {
|
|
3335
|
+
let removed = 0;
|
|
3336
|
+
const callExpressions = [
|
|
3337
|
+
...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
|
|
3338
|
+
];
|
|
3339
|
+
for (const call of callExpressions) {
|
|
3340
|
+
if (call.wasForgotten()) continue;
|
|
3341
|
+
const expr = call.getExpression();
|
|
3342
|
+
if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
|
|
3343
|
+
if (expr.getName() !== "route") continue;
|
|
3344
|
+
const args2 = call.getArguments();
|
|
3345
|
+
if (args2.length === 0) continue;
|
|
3346
|
+
const firstArg = args2[0];
|
|
3347
|
+
if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
|
|
3348
|
+
if (!isStatisticsRouteObject(firstArg)) continue;
|
|
3349
|
+
const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
|
|
3350
|
+
if (stmt) {
|
|
3351
|
+
stmt.remove();
|
|
3352
|
+
removed++;
|
|
3353
|
+
} else {
|
|
3354
|
+
call.replaceWithText("");
|
|
3355
|
+
removed++;
|
|
3356
|
+
}
|
|
3357
|
+
continue;
|
|
3358
|
+
}
|
|
3359
|
+
if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
|
|
3360
|
+
const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
|
|
3361
|
+
({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
|
|
3362
|
+
).map(({ idx }) => idx);
|
|
3363
|
+
matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
|
|
3364
|
+
firstArg.removeElement(idx);
|
|
3365
|
+
removed++;
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
return removed;
|
|
3370
|
+
}
|
|
3371
|
+
function removeStatisticsHandlerImports(sourceFile) {
|
|
3372
|
+
let changed = false;
|
|
3373
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3374
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
|
|
3375
|
+
if (!targetNamed) continue;
|
|
3376
|
+
targetNamed.remove();
|
|
3377
|
+
changed = true;
|
|
3378
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3379
|
+
if (isNowEmpty) decl.remove();
|
|
3380
|
+
}
|
|
3381
|
+
return changed;
|
|
3382
|
+
}
|
|
3383
|
+
function processFile12(sourceFile) {
|
|
3384
|
+
const routesRemoved = removeStatisticsRoutes(sourceFile);
|
|
3385
|
+
const importsCleaned = removeStatisticsHandlerImports(sourceFile);
|
|
3386
|
+
return { routesRemoved, importsCleaned };
|
|
3387
|
+
}
|
|
3388
|
+
function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
|
|
3389
|
+
const result = [];
|
|
3390
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3391
|
+
const moduleSf = decl.getModuleSpecifierSourceFile();
|
|
3392
|
+
if (!moduleSf) continue;
|
|
3393
|
+
const fp = moduleSf.getFilePath();
|
|
3394
|
+
if (!fp.startsWith(subtreeRoot)) continue;
|
|
3395
|
+
result.push(fp);
|
|
3396
|
+
}
|
|
3397
|
+
return result;
|
|
3398
|
+
}
|
|
3399
|
+
function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
|
|
3400
|
+
const initialCandidates = collectLocalImportsInSubtree(
|
|
3401
|
+
startingFile,
|
|
3402
|
+
subtreeRoot
|
|
3403
|
+
);
|
|
3404
|
+
const startingPath = startingFile.getFilePath();
|
|
3405
|
+
const deleted = /* @__PURE__ */ new Set([startingPath]);
|
|
3406
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3407
|
+
const worklist = [...initialCandidates];
|
|
3408
|
+
const orphans = [];
|
|
3409
|
+
while (worklist.length > 0) {
|
|
3410
|
+
const candidate = worklist.shift();
|
|
3411
|
+
if (seen.has(candidate)) continue;
|
|
3412
|
+
seen.add(candidate);
|
|
3413
|
+
if (deleted.has(candidate)) continue;
|
|
3414
|
+
if (!candidate.startsWith(subtreeRoot)) continue;
|
|
3415
|
+
const candidateSf = project.getSourceFile(candidate);
|
|
3416
|
+
if (!candidateSf) continue;
|
|
3417
|
+
const stillImported = project.getSourceFiles().some((sf) => {
|
|
3418
|
+
const sfPath = sf.getFilePath();
|
|
3419
|
+
if (deleted.has(sfPath)) return false;
|
|
3420
|
+
if (sfPath === candidate) return false;
|
|
3421
|
+
return sf.getImportDeclarations().some(
|
|
3422
|
+
(decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
|
|
3423
|
+
);
|
|
3424
|
+
});
|
|
3425
|
+
if (stillImported) continue;
|
|
3426
|
+
const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
|
|
3427
|
+
worklist.push(...next);
|
|
3428
|
+
candidateSf.delete();
|
|
3429
|
+
deleted.add(candidate);
|
|
3430
|
+
orphans.push(candidate);
|
|
3431
|
+
}
|
|
3432
|
+
return orphans;
|
|
3433
|
+
}
|
|
3434
|
+
function processHandlerFile(project) {
|
|
3435
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3436
|
+
const fp = sf.getFilePath();
|
|
3437
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3438
|
+
});
|
|
3439
|
+
for (const sf of sourceFiles) {
|
|
3440
|
+
const fn = sf.getFunction(HANDLER_NAME);
|
|
3441
|
+
if (!fn) continue;
|
|
3442
|
+
const filePath = sf.getFilePath();
|
|
3443
|
+
const exportsByName = [...sf.getExportedDeclarations().keys()];
|
|
3444
|
+
const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
|
|
3445
|
+
if (otherExports.length === 0) {
|
|
3446
|
+
const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
|
|
3447
|
+
const orphansDeleted = deleteOrphanedDescendants(
|
|
3448
|
+
project,
|
|
3449
|
+
sf,
|
|
3450
|
+
subtreeRoot
|
|
3451
|
+
);
|
|
3452
|
+
sf.delete();
|
|
3453
|
+
return { filePath, action: "deleted", orphansDeleted };
|
|
3454
|
+
}
|
|
3455
|
+
fn.remove();
|
|
3456
|
+
return {
|
|
3457
|
+
filePath,
|
|
3458
|
+
action: "function-removed",
|
|
3459
|
+
remainingExports: otherExports,
|
|
3460
|
+
orphansDeleted: []
|
|
3461
|
+
};
|
|
3462
|
+
}
|
|
3463
|
+
return { filePath: "", action: "not-found", orphansDeleted: [] };
|
|
3464
|
+
}
|
|
3465
|
+
async function main16() {
|
|
3466
|
+
const project = new import_ts_morph16.Project({
|
|
3467
|
+
tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3468
|
+
skipAddingFilesFromTsConfig: false
|
|
3469
|
+
});
|
|
3470
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3471
|
+
const fp = sf.getFilePath();
|
|
3472
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3473
|
+
});
|
|
3474
|
+
console.log(
|
|
3475
|
+
`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
|
|
3476
|
+
`
|
|
3477
|
+
);
|
|
3478
|
+
let totalRoutesRemoved = 0;
|
|
3479
|
+
let totalFilesWithImportsCleaned = 0;
|
|
3480
|
+
let totalFilesWithRoutesRemoved = 0;
|
|
3481
|
+
for (const sourceFile of sourceFiles) {
|
|
3482
|
+
const filePath = sourceFile.getFilePath();
|
|
3483
|
+
const rel = import_path16.default.relative(process.cwd(), filePath);
|
|
3484
|
+
const result = processFile12(sourceFile);
|
|
3485
|
+
if (result.routesRemoved > 0) {
|
|
3486
|
+
console.log(
|
|
3487
|
+
` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
|
|
3488
|
+
);
|
|
3489
|
+
totalRoutesRemoved += result.routesRemoved;
|
|
3490
|
+
totalFilesWithRoutesRemoved++;
|
|
3491
|
+
}
|
|
3492
|
+
if (result.importsCleaned) {
|
|
3493
|
+
console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
|
|
3494
|
+
totalFilesWithImportsCleaned++;
|
|
3495
|
+
}
|
|
3496
|
+
if (result.routesRemoved > 0 || result.importsCleaned) {
|
|
3497
|
+
await sourceFile.save();
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
const handlerResult = processHandlerFile(project);
|
|
3501
|
+
switch (handlerResult.action) {
|
|
3502
|
+
case "deleted": {
|
|
3503
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3504
|
+
console.log(
|
|
3505
|
+
` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
|
|
3506
|
+
);
|
|
3507
|
+
for (const orphanPath of handlerResult.orphansDeleted) {
|
|
3508
|
+
const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
|
|
3509
|
+
console.log(
|
|
3510
|
+
` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
|
|
3511
|
+
);
|
|
3512
|
+
}
|
|
3513
|
+
await project.save();
|
|
3514
|
+
break;
|
|
3515
|
+
}
|
|
3516
|
+
case "function-removed": {
|
|
3517
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3518
|
+
console.warn(
|
|
3519
|
+
` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
|
|
3520
|
+
);
|
|
3521
|
+
const sf = project.getSourceFile(handlerResult.filePath);
|
|
3522
|
+
if (sf) await sf.save();
|
|
3523
|
+
break;
|
|
3524
|
+
}
|
|
3525
|
+
case "not-found":
|
|
3526
|
+
break;
|
|
3527
|
+
}
|
|
3528
|
+
if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
|
|
3529
|
+
console.log(`
|
|
3530
|
+
No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
|
|
3531
|
+
return;
|
|
3532
|
+
}
|
|
3533
|
+
const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
|
|
3534
|
+
console.log(
|
|
3535
|
+
`
|
|
3536
|
+
Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
|
|
3537
|
+
);
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3540
|
+
// src/migrations/v2.0/update-package-json.ts
|
|
3541
|
+
var import_fs = require("fs");
|
|
3542
|
+
var import_path17 = __toESM(require("path"));
|
|
3543
|
+
var PACKAGE_JSON_RELATIVE = "package.json";
|
|
3544
|
+
var TARGET_VERSION = "2.0.0";
|
|
3545
|
+
var TARGET_ZOD_RANGE = "^4.2.1";
|
|
3546
|
+
async function main17() {
|
|
3547
|
+
const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
|
|
3548
|
+
if (!(0, import_fs.existsSync)(packageJsonPath)) {
|
|
3549
|
+
console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
|
|
3550
|
+
return;
|
|
3551
|
+
}
|
|
3552
|
+
const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
|
|
3553
|
+
let parsed;
|
|
3554
|
+
try {
|
|
3555
|
+
parsed = JSON.parse(raw);
|
|
3556
|
+
} catch (error) {
|
|
3557
|
+
console.warn(
|
|
3558
|
+
` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
|
|
3559
|
+
);
|
|
3560
|
+
return;
|
|
3561
|
+
}
|
|
3562
|
+
console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
|
|
3563
|
+
const previousVersion = parsed.version;
|
|
3564
|
+
const versionChanged = previousVersion !== TARGET_VERSION;
|
|
3565
|
+
parsed.version = TARGET_VERSION;
|
|
3566
|
+
if (versionChanged) {
|
|
3567
|
+
console.log(
|
|
3568
|
+
` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
|
|
3569
|
+
);
|
|
3570
|
+
} else {
|
|
3571
|
+
console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
|
|
3572
|
+
}
|
|
3573
|
+
let zodBucket = "dependencies";
|
|
3574
|
+
if (parsed.devDependencies && "zod" in parsed.devDependencies) {
|
|
3575
|
+
zodBucket = "devDependencies";
|
|
3576
|
+
}
|
|
3577
|
+
if (!parsed[zodBucket]) {
|
|
3578
|
+
parsed[zodBucket] = {};
|
|
3579
|
+
}
|
|
3580
|
+
const bucket = parsed[zodBucket];
|
|
3581
|
+
const previousZod = bucket.zod;
|
|
3582
|
+
const zodChanged = previousZod !== TARGET_ZOD_RANGE;
|
|
3583
|
+
bucket.zod = TARGET_ZOD_RANGE;
|
|
3584
|
+
if (zodChanged) {
|
|
3585
|
+
console.log(
|
|
3586
|
+
` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
|
|
3587
|
+
);
|
|
3588
|
+
} else {
|
|
3589
|
+
console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
|
|
3590
|
+
}
|
|
3591
|
+
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
3592
|
+
const next = JSON.stringify(parsed, null, 2) + trailingNewline;
|
|
3593
|
+
if (next === raw) {
|
|
3594
|
+
console.log("\n No changes to write.");
|
|
3595
|
+
return;
|
|
3596
|
+
}
|
|
3597
|
+
(0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
|
|
3598
|
+
console.log(`
|
|
3599
|
+
Saved '${PACKAGE_JSON_RELATIVE}'.`);
|
|
3600
|
+
console.log(
|
|
3601
|
+
` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
|
|
3602
|
+
);
|
|
3603
|
+
}
|
|
3604
|
+
|
|
3605
|
+
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3606
|
+
var import_ts_morph17 = require("ts-morph");
|
|
3607
|
+
var import_path18 = __toESM(require("path"));
|
|
2876
3608
|
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
2877
3609
|
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
2878
3610
|
var ACTION_PROPERTY_NAME2 = "action";
|
|
@@ -2893,28 +3625,28 @@ var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
|
2893
3625
|
]);
|
|
2894
3626
|
function getWorkqueueLabel(workqueue) {
|
|
2895
3627
|
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
2896
|
-
if (!slugProperty || !
|
|
3628
|
+
if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
|
|
2897
3629
|
return "(unknown slug)";
|
|
2898
3630
|
}
|
|
2899
3631
|
const slugInitializer = slugProperty.getInitializer();
|
|
2900
|
-
if (!slugInitializer || !
|
|
3632
|
+
if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
|
|
2901
3633
|
return "(unknown slug)";
|
|
2902
3634
|
}
|
|
2903
3635
|
return slugInitializer.getLiteralValue();
|
|
2904
3636
|
}
|
|
2905
3637
|
function getActionTypeName(action) {
|
|
2906
3638
|
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
2907
|
-
if (!typeProperty || !
|
|
3639
|
+
if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
|
|
2908
3640
|
return null;
|
|
2909
3641
|
}
|
|
2910
3642
|
const typeInitializer = typeProperty.getInitializer();
|
|
2911
3643
|
if (!typeInitializer) {
|
|
2912
3644
|
return null;
|
|
2913
3645
|
}
|
|
2914
|
-
if (
|
|
3646
|
+
if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
|
|
2915
3647
|
return typeInitializer.getLiteralValue();
|
|
2916
3648
|
}
|
|
2917
|
-
if (
|
|
3649
|
+
if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
2918
3650
|
return typeInitializer.getName();
|
|
2919
3651
|
}
|
|
2920
3652
|
return null;
|
|
@@ -2928,19 +3660,19 @@ function isUnsupportedActionType(action) {
|
|
|
2928
3660
|
}
|
|
2929
3661
|
function migrateWorkqueueActions(workqueue, relPath) {
|
|
2930
3662
|
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
2931
|
-
if (!actionsProperty || !
|
|
3663
|
+
if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
2932
3664
|
return 0;
|
|
2933
3665
|
}
|
|
2934
3666
|
const actionsInitializer = actionsProperty.getInitializer();
|
|
2935
|
-
if (!actionsInitializer || !
|
|
3667
|
+
if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
2936
3668
|
return 0;
|
|
2937
3669
|
}
|
|
2938
3670
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
2939
3671
|
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
2940
3672
|
if (existingActionProperty) {
|
|
2941
|
-
if (
|
|
3673
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
2942
3674
|
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
2943
|
-
if (existingActionInitializer &&
|
|
3675
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
2944
3676
|
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
2945
3677
|
CONDITIONALS_PROPERTY_NAME
|
|
2946
3678
|
);
|
|
@@ -2965,7 +3697,7 @@ function migrateWorkqueueActions(workqueue, relPath) {
|
|
|
2965
3697
|
return 1;
|
|
2966
3698
|
}
|
|
2967
3699
|
const actionCandidates = actionsInitializer.getElements().filter(
|
|
2968
|
-
(element) =>
|
|
3700
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
2969
3701
|
);
|
|
2970
3702
|
if (actionCandidates.length === 0) {
|
|
2971
3703
|
actionsProperty.remove();
|
|
@@ -3007,36 +3739,36 @@ function migrateWorkqueueActions(workqueue, relPath) {
|
|
|
3007
3739
|
);
|
|
3008
3740
|
return 1;
|
|
3009
3741
|
}
|
|
3010
|
-
function
|
|
3742
|
+
function processFile13(filePath, project) {
|
|
3011
3743
|
const sourceFile = project.getSourceFile(filePath);
|
|
3012
3744
|
if (!sourceFile) return 0;
|
|
3013
3745
|
let migratedWorkqueues = 0;
|
|
3014
|
-
const relPath =
|
|
3746
|
+
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3015
3747
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3016
|
-
|
|
3748
|
+
import_ts_morph17.SyntaxKind.CallExpression
|
|
3017
3749
|
);
|
|
3018
3750
|
for (const call of callExpressions) {
|
|
3019
3751
|
const expression = call.getExpression();
|
|
3020
|
-
if (!
|
|
3752
|
+
if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3021
3753
|
continue;
|
|
3022
3754
|
}
|
|
3023
3755
|
const args2 = call.getArguments();
|
|
3024
3756
|
if (args2.length === 0) continue;
|
|
3025
3757
|
const workqueuesArg = args2[0];
|
|
3026
|
-
if (!
|
|
3758
|
+
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3027
3759
|
for (const element of workqueuesArg.getElements()) {
|
|
3028
|
-
if (!
|
|
3760
|
+
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3029
3761
|
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3030
3762
|
}
|
|
3031
3763
|
}
|
|
3032
3764
|
return migratedWorkqueues;
|
|
3033
3765
|
}
|
|
3034
|
-
async function
|
|
3035
|
-
const srcDir =
|
|
3766
|
+
async function main18() {
|
|
3767
|
+
const srcDir = import_path18.default.join(process.cwd(), "src");
|
|
3036
3768
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3037
3769
|
`);
|
|
3038
|
-
const project = new
|
|
3039
|
-
tsConfigFilePath:
|
|
3770
|
+
const project = new import_ts_morph17.Project({
|
|
3771
|
+
tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
|
|
3040
3772
|
skipAddingFilesFromTsConfig: false
|
|
3041
3773
|
});
|
|
3042
3774
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -3049,7 +3781,7 @@ async function main13() {
|
|
|
3049
3781
|
const modifiedFiles = [];
|
|
3050
3782
|
for (const sourceFile of sourceFiles) {
|
|
3051
3783
|
const filePath = sourceFile.getFilePath();
|
|
3052
|
-
const migrated =
|
|
3784
|
+
const migrated = processFile13(filePath, project);
|
|
3053
3785
|
if (migrated > 0) {
|
|
3054
3786
|
totalMigrated += migrated;
|
|
3055
3787
|
modifiedFiles.push(filePath);
|
|
@@ -3066,7 +3798,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
3066
3798
|
for (const filePath of modifiedFiles) {
|
|
3067
3799
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3068
3800
|
await sourceFile.save();
|
|
3069
|
-
console.log(` Saved: ${
|
|
3801
|
+
console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
|
|
3070
3802
|
}
|
|
3071
3803
|
console.log(
|
|
3072
3804
|
`
|
|
@@ -3075,13 +3807,13 @@ Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to
|
|
|
3075
3807
|
}
|
|
3076
3808
|
|
|
3077
3809
|
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3078
|
-
var
|
|
3079
|
-
var
|
|
3810
|
+
var import_path19 = __toESM(require("path"));
|
|
3811
|
+
var import_ts_morph18 = require("ts-morph");
|
|
3080
3812
|
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3081
|
-
async function
|
|
3082
|
-
const rolesHandlerPath =
|
|
3083
|
-
const project = new
|
|
3084
|
-
tsConfigFilePath:
|
|
3813
|
+
async function main19() {
|
|
3814
|
+
const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3815
|
+
const project = new import_ts_morph18.Project({
|
|
3816
|
+
tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3085
3817
|
skipAddingFilesFromTsConfig: false
|
|
3086
3818
|
});
|
|
3087
3819
|
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
@@ -3130,7 +3862,7 @@ async function main14() {
|
|
|
3130
3862
|
|
|
3131
3863
|
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3132
3864
|
var fs2 = __toESM(require("fs"));
|
|
3133
|
-
var
|
|
3865
|
+
var import_path20 = __toESM(require("path"));
|
|
3134
3866
|
var PATHS_TO_REMOVE = [
|
|
3135
3867
|
{
|
|
3136
3868
|
relativePath: "src/migrations/hearth",
|
|
@@ -3142,9 +3874,9 @@ var PATHS_TO_REMOVE = [
|
|
|
3142
3874
|
},
|
|
3143
3875
|
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3144
3876
|
];
|
|
3145
|
-
async function
|
|
3877
|
+
async function main20() {
|
|
3146
3878
|
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3147
|
-
const absolutePath =
|
|
3879
|
+
const absolutePath = import_path20.default.join(process.cwd(), relativePath);
|
|
3148
3880
|
if (fs2.existsSync(absolutePath)) {
|
|
3149
3881
|
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3150
3882
|
console.log(`Removed ${label} '${relativePath}'.`);
|
|
@@ -3155,9 +3887,9 @@ async function main15() {
|
|
|
3155
3887
|
}
|
|
3156
3888
|
|
|
3157
3889
|
// src/migrations/v2.0/create-events-index.ts
|
|
3158
|
-
var
|
|
3159
|
-
var
|
|
3160
|
-
var
|
|
3890
|
+
var import_ts_morph19 = require("ts-morph");
|
|
3891
|
+
var import_fs2 = __toESM(require("fs"));
|
|
3892
|
+
var import_path21 = __toESM(require("path"));
|
|
3161
3893
|
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3162
3894
|
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3163
3895
|
"getCustomEventsHandler",
|
|
@@ -3179,7 +3911,7 @@ var LICENSE_HEADER = `/*
|
|
|
3179
3911
|
`;
|
|
3180
3912
|
function findEventConfigExports(project, srcDir) {
|
|
3181
3913
|
const found = [];
|
|
3182
|
-
const eventsIndexAbs =
|
|
3914
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
3183
3915
|
for (const sourceFile of project.getSourceFiles()) {
|
|
3184
3916
|
const filePath = sourceFile.getFilePath();
|
|
3185
3917
|
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
@@ -3191,10 +3923,10 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3191
3923
|
for (const decl of statement.getDeclarations()) {
|
|
3192
3924
|
const initializer = decl.getInitializer();
|
|
3193
3925
|
if (!initializer) continue;
|
|
3194
|
-
const unwrapped =
|
|
3195
|
-
if (!
|
|
3926
|
+
const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3927
|
+
if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
|
|
3196
3928
|
const callee = unwrapped.getExpression();
|
|
3197
|
-
if (!
|
|
3929
|
+
if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
|
|
3198
3930
|
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3199
3931
|
found.push({ name: decl.getName(), filePath });
|
|
3200
3932
|
}
|
|
@@ -3203,8 +3935,8 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3203
3935
|
return found;
|
|
3204
3936
|
}
|
|
3205
3937
|
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3206
|
-
const eventsIndexDir =
|
|
3207
|
-
let rel =
|
|
3938
|
+
const eventsIndexDir = import_path21.default.join(srcDir, "events");
|
|
3939
|
+
let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
|
|
3208
3940
|
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3209
3941
|
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3210
3942
|
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
@@ -3281,17 +4013,17 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3281
4013
|
);
|
|
3282
4014
|
}
|
|
3283
4015
|
for (const call of sourceFile.getDescendantsOfKind(
|
|
3284
|
-
|
|
4016
|
+
import_ts_morph19.SyntaxKind.CallExpression
|
|
3285
4017
|
)) {
|
|
3286
4018
|
const callee = call.getExpression();
|
|
3287
|
-
if (!
|
|
4019
|
+
if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
|
|
3288
4020
|
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3289
4021
|
const args2 = call.getArguments();
|
|
3290
4022
|
if (args2.length !== 1) continue;
|
|
3291
4023
|
const [arg] = args2;
|
|
3292
|
-
if (!
|
|
4024
|
+
if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
|
|
3293
4025
|
if (arg.getElements().length === 0) continue;
|
|
3294
|
-
if (!arg.getElements().every((el) =>
|
|
4026
|
+
if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
|
|
3295
4027
|
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
3296
4028
|
changes.push(
|
|
3297
4029
|
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
@@ -3299,13 +4031,13 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3299
4031
|
}
|
|
3300
4032
|
return changes;
|
|
3301
4033
|
}
|
|
3302
|
-
async function
|
|
3303
|
-
const
|
|
3304
|
-
const srcDir =
|
|
4034
|
+
async function main21() {
|
|
4035
|
+
const cwd = process.cwd();
|
|
4036
|
+
const srcDir = import_path21.default.join(cwd, "src");
|
|
3305
4037
|
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
3306
4038
|
`);
|
|
3307
|
-
const project = new
|
|
3308
|
-
tsConfigFilePath:
|
|
4039
|
+
const project = new import_ts_morph19.Project({
|
|
4040
|
+
tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
|
|
3309
4041
|
skipAddingFilesFromTsConfig: false
|
|
3310
4042
|
});
|
|
3311
4043
|
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
@@ -3317,15 +4049,15 @@ async function main16() {
|
|
|
3317
4049
|
}
|
|
3318
4050
|
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
3319
4051
|
for (const e of eventConfigExports) {
|
|
3320
|
-
console.log(` ${e.name} \u2190 ${
|
|
4052
|
+
console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
|
|
3321
4053
|
}
|
|
3322
|
-
const eventsIndexAbs =
|
|
3323
|
-
const eventsIndexRel =
|
|
3324
|
-
if (
|
|
4054
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
4055
|
+
const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
|
|
4056
|
+
if (import_fs2.default.existsSync(eventsIndexAbs)) {
|
|
3325
4057
|
console.log(`
|
|
3326
4058
|
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
3327
4059
|
} else {
|
|
3328
|
-
|
|
4060
|
+
import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
|
|
3329
4061
|
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
3330
4062
|
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
3331
4063
|
overwrite: false
|
|
@@ -3346,7 +4078,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
|
|
|
3346
4078
|
);
|
|
3347
4079
|
return;
|
|
3348
4080
|
}
|
|
3349
|
-
const handlerRelPath =
|
|
4081
|
+
const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
|
|
3350
4082
|
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
3351
4083
|
const changes = modifyHandler(handler, exportNameSet);
|
|
3352
4084
|
if (changes.length === 0) {
|
|
@@ -3366,12 +4098,13 @@ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
|
3366
4098
|
var UPSTREAM_BRANCH = "develop";
|
|
3367
4099
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
3368
4100
|
var FILES_TO_CHECKOUT = [
|
|
3369
|
-
"
|
|
3370
|
-
"
|
|
4101
|
+
"src/analytics/analytics.ts",
|
|
4102
|
+
"Dockerfile",
|
|
4103
|
+
"Dockerfile.assets"
|
|
3371
4104
|
];
|
|
3372
4105
|
function runGit(args2, { silent = false } = {}) {
|
|
3373
4106
|
return (0, import_child_process.execFileSync)("git", args2, {
|
|
3374
|
-
cwd:
|
|
4107
|
+
cwd: process.cwd(),
|
|
3375
4108
|
encoding: "utf8",
|
|
3376
4109
|
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
3377
4110
|
});
|
|
@@ -3387,11 +4120,11 @@ function tryGit(args2) {
|
|
|
3387
4120
|
function assertIsGitRepo() {
|
|
3388
4121
|
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
3389
4122
|
throw new Error(
|
|
3390
|
-
|
|
4123
|
+
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
3391
4124
|
);
|
|
3392
4125
|
}
|
|
3393
4126
|
}
|
|
3394
|
-
async function
|
|
4127
|
+
async function main22() {
|
|
3395
4128
|
console.log(
|
|
3396
4129
|
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
3397
4130
|
`
|
|
@@ -3439,10 +4172,356 @@ async function main17() {
|
|
|
3439
4172
|
}
|
|
3440
4173
|
}
|
|
3441
4174
|
|
|
4175
|
+
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4176
|
+
var import_fs3 = require("fs");
|
|
4177
|
+
var import_path22 = __toESM(require("path"));
|
|
4178
|
+
var import_ts_morph20 = require("ts-morph");
|
|
4179
|
+
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4180
|
+
skipAddingFilesFromTsConfig: true,
|
|
4181
|
+
manipulationSettings: {
|
|
4182
|
+
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4183
|
+
}
|
|
4184
|
+
};
|
|
4185
|
+
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4186
|
+
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4187
|
+
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4188
|
+
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4189
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4190
|
+
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4191
|
+
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4192
|
+
<html>
|
|
4193
|
+
<head>
|
|
4194
|
+
<link
|
|
4195
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4196
|
+
rel="stylesheet"
|
|
4197
|
+
/>
|
|
4198
|
+
<style type="text/css">
|
|
4199
|
+
body {
|
|
4200
|
+
font-family: 'Noto Sans', sans-serif;
|
|
4201
|
+
color: #222;
|
|
4202
|
+
padding: 16px 24px;
|
|
4203
|
+
}
|
|
4204
|
+
|
|
4205
|
+
h1 {
|
|
4206
|
+
font-size: 21px;
|
|
4207
|
+
margin-top: 32px;
|
|
4208
|
+
margin-bottom: 36px;
|
|
4209
|
+
font-weight: 700;
|
|
4210
|
+
}
|
|
4211
|
+
|
|
4212
|
+
p {
|
|
4213
|
+
font-weight: 400;
|
|
4214
|
+
font-size: 16px;
|
|
4215
|
+
line-height: 1.8;
|
|
4216
|
+
margin-bottom: 24px;
|
|
4217
|
+
}
|
|
4218
|
+
|
|
4219
|
+
i {
|
|
4220
|
+
color: #666;
|
|
4221
|
+
font-weight: 400;
|
|
4222
|
+
font-size: 16px;
|
|
4223
|
+
}
|
|
4224
|
+
</style>
|
|
4225
|
+
</head>
|
|
4226
|
+
|
|
4227
|
+
<body>
|
|
4228
|
+
<img
|
|
4229
|
+
src="{{countryLogo}}"
|
|
4230
|
+
alt="country_logo"
|
|
4231
|
+
style="max-height: 88px; max-width: 100%"
|
|
4232
|
+
/>
|
|
4233
|
+
<h1>Your {{applicationName}} account invitation</h1>
|
|
4234
|
+
<p>Hello {{firstname}},</p>
|
|
4235
|
+
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4236
|
+
<p>
|
|
4237
|
+
Username: <strong>{{username}}</strong><br />
|
|
4238
|
+
Password: <strong>{{temporaryPassword}}</strong>
|
|
4239
|
+
</p>
|
|
4240
|
+
<p>
|
|
4241
|
+
Please click the link below to complete your account setup and start using
|
|
4242
|
+
{{applicationName}}.
|
|
4243
|
+
</p>
|
|
4244
|
+
|
|
4245
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4246
|
+
<a href="{{loginURL}}">Complete setup</a>
|
|
4247
|
+
</div>
|
|
4248
|
+
<br />
|
|
4249
|
+
<p>
|
|
4250
|
+
Best regards, <br />
|
|
4251
|
+
{{applicationName}} Team
|
|
4252
|
+
</p>
|
|
4253
|
+
</body>
|
|
4254
|
+
</html>
|
|
4255
|
+
`;
|
|
4256
|
+
var CSV_ROW = "resendInviteNotification,The SMS message that is sent when a user invitation is resent,Your OpenCRVS account invitation was resent. Please login with your username: {{username}} and temporary password: {{temporaryPassword}},Votre invitation de compte OpenCRVS a \xE9t\xE9 renvoy\xE9e. Veuillez vous connecter avec votre nom d'utilisateur : {{username}} et votre mot de passe temporaire : {{temporaryPassword}}.\n";
|
|
4257
|
+
function getObjectLiteralFromConst(declaration) {
|
|
4258
|
+
if (!declaration) {
|
|
4259
|
+
return;
|
|
4260
|
+
}
|
|
4261
|
+
const initializer = declaration.getInitializer();
|
|
4262
|
+
if (!initializer) {
|
|
4263
|
+
return;
|
|
4264
|
+
}
|
|
4265
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4266
|
+
return initializer;
|
|
4267
|
+
}
|
|
4268
|
+
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4269
|
+
const expression = initializer.getExpression();
|
|
4270
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4271
|
+
return expression;
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4275
|
+
const expression = initializer.getExpression();
|
|
4276
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4277
|
+
return expression;
|
|
4278
|
+
}
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
4281
|
+
function patchEmailTemplatesIndex() {
|
|
4282
|
+
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4283
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4284
|
+
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4285
|
+
return false;
|
|
4286
|
+
}
|
|
4287
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4288
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4289
|
+
let changed = false;
|
|
4290
|
+
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4291
|
+
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4292
|
+
);
|
|
4293
|
+
if (triggerVariableObject) {
|
|
4294
|
+
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4295
|
+
if (!hasResendInviteVariable) {
|
|
4296
|
+
const properties = triggerVariableObject.getProperties();
|
|
4297
|
+
const lastProperty = properties[properties.length - 1];
|
|
4298
|
+
if (lastProperty) {
|
|
4299
|
+
sourceFile.insertText(
|
|
4300
|
+
lastProperty.getEnd(),
|
|
4301
|
+
`,
|
|
4302
|
+
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4303
|
+
firstname: z.string(),
|
|
4304
|
+
username: z.string(),
|
|
4305
|
+
temporaryPassword: z.string(),
|
|
4306
|
+
completeSetupUrl: z.string(),
|
|
4307
|
+
loginURL: z.string()
|
|
4308
|
+
})`
|
|
4309
|
+
);
|
|
4310
|
+
changed = true;
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
const templatesObject = getObjectLiteralFromConst(
|
|
4315
|
+
sourceFile.getVariableDeclaration("templates")
|
|
4316
|
+
);
|
|
4317
|
+
if (templatesObject) {
|
|
4318
|
+
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4319
|
+
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4320
|
+
);
|
|
4321
|
+
if (!hasResendInviteTemplate) {
|
|
4322
|
+
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4323
|
+
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4324
|
+
if (anchor) {
|
|
4325
|
+
sourceFile.insertText(
|
|
4326
|
+
anchor.getEnd(),
|
|
4327
|
+
`,
|
|
4328
|
+
[TriggerEvent.RESEND_INVITE]: {
|
|
4329
|
+
type: 'resend-invite',
|
|
4330
|
+
subject: 'Your OpenCRVS account invitation',
|
|
4331
|
+
template:
|
|
4332
|
+
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4333
|
+
}`
|
|
4334
|
+
);
|
|
4335
|
+
changed = true;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
if (changed) {
|
|
4340
|
+
sourceFile.saveSync();
|
|
4341
|
+
}
|
|
4342
|
+
return changed;
|
|
4343
|
+
}
|
|
4344
|
+
function patchNotificationHandler() {
|
|
4345
|
+
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4346
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4347
|
+
return false;
|
|
4348
|
+
}
|
|
4349
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4350
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4351
|
+
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4352
|
+
if (!convertFn) {
|
|
4353
|
+
return false;
|
|
4354
|
+
}
|
|
4355
|
+
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4356
|
+
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4357
|
+
);
|
|
4358
|
+
if (!switchStmt) {
|
|
4359
|
+
return false;
|
|
4360
|
+
}
|
|
4361
|
+
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4362
|
+
const hasResendInvite = clauses.some(
|
|
4363
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4364
|
+
);
|
|
4365
|
+
if (hasResendInvite) {
|
|
4366
|
+
return false;
|
|
4367
|
+
}
|
|
4368
|
+
const userCreatedClauseIndex = clauses.findIndex(
|
|
4369
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4370
|
+
);
|
|
4371
|
+
if (userCreatedClauseIndex < 0) {
|
|
4372
|
+
return false;
|
|
4373
|
+
}
|
|
4374
|
+
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4375
|
+
sourceFile.insertText(
|
|
4376
|
+
userCreatedClause.getEnd(),
|
|
4377
|
+
`
|
|
4378
|
+
|
|
4379
|
+
case TriggerEvent.RESEND_INVITE:
|
|
4380
|
+
return {
|
|
4381
|
+
firstname,
|
|
4382
|
+
username: payload.username,
|
|
4383
|
+
temporaryPassword: payload.temporaryPassword,
|
|
4384
|
+
completeSetupUrl: LOGIN_URL,
|
|
4385
|
+
loginURL: LOGIN_URL
|
|
4386
|
+
}`
|
|
4387
|
+
);
|
|
4388
|
+
sourceFile.saveSync();
|
|
4389
|
+
return true;
|
|
4390
|
+
}
|
|
4391
|
+
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4392
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4393
|
+
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4394
|
+
const fn = sourceFile.getFunction(fnName);
|
|
4395
|
+
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4396
|
+
const expr = returnStmt?.getExpression();
|
|
4397
|
+
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4398
|
+
return { sourceFile, arrayLiteral: void 0 };
|
|
4399
|
+
}
|
|
4400
|
+
return { sourceFile, arrayLiteral: expr };
|
|
4401
|
+
}
|
|
4402
|
+
function patchUserNotificationRoutes() {
|
|
4403
|
+
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4404
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4405
|
+
return false;
|
|
4406
|
+
}
|
|
4407
|
+
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4408
|
+
full,
|
|
4409
|
+
"getUserNotificationRoutes"
|
|
4410
|
+
);
|
|
4411
|
+
if (!arrayLiteral) {
|
|
4412
|
+
return false;
|
|
4413
|
+
}
|
|
4414
|
+
const elements = arrayLiteral.getElements();
|
|
4415
|
+
const routeExists = elements.some(
|
|
4416
|
+
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4417
|
+
);
|
|
4418
|
+
if (routeExists) {
|
|
4419
|
+
return false;
|
|
4420
|
+
}
|
|
4421
|
+
const anchor = elements.find(
|
|
4422
|
+
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4423
|
+
) ?? elements[elements.length - 1];
|
|
4424
|
+
if (!anchor) {
|
|
4425
|
+
return false;
|
|
4426
|
+
}
|
|
4427
|
+
sourceFile.insertText(
|
|
4428
|
+
anchor.getEnd(),
|
|
4429
|
+
`,
|
|
4430
|
+
{
|
|
4431
|
+
method: 'POST',
|
|
4432
|
+
path: '/triggers/user/resend-invite',
|
|
4433
|
+
handler: makeNotificationHandler('resend-invite'),
|
|
4434
|
+
options: {
|
|
4435
|
+
auth: false,
|
|
4436
|
+
tags: ['api'],
|
|
4437
|
+
description: 'Handles notification for resent user invite'
|
|
4438
|
+
}
|
|
4439
|
+
}`
|
|
4440
|
+
);
|
|
4441
|
+
sourceFile.saveSync();
|
|
4442
|
+
return true;
|
|
4443
|
+
}
|
|
4444
|
+
function patchSmsService() {
|
|
4445
|
+
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4446
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4447
|
+
return false;
|
|
4448
|
+
}
|
|
4449
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4450
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4451
|
+
let changed = false;
|
|
4452
|
+
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4453
|
+
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4454
|
+
);
|
|
4455
|
+
if (otherTemplatesObject) {
|
|
4456
|
+
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4457
|
+
if (!hasResendTemplate) {
|
|
4458
|
+
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4459
|
+
otherTemplatesObject.insertPropertyAssignment(
|
|
4460
|
+
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4461
|
+
{
|
|
4462
|
+
name: "resendInviteNotification",
|
|
4463
|
+
initializer: `'resendInviteNotification'`
|
|
4464
|
+
}
|
|
4465
|
+
);
|
|
4466
|
+
changed = true;
|
|
4467
|
+
}
|
|
4468
|
+
}
|
|
4469
|
+
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4470
|
+
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4471
|
+
);
|
|
4472
|
+
if (triggerToSmsTemplateObject) {
|
|
4473
|
+
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4474
|
+
if (!hasResendInviteMap) {
|
|
4475
|
+
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4476
|
+
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4477
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4478
|
+
{
|
|
4479
|
+
name: `['resend-invite']`,
|
|
4480
|
+
initializer: `'resendInviteNotification'`
|
|
4481
|
+
}
|
|
4482
|
+
);
|
|
4483
|
+
changed = true;
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
if (changed) {
|
|
4487
|
+
sourceFile.saveSync();
|
|
4488
|
+
}
|
|
4489
|
+
return changed;
|
|
4490
|
+
}
|
|
4491
|
+
async function main23() {
|
|
4492
|
+
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4493
|
+
const touched = [];
|
|
4494
|
+
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4495
|
+
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4496
|
+
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4497
|
+
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4498
|
+
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4499
|
+
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4500
|
+
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4501
|
+
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4502
|
+
if (!t.endsWith("\n")) t += "\n";
|
|
4503
|
+
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4504
|
+
touched.push(NOTIFICATION_CSV);
|
|
4505
|
+
}
|
|
4506
|
+
}
|
|
4507
|
+
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4508
|
+
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4509
|
+
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4510
|
+
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4511
|
+
touched.push(RESEND_INVITE_HTML);
|
|
4512
|
+
}
|
|
4513
|
+
if (touched.length === 0) {
|
|
4514
|
+
console.log(" Nothing to update (already present or anchors not found).");
|
|
4515
|
+
return;
|
|
4516
|
+
}
|
|
4517
|
+
console.log(` Updated:
|
|
4518
|
+
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4519
|
+
}
|
|
4520
|
+
|
|
3442
4521
|
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
3443
|
-
var
|
|
3444
|
-
var
|
|
3445
|
-
var
|
|
4522
|
+
var import_ts_morph21 = require("ts-morph");
|
|
4523
|
+
var import_fs4 = __toESM(require("fs"));
|
|
4524
|
+
var import_path23 = __toESM(require("path"));
|
|
3446
4525
|
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
3447
4526
|
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
3448
4527
|
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
@@ -3478,10 +4557,10 @@ function findPrecalculateFunction(sourceFile) {
|
|
|
3478
4557
|
return void 0;
|
|
3479
4558
|
}
|
|
3480
4559
|
function getFunctionBodyBlock(fn) {
|
|
3481
|
-
if (
|
|
4560
|
+
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
3482
4561
|
const initializer = fn.getInitializer();
|
|
3483
4562
|
if (!initializer) return void 0;
|
|
3484
|
-
if (!
|
|
4563
|
+
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
3485
4564
|
return void 0;
|
|
3486
4565
|
}
|
|
3487
4566
|
return initializer.getBody();
|
|
@@ -3491,9 +4570,9 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3491
4570
|
const fn = findPrecalculateFunction(sourceFile);
|
|
3492
4571
|
if (!fn) return log;
|
|
3493
4572
|
const body = getFunctionBodyBlock(fn);
|
|
3494
|
-
if (!body || !
|
|
4573
|
+
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
3495
4574
|
for (const statement of [...body.getStatements()]) {
|
|
3496
|
-
const references = statement.getDescendantsOfKind(
|
|
4575
|
+
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
3497
4576
|
if (references) {
|
|
3498
4577
|
statement.remove();
|
|
3499
4578
|
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
@@ -3501,7 +4580,7 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3501
4580
|
}
|
|
3502
4581
|
const remaining = body.getStatements();
|
|
3503
4582
|
const last = remaining[remaining.length - 1];
|
|
3504
|
-
const alreadyCorrect = last &&
|
|
4583
|
+
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
3505
4584
|
if (!alreadyCorrect) {
|
|
3506
4585
|
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
3507
4586
|
log.push(
|
|
@@ -3510,17 +4589,17 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3510
4589
|
}
|
|
3511
4590
|
return log;
|
|
3512
4591
|
}
|
|
3513
|
-
async function
|
|
3514
|
-
const
|
|
3515
|
-
const absPath =
|
|
3516
|
-
if (!
|
|
4592
|
+
async function main24() {
|
|
4593
|
+
const cwd = process.cwd();
|
|
4594
|
+
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4595
|
+
if (!import_fs4.default.existsSync(absPath)) {
|
|
3517
4596
|
console.log(
|
|
3518
4597
|
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3519
4598
|
);
|
|
3520
4599
|
return;
|
|
3521
4600
|
}
|
|
3522
|
-
const project = new
|
|
3523
|
-
tsConfigFilePath:
|
|
4601
|
+
const project = new import_ts_morph21.Project({
|
|
4602
|
+
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
3524
4603
|
skipAddingFilesFromTsConfig: false
|
|
3525
4604
|
});
|
|
3526
4605
|
const sourceFile = project.getSourceFile(absPath);
|
|
@@ -3547,26 +4626,158 @@ async function main18() {
|
|
|
3547
4626
|
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3548
4627
|
}
|
|
3549
4628
|
|
|
3550
|
-
// src/migrations/v2.0/
|
|
3551
|
-
var
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
4629
|
+
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4630
|
+
var import_child_process2 = require("child_process");
|
|
4631
|
+
var import_fs5 = require("fs");
|
|
4632
|
+
var import_os = require("os");
|
|
4633
|
+
var import_path24 = require("path");
|
|
4634
|
+
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4635
|
+
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4636
|
+
var BASE_BRANCH = "release-v1.9";
|
|
4637
|
+
function gitShowBytes(ref, path23) {
|
|
4638
|
+
try {
|
|
4639
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4640
|
+
cwd: process.cwd(),
|
|
4641
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4642
|
+
});
|
|
4643
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4644
|
+
} catch {
|
|
4645
|
+
return null;
|
|
3555
4646
|
}
|
|
3556
|
-
return cwd;
|
|
3557
4647
|
}
|
|
3558
|
-
async function
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
4648
|
+
async function main25() {
|
|
4649
|
+
console.log(
|
|
4650
|
+
`Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4651
|
+
`
|
|
4652
|
+
);
|
|
4653
|
+
assertIsGitRepo();
|
|
4654
|
+
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4655
|
+
try {
|
|
4656
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4657
|
+
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4658
|
+
console.log(
|
|
4659
|
+
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4660
|
+
);
|
|
4661
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4662
|
+
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4663
|
+
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4664
|
+
const upstreamFiles = runGit(
|
|
4665
|
+
[
|
|
4666
|
+
"ls-tree",
|
|
4667
|
+
"-r",
|
|
4668
|
+
"--name-only",
|
|
4669
|
+
"-z",
|
|
4670
|
+
ref,
|
|
4671
|
+
"--",
|
|
4672
|
+
`${INFRASTRUCTURE_DIR}/`
|
|
4673
|
+
],
|
|
4674
|
+
{ silent: true }
|
|
4675
|
+
).split("\0").filter(Boolean);
|
|
4676
|
+
if (upstreamFiles.length === 0) {
|
|
4677
|
+
console.log(
|
|
4678
|
+
` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
|
|
4679
|
+
);
|
|
4680
|
+
return;
|
|
4681
|
+
}
|
|
4682
|
+
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4683
|
+
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4684
|
+
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4685
|
+
let added = 0;
|
|
4686
|
+
let merged = 0;
|
|
4687
|
+
const conflictedFiles = [];
|
|
4688
|
+
for (const file of upstreamFiles) {
|
|
4689
|
+
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4690
|
+
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4691
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
4692
|
+
console.log(` + ${file} (new from upstream)`);
|
|
4693
|
+
added++;
|
|
4694
|
+
} else {
|
|
4695
|
+
console.warn(` [warn] failed to add new file ${file}`);
|
|
4696
|
+
}
|
|
4697
|
+
continue;
|
|
4698
|
+
}
|
|
4699
|
+
const theirContents = gitShowBytes(ref, file);
|
|
4700
|
+
if (theirContents === null) {
|
|
4701
|
+
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4702
|
+
continue;
|
|
4703
|
+
}
|
|
4704
|
+
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4705
|
+
const baseContents = gitShowBytes(baseRef, file);
|
|
4706
|
+
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4707
|
+
try {
|
|
4708
|
+
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4709
|
+
cwd: process.cwd(),
|
|
4710
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4711
|
+
});
|
|
4712
|
+
runGit(["add", "--", file], { silent: true });
|
|
4713
|
+
merged++;
|
|
4714
|
+
} catch (err) {
|
|
4715
|
+
const status = err.status;
|
|
4716
|
+
if (typeof status === "number" && status > 0) {
|
|
4717
|
+
conflictedFiles.push(file);
|
|
4718
|
+
console.warn(
|
|
4719
|
+
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4720
|
+
);
|
|
4721
|
+
} else {
|
|
4722
|
+
conflictedFiles.push(file);
|
|
4723
|
+
console.warn(
|
|
4724
|
+
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4725
|
+
);
|
|
4726
|
+
}
|
|
4727
|
+
}
|
|
4728
|
+
}
|
|
4729
|
+
console.log(
|
|
4730
|
+
`
|
|
4731
|
+
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4732
|
+
);
|
|
4733
|
+
if (conflictedFiles.length > 0) {
|
|
4734
|
+
console.warn(
|
|
4735
|
+
`
|
|
4736
|
+
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4737
|
+
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4738
|
+
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4739
|
+
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4740
|
+
);
|
|
4741
|
+
}
|
|
4742
|
+
} finally {
|
|
4743
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4744
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4745
|
+
}
|
|
3562
4746
|
}
|
|
3563
|
-
|
|
4747
|
+
}
|
|
4748
|
+
|
|
4749
|
+
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4750
|
+
var import_fs6 = require("fs");
|
|
4751
|
+
var import_path25 = require("path");
|
|
4752
|
+
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4753
|
+
async function main26() {
|
|
4754
|
+
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4755
|
+
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
3564
4756
|
console.log(
|
|
3565
|
-
|
|
4757
|
+
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
3566
4758
|
);
|
|
3567
|
-
|
|
4759
|
+
return;
|
|
3568
4760
|
}
|
|
3569
|
-
|
|
4761
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4762
|
+
`);
|
|
4763
|
+
assertIsGitRepo();
|
|
4764
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4765
|
+
silent: true
|
|
4766
|
+
});
|
|
4767
|
+
console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4768
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4769
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4770
|
+
console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4771
|
+
}
|
|
4772
|
+
console.log(
|
|
4773
|
+
`
|
|
4774
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4775
|
+
);
|
|
4776
|
+
}
|
|
4777
|
+
|
|
4778
|
+
// src/migrations/v2.0/index.ts
|
|
4779
|
+
async function runUpgrade(dockerSwarm) {
|
|
4780
|
+
await main18();
|
|
3570
4781
|
await main();
|
|
3571
4782
|
await main2();
|
|
3572
4783
|
await main3();
|
|
@@ -3579,11 +4790,22 @@ async function runUpgrade(ccwd) {
|
|
|
3579
4790
|
await main10();
|
|
3580
4791
|
await main11();
|
|
3581
4792
|
await main12();
|
|
4793
|
+
await main13();
|
|
3582
4794
|
await main14();
|
|
3583
4795
|
await main15();
|
|
3584
4796
|
await main16();
|
|
4797
|
+
await main19();
|
|
4798
|
+
await main20();
|
|
4799
|
+
await main21();
|
|
4800
|
+
await main22();
|
|
4801
|
+
await main23();
|
|
4802
|
+
await main24();
|
|
3585
4803
|
await main17();
|
|
3586
|
-
|
|
4804
|
+
if (dockerSwarm) {
|
|
4805
|
+
await main25();
|
|
4806
|
+
} else {
|
|
4807
|
+
await main26();
|
|
4808
|
+
}
|
|
3587
4809
|
}
|
|
3588
4810
|
|
|
3589
4811
|
// src/cli.ts
|
|
@@ -3598,7 +4820,20 @@ Commands:
|
|
|
3598
4820
|
|
|
3599
4821
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
3600
4822
|
`.trim();
|
|
3601
|
-
|
|
4823
|
+
var UPGRADE_USAGE = `
|
|
4824
|
+
Usage: opencrvs upgrade [options]
|
|
4825
|
+
|
|
4826
|
+
Upgrade the country config in the current working directory to the next
|
|
4827
|
+
major version of OpenCRVS.
|
|
4828
|
+
|
|
4829
|
+
Options:
|
|
4830
|
+
--docker-swarm Keep and merge the 'infrastructure/' directory with
|
|
4831
|
+
upstream changes. Use this if your country deploys
|
|
4832
|
+
OpenCRVS via Docker Swarm. When omitted, the
|
|
4833
|
+
'infrastructure/' directory is deleted (default).
|
|
4834
|
+
-h, --help Show this message.
|
|
4835
|
+
`.trim();
|
|
4836
|
+
function main27() {
|
|
3602
4837
|
const command = args[0];
|
|
3603
4838
|
if (!command || command === "--help" || command === "-h") {
|
|
3604
4839
|
console.log(USAGE);
|
|
@@ -3643,10 +4878,25 @@ Subcommands:
|
|
|
3643
4878
|
}
|
|
3644
4879
|
}
|
|
3645
4880
|
async function handleUpgrade() {
|
|
4881
|
+
const upgradeArgs = args.slice(1);
|
|
4882
|
+
if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
|
|
4883
|
+
console.log(UPGRADE_USAGE);
|
|
4884
|
+
process.exit(0);
|
|
4885
|
+
}
|
|
4886
|
+
const KNOWN_FLAGS = /* @__PURE__ */ new Set(["--docker-swarm"]);
|
|
4887
|
+
const unknownFlags = upgradeArgs.filter(
|
|
4888
|
+
(arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
|
|
4889
|
+
);
|
|
4890
|
+
if (unknownFlags.length > 0) {
|
|
4891
|
+
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
4892
|
+
`);
|
|
4893
|
+
console.log(UPGRADE_USAGE);
|
|
4894
|
+
process.exit(1);
|
|
4895
|
+
}
|
|
4896
|
+
const dockerSwarm = upgradeArgs.includes("--docker-swarm");
|
|
3646
4897
|
console.log("Initiating upgrade...");
|
|
3647
4898
|
try {
|
|
3648
|
-
|
|
3649
|
-
await runUpgrade(pathToCountryconfig);
|
|
4899
|
+
await runUpgrade(dockerSwarm);
|
|
3650
4900
|
console.log("Upgrade completed successfully!");
|
|
3651
4901
|
} catch (error) {
|
|
3652
4902
|
console.error("Upgrade failed:", error);
|
|
@@ -3658,4 +4908,4 @@ function handleCheckTranslations() {
|
|
|
3658
4908
|
console.warn("This command is not implemented yet!");
|
|
3659
4909
|
process.exit(1);
|
|
3660
4910
|
}
|
|
3661
|
-
|
|
4911
|
+
main27();
|