惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
U
Unit 42
MyScale Blog
MyScale Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
量子位
IT之家
IT之家
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Recent Announcements
Recent Announcements
V
Visual Studio Blog
G
Google Developers Blog
Last Week in AI
Last Week in AI
雷峰网
雷峰网
博客园 - 聂微东
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
博客园 - 司徒正美
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏

博客园 - 北山秋叶

macos 上的 zsh 启动问题记录 Keychron Max 键盘改键指南 Github 命令在 命令行 中访问特别慢的解决方法 ai 随想 影响记忆 monorepo(多包)管理中, 引入的 css 文件丢失的问题 (或者说package.json中的 sideEffects 的探索) 浏览器插件 Obsidian web 与 Obsidian 插件 local rest api 结合配置过程记录 package.json中的版本号 mac 下检测网络状态的命令 git clone 需要用户名密码的一个小问题 怎么才能写一个好代码 await和promise结合使用的问题 有趣的二分 ngix反向代理-之反向 redux和flux究竟有什么不同, 说点自己的理解 npm发包记录 由一个聚焦-focus-事件异常跟踪引起的总结 git查看分支的几个方法 test-your-mind-快速测试自己的代码 给Promise在外部增加断点 js中调试技巧-打印日志信息
yeoman编写自己的脚手架
北山秋叶 · 2020-07-22 · via 博客园 - 北山秋叶

在 gulp 时代, 就开始有使用 yeoman, 感觉是一个特别方便的脚手架.

在使用 angularjs 的时候, 经常用这个脚手架生成一些小东西去学习

在有了 create-react-app 这个命令之后, 似乎很少开始接触 yeoman.

yeoman 上有一个比较完善的学习教程 (getStart)[https://yeoman.io/authoring/index.html]

但是突然想到有没有 generator 的 generator ?

果然有. 操作命令如下

npm install -g generator-generator # 安装generator
mkdir bsqy && cd $_ # 新建并进入文件夹
yo generator #执行安装的generator, 输入一些自己的内容. 等待一些时间
# 生成按照你命令的名字, 比如 qs 的一文件夹  generator-qs
#进入文件夹
cd generator-qs
npm link # 让 yo 可以发现你
yo qs # 会创建一个 dummyfile.txt 文件, 并还行一些事情...


主要是看一下 目录下 generator/app/index.js 中的内容

module.exports = class extends Generator {
  prompting() {
    // Have Yeoman greet the user.
    this.log(
      yosay(`Welcome to the brilliant ${chalk.red('generator-bsqy')} generator!`)
    );

    const prompts = [
      {
        type: 'confirm',
        name: 'someAnswer',
        message: 'Would you like to enable this option?',
        default: true
      }
    ];

    return this.prompt(prompts).then(props => {
      // To access props later use this.props.someAnswer;
      this.props = props;
    });
  }

  writing() {
    this.fs.copy(
      this.templatePath('dummyfile.txt'),
      this.destinationPath('dummyfile.txt')
    );
  }

  install() {
    this.installDependencies();
  }
};

其中有 提醒, 有写入创建文件, 有安装要执行的过程, 可以说达到了一个良好代表的标准了 自解释

总结: 了解 yeoman 的快速上手, 可以快速的创建一些自己需要的模板, 如果有必要的话.