Git Product home page Git Product logo

grunt-assets-versioning's Introduction

grunt-assets-versioning Build Status NPM version

![Gitter](https://badges.gitter.im/Join Chat.svg)

Versioning static assets with Grunt

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-assets-versioning --save-dev

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

grunt.loadNpmTasks('grunt-assets-versioning');

The "assets_versioning" task

Overview

In your project's Gruntfile, add a section named assets_versioning to the data object passed into grunt.initConfig().

grunt.initConfig({
  assets_versioning: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      options: {
        tasks: ['uglify:targetTask']
      }
    },
  },
})

This task will version the files output by the task uglify:targetTask.

Options

options.tag

Type: String Possible values: date, hash Default value: hash

Should the revision marker be a md5 hash or a date ?

options.hashLength

Type: Integer Default value: 8

If you choose to version your files using a hash, hashLength let you set how long the hash is going to be.

options.dateFormat

Type: String Default value: YYYYMMDDHHmmss

If you choose to version your files using a date, you can specify a dateformat. grunt-assets-versioning is using moment.js to format date.

options.timezoneOffset

Type: Number Default value: 0

Only works if you choose to version your files using a date. Timezone offset (in hours) to take into account when generating the date version tag. By default, set to 0 (GMT time).

options.tasks

Type: Array or Boolean Default value: false

The tasks you want to run while versioning their destination files.

options.versionsMapFile

Type: String Path to the file in which the versions map will be dumped.

The assets versioning files outputs a map of versions of all the files processed. Here's how that map looks like:

[
  {
    version: '3d04f375',
    originalPath: 'path/to/bundle-a.js',
    versionedPath: 'path/to/bundle-a.3d04f375.js'
  },
  {
    version: '92jdi2j1',
    originalPath: 'path/to/bundle-b.js',
    versionedPath: 'path/to/bundle-b.92jdi2j1.js'
  }
]

By default you can retrieve the map of versions by accessing this configuration variable. grunt.config('assets_versioning.yourTask.versionsMap') The versionsMapFile gives you the possibility to also output that map to a file.

options.versionsMapTemplate

Type: String Default value: null

Path to a lodash template file that is going to be used to generate the versions map file (options.versionsMapFile)

By default, when no template is indicated, the task will output a json file.

The lo-dash template may reuse the keys from the version maps (version, originalPath, versionedPath). Here's an example of a lo-dash template to generate a php dictionary.

<?php

class MyDict
{
  public static $myDict = array(
<% _.forEach(files, function(file) { %>
    "<%= file.originalPath %>" => "<%= file.versionedPath %>",
<% }); %>
  );

options.versionsMapTrimPath

Type: String This gives you the possibility to trim the path output in the version map.

For example, if you set options.versionsMapTrimPath to be 'super/long/path/to/', instead of getting this map:

[
  {
    version: '3d04f375',
    originalPath: 'super/long/path/to/bundle-a.js',
    versionedPath: 'super/long/path/to/bundle_a.3d04f375.js'
  },
  {
    version: '92jdi2j1',
    originalPath: 'super/long/path/to/bundle-b.js',
    versionedPath: 'super/long/path/to/bundle-b.92jdi2j1.js'
  }
]

you will get this one:

[
  {
    version: '3d04f375',
    originalPath: 'bundle-a.js',
    versionedPath: 'bundle_a.3d04f375.js'
  },
  {
    version: '92jdi2j1',
    originalPath: 'bundle-b.js',
    versionedPath: 'bundle-b.92jdi2j1.js'
  }
]

options.skipExisting

Type: Boolean or Array Default value: false

If true, will skip the task if the destination file already exists. If type Array, will skip the task if the destination file, once versioned, is listed in the array.

options.post

Type: Boolean Default value: false

By default, the grunt-assets-versioning task uses the content of the source files to create a version hash. Combined with the skipExisting option, it allows to speed up the deployment process by skipping tasks that would output an already-existing destination file.

If ever you're trying to version a task that doesn't expose all its source files but only an entry point (less, requirejs), you should set the post options to true.

less: {
  production: {
    files: {
      "path/to/result.css": "path/to/source.less"
    }
  }
},
assets_versioning: {
  css: {
    options: {
      post: true,
      tasks: ["less:production"]
    }
  }
}

Usage Examples

Versioning using a hash

In this example, dest.bundle.js is going to be versioned with a hash. All sources files are going to be hashed and those hashes are also going to be hashed. The generated result should be dest/bundle.2j4h2kds.js

grunt.initConfig({
  assets_versioning: {
    options: {
      tag: 'hash',
      hashLength: 6,
    },
    files: {
      'dest/bundle.js': ['src/file1.js', 'src/file2.js'],
    },
  },
})

Versioning using a date

In this example, dest.bundle.js is going to be versioned with a date, using the default format YYYYMMDDHHmmss. The newest modification dates of all src files is going to be used to create this timestamp. The generated result should be dest/bundle.20130413004500.js

grunt.initConfig({
  assets_versioning: {
    options: {
      tag: 'date',
    },
    files: {
      'dest/bundle.js': ['src/file1.js', 'src/file2.js'],
    },
  },
})

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

Release History

