yeoman

by Krist Wongsuphasawat

克里斯特·旺苏帕萨瓦(Krist Wongsuphasawat)

使用yeoman轻松创建Yeoman生成器 (Creating Yeoman generators easily with yeoman-easily)

I’ve used Yeoman to start many of my projects. It’s an amazing web scaffolding tool.

我已经用Yeoman开始了许多项目。 这是一个了不起的Web脚手架工具。

But after creating my own generators several times, I saw the repetitive tasks, somewhat lengthy code, and part of the generator code that confused me every time.

但是,在几次创建自己的生成器之后,我看到了重复的任务,有些冗长的代码以及部分生成器代码,这些代码每次都使我感到困惑。

At one point, I ended up hacking a small utility that I kept copying over and over from project to project. I spent a weekend organizing it and adding several more features to take care of repetitive tasks.

有一次,我最终入侵了一个小实用程序,并不断在项目之间进行复制。 我花了一个周末组织它,并添加了更多功能来处理重复的任务。

约曼很容易诞生。 (And yeoman-easily was born.)

yeoman-easily helps with the following tasks when creating a generator with Yeoman:

使用Yeoman创建生成器时,yeoman- 轻松地帮助完成以下任务:

优势1:确认 (Advantage 1: Confirmation)

Often you would like to ask for user confirmation before proceeding. The first code block below shows how to write this with plain Yeoman. The second code block shows how to write it with the help of yeoman-easily.

通常,您需要在继续操作之前要求用户确认。 下面的第一个代码块显示了如何使用普通Yeoman编写此代码。 第二个代码块显示了如何在yeoman的帮助下轻松编写它。

With yeoman-easily, you can ask for confirmation before proceeding in one line. easily.confirmBeforeStart(message) then easily.checkForConfirmation() returns the result.

使用yeoman,您可以轻松地在一行之前进行确认。 easily.confirmBeforeStart(message)然后easily.checkForConfirmation() 返回结果。

