├── .gitattributes ├── docs ├── docs-options.md ├── docs-related.md ├── README.tmpl.md └── docs-quickstart.md ├── app ├── templates │ ├── _bower.json │ ├── gitignore │ ├── npmignore │ ├── editorconfig │ ├── jshintrc │ ├── _index.js │ ├── test │ │ └── _main.js │ ├── _package.json │ ├── LICENSE-MIT │ └── Gruntfile.js └── index.js ├── .gitignore ├── .travis.yml ├── test ├── test-load.js └── test-creation.js ├── .editorconfig ├── .jshintrc ├── Gruntfile.js ├── LICENSE ├── package.json └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=lf 2 | * text eol=lf 3 | *.* eol=lf 4 | -------------------------------------------------------------------------------- /docs/docs-options.md: -------------------------------------------------------------------------------- 1 | 2 | * `--skip-install` 3 | 4 | Skips the automatic execution of `bower` and `npm` after scaffolding has finished. -------------------------------------------------------------------------------- /app/templates/_bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= _.slugify(fullName) %>", 3 | "version": "0.0.0", 4 | "dependencies": { 5 | } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /docs/docs-related.md: -------------------------------------------------------------------------------- 1 | 2 | * [Assemble generator](https://github.com/assemble/generator-assemble) 3 | * [Assemble helper generator](https://github.com/assemble/generator-helper) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | tmp 17 | temp 18 | *.sublime-* -------------------------------------------------------------------------------- /app/templates/gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | tmp 17 | *.sublime-* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' 4 | before_install: 5 | - currentfolder=${PWD##*/} 6 | - if [ "$currentfolder" != 'generator-plugin' ]; then cd .. && eval "mv $currentfolder generator-plugin" && cd generator-plugin; fi 7 | 8 | -------------------------------------------------------------------------------- /app/templates/npmignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | tmp 17 | *.sublime-* 18 | 19 | Gruntfile.js 20 | test 21 | bower.json 22 | .jshintrc 23 | .editorconfig 24 | .gitignore -------------------------------------------------------------------------------- /test/test-load.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it*/ 2 | 'use strict'; 3 | 4 | var assert = require('assert'); 5 | 6 | describe('plugin generator', function () { 7 | it('can be imported without blowing up', function () { 8 | var app = require('../app'); 9 | assert(app !== undefined); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = false 11 | 12 | # don't mess with whitespace in markdown files 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /app/templates/editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = false 11 | 12 | # don't mess with whitespace in markdown files 13 | [*.md] 14 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": false, 10 | "boss": true, 11 | "eqnull": true, 12 | "node": true, 13 | "globals": { 14 | "module": true, 15 | "exports": true, 16 | "require": true 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/templates/jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "unused": false, 11 | "boss": true, 12 | "eqnull": true, 13 | "node": true, 14 | "globals": { 15 | "describe": true, 16 | "it": true, 17 | "before": true 18 | } 19 | } -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * generator-plugin 3 | * https://github.com/assemble/generator-plugin 4 | * 5 | * Copyright (c) 2014 Brian Woodward, contributors 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | 'use strict'; 10 | 11 | module.exports = function (grunt) { 12 | 13 | // Project configuration. 14 | grunt.initConfig({ 15 | 16 | jshint: { 17 | all: ['Gruntfile.js', 'app/*.js'], 18 | options: { 19 | jshintrc: '.jshintrc' 20 | } 21 | }, 22 | 23 | }); 24 | 25 | grunt.loadNpmTasks('grunt-contrib-jshint'); 26 | grunt.loadNpmTasks('grunt-readme'); 27 | 28 | // By default, lint and run all tests. 29 | grunt.registerTask('default', ['jshint', 'readme']); 30 | 31 | }; 32 | -------------------------------------------------------------------------------- /app/templates/_index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Assemble Plugin: <%= _.slugify(fullName) %> 3 | * <%= homepage %> 4 | * Assemble is the 100% JavaScript static site generator for Node.js, Grunt.js, and Yeoman. 5 | * 6 | * Copyright (c) <%= (new Date).getFullYear() %> <%= contributors %> 7 | * Licensed under the <%= licenseType %> license. 8 | */ 9 | 10 | var options = { 11 | events: ['<%= events.join("','") %>'] 12 | }; 13 | 14 | var plugin = module.exports = function(assemble) { 15 | 16 | assemble.registerPlugin( 17 | '<%= _.slugify(fullName) %>', 18 | '<%= description %>', 19 | options, 20 | function (params, next) { 21 | console.log('<%= fullName %>', params.event); 22 | next(); 23 | } 24 | ); 25 | 26 | }; -------------------------------------------------------------------------------- /docs/README.tmpl.md: -------------------------------------------------------------------------------- 1 | --- 2 | shortname: plugin 3 | username: doowb 4 | --- 5 | # {{{%= name %}}} [![NPM version](https://badge.fury.io/js/{%= name %}.png)](http://badge.fury.io/js/{%= name %}) {% if (travis) { %} [![Build Status]({%= travis %}.png)]({%= travis %}){% } %} 6 | 7 | > {%= description %} 8 | 9 | ## Getting Started 10 | {%= _.doc("docs-quickstart.md") %} 11 | 12 | ## Options 13 | {%= _.doc("docs-options.md") %} 14 | 15 | ## Author 16 | 17 | **Brian Woodward** 18 | 19 | + [twitter/doowb](https://twitter.com/doowb) 20 | + [github/doowb](http://github.com/doowb) 21 | 22 | ## Related 23 | {%= _.doc("docs-related.md") %} 24 | 25 | ## License 26 | {%= copyright %} 27 | {%= license %} 28 | 29 | *** 30 | 31 | _This file was generated on {%= grunt.template.today('yyyy-mm-dd') %}._ 32 | -------------------------------------------------------------------------------- /app/templates/test/_main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Assemble Plugin: <%= _.slugify(fullName) %> 3 | * <%= homepage %> 4 | * Assemble is the 100% JavaScript static site generator for Node.js, Grunt.js, and Yeoman. 5 | * 6 | * Copyright (c) <%= (new Date).getFullYear() %> <%= contributors %> 7 | * Licensed under the <%= licenseType %> license. 8 | */ 9 | 10 | var expect = require('chai').expect; 11 | 12 | var <%= _.safename(fullName) %> = require('../'); 13 | 14 | describe('<%= _.slugify(fullName) %>', function() { 15 | 16 | before(function(){ 17 | // run any code before tests here 18 | }); 19 | 20 | it('should do something awesome', function() { 21 | var expected = '<%= _.slugify(fullName) %>'; 22 | var actual = '<%= _.slugify(fullName) %>'; 23 | expect(actual).to.eql(expected); 24 | }); 25 | 26 | }); -------------------------------------------------------------------------------- /app/templates/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= _.slugify(fullName) %>", 3 | "description": "<%= description %>", 4 | "version": "0.1.0", 5 | "homepage": "<%= homepage %>", 6 | 7 | "repository": { 8 | "type": "<%= repositoryType %>", 9 | "url": "<%= repositoryUrl %>" 10 | }, 11 | 12 | "bugs": { 13 | "url": "<%= bugUrl %>" 14 | }, 15 | 16 | "license": { 17 | "type": "<%= licenseType %>", 18 | "url": "<%= licenseUrl %>" 19 | }, 20 | 21 | "engines": { 22 | "node": ">=0.8.0" 23 | }, 24 | 25 | "main": "./index.js", 26 | 27 | "devDependencies": { 28 | "grunt": "~0.4.2", 29 | "grunt-contrib-jshint": "~0.7.0", 30 | "grunt-readme": "~0.4.0", 31 | "grunt-repos": "~0.1.2", 32 | "grunt-mocha-test": "~0.8.1", 33 | "grunt-contrib-watch": "~0.5.3", 34 | "chai": "~1.8.1" 35 | }, 36 | 37 | "keywords": [ 38 | "plugin", 39 | "assemble", 40 | "assemble plugin" 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Assemble 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /app/templates/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) <%= (new Date).getFullYear() %> <%= contributors %> 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-plugin", 3 | "version": "0.1.2", 4 | "description": "Yeoman generator for Assemble plugins", 5 | "keywords": [ 6 | "yeoman-generator", 7 | "assemble", 8 | "plugin", 9 | "plugins" 10 | ], 11 | "homepage": "https://github.com/assemble/generator-plugin", 12 | "bugs": "https://github.com/assemble/generator-plugin/issues", 13 | "author": { 14 | "name": "Brian Woodward", 15 | "email": "brian.woodward@gmail.com", 16 | "url": "https://github.com/doowb" 17 | }, 18 | "main": "app/index.js", 19 | "repository": { 20 | "type": "git", 21 | "url": "git://github.com/assemble/generator-plugin.git" 22 | }, 23 | "scripts": { 24 | "test": "mocha" 25 | }, 26 | "dependencies": { 27 | "yeoman-generator": "~0.16.0", 28 | "lodash": "~2.4.1" 29 | }, 30 | "devDependencies": { 31 | "mocha": "~1.17.1", 32 | "grunt-readme": "~0.4.5", 33 | "grunt": "~0.4.2", 34 | "grunt-contrib-jshint": "~0.8.0" 35 | }, 36 | "peerDependencies": { 37 | "yo": ">=1.0.0" 38 | }, 39 | "engines": { 40 | "node": ">=0.10.0", 41 | "npm": ">=1.2.10" 42 | }, 43 | "licenses": [ 44 | { 45 | "type": "MIT" 46 | } 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /docs/docs-quickstart.md: -------------------------------------------------------------------------------- 1 | ## What is Yeoman? 2 | 3 | Trick question. It's not a thing. It's this guy: 4 | 5 | ![](http://i.imgur.com/JHaAlBJ.png) 6 | 7 | Basically, he wears a top hat, lives in your computer, and waits for you to tell him what kind of application you wish to create. 8 | 9 | Not every new computer comes with a Yeoman pre-installed. He lives in the [npm](https://npmjs.org) package repository. You only have to ask for him once, then he packs up and moves into your hard drive. *Make sure you clean up, he likes new and shiny things.* 10 | 11 | ``` 12 | $ npm install -g yo 13 | ``` 14 | 15 | ## Yeoman Generators 16 | 17 | Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension. 18 | 19 | To install {%= name %} from npm, run: 20 | 21 | ``` 22 | $ npm install -g {%= name %} 23 | ``` 24 | 25 | Finally, initiate the generator: 26 | 27 | ``` 28 | $ yo {%= shortname %} 29 | ``` 30 | 31 | ## Getting To Know Yeoman 32 | 33 | Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced. 34 | 35 | If you'd like to get to know Yeoman better and meet some of his friends, [Grunt](http://gruntjs.com) and [Bower](http://bower.io), check out the complete [Getting Started Guide](https://github.com/yeoman/yeoman/wiki/Getting-Started). -------------------------------------------------------------------------------- /test/test-creation.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it*/ 2 | 'use strict'; 3 | 4 | var path = require('path'); 5 | var helpers = require('yeoman-generator').test; 6 | 7 | 8 | describe('plugin generator', function () { 9 | 10 | beforeEach(function (done) { 11 | helpers.testDirectory(path.join(__dirname, 'temp'), function (err) { 12 | if (err) { 13 | return done(err); 14 | } 15 | 16 | this.app = helpers.createGenerator('plugin:app', [ 17 | '../../app' 18 | ]); 19 | done(); 20 | }.bind(this)); 21 | }); 22 | 23 | it('creates expected files', function (done) { 24 | 25 | var expected = [ 26 | // add files you expect to exist here. 27 | '.jshintrc', 28 | '.editorconfig', 29 | '.gitignore', 30 | '.npmignore', 31 | 'LICENSE-MIT', 32 | 'bower.json', 33 | 'test/main.js', 34 | 'index.js' 35 | ]; 36 | 37 | helpers.mockPrompt(this.app, { 38 | pluginName: 'myPlugin', 39 | fullName: 'assemble-plugin-myPlugin', 40 | description: 'The best plugin ever', 41 | user: 'assemble', 42 | events: ['assemble:after:render'], 43 | homepage: 'https://github.com/assemble/assemble-plugin-myPlugin', 44 | repositoryUrl: 'https://github.com/assemble/assemble-plugin-myPlugin.git', 45 | bugUrl: 'https://github.com/assemble/assemble-plugin-myPlugin/issues', 46 | licenseType: 'MIT', 47 | licenseUrl: 'https://github.com/assemble/assemble-plugin-myPlugin/blob/master/LICENSE-MIT', 48 | contributors: 'assemble' 49 | }); 50 | 51 | this.app.options['skip-install'] = true; 52 | 53 | this.app.run({}, function () { 54 | helpers.assertFile(expected); 55 | done(); 56 | }); 57 | }); 58 | }); 59 | -------------------------------------------------------------------------------- /app/templates/Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * <%= _.slugify(fullName) %> 3 | * <%= repositoryUrl %> 4 | * 5 | * Copyright (c) <%= (new Date).getFullYear() %> <%= contributors %> 6 | * Licensed under the <%= licenseType %> license. 7 | */ 8 | 9 | 'use strict'; 10 | 11 | module.exports = function(grunt) { 12 | 13 | // Project configuration. 14 | grunt.initConfig({ 15 | pkg : grunt.file.readJSON('package.json'), 16 | 17 | /** 18 | * Configure jshint to check our javascript files 19 | */ 20 | jshint: { 21 | all: ['Gruntfile.js', 'test/*.js', '*.js'], 22 | options: { 23 | jshintrc: '.jshintrc' 24 | } 25 | }, 26 | 27 | /** 28 | * Run mocha tests. 29 | */ 30 | mochaTest: { 31 | test: { 32 | options: { 33 | spawn: false, 34 | clearRequireCache: true, 35 | reporter: 'progress' 36 | }, 37 | src: ['test/*.js'] 38 | } 39 | }, 40 | 41 | /** 42 | * Watch source files and run tests when changes are made. 43 | */ 44 | watch: { 45 | dev: { 46 | files: ['Gruntfile.js', 'test/*.js', '*.js'], 47 | tasks: ['test'] 48 | } 49 | }, 50 | 51 | 52 | /** 53 | * Use helpers.json for context to generate list 54 | * of related repos 55 | */ 56 | readme: { 57 | options: { 58 | boilerplate: 'node-util' 59 | } 60 | } 61 | 62 | }); 63 | 64 | // These plugins provide necessary tasks. 65 | grunt.loadNpmTasks('grunt-contrib-watch'); 66 | grunt.loadNpmTasks('grunt-contrib-jshint'); 67 | grunt.loadNpmTasks('grunt-mocha-test'); 68 | grunt.loadNpmTasks('grunt-readme'); 69 | 70 | // Tests 71 | grunt.registerTask('test', ['jshint', 'mochaTest']); 72 | 73 | // Dev 74 | grunt.registerTask('dev', ['test', 'watch']); 75 | 76 | // Docs 77 | grunt.registerTask('docs', ['readme']); 78 | 79 | // By default, lint and run all tests. 80 | grunt.registerTask('default', ['test', 'readme']); 81 | 82 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # {{generator-plugin}} [![NPM version](https://badge.fury.io/js/generator-plugin.png)](http://badge.fury.io/js/generator-plugin) [![Build Status](https://travis-ci.org/assemble/generator-plugin.png)](https://travis-ci.org/assemble/generator-plugin) 2 | 3 | > Yeoman generator for Assemble plugins 4 | 5 | ## Getting Started 6 | ### What is Yeoman? 7 | 8 | Trick question. It's not a thing. It's this guy: 9 | 10 | ![](http://i.imgur.com/JHaAlBJ.png) 11 | 12 | Basically, he wears a top hat, lives in your computer, and waits for you to tell him what kind of application you wish to create. 13 | 14 | Not every new computer comes with a Yeoman pre-installed. He lives in the [npm](https://npmjs.org) package repository. You only have to ask for him once, then he packs up and moves into your hard drive. *Make sure you clean up, he likes new and shiny things.* 15 | 16 | ``` 17 | $ npm install -g yo 18 | ``` 19 | 20 | ### Yeoman Generators 21 | 22 | Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension. 23 | 24 | To install generator-plugin from npm, run: 25 | 26 | ``` 27 | $ npm install -g generator-plugin 28 | ``` 29 | 30 | Finally, initiate the generator: 31 | 32 | ``` 33 | $ yo plugin 34 | ``` 35 | 36 | ### Getting To Know Yeoman 37 | 38 | Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced. 39 | 40 | If you'd like to get to know Yeoman better and meet some of his friends, [Grunt](http://gruntjs.com) and [Bower](http://bower.io), check out the complete [Getting Started Guide](https://github.com/yeoman/yeoman/wiki/Getting-Started). 41 | 42 | 43 | ## Options 44 | 45 | * `--skip-install` 46 | 47 | Skips the automatic execution of `bower` and `npm` after scaffolding has finished. 48 | 49 | 50 | ## Author 51 | 52 | **Brian Woodward** 53 | 54 | + [twitter/doowb](https://twitter.com/doowb) 55 | + [github/doowb](http://github.com/doowb) 56 | 57 | ## Related 58 | 59 | * [Assemble generator](https://github.com/assemble/generator-assemble) 60 | * [Assemble helper generator](https://github.com/assemble/generator-helper) 61 | 62 | 63 | ## License 64 | Copyright (c) 2014 Brian Woodward, contributors. 65 | Released under the MIT license 66 | 67 | *** 68 | 69 | _This file was generated on 2014-03-06._ 70 | -------------------------------------------------------------------------------- /app/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var yeoman = require('yeoman-generator'); 3 | var util = require('util'); 4 | var path = require('path'); 5 | var _ = require('lodash'); 6 | 7 | var safename = function (name, patterns) { 8 | var prefixes = ['grunt', 'plugin', 'assemble-plugin', 'mixin', 'assemble-contrib', 'assemble']; 9 | var remove = _.unique(_.flatten(_.union([], prefixes, patterns || []))); 10 | var re = new RegExp('^(?:' + remove.join('|') + ')[-_]?'); 11 | return name.replace(re, '').replace(/[\W_]+/g, '_').replace(/^(\d)/, '_$1'); 12 | }; 13 | 14 | var processTemplate = function(tmpl) { 15 | return function(answers) { 16 | return this._.template(tmpl, answers); 17 | }; 18 | }; 19 | 20 | var PluginGenerator = yeoman.generators.Base.extend({ 21 | 22 | init: function () { 23 | this.pkg = require('../package.json'); 24 | this.description = this.pkg.description; 25 | 26 | this.on('end', function () { 27 | this.installDependencies({ skipInstall: this.options['skip-install'] }); 28 | }); 29 | 30 | this._.mixin({ 'safename': safename }); 31 | }, 32 | 33 | askFor: function () { 34 | var cb = this.async(); 35 | var self = this; 36 | 37 | if (!this.options['skip-welcome-message']) { 38 | console.log(this.yeoman); 39 | } 40 | 41 | var prompts = [ 42 | { 43 | name: 'pluginName', 44 | message: 'What do you want to call your plugin?', 45 | 'default': 'myPlugin' 46 | }, 47 | { 48 | name: 'fullName', 49 | message: 'What will the full name be?', 50 | 'default': processTemplate('assemble-plugin-<%= _.slugify(pluginName) %>').bind(self) 51 | }, 52 | { 53 | name: 'description', 54 | message: 'How would you describe your plugin?' 55 | }, 56 | { 57 | type: 'checkbox', 58 | name: 'events', 59 | message: 'What events will your plugin subsribte to?', 60 | 'default': 'assemble:before:build', 61 | choices: [ 62 | 'assemble:before:configuration', 63 | 'assemble:after:configuration', 64 | 'assemble:before:data', 65 | 'assemble:after:data', 66 | 'assemble:before:build', 67 | 'component:before:build', 68 | 'component:after:build', 69 | 'assemble:after:build', 70 | 'assemble:before:render', 71 | 'component:before:render', 72 | 'component:after:render', 73 | 'assemble:after:render' 74 | ] 75 | }, 76 | { 77 | name: 'user', 78 | message: 'What user/org will your plugin live under?' 79 | }, 80 | { 81 | name: 'homepage', 82 | message: 'What is the homepage for your plugin?', 83 | 'default': processTemplate('https://github.com/<%= user %>/<%= _.slugify(fullName) %>').bind(self) 84 | }, 85 | { 86 | name: 'repositoryUrl', 87 | message: 'Where will your plugin be stored?', 88 | 'default': processTemplate('https://github.com/<%= user %>/<%= _.slugify(fullName) %>.git').bind(self) 89 | }, 90 | { 91 | name: 'bugUrl', 92 | message: 'Where can people submit bugs for your plugin?', 93 | 'default': processTemplate('https://github.com/<%= user %>/<%= _.slugify(fullName) %>/issues').bind(self) 94 | }, 95 | { 96 | name: 'licenseType', 97 | message: 'What type of license does your plugin have?', 98 | 'default': 'MIT' 99 | }, 100 | { 101 | name: 'licenseUrl', 102 | message: 'Where can the license be found?', 103 | 'default': processTemplate('https://github.com/<%= user %>/<%= _.slugify(fullName) %>/blob/master/LICENSE-<%= licenseType %>').bind(self) 104 | }, 105 | { 106 | name: 'contributors', 107 | message: 'Who are the contributors on your plugin?', 108 | 'default': processTemplate('<%= user %>').bind(self) 109 | } 110 | ]; 111 | 112 | this.prompt(prompts, function (answers) { 113 | 114 | for (var key in answers) { 115 | if (answers.hasOwnProperty(key)) { 116 | self[key] = answers[key]; 117 | } 118 | } 119 | 120 | // calculated answers 121 | self.repositoryType = 'git'; 122 | 123 | cb(); 124 | }.bind(this)); 125 | }, 126 | 127 | /** 128 | * Setup any configuration files that have to do with package manangers. 129 | * eg: package.json, bower.json 130 | * @return {undefined} 131 | */ 132 | packageManagerConfigs: function () { 133 | this.copy('npmignore', '.npmignore'); 134 | this.template('_package.json', 'package.json'); 135 | this.template('_bower.json', 'bower.json'); 136 | }, 137 | 138 | /** 139 | * Setup any configuration files that have to do with the project 140 | * eg: editor settings, development settings (jshint, gruntfile) 141 | * @return {[type]} [description] 142 | */ 143 | projectConfigs: function () { 144 | this.copy('editorconfig', '.editorconfig'); 145 | this.copy('jshintrc', '.jshintrc'); 146 | this.copy('gitignore', '.gitignore'); 147 | this.copy('LICENSE-MIT', 'LICENSE-MIT'); 148 | this.template('Gruntfile.js', 'Gruntfile.js'); 149 | }, 150 | 151 | testSetup: function () { 152 | this.mkdir('test'); 153 | this.template('test/_main.js', 'test/main.js'); 154 | }, 155 | 156 | helperFiles: function () { 157 | this.template('_index.js', 'index.js'); 158 | }, 159 | 160 | }); 161 | 162 | module.exports = PluginGenerator; 163 | --------------------------------------------------------------------------------