Skip to content

Commit 2c58334

Browse files
committed
zap: logger
1 parent 9a56816 commit 2c58334

File tree

2 files changed

+61
-79
lines changed

2 files changed

+61
-79
lines changed

index.d.ts

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
11
/// <reference types="node"/>
22

3-
import fs from 'fs-extra';
4-
import chalk from 'chalk';
5-
import cheerio from 'cheerio';
6-
import semver from 'semver';
7-
import semverRegex from 'semver-regex';
8-
import _ from 'lodash';
9-
import ora from 'ora';
10-
import dedent from 'dedent';
11-
import globby from 'globby';
12-
import globParent from 'glob-parent';
13-
import isGlob from 'is-glob';
14-
import npa from 'npm-package-arg';
15-
import parseGitUrl from 'git-url-parse';
16-
import multimatch from 'multimatch';
17-
import stringifyObject from 'stringify-object';
18-
import LRU from 'lru-cache';
19-
import inquirer from 'inquirer';
20-
import execa from 'execa';
21-
import yParser from 'yargs-parser';
22-
import yUnParser from 'yargs-unparser';
23-
import debug from 'debug';
24-
import importFresh from 'import-fresh';
25-
import shell from 'shelljs';
26-
import onExit from 'signal-exit';
27-
import hash from 'hash-sum';
28-
import path from 'path';
3+
export * as fs from 'fs-extra';
4+
export * as chalk from 'chalk';
5+
export * as cheerio from 'cheerio';
6+
export * as semver from 'semver';
7+
export * as semverRegex from 'semver-regex';
8+
export * as _ from 'lodash';
9+
export * as ora from 'ora';
10+
export * as dedent from 'dedent';
11+
export * as globby from 'globby';
12+
export * as globParent from 'glob-parent';
13+
export * as isGlob from 'is-glob';
14+
export * as npa from 'npm-package-arg';
15+
export * as parseGitUrl from 'git-url-parse';
16+
export * as multimatch from 'multimatch';
17+
export * as stringifyObject from 'stringify-object';
18+
export * as LRU from 'lru-cache';
19+
export * as inquirer from 'inquirer';
20+
export * as execa from 'execa';
21+
export * as yParser from 'yargs-parser';
22+
export * as yUnParser from 'yargs-unparser';
23+
export * as debug from 'debug';
24+
export * as importFresh from 'import-fresh';
25+
export * as shell from 'shelljs';
26+
export * as onExit from 'signal-exit';
27+
export * as hash from 'hash-sum';
28+
export * as path from 'path';
2929

3030
export function tryRequire(id: string, req?: Object): any | null;
3131
export function assert(value: any, message?: string | Error): void;
3232

33-
import * as moduleAlias from './src/moduleAlias';
34-
import * as getPadLength from './src/getPadLength';
35-
import * as injectHtml from './src/injectHtml';
36-
import * as logger from './src/logger';
37-
import * as prompt from './src/prompt';
38-
import * as smartMerge from './src/smartMerge';
39-
import * as virtualFile from './src/virtualFile';
40-
import * as openBrowser from './src/openBrowser';
41-
import * as Env from './src/Env';
42-
import validateSchema from './src/validateSchema';
43-
import loadFile from './src/loadFile';
44-
45-
export { moduleAlias, getPadLength, injectHtml, loadFile, smartMerge, virtualFile, logger, prompt, openBrowser, Env };
46-
47-
export { assert, fs, chalk, cheerio, semver, semverRegex, _, ora, dedent, globby, globParent, isGlob, npa, parseGitUrl, multimatch, stringifyObject, LRU, inquirer, execa, yParser, yUnParser, debug, importFresh, shell, onExit, hash, path };
33+
export * as moduleAlias from './src/moduleAlias';
34+
export * as getPadLength from './src/getPadLength';
35+
export * as injectHtml from './src/injectHtml';
36+
export * as logger from './src/logger';
37+
export * as prompt from './src/prompt';
38+
export * as smartMerge from './src/smartMerge';
39+
export * as virtualFile from './src/virtualFile';
40+
export * as openBrowser from './src/openBrowser';
41+
export * as Env from './src/Env';
42+
export * as validateSchema from './src/validateSchema';
43+
export * as loadFile from './src/loadFile';

