javascript - Can I use grunt to set a property value in a json file? -
still learning ropes of grunt , can't find solution this. have config file, config.json data.
when run specific grunt task want increment value in config.json file. i've been able find lot of information on how read file nothing far on changing value.
thanks.
you can use https://github.com/eruizdechavez/grunt-string-replace replace string , save file
'string-replace': { dist: { files: { 'dest/': 'src/**', 'prod/': ['src/*.js', 'src/*.css'], }, options: { replacements: [{ pattern: /\/(asdf|qwer)\//ig, replacement: '"$1"' }, { pattern: ',', replacement: ';' }] } } }
with grunt plugin u can substitute regex pattern (or simple string) replacement
the steps make final json are:
- load json file >> http://gruntjs.com/api/grunt.file
- apply replace task >> on top
- save json file >> grunt.file.write(filepath, contents [, options])
Comments
Post a Comment