  • 2015-01-29 v1.0.4 Fix MomentJS warning
  • 2015-01-28 v1.0.3 Bug fixing.
  • 2014-11-22 v1.0.2 Add a post mode which generates the version hash based on the destination files and not the source files.
  • 2014-11-02 v1.0.1 Add the ability to generate a version map based on a lo-dash template
  • 2014-11-02 v1.0.0 options.tasks accepts multiple.tasks. options.use replaced by options.tag
  • 2014-11-01 v0.6.0 Major refactoring. skipVersioning false by default. options.versionsMapFile replaces options.output
  • 2014-10-12 v0.5.0 Add tasks option that will eventually replace options.multitask and options.multitaskTarget. Only accept a single task so far.
  • 2014-10-11 v0.4.0 Skip task by providing an array of destination files to ignore.
  • 2014-10-10 v0.3.1 Provide more feedback in debug mode. Improve unit tests coverage significantly.
  • 2014-09-27 v0.3.0 Concatenate files if no surrogate task is passed. Changes in default options. Use hash instead of date. Skip versioning if destination file already exists.
  • 2014-09-26 v0.2.0 Travis Integration, options.timezoneOffset (default: 0 - UTC Time)
  • 2013-06-30 v0.1.5 Update JSHint Configuration and fix warnings
  • 2013-06-30 v0.1.4 Make it work with the Compact format file mapping
  • 2013-06-02 v0.1.3 Fix dateFormat bug
  • 2013-06-02 v0.1.2 Minor bug fixes
  • 2013-05-01 v0.1.1 Add Surrogate tasks and documentation
  • 2013-04-26 v0.1.0 Initial commit

grunt-assets-versioning's People

Contributors

ajwdev avatar bcullman avatar gitter-badger avatar theasta avatar tmihalik 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar

grunt-assets-versioning's Issues

Delete old versioning

Hello,

We can accomplish it using other package, but ti will be great if it can be an option how detect if the package is hash or date versioning and delete all the files before generate the new one, or maybe the possibility to pass a regexp of what delete to be more flexible.

Anyway, great work.

Add a new option: tasks to replace multitask and multitaskTarget

Instead of having the user to point to the external task to version using the options multitask and multitaskTarget, add a options.tasks array to list multitasks to target

assets_versioning: {
    js: {
        options: {
            tasks: [ 'uglify:production']
        }
    }
}

The first iteration will only allow to specify one multitask. Version 0.6.0 will let the user specify multiple multitasks at once.

  • Preserve backward compatibility
  • Add unit tests
  • Remove multitask and multitaskTarget from documentation
  • Document the new option

Use the destination file content instead of sources to version external tasks

The plugin is using the source files content to version the destination file. This way it is possible to deduce the version tag before actually running the task itself.
However it is important to make it possible to version the destination file based on its own content, which means the external tasks passed in the tasks options should be executed first..

This option could be called post or postVersioning or postMode

