Git Product home page Git Product logo

Comments (4)

lewisf avatar lewisf commented on June 18, 2024

+1

from redux-cli.

SpencerCDixon avatar SpencerCDixon commented on June 18, 2024

Yeah this is totally doable!

First let me re-iterate the question to make sure I'm understanding what exactly you'd like to do:

When you run redux g dumb MyComponent you want the MyComponent.test.js file to live inside a __tests__ folder that is nested in the components folder?

If so, to implement that you can override the default blueprints that come with the CLI and/or the starter kit. To do that you just need to create a local blueprints folder in your project root OR modify a blueprint that is already in your project root (if using the starter kit). You would want to change the blueprint for dumb to look like this:

  1 dumb
      2 ├── files
      3 │   └── __root__
      4 │       └── __dumb__
      5 │           ├── __test__
      6 │           │   └── __name__.test.js
      7 │           └── __name__.js
      8 └── index.js

Now we have a little bit of an issue because the __test__ token is going to be automatically converted to whatever your testBase is. However, we can take advantage of the 'hooks' inside each blueprints index.js to modify functionality. So inside the index.js file for the dumb blueprint you could do this:

module.exports = {
  description() {
    return 'Generates a dumb (aka Pure) component';
  },
  fileMapTokens() {
    return {
      __test__: (options) => {
        return '__test__';
      }
    };
  }
};

This essentially overrides the default behavior and says that when mapping the files to be generated leave the __test__ token alone and use the STRING '__test__'for the folder name.

Hope this makes sense, let me know if you have any questions!

from redux-cli.

qmmr avatar qmmr commented on June 18, 2024

Hi Spencer,
Thanks, works like a charm! I had to add the path to __dumb__ compoents as well, like so:

module.exports = {
  description() {
    return 'Generates a dumb (aka Pure) component';
  },
  fileMapTokens() {
    return {
      __test__: (options) => '__tests__',
      __dumb__: (options) => 'components',
    };
  }
};

👍

from redux-cli.

SpencerCDixon avatar SpencerCDixon commented on June 18, 2024

Awesome, glad you got it working!

from redux-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.