连接commander.js和Inquirer.js后,应该直接连接colors.js了。毕竟我们现在是从控制台输出,控制台不是太亮(看中了)。但是之前的Inquires.js厉害了,直接加了1.7w字,所以相对来说这篇文章更短。阅读tips:本文略短易读,下篇会更大,不接受投诉~1前言colors.js是Marak制作的4.1kstar(2021-06-16)仓库。接入colors.js后,可以让你的控制台更炸裂,更美观。安装:npmicolors输入代码:src/index.tsimportprogramfrom'commander';importcommonfrom'./common';importcolorsfrom'colors';program.version('0.0.1').description('Toolslibrary')program.command('jsliang').description('jslianghelpcommand').action(()=>{common();});program.command('test').description('测试通道').action(()=>{consttext=`___________________||/___/||||/||\\||/___||||___||||//|||\\||||_||\\___\\||||//—||||\\|||_||_||___||||___||//||||\\|||_||\\_____//_____/|_____||_|/_/|_||_|\\_|\\_____/`;console.log(colors.rainbow(text));});program.parse(process.argv);package.json{"name":"jsliang","version":"1.0.0","description":"Fe-util,Node工具库","main":"index.js","scripts":{"jsliang":"ts-node./src/index.tsjsliang","test":"ts-node./src/index.tstest"},"keywords":["jsliang","NodeToolkit","Node"],"author":"jsliang","license":"ISC","devDependencies":{"@types/inquirer":"^7.3.1","@types/node":"^15.12.2","@typescript-eslint/eslint-plugin":"^4.26.1","@typescript-eslint/parser":"^4.26.1","eslint":"^7.28.0","ts-node":"^10.0.0","typescript":"^4.3.2"},"dependencies":{"colors":"^1.4.0","commander":"^7.2.0","inquirer":"^8.1.0","rxjs":"^5.5.12"}}执行npmruntest,发现控制台很漂亮:在上面的代码中,添加了测试相关的说明(后面我们会把测试内容塞在这里,不用加,但是以jsliang为例)至于这个漂亮的字体,是Kalvin在线工具ASCII字体生成器用ASCII艺术字转换器转换出来的。这里推荐两个免费的,更多的朋友可以自己去挖掘。二,如果你想在颜色上做好.js,工欲善其事必先利其器,上面我们在colors.js中展示了彩虹色colors.rainbow,所以肯定还有其他颜色。从'colors'导入颜色;console.log(colors.rainbow('rainbow'));console.log(colors.black('black'));console.log(colors.red('red'));console.log(colors.green('green'));console.log(colors.yellow('yellow'));console.log(colors.blue('blue'));console.log(colors.magenta('洋红色'));console.log(colors.cyan('cyan'));console.log(colors.white('white'));console.log(colors.gray('gray'));console.log(colors.grey('grey'));console.log(colors.bgBlack('bgBlack'));console.log(colors.bgRed('bgRed'));console.log(colors.bgGreen('bgGreen'));console.log(colors.bgYellow('bgYellow'));console.log(colors.bgBlue('bgBlue'));console.log(colors.bgMagenta('bgMagenta'));console.log(颜色.bgCyan('bgCyan'));console.log(colors.bgWhite('bgWhite'));console.log(colors.bgGrey('bgGrey'));console.log(colors.reset('reset'));console.log(colors.bold('bold'));console.log(colors.dim('dim'));console.log(colors.italic('italic'));console.log(colors.underline('下划线'));console.log(colors.inverse('inverse'));console.log(colors.hidden('hidden'));console.log(colors.strikethrough('strikethrough'));console.log(colors.rainbow('rainbow'));console.log(colors.zebra('zebra'));console.log(colors.america('america'));console.log(colors.trap('trap'));console.log(colors.random('随机的'));把它们扔进测试,执行npmruntest,得到一个花哨的打印:triplerewriteconsole.logOK,我们已经华丽丽的吹口哨了,如果你每次打印都要引用颜色,那我就没法解释了因此,让我们重写console.log,以便无论何时何地使用它,我们都有彩虹色!base/getType.ts/***@namegetType*@descriptiongettype*@param{string|object}参数变量传入*/exportconstgetType=(param:string):string=>{returnObject.prototype.toString.call(param).slice(8,-1);};base/console.tsimportcolorsfrom'colors';import{getType}from'./getType';//打印索引letconsoleIndex=1;//覆盖console.logconstlog=console.log;console.log=(...args:any)=>{log(`\n---${consoleIndex++}---`);for(leti=0;i
基于https://github.com/LiangJunrong/document-library上的作品获得许可。
非本许可协议授权的使用权可从https://creativecommons.org/licenses/by-nc-sa/2.5/cn/获取。
