yeoman_使用yeoman轻松创建Yeoman生成器

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/396149.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux 轻量化图形界面,YOXIOS 入门教程--基于Linux的 轻量化GUI图形系统和硬件平台(41页)-原创力文档...

YOXIOS --基于 Linux 的轻量化 GUI图形系统和硬件平台YOXIOS 入门教程基于 Linux 的 轻量化 GUI图形系统和硬件平台(V1.0 2020-05)提示:阅读此文档需要有一定的单片机开发、C/C编程语言、和使用 IDE开发工具的基础YOXIOS (C) 2020 游芯科技第 1 页 共 41 页YOXIOS -…

第一阶段 XHTML.定位样式

一位初学php的随堂笔记,记录自己的成长! 1.清除浮动 (1)格式 clear:both清除两边|left清除左边 right清除右边 高度塌陷:父元素中的子元素都浮动,而父元素 没有设置高,那父元素的高为0 (2)万能清除(在父元素…

Canvas入门06-线段与像素边界

我们知道,使用以下2个API可以绘制一条线段: moveTo(x, y) 向当前路径中增加一条子路径,该子路径只包含一个点,此为线段的起始点lineTo(x, y) 将线段的下一个点加入子路径中context.strokeStyle rgb(200, 200, 0); context.lineWi…

函数表达书-读书笔记

定义函数的方式有两种:一种是函数声明,另一种就是函数表达式。函数声明的语法如下: function functionName(arg0,arg1,arg2){//函数体 } 函数声明,有一个重要特征就是函数声明提升。也就是在执行代码之前会先读取函数声明&#xf…

vue截取一个字符串_vue 截取字符串

let str abcdef;// 0str str.slice(0);//返回整个字符串 abcdefstr str.substring(0);//返回整个字符串 abcdefstr str.substr(0);//返回整个字符串 abcdef// 使用一个参数str str.slice(2);//截取第二个之后所有的字符 cdefstr str.substring(2);//截取第二个之后所有的…

网络工程师需要哪些知识_成长工程师可以教给我们哪些工程知识

网络工程师需要哪些知识I’ve been working as an engineer on the growth team at Airbnb for a couple of months now.我已经在Airbnb的成长团队担任工程师几个月了。 Since I’m in an environment full of passionate developers, I wanted to share some of the good eng…

linux父进程循环,LINUX C 父进程建立多个子进程循环非堵塞回收列子

下面 代码主要用于复习,留于此点击(此处)折叠或打开/*************************************************************************> File Name: fork5.c> Author: gaopeng QQ:22389860 all right reserved> Mail: gaopp_200217163.com> Created Time: …

服务器自动运行python_在虚拟主机中安装了python程序,如何使它在服务器上自动运行?...

{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":3,"count":3}]},"card":[{"des":"IP地理位置库(GeoIP Databases)是对运营商分…

模拟测试

题解: 3道水题。。 1。生活大爆炸版剪刀石头布 忘记怎么打f[5][5]{}这个了。。 然后发现里面啥都不加也可以 加的话要是{} 2.送礼物 双向搜 有点卡常数。。 我没写dfs 写了dp求多少(好智障啊。。 访问数组挺慢的所以应该速度差不多。。) lowb…

javascript闭包_通过邮寄包裹解释JavaScript闭包

javascript闭包by Kevin Kononenko凯文科诺年科(Kevin Kononenko) 通过邮寄包裹解释JavaScript闭包 (JavaScript Closures Explained by Mailing a Package) 如果您以前寄过包裹或信件,那么您可以了解JavaScript中的闭包。 (If you have mailed a package or lette…

linux 加入ad 用ssh,使用samba验证AD用户,允许AD用户登录到linux

使用samba验证AD用户,允许AD用户登录到linux2007年06月26日 星期二 14:101、先把samba加入到AD域中2、在smb.conf中添加一行,让登录进来的用户使用bashtemplate shell /bin/bash3、运行authconfig,在验证中选择 使用smb和kerberos,winbind验…

体会日子

体会日子 开通了博客园, 日子要记录一下。 以后要好好上进了。 posted on 2016-05-01 23:16 体会日子 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/yukunshi/p/5451485.html

selenium 难定位元素、时间插件

关于frame: 1. 如果网页存在iframe的话,传统的定位有时候找不到元素,需要切换frame; # 切换到leftFrame定位“测井设计” driver.switch_to_frame("leftFrame") driver.find_element_by_link_text(u"设计").click() # 切…

python kmeans聚类 对二维坐标点聚类_Kmeans均值聚类算法原理以及Python如何实现

第一步.随机生成质心由于这是一个无监督学习的算法,因此我们首先在一个二维的坐标轴下随机给定一堆点,并随即给定两个质心,我们这个算法的目的就是将这一堆点根据它们自身的坐标特征分为两类,因此选取了两个质心,什么时…

HDU 2544最短路dijkstra模板题

最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 33657 Accepted Submission(s): 14617Problem Description在每年的校赛里,全部进入决赛的同学都会获得一件非常美丽的t-shirt。可是每当我们…

我为期一个月的GitHub的经验教训

by JS由JS 我为期一个月的GitHub的经验教训 (Lessons from my month-long GitHub commit streak) “I want to learn JavaScript. Like, really learn it. Like, truly understand it.” — me in November 2016“我想学习JavaScript。 喜欢,真正地学习它。 喜欢&a…

安装itunes需要管理员身份_ITUNES无法安装,提示没有权限如何解决?

展开全部注意机器一定要登陆管理员系统,如果现在不是,可以注62616964757a686964616fe78988e69d8331333365646263销,切换一下用户。还有计算机不要有漏洞,如果有的话修复一下。打开开始运行,输入regedit,点击确认打开注册表编辑器,…

vs2012新建项目产生的问题

当用vs新建web项目时遇到 只需下载一个vs2012的更新插件 http://download.microsoft.com/download/A/0/2/A02C37E0-77F7-448A-BD5C-F66AB1F78DBC/VS11-KB3002339.exe 点击安装更新即可. 转载于:https://www.cnblogs.com/GreenLeaves/p/5452073.html

zoj4062 Plants vs. Zombies 二分+模拟(贪心的思维)

题目传送门 题目大意:有n个植物排成一排,标号为1-n,每株植物有自己的生长速度ai,每对植物浇一次水,该株植物就长高ai,现在机器人从第0个格子出发,每次走一步,不能停留,每…

MyBatis注解模式批量insert方法

2019独角兽企业重金招聘Python工程师标准>>> 方法一:script标签方式 Insert("<script>insert into xxx (channelId,siteId) " "values " "<foreach collection\"list\" item\"item\" index\"index\&quo…