dotcom-tool-kit 1.3.0 → 1.4.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 +10 -8
- package/lib/config.d.ts +3 -2
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +2 -2
- package/lib/help.d.ts +2 -1
- package/lib/help.d.ts.map +1 -1
- package/lib/help.js +13 -13
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -8
- package/lib/install.d.ts +2 -1
- package/lib/install.d.ts.map +1 -1
- package/lib/install.js +3 -3
- package/lib/messages.d.ts +1 -18
- package/lib/messages.d.ts.map +1 -1
- package/lib/messages.js +27 -47
- package/lib/plugin.d.ts +4 -3
- package/lib/plugin.d.ts.map +1 -1
- package/lib/plugin.js +9 -9
- package/package.json +9 -8
package/bin/run
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
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'],
|
|
6
5
|
'--': true
|
|
7
6
|
})
|
|
8
7
|
|
|
9
8
|
const { runTasks, showHelp, installHooks } = require('../lib')
|
|
10
|
-
const { styles } = require('
|
|
9
|
+
const { rootLogger, styles } = require('@dotcom-tool-kit/logger')
|
|
11
10
|
|
|
12
11
|
async function main() {
|
|
13
12
|
try {
|
|
14
13
|
if (argv.install) {
|
|
15
|
-
await installHooks()
|
|
14
|
+
await installHooks(rootLogger)
|
|
16
15
|
} else if (argv.help || argv._.length === 0) {
|
|
17
|
-
await showHelp(argv._)
|
|
16
|
+
await showHelp(rootLogger, argv._)
|
|
18
17
|
} else {
|
|
19
18
|
if (argv['--'].length > 0) {
|
|
20
19
|
// The `--` in a command such as `dotcom-tool-kit test:staged --`
|
|
@@ -24,16 +23,19 @@ async function main() {
|
|
|
24
23
|
// the command becomes something like `dotcom-tool-kit test:staged --
|
|
25
24
|
// index.js`. When this command is executed it runs the configured task
|
|
26
25
|
// where the file path arguments would then be extracted.
|
|
27
|
-
await runTasks(argv._, argv['--'])
|
|
26
|
+
await runTasks(rootLogger, argv._, argv['--'])
|
|
28
27
|
} else {
|
|
29
|
-
await runTasks(argv._)
|
|
28
|
+
await runTasks(rootLogger, argv._)
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
} catch (error) {
|
|
33
32
|
if (error.details) {
|
|
34
|
-
|
|
33
|
+
rootLogger.error('', { skipformat: true })
|
|
34
|
+
rootLogger.error(error.message)
|
|
35
|
+
rootLogger.error(styles.ruler(), { skipformat: true })
|
|
36
|
+
rootLogger.error(error.details, { skipformat: true })
|
|
35
37
|
} else {
|
|
36
|
-
|
|
38
|
+
rootLogger.error(error.stack)
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
process.exitCode = error.exitCode || 1
|
package/lib/config.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Logger } from 'winston';
|
|
1
2
|
import type { HookTask } from './hook';
|
|
2
3
|
import { Conflict } from './conflict';
|
|
3
4
|
import type { TaskClass, Hook, Plugin } from '@dotcom-tool-kit/types';
|
|
@@ -40,10 +41,10 @@ export interface ValidConfig extends Config {
|
|
|
40
41
|
}
|
|
41
42
|
export declare function validateConfig(config: Config): Promise<ValidConfig>;
|
|
42
43
|
export declare function checkInstall(config: ValidConfig): Promise<void>;
|
|
43
|
-
export declare function loadConfig(options?: {
|
|
44
|
+
export declare function loadConfig(logger: Logger, options?: {
|
|
44
45
|
validate?: true;
|
|
45
46
|
}): Promise<ValidConfig>;
|
|
46
|
-
export declare function loadConfig(options?: {
|
|
47
|
+
export declare function loadConfig(logger: Logger, options?: {
|
|
47
48
|
validate?: false;
|
|
48
49
|
}): Promise<Config>;
|
|
49
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
|
@@ -99,9 +99,9 @@ async function checkInstall(config) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
exports.checkInstall = checkInstall;
|
|
102
|
-
async function loadConfig({ validate = true } = {}) {
|
|
102
|
+
async function loadConfig(logger, { validate = true } = {}) {
|
|
103
103
|
// start loading config and child plugins, starting from the consumer app directory
|
|
104
|
-
const config = await (0, plugin_1.loadPluginConfig)({
|
|
104
|
+
const config = await (0, plugin_1.loadPluginConfig)(logger, {
|
|
105
105
|
id: 'app root',
|
|
106
106
|
root: process.cwd()
|
|
107
107
|
}, createConfig());
|
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":"
|
|
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
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const config_1 = require("./config");
|
|
4
4
|
const options_1 = require("@dotcom-tool-kit/options");
|
|
5
|
-
const
|
|
6
|
-
async function showHelp(hooks) {
|
|
7
|
-
const config = await (0, config_1.loadConfig)();
|
|
5
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
6
|
+
async function showHelp(logger, hooks) {
|
|
7
|
+
const config = await (0, config_1.loadConfig)(logger);
|
|
8
8
|
if (hooks.length === 0) {
|
|
9
9
|
hooks = Object.keys(config.hooks).sort();
|
|
10
10
|
}
|
|
@@ -15,17 +15,17 @@ async function showHelp(hooks) {
|
|
|
15
15
|
}
|
|
16
16
|
await (0, config_1.checkInstall)(config);
|
|
17
17
|
const missingHooks = hooks.filter((hook) => !config.hooks[hook]);
|
|
18
|
-
|
|
19
|
-
🧰 ${
|
|
18
|
+
logger.info(`
|
|
19
|
+
🧰 ${logger_1.styles.title(`welcome to ${logger_1.styles.app('Tool Kit')}!`)}
|
|
20
20
|
|
|
21
21
|
Tool Kit is modern, maintainable & modular developer tooling for FT.com projects.
|
|
22
22
|
|
|
23
|
-
${
|
|
23
|
+
${logger_1.styles.URL('https://github.com/financial-times/dotcom-tool-kit')}
|
|
24
24
|
|
|
25
|
-
${
|
|
25
|
+
${logger_1.styles.ruler()}
|
|
26
26
|
${Object.keys(config.hooks).length === 0
|
|
27
27
|
? `there are no hooks available. you'll need to install plugins that define hooks to be able to run Tool Kit tasks.`
|
|
28
|
-
:
|
|
28
|
+
: logger_1.styles.dim(hooks.length === 0
|
|
29
29
|
? 'available hooks'
|
|
30
30
|
: `help for ${hooks.length - missingHooks.length} ${hooks.length - missingHooks.length > 1 ? 'hooks' : 'hook'}`)}:
|
|
31
31
|
`);
|
|
@@ -34,21 +34,21 @@ ${Object.keys(config.hooks).length === 0
|
|
|
34
34
|
if (Hook) {
|
|
35
35
|
const tasks = config.hookTasks[hook];
|
|
36
36
|
/* eslint-disable @typescript-eslint/no-explicit-any -- Object.constructor does not consider static properties */
|
|
37
|
-
|
|
37
|
+
logger.info(`${logger_1.styles.heading(hook)}
|
|
38
38
|
${Hook.constructor.description ? Hook.constructor.description + '\n' : ''}
|
|
39
39
|
${tasks && tasks.tasks.length
|
|
40
40
|
? `runs ${tasks.tasks.length > 1 ? 'these tasks' : 'this task'}:
|
|
41
41
|
${tasks.tasks
|
|
42
|
-
.map((task) => `- ${
|
|
42
|
+
.map((task) => `- ${logger_1.styles.task(task)} ${logger_1.styles.dim(config.tasks[task].description)}`)
|
|
43
43
|
.join('\n')}`
|
|
44
|
-
:
|
|
45
|
-
${
|
|
44
|
+
: logger_1.styles.dim('no tasks configured to run on this hook.')}
|
|
45
|
+
${logger_1.styles.ruler()}
|
|
46
46
|
`);
|
|
47
47
|
/*eslint-enable @typescript-eslint/no-explicit-any */
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
if (missingHooks.length) {
|
|
51
|
-
|
|
51
|
+
logger.warn(`no such ${missingHooks.length > 1 ? 'hooks' : 'hook'} ${missingHooks.map(logger_1.styles.hook).join(', ')}`);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
exports.default = showHelp;
|
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 messages_1 = require("./messages");
|
|
10
9
|
const options_1 = require("@dotcom-tool-kit/options");
|
|
11
|
-
|
|
12
|
-
|
|
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}`)
|
|
@@ -32,7 +32,7 @@ ${availableHooks}`;
|
|
|
32
32
|
for (const hook of hooks) {
|
|
33
33
|
const errors = [];
|
|
34
34
|
if (!config.hookTasks[hook]) {
|
|
35
|
-
|
|
35
|
+
logger.warn(`no task configured for ${hook}: skipping assignment...`);
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
38
|
const assignment = config.hookTasks[hook];
|
|
@@ -42,7 +42,7 @@ ${availableHooks}`;
|
|
|
42
42
|
// `Task` is an abstract class. here we know it's a concrete subclass
|
|
43
43
|
// but typescript doesn't, so cast it to any.
|
|
44
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
-
const task = new Task(options);
|
|
45
|
+
const task = new Task(logger, options);
|
|
46
46
|
try {
|
|
47
47
|
await task.run(files);
|
|
48
48
|
}
|
|
@@ -56,16 +56,16 @@ ${availableHooks}`;
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
if (errors.length > 0) {
|
|
59
|
-
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)}`);
|
|
60
60
|
error.details = errors
|
|
61
|
-
.map(({ hook, task, error }) => `${
|
|
61
|
+
.map(({ hook, task, error }) => `${logger_1.styles.heading(`${logger_1.styles.task(task)}:`)}
|
|
62
62
|
|
|
63
63
|
${error.message}${error instanceof error_1.ToolKitError
|
|
64
64
|
? `
|
|
65
65
|
|
|
66
66
|
${error.details}`
|
|
67
67
|
: ''}`)
|
|
68
|
-
.join(
|
|
68
|
+
.join(`${logger_1.styles.dim(logger_1.styles.ruler())}\n`);
|
|
69
69
|
error.exitCode = errors.length + 1;
|
|
70
70
|
throw error;
|
|
71
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":"AAEA,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAA;AAE7C,wBAA8B,YAAY,
|
|
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
|
@@ -3,8 +3,8 @@ 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
|
-
async function installHooks() {
|
|
7
|
-
const config = await (0, config_1.loadConfig)();
|
|
6
|
+
async function installHooks(logger) {
|
|
7
|
+
const config = await (0, config_1.loadConfig)(logger);
|
|
8
8
|
const tasks = Object.values(config.hooks).map((hook) => async () => {
|
|
9
9
|
if (!(await hook.check())) {
|
|
10
10
|
await hook.install();
|
|
@@ -31,7 +31,7 @@ async function installHooks() {
|
|
|
31
31
|
}
|
|
32
32
|
if (errors.length) {
|
|
33
33
|
const error = new error_1.ToolKitError('could not automatically install hooks:');
|
|
34
|
-
error.details = errors.map((error) => error.message).join('\n
|
|
34
|
+
error.details = errors.map((error) => `- ${error.message}`).join('\n');
|
|
35
35
|
throw error;
|
|
36
36
|
}
|
|
37
37
|
return config;
|
package/lib/messages.d.ts
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
|
-
import colours from 'ansi-colors';
|
|
2
1
|
import type { PluginOptions } from './config';
|
|
3
2
|
import type { Conflict } from './conflict';
|
|
4
3
|
import type { HookTask } from './hook';
|
|
5
4
|
import type { Hook, TaskClass } from '@dotcom-tool-kit/types';
|
|
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 };
|
|
23
5
|
export declare const formatTaskConflicts: (conflicts: Conflict<TaskClass>[]) => string;
|
|
24
6
|
export declare const formatHookConflicts: (conflicts: Conflict<Hook>[]) => string;
|
|
25
7
|
export declare const formatHookTaskConflicts: (conflicts: Conflict<HookTask>[]) => string;
|
|
@@ -32,4 +14,5 @@ declare type Missing = {
|
|
|
32
14
|
tasks: string[];
|
|
33
15
|
};
|
|
34
16
|
export declare const formatMissingTasks: (missingTasks: Missing[], tasks: string[]) => string;
|
|
17
|
+
export {};
|
|
35
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,102 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatMissingTasks = exports.formatUninstalledHooks = exports.formatUnusedOptions = 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;
|
|
75
55
|
const formatUnusedOptions = (unusedOptions, definedPlugins) => `Options are defined in your Tool Kit configuration for plugins that don't exist:
|
|
76
56
|
|
|
77
|
-
${unusedOptions.map((optionName) => `- ${
|
|
57
|
+
${unusedOptions.map((optionName) => `- ${logger_1.styles.plugin(optionName)}`).join('\n')}
|
|
78
58
|
|
|
79
59
|
They could be misspelt, or defined by a Tool Kit plugin that isn't installed in this app.
|
|
80
60
|
|
|
81
61
|
${definedPlugins.length > 0
|
|
82
|
-
? `Plugins that are defined and can have options set are: ${definedPlugins.map(
|
|
62
|
+
? `Plugins that are defined and can have options set are: ${definedPlugins.map(logger_1.styles.plugin).join(', ')}`
|
|
83
63
|
: `There are no plugins installed currently. You'll need to install some plugins before options can be set.`}.
|
|
84
64
|
`;
|
|
85
65
|
exports.formatUnusedOptions = formatUnusedOptions;
|
|
86
66
|
const formatUninstalledHooks = (uninstalledHooks) => `These hooks aren't installed into your app:
|
|
87
67
|
|
|
88
|
-
${uninstalledHooks.map((hook) => `- ${
|
|
68
|
+
${uninstalledHooks.map((hook) => `- ${logger_1.styles.hook(hook.id || 'unknown event')}`).join('\n')}
|
|
89
69
|
|
|
90
|
-
Run ${
|
|
70
|
+
Run ${logger_1.styles.task('dotcom-tool-kit --install')} to install these hooks.
|
|
91
71
|
`;
|
|
92
72
|
exports.formatUninstalledHooks = formatUninstalledHooks;
|
|
93
|
-
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)})`)}`;
|
|
94
74
|
const formatMissingTasks = (missingTasks, tasks) => `These tasks don't exist, but are configured to run from hooks:
|
|
95
75
|
|
|
96
76
|
${missingTasks.map(formatMissingTask).join('\n')}
|
|
97
77
|
|
|
98
78
|
They could be misspelt, or defined by a Tool Kit plugin that isn't used by this app.
|
|
99
79
|
|
|
100
|
-
Available tasks are: ${tasks.map(
|
|
80
|
+
Available tasks are: ${tasks.map(logger_1.styles.task).join(', ')}.
|
|
101
81
|
`;
|
|
102
82
|
exports.formatMissingTasks = formatMissingTasks;
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { Logger } from 'winston';
|
|
1
2
|
import { Config } from './config';
|
|
2
3
|
import { Plugin } from '@dotcom-tool-kit/types';
|
|
3
|
-
export declare function loadPluginConfig(plugin: Plugin, config: Config): Promise<Config>;
|
|
4
|
-
export declare function loadPlugin(id: string, config: Config, parent?: Plugin): Promise<Plugin>;
|
|
5
|
-
export declare function loadPlugins(plugins: string[], config: Config, parent?: Plugin): Promise<Plugin[]>;
|
|
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[]>;
|
|
6
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
|
@@ -6,14 +6,14 @@ const import_from_1 = (0, tslib_1.__importDefault)(require("import-from"));
|
|
|
6
6
|
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
|
-
const messages_1 = require("./messages");
|
|
10
9
|
const rc_file_1 = require("./rc-file");
|
|
11
10
|
const error_1 = require("@dotcom-tool-kit/error");
|
|
11
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
12
12
|
const types_1 = require("@dotcom-tool-kit/types");
|
|
13
|
-
async function loadPluginConfig(plugin, config) {
|
|
13
|
+
async function loadPluginConfig(logger, plugin, config) {
|
|
14
14
|
const { plugins = [], hooks = {}, options = {} } = await (0, rc_file_1.loadToolKitRC)(plugin.root);
|
|
15
15
|
// load any plugins requested by this plugin
|
|
16
|
-
await loadPlugins(plugins, config, plugin);
|
|
16
|
+
await loadPlugins(logger, plugins, config, plugin);
|
|
17
17
|
// load plugin hook tasks. do this after loading child plugins, so
|
|
18
18
|
// parent hooks get assigned after child hooks and can override them
|
|
19
19
|
(0, lodash_mergewith_1.default)(config.hookTasks, hooks,
|
|
@@ -75,7 +75,7 @@ async function loadPluginConfig(plugin, config) {
|
|
|
75
75
|
return config;
|
|
76
76
|
}
|
|
77
77
|
exports.loadPluginConfig = loadPluginConfig;
|
|
78
|
-
async function loadPlugin(id, config, parent) {
|
|
78
|
+
async function loadPlugin(logger, id, config, parent) {
|
|
79
79
|
// don't load duplicate plugins
|
|
80
80
|
if (id in config.plugins) {
|
|
81
81
|
return config.plugins[id];
|
|
@@ -86,11 +86,11 @@ async function loadPlugin(id, config, parent) {
|
|
|
86
86
|
const rawPlugin = (0, import_from_1.default)(root, id);
|
|
87
87
|
let basePlugin;
|
|
88
88
|
try {
|
|
89
|
-
basePlugin = (0, types_1.instantiatePlugin)(rawPlugin);
|
|
89
|
+
basePlugin = (0, types_1.instantiatePlugin)(rawPlugin, logger);
|
|
90
90
|
}
|
|
91
91
|
catch (error) {
|
|
92
92
|
if (error instanceof error_1.ToolKitError) {
|
|
93
|
-
error.details = `the package ${
|
|
93
|
+
error.details = `the package ${logger_1.styles.plugin(id)} at ${logger_1.styles.filepath(pluginRoot)} is not a valid plugin`;
|
|
94
94
|
}
|
|
95
95
|
throw error;
|
|
96
96
|
}
|
|
@@ -128,11 +128,11 @@ async function loadPlugin(id, config, parent) {
|
|
|
128
128
|
conflicting: conflicting.concat(newHook)
|
|
129
129
|
};
|
|
130
130
|
});
|
|
131
|
-
await loadPluginConfig(plugin, config);
|
|
131
|
+
await loadPluginConfig(logger, plugin, config);
|
|
132
132
|
return plugin;
|
|
133
133
|
}
|
|
134
134
|
exports.loadPlugin = loadPlugin;
|
|
135
|
-
function loadPlugins(plugins, config, parent) {
|
|
136
|
-
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)));
|
|
137
137
|
}
|
|
138
138
|
exports.loadPlugins = loadPlugins;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dotcom-tool-kit",
|
|
3
|
-
"version": "1.3
|
|
3
|
+
"version": "1.4.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",
|
|
@@ -25,15 +25,16 @@
|
|
|
25
25
|
"@types/node": "^12.20.24",
|
|
26
26
|
"chai": "^4.3.4",
|
|
27
27
|
"globby": "^10.0.2",
|
|
28
|
-
"ts-node": "^8.10.2"
|
|
28
|
+
"ts-node": "^8.10.2",
|
|
29
|
+
"winston": "^3.5.1"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@dotcom-tool-kit/error": "^1.3
|
|
32
|
-
"@dotcom-tool-kit/hook": "^1.3
|
|
33
|
-
"@dotcom-tool-kit/
|
|
34
|
-
"@dotcom-tool-kit/
|
|
35
|
-
"@dotcom-tool-kit/
|
|
36
|
-
"
|
|
32
|
+
"@dotcom-tool-kit/error": "^1.4.3",
|
|
33
|
+
"@dotcom-tool-kit/hook": "^1.4.3",
|
|
34
|
+
"@dotcom-tool-kit/logger": "^1.4.3",
|
|
35
|
+
"@dotcom-tool-kit/options": "^1.4.3",
|
|
36
|
+
"@dotcom-tool-kit/types": "^1.4.3",
|
|
37
|
+
"@dotcom-tool-kit/wait-for-ok": "^1.4.3",
|
|
37
38
|
"cosmiconfig": "^7.0.0",
|
|
38
39
|
"import-from": "^3.0.0",
|
|
39
40
|
"lodash.mergewith": "^4.6.2",
|