src/logger/index.js

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,26 @@ function dyeMessage(type, message) {
100100
}
101101

102102
const format = {
103-
debug(...arrs) {
104-
const message = utils.format(...(arrs || []));
105-
return `${chalk.bgMagenta(' DEBUG ')} ${dyeMessage('debug', message)}`;
106-
},
107-
warn(...arrs) {
108-
const message = utils.format(...(arrs || []));
109-
return `${chalk.bgYellowBright.black(' WARN ')} ${dyeMessage('warn', message)}`;
110-
},
111-
error(...arrs) {
112-
const message = utils.format(...(arrs || []));
113-
return `${chalk.bgRed(' ERROR ')} ${dyeMessage('error', message)}`;
114-
},
115-
info(...arrs) {
116-
const message = utils.format(...(arrs || []));
117-
return `${chalk.bgBlue(' INFO ')} ${dyeMessage('info', message)}`;
118-
},
119-
success(...arrs) {
120-
const message = utils.format(...(arrs || []));
121-
return `${chalk.bgHex('#007007')(' SUCCESS ')} ${dyeMessage('success', message)}`;
122-
},
103+
// debug(...arrs) {
104+
// const message = utils.format(...(arrs || []));
105+
// return `${chalk.bgMagenta(' DEBUG ')} ${dyeMessage('debug', message)}`;
106+
// },
107+
// warn(...arrs) {
108+
// const message = utils.format(...(arrs || []));
109+
// return `${chalk.bgYellowBright.black(' WARN ')} ${dyeMessage('warn', message)}`;
110+
// },
111+
// error(...arrs) {
112+
// const message = utils.format(...(arrs || []));
113+
// return `${chalk.bgRed(' ERROR ')} ${dyeMessage('error', message)}`;
114+
// },
115+
// info(...arrs) {
116+
// const message = utils.format(...(arrs || []));
117+
// return `${chalk.bgBlue(' INFO ')} ${dyeMessage('info', message)}`;
118+
// },
119+
// success(...arrs) {
120+
// const message = utils.format(...(arrs || []));
121+
// return `${chalk.bgHex('#007007')(' SUCCESS ')} ${dyeMessage('success', message)}`;
122+
// },
123123
logo(...arrs) {
124124
const message = utils.format(...(arrs || []));
125125
const { NAME } = CONSTANTS;
@@ -133,11 +133,9 @@ const format = {
133133

134134
class Logger {
135135

136-
constructor(log, { alias = new Map(), customFormat = new Map() }) {
136+
constructor(log, { alias = new Map() }) {
137137
this.npmlog = log;
138138
this.aliasMap = new Map(alias);
139-
// 兼容
140-
this.customFormatMap = new Map(customFormat);
141139
}
142140

143141
checkLevel(l) {
@@ -215,7 +213,7 @@ class Logger {
215213
if ([ 'logo', 'json' ].includes(type)) {
216214
const logger = this.getStdoutMethod(type);
217215
return (...args) => {
218-
return logger(this.format[type](...args));
216+
return logger(format[type](...args));
219217
};
220218
}
221219
const logger = this.getNpmlogMethod(type);
@@ -257,21 +255,9 @@ class Logger {
257255
return this.aliasMap.get(type);
258256
}
259257

260-
addCustomToString(key, value) {
261-
this.customFormatMap.set(key, value);
262-
}
263-
264258
newGroup(name, ...args) {
265259
const newLog = this.npmlog.newGroup(name, ...args);
266-
return factroy(newLog, { alias: this.aliasMap, customFormat: this.customFormatMap });
267-
}
268-
269-
get format() { // 兼容 toString
270-
return new Proxy(this, {
271-
get(target, prop) {
272-
return target.customFormatMap.get(prop);
273-
},
274-
});
260+
return factroy(newLog, { alias: this.aliasMap });
275261
}
276262
}
277263

@@ -302,7 +288,7 @@ function factroy(log, opts = {}) {
302288
}
303289

304290
function createInstance() {
305-
return factroy(npmlog, { customFormat: Object.entries(format) });
291+
return factroy(npmlog);
306292
}
307293

308294
module.exports = createInstance();

0 commit comments

Comments
 (0)