-
Notifications
You must be signed in to change notification settings - Fork 381
/
cleanup.html
22 lines (21 loc) · 14.3 KB
/
cleanup.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><title>Generators New Year Cleanup! | Yeoman</title><meta name=viewport content="width=device-width"><link href="http://fonts.googleapis.com/css?family=Roboto+Slab:400,700|Roboto:400,700,700italic,400italic" rel=stylesheet><link rel=stylesheet href=/static/bundle-4963.138cb6b273.css><link href=/blog/atom.xml type=application/atom+xml rel=alternate title="Yeoman Blog Atom Feed"><link rel="shortcut icon" href=../static/favicon.b25e58c4b8.ico></head><body class=blog><header class=page-header><div class=container><div class=mobile-bar><h1 class=logo><a href="/"><img src=/static/logo.f0661e3819.png alt=Yeoman></a></h1><button class="mobile-menu-toggle ir">open</button></div><nav class=main-menu><ul class=main-nav><li><a href="/learning/">Using Yeoman</a><ul> <li><a href=/learning/index.html>Getting started</a></li> <li><a href=/codelab.html>Tutorial (codelab)</a></li> <li><a href=/learning/resources.html>Resources</a></li> <li><a href=/learning/deployment.html>Deployment</a></li> <li><a href=/learning/faq.html>FAQ</a></li> <li><a href=/learning/support.html>Support</a></li></ul></li><li><a href="/generators/">Discovering generators</a></li> <li><a href="/authoring/">Creating a generator</a><ul> <li><a href=/authoring/index.html>Getting started</a></li> <li><a href=/authoring/running-context.html>Running Context</a></li> <li><a href=/authoring/user-interactions.html>User Interactions</a></li> <li><a href=/authoring/composability.html>Composability</a></li> <li><a href=/authoring/dependencies.html>Managing Dependencies</a></li> <li><a href=/authoring/file-system.html>Interacting with the file system</a></li> <li><a href=/authoring/gruntfile.html>Creating a Gruntfile</a></li> <li><a href=/authoring/storage.html>Storing user configs</a></li> <li><a href=/authoring/testing.html>Unit testing</a></li> <li><a href=/authoring/debugging.html>Debugging Generators</a></li> <li><a href=/authoring/integrating-yeoman.html>Integrating Yeoman in other tools</a></li> <li><a href="http://yeoman.github.io/generator/">Full API documentation</a></li></ul></li><li><a href="/blog/" class=active>Blog</a></li> <li><a href="/contributing/">Contributing</a><ul> <li><a href=/contributing/index.html>Contributing</a></li> <li><a href=/contributing/opening-issues.html>How to open an issue</a></li> <li><a href=/contributing/pull-request.html>How to submit a PR</a></li> <li><a href=/contributing/style-guide.html>Style Guide</a></li> <li><a href=/contributing/testing-guidelines.html>Testing Guidelines</a></li> <li><a href=/contributing/ticketing.html>Issue system overview</a></li></ul></li></ul></nav></div></header><div id=content><h2 class=page-title><div class=container>Generators New Year Cleanup!</div></h2><div class="container has-sidebar clearfix"><nav class=context-nav><ul><li><a href=/blog/archive.html>View the Archives</a></li> <li class=year_divider><a class=year_title>2015</a><ul> <li><a href=/blog/state-of-the-moustache-2015.html>State of the Moustache</a></li></ul></li><li class=year_divider><a class=year_title>2014</a><ul> <li><a href=/blog/bower_components-in-project-root.html>Why Bower_Components was moved to a Project's Root Directory</a></li> <li><a href=/blog/release-0.18.html>Yeoman generator version 0.18.0 - Release announcement</a></li> <li><a href=/blog/generator-karma-rewrite.html>Karma Generator Rewrite 0.8.0</a></li> <li><a href=/blog/generator-0.17.html>Yeoman Generator 0.17.0 prerelease 1</a></li> <li><a href=/blog/releases-march-7th.html>Yeoman updates for Friday, March 7th.</a></li> <li><a href=/blog/performance-optimization.html>Grunt And Gulp Tasks For Performance Optimization</a></li> <li><a href=/blog/whats-new-in-backbone-generator.html>What's new in the Backbone generator</a></li> <li><a href=/blog/generator-update-feb-0207.html>Updates to some of our generators</a></li> <li><a href=/blog/gulp-explore.html>Exploring A Generator For Gulp.js</a></li> <li><a href=/blog/cleanup.html>Generators New Year Cleanup!</a></li></ul></li><li class=year_divider><a class=year_title>2013</a><ul> <li><a href=/blog/hello-1.0.html>Release the Kraken! - Announcing Yeoman 1.0</a></li></ul></li></ul></nav><article class=main><section class=content-chunk><section><div class="blog-post-meta clearfix"><p class=date>21 Jan 2014</p><div class=social><a href=https://twitter.com/share class=twitter-share-button data-text="Generators New Year Cleanup!">Tweet</a><script>!function(t,e,r){var n,s=t.getElementsByTagName(e)[0],i=/^http:/.test(t.location)?"http":"https";t.getElementById(r)||(n=t.createElement(e),n.id=r,n.src=i+"://platform.twitter.com/widgets.js",s.parentNode.insertBefore(n,s))}(document,"script","twitter-wjs");</script><script src=https://apis.google.com/js/plusone.js></script><g:plus action=share></g:plus></div></div><div class=post><p>A lots of changes and new features have been introduced in the Generator System (<code>npm search yeoman-generator</code>) lately. If you're not watching the <a href=https://github.com/yeoman/generator>yeoman/generator</a>, maybe you've been let down on the latest changes. Fear not, we <a href=https://github.com/yeoman/generator/releases>documented every recent release in our changelog</a>!</p><p>Along with the new year start, we've decided to build a todos list of the most important changes our official generators should implement. This will allow them to be clean, but also ready for the new upcoming feature; notably the capacity to compose multiples generators together!</p><p>You may not be an official generator maintainer, but we invite you to follow our lead and make sure you follow these guidelines. So, here it goes!</p><h3>Generators should generate a <code>.yo-rc.json</code> file</h3><p>The <code>.yo-rc.json</code> file allow you to save configuration, but is also the marker used to define a project root folder. This allow user from running <code>yo</code> command from sub directory to work on their whole project.</p><p>It is also how composed generators will know what is the root of a project.</p><p>Simply add this line somewhere in your generator to generate the file at least once:</p><div class=highlight><pre><code class=language-javascript data-lang=javascript><span class=k>this</span><span class=p>.</span><span class=nx>config</span><span class=p>.</span><span class=nx>save</span><span class=p>();</span>
</code></pre></div><p>Of course, if you're using the config object to store datas, it'll already be created. <a href=http://yeoman.github.io/generator/Storage.html>Read more on the config Storage in our API reference</a>.</p><h3>Use the new <code>.extend()</code> method instead of <code>util.inherit</code></h3><p>Until recently, you'd extend the Base generator this way:</p><div class=highlight><pre><code class=language-javascript data-lang=javascript><span class=kd>var</span> <span class=nx>BlogGenerator</span> <span class=o>=</span> <span class=nx>module</span><span class=p>.</span><span class=nx>exports</span> <span class=o>=</span> <span class=kd>function</span> <span class=p>()</span> <span class=p>{</span>
<span class=nx>generators</span><span class=p>.</span><span class=nx>Base</span><span class=p>.</span><span class=nx>apply</span><span class=p>(</span><span class=k>this</span><span class=p>,</span> <span class=nx>arguments</span><span class=p>);</span>
<span class=c1>// ...</span>
<span class=p>};</span>
<span class=nx>util</span><span class=p>.</span><span class=nx>inherits</span><span class=p>(</span><span class=nx>BlogGenerator</span><span class=p>,</span> <span class=nx>generators</span><span class=p>.</span><span class=nx>Base</span><span class=p>);</span>
</code></pre></div><p>You can now do the same in a fashion similar to Backbone.js:</p><div class=highlight><pre><code class=language-javascript data-lang=javascript><span class=kd>var</span> <span class=nx>BlogGenerator</span> <span class=o>=</span> <span class=nx>module</span><span class=p>.</span><span class=nx>exports</span> <span class=o>=</span> <span class=nx>generators</span><span class=p>.</span><span class=nx>Base</span><span class=p>.</span><span class=nx>extend</span><span class=p>({</span>
<span class=cm>/* prototype methods goes here */</span>
<span class=p>});</span>
</code></pre></div><p>As you may know, our next big milestone is to allow generator to be composed with each other. This mean you'll be able to use external generators inside your own, and allow user to build their app using multiple generators (like, I want to build an app with Sailsjs and Angular, with Bootstrap and support for Jenkins tests). Using the <code>.extend</code> inheritance signature will make it easier to get your generator ready to integrate into the composable yeoman ecosystem.</p><p>Note that we extracted the <a href=https://github.com/SBoudrias/class-extend>inheritance logic into a small standalone NPM module</a>. It'll be easy to add such functionnality into your own projects without any overhead!</p><h3>Remove use of deprecated test methods</h3><p>In release <code>0.16.0</code>, we deprecated some tests methods and added some other. Deprecation are now logged to the console, so make sure you get rid of those!</p><p>Also, <a href=http://yeoman.github.io/generator/assert.html>helpers assertions methods</a> are now exposed on the <code>yeoman.assert</code> namespace.</p><h3>Update dependencies in the generated bower.json and package.json</h3><p>As usual, update your deps. You may use <a href=https://github.com/alanshaw/david>david tool</a> for that.</p><h3>Make sure package.json <code>peerDependencies</code> do not use tilde <code>~</code> versioning</h3><p>NPM <code>peerDependencies</code> are tricky to get right. As they're installed in the global <code>node_modules</code> folder, they're often the cause of installation errors due to incompatible version required between differents packages. Please, be a good citizen and don't make the issue worse by using restrictive version requirement.</p><p>So, make it a rule to always defines <code>peerDependencies</code> version using a minimum range (<code>>=</code>), or using any available version (<code>*</code>).</p><div class=highlight><pre><code class=language-json data-lang=json><span class=p>{</span>
<span class=nt>"peerDependencies"</span><span class=p>:</span> <span class=p>{</span>
<span class=err>//</span> <span class=err>GOOD</span>
<span class=nt>"grunt-cli"</span><span class=p>:</span> <span class=s2>">= 0.1.0"</span><span class=p>,</span>
<span class=err>//</span> <span class=err>GOOD</span>
<span class=nt>"gulp"</span><span class=p>:</span> <span class=s2>"*"</span><span class=p>,</span>
<span class=err>//</span> <span class=err>BAD</span> <span class=err>-</span> <span class=err>don't</span> <span class=err>ever</span> <span class=err>do</span> <span class=err>this</span>
<span class=nt>"generator-karma"</span><span class=p>:</span> <span class=s2>"~1.2.0"</span><span class=p>,</span>
<span class=nt>"generator-commonjs"</span><span class=p>:</span> <span class=s2>"1.2.0"</span>
<span class=p>}</span>
<span class=p>}</span>
</code></pre></div><h3>On that, good luck!</h3><p>That's all folks! Good luck and keep on building awesome generators.</p><p>If you're a generator author, you really should click the <a href=https://github.com/yeoman/generator><code>watch</code> button on the Generator system repo</a> - this way you'll be kept up to date on our future plan and updates. Also make sure to check the <code>[Composability]</code> issues, this is our next big milestone and we need your feedback!</p></div><hr><a href="/blog/">« View More Posts</a></section></section></article></div></div><footer class=page-footer><ul class="footer-links footer-links-social"><li><a href=https://plus.google.com/101063139999404044459/posts class=icon><img src=/static/social-gplus.cdac08228d.svg alt=Google+></a></li> <li><a href=https://twitter.com/yeoman class=icon><img src=/static/social-twitter.60eb981a15.svg alt=Twitter></a></li> <li><a href=https://github.com/yeoman/yeoman class=icon><img src=/static/social-github.767995ad17.svg alt=Github></a></li> <li><a href=/blog/atom.xml class=icon><img src=/static/social-feed.c635057faf.svg alt=Feed></a></li></ul><ul class="footer-links footer-links-contribute"><li><a href="http://yeoman.github.io/generator/" class=btn>API</a></li> <li><a href=https://github.com/yeoman/yeoman.io/blob/master/app/_posts/blog/2014-01-21-cleanup.md class="btn btn-improve" title="Edit this page on Github to help improve the site">Improve this page</a></li></ul></footer><script src=//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js></script><script src=/static/bundle-5022.6f6c082cfd.js async></script><script>!function(t,e,n){"undefined"!=typeof n.module&&n.module.exports?n.module.exports=e():"undefined"!=typeof n.define&&"function"==n.define&&n.define.amd?define(t,e):n[t]=e()}("$script",function(){function t(t,e){for(var n=0,o=t.length;o>n;++n)if(!e(t[n]))return l;return 1}function e(e,n){t(e,function(t){return!n(t)})}function n(i,c,l){function p(t){return t.call?t():s[t]}function g(){if(!--w){s[y]=1,v&&v();for(var n in f)t(n.split("|"),p)&&!e(f[n],p)&&(f[n]=[])}}i=i[m]?i:[i];var h=c&&c.call,v=h?c:l,y=h?i.join(""):c,w=i.length;return setTimeout(function(){e(i,function(t){return d[t]?(y&&(u[y]=1),2==d[t]&&g()):(d[t]=1,y&&(u[y]=1),o(!a.test(t)&&r?r+t+".js":t,g),void 0)})},0),n}function o(t,e){var n=i.createElement("script"),o=l;n.onload=n.onerror=n[v]=function(){n[g]&&!/^c|loade/.test(n[g])||o||(n.onload=n[v]=null,o=1,d[t]=2,e())},n.async=1,n.src=t,c.insertBefore(n,c.firstChild)}var r,i=document,c=i.getElementsByTagName("head")[0],a=/^https?:\/\//,s={},u={},f={},d={},l=!1,m="push",p="DOMContentLoaded",g="readyState",h="addEventListener",v="onreadystatechange";return!i[g]&&i[h]&&(i[h](p,function y(){i.removeEventListener(p,y,l),i[g]="complete"},l),i[g]="loading"),n.get=o,n.order=function(t,e,o){!function r(i){i=t.shift(),t.length?n(i,r):n(i,e,o)}()},n.path=function(t){r=t},n.ready=function(o,r,i){o=o[m]?o:[o];var c=[];return!e(o,function(t){s[t]||c[m](t)})&&t(o,function(t){return s[t]})?r():!function(t){f[t]=f[t]||[],f[t][m](r),i&&i(c)}(o.join("|")),n},n},this);var _gaq=[["_setAccount","UA-32956520-1"],["_setDomainName",".yeoman.io"],["_trackPageview"],["_trackPageLoadTime"]];$script("http://www.google-analytics.com/ga.js"),$script("https://apis.google.com/js/plusone.js"),$script("//platform.twitter.com/widgets.js");</script></body></html>