  • Add documentation
  • Add unit tests
  • Add grunt debug statements

Task 'assets_versioning:local' doesn't exist or doesn't have any configuration

Hi, this is my Gruntfile.js:
`module.exports = function(grunt) {
// Project configuration.

grunt.loadNpmTasks('grunt-contrib-uglify');

grunt.loadNpmTasks('grunt-contrib-requirejs');

grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-contrib-copy');

grunt.loadNpmTasks('grunt-contrib-cssmin');

grunt.loadNpmTasks('grunt-assets-versioning');

grunt.initConfig({

pkg: grunt.file.readJSON('package.json'),
copy: {
    local: {
        files: [{
            cwd: 'src',  // set working folder / root to copy
            src: '**/*',           // copy all files and subfolders
            dest: 'dest',    // destination folder
            expand: true           // required when using cwd
        }]
    },
    dev: {

    }
},
uglify: {
    options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
        mangle: false,
        compress: {
            drop_console: true
        }
    },
    local: {


        files: {
            'src/main.js': ['dest/main.js']
        }

    },
    dev: {

        files: {
             'src/main.js': ['dest/main.js']
        }

    }

},

  cssmin: {
      options: {
          shorthandCompacting: false,
          roundingPrecision: -1
      },
      local: {

          files: {
              'src/style.css': ['dest/style.css']
          }

      },
      dev: {

          files: {
              'src/style.css': ['dest/style.css']
          }

      }

  },

  assets_versioning: {
      options: {
          tag: 'hash',
          hashLength: 6,
          versionsMapFile: 'map.json',
          versionize: false
      },
      local: {
          files: [
              {
                  src: 'src/main.js',
                  dest: 'dest/main.js'
              }
          ]

      },
      dev: {
         files: [
              {
                  src: 'src/main.js',
                  dest: 'dest/main.js'
              }
          ]

      }


  },
  'string-replace': {
      options: {
          replacements:replacements()
      },
      local: {
          files: {
              'src/': 'dest/**'
          }

      },
      dev: {
          files: {
               'src/': 'dest/**'
          }
      }
  }

});

var dev_target = grunt.option('env');
grunt.registerTask('default', ['copy:'+dev_target,'uglify:'+dev_target,'cssmin:'+dev_target]);
grunt.registerTask('versioning', ['assets_versioning:'+dev_target]);
grunt.registerTask('replace', ['string-replace:'+dev_target]);

function replacements() {
var projectFile = "map.json";

    if (!grunt.file.exists(projectFile)) {
        grunt.log.error("file " + projectFile + " not found");
        return true;//return false to abort the execution
    }
    var project = grunt.file.readJSON(projectFile);//get file as json object
    var version = project[0].version;
    var myObj = [];

    for(var i = 0;i<project.length;i++) {
        var originalArr = project[i].originalPath.split('/');
        var original = originalArr[originalArr.length-1];
        var destArr = project[i].versionedPath.split('/');
        var dest = destArr[destArr.length-1];
        myObj.push({'pattern' : original,'replacement' : dest});
        grunt.log.error(myObj[i]['pattern']+"-"+myObj[i]['replacement']);
    }

    return myObj;
}`

when I run

grunt versioning --env=local -v

I get the following warning:

Warning: Task 'assets_versioning:local' doesn't exist or doesn't have any configuration. Use --force to continue.

Is there any compatibility issue with other Grunt plugins I'm using, or is there something wrong in my configuration?

Thank you.

Source file check in post mode

In post mode the existence of source files is checked, even though they are irrelevant for versioning. This check should be disabled in post mode so i does not fail for tasks that have no source files but generate destination files (example: browserify task with aliases).

Versioning folder

There is a way to versioning files of some folders? Or specifying files with regex?
Some tasks, like copy, returns the warning: Task 'copy:main' has no source files.� Use --force to continue..

copy: {
            main: {
                files: [
                    // includes files within path
                    {expand: true,
                        cwd: 'web',
                        src: [
                            'images/**/*',
                            'unico/**/*',
                            'unico/_common/**/*',
                            'views/**/*',
                            'vision/{css,img,templates}/**/*',
                            'index.html',
                            'login.html',
                            'fonts/**/*',
                            'js/field/templates/**/*',
                            'js/require.js',
                            'WEB-INF/**/*'
                        ],
                        dest: 'dist'}
                ]
            }
        }

Warn If no files are passed

Overview

If you use an improper configuration or forget to pass files to the plugin, grunt-assets-versioning doesn't give any warning. Even worst, the feedback leads to think it may have worked.

Steps to reproduce

no_files: {
  options: {
    use: 'date'
  },
  // old declaration format : this.files will be empty
    'tmp/js/no_file/no_file.js': ['test/fixtures/js/file2.js']
},

Actual

No warning. It feels like it worked.

Expected

The plugin should give a warning.

Getting multitask to work with my set up

Hello all I've been looking to a good solution to cache busting and I came across this and wanted to know how I can get my set up to work with this plugin.

Below you can see what I have in my Gruntfile:

module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

less: {
  prod: {
    options: {
      compress: true,
      yuicompress: true,
      optimization: 2
    },
    files: {
      'public/assets/css/app.css': ['public/assets/less/app.less']
    }
  }
},
concat: {
  options: {
    separator: ';\n\n'
  },
  extras: {
    src: ['public/assets/bower_components/jquery/jquery-migrate.min.js', 'public/assets/bower_components/bootstrap/dist/js/bootstrap.min.js', 'public/assets/js/dev/jquery.mobile.custom.min.js', 'public/assets/js/dev/bootstrap-select.min.js', 'public/assets/js/dev/jquery.fitvids.js', 'public/assets/js/dev/iframe.xss.response-3.3.0.js', 'public/assets/js/dev/jquery.fineuploader-3.3.0.min.js'],
    dest: 'public/assets/js/dev/plugins.js'
  }
},
uglify: {
  options: {
    mangle: false
  },
  my_target: {
    files: {
      'public/assets/js/app.min.js': ['public/assets/js/dev/plugins.js', 'public/assets/js/dev/app.js']
    }
  }
},
watch: {
  grunt: {
    files: ['Gruntfile.js']
  },

  less: {
    files: ['public/assets/bower_components/bootstrap/less/*.less', 'public/assets/less/*.less'],
    tasks: 'less'
  },

  uglify: {
    files: ['public/assets/js/dev/app.js'],
    tasks: 'uglify'
  }

}

});

grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('build', ['less', 'concat', 'uglify']);
grunt.registerTask('default', ['build', 'watch']);
}

I've noticed that multitask is being used in some examples and just not sure how that would work with all the current task I have running.

Use the destination file content instead of sources to version internal tasks

The plugin is using the source files content to version the destination file. This way it is possible to deduce the version tag before actually running the task itself.
However it is important to make it possible to version the destination file based on its own content, which means the internal task must first concatenate or copy and then version the destination file

This option could be called post or postVersioning or postMode

  • Add unit tests
  • Add grunt debug statements

version map merge option?

Would be nice to have a merge option for the version map. Currently when running watch commands it will override the file and lose all other versioned file mappings. A merge option would allow us to use watch commands and only merge in current changes.

Similar to what https://www.npmjs.com/package/grunt-hashmap does.

Improve the documentation

The documentation is not complete and could be improved.

Satisfaction criteria

  • Add more examples, especially about the multitask option
  • Document the output option.
  • Link to the webperf talk

Replace output* options by versionsMap* options

From version 0.6.0 it will be possible to dump all the versions either in a json file or in a grunt config variable. To make it possible, it is necessary to change the name of the options so they reflect what they are doing:

  • versionsMapFile will replace output
  • the map of versions wille automatically be saved to a config variable
  • versionsMapTrimPath will replace outputTrimDir
  • Update the documentation
  • Add/Update unit tests

Add a options.timezoneOffset

Previously the date version tag was generated using the actual timezone. In ticket #12 I changed it so it is now the UTC timezone.
I want to provide an option so users can actually set a timezoneOffset in hours.

Satisfaction criteria

  • by default, 0
  • covered by unit tests
  • documented in the README file

file.versionedPath contains backslashes on Windows

Chances are, most use cases will require normalized forward slashes in file.versionedPath since it's mostly used for generating URIs. Any chance you could look into this and either normalize the behavior or add an option to normalize slashes?

E.g. on Windows I get: css/dist\admin.1510b31f.css instead of css/dist/admin.1510b31f.css

OriginalPath in versionFile not src path

