LoginSignup
3
3

More than 5 years have passed since last update.

yaml で書いた複数の設定ファイルをひとつの json に書き出す Gruntfile

Posted at

grunt ムネアツですね!

yaml で書いた複数の設定ファイルを、ひとつの json にまとめたい場合の Gruntfile です。
以下は、src/*.yml をまず src/*json に書き出し、js/settings.json にまとめる方法です。

使用するプラグイン

grunt-yaml

https://npmjs.org/package/grunt-yaml
npm install grunt-yaml --save-dev

grunt-extend

https://npmjs.org/package/grunt-extend
npm install grunt-extend --save-dev

module.exports = (grunt) ->
    pkg = grunt.file.readJSON 'package.json'
    grunt.initConfig
        yaml:
            my_target:
                files:
                    'src/hoge.json': ['src/hoge.yml']
                    'src/fuga.json': ['src/fuga.yml']
        extend:
            my_target:
                files: 'js/settings.json': ['src/*.json']
        watch:
            files: ['src/*.yml']
            tasks: ['yaml', 'extend']

    for t of pkg.devDependencies
        if t.substring(0, 6) is 'grunt-'
            grunt.loadNpmTasks t

    grunt.registerTask 'default', ['yaml', 'extend']
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3