├── .gitattributes ├── .gitignore ├── .jshintrc ├── .npmignore ├── CHANGELOG.md ├── README.md ├── app ├── index.js └── templates │ ├── CHANGELOG.md │ ├── README.md │ ├── _package.json │ ├── babelrc │ ├── eslintrc │ ├── gitignore │ ├── lib │ └── index.js │ ├── npmignore │ └── test │ └── test.js ├── package.json └── test ├── test-creation.js └── test-load.js /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.seed 2 | *.log 3 | *.csv 4 | *.dat 5 | *.out 6 | *.pid 7 | *.gz 8 | *.orig 9 | 10 | work 11 | build 12 | dist 13 | test/temp 14 | pids 15 | logs 16 | results 17 | coverage 18 | lib-cov 19 | html-report 20 | xunit.xml 21 | node_modules 22 | npm-debug.log 23 | 24 | .project 25 | .idea 26 | .settings 27 | .iml 28 | *.sublime-workspace 29 | *.sublime-project 30 | 31 | .DS_Store* 32 | ehthumbs.db 33 | Icon? 34 | Thumbs.db 35 | .AppleDouble 36 | .LSOverride 37 | .Spotlight-V100 38 | .Trashes 39 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 2, 10 | "latedef": true, 11 | "newcap": true, 12 | "noarg": true, 13 | "quotmark": "single", 14 | "regexp": true, 15 | "undef": true, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true, 20 | "white": true 21 | } 22 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Automatically ignored per: 2 | # https://www.npmjs.org/doc/developers.html#Keeping-files-out-of-your-package 3 | # 4 | # .*.swp 5 | # ._* 6 | # .DS_Store 7 | # .git 8 | # .hg 9 | # .lock-wscript 10 | # .svn 11 | # .wafpickle-* 12 | # CVS 13 | # npm-debug.log 14 | # node_modules 15 | 16 | *.seed 17 | *.log 18 | *.csv 19 | *.dat 20 | *.out 21 | *.pid 22 | *.gz 23 | *.orig 24 | 25 | work 26 | build 27 | dist 28 | test 29 | pids 30 | logs 31 | results 32 | coverage 33 | lib-cov 34 | html-report 35 | xunit.xml 36 | 37 | .project 38 | .idea 39 | .settings 40 | .iml 41 | *.sublime-workspace 42 | *.sublime-project 43 | 44 | ehthumbs.db 45 | Icon? 46 | Thumbs.db 47 | .AppleDouble 48 | .LSOverride 49 | .Spotlight-V100 50 | .Trashes 51 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### v3.0.0 2 | 3 | - Now only supports ES2015 features missing from Node v4+. 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Module Generator 2 | 3 | Yeoman generator for es6 modules. 4 | 5 | Supports: 6 | 7 | - `es6` using babel6 8 | - including `async/await` with `babel-regenerator-runtime` 9 | - linting using `eslint` 10 | - tests using `tape` 11 | 12 | Requires: 13 | 14 | - Node.js version 4+ (only supports ES2015 features missing from V4+) 15 | 16 | ### Install 17 | 18 | ```shell 19 | npm install -g yo 20 | npm install -g generator-es6-module 21 | ``` 22 | 23 | ### Usage 24 | 25 | ``` 26 | mkdir somedir && cd $_ 27 | yo es6-module 28 | ``` 29 | -------------------------------------------------------------------------------- /app/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util'); 4 | var path = require('path'); 5 | var yeoman = require('yeoman-generator'); 6 | var chalk = require('chalk'); 7 | 8 | 9 | var ModuleGenerator = yeoman.generators.Base.extend({ 10 | init: function () { 11 | this.pkg = yeoman.file.readJSON(path.join(__dirname, '../package.json')); 12 | 13 | this.on('end', function () { 14 | if (!this.options['skip-install']) { 15 | this.npmInstall(); 16 | } 17 | }); 18 | }, 19 | 20 | askFor: function () { 21 | var done = this.async(); 22 | 23 | this.appname = path.basename(process.cwd()); 24 | 25 | // have Yeoman greet the user 26 | console.log(chalk.magenta('ES6 Module Generator')); 27 | 28 | var prompts = [{ 29 | name: 'appname', 30 | message: 'What would you like to call your module?', 31 | default : this.appname, 32 | }, 33 | { 34 | name: 'creatorName', 35 | message: 'What is your name?' 36 | }, 37 | { 38 | name: 'githubUser', 39 | message: 'What is your github user name?' 40 | }, 41 | { 42 | name: 'email', 43 | message: 'What is your email?' 44 | }]; 45 | 46 | this.prompt(prompts, function (props) { 47 | 48 | this.appname = props.appname || this.appname; 49 | this.creatorName = props.creatorName; 50 | this.githubUser = props.githubUser; 51 | this.email = props.email; 52 | this.appRoot = path.basename(process.cwd()) === this.appname ? this.destinationRoot() : path.join(this.destinationRoot(), this.appname); 53 | 54 | if (process.cwd() !== this.appRoot) { 55 | this.mkdir(this.appRoot); 56 | process.chdir(this.appRoot); 57 | } 58 | 59 | done(); 60 | }.bind(this)); 61 | }, 62 | 63 | app: function () { 64 | this.mkdir('lib'); 65 | this.mkdir('test'); 66 | 67 | this.template('_package.json', 'package.json'); 68 | }, 69 | 70 | projectfiles: function () { 71 | this.copy('gitignore', '.gitignore'); 72 | this.copy('npmignore', '.npmignore'); 73 | this.copy('eslintrc', '.eslintrc'); 74 | this.copy('babelrc', '.babelrc'); 75 | 76 | this.copy('README.md'); 77 | this.copy('CHANGELOG.md'); 78 | 79 | this.copy('lib/index.js'); 80 | 81 | this.template('test/test.js', 'test/test-' + this.appname + '.js'); 82 | } 83 | }); 84 | 85 | module.exports = ModuleGenerator; 86 | -------------------------------------------------------------------------------- /app/templates/CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tlivings/generator-es6-module/b17aa6614a9fa296495ec33284fd21697fe3b98e/app/templates/CHANGELOG.md -------------------------------------------------------------------------------- /app/templates/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tlivings/generator-es6-module/b17aa6614a9fa296495ec33284fd21697fe3b98e/app/templates/README.md -------------------------------------------------------------------------------- /app/templates/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= _.slugify(appname) %>", 3 | "description": "", 4 | "version": "0.0.1", 5 | "author": "<%= creatorName %> <<%= email %>>", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/<%= githubUser %>/<%= _.slugify(appname) %>.git" 9 | }, 10 | "bugs" : "http://github.com/<%= githubUser %>/<%= _.slugify(appname) %>/issues", 11 | "engines" : { 12 | "node" : ">= 4.0.0" 13 | }, 14 | "dependencies": { 15 | "babel-regenerator-runtime": "^6.3.13", 16 | "babel-runtime": "^6.3.19" 17 | }, 18 | "devDependencies": { 19 | "babel-cli": "^6.1.4", 20 | "babel-eslint": "^4.0.0", 21 | "babel-plugin-syntax-async-functions": "^6.1.18", 22 | "babel-plugin-transform-es2015-arrow-functions": "^6.4.0", 23 | "babel-plugin-transform-es2015-for-of": "^6.3.13", 24 | "babel-plugin-transform-regenerator": "^6.4.4", 25 | "babel-plugin-transform-runtime": "^6.3.13", 26 | "babel-preset-es2015-node4": "^2.0.2", 27 | "eslint": "^1.10.3", 28 | "istanbul": "^0.4.1", 29 | "tape": "^4.2.2" 30 | }, 31 | "scripts": { 32 | "prepublish": "npm run compile", 33 | "test": "npm run compile && babel-node --plugins transform-es2015-arrow-functions node_modules/.bin/tape test/*.js", 34 | "compile": "babel --out-dir dist lib/**.js", 35 | "lint": "eslint lib", 36 | "cover": "npm run compile && babel-node --plugins transform-es2015-arrow-functions node_modules/.bin/istanbul cover node_modules/.bin/tape -- test/*.js" 37 | }, 38 | "main": "./dist/lib" 39 | } 40 | -------------------------------------------------------------------------------- /app/templates/babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015-node4" 4 | ], 5 | "plugins": [ 6 | "transform-runtime", 7 | "transform-regenerator", 8 | "syntax-async-functions", 9 | "transform-es2015-for-of" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /app/templates/eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": ["eslint:recommended"] 4 | } 5 | -------------------------------------------------------------------------------- /app/templates/gitignore: -------------------------------------------------------------------------------- 1 | *.seed 2 | *.log 3 | *.csv 4 | *.dat 5 | *.out 6 | *.pid 7 | *.gz 8 | *.orig 9 | 10 | work 11 | build 12 | dist 13 | pids 14 | logs 15 | results 16 | coverage 17 | lib-cov 18 | html-report 19 | xunit.xml 20 | node_modules 21 | npm-debug.log 22 | 23 | .project 24 | .idea 25 | .settings 26 | .iml 27 | *.sublime-workspace 28 | *.sublime-project 29 | 30 | .DS_Store* 31 | ehthumbs.db 32 | Icon? 33 | Thumbs.db 34 | .AppleDouble 35 | .LSOverride 36 | .Spotlight-V100 37 | .Trashes 38 | -------------------------------------------------------------------------------- /app/templates/lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export default { 4 | 5 | }; 6 | -------------------------------------------------------------------------------- /app/templates/npmignore: -------------------------------------------------------------------------------- 1 | # Automatically ignored per: 2 | # https://www.npmjs.org/doc/developers.html#Keeping-files-out-of-your-package 3 | # 4 | # .*.swp 5 | # ._* 6 | # .DS_Store 7 | # .git 8 | # .hg 9 | # .lock-wscript 10 | # .svn 11 | # .wafpickle-* 12 | # CVS 13 | # npm-debug.log 14 | # node_modules 15 | 16 | *.seed 17 | *.log 18 | *.csv 19 | *.dat 20 | *.out 21 | *.pid 22 | *.gz 23 | *.orig 24 | 25 | work 26 | build 27 | test 28 | pids 29 | logs 30 | results 31 | coverage 32 | lib-cov 33 | html-report 34 | xunit.xml 35 | 36 | .project 37 | .idea 38 | .settings 39 | .iml 40 | *.sublime-workspace 41 | *.sublime-project 42 | 43 | ehthumbs.db 44 | Icon? 45 | Thumbs.db 46 | .AppleDouble 47 | .LSOverride 48 | .Spotlight-V100 49 | .Trashes 50 | -------------------------------------------------------------------------------- /app/templates/test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | <% var importName = _.slugify(appname); %> 4 | 5 | import Test from 'tape'; 6 | import <%= importName[0].toUpperCase() + importName.substr(1) %> from '../dist/lib'; 7 | 8 | Test('test <%= importName %>', (t) => { 9 | 10 | t.test('plan', (t) => { 11 | t.plan(1); 12 | 13 | t.ok(true); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-es6-module", 3 | "version": "3.0.0", 4 | "description": "Yeoman generator for es6 based node.js modules using babel-runtime.", 5 | "main": "app/index.js", 6 | "repository": "https://github.com/tlivings/generator-es6-module", 7 | "author": { 8 | "name": "Trevor Livingston", 9 | "email": "tlivings@gmail.com", 10 | "url": "https://github.com/tlivings" 11 | }, 12 | "files": [ 13 | "app" 14 | ], 15 | "keywords": [ 16 | "yeoman-generator", 17 | "es6", 18 | "yeoman", 19 | "yo", 20 | "generator" 21 | ], 22 | "dependencies": { 23 | "async": "^1.5.0", 24 | "chalk": "~0.4.0", 25 | "yeoman-generator": "~0.16.0" 26 | }, 27 | "devDependencies": { 28 | "tape": "^3.5.0", 29 | "istanbul": "~0.3.6", 30 | "jshint": "^2.6.0" 31 | }, 32 | "peerDependencies": { 33 | "yo": "^1.0.0" 34 | }, 35 | "scripts": { 36 | "test": "tape test/*.js", 37 | "cover": "istanbul cover tape -- test/*.js", 38 | "lint": "jshint -c .jshintrc lib/" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/test-creation.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it */ 2 | 'use strict'; 3 | 4 | var fs = require('fs'); 5 | var path = require('path'); 6 | var helpers = require('yeoman-generator').test; 7 | var test = require('tape'); 8 | 9 | test('module generator', function (t) { 10 | var app; 11 | 12 | function setup (done) { 13 | helpers.testDirectory(path.join(__dirname, 'temp'), function (err) { 14 | if (err) { 15 | return done(err); 16 | } 17 | 18 | app = helpers.createGenerator('es6-module:app', [ 19 | '../../app' 20 | ]); 21 | done(); 22 | }); 23 | } 24 | 25 | t.test('creates expected files', function (t) { 26 | 27 | setup(function () { 28 | var expected = [ 29 | // add files you expect to exist here. 30 | '.gitignore', 31 | '.npmignore', 32 | '.babelrc', 33 | 'README.md', 34 | 'CHANGELOG.md', 35 | 'package.json', 36 | 'test/test-mymodule.js', 37 | 'lib/index.js' 38 | ]; 39 | 40 | helpers.mockPrompt(app, { 41 | 'appname' : 'mymodule' 42 | }); 43 | 44 | app.options['skip-install'] = true; 45 | 46 | app.run({}, function () { 47 | var pkg; 48 | 49 | expected.forEach(function (file) { 50 | t.ok(fs.existsSync(file), 'file exists.'); 51 | }); 52 | 53 | pkg = require('./temp/mymodule/package.json'); 54 | 55 | t.equal(pkg.name, 'mymodule'); 56 | 57 | t.end(); 58 | }); 59 | }) 60 | }); 61 | 62 | }); 63 | -------------------------------------------------------------------------------- /test/test-load.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it*/ 2 | 'use strict'; 3 | 4 | var assert = require('assert'); 5 | var test = require('tape'); 6 | 7 | test('module generator', function (t) { 8 | 9 | t.test('can be imported without blowing up', function (t) { 10 | var app = require('../app'); 11 | 12 | t.plan(1); 13 | 14 | t.ok(app, 'app is defined.'); 15 | }); 16 | }); 17 | --------------------------------------------------------------------------------