@opencrvs/toolkit 2.1.0-rc.d1b9774 → 2.1.0-rc.d235243
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/README.md +2 -12
- package/build.sh +15 -5
- package/create-countryconfig/index.js +164 -4
- package/dist/application-config/index.js +36 -25
- package/dist/authentication/index.d.ts +8 -9
- package/dist/authentication/index.js +23 -8
- package/dist/cli.js +1981 -2823
- package/dist/commons/api/router.d.ts +252 -290
- package/dist/commons/application-config/index.d.ts +0 -2
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +19 -4
- package/dist/commons/events/ActionConfig.d.ts +5 -14
- package/dist/commons/events/ActionDocument.d.ts +30 -4
- package/dist/commons/events/AdvancedSearchConfig.d.ts +24 -12
- package/dist/commons/events/AuditLog.d.ts +1 -0
- package/dist/commons/events/Draft.d.ts +1 -21
- package/dist/commons/events/EventDocument.d.ts +4 -4
- package/dist/commons/events/FieldConfig.d.ts +26 -15
- package/dist/commons/events/FieldTypeMapping.d.ts +10 -10
- package/dist/commons/events/FieldValue.d.ts +1 -0
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/locations.d.ts +4 -0
- package/dist/commons/events/scopes.d.ts +21 -1
- package/dist/commons/events/test.utils.d.ts +71 -22
- package/dist/commons/events/utils.d.ts +37 -2
- package/dist/conditionals/index.js +21 -7
- package/dist/environment/derived-variables.d.ts +18 -0
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +21 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +2 -1
- package/dist/environment/manage-users.js +1 -1
- package/dist/environment/questions.d.ts +16 -0
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +27 -2
- package/dist/environment/setup-environment.d.ts +1 -1
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +633 -560
- package/dist/environment/swarm-to-k8s.js +3 -4
- package/dist/environment/templates.d.ts +0 -1
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +3 -8
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +6 -1
- package/dist/environment/utils.d.ts +0 -12
- package/dist/environment/utils.d.ts.map +1 -1
- package/dist/environment/utils.js +1 -28
- package/dist/events/index.js +2115 -1884
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +4 -4
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
- package/dist/migrations/v2.1/add-translations.js +4 -68
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
- package/dist/migrations/v2.1/enable-telemetry.js +30 -13
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +35 -1261
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
- package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-sentry.js +354 -0
- package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
- package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
- package/dist/migrations/v2.1/template-files.d.ts +8 -0
- package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
- package/dist/migrations/v2.1/template-files.js +49 -0
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
- package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
- package/dist/migrations/v2.2/add-e2e-tests.d.ts +19 -0
- package/dist/migrations/v2.2/add-e2e-tests.d.ts.map +1 -0
- package/dist/migrations/v2.2/add-e2e-tests.js +143 -0
- package/dist/migrations/v2.2/index.d.ts +6 -0
- package/dist/migrations/v2.2/index.d.ts.map +1 -0
- package/dist/migrations/v2.2/index.js +279 -0
- package/dist/migrations/v2.2/template-files.d.ts +8 -0
- package/dist/migrations/v2.2/template-files.d.ts.map +1 -0
- package/dist/migrations/v2.2/template-files.js +49 -0
- package/dist/migrations/v2.2/upgrade-tilt.d.ts +8 -0
- package/dist/migrations/v2.2/upgrade-tilt.d.ts.map +1 -0
- package/dist/migrations/v2.2/upgrade-tilt.js +139 -0
- package/dist/notification/index.js +249 -207
- package/dist/scopes/index.d.ts +288 -5
- package/dist/scopes/index.js +22 -7
- package/dist/telemetry/index.js +4 -0
- package/dist/templates/charts-values/dependencies/values.yaml +8 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +6 -0
- package/dist/templates/charts-values/opentelemetry/values.yaml +7 -0
- package/dist/templates/charts-values/traefik/values.yaml +2 -3
- package/dist/templates/countryconfig-template/.tiltignore +1 -0
- package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
- package/dist/templates/countryconfig-template/Tiltfile +112 -0
- package/dist/templates/countryconfig-template/assets/README.md +1 -0
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
- package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
- package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
- package/dist/templates/countryconfig-template/e2e/README.md +36 -0
- package/dist/templates/countryconfig-template/e2e/constants.ts +28 -0
- package/dist/templates/countryconfig-template/e2e/login.e2e.ts +59 -0
- package/dist/templates/countryconfig-template/package.json +153 -0
- package/dist/templates/countryconfig-template/playwright.config.ts +42 -0
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
- package/dist/templates/countryconfig-template/tilt/common.tilt +159 -0
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
- package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
- package/dist/translations/template.d.ts +11 -0
- package/dist/translations/template.d.ts.map +1 -0
- package/dist/translations/template.js +100 -0
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +180 -15
- package/opencrvs-toolkit-2.1.0-rc.d235243.tgz +0 -0
- package/package.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
- package/dist/migrations/v2.0/create-events-index.d.ts +0 -3
- package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
- package/dist/migrations/v2.0/create-events-index.js +0 -325
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
- package/dist/migrations/v2.0/index.d.ts +0 -13
- package/dist/migrations/v2.0/index.d.ts.map +0 -1
- package/dist/migrations/v2.0/index.js +0 -103
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-scopes.js +0 -305
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
- package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
- package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
- package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
- package/dist/migrations/v2.0/update-package-json.js +0 -105
- package/dist/translations/check.d.ts +0 -19
- package/dist/translations/check.d.ts.map +0 -1
- package/dist/translations/check.js +0 -127
- package/opencrvs-toolkit-2.1.0-rc.d1b9774.tgz +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Whether a Playwright config only runs tests from the `e2e/` directory. */
|
|
2
|
+
export declare function pointsIntoE2EDir(config: string): boolean;
|
|
3
|
+
type PackageJson = {
|
|
4
|
+
scripts?: Record<string, string>;
|
|
5
|
+
dependencies?: Record<string, string>;
|
|
6
|
+
devDependencies?: Record<string, string>;
|
|
7
|
+
};
|
|
8
|
+
/** `packageJson` with the template's e2e scripts and Playwright dependency added where missing. */
|
|
9
|
+
export declare function withE2EPackageEntries(packageJson: PackageJson, templatePackageJson: PackageJson): {
|
|
10
|
+
dependencies?: Record<string, string>;
|
|
11
|
+
devDependencies?: Record<string, string>;
|
|
12
|
+
scripts: {
|
|
13
|
+
[x: string]: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function addE2ETests(cwd: string, templateDir: string): boolean;
|
|
17
|
+
declare function main(): Promise<void>;
|
|
18
|
+
export { main };
|
|
19
|
+
//# sourceMappingURL=add-e2e-tests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-e2e-tests.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.2/add-e2e-tests.ts"],"names":[],"mappings":"AAkDA,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,WAQ9C;AAED,KAAK,WAAW,GAAG;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACzC,CAAA;AAED,mGAAmG;AACnG,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,EACxB,mBAAmB,EAAE,WAAW;mBAPjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;sBACnB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;EAmCzC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,WAoD3D;AAED,iBAAe,IAAI,kBAUlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,143 @@
|
|
|
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.pointsIntoE2EDir = pointsIntoE2EDir;
|
|
26
|
+
exports.withE2EPackageEntries = withE2EPackageEntries;
|
|
27
|
+
exports.addE2ETests = addE2ETests;
|
|
28
|
+
exports.main = main;
|
|
29
|
+
/**
|
|
30
|
+
* Codemod: add the sample Playwright e2e suite from the country config template.
|
|
31
|
+
*
|
|
32
|
+
* Core's own e2e suite moved from the country configs into
|
|
33
|
+
* opencrvs-core/packages/testland. Country configs keep a suite of their own
|
|
34
|
+
* under `e2e/`, which the infrastructure `e2e.yml` workflow runs after every
|
|
35
|
+
* deployment to an environment with E2E_ENABLED=true.
|
|
36
|
+
*
|
|
37
|
+
* What it does, only when the country config has no `e2e/` directory yet:
|
|
38
|
+
* 1. Copies the template's `e2e/` directory.
|
|
39
|
+
* 2. Writes the template's `playwright.config.ts`. An existing config is
|
|
40
|
+
* replaced only when its `testDir` points into the missing `e2e/`
|
|
41
|
+
* directory (as Farajaland's did), otherwise it is left in place.
|
|
42
|
+
* 3. Adds the `e2e` scripts and the `@playwright/test` dev dependency to
|
|
43
|
+
* package.json, unless they are already there.
|
|
44
|
+
* 4. Adds Playwright's output directories to `.gitignore`.
|
|
45
|
+
*
|
|
46
|
+
* An existing `e2e/` directory is the country's own suite and is left alone.
|
|
47
|
+
*/
|
|
48
|
+
const fs_1 = require("fs");
|
|
49
|
+
const path_1 = __importDefault(require("path"));
|
|
50
|
+
const template_files_1 = require("./template-files");
|
|
51
|
+
const upgrade_tilt_1 = require("./upgrade-tilt");
|
|
52
|
+
const E2E_DIR = 'e2e';
|
|
53
|
+
const PLAYWRIGHT_CONFIG = 'playwright.config.ts';
|
|
54
|
+
const PLAYWRIGHT_PACKAGE = '@playwright/test';
|
|
55
|
+
const E2E_SCRIPTS = ['e2e', 'e2e:ui', 'e2e:dev'];
|
|
56
|
+
const IGNORED_PATHS = ['playwright-report', 'test-results'];
|
|
57
|
+
const TEST_DIR_PATTERN = /testDir\s*:\s*(["'`])(.*?)\1/;
|
|
58
|
+
function copyFile(templateDir, cwd, file) {
|
|
59
|
+
const target = path_1.default.join(cwd, file);
|
|
60
|
+
(0, fs_1.mkdirSync)(path_1.default.dirname(target), { recursive: true });
|
|
61
|
+
(0, fs_1.writeFileSync)(target, (0, fs_1.readFileSync)(path_1.default.join(templateDir, file), 'utf8'));
|
|
62
|
+
}
|
|
63
|
+
/** Whether a Playwright config only runs tests from the `e2e/` directory. */
|
|
64
|
+
function pointsIntoE2EDir(config) {
|
|
65
|
+
var _a;
|
|
66
|
+
const testDir = (_a = config.match(TEST_DIR_PATTERN)) === null || _a === void 0 ? void 0 : _a[2];
|
|
67
|
+
if (testDir === undefined) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return path_1.default.posix.normalize(testDir).split('/')[0] === E2E_DIR;
|
|
71
|
+
}
|
|
72
|
+
/** `packageJson` with the template's e2e scripts and Playwright dependency added where missing. */
|
|
73
|
+
function withE2EPackageEntries(packageJson, templatePackageJson) {
|
|
74
|
+
var _a, _b, _c, _d;
|
|
75
|
+
const scripts = Object.assign({}, packageJson.scripts);
|
|
76
|
+
for (const script of E2E_SCRIPTS) {
|
|
77
|
+
const templateScript = (_a = templatePackageJson.scripts) === null || _a === void 0 ? void 0 : _a[script];
|
|
78
|
+
if (templateScript && !scripts[script]) {
|
|
79
|
+
scripts[script] = templateScript;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const hasPlaywright = !!((_b = packageJson.dependencies) === null || _b === void 0 ? void 0 : _b[PLAYWRIGHT_PACKAGE]) ||
|
|
83
|
+
!!((_c = packageJson.devDependencies) === null || _c === void 0 ? void 0 : _c[PLAYWRIGHT_PACKAGE]);
|
|
84
|
+
const playwrightVersion = (_d = templatePackageJson.devDependencies) === null || _d === void 0 ? void 0 : _d[PLAYWRIGHT_PACKAGE];
|
|
85
|
+
return Object.assign(Object.assign(Object.assign({}, packageJson), { scripts }), (hasPlaywright || !playwrightVersion
|
|
86
|
+
? {}
|
|
87
|
+
: {
|
|
88
|
+
devDependencies: Object.assign(Object.assign({}, packageJson.devDependencies), { [PLAYWRIGHT_PACKAGE]: playwrightVersion })
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
function addE2ETests(cwd, templateDir) {
|
|
92
|
+
if ((0, fs_1.existsSync)(path_1.default.join(cwd, E2E_DIR))) {
|
|
93
|
+
console.log(` ↷ ${E2E_DIR}/ already exists, leaving it as is`);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
for (const file of (0, template_files_1.listFiles)(templateDir, E2E_DIR)) {
|
|
97
|
+
copyFile(templateDir, cwd, file);
|
|
98
|
+
console.log(` ✓ created ${file}`);
|
|
99
|
+
}
|
|
100
|
+
const configPath = path_1.default.join(cwd, PLAYWRIGHT_CONFIG);
|
|
101
|
+
if (!(0, fs_1.existsSync)(configPath)) {
|
|
102
|
+
copyFile(templateDir, cwd, PLAYWRIGHT_CONFIG);
|
|
103
|
+
console.log(` ✓ created ${PLAYWRIGHT_CONFIG}`);
|
|
104
|
+
}
|
|
105
|
+
else if (pointsIntoE2EDir((0, fs_1.readFileSync)(configPath, 'utf8'))) {
|
|
106
|
+
copyFile(templateDir, cwd, PLAYWRIGHT_CONFIG);
|
|
107
|
+
console.log(` ✓ updated ${PLAYWRIGHT_CONFIG}`);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.warn(` ⚠️ ${PLAYWRIGHT_CONFIG} does not run tests from ${E2E_DIR}/ and was left in place. Point its testDir to './${E2E_DIR}' and testMatch to '**/*.e2e.ts' to run the sample tests.`);
|
|
111
|
+
}
|
|
112
|
+
const packageJsonPath = path_1.default.join(cwd, 'package.json');
|
|
113
|
+
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
114
|
+
const contents = (0, fs_1.readFileSync)(packageJsonPath, 'utf8');
|
|
115
|
+
const updated = withE2EPackageEntries(JSON.parse(contents), JSON.parse((0, fs_1.readFileSync)(path_1.default.join(templateDir, 'package.json'), 'utf8')));
|
|
116
|
+
// Keep the file's trailing newline, if it had one.
|
|
117
|
+
const trailingNewline = contents.endsWith('\n') ? '\n' : '';
|
|
118
|
+
const serialised = `${JSON.stringify(updated, null, 2)}${trailingNewline}`;
|
|
119
|
+
if (serialised !== contents) {
|
|
120
|
+
(0, fs_1.writeFileSync)(packageJsonPath, serialised);
|
|
121
|
+
console.log(' ✓ updated package.json');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const gitignorePath = path_1.default.join(cwd, '.gitignore');
|
|
125
|
+
const gitignore = (0, fs_1.existsSync)(gitignorePath)
|
|
126
|
+
? (0, fs_1.readFileSync)(gitignorePath, 'utf8')
|
|
127
|
+
: '';
|
|
128
|
+
const updatedGitignore = IGNORED_PATHS.reduce(upgrade_tilt_1.withIgnoreEntry, gitignore);
|
|
129
|
+
if (updatedGitignore !== gitignore) {
|
|
130
|
+
(0, fs_1.writeFileSync)(gitignorePath, updatedGitignore);
|
|
131
|
+
console.log(' ✓ updated .gitignore');
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
function main() {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
console.log('Adding sample e2e tests...\n');
|
|
138
|
+
const added = addE2ETests(process.cwd(), (0, template_files_1.findTemplateDir)());
|
|
139
|
+
if (added) {
|
|
140
|
+
console.log(`\n Install dependencies to add ${PLAYWRIGHT_PACKAGE} to your lockfile, then run the tests with: npx playwright test\n`);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.2/index.ts"],"names":[],"mappings":"AAaA;;;GAGG;AACH,wBAAsB,UAAU,kBAG/B"}
|
|
@@ -0,0 +1,279 @@
|
|
|
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/v2.2/add-e2e-tests.ts
|
|
39
|
+
var import_fs3 = require("fs");
|
|
40
|
+
var import_path3 = __toESM(require("path"));
|
|
41
|
+
|
|
42
|
+
// src/migrations/v2.2/template-files.ts
|
|
43
|
+
var import_fs = require("fs");
|
|
44
|
+
var import_path = __toESM(require("path"));
|
|
45
|
+
function findTemplateDir() {
|
|
46
|
+
const candidates = [
|
|
47
|
+
import_path.default.resolve(__dirname, "templates", "countryconfig-template"),
|
|
48
|
+
import_path.default.resolve(__dirname, "../../../../countryconfig-template")
|
|
49
|
+
];
|
|
50
|
+
const templateDir = candidates.find(
|
|
51
|
+
(candidate) => (0, import_fs.existsSync)(import_path.default.join(candidate, "Tiltfile"))
|
|
52
|
+
);
|
|
53
|
+
if (!templateDir) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Country config template files not found in any of: ${candidates.join(", ")}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return templateDir;
|
|
59
|
+
}
|
|
60
|
+
function listFiles(root, dir) {
|
|
61
|
+
const absolute = import_path.default.join(root, dir);
|
|
62
|
+
if (!(0, import_fs.existsSync)(absolute)) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
return (0, import_fs.readdirSync)(absolute, { withFileTypes: true }).flatMap((entry) => {
|
|
66
|
+
const relative = import_path.default.posix.join(dir, entry.name);
|
|
67
|
+
return entry.isDirectory() ? listFiles(root, relative) : [relative];
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/migrations/v2.2/upgrade-tilt.ts
|
|
72
|
+
var import_fs2 = require("fs");
|
|
73
|
+
var import_path2 = __toESM(require("path"));
|
|
74
|
+
var COUNTRY_OWNED_DIR = "tilt/helm/";
|
|
75
|
+
var CHARTS_CHECKOUT_DIR = ".opencrvs-core-charts";
|
|
76
|
+
var IMAGE_NAME_PATTERN = /^countryconfig_image_name\s*=\s*(["'])(.*?)\1/m;
|
|
77
|
+
function writeIfChanged(cwd, relativePath, contents, mode) {
|
|
78
|
+
const target = import_path2.default.join(cwd, relativePath);
|
|
79
|
+
const existed = (0, import_fs2.existsSync)(target);
|
|
80
|
+
if (existed && (0, import_fs2.readFileSync)(target, "utf8") === contents) {
|
|
81
|
+
return "unchanged";
|
|
82
|
+
}
|
|
83
|
+
(0, import_fs2.mkdirSync)(import_path2.default.dirname(target), { recursive: true });
|
|
84
|
+
(0, import_fs2.writeFileSync)(target, contents);
|
|
85
|
+
if (mode !== void 0) {
|
|
86
|
+
(0, import_fs2.chmodSync)(target, mode & 511);
|
|
87
|
+
}
|
|
88
|
+
return existed ? "updated" : "created";
|
|
89
|
+
}
|
|
90
|
+
function report(relativePath, change) {
|
|
91
|
+
if (change !== "unchanged") {
|
|
92
|
+
console.log(` \u2713 ${change} ${relativePath}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function renderTiltfile(template, existing) {
|
|
96
|
+
const imageName = existing?.match(IMAGE_NAME_PATTERN)?.[2];
|
|
97
|
+
if (!imageName) {
|
|
98
|
+
return template;
|
|
99
|
+
}
|
|
100
|
+
return template.replace(
|
|
101
|
+
IMAGE_NAME_PATTERN,
|
|
102
|
+
(_line, quote) => `countryconfig_image_name=${quote}${imageName}${quote}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
function withIgnoreEntry(contents, line) {
|
|
106
|
+
const normalise = (entry) => entry.trim().replace(/^\//, "").replace(/\/$/, "");
|
|
107
|
+
const alreadyIgnored = contents.split(/\r?\n/).some((entry) => normalise(entry) === normalise(line));
|
|
108
|
+
if (alreadyIgnored) {
|
|
109
|
+
return contents;
|
|
110
|
+
}
|
|
111
|
+
const separator = contents === "" || contents.endsWith("\n") ? "" : "\n";
|
|
112
|
+
return `${contents}${separator}${line}
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
function ensureIgnored(cwd, file, line) {
|
|
116
|
+
const target = import_path2.default.join(cwd, file);
|
|
117
|
+
const contents = (0, import_fs2.existsSync)(target) ? (0, import_fs2.readFileSync)(target, "utf8") : "";
|
|
118
|
+
report(file, writeIfChanged(cwd, file, withIgnoreEntry(contents, line)));
|
|
119
|
+
}
|
|
120
|
+
function upgradeTilt(cwd, templateDir) {
|
|
121
|
+
const tiltfilePath = import_path2.default.join(cwd, "Tiltfile");
|
|
122
|
+
const existingTiltfile = (0, import_fs2.existsSync)(tiltfilePath) ? (0, import_fs2.readFileSync)(tiltfilePath, "utf8") : void 0;
|
|
123
|
+
report(
|
|
124
|
+
"Tiltfile",
|
|
125
|
+
writeIfChanged(
|
|
126
|
+
cwd,
|
|
127
|
+
"Tiltfile",
|
|
128
|
+
renderTiltfile(
|
|
129
|
+
(0, import_fs2.readFileSync)(import_path2.default.join(templateDir, "Tiltfile"), "utf8"),
|
|
130
|
+
existingTiltfile
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
const templateFiles = listFiles(templateDir, "tilt");
|
|
135
|
+
for (const file of templateFiles) {
|
|
136
|
+
const source = import_path2.default.join(templateDir, file);
|
|
137
|
+
const countryOwned = file.startsWith(COUNTRY_OWNED_DIR);
|
|
138
|
+
if (countryOwned && (0, import_fs2.existsSync)(import_path2.default.join(cwd, file))) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
report(
|
|
142
|
+
file,
|
|
143
|
+
writeIfChanged(
|
|
144
|
+
cwd,
|
|
145
|
+
file,
|
|
146
|
+
(0, import_fs2.readFileSync)(source, "utf8"),
|
|
147
|
+
(0, import_fs2.statSync)(source).mode
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
const unknownFiles = listFiles(cwd, "tilt").filter(
|
|
152
|
+
(file) => !file.startsWith(COUNTRY_OWNED_DIR) && !templateFiles.includes(file)
|
|
153
|
+
);
|
|
154
|
+
for (const file of unknownFiles) {
|
|
155
|
+
console.warn(
|
|
156
|
+
` \u26A0\uFE0F ${file} is not part of the template and was left in place.`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
ensureIgnored(cwd, ".tiltignore", `${CHARTS_CHECKOUT_DIR}/`);
|
|
160
|
+
ensureIgnored(cwd, ".gitignore", CHARTS_CHECKOUT_DIR);
|
|
161
|
+
if (existingTiltfile?.includes("opencrvs-helm-charts")) {
|
|
162
|
+
console.log(
|
|
163
|
+
` \u2139\uFE0F The Tiltfile no longer uses ../opencrvs-helm-charts; charts are cloned into ${CHARTS_CHECKOUT_DIR}/ instead. The old checkout can be deleted.`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function main() {
|
|
168
|
+
console.log("Upgrading the local Tilt setup...\n");
|
|
169
|
+
upgradeTilt(process.cwd(), findTemplateDir());
|
|
170
|
+
console.log(
|
|
171
|
+
"\n Review local customisations with: git diff -- Tiltfile tilt/ .tiltignore .gitignore\n"
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/migrations/v2.2/add-e2e-tests.ts
|
|
176
|
+
var E2E_DIR = "e2e";
|
|
177
|
+
var PLAYWRIGHT_CONFIG = "playwright.config.ts";
|
|
178
|
+
var PLAYWRIGHT_PACKAGE = "@playwright/test";
|
|
179
|
+
var E2E_SCRIPTS = ["e2e", "e2e:ui", "e2e:dev"];
|
|
180
|
+
var IGNORED_PATHS = ["playwright-report", "test-results"];
|
|
181
|
+
var TEST_DIR_PATTERN = /testDir\s*:\s*(["'`])(.*?)\1/;
|
|
182
|
+
function copyFile(templateDir, cwd, file) {
|
|
183
|
+
const target = import_path3.default.join(cwd, file);
|
|
184
|
+
(0, import_fs3.mkdirSync)(import_path3.default.dirname(target), { recursive: true });
|
|
185
|
+
(0, import_fs3.writeFileSync)(target, (0, import_fs3.readFileSync)(import_path3.default.join(templateDir, file), "utf8"));
|
|
186
|
+
}
|
|
187
|
+
function pointsIntoE2EDir(config) {
|
|
188
|
+
const testDir = config.match(TEST_DIR_PATTERN)?.[2];
|
|
189
|
+
if (testDir === void 0) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
return import_path3.default.posix.normalize(testDir).split("/")[0] === E2E_DIR;
|
|
193
|
+
}
|
|
194
|
+
function withE2EPackageEntries(packageJson, templatePackageJson) {
|
|
195
|
+
const scripts = { ...packageJson.scripts };
|
|
196
|
+
for (const script of E2E_SCRIPTS) {
|
|
197
|
+
const templateScript = templatePackageJson.scripts?.[script];
|
|
198
|
+
if (templateScript && !scripts[script]) {
|
|
199
|
+
scripts[script] = templateScript;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const hasPlaywright = !!packageJson.dependencies?.[PLAYWRIGHT_PACKAGE] || !!packageJson.devDependencies?.[PLAYWRIGHT_PACKAGE];
|
|
203
|
+
const playwrightVersion = templatePackageJson.devDependencies?.[PLAYWRIGHT_PACKAGE];
|
|
204
|
+
return {
|
|
205
|
+
...packageJson,
|
|
206
|
+
scripts,
|
|
207
|
+
...hasPlaywright || !playwrightVersion ? {} : {
|
|
208
|
+
devDependencies: {
|
|
209
|
+
...packageJson.devDependencies,
|
|
210
|
+
[PLAYWRIGHT_PACKAGE]: playwrightVersion
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function addE2ETests(cwd, templateDir) {
|
|
216
|
+
if ((0, import_fs3.existsSync)(import_path3.default.join(cwd, E2E_DIR))) {
|
|
217
|
+
console.log(` \u21B7 ${E2E_DIR}/ already exists, leaving it as is`);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
for (const file of listFiles(templateDir, E2E_DIR)) {
|
|
221
|
+
copyFile(templateDir, cwd, file);
|
|
222
|
+
console.log(` \u2713 created ${file}`);
|
|
223
|
+
}
|
|
224
|
+
const configPath = import_path3.default.join(cwd, PLAYWRIGHT_CONFIG);
|
|
225
|
+
if (!(0, import_fs3.existsSync)(configPath)) {
|
|
226
|
+
copyFile(templateDir, cwd, PLAYWRIGHT_CONFIG);
|
|
227
|
+
console.log(` \u2713 created ${PLAYWRIGHT_CONFIG}`);
|
|
228
|
+
} else if (pointsIntoE2EDir((0, import_fs3.readFileSync)(configPath, "utf8"))) {
|
|
229
|
+
copyFile(templateDir, cwd, PLAYWRIGHT_CONFIG);
|
|
230
|
+
console.log(` \u2713 updated ${PLAYWRIGHT_CONFIG}`);
|
|
231
|
+
} else {
|
|
232
|
+
console.warn(
|
|
233
|
+
` \u26A0\uFE0F ${PLAYWRIGHT_CONFIG} does not run tests from ${E2E_DIR}/ and was left in place. Point its testDir to './${E2E_DIR}' and testMatch to '**/*.e2e.ts' to run the sample tests.`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
const packageJsonPath = import_path3.default.join(cwd, "package.json");
|
|
237
|
+
if ((0, import_fs3.existsSync)(packageJsonPath)) {
|
|
238
|
+
const contents = (0, import_fs3.readFileSync)(packageJsonPath, "utf8");
|
|
239
|
+
const updated = withE2EPackageEntries(
|
|
240
|
+
JSON.parse(contents),
|
|
241
|
+
JSON.parse((0, import_fs3.readFileSync)(import_path3.default.join(templateDir, "package.json"), "utf8"))
|
|
242
|
+
);
|
|
243
|
+
const trailingNewline = contents.endsWith("\n") ? "\n" : "";
|
|
244
|
+
const serialised = `${JSON.stringify(updated, null, 2)}${trailingNewline}`;
|
|
245
|
+
if (serialised !== contents) {
|
|
246
|
+
(0, import_fs3.writeFileSync)(packageJsonPath, serialised);
|
|
247
|
+
console.log(" \u2713 updated package.json");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const gitignorePath = import_path3.default.join(cwd, ".gitignore");
|
|
251
|
+
const gitignore = (0, import_fs3.existsSync)(gitignorePath) ? (0, import_fs3.readFileSync)(gitignorePath, "utf8") : "";
|
|
252
|
+
const updatedGitignore = IGNORED_PATHS.reduce(withIgnoreEntry, gitignore);
|
|
253
|
+
if (updatedGitignore !== gitignore) {
|
|
254
|
+
(0, import_fs3.writeFileSync)(gitignorePath, updatedGitignore);
|
|
255
|
+
console.log(" \u2713 updated .gitignore");
|
|
256
|
+
}
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
async function main2() {
|
|
260
|
+
console.log("Adding sample e2e tests...\n");
|
|
261
|
+
const added = addE2ETests(process.cwd(), findTemplateDir());
|
|
262
|
+
if (added) {
|
|
263
|
+
console.log(
|
|
264
|
+
`
|
|
265
|
+
Install dependencies to add ${PLAYWRIGHT_PACKAGE} to your lockfile, then run the tests with: npx playwright test
|
|
266
|
+
`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/migrations/v2.2/index.ts
|
|
272
|
+
async function runUpgrade() {
|
|
273
|
+
await main();
|
|
274
|
+
await main2();
|
|
275
|
+
}
|
|
276
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
277
|
+
0 && (module.exports = {
|
|
278
|
+
runUpgrade
|
|
279
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the bundled template files are: next to the built CLI in `dist/`, or
|
|
3
|
+
* the template package itself when running from source (tests, ts-node).
|
|
4
|
+
*/
|
|
5
|
+
export declare function findTemplateDir(): string;
|
|
6
|
+
/** Every file under `dir`, relative to `root`, with forward slashes. */
|
|
7
|
+
export declare function listFiles(root: string, dir: string): string[];
|
|
8
|
+
//# sourceMappingURL=template-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.2/template-files.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,wBAAgB,eAAe,WAiB9B;AAED,wEAAwE;AACxE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAW7D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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.findTemplateDir = findTemplateDir;
|
|
17
|
+
exports.listFiles = listFiles;
|
|
18
|
+
/**
|
|
19
|
+
* Country config template files bundled into the toolkit by `build.sh`, shared
|
|
20
|
+
* by the codemods that copy them into a country config.
|
|
21
|
+
*/
|
|
22
|
+
const fs_1 = require("fs");
|
|
23
|
+
const path_1 = __importDefault(require("path"));
|
|
24
|
+
/**
|
|
25
|
+
* Where the bundled template files are: next to the built CLI in `dist/`, or
|
|
26
|
+
* the template package itself when running from source (tests, ts-node).
|
|
27
|
+
*/
|
|
28
|
+
function findTemplateDir() {
|
|
29
|
+
const candidates = [
|
|
30
|
+
path_1.default.resolve(__dirname, 'templates', 'countryconfig-template'),
|
|
31
|
+
path_1.default.resolve(__dirname, '../../../../countryconfig-template')
|
|
32
|
+
];
|
|
33
|
+
const templateDir = candidates.find((candidate) => (0, fs_1.existsSync)(path_1.default.join(candidate, 'Tiltfile')));
|
|
34
|
+
if (!templateDir) {
|
|
35
|
+
throw new Error(`Country config template files not found in any of: ${candidates.join(', ')}`);
|
|
36
|
+
}
|
|
37
|
+
return templateDir;
|
|
38
|
+
}
|
|
39
|
+
/** Every file under `dir`, relative to `root`, with forward slashes. */
|
|
40
|
+
function listFiles(root, dir) {
|
|
41
|
+
const absolute = path_1.default.join(root, dir);
|
|
42
|
+
if (!(0, fs_1.existsSync)(absolute)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return (0, fs_1.readdirSync)(absolute, { withFileTypes: true }).flatMap((entry) => {
|
|
46
|
+
const relative = path_1.default.posix.join(dir, entry.name);
|
|
47
|
+
return entry.isDirectory() ? listFiles(root, relative) : [relative];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The template Tiltfile, keeping the image name the country already uses. */
|
|
2
|
+
export declare function renderTiltfile(template: string, existing?: string): string;
|
|
3
|
+
/** `contents` with `line` appended, unless an equivalent entry is there already. */
|
|
4
|
+
export declare function withIgnoreEntry(contents: string, line: string): string;
|
|
5
|
+
export declare function upgradeTilt(cwd: string, templateDir: string): void;
|
|
6
|
+
declare function main(): Promise<void>;
|
|
7
|
+
export { main };
|
|
8
|
+
//# sourceMappingURL=upgrade-tilt.d.ts.map
|