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.pswp.cn/news/396149.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/396149.shtml
英文地址,請注明出處:http://en.pswp.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…