Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override Generators #104

Open
imaustink opened this issue Apr 12, 2018 · 3 comments
Open

Override Generators #104

imaustink opened this issue Apr 12, 2018 · 3 comments

Comments

@imaustink
Copy link

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.

@justinbmeyer
Copy link

There is a generator generator already and a guide for it:https://donejs.com/generator.html

Does this do what you need?

@justinbmeyer
Copy link

To restate, I think you should create an rvm-component generator (instead of mixing this into the current generator). The types of generators is unlimited, making trying to support them all within DoneJS problematic. This is why we made creating new ones easy.

@matthewp
Copy link
Contributor

I agree about this becoming a generator. I think one reason why this type of request comes up often is because it's more natural to do donejs add component MyComponent than it is to do donejs add rvm-component MyComponent. For can-components it's not donejs add can-component my-component.

I wonder if we should support some method to alias generator names, so that you can use the shorthand. The flow might be like this:

donejs add rvm-component

donejs alias component rvm-component

donejs add component MyComponent

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

No branches or pull requests

4 participants