优势2:提示 (Advantage #2: Prompting)

Handling results from the prompt, then choosing which prompt to display used to be complicated.

处理来自提示的结果,然后选择要显示的提示曾经很复杂。

  • this.prompt() returns a promise which needs to be handled to obtain the answers and store them. The answers are commonly stored into this.props. This block of code has to be written again and again.

    this.prompt()返回一个promise,需要对其进行处理才能获得答案并存储它们。 答案通常存储在this.props 。 此代码块必须一次又一次地编写。

  • A parent generator often passes the parameters to the child generator via options. From what I have seen, many generators will hide the prompts for fields that are present in the options. (Yes, you have to write code to check that.) Then combine answers from prompts and options into this.props.

    父生成器通常通过选项将参数传递给子生成器。 据我所知,许多生成器将隐藏选项中存在的字段提示。 (是的,您必须编写代码进行检查。)然后将提示和选项的答案合并到this.props

For convenience, yeoman-easily:

为了方便起见,您可以轻松地:

  • Handles storing user’s answers from the prompts into this.props. Just call easily.prompt(prompts) instead of this.prompt(prompts)

    处理将来自提示的用户答案存储到this.props 。 只需easily.prompt(prompts)调用easily.prompt(prompts)而不是this.prompt(prompts)

  • Can automatically skip a prompt if an option with the same name is present. It will also copy the value of existing this.options[field] into this.props[field].

    如果存在具有相同名称的选项,则可以自动跳过提示。 它还会将现有this.options[field]的值复制到this.props[field]

  • Can register common prompts via easily.learnPrompts(prompts) and allow looking up prompts by name while calling easily.prompt(). This can save a lot of time if you create multiple generators that ask similar questions.

    可以通过以下方式注册常见提示 easily.learnPrompts(prompts)并允许在调用easily.prompt()按名称查找提示。 如果创建多个生成器来询问类似的问题,则可以节省大量时间。

优势3:撰写 (Advantage #3: Composing)

Yeoman generator can call (composeWith) another generator from another package or local subgenerator, but the current syntax for doing so is somewhat long. I am still not sure what the local field means.

Yeoman生成器可以从另一个包或本地子生成器调用( composeWith )另一个生成器,但是当前的语法有些长。 我仍然不确定本地领域的含义。

yeoman-easily simplifies the syntax to easily.composeWithLocal(name, namespace, options) and easily.composeWithExternal(package, namespace, options).

easily.composeWithLocal(name, namespace, options)轻松地将语法简化为easily.composeWithLocal(name, namespace, options)easily.composeWithExternal(package, namespace, options)

优势4:文件处理 (Advantage #4: File handling)

Yeoman provides flexible APIs for file handling to cover many scenarios. But it takes a few lines to perform common task such as copying a file from the template directory to the destination directory. A function for bulk copying also exists, but it’s discouraged.

Yeoman提供了灵活的API用于文件处理,以涵盖许多情况。 但是执行常见任务需要花费几行,例如将文件从模板目录复制到目标目录。 还存在用于批量复制的功能,但不建议使用。

To address the above issues, yeoman-easily:

为了解决上述问题,可以轻松地:

  • Provides I/O functions that wraps this.fs.xxx and also resolves template and destination directory for common cases (from template to destination). These functions include read, write, writeJSON, extendJSON, exists, copy, and copyTemplate. I have a full list in my API documentation.

    提供包装this.fs.xxx I / O函数,并为常见情况(从模板到目标)解析模板目标目录。 这些功能包括readwritewriteJSONextendJSONexistscopycopyTemplate 。 我的API文档中有完整列表。

  • Provides functions for mass copying both static and dynamic files based on glob pattern. See easily.copyFiles(…) in the example below.

    提供用于基于全局模式批量复制静态和动态文件的功能。 请参见以下示例中的easily.copyFiles(…)

优势5:方法链接 (Advantage 5: Method chaining)

yeoman-easily was created with chaining in mind and support method chaining for fluent coding.

yeoman-easily创建时考虑了链接,并为流畅的编码提供了支持方法链接。

全部放在一起 (Putting it all together)

Here’s an example that demonstrates all of these advantages together into one generator:

下面的示例将所有这些优点一起展示到一个生成器中:

The yeoman-easily package is now available on npm. Visit the github repo for more details, API documentation and examples. I welcome your pull requests and bug reports.

yeoman轻松软件包现在在npm上可用。 请访问github repo获取更多详细信息, API文档和示例。 我欢迎您的请求请求和错误报告。

翻译自: https://www.freecodecamp.org/news/creating-yeoman-generators-easily-with-yeoman-easily-cf552aef0d2f/

yeoman

yeoman_使用yeoman轻松创建Yeoman生成器相关推荐

  1. 工作流程怎么安排?用Edraw Max轻松创建工作流程图!

    思维导图软件推荐: MindManager XMind:ZEN TheBrain Edraw Max(亿图图示)是一款综合图形图表制作软件,它包含丰富的实例和模版,帮助您轻松创建流程图.网络拓扑图.组 ...

  2. 盘启动盘_[装机]推荐唯二的两个开源免费的启动盘工具,轻松创建USB启动盘

    不卖关子: ventoy 和 rufus. 官网等: ventoy github​github.comventoy官网 新一代启多系统启动u盘解决方案​www.ventoy.netrufus 轻松创建 ...

  3. 轻松创建Silverlight 4开发环境

    在银光中国网有一篇"轻松创建Silverlight开发环境"文章,相信帮助了不少Silverlight新手,不过该文章介绍的是Silverlight 3开发环境,本篇将基于上文进行 ...

  4. EasyStruct.js轻松创建可填入式html模板结构

    友情提醒:由于旧版本的EasyStruct有一些bug,现在已经全部修复,而且增加了一份详细的demo,如果想要使用的话可以直接下载demo去看了,下面这篇介绍可以跳过了. 友情链接:http://d ...

  5. Bootstrap Magic – 轻松创建自己的 Bootstrap 主题

    Bootstrap Magic 是一款基于 Bootstrap 和 AngularJS 的主题创建工具.您可以轻松地创建您自己的 Twitter Bootstrap 主题,可以立即看到你的内容变化.您 ...

  6. redux引用多个中间件_如何轻松创建您的第一个Redux中间件

    redux引用多个中间件 by Gabriele Cimato 加布里埃莱·西马托(Gabriele Cimato) 如何轻松创建您的第一个Redux中间件 (How to create your f ...

  7. GitLab轻松创建一个Merge Request

    简写说明 - MR = Merge Request - 主仓 = 组织创建的仓库(下文中是 awesome-php 组织创建的 awesome-one 仓库) 什么是Merge Request - 相 ...

  8. 轻松创建天龙八部的场景

    +++++++++++++++++++++++++++++++++++++++++++++ +++++++++    轻松创建天龙八部的场景  ++++++++++++ +++++++++++++++ ...

  9. 创建多个wordpress_如何轻松创建多语言WordPress网站

    创建多个wordpress Do you want to translate your WordPress site in multiple languages? 您想用多种语言翻译WordPress ...

最新文章

  1. 定向输出命令_Linux系统管理-输入输出
  2. 前端开发技巧-那些不常见但十分有效的小玩意
  3. Vagrant挂载目录失败mount: unknown filesystem type ‘vboxsf’
  4. 算法笔记--字符串hash
  5. 【专升本计算机】2021年甘肃省专升本计算机全真模拟试题(四)
  6. http协议工作流程
  7. java script eval_java ScriptEngine 使用 (支持JavaScript脚本,eval()函数等)
  8. Ios精品源码,扁平化的ActionSheet仿花椒截屏demo文件签名重叠卡片滚动汽车仪表盘...
  9. 手把手教你用WPE“修改”各种魔兽SF
  10. DM9601 USB网卡驱动
  11. 【原创】JQWidgets-TreeGrid 1、快速入门
  12. 【Scratch案例实操】Scratch字母排序 scratch编程案例教学 scratch创意编程 少儿编程教案
  13. 万维钢解读,从数学上解释为什么绝大多数投资者都会输给市场?最可能值,远远小于平均值...
  14. 计算机应用无法打开,为什么电脑界面的部分软件无法打开
  15. 计算机认知训练效果,维持认知健康人群晚年认知功能的计算机认知训练
  16. 一篇会改变身处职场的你思维的一篇文章
  17. 图书管理系统java课设_JavaGUI图书管理系统(可作课程设计)
  18. pythonapi_Python API
  19. 整数a和整数b间1的个数
  20. 学习廖雪峰Git入门教程--总结

热门文章

  1. 这个回答让我错失offer!offer拿到手软
  2. django -- 实现ORM登录
  3. WebGL——osg框架学习一
  4. SGU traffic light
  5. Win7/8出现An error occurred on the server when processing the URL解决办法
  6. Spring JTA应用JOTM Atomikos II JOTM
  7. 2011年的MVP礼包
  8. UNITY3D 脑袋顶血顶名
  9. 各种数据库连接的总结
  10. 可用于 线性判别、聚类分析 的R语言函数总结