Skip to content

Override Generators #104

Description

@imaustink

What

A related issue (donejs/generator-donejs#140) outlines the method of using the .donejs folder to customize a generator's templates. It would be nice to have the ability to custom the generator itself.

Why

For a react-view-model project. Since a custom element tag name that the component prompt collects doesn't translate well to a react component so I'd like to change the prompt and it's validation.

You could also do things like making a component generator that prompts you for a type and builds one of several predefined types.

How

My immediate thought would be to modify the add command to do something like:

var path = require('path');
var utils = require('../utils');
var generate = require('./cmd-generate');
var debug = require('debug')('donejs-cli:add');  

module.exports = function(root, name, params) {
  var generators = require(path.join(root, 'node_modules', 'generator-donejs'));
  var customGeneratorPath = path.join(process.cwd(), '.donejs', 'name', 'index.js');

  // Use the custom generator here!
  if (fs.exists(customGeneratorPath)) {
    return utils.generate(root, '.donejs', [name].concat(params))
  }

  if (generators[name]) {
    debug('add called but running generate instead', name, params);
    return generate(root, name, params);
  }

  debug('add', name, params);
  return utils.add(path.join(root, 'node_modules'), name, params);
};

Comments Please 😃

I am happy to implement this in my spare time because I'd like to see it done ASAP. I just would like a little input first so I know if I am heading down the wrong path before I start.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions