@opencrvs/toolkit 2.1.2 → 2.2.0-rc.19ec10b
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/build.sh +9 -14
- package/create-countryconfig/package.json +1 -1
- package/dist/application-config/index.js +57 -14
- package/dist/authentication/index.d.ts +2 -1
- package/dist/authentication/index.js +34 -14
- package/dist/cli.js +1491 -2020
- package/dist/commons/api/router.d.ts +1564 -248
- package/dist/commons/application-config/index.d.ts +3 -3
- package/dist/commons/conditionals/conditionals.d.ts +58 -7
- package/dist/commons/conditionals/index.d.ts +1 -0
- package/dist/commons/conditionals/validate.d.ts +6 -1
- package/dist/commons/events/ActionConfig.d.ts +146 -20
- package/dist/commons/events/ActionDocument.d.ts +89 -0
- package/dist/commons/events/ActionInput.d.ts +56 -4
- package/dist/commons/events/ActionStatus.d.ts +2 -2
- package/dist/commons/events/ActionType.d.ts +13 -1
- package/dist/commons/events/AdvancedSearchConfig.d.ts +15 -0
- package/dist/commons/events/AuditLog.d.ts +4 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +192 -18
- package/dist/commons/events/Draft.d.ts +36 -1
- package/dist/commons/events/EventConfig.d.ts +473 -6
- package/dist/commons/events/EventDocument.d.ts +90 -0
- package/dist/commons/events/EventIndex.d.ts +44 -6
- package/dist/commons/events/EventInput.d.ts +1 -0
- package/dist/commons/events/EventMetadata.d.ts +24 -1
- package/dist/commons/events/EventStatus.d.ts +1 -0
- package/dist/commons/events/FieldConfig.d.ts +11 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
- package/dist/commons/events/Flag.d.ts +1 -7
- package/dist/commons/events/PlainDate.d.ts +6 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +224 -33
- package/dist/commons/events/defineConfig.d.ts +7 -2
- package/dist/commons/events/event.d.ts +20 -1
- package/dist/commons/events/eventConfigValidation.d.ts +26 -1
- package/dist/commons/events/field.d.ts +37 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/locations.d.ts +1 -1
- package/dist/commons/events/scopes.d.ts +4 -1
- package/dist/commons/events/state/flags.d.ts +1 -1
- package/dist/commons/events/state/index.d.ts +11 -2
- package/dist/commons/events/state/utils.d.ts +11 -1
- package/dist/commons/events/test.utils.d.ts +89 -7
- package/dist/commons/events/toNotificationForm.d.ts +17 -0
- package/dist/commons/events/utils.d.ts +90 -10
- package/dist/commons/users/Role.d.ts +23 -0
- package/dist/commons/users/User.d.ts +263 -0
- package/dist/commons/users/authentication.d.ts +67 -0
- package/dist/commons/users/index.d.ts +5 -0
- package/dist/commons/users/roleValidations.d.ts +15 -0
- package/dist/commons/users/scopes.d.ts +1402 -0
- package/dist/commons/users/userReferences.d.ts +176 -0
- package/dist/conditionals/index.js +29 -9
- package/dist/environment/custom-types.d.ts +1 -0
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/derived-variables.d.ts +24 -4
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +27 -4
- package/dist/environment/questions.d.ts +42 -9
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +71 -48
- package/dist/environment/registry.d.ts +15 -0
- package/dist/environment/registry.d.ts.map +1 -0
- package/dist/environment/registry.js +112 -0
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +165 -35
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +2050 -1156
- package/dist/migrations/add-notify-config.d.ts +40 -0
- package/dist/migrations/add-notify-config.d.ts.map +1 -0
- package/dist/migrations/add-notify-config.js +249 -0
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +1306 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
- package/dist/migrations/move-declaration-to-declare-action.js +260 -0
- package/dist/migrations/{v2.1 → persistent}/add-translations.d.ts +7 -1
- package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
- package/dist/migrations/{v2.1 → persistent}/add-translations.js +14 -12
- package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
- package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
- package/dist/migrations/persistent/check-upgrade-path.js +105 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
- package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
- package/dist/migrations/read-declaration-through-helper.d.ts +39 -0
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
- package/dist/migrations/read-declaration-through-helper.js +199 -0
- package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
- package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
- package/dist/migrations/replace-incomplete-flag.js +126 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
- package/dist/migrations/resolve-versioned-event-config.js +353 -0
- package/dist/migrations/utils.d.ts +61 -0
- package/dist/migrations/utils.d.ts.map +1 -0
- package/dist/migrations/utils.js +218 -0
- package/dist/notification/index.js +1081 -209
- package/dist/roles/index.d.ts +2 -0
- package/dist/roles/index.d.ts.map +1 -0
- package/dist/roles/index.js +730 -0
- package/dist/scopes/index.d.ts +83 -100
- package/dist/scopes/index.js +29 -13
- package/dist/templates/charts-values/dependencies/values.yaml +6 -3
- package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -10
- package/dist/templates/charts-values/traefik/values.yaml +4 -3
- package/dist/verify/endpoints.d.ts +11 -0
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +21 -27
- package/opencrvs-toolkit-2.2.0-rc.19ec10b.tgz +0 -0
- package/package.json +5 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +3 -5
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
- package/dist/migrations/v2.1/add-translations.d.ts.map +0 -1
- package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
- package/dist/migrations/v2.1/enable-telemetry.js +0 -455
- package/dist/migrations/v2.1/index.d.ts +0 -6
- package/dist/migrations/v2.1/index.d.ts.map +0 -1
- package/dist/migrations/v2.1/index.js +0 -2170
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -14
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
- package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-sentry.js +0 -354
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
- package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
- package/dist/migrations/v2.1/template-files.d.ts +0 -8
- package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
- package/dist/migrations/v2.1/template-files.js +0 -49
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -8
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
- package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
- package/dist/templates/countryconfig-template/.tiltignore +0 -1
- package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
- package/dist/templates/countryconfig-template/Tiltfile +0 -112
- package/dist/templates/countryconfig-template/assets/README.md +0 -1
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
- package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
- package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
- package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
- package/opencrvs-toolkit-2.1.2.tgz +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codemod: Move the top-level `declaration` given to `defineConfig` onto the
|
|
3
|
+
* event's DECLARE action.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* ts-node -r tsconfig-paths/register src/migrations/move-declaration-to-declare-action.ts
|
|
7
|
+
*
|
|
8
|
+
* Why:
|
|
9
|
+
* As of v2.2 the declaration form lives on the DECLARE action. `defineConfig`
|
|
10
|
+
* still accepts a top-level `declaration`, but warns that it is deprecated
|
|
11
|
+
* and will stop accepting it in a future release.
|
|
12
|
+
*
|
|
13
|
+
* What it does:
|
|
14
|
+
* - Scans all TypeScript files under `src/`
|
|
15
|
+
* - Finds every call to the toolkit's `defineConfig` given an object literal
|
|
16
|
+
* with a top-level `declaration`
|
|
17
|
+
* - Moves that `declaration` property, as written, into the object literal
|
|
18
|
+
* of the DECLARE action in `actions`, after its `label` (or its `type` when
|
|
19
|
+
* it has no `label`)
|
|
20
|
+
* - Moves the comments on the lines above it and after it with it
|
|
21
|
+
* - Logs, without changing, configs it cannot rewrite safely: a config not
|
|
22
|
+
* given as an object literal, `actions` that is not an array literal, an
|
|
23
|
+
* action not written inline whose type does not rule out DECLARE, no
|
|
24
|
+
* DECLARE action or more than one, and a DECLARE action that already has
|
|
25
|
+
* a `declaration` (which `defineConfig` rejects)
|
|
26
|
+
* - Saves the modified files in-place
|
|
27
|
+
*/
|
|
28
|
+
import { SourceFile } from 'ts-morph';
|
|
29
|
+
/**
|
|
30
|
+
* Moves the top-level `declaration` of every toolkit `defineConfig` call in the
|
|
31
|
+
* file onto its DECLARE action.
|
|
32
|
+
*
|
|
33
|
+
* @returns the number of event configs rewritten.
|
|
34
|
+
*/
|
|
35
|
+
export declare function moveDeclarationToDeclareAction(sourceFile: SourceFile): number;
|
|
36
|
+
declare function main(): Promise<void>;
|
|
37
|
+
export { main };
|
|
38
|
+
//# sourceMappingURL=move-declaration-to-declare-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"move-declaration-to-declare-action.d.ts","sourceRoot":"","sources":["../../src/migrations/move-declaration-to-declare-action.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAOL,UAAU,EAEX,MAAM,UAAU,CAAA;AA2MjB;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAyC7E;AAED,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.moveDeclarationToDeclareAction = moveDeclarationToDeclareAction;
|
|
26
|
+
exports.main = main;
|
|
27
|
+
/**
|
|
28
|
+
* Codemod: Move the top-level `declaration` given to `defineConfig` onto the
|
|
29
|
+
* event's DECLARE action.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* ts-node -r tsconfig-paths/register src/migrations/move-declaration-to-declare-action.ts
|
|
33
|
+
*
|
|
34
|
+
* Why:
|
|
35
|
+
* As of v2.2 the declaration form lives on the DECLARE action. `defineConfig`
|
|
36
|
+
* still accepts a top-level `declaration`, but warns that it is deprecated
|
|
37
|
+
* and will stop accepting it in a future release.
|
|
38
|
+
*
|
|
39
|
+
* What it does:
|
|
40
|
+
* - Scans all TypeScript files under `src/`
|
|
41
|
+
* - Finds every call to the toolkit's `defineConfig` given an object literal
|
|
42
|
+
* with a top-level `declaration`
|
|
43
|
+
* - Moves that `declaration` property, as written, into the object literal
|
|
44
|
+
* of the DECLARE action in `actions`, after its `label` (or its `type` when
|
|
45
|
+
* it has no `label`)
|
|
46
|
+
* - Moves the comments on the lines above it and after it with it
|
|
47
|
+
* - Logs, without changing, configs it cannot rewrite safely: a config not
|
|
48
|
+
* given as an object literal, `actions` that is not an array literal, an
|
|
49
|
+
* action not written inline whose type does not rule out DECLARE, no
|
|
50
|
+
* DECLARE action or more than one, and a DECLARE action that already has
|
|
51
|
+
* a `declaration` (which `defineConfig` rejects)
|
|
52
|
+
* - Saves the modified files in-place
|
|
53
|
+
*/
|
|
54
|
+
const ts_morph_1 = require("ts-morph");
|
|
55
|
+
const path_1 = __importDefault(require("path"));
|
|
56
|
+
const utils_1 = require("./utils");
|
|
57
|
+
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
58
|
+
const DECLARATION_PROPERTY_NAME = 'declaration';
|
|
59
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
60
|
+
const DECLARE_ACTION_TYPE = 'DECLARE';
|
|
61
|
+
/**
|
|
62
|
+
* Finds the DECLARE action in `actions`, or logs why the config cannot be
|
|
63
|
+
* rewritten and returns undefined.
|
|
64
|
+
*/
|
|
65
|
+
function findDeclareAction(config) {
|
|
66
|
+
const actions = (0, utils_1.findProperty)(config, ACTIONS_PROPERTY_NAME);
|
|
67
|
+
const actionsValue = ts_morph_1.Node.isPropertyAssignment(actions)
|
|
68
|
+
? actions.getInitializer()
|
|
69
|
+
: undefined;
|
|
70
|
+
if (!ts_morph_1.Node.isArrayLiteralExpression(actionsValue)) {
|
|
71
|
+
console.warn(` [${(0, utils_1.location)(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. Move \`${DECLARATION_PROPERTY_NAME}\` onto the ${DECLARE_ACTION_TYPE} action by hand.`);
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
const candidates = actionsValue
|
|
75
|
+
.getElements()
|
|
76
|
+
.filter((element) => (0, utils_1.mayBeAction)(element, DECLARE_ACTION_TYPE));
|
|
77
|
+
if (candidates.length !== 1 ||
|
|
78
|
+
!ts_morph_1.Node.isObjectLiteralExpression(candidates[0])) {
|
|
79
|
+
console.warn(` [${(0, utils_1.location)(config)}] Skipped: could not find exactly one ${DECLARE_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME}\`. Move \`${DECLARATION_PROPERTY_NAME}\` onto it by hand.`);
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const declareAction = candidates[0];
|
|
83
|
+
if ((0, utils_1.findProperty)(declareAction, DECLARATION_PROPERTY_NAME)) {
|
|
84
|
+
console.warn(` [${(0, utils_1.location)(config)}] Skipped: \`${DECLARATION_PROPERTY_NAME}\` is set both at the top level and on the ${DECLARE_ACTION_TYPE} action. Keep only the one on the action.`);
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
return declareAction;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns the edits inserting the property into the DECLARE action after its
|
|
91
|
+
* `label`, or after its `type` when it has no `label`, in the action's own
|
|
92
|
+
* layout: on lines of its own at the anchor's indentation, together with its
|
|
93
|
+
* comments, or inline when the action is on one line.
|
|
94
|
+
*/
|
|
95
|
+
function insertIntoDeclareAction(declareAction, property) {
|
|
96
|
+
var _a;
|
|
97
|
+
// `type` is always there: it is how the DECLARE action was found
|
|
98
|
+
const anchor = (_a = declareAction.getProperty('label')) !== null && _a !== void 0 ? _a : declareAction.getPropertyOrThrow('type');
|
|
99
|
+
const text = property.getSourceFile().getFullText();
|
|
100
|
+
const anchorLayout = (0, utils_1.layoutOf)(anchor);
|
|
101
|
+
const layout = (0, utils_1.layoutOf)(property);
|
|
102
|
+
const indent = (0, utils_1.indentationOf)(anchor);
|
|
103
|
+
// Copied as text so the value keeps its formatting and its comments, with
|
|
104
|
+
// continuation lines re-indented from the property's indentation to the
|
|
105
|
+
// anchor's
|
|
106
|
+
const oldIndent = (0, utils_1.indentationOf)(property);
|
|
107
|
+
const reindent = (lines) => lines
|
|
108
|
+
.split('\n')
|
|
109
|
+
.map((line, index) => index > 0 && line.startsWith(oldIndent)
|
|
110
|
+
? indent + line.slice(oldIndent.length)
|
|
111
|
+
: line)
|
|
112
|
+
.join('\n');
|
|
113
|
+
if (anchorLayout.ownsLines) {
|
|
114
|
+
const moved = reindent(text.slice(layout.start, property.getEnd()));
|
|
115
|
+
const position = anchorLayout.end + (0, utils_1.restOfLine)(text, anchorLayout.end).length;
|
|
116
|
+
const insertion = `\n${indent}${moved}${anchorLayout.hasComma ? ',' : ''}${layout.trailingComment}`;
|
|
117
|
+
if (anchorLayout.hasComma) {
|
|
118
|
+
return [(0, utils_1.insertAt)(position, insertion)];
|
|
119
|
+
}
|
|
120
|
+
// The anchor was the last property: it needs a comma now
|
|
121
|
+
return position === anchor.getEnd()
|
|
122
|
+
? [(0, utils_1.insertAt)(position, `,${insertion}`)]
|
|
123
|
+
: [(0, utils_1.insertAt)(anchor.getEnd(), ','), (0, utils_1.insertAt)(position, insertion)];
|
|
124
|
+
}
|
|
125
|
+
const droppedComments = text.slice(layout.start, property.getStart(true)).trim() !== '' ||
|
|
126
|
+
layout.trailingComment !== '';
|
|
127
|
+
if (droppedComments) {
|
|
128
|
+
console.warn(` [${(0, utils_1.location)(property)}] The comments next to \`${DECLARATION_PROPERTY_NAME}\` were not moved with it. Move them onto the ${DECLARE_ACTION_TYPE} action by hand.`);
|
|
129
|
+
}
|
|
130
|
+
const isMultiLine = declareAction.getText().includes('\n');
|
|
131
|
+
const separator = isMultiLine ? `,\n${indent}` : ', ';
|
|
132
|
+
return [
|
|
133
|
+
(0, utils_1.insertAt)(anchor.getEnd(), `${separator}${reindent(property.getText(true))}`)
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns the edits removing the property together with the comma separating
|
|
138
|
+
* it from its neighbours and, when it is on lines of its own, those lines.
|
|
139
|
+
*/
|
|
140
|
+
function removeFromConfig(property) {
|
|
141
|
+
var _a;
|
|
142
|
+
const text = property.getSourceFile().getFullText();
|
|
143
|
+
const layout = (0, utils_1.layoutOf)(property);
|
|
144
|
+
// The comma before the property, past any comments, which ts-morph lists
|
|
145
|
+
// as siblings
|
|
146
|
+
const previousComma = (_a = property
|
|
147
|
+
.getPreviousSiblings()
|
|
148
|
+
.find((sibling) => !(0, utils_1.isOnlyComments)(sibling.getText()))) === null || _a === void 0 ? void 0 : _a.asKind(ts_morph_1.SyntaxKind.CommaToken);
|
|
149
|
+
if (layout.ownsLines) {
|
|
150
|
+
const lines = {
|
|
151
|
+
start: text.lastIndexOf('\n', layout.start - 1),
|
|
152
|
+
end: layout.end + (0, utils_1.restOfLine)(text, layout.end).length,
|
|
153
|
+
text: ''
|
|
154
|
+
};
|
|
155
|
+
// The last property: drop the comma before it too
|
|
156
|
+
return !layout.hasComma && previousComma
|
|
157
|
+
? [
|
|
158
|
+
lines,
|
|
159
|
+
{
|
|
160
|
+
start: previousComma.getStart(),
|
|
161
|
+
end: previousComma.getEnd(),
|
|
162
|
+
text: ''
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
: [lines];
|
|
166
|
+
}
|
|
167
|
+
if (layout.hasComma) {
|
|
168
|
+
return [{ start: property.getFullStart(), end: layout.end, text: '' }];
|
|
169
|
+
}
|
|
170
|
+
// The last property: drop the comma before it instead
|
|
171
|
+
return [
|
|
172
|
+
{
|
|
173
|
+
start: (previousComma !== null && previousComma !== void 0 ? previousComma : property).getStart(),
|
|
174
|
+
end: property.getEnd(),
|
|
175
|
+
text: ''
|
|
176
|
+
}
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Returns the config given to a toolkit `defineConfig` call when it is an
|
|
181
|
+
* object literal. Logs a config given any other way that may have a top-level
|
|
182
|
+
* `declaration`, as it cannot be rewritten.
|
|
183
|
+
*/
|
|
184
|
+
function findConfigLiteral(call) {
|
|
185
|
+
const config = call.getArguments()[0];
|
|
186
|
+
if (!config || ts_morph_1.Node.isObjectLiteralExpression(config)) {
|
|
187
|
+
return config;
|
|
188
|
+
}
|
|
189
|
+
if (config.getType().getProperty(DECLARATION_PROPERTY_NAME)) {
|
|
190
|
+
console.warn(` [${(0, utils_1.location)(config)}] Skipped: \`${DEFINE_CONFIG_NAME}\` is not given an object literal. If its config has a top-level \`${DECLARATION_PROPERTY_NAME}\`, move it onto the ${DECLARE_ACTION_TYPE} action by hand.`);
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Moves the top-level `declaration` of every toolkit `defineConfig` call in the
|
|
196
|
+
* file onto its DECLARE action.
|
|
197
|
+
*
|
|
198
|
+
* @returns the number of event configs rewritten.
|
|
199
|
+
*/
|
|
200
|
+
function moveDeclarationToDeclareAction(sourceFile) {
|
|
201
|
+
const configs = sourceFile
|
|
202
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
|
|
203
|
+
.filter(utils_1.isToolkitDefineConfigCall)
|
|
204
|
+
.map(findConfigLiteral)
|
|
205
|
+
.filter(ts_morph_1.Node.isObjectLiteralExpression);
|
|
206
|
+
const edits = [];
|
|
207
|
+
let changes = 0;
|
|
208
|
+
for (const config of configs) {
|
|
209
|
+
const declaration = (0, utils_1.findProperty)(config, DECLARATION_PROPERTY_NAME);
|
|
210
|
+
if (!declaration) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const declareAction = findDeclareAction(config);
|
|
214
|
+
if (!declareAction) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
console.log(` [${(0, utils_1.location)(declaration)}] Moved \`${declaration.getText()}\` onto the ${DECLARE_ACTION_TYPE} action`);
|
|
218
|
+
edits.push(...insertIntoDeclareAction(declareAction, declaration), ...removeFromConfig(declaration));
|
|
219
|
+
changes++;
|
|
220
|
+
}
|
|
221
|
+
if (changes === 0) {
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
(0, utils_1.applyTextEdits)(sourceFile, edits);
|
|
225
|
+
return changes;
|
|
226
|
+
}
|
|
227
|
+
function main() {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
230
|
+
console.log(`Scanning for top-level event declarations in: ${srcDir}\n`);
|
|
231
|
+
const project = new ts_morph_1.Project({
|
|
232
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
233
|
+
skipAddingFilesFromTsConfig: false
|
|
234
|
+
});
|
|
235
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
236
|
+
const fp = sf.getFilePath();
|
|
237
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
238
|
+
});
|
|
239
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
240
|
+
let totalChanges = 0;
|
|
241
|
+
const modifiedFiles = [];
|
|
242
|
+
for (const sourceFile of sourceFiles) {
|
|
243
|
+
const changes = moveDeclarationToDeclareAction(sourceFile);
|
|
244
|
+
if (changes > 0) {
|
|
245
|
+
totalChanges += changes;
|
|
246
|
+
modifiedFiles.push(sourceFile);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (modifiedFiles.length === 0) {
|
|
250
|
+
console.log('No top-level event declarations found. Nothing to do.');
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
254
|
+
for (const sourceFile of modifiedFiles) {
|
|
255
|
+
yield sourceFile.save();
|
|
256
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), sourceFile.getFilePath())}`);
|
|
257
|
+
}
|
|
258
|
+
console.log(`\nDone. Moved ${totalChanges} declaration(s) across ${modifiedFiles.length} file(s).`);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
@@ -4,6 +4,12 @@ import { CsvFile } from '../../csv';
|
|
|
4
4
|
* local file's columns.
|
|
5
5
|
*/
|
|
6
6
|
export declare function rowsToAdd(local: CsvFile, template: CsvFile): string[];
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @param targetVersion the major.minor the country config is upgraded to, e.g. `2.2`.
|
|
9
|
+
*/
|
|
10
|
+
declare function main(targetVersion: string): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* @knipignore
|
|
13
|
+
*/
|
|
8
14
|
export { main };
|
|
9
15
|
//# sourceMappingURL=add-translations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-translations.d.ts","sourceRoot":"","sources":["../../../src/migrations/persistent/add-translations.ts"],"names":[],"mappings":"AAkCA,OAAO,EACL,OAAO,EAMR,MAAM,WAAW,CAAA;AAYlB;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAgBrE;AAqED;;GAEG;AACH,iBAAe,IAAI,CAAC,aAAa,EAAE,MAAM,iBA2BxC;AAED;;GAEG;AACH,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -29,8 +29,9 @@ exports.main = main;
|
|
|
29
29
|
* config.
|
|
30
30
|
*
|
|
31
31
|
* Unlike every other codemod, this one carries no list of what it changes, and
|
|
32
|
-
* should not need editing again
|
|
33
|
-
*
|
|
32
|
+
* should not need editing again: every version's upgrade runs it, passing the
|
|
33
|
+
* version it upgrades to. Its input is `client.csv` and `login.csv` from
|
|
34
|
+
* the country config template of that version, fetched from
|
|
34
35
|
* GitHub; whatever rows those files have gained, this adds. A pull request that
|
|
35
36
|
* introduces a translation key therefore only has to add it to the template —
|
|
36
37
|
* `packages/countryconfig-template/src/translations/` — which the
|
|
@@ -48,8 +49,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
48
49
|
const csv_1 = require("../../csv");
|
|
49
50
|
const template_1 = require("../../translations/template");
|
|
50
51
|
const APPLICATIONS = ['client', 'login'];
|
|
51
|
-
/** The version this folder upgrades a country config to. */
|
|
52
|
-
const TARGET_VERSION = '2.1';
|
|
53
52
|
const skipped = [];
|
|
54
53
|
function warnSkipped(message) {
|
|
55
54
|
skipped.push(message);
|
|
@@ -73,7 +72,7 @@ function rowsToAdd(local, template) {
|
|
|
73
72
|
}));
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
|
-
function updateApplication(cwd, refs, application) {
|
|
75
|
+
function updateApplication(cwd, targetVersion, refs, application) {
|
|
77
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
77
|
const relativePath = `src/translations/${application}.csv`;
|
|
79
78
|
const local = (0, csv_1.readCsvFile)(path_1.default.join(cwd, relativePath));
|
|
@@ -83,7 +82,7 @@ function updateApplication(cwd, refs, application) {
|
|
|
83
82
|
}
|
|
84
83
|
const fetched = yield (0, template_1.fetchTemplate)(refs, application);
|
|
85
84
|
if (!fetched) {
|
|
86
|
-
warnSkipped(`No ${application}.csv found in the ${
|
|
85
|
+
warnSkipped(`No ${application}.csv found in the ${targetVersion} country config template on GitHub; ${application}.csv not updated`);
|
|
87
86
|
return;
|
|
88
87
|
}
|
|
89
88
|
const template = readTemplate(fetched.contents);
|
|
@@ -113,26 +112,29 @@ function readTemplate(contents) {
|
|
|
113
112
|
};
|
|
114
113
|
}
|
|
115
114
|
/** Refs to read the template from. Undefined when GitHub cannot be asked. */
|
|
116
|
-
function listRefs() {
|
|
115
|
+
function listRefs(targetVersion) {
|
|
117
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
117
|
try {
|
|
119
|
-
return yield (0, template_1.candidateRefs)(
|
|
118
|
+
return yield (0, template_1.candidateRefs)(targetVersion);
|
|
120
119
|
}
|
|
121
120
|
catch (error) {
|
|
122
|
-
warnSkipped(`Could not list the ${
|
|
121
|
+
warnSkipped(`Could not list the ${targetVersion} refs on GitHub (${error.message}); translations not added`);
|
|
123
122
|
return undefined;
|
|
124
123
|
}
|
|
125
124
|
});
|
|
126
125
|
}
|
|
127
|
-
|
|
126
|
+
/**
|
|
127
|
+
* @param targetVersion the major.minor the country config is upgraded to, e.g. `2.2`.
|
|
128
|
+
*/
|
|
129
|
+
function main(targetVersion) {
|
|
128
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
131
|
const cwd = process.cwd();
|
|
130
132
|
console.log('Adding the translation keys core gained this version...\n');
|
|
131
|
-
const refs = yield listRefs();
|
|
133
|
+
const refs = yield listRefs(targetVersion);
|
|
132
134
|
if (refs) {
|
|
133
135
|
for (const application of APPLICATIONS) {
|
|
134
136
|
try {
|
|
135
|
-
yield updateApplication(cwd, refs, application);
|
|
137
|
+
yield updateApplication(cwd, targetVersion, refs, application);
|
|
136
138
|
}
|
|
137
139
|
catch (error) {
|
|
138
140
|
warnSkipped(`Could not read ${application}.csv from the country config template on GitHub (${error.message}); ${application}.csv not updated`);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const TOOLKIT_PACKAGE_NAME = "@opencrvs/toolkit";
|
|
2
|
+
interface MajorMinor {
|
|
3
|
+
major: number;
|
|
4
|
+
minor: number;
|
|
5
|
+
}
|
|
6
|
+
export type UpgradePathCheck = {
|
|
7
|
+
status: 'ok';
|
|
8
|
+
} | {
|
|
9
|
+
status: 'unknown';
|
|
10
|
+
message: string;
|
|
11
|
+
} | {
|
|
12
|
+
status: 'blocked';
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Reads the major.minor out of a version or a version range, e.g. `2.1` out of
|
|
17
|
+
* `2.1.0`, `^2.1.3` or `2.2.0-rc.1`. Returns undefined when there is none, as
|
|
18
|
+
* in `workspace:*` or `latest`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function findMajorMinor(version: string): MajorMinor | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the `@opencrvs/toolkit` version the country config in the directory
|
|
23
|
+
* depends on, as written in its `package.json`, or undefined when it has none.
|
|
24
|
+
*/
|
|
25
|
+
export declare function findCountryConfigToolkitVersion(cwd: string): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Checks that the country config is on the minor version before the toolkit's,
|
|
28
|
+
* or already on the toolkit's: the steps are idempotent, so running them again
|
|
29
|
+
* after a patch release is safe.
|
|
30
|
+
*
|
|
31
|
+
* @param countryConfigToolkitVersion the toolkit version the country config depends on.
|
|
32
|
+
* @param toolkitVersion the version of the toolkit running the upgrade.
|
|
33
|
+
*/
|
|
34
|
+
export declare function checkUpgradePath(countryConfigToolkitVersion: string | undefined, toolkitVersion: string): UpgradePathCheck;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=check-upgrade-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-upgrade-path.d.ts","sourceRoot":"","sources":["../../../src/migrations/persistent/check-upgrade-path.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,oBAAoB,sBAAsB,CAAA;AAEvD,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,GAChB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAE1C;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAMtE;AAMD;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,SAAS,CAapB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,2BAA2B,EAAE,MAAM,GAAG,SAAS,EAC/C,cAAc,EAAE,MAAM,GACrB,gBAAgB,CAoDlB"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TOOLKIT_PACKAGE_NAME = void 0;
|
|
17
|
+
exports.findMajorMinor = findMajorMinor;
|
|
18
|
+
exports.findCountryConfigToolkitVersion = findCountryConfigToolkitVersion;
|
|
19
|
+
exports.checkUpgradePath = checkUpgradePath;
|
|
20
|
+
/**
|
|
21
|
+
* Checks that a country config is upgraded one minor version at a time, as the
|
|
22
|
+
* documentation recommends. The toolkit only carries the steps from the
|
|
23
|
+
* previous minor to its own, so upgrading from further back would silently skip
|
|
24
|
+
* the steps of the versions in between.
|
|
25
|
+
*/
|
|
26
|
+
const fs_1 = __importDefault(require("fs"));
|
|
27
|
+
const path_1 = __importDefault(require("path"));
|
|
28
|
+
exports.TOOLKIT_PACKAGE_NAME = '@opencrvs/toolkit';
|
|
29
|
+
/**
|
|
30
|
+
* Reads the major.minor out of a version or a version range, e.g. `2.1` out of
|
|
31
|
+
* `2.1.0`, `^2.1.3` or `2.2.0-rc.1`. Returns undefined when there is none, as
|
|
32
|
+
* in `workspace:*` or `latest`.
|
|
33
|
+
*/
|
|
34
|
+
function findMajorMinor(version) {
|
|
35
|
+
const match = /(\d+)\.(\d+)/.exec(version);
|
|
36
|
+
return match
|
|
37
|
+
? { major: Number(match[1]), minor: Number(match[2]) }
|
|
38
|
+
: undefined;
|
|
39
|
+
}
|
|
40
|
+
function format({ major, minor }) {
|
|
41
|
+
return `${major}.${minor}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the `@opencrvs/toolkit` version the country config in the directory
|
|
45
|
+
* depends on, as written in its `package.json`, or undefined when it has none.
|
|
46
|
+
*/
|
|
47
|
+
function findCountryConfigToolkitVersion(cwd) {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
var _c;
|
|
50
|
+
try {
|
|
51
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(cwd, 'package.json'), 'utf-8'));
|
|
52
|
+
return ((_c = (_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a[exports.TOOLKIT_PACKAGE_NAME]) !== null && _c !== void 0 ? _c : (_b = packageJson.devDependencies) === null || _b === void 0 ? void 0 : _b[exports.TOOLKIT_PACKAGE_NAME]);
|
|
53
|
+
}
|
|
54
|
+
catch (_d) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks that the country config is on the minor version before the toolkit's,
|
|
60
|
+
* or already on the toolkit's: the steps are idempotent, so running them again
|
|
61
|
+
* after a patch release is safe.
|
|
62
|
+
*
|
|
63
|
+
* @param countryConfigToolkitVersion the toolkit version the country config depends on.
|
|
64
|
+
* @param toolkitVersion the version of the toolkit running the upgrade.
|
|
65
|
+
*/
|
|
66
|
+
function checkUpgradePath(countryConfigToolkitVersion, toolkitVersion) {
|
|
67
|
+
const target = findMajorMinor(toolkitVersion);
|
|
68
|
+
const current = countryConfigToolkitVersion
|
|
69
|
+
? findMajorMinor(countryConfigToolkitVersion)
|
|
70
|
+
: undefined;
|
|
71
|
+
if (!target || !current) {
|
|
72
|
+
return {
|
|
73
|
+
status: 'unknown',
|
|
74
|
+
message: `Could not tell which version the country config is on from its ${exports.TOOLKIT_PACKAGE_NAME} dependency (${countryConfigToolkitVersion !== null && countryConfigToolkitVersion !== void 0 ? countryConfigToolkitVersion : 'not found'}). Make sure it is on the version before ${toolkitVersion}: upgrade one minor version at a time.`
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const isSameVersion = current.major === target.major && current.minor === target.minor;
|
|
78
|
+
const isPreviousMinor = current.major === target.major && current.minor === target.minor - 1;
|
|
79
|
+
// Which minor a major ends on is not known here, so any minor of the
|
|
80
|
+
// previous major is let through to the next major's x.0
|
|
81
|
+
const isPreviousMajor = target.minor === 0 && current.major === target.major - 1;
|
|
82
|
+
if (isSameVersion || isPreviousMinor || isPreviousMajor) {
|
|
83
|
+
return { status: 'ok' };
|
|
84
|
+
}
|
|
85
|
+
const isNewer = current.major > target.major ||
|
|
86
|
+
(current.major === target.major && current.minor > target.minor);
|
|
87
|
+
if (isNewer) {
|
|
88
|
+
return {
|
|
89
|
+
status: 'blocked',
|
|
90
|
+
message: `The country config is already on ${format(current)}, newer than toolkit ${toolkitVersion}. Run the upgrade with the toolkit of the version you are upgrading to.`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const upgradesFrom = target.minor > 0
|
|
94
|
+
? format({ major: target.major, minor: target.minor - 1 })
|
|
95
|
+
: `the last ${target.major - 1}.x`;
|
|
96
|
+
// Which minor a major ends on is not known here, so the next version is
|
|
97
|
+
// named only within a major
|
|
98
|
+
const nextStep = current.major === target.major
|
|
99
|
+
? `: run \`npx ${exports.TOOLKIT_PACKAGE_NAME}@${format({ major: current.major, minor: current.minor + 1 })} upgrade\` first`
|
|
100
|
+
: '';
|
|
101
|
+
return {
|
|
102
|
+
status: 'blocked',
|
|
103
|
+
message: `The country config is on ${format(current)}, but toolkit ${toolkitVersion} only upgrades from ${upgradesFrom}. Upgrade one minor version at a time${nextStep}.`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the `package.json` text with its toolkit dependency set to the
|
|
3
|
+
* version, or undefined when there is nothing to update.
|
|
4
|
+
*/
|
|
5
|
+
export declare function updateToolkitDependency(packageJson: string, toolkitVersion: string): string | undefined;
|
|
6
|
+
export declare function main(toolkitVersion: string): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=update-toolkit-dependency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-toolkit-dependency.d.ts","sourceRoot":"","sources":["../../../src/migrations/persistent/update-toolkit-dependency.ts"],"names":[],"mappings":"AAoCA;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,GACrB,MAAM,GAAG,SAAS,CAepB;AAED,wBAAsB,IAAI,CAAC,cAAc,EAAE,MAAM,iBAwBhD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.updateToolkitDependency = updateToolkitDependency;
|
|
26
|
+
exports.main = main;
|
|
27
|
+
/**
|
|
28
|
+
* Upgrade step: Point the country config's `@opencrvs/toolkit` dependency at
|
|
29
|
+
* the toolkit running the upgrade.
|
|
30
|
+
*
|
|
31
|
+
* Why:
|
|
32
|
+
* The upgrade checks which version it upgrades from by the toolkit version
|
|
33
|
+
* the country config depends on. Updating it here, rather than by hand before
|
|
34
|
+
* upgrading, keeps that version the one the country config was on until its
|
|
35
|
+
* steps have run.
|
|
36
|
+
*
|
|
37
|
+
* What it does:
|
|
38
|
+
* - Rewrites the version of `@opencrvs/toolkit` in `package.json`, keeping a
|
|
39
|
+
* `^` or `~` in front of it and the rest of the file as written
|
|
40
|
+
* - Leaves a version without a major.minor alone, as in `workspace:*`
|
|
41
|
+
*/
|
|
42
|
+
const fs_1 = __importDefault(require("fs"));
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
44
|
+
const check_upgrade_path_1 = require("./check-upgrade-path");
|
|
45
|
+
const DEPENDENCY_PATTERN = new RegExp(`("${check_upgrade_path_1.TOOLKIT_PACKAGE_NAME}"\\s*:\\s*")([^"]*)(")`, 'g');
|
|
46
|
+
/**
|
|
47
|
+
* Returns the `package.json` text with its toolkit dependency set to the
|
|
48
|
+
* version, or undefined when there is nothing to update.
|
|
49
|
+
*/
|
|
50
|
+
function updateToolkitDependency(packageJson, toolkitVersion) {
|
|
51
|
+
const updated = packageJson.replace(DEPENDENCY_PATTERN, (match, before, version, after) => {
|
|
52
|
+
var _a;
|
|
53
|
+
var _b;
|
|
54
|
+
if (!(0, check_upgrade_path_1.findMajorMinor)(version)) {
|
|
55
|
+
return match;
|
|
56
|
+
}
|
|
57
|
+
const range = (_b = (_a = /^[\^~]?/.exec(version)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
|
|
58
|
+
return `${before}${range}${toolkitVersion}${after}`;
|
|
59
|
+
});
|
|
60
|
+
return updated === packageJson ? undefined : updated;
|
|
61
|
+
}
|
|
62
|
+
function main(toolkitVersion) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const packageJsonPath = path_1.default.join(process.cwd(), 'package.json');
|
|
65
|
+
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
66
|
+
console.log(`No package.json found. Skipping ${check_upgrade_path_1.TOOLKIT_PACKAGE_NAME}.`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const updated = updateToolkitDependency(fs_1.default.readFileSync(packageJsonPath, 'utf-8'), toolkitVersion);
|
|
70
|
+
if (!updated) {
|
|
71
|
+
console.log(`${check_upgrade_path_1.TOOLKIT_PACKAGE_NAME} in package.json needs no update. Nothing to do.`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
fs_1.default.writeFileSync(packageJsonPath, updated);
|
|
75
|
+
console.log(`Updated ${check_upgrade_path_1.TOOLKIT_PACKAGE_NAME} to ${toolkitVersion} in package.json. Install the dependencies again to use it.`);
|
|
76
|
+
});
|
|
77
|
+
}
|