Skip to content

shinate/gulp-version-number

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-version-number

Add version number to js/css/image in HTML

NPM version

usage

var version = require('gulp-version-number');

gulp.src('src/*.html')
    .pipe(version({
		... configuration ...
    }))
    .pipe(gulp.dest('build'));

configuration

config

{

    /**
     * Global version value
     * default: %MDS%
     */
    'value' : '%MDS%',

    /**
     * MODE: REPLACE
     * eg:
     *    'keyword'
     *    /regexp/ig
     *    ['keyword']
     *    [/regexp/ig, '%MD5%']]
     */
    'replaces' : [
    
        /**
         * {String|Regexp} Replace Keyword/Rules to global value (config.value)
         */
        '#{VERSION_REPlACE}#',
        
        /**
         * {Array}
         * Replace keyword to custom value
         * if just have keyword, the value will use the global value (config.value).
         */    
        [/#{VERSION_REPlACE}#/g, '%TS%']
    ],
    
    
    /**
     * MODE: APPEND
     * Can coexist and replace, after execution to replace
     */
    'append' : {
    
        /**
         * Parameter
         */
        'key' : '_v',
        
        /**
         * Whether to overwrite the existing parameters
         * default: 0 (don't overwrite)
         * If the parameter already exists, as a "custom", covering not executed.
         * If you need to cover, please set to 1
         */
        'cover' : 0,
        
        /**
         * Appended to the position (specify type)
         * {String|Array|Object}
         * If you set to 'all', will apply to all type, rules will use the global setting.
         * If an array or object, will use your custom rules.
         * others will passing.
         * 
         * eg:
         *     'js'
         *     ['js']
         *     {type:'js'}
         *     ['css', '%DATE%']
         */
        'to' : [
        
            /**
             * {String} Specify type, the value is the global value
             */
            'css',
            
            /**
             * {Array}
             * Specify type, keyword and cover rules will use the global 
             * setting, If you need more details, please use the object 
             * configure.
             *
             * argument 0 necessary, otherwise passing.
             * argument 1 optional, the value will use the global value
             */
              ['image', '%TS%'],
              
            /**
             * {Object}
             * Use detailed custom rules to replace, missing items will 
             * be taken in setting the global completion
             
             * type is necessary, otherwise passing.
             */
            {
                'type'  : 'js',
                'attr'  : ['src', 'custom-src'] // String or Array, undefined this will use default. css: "href", js: ...
                'key'   : '_v',
                'value' : '%DATE%',
                'cover' : 1,
                'files': ['build.js', /dependency.js/] // Array [{String|Regex}] of explicit files to append to
            }
        ]
    },
 
    /**
     * Output to config file
     */
    'output' : {
        'file' : 'version.json'
    }
}

Priority - Covering relations

  • {Object}config.append.to[x].type == {Array}config.append.to[x][0] == {String}config.append.to[x]
  • config.append.to[x].key > config.append.key
  • config.append.to[x].cover > config.append.cover
  • config.append.to[x].value == config.append.to[x][1] [ (IF cover is TRUE) > (ELSE) == config.replace[x][1] ] > config.value

Options

Version types

  • %DATE% date [YYYYMMDD]
  • %DT% date + time [YYYYMMDDHHIISS]
  • %TS% timestamp [INT10]
  • %TSM% timestamp(millisecond) [INT13]
  • %MD5% MD5(timestamp) [STRING32]
  • %MDS% MD5(MD5(timestamp) + salt) [STRING32]
  • {STRING} In addition to the above keywords, considered custom

Change log

= 0.2.0 =
  • Add a configure prop to "Object" model at "options.append.to", set the attribute what you want to match
append : {
 to : [
   '???': {
     ...,
     'attr': [...] // string or array
     ...
   },
   ...
 ]
}
= 0.1.4 =
  • Detailed description comment and readme.
  • Change salt to length 8
= 0.1.3 =
  • BUGFIX: css rules
= 0.1.2 =
  • Output function mounting, the version output to a file.
= 0.1.1 =
  • BUGFIX: regexp
= 0.1.0 =

I was born

About

Add version number to js/css/image in HTML

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •