Skip to content

Instantly share code, notes, and snippets.

@ratbeard
Forked from anonymous/generators.generator-bot.app.index.js
Last active August 29, 2015 13:55
Show Gist options
  • Save ratbeard/8701259 to your computer and use it in GitHub Desktop.
Save ratbeard/8701259 to your computer and use it in GitHub Desktop.
module.exports = (generate) ->
{register, copy, mkdir, set, camelcase} = generate
# Register all generators in 1 file
# Templates are run through a <%= %>
# args are automatically 'set' and available inside templates
# extend string prototype w/ handy helpers
# need a --dry-run options
register(name: "bot", args: "<name>", run: (args) ->
mkdir("src/bots/<%= name.camelcase %>")
copy("./api.coffee.template", "src/bots/<%= name.camelcase %>/")
copy("./bot.coffee.template", "src/bots/<%= name.camelcase %>/")
)
}
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var botname = null
var BotGenerator = module.exports = function BotGenerator(args, options, config) {
botname = args[0]
yeoman.generators.Base.apply(this, arguments);
};
util.inherits(BotGenerator, yeoman.generators.Base);
BotGenerator.prototype.askFor = function askFor() {
var cb = this.async();
var prompts = [{
name: 'bot',
message: 'Bot name?',
default: 'newbot'
}];
if (botname) prompts.shift()
this.prompt(prompts, function (props) {
this.bot = botname || props.bot;
this.botClass = this.bot[0].toUpperCase() + this.bot.slice(1);
cb();
}.bind(this));
};
BotGenerator.prototype.app = function app() {
path = 'src/bots/' + this.bot + '/'
this.mkdir(path);
this.template("api.coffee", path + 'api.coffee')
this.template("bot.coffee", path + 'bot.coffee')
};
BotGenerator.prototype.projectfiles = function projectfiles() {
//this.copy('editorconfig', '.editorconfig');
//this.copy('jshintrc', '.jshintrc');
};
@ratbeard
Copy link
Author

Why I don't like yeoman:

  • The api (see above) is terrible
  • Custom generators must either be published on npm, or npm link'ed locally to use (adding extra step)
  • Took me 14 seconds to run the above (copy and interpolate 2 files...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment