@opencrvs/toolkit 2.2.0-rc.ab91cce → 2.2.0-rc.e6591c5
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 +17 -14
- 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 +2631 -377
- 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 +7 -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 +68 -21
- 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 +448 -1
- 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 +4 -1
- package/dist/commons/events/eventConfigValidation.d.ts +9 -0
- package/dist/commons/events/field.d.ts +5 -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 +85 -8
- package/dist/commons/events/toNotificationForm.d.ts +17 -0
- package/dist/commons/events/utils.d.ts +88 -8
- 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 +19 -7
- package/dist/configurator/index.d.ts +24 -0
- package/dist/configurator/index.d.ts.map +1 -0
- package/dist/configurator/index.js +161 -0
- package/dist/configurator/layout.d.ts +29 -0
- package/dist/configurator/layout.d.ts.map +1 -0
- package/dist/configurator/layout.js +78 -0
- package/dist/configurator/paths.d.ts +13 -0
- package/dist/configurator/paths.d.ts.map +1 -0
- package/dist/configurator/paths.js +48 -0
- package/dist/configurator/server/environments.d.ts +20 -0
- package/dist/configurator/server/environments.d.ts.map +1 -0
- package/dist/configurator/server/environments.js +143 -0
- package/dist/configurator/server/files.d.ts +11 -0
- package/dist/configurator/server/files.d.ts.map +1 -0
- package/dist/configurator/server/files.js +67 -0
- package/dist/configurator/server/github.d.ts +56 -0
- package/dist/configurator/server/github.d.ts.map +1 -0
- package/dist/configurator/server/github.js +239 -0
- package/dist/configurator/server/plugin.d.ts +39 -0
- package/dist/configurator/server/plugin.d.ts.map +1 -0
- package/dist/configurator/server/plugin.js +298 -0
- package/dist/configurator/server/seal.d.ts +2 -0
- package/dist/configurator/server/seal.d.ts.map +1 -0
- package/dist/configurator/server/seal.js +36 -0
- package/dist/configurator/server/sshKeys.d.ts +5 -0
- package/dist/configurator/server/sshKeys.d.ts.map +1 -0
- package/dist/configurator/server/sshKeys.js +28 -0
- package/dist/configurator/server/start.d.ts +12 -0
- package/dist/configurator/server/start.d.ts.map +1 -0
- package/dist/configurator/server/start.js +91 -0
- package/dist/configurator/testing.d.ts +11 -0
- package/dist/configurator/testing.d.ts.map +1 -0
- package/dist/configurator/testing.js +74 -0
- package/dist/configurator/ui/bindings/bindings.d.ts +35 -0
- package/dist/configurator/ui/bindings/bindings.d.ts.map +1 -0
- package/dist/configurator/ui/bindings/bindings.js +5 -0
- package/dist/configurator/ui/bindings/parsers.d.ts +7 -0
- package/dist/configurator/ui/bindings/parsers.d.ts.map +1 -0
- package/dist/configurator/ui/bindings/parsers.js +85 -0
- package/dist/configurator/ui/form/users.d.ts +11 -0
- package/dist/configurator/ui/form/users.d.ts.map +1 -0
- package/dist/configurator/ui/form/users.js +33 -0
- package/dist/configurator/ui/plan/dependencyHosts.d.ts +2 -0
- package/dist/configurator/ui/plan/dependencyHosts.d.ts.map +1 -0
- package/dist/configurator/ui/plan/dependencyHosts.js +36 -0
- package/dist/configurator/ui/plan/templateValues.d.ts +11 -0
- package/dist/configurator/ui/plan/templateValues.d.ts.map +1 -0
- package/dist/configurator/ui/plan/templateValues.js +70 -0
- package/dist/configurator/workflows.d.ts +54 -0
- package/dist/configurator/workflows.d.ts.map +1 -0
- package/dist/configurator/workflows.js +161 -0
- package/dist/configurator-assets/forms/bindings.yml +265 -0
- package/dist/configurator-assets/templates/README.md +18 -0
- package/dist/configurator-assets/templates/charts-values/dependencies/values.override.yaml +4 -0
- package/dist/configurator-assets/templates/charts-values/dependencies/values.yaml +96 -0
- package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
- package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.yaml +83 -0
- package/dist/configurator-assets/templates/charts-values/opentelemetry/values.yaml +102 -0
- package/dist/configurator-assets/templates/charts-values/traefik/values.override.yaml +4 -0
- package/dist/configurator-assets/templates/charts-values/traefik/values.yaml +130 -0
- package/dist/configurator-assets/templates/inventory/inventory.template.yml +98 -0
- package/dist/configurator-assets/ui/apple-touch-icon.png +0 -0
- package/dist/configurator-assets/ui/assets/index-CaqYFJUk.css +6 -0
- package/dist/configurator-assets/ui/assets/index-DU1Y6E0b.js +169 -0
- package/dist/configurator-assets/ui/assets/opencrvs-logo-sIjz08HT.svg +1 -0
- package/dist/configurator-assets/ui/assets/poppins-400-BwTUGeWf.woff2 +0 -0
- package/dist/configurator-assets/ui/assets/poppins-500-CWICHMj6.woff2 +0 -0
- package/dist/configurator-assets/ui/assets/poppins-600-DJVo7c07.woff2 +0 -0
- package/dist/configurator-assets/ui/assets/poppins-700-g9MkRaG0.woff2 +0 -0
- package/dist/configurator-assets/ui/favicon-32x32.png +0 -0
- package/dist/configurator-assets/ui/index.html +25 -0
- 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 +18 -4
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +20 -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 +145 -25
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +957 -215
- 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/{add-translations.d.ts → persistent/add-translations.d.ts} +1 -1
- package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
- package/dist/migrations/{add-translations.js → persistent/add-translations.js} +2 -2
- 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/{v2.2/read-declaration-through-helper.d.ts → read-declaration-through-helper.d.ts} +1 -1
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
- package/dist/migrations/{v2.2/read-declaration-through-helper.js → read-declaration-through-helper.js} +4 -62
- 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 +810 -84
- 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 +5 -2
- package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -7
- package/dist/templates/charts-values/traefik/values.yaml +2 -0
- 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.e6591c5.tgz +0 -0
- package/package.json +17 -4
- package/tsconfig.build.json +11 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +15 -6
- package/dist/migrations/add-translations.d.ts.map +0 -1
- 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/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 -50
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -17
- 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 -11
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
- package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
- package/dist/migrations/v2.2/index.d.ts +0 -6
- package/dist/migrations/v2.2/index.d.ts.map +0 -1
- package/dist/migrations/v2.2/index.js +0 -456
- package/dist/migrations/v2.2/read-declaration-through-helper.d.ts.map +0 -1
- 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.2.0-rc.ab91cce.tgz +0 -0
|
@@ -1,139 +0,0 @@
|
|
|
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.renderTiltfile = renderTiltfile;
|
|
26
|
-
exports.withIgnoreEntry = withIgnoreEntry;
|
|
27
|
-
exports.upgradeTilt = upgradeTilt;
|
|
28
|
-
exports.main = main;
|
|
29
|
-
/**
|
|
30
|
-
* Codemod: bring the local Tilt setup in line with the country config template.
|
|
31
|
-
*
|
|
32
|
-
* Up to v2.0 the Tiltfile cloned opencrvs/opencrvs-helm-charts into a sibling
|
|
33
|
-
* `../opencrvs-helm-charts` directory and loaded its `tilt/opencrvs.tilt`. The
|
|
34
|
-
* charts now live in opencrvs-core, and the Tilt helpers ship with the country
|
|
35
|
-
* config itself under `tilt/`.
|
|
36
|
-
*
|
|
37
|
-
* What it does:
|
|
38
|
-
* 1. Replaces `Tiltfile` with the template's, carrying over the country's
|
|
39
|
-
* `countryconfig_image_name`.
|
|
40
|
-
* 2. Replaces every file under `tilt/` that core owns (the helpers and
|
|
41
|
-
* `tilt/examples/`) with the template's.
|
|
42
|
-
* 3. Creates `tilt/helm/<chart>/values.yaml` when missing. These hold the
|
|
43
|
-
* country's own overrides and are never overwritten.
|
|
44
|
-
* 4. Adds `.opencrvs-core-charts/` (the Tiltfile's charts checkout) to
|
|
45
|
-
* `.tiltignore` and `.gitignore`.
|
|
46
|
-
*
|
|
47
|
-
* The template files are bundled into the toolkit at build time, so they always
|
|
48
|
-
* match the toolkit version being run.
|
|
49
|
-
*
|
|
50
|
-
* Caveats:
|
|
51
|
-
* - Local changes to the Tiltfile or to core owned files under `tilt/` are
|
|
52
|
-
* overwritten. Review them with `git diff -- Tiltfile tilt/` and move
|
|
53
|
-
* chart overrides into `tilt/helm/`.
|
|
54
|
-
* - Files under `tilt/` that the template does not have are left in place.
|
|
55
|
-
*/
|
|
56
|
-
const fs_1 = require("fs");
|
|
57
|
-
const path_1 = __importDefault(require("path"));
|
|
58
|
-
const template_files_1 = require("./template-files");
|
|
59
|
-
/** Paths under `tilt/` the country owns: created when missing, never replaced. */
|
|
60
|
-
const COUNTRY_OWNED_DIR = 'tilt/helm/';
|
|
61
|
-
const CHARTS_CHECKOUT_DIR = '.opencrvs-core-charts';
|
|
62
|
-
const IMAGE_NAME_PATTERN = /^countryconfig_image_name\s*=\s*(["'])(.*?)\1/m;
|
|
63
|
-
function writeIfChanged(cwd, relativePath, contents, mode) {
|
|
64
|
-
const target = path_1.default.join(cwd, relativePath);
|
|
65
|
-
const existed = (0, fs_1.existsSync)(target);
|
|
66
|
-
if (existed && (0, fs_1.readFileSync)(target, 'utf8') === contents) {
|
|
67
|
-
return 'unchanged';
|
|
68
|
-
}
|
|
69
|
-
(0, fs_1.mkdirSync)(path_1.default.dirname(target), { recursive: true });
|
|
70
|
-
(0, fs_1.writeFileSync)(target, contents);
|
|
71
|
-
// Keeps shell scripts such as clear-all-data.sh executable
|
|
72
|
-
if (mode !== undefined) {
|
|
73
|
-
(0, fs_1.chmodSync)(target, mode & 0o777);
|
|
74
|
-
}
|
|
75
|
-
return existed ? 'updated' : 'created';
|
|
76
|
-
}
|
|
77
|
-
function report(relativePath, change) {
|
|
78
|
-
if (change !== 'unchanged') {
|
|
79
|
-
console.log(` ✓ ${change} ${relativePath}`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/** TODO: ????? The template Tiltfile, keeping the image name the country already uses. */
|
|
83
|
-
function renderTiltfile(template, existing) {
|
|
84
|
-
var _a;
|
|
85
|
-
const imageName = (_a = existing === null || existing === void 0 ? void 0 : existing.match(IMAGE_NAME_PATTERN)) === null || _a === void 0 ? void 0 : _a[2];
|
|
86
|
-
if (!imageName) {
|
|
87
|
-
return template;
|
|
88
|
-
}
|
|
89
|
-
return template.replace(IMAGE_NAME_PATTERN, (_line, quote) => `countryconfig_image_name=${quote}${imageName}${quote}`);
|
|
90
|
-
}
|
|
91
|
-
/** `contents` with `line` appended, unless an equivalent entry is there already. */
|
|
92
|
-
function withIgnoreEntry(contents, line) {
|
|
93
|
-
const normalise = (entry) => entry.trim().replace(/^\//, '').replace(/\/$/, '');
|
|
94
|
-
const alreadyIgnored = contents
|
|
95
|
-
.split(/\r?\n/)
|
|
96
|
-
.some((entry) => normalise(entry) === normalise(line));
|
|
97
|
-
if (alreadyIgnored) {
|
|
98
|
-
return contents;
|
|
99
|
-
}
|
|
100
|
-
const separator = contents === '' || contents.endsWith('\n') ? '' : '\n';
|
|
101
|
-
return `${contents}${separator}${line}\n`;
|
|
102
|
-
}
|
|
103
|
-
function ensureIgnored(cwd, file, line) {
|
|
104
|
-
const target = path_1.default.join(cwd, file);
|
|
105
|
-
const contents = (0, fs_1.existsSync)(target) ? (0, fs_1.readFileSync)(target, 'utf8') : '';
|
|
106
|
-
report(file, writeIfChanged(cwd, file, withIgnoreEntry(contents, line)));
|
|
107
|
-
}
|
|
108
|
-
function upgradeTilt(cwd, templateDir) {
|
|
109
|
-
const tiltfilePath = path_1.default.join(cwd, 'Tiltfile');
|
|
110
|
-
const existingTiltfile = (0, fs_1.existsSync)(tiltfilePath)
|
|
111
|
-
? (0, fs_1.readFileSync)(tiltfilePath, 'utf8')
|
|
112
|
-
: undefined;
|
|
113
|
-
report('Tiltfile', writeIfChanged(cwd, 'Tiltfile', renderTiltfile((0, fs_1.readFileSync)(path_1.default.join(templateDir, 'Tiltfile'), 'utf8'), existingTiltfile)));
|
|
114
|
-
const templateFiles = (0, template_files_1.listFiles)(templateDir, 'tilt');
|
|
115
|
-
for (const file of templateFiles) {
|
|
116
|
-
const source = path_1.default.join(templateDir, file);
|
|
117
|
-
const countryOwned = file.startsWith(COUNTRY_OWNED_DIR);
|
|
118
|
-
if (countryOwned && (0, fs_1.existsSync)(path_1.default.join(cwd, file))) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
report(file, writeIfChanged(cwd, file, (0, fs_1.readFileSync)(source, 'utf8'), (0, fs_1.statSync)(source).mode));
|
|
122
|
-
}
|
|
123
|
-
const unknownFiles = (0, template_files_1.listFiles)(cwd, 'tilt').filter((file) => !file.startsWith(COUNTRY_OWNED_DIR) && !templateFiles.includes(file));
|
|
124
|
-
for (const file of unknownFiles) {
|
|
125
|
-
console.warn(` ⚠️ ${file} is not part of the template and was left in place.`);
|
|
126
|
-
}
|
|
127
|
-
ensureIgnored(cwd, '.tiltignore', `${CHARTS_CHECKOUT_DIR}/`);
|
|
128
|
-
ensureIgnored(cwd, '.gitignore', CHARTS_CHECKOUT_DIR);
|
|
129
|
-
if (existingTiltfile === null || existingTiltfile === void 0 ? void 0 : existingTiltfile.includes('opencrvs-helm-charts')) {
|
|
130
|
-
console.log(` ℹ️ The Tiltfile no longer uses ../opencrvs-helm-charts; charts are cloned into ${CHARTS_CHECKOUT_DIR}/ instead. The old checkout can be deleted.`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function main() {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
console.log('Upgrading the local Tilt setup...\n');
|
|
136
|
-
upgradeTilt(process.cwd(), (0, template_files_1.findTemplateDir)());
|
|
137
|
-
console.log('\n Review local customisations with: git diff -- Tiltfile tilt/ .tiltignore .gitignore\n');
|
|
138
|
-
});
|
|
139
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.2/index.ts"],"names":[],"mappings":"AAaA;;;GAGG;AACH,wBAAsB,UAAU,kBAG/B"}
|
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/migrations/v2.2/index.ts
|
|
32
|
-
var v2_exports = {};
|
|
33
|
-
__export(v2_exports, {
|
|
34
|
-
runUpgrade: () => runUpgrade
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(v2_exports);
|
|
37
|
-
|
|
38
|
-
// src/migrations/add-translations.ts
|
|
39
|
-
var import_path = __toESM(require("path"));
|
|
40
|
-
|
|
41
|
-
// src/csv.ts
|
|
42
|
-
var import_fs = require("fs");
|
|
43
|
-
function parseCsvLine(line) {
|
|
44
|
-
const values = [];
|
|
45
|
-
let value = "";
|
|
46
|
-
let quoted = false;
|
|
47
|
-
for (let index = 0; index < line.length; index++) {
|
|
48
|
-
const character = line[index];
|
|
49
|
-
if (quoted) {
|
|
50
|
-
if (character !== '"') {
|
|
51
|
-
value += character;
|
|
52
|
-
} else if (line[index + 1] === '"') {
|
|
53
|
-
value += '"';
|
|
54
|
-
index++;
|
|
55
|
-
} else {
|
|
56
|
-
quoted = false;
|
|
57
|
-
}
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (character === '"') {
|
|
61
|
-
quoted = true;
|
|
62
|
-
} else if (character === ",") {
|
|
63
|
-
values.push(value);
|
|
64
|
-
value = "";
|
|
65
|
-
} else {
|
|
66
|
-
value += character;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
values.push(value);
|
|
70
|
-
return values;
|
|
71
|
-
}
|
|
72
|
-
function toCsvLine(values) {
|
|
73
|
-
return values.map(
|
|
74
|
-
(value) => /["\n,]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value
|
|
75
|
-
).join(",");
|
|
76
|
-
}
|
|
77
|
-
function idOf(line) {
|
|
78
|
-
const comma = line.indexOf(",");
|
|
79
|
-
return comma === -1 ? line : line.slice(0, comma);
|
|
80
|
-
}
|
|
81
|
-
function readCsvFile(path3) {
|
|
82
|
-
if (!(0, import_fs.existsSync)(path3)) {
|
|
83
|
-
return void 0;
|
|
84
|
-
}
|
|
85
|
-
const contents = (0, import_fs.readFileSync)(path3, "utf8");
|
|
86
|
-
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
87
|
-
const trailingNewline = /\r?\n$/.test(contents);
|
|
88
|
-
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
89
|
-
const body = lines.slice(1).filter((line) => line !== "");
|
|
90
|
-
return { header: lines[0], body, newline, trailingNewline };
|
|
91
|
-
}
|
|
92
|
-
function writeCsvFile(path3, file) {
|
|
93
|
-
(0, import_fs.writeFileSync)(
|
|
94
|
-
path3,
|
|
95
|
-
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
function addRows(file, rows) {
|
|
99
|
-
const isSorted = file.body.every(
|
|
100
|
-
(line, index) => index === 0 || idOf(file.body[index - 1]) <= idOf(line)
|
|
101
|
-
);
|
|
102
|
-
const added = [];
|
|
103
|
-
for (const row of rows) {
|
|
104
|
-
const id = idOf(row);
|
|
105
|
-
if (file.body.some((line) => idOf(line) === id)) {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const insertAt = isSorted ? file.body.findIndex((line) => idOf(line) > id) : -1;
|
|
109
|
-
if (insertAt === -1) {
|
|
110
|
-
file.body.push(row);
|
|
111
|
-
} else {
|
|
112
|
-
file.body.splice(insertAt, 0, row);
|
|
113
|
-
}
|
|
114
|
-
added.push(id);
|
|
115
|
-
}
|
|
116
|
-
return added;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/translations/template.ts
|
|
120
|
-
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
121
|
-
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
122
|
-
async function matchingRefs(namespace, prefix) {
|
|
123
|
-
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
124
|
-
const response = await fetch(url, {
|
|
125
|
-
headers: { accept: "application/vnd.github+json" }
|
|
126
|
-
});
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
throw new Error(
|
|
129
|
-
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
const refs = await response.json();
|
|
133
|
-
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
134
|
-
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
135
|
-
}
|
|
136
|
-
async function candidateRefs(version) {
|
|
137
|
-
return [
|
|
138
|
-
...await matchingRefs("heads", `release/${version}.`),
|
|
139
|
-
...await matchingRefs("tags", `v${version}.`),
|
|
140
|
-
"develop"
|
|
141
|
-
];
|
|
142
|
-
}
|
|
143
|
-
async function fetchTemplate(refs, application) {
|
|
144
|
-
for (const ref of refs) {
|
|
145
|
-
const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
|
|
146
|
-
const response = await fetch(url);
|
|
147
|
-
if (response.ok) {
|
|
148
|
-
return { ref, contents: await response.text() };
|
|
149
|
-
}
|
|
150
|
-
if (response.status !== 404) {
|
|
151
|
-
throw new Error(
|
|
152
|
-
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return void 0;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// src/migrations/add-translations.ts
|
|
160
|
-
var APPLICATIONS = ["client", "login"];
|
|
161
|
-
var skipped = [];
|
|
162
|
-
function warnSkipped(message) {
|
|
163
|
-
skipped.push(message);
|
|
164
|
-
console.warn(` \u26A0\uFE0F ${message}`);
|
|
165
|
-
}
|
|
166
|
-
function rowsToAdd(local, template) {
|
|
167
|
-
const localColumns = parseCsvLine(local.header);
|
|
168
|
-
const templateColumns = parseCsvLine(template.header);
|
|
169
|
-
return template.body.filter((line) => line !== "").map((line) => {
|
|
170
|
-
const values = parseCsvLine(line);
|
|
171
|
-
return toCsvLine(
|
|
172
|
-
localColumns.map((column) => {
|
|
173
|
-
const index = templateColumns.indexOf(column);
|
|
174
|
-
return index === -1 ? "" : values[index] ?? "";
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
async function updateApplication(cwd, targetVersion, refs, application) {
|
|
180
|
-
const relativePath = `src/translations/${application}.csv`;
|
|
181
|
-
const local = readCsvFile(import_path.default.join(cwd, relativePath));
|
|
182
|
-
if (!local) {
|
|
183
|
-
warnSkipped(`${relativePath} not found; translations not added`);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const fetched = await fetchTemplate(refs, application);
|
|
187
|
-
if (!fetched) {
|
|
188
|
-
warnSkipped(
|
|
189
|
-
`No ${application}.csv found in the ${targetVersion} country config template on GitHub; ${application}.csv not updated`
|
|
190
|
-
);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const template = readTemplate(fetched.contents);
|
|
194
|
-
const added = addRows(local, rowsToAdd(local, template));
|
|
195
|
-
if (added.length === 0) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
writeCsvFile(import_path.default.join(cwd, relativePath), local);
|
|
200
|
-
} catch (error) {
|
|
201
|
-
warnSkipped(
|
|
202
|
-
`Could not write ${relativePath} (${error.message}); translations not added`
|
|
203
|
-
);
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
for (const id of added) {
|
|
207
|
-
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function readTemplate(contents) {
|
|
211
|
-
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
212
|
-
return {
|
|
213
|
-
header: lines[0],
|
|
214
|
-
body: lines.slice(1),
|
|
215
|
-
newline: "\n",
|
|
216
|
-
trailingNewline: true
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
async function listRefs(targetVersion) {
|
|
220
|
-
try {
|
|
221
|
-
return await candidateRefs(targetVersion);
|
|
222
|
-
} catch (error) {
|
|
223
|
-
warnSkipped(
|
|
224
|
-
`Could not list the ${targetVersion} refs on GitHub (${error.message}); translations not added`
|
|
225
|
-
);
|
|
226
|
-
return void 0;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
async function main(targetVersion) {
|
|
230
|
-
const cwd = process.cwd();
|
|
231
|
-
console.log("Adding the translation keys core gained this version...\n");
|
|
232
|
-
const refs = await listRefs(targetVersion);
|
|
233
|
-
if (refs) {
|
|
234
|
-
for (const application of APPLICATIONS) {
|
|
235
|
-
try {
|
|
236
|
-
await updateApplication(cwd, targetVersion, refs, application);
|
|
237
|
-
} catch (error) {
|
|
238
|
-
warnSkipped(
|
|
239
|
-
`Could not read ${application}.csv from the country config template on GitHub (${error.message}); ${application}.csv not updated`
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
if (skipped.length > 0) {
|
|
245
|
-
console.warn(
|
|
246
|
-
`
|
|
247
|
-
\u26A0\uFE0F ${skipped.length} step(s) were skipped. Add the missing translations by hand before upgrading:`
|
|
248
|
-
);
|
|
249
|
-
for (const message of skipped) {
|
|
250
|
-
console.warn(` - ${message}`);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// src/migrations/v2.2/read-declaration-through-helper.ts
|
|
256
|
-
var import_ts_morph = require("ts-morph");
|
|
257
|
-
var import_path2 = __toESM(require("path"));
|
|
258
|
-
var EVENT_CONFIG_TYPE_NAME = "EventConfig";
|
|
259
|
-
var DECLARATION_PROPERTY_NAME = "declaration";
|
|
260
|
-
var GET_DECLARATION_NAME = "getDeclaration";
|
|
261
|
-
var TOOLKIT_EVENTS_MODULE = "@opencrvs/toolkit/events";
|
|
262
|
-
function isToolkitEventConfig(type) {
|
|
263
|
-
const nonNullableType = type.getNonNullableType();
|
|
264
|
-
const symbol = nonNullableType.getAliasSymbol() ?? nonNullableType.getSymbol();
|
|
265
|
-
if (symbol?.getName() !== EVENT_CONFIG_TYPE_NAME) {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
return symbol.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
269
|
-
}
|
|
270
|
-
function isDeclarationReadOnEventConfig(node) {
|
|
271
|
-
return node.getName() === DECLARATION_PROPERTY_NAME && isToolkitEventConfig(node.getExpression().getType());
|
|
272
|
-
}
|
|
273
|
-
function isAssignmentOperator(kind) {
|
|
274
|
-
return kind >= import_ts_morph.SyntaxKind.FirstAssignment && kind <= import_ts_morph.SyntaxKind.LastAssignment;
|
|
275
|
-
}
|
|
276
|
-
function isWriteTarget(node) {
|
|
277
|
-
const parent = node.getParent();
|
|
278
|
-
if (import_ts_morph.Node.isDeleteExpression(parent)) {
|
|
279
|
-
return true;
|
|
280
|
-
}
|
|
281
|
-
return import_ts_morph.Node.isBinaryExpression(parent) && parent.getLeft() === node && isAssignmentOperator(parent.getOperatorToken().getKind());
|
|
282
|
-
}
|
|
283
|
-
function location(node) {
|
|
284
|
-
const relPath = import_path2.default.relative(
|
|
285
|
-
process.cwd(),
|
|
286
|
-
node.getSourceFile().getFilePath()
|
|
287
|
-
);
|
|
288
|
-
return `${relPath}:${node.getStartLineNumber()}`;
|
|
289
|
-
}
|
|
290
|
-
function warnDestructuredDeclarations(sourceFile) {
|
|
291
|
-
for (const pattern of sourceFile.getDescendantsOfKind(
|
|
292
|
-
import_ts_morph.SyntaxKind.ObjectBindingPattern
|
|
293
|
-
)) {
|
|
294
|
-
const destructuresDeclaration = pattern.getElements().some(
|
|
295
|
-
(element) => (element.getPropertyNameNode()?.getText() ?? element.getName()) === DECLARATION_PROPERTY_NAME
|
|
296
|
-
);
|
|
297
|
-
if (destructuresDeclaration && isToolkitEventConfig(pattern.getType())) {
|
|
298
|
-
console.warn(
|
|
299
|
-
` [${location(pattern)}] Destructures \`${DECLARATION_PROPERTY_NAME}\` from an EventConfig. Rewrite it to use \`${GET_DECLARATION_NAME}(config)\` by hand.`
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
function warnSpreadDeclarations(sourceFile) {
|
|
305
|
-
for (const literal of sourceFile.getDescendantsOfKind(
|
|
306
|
-
import_ts_morph.SyntaxKind.ObjectLiteralExpression
|
|
307
|
-
)) {
|
|
308
|
-
const properties = literal.getProperties();
|
|
309
|
-
const spreadsEventConfig = properties.some(
|
|
310
|
-
(property) => import_ts_morph.Node.isSpreadAssignment(property) && isToolkitEventConfig(property.getExpression().getType())
|
|
311
|
-
);
|
|
312
|
-
const setsDeclaration = properties.some(
|
|
313
|
-
(property) => (import_ts_morph.Node.isPropertyAssignment(property) || import_ts_morph.Node.isShorthandPropertyAssignment(property)) && property.getName() === DECLARATION_PROPERTY_NAME
|
|
314
|
-
);
|
|
315
|
-
if (spreadsEventConfig && setsDeclaration) {
|
|
316
|
-
console.warn(
|
|
317
|
-
` [${location(literal)}] Spreads an EventConfig and sets \`${DECLARATION_PROPERTY_NAME}\` next to it. The spread config already has a \`${DECLARATION_PROPERTY_NAME}\` on its DECLARE action, so replace that one by hand.`
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function findToolkitImport(sourceFile) {
|
|
323
|
-
return sourceFile.getImportDeclaration(
|
|
324
|
-
(declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE && !declaration.isTypeOnly() && !declaration.getNamespaceImport()
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
function findGetDeclarationName(sourceFile) {
|
|
328
|
-
const imported = findToolkitImport(sourceFile)?.getNamedImports().find((namedImport) => namedImport.getName() === GET_DECLARATION_NAME);
|
|
329
|
-
if (imported) {
|
|
330
|
-
return imported.getAliasNode()?.getText() ?? GET_DECLARATION_NAME;
|
|
331
|
-
}
|
|
332
|
-
if (sourceFile.getLocal(GET_DECLARATION_NAME)) {
|
|
333
|
-
return void 0;
|
|
334
|
-
}
|
|
335
|
-
return GET_DECLARATION_NAME;
|
|
336
|
-
}
|
|
337
|
-
function addGetDeclarationImport(sourceFile) {
|
|
338
|
-
const toolkitImport = findToolkitImport(sourceFile);
|
|
339
|
-
if (!toolkitImport) {
|
|
340
|
-
const imports = sourceFile.getImportDeclarations();
|
|
341
|
-
const lastImport = imports[imports.length - 1];
|
|
342
|
-
sourceFile.insertStatements(
|
|
343
|
-
lastImport ? lastImport.getChildIndex() + 1 : 0,
|
|
344
|
-
`import { ${GET_DECLARATION_NAME} } from '${TOOLKIT_EVENTS_MODULE}'`
|
|
345
|
-
);
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const alreadyImported = toolkitImport.getNamedImports().some((namedImport) => namedImport.getName() === GET_DECLARATION_NAME);
|
|
349
|
-
if (alreadyImported) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const namedImports = toolkitImport.getNamedImports();
|
|
353
|
-
if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
|
|
354
|
-
toolkitImport.addNamedImport(GET_DECLARATION_NAME);
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
const names = [
|
|
358
|
-
...namedImports.map((namedImport) => namedImport.getText()),
|
|
359
|
-
GET_DECLARATION_NAME
|
|
360
|
-
];
|
|
361
|
-
const specifiers = toolkitImport.getText().includes("\n") ? `{
|
|
362
|
-
${names.join(",\n ")}
|
|
363
|
-
}` : `{ ${names.join(", ")} }`;
|
|
364
|
-
toolkitImport.replaceWithText(
|
|
365
|
-
`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE}'`
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
function rewriteDeclarationReads(sourceFile) {
|
|
369
|
-
warnDestructuredDeclarations(sourceFile);
|
|
370
|
-
warnSpreadDeclarations(sourceFile);
|
|
371
|
-
const reads = sourceFile.getDescendantsOfKind(import_ts_morph.SyntaxKind.PropertyAccessExpression).filter(isDeclarationReadOnEventConfig).filter((node) => {
|
|
372
|
-
if (node.hasQuestionDotToken()) {
|
|
373
|
-
console.warn(
|
|
374
|
-
` [${location(node)}] Skipped optional chain \`${node.getText()}\`. Rewrite it to use \`${GET_DECLARATION_NAME}()\` by hand.`
|
|
375
|
-
);
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
if (isWriteTarget(node)) {
|
|
379
|
-
console.warn(
|
|
380
|
-
` [${location(node)}] Skipped write to \`${node.getText()}\`. Set \`${DECLARATION_PROPERTY_NAME}\` on the DECLARE action instead.`
|
|
381
|
-
);
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
return true;
|
|
385
|
-
}).sort((a, b) => b.getStart() - a.getStart());
|
|
386
|
-
if (reads.length === 0) {
|
|
387
|
-
return 0;
|
|
388
|
-
}
|
|
389
|
-
const getDeclarationName = findGetDeclarationName(sourceFile);
|
|
390
|
-
if (!getDeclarationName) {
|
|
391
|
-
console.warn(
|
|
392
|
-
` [${location(reads[reads.length - 1])}] Skipped ${reads.length} read(s): the file already declares its own \`${GET_DECLARATION_NAME}\`. Rewrite them to use the toolkit's \`${GET_DECLARATION_NAME}()\` by hand.`
|
|
393
|
-
);
|
|
394
|
-
return 0;
|
|
395
|
-
}
|
|
396
|
-
for (const read of reads) {
|
|
397
|
-
console.log(
|
|
398
|
-
` [${location(read)}] ${read.getText()} -> ${getDeclarationName}(${read.getExpression().getText()})`
|
|
399
|
-
);
|
|
400
|
-
read.replaceWithText(
|
|
401
|
-
`${getDeclarationName}(${read.getExpression().getText()})`
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
addGetDeclarationImport(sourceFile);
|
|
405
|
-
return reads.length;
|
|
406
|
-
}
|
|
407
|
-
async function main2() {
|
|
408
|
-
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
409
|
-
console.log(`Scanning for EventConfig declaration reads in: ${srcDir}
|
|
410
|
-
`);
|
|
411
|
-
const project = new import_ts_morph.Project({
|
|
412
|
-
tsConfigFilePath: import_path2.default.resolve(srcDir, "../tsconfig.json"),
|
|
413
|
-
skipAddingFilesFromTsConfig: false
|
|
414
|
-
});
|
|
415
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
416
|
-
const fp = sf.getFilePath();
|
|
417
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
418
|
-
});
|
|
419
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
420
|
-
`);
|
|
421
|
-
let totalChanges = 0;
|
|
422
|
-
const modifiedFiles = [];
|
|
423
|
-
for (const sourceFile of sourceFiles) {
|
|
424
|
-
const changes = rewriteDeclarationReads(sourceFile);
|
|
425
|
-
if (changes > 0) {
|
|
426
|
-
totalChanges += changes;
|
|
427
|
-
modifiedFiles.push(sourceFile);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
if (modifiedFiles.length === 0) {
|
|
431
|
-
console.log("No EventConfig declaration reads found. Nothing to do.");
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
console.log(`
|
|
435
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
436
|
-
for (const sourceFile of modifiedFiles) {
|
|
437
|
-
await sourceFile.save();
|
|
438
|
-
console.log(
|
|
439
|
-
` Saved: ${import_path2.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
console.log(
|
|
443
|
-
`
|
|
444
|
-
Done. Rewrote ${totalChanges} declaration read(s) across ${modifiedFiles.length} file(s).`
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// src/migrations/v2.2/index.ts
|
|
449
|
-
async function runUpgrade() {
|
|
450
|
-
await main2();
|
|
451
|
-
await main("2.2");
|
|
452
|
-
}
|
|
453
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
454
|
-
0 && (module.exports = {
|
|
455
|
-
runUpgrade
|
|
456
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read-declaration-through-helper.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.2/read-declaration-through-helper.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAIL,UAAU,EAGX,MAAM,UAAU,CAAA;AA8LjB;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAqDtE;AAED,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.opencrvs-core-charts/
|