Yeman 搭建脚手架

 

一、在全局范围安装 yo

$ npm install yo --global # or yarn global add yo

  

二、安装对应的 generator

$ npm install generator-node --global # yarn global add generator-node

  

三、通过 yo 运行 generator [ 生成 yo 的目录结构 ]

$ mkdir my-module
$ yo node

 

如果以上报错,请自行执行 npm install

I'm all done. Running npm install for you to install the required dependencies. If this fails, try running the command yourself.

 

四、安装node:cli 

$ yo node:cli

  

五、将该项目暴露到全局

$ yarn link

如果你看到以下内容,说明,项目暴露到全局成功

info You can now run `yarn link "***你的项目名"` in the projects where you want to use this package and it will be used instead.

 

六、测试 全局是否可以找到该项目

$ ***你的项目名 --help  (my-module --help) 

  

啊哟喂:报错了 -bash: /usr/local/bin/my-module: Permission denied ,看来是没有权限导致的

 

解决方案:

1. 到上一个目录,

$ cd ..

2. 将该项目授权

$ sudo chmod -R 777 项目名

3. 回到项目中

$ cd my-module

4. 再次查看

$ my-module --help

  

啊哦,又卡着了, 

Error: Cannot find module 'meow' ----提示缺少“meow”模版

1. 安装模版

$ cnpm install meow # yarn add meow

2. 再次测试 my-module 

my-module --help

如看到以下,则表示成功
  脚手架

  Usage
    $ gqx-cli [input]

  Options
    --foo  Lorem ipsum. [Default: false]

  Examples
    $ gqx-cli
    unicorns
    $ gqx-cli rainbows
    unicorns & rainbows

 

七、打开 yeman 网址,选择适合你的 generator 

$ yarn global add generator webapp (webapp 是我选择的 generator)

  

八、yeman 运行 webapp

$ yo webapp

 

九、 使用脚手架

  1. 在其他文件夹,新建 my-cli 文件夹
  2. 因为在第六步已经将该文件设置为全局访问,所以可以直接使用
  3. 控制台输入 $ my-module 
  4. 在目录下查看 my-cli内是否有my-module 内包含的文件,如果已经存在则成功

 

posted @ 2020-08-10 14:15  小短腿奔跑吧  阅读(249)  评论(0编辑  收藏  举报