Giter Site home page Giter Site logo

Modify action for json files about plop HOT 8 CLOSED

plopjs avatar plopjs commented on August 16, 2024 1
Modify action for json files

from plop.

Comments (8)

mritzco avatar mritzco commented on August 16, 2024 1

I created a custom action type to add data to my config.json file.
Tried to follow the plop style to keep it customizable.

https://gist.github.com/mritzco/88306b56c0184e66e33374d6b6ed2751

from plop.

wbobeirne avatar wbobeirne commented on August 16, 2024

I went ahead and made a custom action for this, but I definitely think this could get rolled in as a flag on modify action types or a new action type altogether. Here's the code for alterJsonAction.js: https://gist.github.com/wbobeirne/63e1b8c3a16ffce6dac5c7d81afd5cec?ts=2

Example usage from my use case is:

const alterJsonAction = require("alterJsonAction");

actions: [alterJsonAction({
    path: "../webpack/entries.json",
    alter: (json, data) => {
        const name = snakeCase(data.name);
        json[data.platform][name] = `pages/${name}`;
        return json;
    },
})],

I also threw in an indentation arg there that takes an int or "\t", if 2 spaces ain't your game.

from plop.

amwmedia avatar amwmedia commented on August 16, 2024

sorry for the late response, I agree that this would be pretty useful in some cases. I'll have to give some more thought to the best implementation for this feature. Thanks!

from plop.

amwmedia avatar amwmedia commented on August 16, 2024

hey, with plop 1.8.0 you can now create custom action types that you can share with other projects :-)

from plop.

amwmedia avatar amwmedia commented on August 16, 2024

nice! You could publish this out as an NPM module that others can use via plop.load(). If you want to do that and need help, let me know.

from plop.

mritzco avatar mritzco commented on August 16, 2024

I'll happily do! Just publish to npm or any specific requirements?

from plop.

amwmedia avatar amwmedia commented on August 16, 2024

Sorry for the delay on this response. You can look at this repo as a guide to how this is done. I'm going to try to get more instructional content together soon.

from plop.

mritzco avatar mritzco commented on August 16, 2024

@amwmedia
Ok, that took a bit longer than expected:

Could you please take a look at this repo and let me know if that would do.

Original method gets the config on the method call, while the load method passes the config on the require function. It's working with the testing file but I'm not sure it will work properly in all cases.

from plop.

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.