当你连续写了多个 Node 应用, 都想要 console 漂亮一点, 你可能会像下面这样封装一个函数git
import chalk from "chalk";
function noop(msg: string): string {
return msg
}
function log(fn: Function): (msg: string) => void {
return (msg: string): void => {
console.log(fn(msg));
};
}
export default {
success: log(chalk.green),
error: log(chalk.red),
warn: log(chalk.yellow),
info: log(chalk.cyan),
log: log(noop)
};
复制代码
调用方式github
import log from './log'
log.success("hello green message!")
log.error("hello red message!")
log.warn("hello yellow message!")
log.info("hello cyan message!")
log.log("hello normal message!")
复制代码
慢慢的发现每一个项目都须要这么一个 log 文件, 是的! 咱们此时能够考虑把这些经常使用的函数封装集合到一个 npm 包里面了!npm
考虑到代码量的增长以及贡献者的增长事先加入单元测试是颇有必要的浏览器
Travis CI 提供的是持续集成服务(Continuous Integration,简称 CI)。它绑定 Github 上面的项目,只要有新的代码,就会自动抓取。而后,提供一个运行环境,执行测试,完成构建,还能部署到服务器。 bash
![]()
当 src 目录新增一个实用函数文件, index.ts 可以自动抓取而后挂载在 module.export 上服务器
Object.defineProperty(module.export, 'log', {
configurable: false,
enumerable: true,
get: () => require('./log')
});
复制代码
github.com/xiaoxiaojx/… 欢迎 🌟 Star 🌟 和 Pr 和 在项目中使用~框架