背景

工作中难免会遇到须要新建一些雷同或相似的文件,例如在不同的我的项目中新建.gitignore、package.json、tsconfig.json文件,又或者是在同一个我的项目的不同目录下新建README.md、index.js文件。每次新建文件都须要思考应配置哪些字段,即便去复制粘贴,在我的项目之间切换或者查找某个目录下相似的文件,也是有些麻烦的。

介绍

如果有个工具能将罕用的文件作为模板暂存起来,在要应用的中央间接创立,会省去下面枯燥乏味的步骤,这就是tpl-manager所做的事件。tpl-manager是受nrm的启发,开发的一个命令行工具,用于疾速的新建模板文件,帮你省去复制粘贴这一无聊的步骤提高效率。

装置

$ npm install tpl-manager -g

示例

增加模板文件

$ tpl add README.mdSUCCESS  Add template success!

查看模板文件列表

$ tpl ls* .gitignore* README.md* package.json

应用模板新建文件

$ tpl use? Please select a template:  (Use arrow keys)❯ .gitignore   README.md   package.json 

应用键盘方向键抉择所需的模板,而后回车即可在以后所在目录下创立文件

用法

Usage: tpl [options] [command]Options:  -V, --version             output the version number  -h, --help                display help for commandCommands:  ls                        List all the templates  use [template] [name]     Use current template  add <template> [name]     Add custom template  rename <template> [name]  Change custom template name  del <template>            Delete custom template  view <template>           View the template  info <template>           Template Info  help [command]            display help for command

TODO

  • [ ] 用Typescript重写
  • [ ] 补充测试用例

集体教训

例如在某个目录下新建package.json文件,用 npm init -y 创立的模板太简略须要一些别的字段,能够补充下缺失的字段,用 tpl add package.json 命令暂存为模板便于下次应用,.gitignore、tsconfig.json、README.md文件在不同我的项目中也都相似,也能够暂存下不便下次应用。