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

Add support for specifying a path for the generate command #9387

Merged
merged 1 commit into from Jan 26, 2022

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Nov 23, 2020

This is needed for this project:

Which has these remaining TODOs before the idea can even work

  • add an API to allow accessing what files are generated in afterInstall (not the focus of this PR)
  • add a path in place of the blueprint name, similar to how new can use a path to a local blueprint,
    rather than rely on the name resolution system currently in place.
    this is useful, for wanting to chain blueprint executions, as is the focus of ember-codemod-blueprint
    (what this PR is focused on)

I'm open to advice on approach here, but those two bullets are what I need to be able to build more straightforward and extensible blueprint in user-space.

I'm kind of thinking about blueprints being like this at a high level (after the above work):

generateBaseBlueprint('ember-source/blueprints/component')
 |> renameToTypeScript
 |> addTypeArgument
 |> etc

actual api in https://github.com/NullVoxPopuli/ember-codemod-blueprint -- main difference is no pipes, and you'd want to work with specific file paths, rather than whatever the blueprint output is.
So a snippet from ember-codemod-blueprint,

module.exports = codemodBlueprint({
  upstream: 'ember-source/blueprints/component',
 
  transform(options, helpers) {
    let { transformScript, transformTemplate } = helpers;
    let { generatedFiles } = options;

    for (let fileInfo of generatedFiles) {
      
      if (fileInfo.name.includes('app/components') && fileInfo.name.endsWith('.js')) {
        await transformScript(
          scriptPath, 
          transformA, 
          transformB, 
          transformC
       );
     }
     // etc, and more transforms for the other files
    }
});

This approach should work for app-generation as well, but the transform hook may be much bigger, depending on how different your team's default app is from the base blueprint

@NullVoxPopuli NullVoxPopuli force-pushed the support-local-blueprints branch 2 times, most recently from e63895b to 37837d9 Compare December 5, 2020 21:52
@mehulkar
Copy link
Contributor

Some high level feedback: instead of a second arg, you could use the same one? ember g named-blueprint and ember g path/to/blueprint could be nicer

@NullVoxPopuli NullVoxPopuli changed the title Add support for specifying a --blueprint path for the generate command Add support for specifying a path for the generate command Dec 17, 2020
@NullVoxPopuli
Copy link
Contributor Author

NullVoxPopuli commented Dec 17, 2020

Just tried this in a monorepo, and it was succesful:

❯ ember g ../../../node_modules/ember-source/blueprints/component my-component-via-path
installing component
  create addon/components/my-component-via-path/index.hbs
  skip addon/components/my-component-via-path/index.js
  tip to add a class, run `ember generate component-class my-component-via-path`
installing component-test
  create tests/integration/components/my-component-via-path-test.js
installing component-addon
  create app/components/my-component-via-path.js
  
❯  ember d ../../../node_modules/ember-source/blueprints/component my-component-via-path
uninstalling component
  remove addon/components/my-component-via-path/index.hbs
uninstalling component-test
  remove tests/integration/components/my-component-via-path-test.js
uninstalling component-addon
  remove app/components/my-component-via-path.js

@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review December 17, 2020 21:23
@NullVoxPopuli
Copy link
Contributor Author

Related: emberjs/rfcs#699

@@ -1279,6 +1279,23 @@ let Blueprint = CoreObject.extend({
Blueprint.lookup = function (name, options) {
options = options || {};

if (name.includes(path.sep)) {
let blueprintPath = path.resolve(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add check for relative/absolute paths, is cwd = curren project dir?

@locks locks added the agenda label Jan 10, 2022
Copy link
Contributor

@ef4 ef4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems OK to land, we just need to rebase and make sure tests still pass.

rather than relying on blueprint lookup/resolver rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants