dotcom-tool-kit 1.5.2 → 1.7.0-beta.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAA;AAE7C,wBAA8B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmC1E"}
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAA;AAE7C,wBAA8B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqC1E"}
package/lib/install.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const error_1 = require("@dotcom-tool-kit/error");
4
4
  const options_1 = require("@dotcom-tool-kit/options");
5
5
  const config_1 = require("./config");
6
+ const postInstall_1 = require("./postInstall");
6
7
  async function installHooks(logger) {
7
8
  const config = await (0, config_1.loadConfig)(logger);
8
9
  const tasks = Object.values(config.hooks).map((hook) => async () => {
@@ -29,6 +30,8 @@ async function installHooks(logger) {
29
30
  }
30
31
  }
31
32
  }
33
+ // Hack: for now we will do a postinstall, later we shall refactor circleciconfighook so we dont need to postinstall
34
+ await (0, postInstall_1.postInstall)(logger);
32
35
  if (errors.length) {
33
36
  const error = new error_1.ToolKitError('could not automatically install hooks:');
34
37
  error.details = errors.map((error) => `- ${error.message}`).join('\n');
@@ -0,0 +1,7 @@
1
+ import type { Logger } from 'winston';
2
+ /**
3
+ * This step adds the tags only filter to rest of the jobs in the workflow if there is a job that contains the semverRegex.
4
+ * CircleCI will only run the jobs if the rest of the jobs have the tags filter.
5
+ */
6
+ export declare function postInstall(logger: Logger): Promise<void>;
7
+ //# sourceMappingURL=postInstall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postInstall.d.ts","sourceRoot":"","sources":["../src/postInstall.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;;GAGG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,iBAoB/C"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postInstall = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
6
+ const fs_1 = require("fs");
7
+ const npm_publish_1 = require("@dotcom-tool-kit/npm/lib/tasks/npm-publish");
8
+ const yaml = (0, tslib_1.__importStar)(require("js-yaml"));
9
+ const lodash_1 = require("lodash");
10
+ /**
11
+ * This step adds the tags only filter to rest of the jobs in the workflow if there is a job that contains the semverRegex.
12
+ * CircleCI will only run the jobs if the rest of the jobs have the tags filter.
13
+ */
14
+ async function postInstall(logger) {
15
+ var _a, _b;
16
+ const circleConfigPath = path_1.default.resolve(process.cwd(), '.circleci/config.yml');
17
+ const rawCircleConfig = await fs_1.promises.readFile(circleConfigPath, 'utf8');
18
+ if (rawCircleConfig && rawCircleConfig.includes(npm_publish_1.semVerRegex.source)) {
19
+ logger.info('running postInstall step');
20
+ const circleConfig = yaml.load(rawCircleConfig);
21
+ const jobs = (_b = (_a = circleConfig.workflows) === null || _a === void 0 ? void 0 : _a['tool-kit']) === null || _b === void 0 ? void 0 : _b.jobs;
22
+ jobs === null || jobs === void 0 ? void 0 : jobs.forEach((job, index) => {
23
+ const tagsFilterConfig = { filters: { tags: { only: `${npm_publish_1.semVerRegex}` } } };
24
+ if (typeof job === "string") {
25
+ jobs[index] = { [job]: tagsFilterConfig };
26
+ }
27
+ else {
28
+ Object.entries(job).forEach(([key, value]) => {
29
+ job[key] = (0, lodash_1.merge)(value, tagsFilterConfig);
30
+ });
31
+ }
32
+ });
33
+ logger.info(`writing postInstall results to file ${circleConfigPath}`);
34
+ await fs_1.promises.writeFile(circleConfigPath, yaml.dump(circleConfig));
35
+ }
36
+ }
37
+ exports.postInstall = postInstall;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotcom-tool-kit",
3
- "version": "1.5.2",
3
+ "version": "1.7.0-beta.0",
4
4
  "description": "modern, maintainable, modular developer tooling for FT.com projects",
5
5
  "author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
6
6
  "license": "MIT",
@@ -22,6 +22,7 @@
22
22
  "devDependencies": {
23
23
  "@dotcom-tool-kit/circleci": "file:../../plugins/circleci",
24
24
  "@jest/globals": "^27.4.6",
25
+ "@types/js-yaml": "^4.0.5",
25
26
  "@types/lodash.mergewith": "^4.6.6",
26
27
  "@types/node": "^12.20.24",
27
28
  "chai": "^4.3.4",
@@ -30,14 +31,15 @@
30
31
  "winston": "^3.5.1"
31
32
  },
32
33
  "dependencies": {
33
- "@dotcom-tool-kit/error": "^1.5.2",
34
- "@dotcom-tool-kit/hook": "^1.5.2",
35
- "@dotcom-tool-kit/logger": "^1.5.2",
36
- "@dotcom-tool-kit/options": "^1.5.2",
37
- "@dotcom-tool-kit/types": "^1.5.2",
38
- "@dotcom-tool-kit/wait-for-ok": "^1.5.2",
34
+ "@dotcom-tool-kit/error": "^1.7.0-beta.0",
35
+ "@dotcom-tool-kit/hook": "^1.7.0-beta.0",
36
+ "@dotcom-tool-kit/logger": "^1.7.0-beta.0",
37
+ "@dotcom-tool-kit/options": "^1.7.0-beta.0",
38
+ "@dotcom-tool-kit/types": "^1.7.0-beta.0",
39
+ "@dotcom-tool-kit/wait-for-ok": "^1.7.0-beta.0",
39
40
  "cosmiconfig": "^7.0.0",
40
41
  "import-from": "^3.0.0",
42
+ "js-yaml": "^4.1.0",
41
43
  "lodash.mergewith": "^4.6.2",
42
44
  "minimist": "^1.2.5",
43
45
  "resolve-from": "^5.0.0",