dotcom-tool-kit 1.0.0 → 1.0.2-beta.3
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/bin/run +31 -20
- package/lib/config.d.ts +9 -12
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +28 -16
- package/lib/conflict.d.ts +1 -1
- package/lib/conflict.d.ts.map +1 -1
- package/lib/help.d.ts +2 -1
- package/lib/help.d.ts.map +1 -1
- package/lib/help.js +27 -16
- package/lib/hook.d.ts +1 -11
- package/lib/hook.d.ts.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +17 -11
- package/lib/install.d.ts +2 -1
- package/lib/install.d.ts.map +1 -1
- package/lib/install.js +10 -5
- package/lib/messages.d.ts +6 -22
- package/lib/messages.d.ts.map +1 -1
- package/lib/messages.js +36 -45
- package/lib/plugin.d.ts +5 -14
- package/lib/plugin.d.ts.map +1 -1
- package/lib/plugin.js +20 -7
- package/package.json +12 -9
package/bin/run
CHANGED
|
@@ -1,34 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const c = require('ansi-colors')
|
|
4
3
|
const argv = require('minimist')(process.argv.slice(2), {
|
|
5
|
-
|
|
4
|
+
boolean: ['help', 'install'],
|
|
5
|
+
'--': true
|
|
6
6
|
})
|
|
7
7
|
|
|
8
8
|
const { runTasks, showHelp, installHooks } = require('../lib')
|
|
9
|
-
const { styles } = require('
|
|
9
|
+
const { rootLogger, styles } = require('@dotcom-tool-kit/logger')
|
|
10
10
|
|
|
11
11
|
async function main() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
try {
|
|
13
|
+
if (argv.install) {
|
|
14
|
+
await installHooks(rootLogger)
|
|
15
|
+
} else if (argv.help || argv._.length === 0) {
|
|
16
|
+
await showHelp(rootLogger, argv._)
|
|
17
|
+
} else {
|
|
18
|
+
if (argv['--'].length > 0) {
|
|
19
|
+
// The `--` in a command such as `dotcom-tool-kit test:staged --`
|
|
20
|
+
// delineates between hooks and file patterns. For example, when the
|
|
21
|
+
// lint-staged task is run it will identify the files that are staged
|
|
22
|
+
// and match its glob patterns and append them to the command, so that
|
|
23
|
+
// the command becomes something like `dotcom-tool-kit test:staged --
|
|
24
|
+
// index.js`. When this command is executed it runs the configured task
|
|
25
|
+
// where the file path arguments would then be extracted.
|
|
26
|
+
await runTasks(rootLogger, argv._, argv['--'])
|
|
17
27
|
} else {
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
} catch(error) {
|
|
21
|
-
if(error.details) {
|
|
22
|
-
console.error(
|
|
23
|
-
styles.error(error.message) + '\n\n' +
|
|
24
|
-
error.details
|
|
25
|
-
)
|
|
26
|
-
} else {
|
|
27
|
-
console.error(error.stack)
|
|
28
|
+
await runTasks(rootLogger, argv._)
|
|
28
29
|
}
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (error.details) {
|
|
33
|
+
rootLogger.error('', { skipformat: true })
|
|
34
|
+
rootLogger.error(error.message)
|
|
35
|
+
rootLogger.error(styles.ruler(), { skipformat: true })
|
|
36
|
+
rootLogger.error(error.details, { skipformat: true })
|
|
37
|
+
} else {
|
|
38
|
+
rootLogger.error(error.stack)
|
|
39
|
+
}
|
|
29
40
|
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
process.exitCode = error.exitCode || 1
|
|
42
|
+
}
|
|
32
43
|
}
|
|
33
44
|
|
|
34
45
|
main()
|
package/lib/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { HookTask
|
|
3
|
-
import { Plugin } from './plugin';
|
|
1
|
+
import type { Logger } from 'winston';
|
|
2
|
+
import type { HookTask } from './hook';
|
|
4
3
|
import { Conflict } from './conflict';
|
|
4
|
+
import type { TaskClass, Hook, Plugin } from '@dotcom-tool-kit/types';
|
|
5
5
|
export interface PluginOptions {
|
|
6
6
|
options: Record<string, unknown>;
|
|
7
7
|
plugin: Plugin;
|
|
@@ -22,7 +22,7 @@ export interface Config {
|
|
|
22
22
|
[id: string]: PluginOptions | Conflict<PluginOptions> | undefined;
|
|
23
23
|
};
|
|
24
24
|
hooks: {
|
|
25
|
-
[id: string]:
|
|
25
|
+
[id: string]: Hook | Conflict<Hook>;
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
export interface ValidConfig extends Config {
|
|
@@ -36,18 +36,15 @@ export interface ValidConfig extends Config {
|
|
|
36
36
|
[id: string]: PluginOptions;
|
|
37
37
|
};
|
|
38
38
|
hooks: {
|
|
39
|
-
[id: string]:
|
|
39
|
+
[id: string]: Hook;
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
export declare function validateConfig(config: Config
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export declare function loadConfig(options?: {
|
|
42
|
+
export declare function validateConfig(config: Config): Promise<ValidConfig>;
|
|
43
|
+
export declare function checkInstall(config: ValidConfig): Promise<void>;
|
|
44
|
+
export declare function loadConfig(logger: Logger, options?: {
|
|
46
45
|
validate?: true;
|
|
47
|
-
checkInstall?: boolean;
|
|
48
46
|
}): Promise<ValidConfig>;
|
|
49
|
-
export declare function loadConfig(options?: {
|
|
47
|
+
export declare function loadConfig(logger: Logger, options?: {
|
|
50
48
|
validate?: false;
|
|
51
|
-
checkInstall?: boolean;
|
|
52
49
|
}): Promise<Config>;
|
|
53
50
|
//# sourceMappingURL=config.d.ts.map
|
package/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEtC,OAAO,EAAE,QAAQ,EAA+C,MAAM,YAAY,CAAA;AAElF,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAYrE,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACjC,KAAK,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAA;KAAE,CAAA;IACxD,SAAS,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAA;KAAE,CAAA;IAC1D,OAAO,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;KAAE,CAAA;IAC9E,KAAK,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;KAAE,CAAA;CAC/C;AAED,MAAM,WAAW,WAAY,SAAQ,MAAM;IACzC,KAAK,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;IAClC,SAAS,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE,CAAA;IACrC,OAAO,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,CAAA;IACxC,KAAK,EAAE;QAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CAC9B;AAmBD,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAyFzE;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAWrE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAC/F,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA"}
|
package/lib/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadConfig = exports.validateConfig = void 0;
|
|
3
|
+
exports.loadConfig = exports.checkInstall = exports.validateConfig = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
6
6
|
const plugin_1 = require("./plugin");
|
|
@@ -20,7 +20,7 @@ async function asyncFilter(items, predicate) {
|
|
|
20
20
|
const results = await Promise.all(items.map(async (item) => ({ item, keep: await predicate(item) })));
|
|
21
21
|
return results.filter(({ keep }) => keep).map(({ item }) => item);
|
|
22
22
|
}
|
|
23
|
-
async function validateConfig(config
|
|
23
|
+
async function validateConfig(config) {
|
|
24
24
|
const hookTaskConflicts = (0, conflict_1.findConflicts)(Object.values(config.hookTasks));
|
|
25
25
|
const hookConflicts = (0, conflict_1.findConflicts)(Object.values(config.hooks));
|
|
26
26
|
const taskConflicts = (0, conflict_1.findConflicts)(Object.values(config.tasks));
|
|
@@ -53,7 +53,6 @@ async function validateConfig(config, { checkInstall = true } = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
const configuredHookTasks = (0, conflict_1.withoutConflicts)(Object.values(config.hookTasks));
|
|
56
|
-
const definedHooks = (0, conflict_1.withoutConflicts)(Object.values(config.hooks));
|
|
57
56
|
const definedHookIds = new Set(Object.keys(config.hooks));
|
|
58
57
|
const undefinedHookTasks = configuredHookTasks.filter((hookTask) => {
|
|
59
58
|
// we only care about undefined hooks that were configured by the app, not default config from plugins
|
|
@@ -65,6 +64,13 @@ async function validateConfig(config, { checkInstall = true } = {}) {
|
|
|
65
64
|
shouldThrow = true;
|
|
66
65
|
error.details += (0, messages_1.formatUndefinedHookTasks)(undefinedHookTasks, Array.from(definedHookIds));
|
|
67
66
|
}
|
|
67
|
+
const unusedOptions = Object.entries(config.options)
|
|
68
|
+
.filter(([, option]) => option && !(0, conflict_1.isConflict)(option) && !option.forPlugin && option.plugin.root === process.cwd())
|
|
69
|
+
.map(([id]) => id);
|
|
70
|
+
if (unusedOptions.length > 0) {
|
|
71
|
+
shouldThrow = true;
|
|
72
|
+
error.details += (0, messages_1.formatUnusedOptions)(unusedOptions, Object.keys(config.plugins));
|
|
73
|
+
}
|
|
68
74
|
const missingTasks = configuredHookTasks
|
|
69
75
|
.map((hook) => ({
|
|
70
76
|
hook,
|
|
@@ -75,28 +81,34 @@ async function validateConfig(config, { checkInstall = true } = {}) {
|
|
|
75
81
|
shouldThrow = true;
|
|
76
82
|
error.details += (0, messages_1.formatMissingTasks)(missingTasks, Object.keys(config.tasks));
|
|
77
83
|
}
|
|
78
|
-
if (checkInstall) {
|
|
79
|
-
const uninstalledHooks = await asyncFilter(definedHooks, async (Hook) => {
|
|
80
|
-
const hook = new Hook();
|
|
81
|
-
return !(await hook.check());
|
|
82
|
-
});
|
|
83
|
-
if (uninstalledHooks.length > 0) {
|
|
84
|
-
shouldThrow = true;
|
|
85
|
-
error.details += (0, messages_1.formatUninstalledHooks)(uninstalledHooks);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
84
|
if (shouldThrow) {
|
|
89
85
|
throw error;
|
|
90
86
|
}
|
|
91
87
|
return config;
|
|
92
88
|
}
|
|
93
89
|
exports.validateConfig = validateConfig;
|
|
94
|
-
async function
|
|
90
|
+
async function checkInstall(config) {
|
|
91
|
+
const definedHooks = (0, conflict_1.withoutConflicts)(Object.values(config.hooks));
|
|
92
|
+
const uninstalledHooks = await asyncFilter(definedHooks, async (hook) => {
|
|
93
|
+
return !(await hook.check());
|
|
94
|
+
});
|
|
95
|
+
if (uninstalledHooks.length > 0) {
|
|
96
|
+
const error = new error_1.ToolKitError('There are problems with your Tool Kit installation.');
|
|
97
|
+
error.details = (0, messages_1.formatUninstalledHooks)(uninstalledHooks);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.checkInstall = checkInstall;
|
|
102
|
+
async function loadConfig(logger, { validate = true } = {}) {
|
|
95
103
|
// start loading config and child plugins, starting from the consumer app directory
|
|
96
|
-
const config = await (0, plugin_1.loadPluginConfig)({
|
|
104
|
+
const config = await (0, plugin_1.loadPluginConfig)(logger, {
|
|
97
105
|
id: 'app root',
|
|
98
106
|
root: process.cwd()
|
|
99
107
|
}, createConfig());
|
|
100
|
-
return validate ? validateConfig(config
|
|
108
|
+
return validate ? validateConfig(config) : config;
|
|
101
109
|
}
|
|
102
110
|
exports.loadConfig = loadConfig;
|
|
111
|
+
// abstract class TestBase {}
|
|
112
|
+
// class Test extends TestBase {}
|
|
113
|
+
// const testBase = TestBase
|
|
114
|
+
// const test = new testBase()
|
package/lib/conflict.d.ts
CHANGED
package/lib/conflict.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../src/conflict.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../src/conflict.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpD,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,CAAC,EAAE,CAAA;CACjB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAElE;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAU7E;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAUtE"}
|
package/lib/help.d.ts
CHANGED
package/lib/help.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAGA,wBAA8B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,wBAA8B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAiErF"}
|
package/lib/help.js
CHANGED
|
@@ -1,43 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const config_1 = require("./config");
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const options_1 = require("@dotcom-tool-kit/options");
|
|
5
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
6
|
+
async function showHelp(logger, hooks) {
|
|
7
|
+
const config = await (0, config_1.loadConfig)(logger);
|
|
7
8
|
if (hooks.length === 0) {
|
|
8
9
|
hooks = Object.keys(config.hooks).sort();
|
|
9
10
|
}
|
|
11
|
+
for (const pluginOptions of Object.values(config.options)) {
|
|
12
|
+
if (pluginOptions.forPlugin) {
|
|
13
|
+
(0, options_1.setOptions)(pluginOptions.forPlugin.id, pluginOptions.options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
await (0, config_1.checkInstall)(config);
|
|
10
17
|
const missingHooks = hooks.filter((hook) => !config.hooks[hook]);
|
|
11
|
-
|
|
12
|
-
🧰 ${
|
|
18
|
+
logger.info(`
|
|
19
|
+
🧰 ${logger_1.styles.title(`welcome to ${logger_1.styles.app('Tool Kit')}!`)}
|
|
13
20
|
|
|
14
21
|
Tool Kit is modern, maintainable & modular developer tooling for FT.com projects.
|
|
15
22
|
|
|
16
|
-
${
|
|
23
|
+
${logger_1.styles.URL('https://github.com/financial-times/dotcom-tool-kit')}
|
|
17
24
|
|
|
18
|
-
${
|
|
19
|
-
${Object.keys(config.hooks).length === 0
|
|
20
|
-
?
|
|
21
|
-
:
|
|
25
|
+
${logger_1.styles.ruler()}
|
|
26
|
+
${Object.keys(config.hooks).length === 0
|
|
27
|
+
? `there are no hooks available. you'll need to install plugins that define hooks to be able to run Tool Kit tasks.`
|
|
28
|
+
: logger_1.styles.dim(hooks.length === 0
|
|
29
|
+
? 'available hooks'
|
|
30
|
+
: `help for ${hooks.length - missingHooks.length} ${hooks.length - missingHooks.length > 1 ? 'hooks' : 'hook'}`)}:
|
|
22
31
|
`);
|
|
23
32
|
for (const hook of hooks) {
|
|
24
33
|
const Hook = config.hooks[hook];
|
|
25
34
|
if (Hook) {
|
|
26
35
|
const tasks = config.hookTasks[hook];
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- Object.constructor does not consider static properties */
|
|
37
|
+
logger.info(`${logger_1.styles.heading(hook)}
|
|
38
|
+
${Hook.constructor.description ? Hook.constructor.description + '\n' : ''}
|
|
29
39
|
${tasks && tasks.tasks.length
|
|
30
40
|
? `runs ${tasks.tasks.length > 1 ? 'these tasks' : 'this task'}:
|
|
31
41
|
${tasks.tasks
|
|
32
|
-
.map((task) => `- ${
|
|
42
|
+
.map((task) => `- ${logger_1.styles.task(task)} ${logger_1.styles.dim(config.tasks[task].description)}`)
|
|
33
43
|
.join('\n')}`
|
|
34
|
-
:
|
|
35
|
-
${
|
|
44
|
+
: logger_1.styles.dim('no tasks configured to run on this hook.')}
|
|
45
|
+
${logger_1.styles.ruler()}
|
|
36
46
|
`);
|
|
47
|
+
/*eslint-enable @typescript-eslint/no-explicit-any */
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
if (missingHooks.length) {
|
|
40
|
-
|
|
51
|
+
logger.warn(`no such ${missingHooks.length > 1 ? 'hooks' : 'hook'} ${missingHooks.map(logger_1.styles.hook).join(', ')}`);
|
|
41
52
|
}
|
|
42
53
|
}
|
|
43
54
|
exports.default = showHelp;
|
package/lib/hook.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import type { Plugin } from '
|
|
1
|
+
import type { Plugin } from '@dotcom-tool-kit/types';
|
|
2
2
|
export interface HookTask {
|
|
3
3
|
id: string;
|
|
4
4
|
plugin: Plugin;
|
|
5
5
|
tasks: string[];
|
|
6
6
|
}
|
|
7
|
-
export interface HookClass {
|
|
8
|
-
id?: string;
|
|
9
|
-
plugin?: Plugin;
|
|
10
|
-
description?: string;
|
|
11
|
-
new (): Hook;
|
|
12
|
-
}
|
|
13
|
-
export interface Hook {
|
|
14
|
-
check(): Promise<boolean>;
|
|
15
|
-
install(): Promise<void>;
|
|
16
|
-
}
|
|
17
7
|
//# sourceMappingURL=hook.d.ts.map
|
package/lib/hook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpD,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Logger } from 'winston';
|
|
2
|
+
export declare function runTasks(logger: Logger, hooks: string[], files?: string[]): Promise<void>;
|
|
2
3
|
export { default as showHelp } from './help';
|
|
3
4
|
export { default as installHooks } from './install';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAQrC,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8E/F;AAED,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.installHooks = exports.showHelp = exports.runTasks = void 0;
|
|
7
7
|
const error_1 = require("@dotcom-tool-kit/error");
|
|
8
8
|
const config_1 = require("./config");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const config = await (0, config_1.loadConfig)();
|
|
9
|
+
const options_1 = require("@dotcom-tool-kit/options");
|
|
10
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
11
|
+
async function runTasks(logger, hooks, files) {
|
|
12
|
+
const config = await (0, config_1.loadConfig)(logger);
|
|
13
13
|
const availableHooks = Object.keys(config.hooks)
|
|
14
14
|
.sort()
|
|
15
15
|
.map((id) => `- ${id}`)
|
|
@@ -23,22 +23,28 @@ hooks that are available are:
|
|
|
23
23
|
${availableHooks}`;
|
|
24
24
|
throw error;
|
|
25
25
|
}
|
|
26
|
+
for (const pluginOptions of Object.values(config.options)) {
|
|
27
|
+
if (pluginOptions.forPlugin) {
|
|
28
|
+
(0, options_1.setOptions)(pluginOptions.forPlugin.id, pluginOptions.options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await (0, config_1.checkInstall)(config);
|
|
26
32
|
for (const hook of hooks) {
|
|
27
33
|
const errors = [];
|
|
28
34
|
if (!config.hookTasks[hook]) {
|
|
29
|
-
|
|
35
|
+
logger.warn(`no task configured for ${hook}: skipping assignment...`);
|
|
30
36
|
continue;
|
|
31
37
|
}
|
|
32
38
|
const assignment = config.hookTasks[hook];
|
|
33
39
|
for (const id of assignment.tasks) {
|
|
34
40
|
const Task = config.tasks[id];
|
|
35
|
-
const options = Task.plugin ? (
|
|
41
|
+
const options = Task.plugin ? (0, options_1.getOptions)(Task.plugin.id) : {};
|
|
36
42
|
// `Task` is an abstract class. here we know it's a concrete subclass
|
|
37
43
|
// but typescript doesn't, so cast it to any.
|
|
38
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
const task = new Task(options);
|
|
45
|
+
const task = new Task(logger, options);
|
|
40
46
|
try {
|
|
41
|
-
await task.run();
|
|
47
|
+
await task.run(files);
|
|
42
48
|
}
|
|
43
49
|
catch (error) {
|
|
44
50
|
// allow subsequent hook tasks to run on error
|
|
@@ -50,16 +56,16 @@ ${availableHooks}`;
|
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
if (errors.length > 0) {
|
|
53
|
-
const error = new error_1.ToolKitError(`error running tasks for ${
|
|
59
|
+
const error = new error_1.ToolKitError(`error running tasks for ${logger_1.styles.hook(hook)}`);
|
|
54
60
|
error.details = errors
|
|
55
|
-
.map(({ hook, task, error }) => `${
|
|
61
|
+
.map(({ hook, task, error }) => `${logger_1.styles.heading(`${logger_1.styles.task(task)}:`)}
|
|
56
62
|
|
|
57
63
|
${error.message}${error instanceof error_1.ToolKitError
|
|
58
64
|
? `
|
|
59
65
|
|
|
60
66
|
${error.details}`
|
|
61
67
|
: ''}`)
|
|
62
|
-
.join(
|
|
68
|
+
.join(`${logger_1.styles.dim(logger_1.styles.ruler())}\n`);
|
|
63
69
|
error.exitCode = errors.length + 1;
|
|
64
70
|
throw error;
|
|
65
71
|
}
|
package/lib/install.d.ts
CHANGED
package/lib/install.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"
|
|
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"}
|
package/lib/install.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const error_1 = require("@dotcom-tool-kit/error");
|
|
4
|
+
const options_1 = require("@dotcom-tool-kit/options");
|
|
4
5
|
const config_1 = require("./config");
|
|
5
|
-
async function installHooks() {
|
|
6
|
-
const config = await (0, config_1.loadConfig)(
|
|
7
|
-
const tasks = Object.values(config.hooks).map((
|
|
8
|
-
const hook = new Hook();
|
|
6
|
+
async function installHooks(logger) {
|
|
7
|
+
const config = await (0, config_1.loadConfig)(logger);
|
|
8
|
+
const tasks = Object.values(config.hooks).map((hook) => async () => {
|
|
9
9
|
if (!(await hook.check())) {
|
|
10
10
|
await hook.install();
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
+
for (const pluginOptions of Object.values(config.options)) {
|
|
14
|
+
if (pluginOptions.forPlugin) {
|
|
15
|
+
(0, options_1.setOptions)(pluginOptions.forPlugin.id, pluginOptions.options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
13
18
|
const errors = [];
|
|
14
19
|
for (const task of tasks) {
|
|
15
20
|
try {
|
|
@@ -26,7 +31,7 @@ async function installHooks() {
|
|
|
26
31
|
}
|
|
27
32
|
if (errors.length) {
|
|
28
33
|
const error = new error_1.ToolKitError('could not automatically install hooks:');
|
|
29
|
-
error.details = errors.map((error) => error.message).join('\n
|
|
34
|
+
error.details = errors.map((error) => `- ${error.message}`).join('\n');
|
|
30
35
|
throw error;
|
|
31
36
|
}
|
|
32
37
|
return config;
|
package/lib/messages.d.ts
CHANGED
|
@@ -1,34 +1,18 @@
|
|
|
1
|
-
import colours from 'ansi-colors';
|
|
2
1
|
import type { PluginOptions } from './config';
|
|
3
2
|
import type { Conflict } from './conflict';
|
|
4
|
-
import type { HookTask
|
|
5
|
-
import type { TaskClass } from '@dotcom-tool-kit/
|
|
6
|
-
declare const s: {
|
|
7
|
-
hook: colours.StyleFunction;
|
|
8
|
-
task: colours.StyleFunction;
|
|
9
|
-
plugin: colours.StyleFunction;
|
|
10
|
-
URL: colours.StyleFunction;
|
|
11
|
-
filepath: colours.StyleFunction;
|
|
12
|
-
app: colours.StyleFunction;
|
|
13
|
-
option: colours.StyleFunction;
|
|
14
|
-
makeTarget: colours.StyleFunction;
|
|
15
|
-
heading: colours.StyleFunction;
|
|
16
|
-
dim: colours.StyleFunction;
|
|
17
|
-
title: colours.StyleFunction;
|
|
18
|
-
error: (string: string) => string;
|
|
19
|
-
warning: (string: string) => string;
|
|
20
|
-
ruler: () => string;
|
|
21
|
-
};
|
|
22
|
-
export { s as styles };
|
|
3
|
+
import type { HookTask } from './hook';
|
|
4
|
+
import type { Hook, TaskClass } from '@dotcom-tool-kit/types';
|
|
23
5
|
export declare const formatTaskConflicts: (conflicts: Conflict<TaskClass>[]) => string;
|
|
24
|
-
export declare const formatHookConflicts: (conflicts: Conflict<
|
|
6
|
+
export declare const formatHookConflicts: (conflicts: Conflict<Hook>[]) => string;
|
|
25
7
|
export declare const formatHookTaskConflicts: (conflicts: Conflict<HookTask>[]) => string;
|
|
26
8
|
export declare const formatOptionConflicts: (conflicts: Conflict<PluginOptions>[]) => string;
|
|
27
9
|
export declare const formatUndefinedHookTasks: (undefinedHooks: HookTask[], definedHooks: string[]) => string;
|
|
28
|
-
export declare const
|
|
10
|
+
export declare const formatUnusedOptions: (unusedOptions: string[], definedPlugins: string[]) => string;
|
|
11
|
+
export declare const formatUninstalledHooks: (uninstalledHooks: Hook[]) => string;
|
|
29
12
|
declare type Missing = {
|
|
30
13
|
hook: HookTask;
|
|
31
14
|
tasks: string[];
|
|
32
15
|
};
|
|
33
16
|
export declare const formatMissingTasks: (missingTasks: Missing[], tasks: string[]) => string;
|
|
17
|
+
export {};
|
|
34
18
|
//# sourceMappingURL=messages.d.ts.map
|
package/lib/messages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEtC,OAAO,KAAK,EAAU,IAAI,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AASrE,eAAO,MAAM,mBAAmB,cAAe,SAAS,SAAS,CAAC,EAAE,KAAG,MAKE,CAAA;AASzE,eAAO,MAAM,mBAAmB,cAAe,SAAS,IAAI,CAAC,EAAE,KAAG,MAKO,CAAA;AAazE,eAAO,MAAM,uBAAuB,cAAe,SAAS,QAAQ,CAAC,EAAE,KAAG,MAQzE,CAAA;AAOD,eAAO,MAAM,qBAAqB,cAAe,SAAS,aAAa,CAAC,EAAE,KAAG,MAU5E,CAAA;AAMD,eAAO,MAAM,wBAAwB,mBACnB,QAAQ,EAAE,gBACZ,MAAM,EAAE,KACrB,MAWF,CAAA;AAED,eAAO,MAAM,mBAAmB,kBACf,MAAM,EAAE,kBACP,MAAM,EAAE,KACvB,MAWF,CAAA;AAED,eAAO,MAAM,sBAAsB,qBACf,IAAI,EAAE,KACvB,MAKF,CAAA;AAED,aAAK,OAAO,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAOlD,eAAO,MAAM,kBAAkB,iBACf,OAAO,EAAE,SAChB,MAAM,EAAE,KACd,MAOF,CAAA"}
|
package/lib/messages.js
CHANGED
|
@@ -1,91 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatMissingTasks = exports.formatUninstalledHooks = exports.formatUndefinedHookTasks = exports.formatOptionConflicts = exports.formatHookTaskConflicts = exports.formatHookConflicts = exports.formatTaskConflicts =
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
hook: ansi_colors_1.default.magenta,
|
|
10
|
-
task: ansi_colors_1.default.blueBright,
|
|
11
|
-
plugin: ansi_colors_1.default.cyan,
|
|
12
|
-
URL: ansi_colors_1.default.cyan.underline,
|
|
13
|
-
filepath: ansi_colors_1.default.italic,
|
|
14
|
-
app: ansi_colors_1.default.green,
|
|
15
|
-
option: ansi_colors_1.default.blue,
|
|
16
|
-
makeTarget: ansi_colors_1.default.grey.italic,
|
|
17
|
-
heading: ansi_colors_1.default.bold,
|
|
18
|
-
dim: ansi_colors_1.default.grey,
|
|
19
|
-
title: ansi_colors_1.default.bold.underline,
|
|
20
|
-
error: (string) => `${ansi_colors_1.default.red.bold('‼︎')} ${s.title(string)}`,
|
|
21
|
-
warning: (string) => `${ansi_colors_1.default.yellow.bold('⚠︎')} ${s.title(string)}`,
|
|
22
|
-
ruler: () => s.dim('─'.repeat(process.stdout.columns / 2))
|
|
23
|
-
};
|
|
24
|
-
exports.styles = s;
|
|
25
|
-
const formatTaskConflict = (conflict) => `- ${s.task(conflict.conflicting[0].id || 'unknown task')} ${s.dim('from plugins')} ${conflict.conflicting
|
|
26
|
-
.map((task) => s.plugin(task.plugin ? task.plugin.id : 'unknown plugin'))
|
|
27
|
-
.join(s.dim(', '))}`;
|
|
28
|
-
const formatTaskConflicts = (conflicts) => `${s.heading('There are multiple plugins that include the same tasks')}:
|
|
3
|
+
exports.formatMissingTasks = exports.formatUninstalledHooks = exports.formatUnusedOptions = exports.formatUndefinedHookTasks = exports.formatOptionConflicts = exports.formatHookTaskConflicts = exports.formatHookConflicts = exports.formatTaskConflicts = void 0;
|
|
4
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
5
|
+
const formatTaskConflict = (conflict) => `- ${logger_1.styles.task(conflict.conflicting[0].id || 'unknown task')} ${logger_1.styles.dim('from plugins')} ${conflict.conflicting
|
|
6
|
+
.map((task) => logger_1.styles.plugin(task.plugin ? task.plugin.id : 'unknown plugin'))
|
|
7
|
+
.join(logger_1.styles.dim(', '))}`;
|
|
8
|
+
const formatTaskConflicts = (conflicts) => `${logger_1.styles.heading('There are multiple plugins that include the same tasks')}:
|
|
29
9
|
${conflicts.map(formatTaskConflict).join('\n')}
|
|
30
10
|
|
|
31
11
|
You must resolve this conflict by removing all but one of these plugins.`;
|
|
32
12
|
exports.formatTaskConflicts = formatTaskConflicts;
|
|
33
|
-
const formatHookConflict = (conflict) => `- ${
|
|
34
|
-
.map((task) =>
|
|
35
|
-
.join(
|
|
36
|
-
const formatHookConflicts = (conflicts) => `${
|
|
13
|
+
const formatHookConflict = (conflict) => `- ${logger_1.styles.hook(conflict.conflicting[0].id || 'unknown event')} ${logger_1.styles.dim('from plugins')} ${conflict.conflicting
|
|
14
|
+
.map((task) => logger_1.styles.plugin(task.plugin ? task.plugin.id : 'unknown plugin'))
|
|
15
|
+
.join(logger_1.styles.dim(', '))}`;
|
|
16
|
+
const formatHookConflicts = (conflicts) => `${logger_1.styles.heading('There are multiple plugins that include the same hooks')}:
|
|
37
17
|
${conflicts.map(formatHookConflict).join('\n')}
|
|
38
18
|
|
|
39
19
|
You must resolve this conflict by removing all but one of these plugins.`;
|
|
40
20
|
exports.formatHookConflicts = formatHookConflicts;
|
|
41
|
-
const formatHookTaskConflict = (conflict) => `${
|
|
21
|
+
const formatHookTaskConflict = (conflict) => `${logger_1.styles.hook(conflict.conflicting[0].id)}:
|
|
42
22
|
${conflict.conflicting
|
|
43
|
-
.map((hook) => `- ${hook.tasks.map(
|
|
23
|
+
.map((hook) => `- ${hook.tasks.map(logger_1.styles.task).join(logger_1.styles.dim(', '))} ${logger_1.styles.dim('by plugin')} ${logger_1.styles.plugin(hook.plugin.id)}`)
|
|
44
24
|
.join('\n')}
|
|
45
25
|
`;
|
|
46
|
-
const formatHookTaskConflicts = (conflicts) => `${
|
|
26
|
+
const formatHookTaskConflicts = (conflicts) => `${logger_1.styles.heading('These hooks are configured to run different tasks by multiple plugins')}:
|
|
47
27
|
${conflicts.map(formatHookTaskConflict).join('\n')}
|
|
48
|
-
You must resolve this conflict by explicitly configuring which task to run for these hooks. See ${
|
|
28
|
+
You must resolve this conflict by explicitly configuring which task to run for these hooks. See ${logger_1.styles.URL('https://github.com/financial-times/dotcom-tool-kit/tree/main/docs/resolving-hook-conflicts.md')} for more details.
|
|
49
29
|
|
|
50
30
|
`;
|
|
51
31
|
exports.formatHookTaskConflicts = formatHookTaskConflicts;
|
|
52
|
-
const formatOptionConflict = (conflict) => `${
|
|
53
|
-
${conflict.conflicting.map((option) => `- ${
|
|
54
|
-
const formatOptionConflicts = (conflicts) => `${
|
|
32
|
+
const formatOptionConflict = (conflict) => `${logger_1.styles.plugin(conflict.conflicting[0].forPlugin.id)}, configured by:
|
|
33
|
+
${conflict.conflicting.map((option) => `- ${logger_1.styles.plugin(option.plugin.id)}`)}`;
|
|
34
|
+
const formatOptionConflicts = (conflicts) => `${logger_1.styles.heading('These plugins have conflicting options')}:
|
|
55
35
|
|
|
56
36
|
${conflicts.map(formatOptionConflict).join('\n')}
|
|
57
37
|
|
|
58
|
-
You must resolve this conflict by providing options in your app's Tool Kit configuration for these plugins, or installing a use-case plugin that provides these options. See ${
|
|
38
|
+
You must resolve this conflict by providing options in your app's Tool Kit configuration for these plugins, or installing a use-case plugin that provides these options. See ${logger_1.styles.URL('https://github.com/financial-times/dotcom-tool-kit/tree/main/readme.md#options')} for more details.
|
|
59
39
|
|
|
60
40
|
`;
|
|
61
41
|
exports.formatOptionConflicts = formatOptionConflicts;
|
|
62
|
-
const formatPlugin = (plugin) => plugin.id === 'app root' ?
|
|
42
|
+
const formatPlugin = (plugin) => plugin.id === 'app root' ? logger_1.styles.app('your app') : `plugin ${logger_1.styles.plugin(plugin.id)}`;
|
|
63
43
|
// TODO text similarity "did you mean...?"
|
|
64
44
|
const formatUndefinedHookTasks = (undefinedHooks, definedHooks) => `Hooks must be defined by a plugin before you can configure a task to run for them. In your Tool Kit configuration you've configured hooks that aren't defined:
|
|
65
45
|
|
|
66
|
-
${undefinedHooks.map((hook) => `- ${
|
|
46
|
+
${undefinedHooks.map((hook) => `- ${logger_1.styles.hook(hook.id)}`).join('\n')}
|
|
67
47
|
|
|
68
48
|
They could be misspelt, or defined by a Tool Kit plugin that isn't installed in this app.
|
|
69
49
|
|
|
70
50
|
${definedHooks.length > 0
|
|
71
|
-
? `Hooks that are defined and available for tasks are: ${definedHooks.map(
|
|
51
|
+
? `Hooks that are defined and available for tasks are: ${definedHooks.map(logger_1.styles.hook).join(', ')}`
|
|
72
52
|
: `There are no hooks defined by this app's plugins. You probably need to install some plugins to define hooks.`}.
|
|
73
53
|
`;
|
|
74
54
|
exports.formatUndefinedHookTasks = formatUndefinedHookTasks;
|
|
55
|
+
const formatUnusedOptions = (unusedOptions, definedPlugins) => `Options are defined in your Tool Kit configuration for plugins that don't exist:
|
|
56
|
+
|
|
57
|
+
${unusedOptions.map((optionName) => `- ${logger_1.styles.plugin(optionName)}`).join('\n')}
|
|
58
|
+
|
|
59
|
+
They could be misspelt, or defined by a Tool Kit plugin that isn't installed in this app.
|
|
60
|
+
|
|
61
|
+
${definedPlugins.length > 0
|
|
62
|
+
? `Plugins that are defined and can have options set are: ${definedPlugins.map(logger_1.styles.plugin).join(', ')}`
|
|
63
|
+
: `There are no plugins installed currently. You'll need to install some plugins before options can be set.`}.
|
|
64
|
+
`;
|
|
65
|
+
exports.formatUnusedOptions = formatUnusedOptions;
|
|
75
66
|
const formatUninstalledHooks = (uninstalledHooks) => `These hooks aren't installed into your app:
|
|
76
67
|
|
|
77
|
-
${uninstalledHooks.map((hook) => `- ${
|
|
68
|
+
${uninstalledHooks.map((hook) => `- ${logger_1.styles.hook(hook.id || 'unknown event')}`).join('\n')}
|
|
78
69
|
|
|
79
|
-
Run ${
|
|
70
|
+
Run ${logger_1.styles.task('dotcom-tool-kit --install')} to install these hooks.
|
|
80
71
|
`;
|
|
81
72
|
exports.formatUninstalledHooks = formatUninstalledHooks;
|
|
82
|
-
const formatMissingTask = (missing) => `- ${missing.tasks.map(
|
|
73
|
+
const formatMissingTask = (missing) => `- ${missing.tasks.map(logger_1.styles.task).join(', ')} ${logger_1.styles.dim(`(assigned to ${logger_1.styles.hook(missing.hook.id)} by ${formatPlugin(missing.hook.plugin)})`)}`;
|
|
83
74
|
const formatMissingTasks = (missingTasks, tasks) => `These tasks don't exist, but are configured to run from hooks:
|
|
84
75
|
|
|
85
76
|
${missingTasks.map(formatMissingTask).join('\n')}
|
|
86
77
|
|
|
87
78
|
They could be misspelt, or defined by a Tool Kit plugin that isn't used by this app.
|
|
88
79
|
|
|
89
|
-
Available tasks are: ${tasks.map(
|
|
80
|
+
Available tasks are: ${tasks.map(logger_1.styles.task).join(', ')}.
|
|
90
81
|
`;
|
|
91
82
|
exports.formatMissingTasks = formatMissingTasks;
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { HookClass } from './hook';
|
|
1
|
+
import type { Logger } from 'winston';
|
|
3
2
|
import { Config } from './config';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
tasks?: TaskClass[];
|
|
9
|
-
hooks?: {
|
|
10
|
-
[id: string]: HookClass;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export declare function loadPluginConfig(plugin: Plugin, config: Config): Promise<Config>;
|
|
14
|
-
export declare function loadPlugin(id: string, config: Config, parent?: Plugin): Promise<Plugin>;
|
|
15
|
-
export declare function loadPlugins(plugins: string[], config: Config, parent?: Plugin): Promise<Plugin[]>;
|
|
3
|
+
import { Plugin } from '@dotcom-tool-kit/types';
|
|
4
|
+
export declare function loadPluginConfig(logger: Logger, plugin: Plugin, config: Config): Promise<Config>;
|
|
5
|
+
export declare function loadPlugin(logger: Logger, id: string, config: Config, parent?: Plugin): Promise<Plugin>;
|
|
6
|
+
export declare function loadPlugins(logger: Logger, plugins: string[], config: Config, parent?: Plugin): Promise<Plugin[]>;
|
|
16
7
|
//# sourceMappingURL=plugin.d.ts.map
|
package/lib/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGrC,OAAO,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAA;AAKhD,OAAO,EAA2B,MAAM,EAAa,MAAM,wBAAwB,CAAA;AAEnF,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA6FtG;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAkFjB;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,EAAE,CAAC,CAEnB"}
|
package/lib/plugin.js
CHANGED
|
@@ -7,10 +7,13 @@ const resolve_from_1 = (0, tslib_1.__importDefault)(require("resolve-from"));
|
|
|
7
7
|
const lodash_mergewith_1 = (0, tslib_1.__importDefault)(require("lodash.mergewith"));
|
|
8
8
|
const conflict_1 = require("./conflict");
|
|
9
9
|
const rc_file_1 = require("./rc-file");
|
|
10
|
-
|
|
10
|
+
const error_1 = require("@dotcom-tool-kit/error");
|
|
11
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
12
|
+
const types_1 = require("@dotcom-tool-kit/types");
|
|
13
|
+
async function loadPluginConfig(logger, plugin, config) {
|
|
11
14
|
const { plugins = [], hooks = {}, options = {} } = await (0, rc_file_1.loadToolKitRC)(plugin.root);
|
|
12
15
|
// load any plugins requested by this plugin
|
|
13
|
-
await loadPlugins(plugins, config, plugin);
|
|
16
|
+
await loadPlugins(logger, plugins, config, plugin);
|
|
14
17
|
// load plugin hook tasks. do this after loading child plugins, so
|
|
15
18
|
// parent hooks get assigned after child hooks and can override them
|
|
16
19
|
(0, lodash_mergewith_1.default)(config.hookTasks, hooks,
|
|
@@ -72,7 +75,7 @@ async function loadPluginConfig(plugin, config) {
|
|
|
72
75
|
return config;
|
|
73
76
|
}
|
|
74
77
|
exports.loadPluginConfig = loadPluginConfig;
|
|
75
|
-
async function loadPlugin(id, config, parent) {
|
|
78
|
+
async function loadPlugin(logger, id, config, parent) {
|
|
76
79
|
// don't load duplicate plugins
|
|
77
80
|
if (id in config.plugins) {
|
|
78
81
|
return config.plugins[id];
|
|
@@ -80,7 +83,17 @@ async function loadPlugin(id, config, parent) {
|
|
|
80
83
|
const root = parent ? parent.root : process.cwd();
|
|
81
84
|
// load plugin relative to the parent plugin
|
|
82
85
|
const pluginRoot = (0, resolve_from_1.default)(root, id);
|
|
83
|
-
const
|
|
86
|
+
const rawPlugin = (0, import_from_1.default)(root, id);
|
|
87
|
+
let basePlugin;
|
|
88
|
+
try {
|
|
89
|
+
basePlugin = (0, types_1.instantiatePlugin)(rawPlugin, logger);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error instanceof error_1.ToolKitError) {
|
|
93
|
+
error.details = `the package ${logger_1.styles.plugin(id)} at ${logger_1.styles.filepath(pluginRoot)} is not a valid plugin`;
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
84
97
|
const plugin = {
|
|
85
98
|
...basePlugin,
|
|
86
99
|
id,
|
|
@@ -115,11 +128,11 @@ async function loadPlugin(id, config, parent) {
|
|
|
115
128
|
conflicting: conflicting.concat(newHook)
|
|
116
129
|
};
|
|
117
130
|
});
|
|
118
|
-
await loadPluginConfig(plugin, config);
|
|
131
|
+
await loadPluginConfig(logger, plugin, config);
|
|
119
132
|
return plugin;
|
|
120
133
|
}
|
|
121
134
|
exports.loadPlugin = loadPlugin;
|
|
122
|
-
function loadPlugins(plugins, config, parent) {
|
|
123
|
-
return Promise.all(plugins.map((plugin) => loadPlugin(plugin, config, parent)));
|
|
135
|
+
function loadPlugins(logger, plugins, config, parent) {
|
|
136
|
+
return Promise.all(plugins.map((plugin) => loadPlugin(logger, plugin, config, parent)));
|
|
124
137
|
}
|
|
125
138
|
exports.loadPlugins = loadPlugins;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dotcom-tool-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2-beta.3",
|
|
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",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/financial-times/dotcom-tool-kit.git",
|
|
10
|
-
"directory": "
|
|
10
|
+
"directory": "core/cli"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/financial-times/dotcom-tool-kit",
|
|
13
13
|
"bugs": "https://github.com/financial-times/dotcom-tool-kit/issues",
|
|
@@ -17,21 +17,24 @@
|
|
|
17
17
|
"dotcom-tool-kit": "./bin/run"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"test": "cd ../../ ; npx jest --silent --projects
|
|
20
|
+
"test": "cd ../../ ; npx jest --silent --projects core/cli"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@jest/globals": "^26.6.2",
|
|
23
|
+
"@jest/globals": "^27.4.6",
|
|
25
24
|
"@types/lodash.mergewith": "^4.6.6",
|
|
26
25
|
"@types/node": "^12.20.24",
|
|
27
26
|
"chai": "^4.3.4",
|
|
28
27
|
"globby": "^10.0.2",
|
|
29
|
-
"ts-node": "^8.10.2"
|
|
28
|
+
"ts-node": "^8.10.2",
|
|
29
|
+
"winston": "^3.5.1"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@dotcom-tool-kit/error": "^1.0.
|
|
33
|
-
"@dotcom-tool-kit/
|
|
34
|
-
"
|
|
32
|
+
"@dotcom-tool-kit/error": "^1.0.2-beta.3",
|
|
33
|
+
"@dotcom-tool-kit/hook": "^1.0.2-beta.3",
|
|
34
|
+
"@dotcom-tool-kit/logger": "^1.0.2-beta.3",
|
|
35
|
+
"@dotcom-tool-kit/options": "^1.0.2-beta.3",
|
|
36
|
+
"@dotcom-tool-kit/types": "^1.0.2-beta.3",
|
|
37
|
+
"@dotcom-tool-kit/wait-for-ok": "^1.0.2-beta.3",
|
|
35
38
|
"cosmiconfig": "^7.0.0",
|
|
36
39
|
"import-from": "^3.0.0",
|
|
37
40
|
"lodash.mergewith": "^4.6.2",
|