{"id":16440477,"url":"https://github.com/icai/gulp-multifile","last_synced_at":"2026-05-08T03:12:58.271Z","repository":{"id":43131213,"uuid":"63876974","full_name":"icai/gulp-multifile","owner":"icai","description":"generate collection files from json files and template file","archived":false,"fork":false,"pushed_at":"2018-04-20T15:01:41.000Z","size":9,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T21:18:04.133Z","etag":null,"topics":["generator","gulp","gulp-plugin","json","json-files","template"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-21T14:36:46.000Z","updated_at":"2017-05-14T07:42:50.000Z","dependencies_parsed_at":"2022-08-30T09:42:08.681Z","dependency_job_id":null,"html_url":"https://github.com/icai/gulp-multifile","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Fgulp-multifile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Fgulp-multifile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Fgulp-multifile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Fgulp-multifile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icai","download_url":"https://codeload.github.com/icai/gulp-multifile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240766672,"owners_count":19854114,"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":["generator","gulp","gulp-plugin","json","json-files","template"],"created_at":"2024-10-11T09:12:13.147Z","updated_at":"2026-05-08T03:12:53.240Z","avatar_url":"https://github.com/icai.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-multifile\n\ngenerate collection files from json files and template file.\n\n\n[![NPM](https://nodei.co/npm/gulp-multifile.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/gulp-multifile/)\n\n\n\n## Getting Started\n\n\nyou may install this plugin with this command:\n\n```shell\nnpm install gulp-multifile --save-dev\n```\n\n## Setup\n\nOnce the plugin has been installed, it may be enabled inside your gulpfile with this line of JavaScript:\n\n\n\n```js\nvar multifile = require('gulp-multifile');\n\n\ngulp.task('gen:scss', function() {\n    gulp.src('src/data/*.json')\n        .pipe(multifile({\n            template: \"src/template/sass.tpl\",\n            rename: function(paths, data, dataFile) {\n                paths.dirname = path.basename(dataFile.basename, '.json')\n                paths.basename = data.name;\n                paths.extname = \".scss\";\n                return paths;\n            }\n        }))\n        .pipe(gulp.dest('src/sass'));\n\n        // src/data/file1.json =\u003e `{ name: 'file1-0'}`\n        // output file =\u003e src/sass/file1/file1-0.scss\n\n});\n\n\n```\n\n\n## Options\n\n\n**Plugin options** are:\n\n|       Property       | Necessary |    Type    |         Plugin default value        |\n| -------------------- | --------- | ---------- | ----------------------------------- |\n| template             | yes       | `String`   | undefined                           |\n| rename               | yes       | `Function` | undefined                           |\n| [filter]             | no        | `Function` | null                                |\n| [extdata]            | no        | 'Object'   | 'undefined'                                |\n| [varname / variable] | no        | `String`   | 'data', _.templateSettings.variable |\n| [escape]             | no        | 'RegExp'   | _.templateSettings.escape           |\n| [evaluate]           | no        | 'RegExp'   | _.templateSettings.evaluate         |\n| [interpolate]        | no        | 'RegExp'   | _.templateSettings.interpolate      |\n| [engine]             | no        | 'Function' | undefined                           |\n\t\n\nMore detailed explanation is below.\n\n#### options.template\n\nType: `String`\n\nDefault value: `undefined`\n\nThe template file for collection generating\n\n\n\n#### options.rename\n\nType: `Function`\n\nDefault value: `undefined`\n\nCan define rename function to output your file which you should return `Object` including keys `dirname`, `basename`, `extname` in order to make file relative path.\n\n```js\n\trename: function(paths, data, dataFile) {\n\t    paths.dirname = path.basename(dataFile.basename, '.json')\n\t    paths.basename = data.name;\n\t    paths.extname = \".scss\";\n\t    return paths; \n        // return the path object for building file relative path\n\t}\n\n```\n\n\n\n\n#### options.filter\n\nType: `Function`\n\nDefault value: `undefined`\n\nCan define filter function to skin the item data render which you should `return false`.\n\n\n```js\nfilter: function(data, file){\n    // data is json model data\n    // file is json file\n\n    // you should return value here \n}\n\n```\n\n#### options.extdata\n\nType: `Object`\n\nDefault value: `undefined`\n\n\nextend the json data, this `extdata` inject to `data.extdata`, if it given.\n\n\n\n#### options.varname / options.variable\n\nType: `String`\n\nDefault value: `data`\n\n\nlodash templateSettings `_.templateSettings.variable`\n\nUsed to reference the data object in the template text.\n\n\n#### options.escape\n\nType: `RegExp`\n\nDefault value: `_.templateSettings.escape`\n\n\nlodash templateSettings `_.templateSettings.escape`\n\nUsed to detect `data` property values to be HTML-escaped.\n\n\n#### options.evaluate\n\nType: `RegExp`\n\nDefault value: `_.templateSettings.evaluate`\n\nlodash templateSettings `_.templateSettings.evaluate`\n\nUsed to detect code to be evaluated.\n\n\n#### options.interpolate\n\nType: `RegExp`\n\nDefault value: `_.templateSettings.interpolate`\n\n\nlodash templateSettings `_.templateSettings.interpolate`\n\nUsed to detect `data` property values to inject.\n\n\n#### options.engine\n\nType: `Function`\n\nDefault value: `undefined`\n\nreturn {Function} compiled source method\n\nUsed to replace lodash template, if the template engine privided.\n\n```js\n\nengine: function(templatefile){\n    return doT.template(templatefile);\n}\n\n```\n\n## Note\n\n#### Json File\nthe json pass from gulp.src , which their format as following is correct:\n\n\n**Array**\n\n`[{ 'name': 'I am name'},{ 'name': 'name also'}]` \n\ngenerate two file, which this json is a collection file.\n\n**Object**\n\n`{ 'name' : 'model'}`\n\ngenerate one file, which this json is a model file.\n\n\n#### Template Engine\n\nwe use `lodash.template` to do this, you can use `engine` parameter to replace  it.\n\n\n\n\n\n## Demo\nsee the [cozhihu](https://github.com/icai/cozhihu) project or unit testing.\n\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Gulp](http://gulpjs.com/).\n\n\n\n## License\nCopyright (c) 2017 Terry Cai. Licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficai%2Fgulp-multifile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficai%2Fgulp-multifile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficai%2Fgulp-multifile/lists"}