How can I compress my source folder while excluding the root directory?

417 views Asked by At

I'm using grunt-contrib-compress to zip up my deployment package. I have the following config:

//  Zip up the distribution folder and give it a build name. The folder can then be uploaded to the Chrome Web Store.
grunt.registerTask('compress-extension', 'compress the files which are ready to be uploaded to the Chrome Web Store into a .zip', function () {

    //  There's no need to cleanup any old version because this will overwrite if it exists.
    grunt.config.set('compress', {
        dist: {
            options: {
                archive: 'Streamus v' + grunt.option('version') + '.zip'
            },
            files: [{
                src: ['dist/**'],
                dest: '',
            }]
        }
    });

    grunt.task.run('compress');
});

This results in one additional level of directory structure which I would like to avoid. After zipping, the structure looks like:

'Streamus v0.xxx.zip' -> 'dist' -> '[sub directories]'

and I'm hoping for just:

'Streamus v0.xxx.zip' -> '[sub directories]'

What's the simplest way to go about doing this? Can I just express that desire in the "files" configuration section of compress? Maybe with a flatten?

1

There are 1 answers

0
Sean Anderson On

Oh, I see. If you set "cwd" to the folder you want to exclude and then your "src" to take into account your new cwd, it works as desired:

//  Zip up the distribution folder and give it a build name. The folder can then be uploaded to the Chrome Web Store.
grunt.registerTask('compress-extension', 'compress the files which are ready to be uploaded to the Chrome Web Store into a .zip', function () {

    //  There's no need to cleanup any old version because this will overwrite if it exists.
    grunt.config.set('compress', {
        dist: {
            options: {
                archive: 'Streamus v' + grunt.option('version') + '.zip'
            },
            files: [{
                src: ['**'],
                dest: '',
                cwd: 'dist/',
                expand: true
            }]
        }
    });

    grunt.task.run('compress');
});