twolfson / grunt-zip

Zip and unzip files via a grunt plugin
MIT License
87 stars 19 forks source link

Router not working with multiple zip tasks #47

Closed r14n closed 6 years ago

r14n commented 6 years ago

I have a custom router to exclude files, but I can't seem to get it to work properly with multiple zip tasks:


      zip: {
            zipChrome: {
                src: ['**'],
                dest: '../emoji-input-old-versions/' + manifestVersionNumber + '-chrome.zip',
                'skip-files': {
                    // Skip over excluded
                    router: function(filepath) {
                        var excluded = ['Gruntfile.js', '.DS_Store', '.git', 'package.json', 'package-lock.json', 'node_modules', 'firefox'];

                        for (var i = 0; i < excluded.length; i++) {

                            if (filepath.indexOf(excluded[i]) > -1) {
                                console.log('Excluded: ' + filepath);
                                return null;
                            }

                        }

                        return filepath;
                    },
                }
            },
            zipFirefox: {
                src: ['**'],
                dest: '../emoji-input-old-versions/' + manifestVersionNumber + '-firefox.zip'
            }
        }

the two zips generated are identical (apart from filename)

it works fine when there is just one task

twolfson commented 6 years ago

router must be specified at the same level of src/dest and in each of the tasks itself. The following should work:

// As its own function
function zipRouter(filepath) {
    var excluded = ['Gruntfile.js', '.DS_Store', '.git', 'package.json', 'package-lock.json', 'node_modules', 'firefox'];

    for (var i = 0; i < excluded.length; i++) {

        if (filepath.indexOf(excluded[i]) > -1) {
            console.log('Excluded: ' + filepath);
            return null;
        }

    }

    return filepath;
}

// Inside `grunt.initConfig()`
      zip: {
            zipChrome: {
                src: ['**'],
                dest: '../emoji-input-old-versions/' + manifestVersionNumber + '-chrome.zip',
                router: zipRouter
            },
            zipFirefox: {
                src: ['**'],
                dest: '../emoji-input-old-versions/' + manifestVersionNumber + '-firefox.zip',
                router: zipRouter
            }
        }
r14n commented 6 years ago

thank you!