Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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']
wings1685
京都で Flügel って名前でフリーエンジニアしてます。Python と Ruby が好きですが、仕事では PHP なんです。
http://flugel.biz/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away