Is it intended behaviour that the originalPath parameter isn't the path of the file that has been versioned?
My config:
all: {
files: [{
expand : true,
src : ['src/css/*.css'],
dest : 'build/'
}],
options : {
versionsMapFile: 'versionMapFile.json',
versionsMapTemplate: 'versionMapFileTemplate.json',
skipExisting: true
}
}

My source file style.css is located in src/css directory. After running the versioning with dest parameter set as build/ I get the below output

Below is what is currently outputted:
originalPath: 'build/css/style.css',
versionedPath: 'build//css/style.804a238e.css'

What I was expected was:
originalPath: 'src/css/style.css',
versionedPath: 'build//css/style.804a238e.css'

Is this because I am using the dest parameter? Is there a better config to try? Apologies if this is a silly question I'm quite new to Grunt.

Problems With

I used a combination of your 'images_with_date' and 'images_with_hash' examples to create the listing below but it doesn't actually create the files. It does create a JSON output with the correct information.

png:{
  files:[{
    expand : true,
    cwd    : "public/img/",
    src    : ['**/*.png'],
    dest   : "public/i/"
  }],
  options:{
    use: 'hash',
    output: 'data/cache/versions/png.json',
    outputTrimDir: 'public'
  },
}

I was able to get the task to work when I use the multitask option but not when it's run directly. Is there something I'm missing?

Thanks for writing the task. Your presentation really convinced me to try Grunt.

Fix jshint warnings

The current jshint configuration is far too permissive. Fix it.

Satisfaction criteria

  • Update jshint conf
  • Fix warnings

Readme needs explanation on how to substitue assets link in template

I was reviewing the Readme and I didn't find how to use generated versioned files on my template. For instance what should I do to replace on my index.html file:
<link rel="stylesheet" href="styles/app.css">
<script src="app.js"></script>
with the appropiate asset versioned file? Something like:
<link rel="stylesheet" href="styles/app.min.f4ae3f.css">
<script src="app.271e7f.js"></script>
generated after runing the task

Ramp up the unit tests code coverage

List of the tests to add

task_files_object_format
task_files_array_format
task_expand_format

files_compact_format
files_files_object_format
files_files_array_format

options_hashLength
options_skipExisting_true
options_skipExisting_false
options_output
options_outputTrimDir
options_tag_date
options_tag_hash

fail_missing_src
fail_missing_dest
fail_mix_files_task

Changed API?

I have this in my in my gruntFile.js and it worked fine before updating Node, but now it, not only uses hash instead of date but also skips making assets_versioning.js. Something I'm doing wrong? My apologies in advance if this is not the right place for this.
Here's the part for assets_versioning
assets_versioning: {
options: {
use: 'date',
dateFormat: 'MMDDHHmm',
tasks: ['uglify:min'],
skipExisting: false
},
target: {
expand: true,
options: {
output: 'versioning/assets_versioning.json'
},
},
}
the minified and versioned file is hashed, not dated and the assets_versioning.js doesn't get created.

Thank you,
Aron (a.k.a. chakkimatti)

Versioning of compass output files

I can't seem to get asset versioning running in combination with sass/compass.

Here's my Gruntfile snippet:

// parse sass/compass
compass: {
    dist: {
        options: {
            config: 'src/content/config.rb'
        }
    }
},

// add version to sass/compass output filenames
assets_versioning: {
    dist: {
        options: {
            use: 'date',
            multitask: 'compass'
        }
    }
},

[...]

grunt.registerTask(
    'default', 'watch'
);

I tried the same with javascript concat, which worked fine.
Am I missing something?

Unable to process multiple files

Trying to version multiple files unfortunately I keep having a warning:
Task 'assets_versioning:files' doesn't have any src-dest file mappings.

assets_versioning: {
            options: {
                tag: 'hash',
                hashLength: 6,
                versionsMapFile: './apps/frontend/assets/version.json'
            },
            files: {
                './public_html/css/file1.css' : './public_html/css/file1.css',
                './public_html/css/file2.min.css' : './public_html/css/file2.min.css'
            }
        }

