twolfson / grunt-zip

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

Unneccesary files #51

Closed AliOsseili closed 6 years ago

AliOsseili commented 6 years ago

Fixed the issue here: https://github.com/twolfson/grunt-zip/issues/50 by using the routers skipping files option, but now when I open my zip it has too many unnecessary folders, here is what it should look like: enhancedfeedleft-win32-x64(time).zip

here is what it actually looks like

enhancedFeedLeft-win32-x64(time).zip -build -enhancedfeedleft...

any ideas on how to fix that, here is what my grunt zip task looks like:

'zip': { 'skip-files': { router: function (filepath) { var extname = path.extname(filepath) if (extname === '.zip') { return null; } else { return 'build/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '/'+filepath; } }, src: ['build/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '/**'], dest: 'BuildZip/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '-' + TimeNow + '.zip' } }

twolfson commented 6 years ago

I think filepath is the full filepath so you're doubly nesting the filepath. Try out:

'zip': {
'skip-files': {
router: function (filepath) {
var extname = path.extname(filepath)
if (extname === '.zip') {
return null;
} else {
return filepath;
}
},
src: ['build/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '/**'],
dest: 'BuildZip/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '-' + TimeNow + '.zip'
}
}
AliOsseili commented 6 years ago

now its nesting it once, is there a way to avoid doing that? I just want the zip to contain what I want zipped instead of having:

electronfeedleft.... .zip -build -electronfeedleft

I'd like

electronfeedleft.... .zip -all that I wwant zipped

twolfson commented 6 years ago

Ahhh, I understand. Yea, using path.basename we can extract the root filename:

https://nodejs.org/api/path.html#path_path_basename_path_ext

'zip': {
'skip-files': {
router: function (filepath) {
var extname = path.extname(filepath)
if (extname === '.zip') {
return null;
} else {
return path.basename(filepath);
}
},
src: ['build/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '/**'],
dest: 'BuildZip/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '-' + TimeNow + '.zip'
}
}
AliOsseili commented 6 years ago

When I tried that it gave me even more files lol: What it should look like

whatiwant

what it actually does

whatidontwant
twolfson commented 6 years ago

I think your glob pattern is off. Try **/* instead of **:

'zip': {
'skip-files': {
router: function (filepath) {
var extname = path.extname(filepath)
if (extname === '.zip') {
return null;
} else {
return path.basename(filepath);
}
},
src: ['build/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '/**/*'],
dest: 'BuildZip/enhancedFeedLeft' + '-' + os_platform + '-' + arch_model + '-' + TimeNow + '.zip'
}
}