GithubHelp home page GithubHelp logo

gulp-version-number's Introduction

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

gulp-version-number's People

Contributors

charanrajtc avatar codebykenny avatar shinate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gulp-version-number's Issues

Append breaking on AngularJS directive

Hello and thanks for a great utility - I wouldn't have been sure my approach to versioning is correct without it.

I'm running into an exception when it tries to replace an AngularJS directive though:

<img-crop/>

caused by this line:

var sts = content.match(/<img[^&gt;]*>/g);

Maybe this matching and the other similar lines can benefit from a space after the tag name, correct me if I'm wrong.

support metadata such as <link>

Wondering if it's possible to target metadata such as <link> and <meta>.
I have these two cases:

<link rel="icon" href="/img/favicon.png">
<meta property="og:image" content="/img/share.png">

Thanks.

TypeError: Cannot read property '1' of null

if (_RULE[1]) {
^

TypeError: Cannot read property '1' of null
at Object.css (/var/www/html/project/node_modules/gulp-version-number/index.js:215:30)
at apply_append (/var/www/html/project/node_modules/gulp-version-number/index.js:200:46)
at /var/www/html/project/node_modules/gulp-version-number/index.js:309:51
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:528:3)

perl TMPL_VAR

Hi, i use gulp-version-number-0.1.7

Source:
<script src="<TMPL_VAR cdn_url>/js/embed.min.js"></script>

Result:
<script src="<TMPL_VAR cdn_url?v=0757b5c1a2b89ddc5a8ef49f1d17795d>/js/embed.min.js"></script>

Assert:
<script src="<TMPL_VAR cdn_url>/js/embed.min.js?v=0757b5c1a2b89ddc5a8ef49f1d17795d"></script>

How to fix this behavior?

Add support for ng-href and on<events> in link tag

I found out that:

<link ng-href="themes/{{theme||'default'}}/css/style.css" rel="stylesheet" onerror="this.href='themes/experter/css/style.css'">

is being parsed as:

<link ng-href="themes/{{theme||?v=44edd1b317271634126140a94694357b'default'}}/css/style.css" rel="stylesheet" onerror="this.href='themes/experter/css/style.css'">

which is not the expected output. The expected output should be:

<link ng-href="themes/{{theme||'default'}}/css/style.css?v=44edd1b317271634126140a94694357b" rel="stylesheet" onerror="this.href='themes/default/css/style.css?v=44edd1b317271634126140a94694357b''">

I'm using version 0.1.7, using the version config as shown below:

const versionConfig = {
    'value': '%MDS%',
    'append': {
        'key': 'v',
        'to': ['js', 'css', 'sass'],
    },
};

target just one file

Hi I'm trying to have the ?v= string applied just to one of the js included in index.html, how could I do?
This way produce error

const $ = gulpLoadPlugins();
const versionConfig = {
'value': '%MDS%',
'append': {
'key': 'v',
'to': ['css', 'script1.js'],
},
};

Version string always be uppercase

gulp.src('src/*')
.pipe(version({
    value: 'v1.0.0',
    replaces: [
        /#version#/g
    ]
}))
.pipe(gulp.dest('dist'));

v1.0.0 will be with V1.0.0 in dest file. All alphabet in version string will be change to uppercase.
Please retain original version string.

index.js#L86

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.