roboshoes / grunt-json-bake

Grunt plugin that lets you merge multiple JSON files into one.
MIT License
7 stars 3 forks source link

parse array before baking the file #5

Open DomSavd opened 8 years ago

DomSavd commented 8 years ago

First of all, thank you for that great plugin.

I think it could be great if we can parse the array before creating the json file in order to only retrieve the data we need from the json files source.

For example, i want to retrieve "books" from a folder with multiples json files with that structure:

{
    "author": {
        "name": "Mathias Paumgarten",
        "url": "http://www.mathias-paumgarten.com"
    },
    "books": [
        {
            "name": "awesome book",
            "released": "2014"
        },
        { ... },
        { ... }
    ]
}

Thank you!

roboshoes commented 8 years ago

That is a good idea. I could imagine a callback for every file it is about to absorb. And when returned false the file will be skipped.

grunt.initConfig( {
    json_bake: {

        your_target: {
            options: {
                onFile: function( path, name ) { return name === "passwords.json" ? false : true }
            },

            files: {
                "dist/final.json": "app/base.json"
            }
        }
    }
} );

This will not include any file that is called passwords.json. What to you think?