@opencrvs/toolkit 2.0.0-rc.2dd0886 → 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/cli.js +34 -25
- 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 +60 -35
- package/dist/migrations/v2.0/index.js +34 -25
- package/opencrvs-toolkit-2.0.0-rc.2e68bac.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.2dd0886.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -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
|
}
|
|
@@ -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();
|
|
@@ -1106,7 +1115,7 @@ function processFile6(filePath, project) {
|
|
|
1106
1115
|
async function main6() {
|
|
1107
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
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-birth-certificate-issuance-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-birth-certificate-issuance-flag.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"add-birth-certificate-issuance-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-birth-certificate-issuance-flag.ts"],"names":[],"mappings":"AAycA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -24,15 +24,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.main = main;
|
|
26
26
|
/**
|
|
27
|
-
* Codemod: Add `pending-first-certificate-issuance` flag to
|
|
27
|
+
* Codemod: Add `pending-first-certificate-issuance` flag to event configs and workqueues.
|
|
28
28
|
*
|
|
29
29
|
* Usage:
|
|
30
30
|
* ts-node -r tsconfig-paths/register src/migrations/v2.0/add-birth-certificate-issuance-flag.ts
|
|
31
31
|
*
|
|
32
32
|
* What it does:
|
|
33
|
-
* defineConfig (
|
|
33
|
+
* defineConfig (every event type — birth, death, marriage, custom, etc.):
|
|
34
34
|
* - Ensures the top-level `flags` array contains the `pending-first-certificate-issuance`
|
|
35
|
-
* flag definition
|
|
35
|
+
* flag definition. The flag's i18n `label.id` is event-specific, e.g.
|
|
36
|
+
* `event.birth.flag.pending-first-certificate-issuance`,
|
|
37
|
+
* `event.death.flag.pending-first-certificate-issuance`.
|
|
36
38
|
* - Ensures every `REGISTER` action has
|
|
37
39
|
* `flags: [{ id: 'pending-first-certificate-issuance', operation: 'add' }]`
|
|
38
40
|
* - Ensures every `PRINT_CERTIFICATE` action has
|
|
@@ -55,20 +57,27 @@ const ACTION_PROPERTY_NAME = 'action';
|
|
|
55
57
|
const FLAGS_PROPERTY_NAME = 'flags';
|
|
56
58
|
const QUERY_PROPERTY_NAME = 'query';
|
|
57
59
|
const TYPE_PROPERTY_NAME = 'type';
|
|
60
|
+
const ID_PROPERTY_NAME = 'id';
|
|
58
61
|
const CLAUSES_PROPERTY_NAME = 'clauses';
|
|
59
62
|
const ANY_OF_PROPERTY_NAME = 'anyOf';
|
|
60
63
|
const FLAG_ID = 'pending-first-certificate-issuance';
|
|
61
64
|
const REGISTER_TYPE = 'REGISTER';
|
|
62
65
|
const PRINT_CERTIFICATE_TYPE = 'PRINT_CERTIFICATE';
|
|
63
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Builds the flag-definition object literal for a given event type so the i18n
|
|
68
|
+
* `label.id` is namespaced per event (e.g. `event.death.flag.…`).
|
|
69
|
+
*/
|
|
70
|
+
function flagDefinitionInitializer(eventType) {
|
|
71
|
+
return `{
|
|
64
72
|
id: '${FLAG_ID}',
|
|
65
73
|
label: {
|
|
66
|
-
id: 'event.
|
|
74
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
67
75
|
defaultMessage: 'Pending first certificate issuance',
|
|
68
76
|
description: 'Flag label for first certificate issuance'
|
|
69
77
|
},
|
|
70
78
|
requiresAction: true
|
|
71
79
|
}`;
|
|
80
|
+
}
|
|
72
81
|
// ─── Generic helpers ──────────────────────────────────────────────────────────
|
|
73
82
|
/**
|
|
74
83
|
* Returns true if the object's `type` property matches the given type name.
|
|
@@ -90,23 +99,36 @@ function isActionOfType(obj, typeName) {
|
|
|
90
99
|
return false;
|
|
91
100
|
}
|
|
92
101
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
102
|
+
* Extracts the event type from a `defineConfig` root config object, using the
|
|
103
|
+
* (lower-cased) value of either the `type` or `id` property. Property name has
|
|
104
|
+
* shifted across core/country-config versions, so both are tried.
|
|
105
|
+
*
|
|
106
|
+
* Handles all known shapes:
|
|
107
|
+
* - `type: 'birth'` / `id: 'birth'`
|
|
108
|
+
* - `type: EventType.BIRTH` / `id: Event.Birth`
|
|
109
|
+
*
|
|
110
|
+
* For `PropertyAccessExpression` (enum access), the *member name* is returned
|
|
111
|
+
* lower-cased — this works for the conventional `EventType.BIRTH = 'birth'` and
|
|
112
|
+
* `Event.Birth = 'birth'` mappings used in core and country configs.
|
|
113
|
+
*
|
|
114
|
+
* Returns null when no event type can be determined.
|
|
95
115
|
*/
|
|
96
|
-
function
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
116
|
+
function getEventType(configArg) {
|
|
117
|
+
for (const propName of [TYPE_PROPERTY_NAME, ID_PROPERTY_NAME]) {
|
|
118
|
+
const prop = configArg.getProperty(propName);
|
|
119
|
+
if (!prop || !ts_morph_1.Node.isPropertyAssignment(prop))
|
|
120
|
+
continue;
|
|
121
|
+
const initializer = prop.getInitializer();
|
|
122
|
+
if (!initializer)
|
|
123
|
+
continue;
|
|
124
|
+
if (ts_morph_1.Node.isStringLiteral(initializer)) {
|
|
125
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
126
|
+
}
|
|
127
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(initializer)) {
|
|
128
|
+
return initializer.getName().toLowerCase();
|
|
129
|
+
}
|
|
108
130
|
}
|
|
109
|
-
return
|
|
131
|
+
return null;
|
|
110
132
|
}
|
|
111
133
|
/**
|
|
112
134
|
* Returns true if an array literal contains an object literal with `id: <id>`.
|
|
@@ -129,17 +151,19 @@ function hasElementWithId(array, id) {
|
|
|
129
151
|
}
|
|
130
152
|
// ─── defineConfig helpers ─────────────────────────────────────────────────────
|
|
131
153
|
/**
|
|
132
|
-
* Ensures the top-level `flags` array in a
|
|
133
|
-
* `pending-first-certificate-issuance` flag definition.
|
|
154
|
+
* Ensures the top-level `flags` array in a `defineConfig` contains the
|
|
155
|
+
* `pending-first-certificate-issuance` flag definition. The flag's i18n
|
|
156
|
+
* `label.id` is namespaced per event type (e.g. `event.death.flag.…`).
|
|
134
157
|
*/
|
|
135
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
158
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
159
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
136
160
|
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME);
|
|
137
161
|
if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
|
|
138
162
|
const flagsInit = flagsProp.getInitializer();
|
|
139
163
|
if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
|
|
140
164
|
if (hasElementWithId(flagsInit, FLAG_ID))
|
|
141
165
|
return false;
|
|
142
|
-
flagsInit.addElement(
|
|
166
|
+
flagsInit.addElement(initializer);
|
|
143
167
|
return true;
|
|
144
168
|
}
|
|
145
169
|
return false;
|
|
@@ -147,7 +171,7 @@ function ensureTopLevelFlagDefinition(configArg) {
|
|
|
147
171
|
// No `flags` property at all — create it
|
|
148
172
|
configArg.addPropertyAssignment({
|
|
149
173
|
name: FLAGS_PROPERTY_NAME,
|
|
150
|
-
initializer: `[\n ${
|
|
174
|
+
initializer: `[\n ${initializer}\n]`
|
|
151
175
|
});
|
|
152
176
|
return true;
|
|
153
177
|
}
|
|
@@ -174,15 +198,15 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
174
198
|
return true;
|
|
175
199
|
}
|
|
176
200
|
/**
|
|
177
|
-
* Processes a
|
|
201
|
+
* Processes a `defineConfig` object: ensures top-level flag definition,
|
|
178
202
|
* REGISTER action flags, and PRINT_CERTIFICATE action flags.
|
|
179
203
|
* Returns the number of changes made.
|
|
180
204
|
*/
|
|
181
|
-
function
|
|
205
|
+
function processConfig(configArg, eventType, relPath) {
|
|
182
206
|
let changes = 0;
|
|
183
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
207
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
184
208
|
changes++;
|
|
185
|
-
console.log(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
|
|
209
|
+
console.log(` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`);
|
|
186
210
|
}
|
|
187
211
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
188
212
|
if (!actionsProp || !ts_morph_1.Node.isPropertyAssignment(actionsProp))
|
|
@@ -197,13 +221,13 @@ function processBirthConfig(configArg, relPath) {
|
|
|
197
221
|
if (isActionOfType(element, REGISTER_TYPE)) {
|
|
198
222
|
if (ensureActionOperationFlag(element, 'add')) {
|
|
199
223
|
changes++;
|
|
200
|
-
console.log(` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`);
|
|
224
|
+
console.log(` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`);
|
|
201
225
|
}
|
|
202
226
|
}
|
|
203
227
|
if (isActionOfType(element, PRINT_CERTIFICATE_TYPE)) {
|
|
204
228
|
if (ensureActionOperationFlag(element, 'remove')) {
|
|
205
229
|
changes++;
|
|
206
|
-
console.log(` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`);
|
|
230
|
+
console.log(` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`);
|
|
207
231
|
}
|
|
208
232
|
}
|
|
209
233
|
}
|
|
@@ -332,9 +356,10 @@ function processFile(filePath, project) {
|
|
|
332
356
|
const configArg = args[0];
|
|
333
357
|
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
334
358
|
continue;
|
|
335
|
-
|
|
359
|
+
const eventType = getEventType(configArg);
|
|
360
|
+
if (!eventType)
|
|
336
361
|
continue;
|
|
337
|
-
totalChanges +=
|
|
362
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
338
363
|
}
|
|
339
364
|
// ── defineWorkqueues ──────────────────────────────────────────────────────
|
|
340
365
|
if (calleeName === DEFINE_WORKQUEUES_NAME) {
|
|
@@ -369,7 +394,7 @@ function processFile(filePath, project) {
|
|
|
369
394
|
function main() {
|
|
370
395
|
return __awaiter(this, void 0, void 0, function* () {
|
|
371
396
|
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
372
|
-
console.log(`Scanning for
|
|
397
|
+
console.log(`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}\n`);
|
|
373
398
|
const project = new ts_morph_1.Project({
|
|
374
399
|
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
375
400
|
skipAddingFilesFromTsConfig: false
|
|
@@ -390,7 +415,7 @@ function main() {
|
|
|
390
415
|
}
|
|
391
416
|
}
|
|
392
417
|
if (modifiedFiles.length === 0) {
|
|
393
|
-
console.log('No
|
|
418
|
+
console.log('No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do.');
|
|
394
419
|
return;
|
|
395
420
|
}
|
|
396
421
|
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
@@ -875,20 +875,23 @@ var ACTION_PROPERTY_NAME = "action";
|
|
|
875
875
|
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
876
876
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
877
877
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
878
|
+
var ID_PROPERTY_NAME = "id";
|
|
878
879
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
879
880
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
880
881
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
881
882
|
var REGISTER_TYPE = "REGISTER";
|
|
882
883
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
883
|
-
|
|
884
|
+
function flagDefinitionInitializer(eventType) {
|
|
885
|
+
return `{
|
|
884
886
|
id: '${FLAG_ID}',
|
|
885
887
|
label: {
|
|
886
|
-
id: 'event.
|
|
888
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
887
889
|
defaultMessage: 'Pending first certificate issuance',
|
|
888
890
|
description: 'Flag label for first certificate issuance'
|
|
889
891
|
},
|
|
890
892
|
requiresAction: true
|
|
891
893
|
}`;
|
|
894
|
+
}
|
|
892
895
|
function isActionOfType(obj, typeName) {
|
|
893
896
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
894
897
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -902,18 +905,20 @@ function isActionOfType(obj, typeName) {
|
|
|
902
905
|
}
|
|
903
906
|
return false;
|
|
904
907
|
}
|
|
905
|
-
function
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
908
|
+
function getEventType(configArg) {
|
|
909
|
+
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME]) {
|
|
910
|
+
const prop = configArg.getProperty(propName);
|
|
911
|
+
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
912
|
+
const initializer = prop.getInitializer();
|
|
913
|
+
if (!initializer) continue;
|
|
914
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
915
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
916
|
+
}
|
|
917
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
918
|
+
return initializer.getName().toLowerCase();
|
|
919
|
+
}
|
|
915
920
|
}
|
|
916
|
-
return
|
|
921
|
+
return null;
|
|
917
922
|
}
|
|
918
923
|
function hasElementWithId(array3, id) {
|
|
919
924
|
for (const el of array3.getElements()) {
|
|
@@ -927,13 +932,14 @@ function hasElementWithId(array3, id) {
|
|
|
927
932
|
}
|
|
928
933
|
return false;
|
|
929
934
|
}
|
|
930
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
935
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
936
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
931
937
|
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME2);
|
|
932
938
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
933
939
|
const flagsInit = flagsProp.getInitializer();
|
|
934
940
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
935
941
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
936
|
-
flagsInit.addElement(
|
|
942
|
+
flagsInit.addElement(initializer);
|
|
937
943
|
return true;
|
|
938
944
|
}
|
|
939
945
|
return false;
|
|
@@ -941,7 +947,7 @@ function ensureTopLevelFlagDefinition(configArg) {
|
|
|
941
947
|
configArg.addPropertyAssignment({
|
|
942
948
|
name: FLAGS_PROPERTY_NAME2,
|
|
943
949
|
initializer: `[
|
|
944
|
-
${
|
|
950
|
+
${initializer}
|
|
945
951
|
]`
|
|
946
952
|
});
|
|
947
953
|
return true;
|
|
@@ -964,11 +970,13 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
964
970
|
});
|
|
965
971
|
return true;
|
|
966
972
|
}
|
|
967
|
-
function
|
|
973
|
+
function processConfig(configArg, eventType, relPath) {
|
|
968
974
|
let changes = 0;
|
|
969
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
975
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
970
976
|
changes++;
|
|
971
|
-
console.log(
|
|
977
|
+
console.log(
|
|
978
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
979
|
+
);
|
|
972
980
|
}
|
|
973
981
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
974
982
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -982,7 +990,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
982
990
|
if (ensureActionOperationFlag(element, "add")) {
|
|
983
991
|
changes++;
|
|
984
992
|
console.log(
|
|
985
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
993
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
986
994
|
);
|
|
987
995
|
}
|
|
988
996
|
}
|
|
@@ -990,7 +998,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
990
998
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
991
999
|
changes++;
|
|
992
1000
|
console.log(
|
|
993
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1001
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
994
1002
|
);
|
|
995
1003
|
}
|
|
996
1004
|
}
|
|
@@ -1088,8 +1096,9 @@ function processFile6(filePath, project) {
|
|
|
1088
1096
|
if (args.length === 0) continue;
|
|
1089
1097
|
const configArg = args[0];
|
|
1090
1098
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1091
|
-
|
|
1092
|
-
|
|
1099
|
+
const eventType = getEventType(configArg);
|
|
1100
|
+
if (!eventType) continue;
|
|
1101
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1093
1102
|
}
|
|
1094
1103
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1095
1104
|
const args = call.getArguments();
|
|
@@ -1118,7 +1127,7 @@ function processFile6(filePath, project) {
|
|
|
1118
1127
|
async function main6() {
|
|
1119
1128
|
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1120
1129
|
console.log(
|
|
1121
|
-
`Scanning for
|
|
1130
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1122
1131
|
`
|
|
1123
1132
|
);
|
|
1124
1133
|
const project = new import_ts_morph6.Project({
|
|
@@ -1143,7 +1152,7 @@ async function main6() {
|
|
|
1143
1152
|
}
|
|
1144
1153
|
if (modifiedFiles.length === 0) {
|
|
1145
1154
|
console.log(
|
|
1146
|
-
"No
|
|
1155
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1147
1156
|
);
|
|
1148
1157
|
return;
|
|
1149
1158
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|