Also tried this approach. But this is giving:
Object # has no method 'indexOf'

 assets_versioning: {
            options: {
                tag: 'hash',
                hashLength: 6,
                versionsMapFile: './apps/frontend/assets/version.json'
            },
            files: [
                {
                    src: './public_html/css/file1.min.css',
                    dest: './public_html/css/file1.min.css',
                },
                {
                    src: './public_html/css/file2.min.css',
                    dest: './public_html/css/file2.min.css',
                }
            ]
        }

Sorry. Missed the target. This is working.

assets_versioning: {
            options: {
                tag: 'hash',
                hashLength: 6,
                versionsMapFile: './apps/frontend/assets/version.json'
            },
            target: {
                files: [
                    {
                        src: './public_html/css/file1.min.css',
                        dest: './public_html/css/file1.min.css',
                    },
                    {
                        src: './public_html/css/file2.min.css',
                        dest: './public_html/css/file2.min.css',
                    }
                ]
            }
        }

Error when running watch with assets-versioning

I have the following grunt configuration:

grunt.initConfig({

    less: { 
        dev: { 
            files:[ {
                expand: true,   
                cwd: 'static/less/',
                src: ['*/master/**/*.less', '*/views/**/*.less'],
                ext: '.css',    
                dest: 'static/csscache/'
            }]
        }
    },

    assets_versioning: {
        options: {
            tag: 'hash',
            hashLength: 32
        },

        css: {
            options: {
                post: true,
                //versionsMapTrimPath: "static/csscache/",
                versionsMapFile : 'staticmap.json',
                versionsMapTemplate: 'json.tpl',
                tasks: ['less:dev']
            }
        }
    },

    watch:{
            less:{
                files: "static/less/**/*.less",
                tasks: ['assets_versioning'],
                options: {
                    nospawn: true
                }
            }
    }
});

When I run "grunt watch" and touches one of the less files, all less files get recompiled and versioned.
However, when I touch one of the less files a second time, I get the following and nothing gets versioned:
"
Running "assets_versioning:css" (assets_versioning) task
Versioning files from less:dev task.
Versioning files from assets_versioning:css task.
Warning: Task 'assets_versioning:css_post_assets_versioning' already exists!
"

Looking at "tasks\helpers\task.js", it seems that when a grunt.config key already exists, it fails in purpose:

Task.prototype.createSurrogate = function (filesObj) {
...
if (grunt.config(surrogateTaskConfigKey)) {
grunt.fail.warn("Task '" + surrogateTask + "' already exists!");
}
...
};

Task.prototype.createPostVersioningTask = function (filesObj) {
...
if (grunt.config(taskConfigKey)) {
grunt.fail.warn("Task '" + postTask + "' already exists!");
}
...
};

Any reason it's done this way?

Improve verbose mode

Debugging an issue reported by an user would be easier if it was possible to get more details using grunt verbose options

Satisfaction criteria

  • Add more feedback using grunt.log.debug
  • Also add more comments

Fix unit tests

The unit tests covering the date hash are not working.

Doesn't work with the Compact format file mapping

Overview

If the original task is using the compact Format file mapping, the destination file doesn't get minified...

Steps to reproduce

module.exports = function(grunt) {
  grunt.initConfig({

assets_versioning: {
    js: {
        options: {
            use: 'hash',
            hashLength: 6,
            multitask: 'concat'
        }
    }
},
concat: {
        js: {
            src: [
            '../front/public/sources/file1.js',
            '../front/public/sources/file2.js'
            ],
            filter: 'isFile',
            dest: '../front/public/built/wdit.js'
        }
    },
});


  grunt.loadNpmTasks('grunt-assets-versioning');
  grunt.loadNpmTasks('grunt-contrib-concat');

  grunt.registerTask('rev', ['assets_versioning']);

  grunt.registerTask('default', ['rev']);
};

then run

grunt assets_versioning:js

Expected

The destination file is created and versioned

Actual

The destination file is created but not versioned

Doesnt do anything

Literally, no output from the task also.

Running "concat:js" (concat) task
File "../front/public/built/wdit.js" created.

Running "assets_versioning:files" (assets_versioning) task

Running "watch" task

    assets_versioning: {
        options: {
            use: 'date'
        },
        files: {
            '../front/public/built/wdit.min.js': ['../front/public/built/wdit.min.js']
        }
    },

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.