Skip to content

Commit 30fce93

Browse files
committed
feat(logger): use threaded logger
1 parent 682b503 commit 30fce93

File tree

22 files changed

+407
-980
lines changed

22 files changed

+407
-980
lines changed

bin/commands/generate.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ import {
99
} from '../../src/constants.mjs';
1010
import { publicGenerators } from '../../src/generators/index.mjs';
1111
import createGenerator from '../../src/generators.mjs';
12+
import logger from '../../src/logger/index.mjs';
13+
import transports from '../../src/logger/transports.mjs';
1214
import { parseChangelog, parseIndex } from '../../src/parsers/markdown.mjs';
1315
import { loadAndParse } from '../utils.mjs';
1416

1517
const availableGenerators = Object.keys(publicGenerators);
18+
const availableTransports = Object.keys(transports);
1619

1720
/**
1821
* @typedef {Object} Options
1922
* @property {Array<string>|string} input - Specifies the glob/path for input files.
2023
* @property {Array<string>|string} [ignore] - Specifies the glob/path for ignoring files.
2124
* @property {Array<keyof publicGenerators>} target - Specifies the generator target mode.
25+
* @property {keyof availableTransports} transport - Specified the logging transport.
2226
* @property {string} version - Specifies the target Node.js version.
2327
* @property {string} changelog - Specifies the path to the Node.js CHANGELOG.md file.
2428
* @property {string} [gitRef] - Git ref/commit URL.
@@ -104,6 +108,15 @@ export default {
104108
})),
105109
},
106110
},
111+
transport: {
112+
flags: ['--transport [transport]'],
113+
desc: 'Transport for logging',
114+
prompt: {
115+
type: 'multiselect',
116+
options: availableTransports.map(t => ({ value: t, label: t })),
117+
initialValue: 'pretty',
118+
},
119+
},
107120
index: {
108121
flags: ['--index <path>'],
109122
desc: 'The index document, for getting the titles of various API docs',
@@ -119,6 +132,8 @@ export default {
119132
* @returns {Promise<void>}
120133
*/
121134
async action(opts) {
135+
logger.add(transports[opts.transport]());
136+
122137
const docs = await loadAndParse(opts.input, opts.ignore);
123138
const releases = await parseChangelog(opts.changelog);
124139
const index = opts.index && (await parseIndex(opts.index));

bin/commands/interactive.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@clack/prompts';
1414

1515
import commands from './index.mjs';
16-
import { Logger } from '../../src/logger/index.mjs';
16+
import logger from '../../src/logger/index.mjs';
1717

1818
/**
1919
* Validates that a string is not empty.
@@ -166,7 +166,7 @@ export default async function interactive() {
166166

167167
const finalCommand = cmdParts.join(' ');
168168

169-
Logger.getInstance().info(`\nGenerated command:\n${finalCommand}\n`);
169+
logger.info(`\nGenerated command:\n${finalCommand}\n`);
170170

171171
// Step 5: Confirm and execute the generated command
172172
if (await confirm({ message: 'Run now?', initialValue: true })) {

bin/utils.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import createMarkdownLoader from '../src/loaders/markdown.mjs';
2-
import { Logger } from '../src/logger/index.mjs';
2+
import logger from '../src/logger/index.mjs';
33
import createMarkdownParser from '../src/parsers/markdown.mjs';
44

55
/**
@@ -43,7 +43,7 @@ export const errorWrap =
4343
try {
4444
return await fn(...args);
4545
} catch (err) {
46-
Logger.getInstance().error(err);
46+
logger.error(err);
4747
process.exit(1);
4848
}
4949
};

0 commit comments

Comments
 (0)