dotcom-tool-kit 1.7.0-beta.3 → 1.7.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;AAGrC;;;GAGG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,iBAgC/C"}
@@ -0,0 +1,50 @@
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("yaml"));
9
+ const lodash_merge_1 = (0, tslib_1.__importDefault)(require("lodash.merge"));
10
+ const circleci_1 = require("@dotcom-tool-kit/types/lib/circleci");
11
+ /**
12
+ * This step adds the tags only filter to rest of the jobs in the workflow if there is a job that contains the semverRegex.
13
+ * CircleCI will only run the jobs if the rest of the jobs have the tags filter.
14
+ */
15
+ async function postInstall(logger) {
16
+ const circleConfigPath = path_1.default.resolve(process.cwd(), '.circleci/config.yml');
17
+ try {
18
+ const rawCircleConfig = await fs_1.promises.readFile(circleConfigPath, 'utf8');
19
+ if (rawCircleConfig && rawCircleConfig.includes(npm_publish_1.semVerRegex.source) && rawCircleConfig.startsWith(circleci_1.automatedComment)) {
20
+ logger.verbose('running postInstall step');
21
+ const yml = YAML.parseDocument(rawCircleConfig);
22
+ const workflows = yml.get('workflows');
23
+ const toolkitWorkflow = workflows.get('tool-kit');
24
+ const jobs = toolkitWorkflow.get('jobs');
25
+ jobs === null || jobs === void 0 ? void 0 : jobs.items.forEach((jobItem, index) => {
26
+ const tagsFilterConfig = { filters: { tags: { only: `${npm_publish_1.semVerRegex}` } } };
27
+ if (jobItem.type === 'PLAIN') { // eg. - checkout
28
+ const node = YAML.createNode({ [jobItem.value]: tagsFilterConfig });
29
+ jobs.items[index] = node;
30
+ }
31
+ else {
32
+ const job = jobItem.items[0];
33
+ const existingFilter = job.value.items.filter((item) => item.key.value === 'filters')[0];
34
+ const merged = existingFilter ? (0, lodash_merge_1.default)(existingFilter.toJSON(), tagsFilterConfig) : tagsFilterConfig;
35
+ const node = YAML.createNode(merged['filters']);
36
+ job.value.set('filters', node);
37
+ }
38
+ });
39
+ logger.info(`writing postInstall results to file ${circleConfigPath}`);
40
+ await fs_1.promises.writeFile(circleConfigPath, yml.toString());
41
+ }
42
+ }
43
+ catch (error) {
44
+ // Not an error if config file doesn't exist
45
+ if (error.code !== 'ENOENT') {
46
+ throw error;
47
+ }
48
+ }
49
+ }
50
+ exports.postInstall = postInstall;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotcom-tool-kit",
3
- "version": "1.7.0-beta.3",
3
+ "version": "1.7.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/lodash.merge": "^4.6.6",
25
26
  "@types/lodash.mergewith": "^4.6.6",
26
27
  "@types/node": "^12.20.24",
27
28
  "chai": "^4.3.4",
@@ -30,18 +31,20 @@
30
31
  "winston": "^3.5.1"
31
32
  },
32
33
  "dependencies": {
33
- "@dotcom-tool-kit/error": "^1.7.0-beta.3",
34
- "@dotcom-tool-kit/hook": "^1.7.0-beta.3",
35
- "@dotcom-tool-kit/logger": "^1.7.0-beta.3",
36
- "@dotcom-tool-kit/options": "^1.7.0-beta.3",
37
- "@dotcom-tool-kit/types": "^1.7.0-beta.3",
38
- "@dotcom-tool-kit/wait-for-ok": "^1.7.0-beta.3",
34
+ "@dotcom-tool-kit/error": "^1.7.0",
35
+ "@dotcom-tool-kit/hook": "^1.7.0",
36
+ "@dotcom-tool-kit/logger": "^1.7.0",
37
+ "@dotcom-tool-kit/options": "^1.7.0",
38
+ "@dotcom-tool-kit/types": "^1.7.0",
39
+ "@dotcom-tool-kit/wait-for-ok": "^1.7.0",
39
40
  "cosmiconfig": "^7.0.0",
40
41
  "import-from": "^3.0.0",
42
+ "lodash.merge": "^4.6.2",
41
43
  "lodash.mergewith": "^4.6.2",
42
44
  "minimist": "^1.2.5",
43
45
  "resolve-from": "^5.0.0",
44
- "tslib": "^1.14.1"
46
+ "tslib": "^1.14.1",
47
+ "yaml": "^1.10.2"
45
48
  },
46
49
  "engines": {
47
50
  "node": ">=8.0.0"