{"id":17472706,"url":"https://github.com/shinnn/grunt-merge-data","last_synced_at":"2025-04-09T22:54:22.304Z","repository":{"id":12687979,"uuid":"15360197","full_name":"shinnn/grunt-merge-data","owner":"shinnn","description":"Merge multiple data into a single JSON file or Grunt config, based on their basename","archived":false,"fork":false,"pushed_at":"2016-09-09T17:48:15.000Z","size":64,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T22:54:16.780Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinnn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-21T14:38:04.000Z","updated_at":"2016-12-31T07:14:39.000Z","dependencies_parsed_at":"2022-09-26T18:41:18.489Z","dependency_job_id":null,"html_url":"https://github.com/shinnn/grunt-merge-data","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fgrunt-merge-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fgrunt-merge-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fgrunt-merge-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fgrunt-merge-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnn","download_url":"https://codeload.github.com/shinnn/grunt-merge-data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125632,"owners_count":21051766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-18T17:34:23.283Z","updated_at":"2025-04-09T22:54:22.279Z","avatar_url":"https://github.com/shinnn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grunt-merge-data\n\n[![NPM version](https://img.shields.io/npm/v/grunt-merge-data.svg)](https://www.npmjs.com/package/grunt-merge-data)\n[![Build Status](https://travis-ci.org/shinnn/grunt-merge-data.svg?branch=master)](https://travis-ci.org/shinnn/grunt-merge-data)\n[![Build status](https://ci.appveyor.com/api/projects/status/ckiescfon6xcce0f?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/grunt-merge-data)\n[![Dependency Status](https://david-dm.org/shinnn/grunt-merge-data.svg)](https://david-dm.org/shinnn/grunt-merge-data)\n[![devDependency Status](https://david-dm.org/shinnn/grunt-merge-data/dev-status.svg)](https://david-dm.org/shinnn/grunt-merge-data#info=devDependencies)\n\nMerge multiple data into a single JSON file or Grunt config, based on their basename\n\n## Installation\n\n[Use npm](https://docs.npmjs.com/cli/install).\n\n```sh\nnpm install --save-dev grunt-merge-data\n```\n\n## Usage\n\nThe plugin may be enabled inside your Gruntfile with this line of JavaScript:\n\n```javascript\ngrunt.loadNpmTasks('grunt-merge-data');\n```\n\n### The `merge_data` task\n\nIn your project's Gruntfile, add a section named `merge_data` to the data object passed into `grunt.initConfig()`.\n\n```javascript\ngrunt.initConfig({\n  merge_data: {\n    options: {\n      // Task-specific options go here.\n    },\n    your_target: {\n      src: ['path/to/src/*.{json,y{,a}ml}']\n      dest: 'path/to/dest/all.json'\n    }\n  }\n})\n```\n\nRunning `merge_data` task task with `grunt merge_data` command will merge all data of specified JSON or YAML files into a single JavaScript object, and write it as a JSON file.\n\nEach of the data will be formatted as `{\u003cbasename of file\u003e: \u003cdata of file\u003e}`.\nFor example, when the source path of task target specifies two files, such as:\n\ndata1.json:\n\n```json\n[\"Classic\", \"Jazz\", \"Rock\"]\n```\ndata2.yaml:\n\n```yaml\nfirst_name: John\nfamily_name: Smith\n```\n\nthey will be merged into a JSON file like this:\n\n```json\n{\n  \"data1\": [\"Classic\", \"Jazz\", \"Rock\"],\n  \"data2\": {\n    \"first_name\": \"John\",\n    \"family_name\": \"Smith\"\n  }\n}\n```\n\n### Options\n\n#### options.data\nType: `Object|Function`\nDefault: `null`\n\nThis is an additional data that will be merged together with the sources files.\n\nThis option will overrides existing data of source files.\nFor example, when `option.data` is `{data1: 'something'}`, the data of `data1.json` won't be reflected in the output.\n\nThis value also might be a function taking a data object of source files as the first argument and returns a data object.\n\n```javascript\noptions: {\n  data: function (data) {\n    return {\n      next_year: data.year + 1,\n      prev_year: data.year - 1\n    };\n  }\n}\n```\n\n#### options.space\nType: `Number|String`\nDefault: `null`\n\nThis option will be directly passed to the [`space` argument](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#space_argument) of `JSON.stringify`. You can control indent style of output file with this option. \n\n#### options.asConfig\nType: `String|Array|Boolean`\nDefault: `false`\n\nIf you specified the project's Grunt configuration in this option, merge result will be assigned to it. See [Accessing Config Data](http://gruntjs.com/api/grunt.config#accessing-config-data) to use this option.\n\nOr, if you set this option `true`, the `context` property of the task traget will be overwritten with the merge result.\n\nFor example, if the task is configured such as:\n\n```javascript\ngrunt.initConfig({\n  merge_data: {\n    target1: {\n      options: {\n        asConfig: true\n      },\n      src: ['path/to/src/*.{json,y{,a}ml}']\n    }\n  }\n})\n``` \n\nthe merge result will be assigned to `merge_data.target1.context`.\n\nWhen you use this option, you can also specify the destination path of task target but don't need to.\nIf you do so, at the same time the Grunt configuration will be updated, the JSON file will be output. Both the configuration and the JSON file will have the same value.\n\n### Usage Examples\n\n#### Default Options\n\n```javascript\ngrunt.initConfig({\n  merge_data: {  \n    files: {\n      'dest/all.json': ['src/data1.json', 'src/data2.json'],\n    }\n  }\n})\n```\n\n#### Updating Grunt configuration\n\n```javascript\ngrunt.initConfig({\n  merge_data: {\n    options: {\n      asConfig: 'someConfig.data' \n    },\n    src: ['src/data1.json', 'src/data2.json']\n  }\n  \n  someConfig: {}\n})\n```\n\n## License\n\nCopyright (c) 2013 - 2016 [Shinnosuke Watanabe](https://github.com/shinnn).\n\nLicensed under [the MIT license](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fgrunt-merge-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnn%2Fgrunt-merge-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fgrunt-merge-data/lists"}