@dotcom-tool-kit/package-json-hook 2.0.0 → 2.1.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.
package/lib/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { PackageJsonHelper } from '@dotcom-tool-kit/hook';
2
- export declare abstract class PackageJsonHook extends PackageJsonHelper {
3
- field: string;
4
- install(): Promise<void>;
5
- }
1
+ export { PackageJsonScriptHook, PackageJsonScriptHook as PackageJsonHook } from './script-hook';
2
+ export { PackageJsonHelper } from './package-json-helper';
6
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAMzD,8BAAsB,eAAgB,SAAQ,iBAAiB;IAC7D,KAAK,SAAY;IAEX,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAa/B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,IAAI,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA"}
package/lib/index.js CHANGED
@@ -1,23 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PackageJsonHook = void 0;
4
- const hook_1 = require("@dotcom-tool-kit/hook");
5
- class PackageJsonHook extends hook_1.PackageJsonHelper {
6
- constructor() {
7
- super(...arguments);
8
- this.field = 'scripts';
9
- }
10
- async install() {
11
- let command = `dotcom-tool-kit ${this.hook}`;
12
- const existingCommand = this.packageJson.getField(this.field)[this.key];
13
- if (existingCommand && existingCommand.startsWith('dotcom-tool-kit ')) {
14
- command = command.concat(existingCommand.replace('dotcom-tool-kit', ''));
15
- }
16
- this.packageJson.requireScript({
17
- stage: this.key,
18
- command
19
- });
20
- this.packageJson.writeChanges();
21
- }
22
- }
23
- exports.PackageJsonHook = PackageJsonHook;
3
+ exports.PackageJsonHelper = exports.PackageJsonHook = exports.PackageJsonScriptHook = void 0;
4
+ var script_hook_1 = require("./script-hook");
5
+ Object.defineProperty(exports, "PackageJsonScriptHook", { enumerable: true, get: function () { return script_hook_1.PackageJsonScriptHook; } });
6
+ Object.defineProperty(exports, "PackageJsonHook", { enumerable: true, get: function () { return script_hook_1.PackageJsonScriptHook; } });
7
+ var package_json_helper_1 = require("./package-json-helper");
8
+ Object.defineProperty(exports, "PackageJsonHelper", { enumerable: true, get: function () { return package_json_helper_1.PackageJsonHelper; } });
@@ -0,0 +1,12 @@
1
+ import { Hook } from '@dotcom-tool-kit/types';
2
+ import type { PackageJson } from '@financial-times/package-json';
3
+ export declare abstract class PackageJsonHelper extends Hook {
4
+ _packageJson?: PackageJson;
5
+ abstract field: string;
6
+ abstract key: string;
7
+ abstract hook: string;
8
+ get packageJson(): PackageJson;
9
+ check(): Promise<boolean>;
10
+ abstract install(): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=package-json-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-json-helper.d.ts","sourceRoot":"","sources":["../src/package-json-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAQhE,8BAAsB,iBAAkB,SAAQ,IAAI;IACnD,YAAY,CAAC,EAAE,WAAW,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB,IAAI,WAAW,IAAI,WAAW,CAO7B;IAEK,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;IAK/B,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAChC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageJsonHelper = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const types_1 = require("@dotcom-tool-kit/types");
6
+ const package_json_1 = (0, tslib_1.__importDefault)(require("@financial-times/package-json"));
7
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
8
+ class PackageJsonHelper extends types_1.Hook {
9
+ get packageJson() {
10
+ if (!this._packageJson) {
11
+ const filepath = path_1.default.resolve(process.cwd(), 'package.json');
12
+ this._packageJson = (0, package_json_1.default)({ filepath });
13
+ }
14
+ return this._packageJson;
15
+ }
16
+ async check() {
17
+ var _a;
18
+ const commands = this.packageJson.getField(this.field);
19
+ return (_a = commands === null || commands === void 0 ? void 0 : commands[this.key]) === null || _a === void 0 ? void 0 : _a.includes(this.hook);
20
+ }
21
+ }
22
+ exports.PackageJsonHelper = PackageJsonHelper;
@@ -0,0 +1,6 @@
1
+ import { PackageJsonHelper } from './package-json-helper';
2
+ export declare abstract class PackageJsonScriptHook extends PackageJsonHelper {
3
+ field: string;
4
+ install(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=script-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-hook.d.ts","sourceRoot":"","sources":["../src/script-hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAMzD,8BAAsB,qBAAsB,SAAQ,iBAAiB;IACnE,KAAK,SAAY;IAEX,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAa/B"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageJsonScriptHook = void 0;
4
+ const package_json_helper_1 = require("./package-json-helper");
5
+ class PackageJsonScriptHook extends package_json_helper_1.PackageJsonHelper {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.field = 'scripts';
9
+ }
10
+ async install() {
11
+ let command = `dotcom-tool-kit ${this.hook}`;
12
+ const existingCommand = this.packageJson.getField(this.field)[this.key];
13
+ if (existingCommand && existingCommand.startsWith('dotcom-tool-kit ')) {
14
+ command = command.concat(existingCommand.replace('dotcom-tool-kit', ''));
15
+ }
16
+ this.packageJson.requireScript({
17
+ stage: this.key,
18
+ command
19
+ });
20
+ this.packageJson.writeChanges();
21
+ }
22
+ }
23
+ exports.PackageJsonScriptHook = PackageJsonScriptHook;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcom-tool-kit/package-json-hook",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  "author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dotcom-tool-kit/hook": "^2.0.0"
13
+ "@financial-times/package-json": "^3.0.0"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",