npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-multifile

v0.2.2

Published

generate collection files from json files and template file

Downloads

4

Readme

gulp-multifile

Getting Started

you may install this plugin with this command:

npm install gulp-multifile --save-dev

##Setup

Once the plugin has been installed, it may be enabled inside your gulpfile with this line of JavaScript:

var multifile = require('gulp-multifile');


gulp.task('gen:scss', function() {
    gulp.src('src/data/*.json')
        .pipe(multifile({
            template: "src/template/sass.tpl",
            rename: function(paths, data, dataFile) {
                paths.dirname = path.basename(dataFile.basename, '.json')
                paths.basename = data.name;
                paths.extname = ".scss";
                return paths;
            }
        }))
        .pipe(gulp.dest('src/sass'));

        // src/data/file1.json => `{ name: 'file1-0'}`
        // output file => src/sass/file1/file1-0.scss

});

##Options

Plugin options are:

| Property | Necessary | Type | Plugin default value | | -------------------- | --------- | ---------- | ----------------------------------- | | template | yes | String | undefined | | rename | yes | Function | undefined | | [filter] | no | Function | null | | [extdata] | no | 'Object' | 'undefined' | | [varname / variable] | no | String | 'data', _.templateSettings.variable | | [escape] | no | 'RegExp' | _.templateSettings.escape | | [evaluate] | no | 'RegExp' | _.templateSettings.evaluate | | [interpolate] | no | 'RegExp' | _.templateSettings.interpolate | | [engine] | no | 'Function' | undefined |

More detailed explanation is below.

options.template

Type: String

Default value: undefined

The template file for collection generating

options.rename

Type: Function

Default value: undefined

Can define rename function to output your file which you should return Object including keys dirname, basename, extname in order to make file relative path.

	rename: function(paths, data, dataFile) {
	    paths.dirname = path.basename(dataFile.basename, '.json')
	    paths.basename = data.name;
	    paths.extname = ".scss";
	    return paths; 
        // return the path object for building file relative path
	}

options.filter

Type: Function

Default value: undefined

Can define filter function to skin the item data render which you should return false.

filter: function(data, file){
    // data is json model data
    // file is json file

    // you should return value here 
}

options.extdata

Type: Object

Default value: undefined

extend the json data, this extdata inject to data.extdata, if it given.

options.varname / options.variable

Type: String

Default value: data

lodash templateSettings _.templateSettings.variable

Used to reference the data object in the template text.

options.escape

Type: RegExp

Default value: _.templateSettings.escape

lodash templateSettings _.templateSettings.escape

Used to detect data property values to be HTML-escaped.

options.evaluate

Type: RegExp

Default value: _.templateSettings.evaluate

lodash templateSettings _.templateSettings.evaluate

Used to detect code to be evaluated.

options.interpolate

Type: RegExp

Default value: _.templateSettings.interpolate

lodash templateSettings _.templateSettings.interpolate

Used to detect data property values to inject.

options.engine

Type: Function

Default value: undefined

return {Function} compiled source method

Used to replace lodash template, if the template engine privided.


engine: function(templatefile){
    return doT.template(templatefile);
}

##Note

####Json File the json pass from gulp.src , which their format as following is correct:

Array

[{ 'name': 'I am name'},{ 'name': 'name also'}]

generate two file, which this json is a collection file.

Object

{ 'name' : 'model'}

generate one file, which this json is a model file.

####Template Engine

we use lodash.template to do this, you can use engine parameter to replace it.

##Demo see the cozhihu project or unit testing.

Contributing

In 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.

License

Copyright (c) 2016 Terry Cai. Licensed under the MIT license.