nfriedly / node-bestzip

Provides a `bestzip` command that uses the system `zip` if avaliable, and a Node.js implimentation otherwise.
MIT License
80 stars 16 forks source link

How can I add timestamp to my zipped file name #26

Open iwangbowen opened 5 years ago

iwangbowen commented 5 years ago

I use this library as one of my npm scripts. Any suggestions on how I can add timestamp to the zipped file.

nfriedly commented 5 years ago

If you're only using bash, then backticks and the date command might work:

{
  "scripts": "bestzip `date`.zip build/"
}

(Backticks execute the command and then replace it with it's output in bash.)

Alternatively, you can write your own script using the programmatic api and do something like (new Date()).toString() + '.zip' for the destination.

AdrianoCahete commented 5 years ago

Isn't easy to make a new feature for this tool to add the date on file?

I'm running on Windows, but my builds machines are unix and windows. Will be way easier if the tool do this by itself.

Please, consider this idea.

nfriedly commented 5 years ago

I don't think that feature makes sense in the library - there's too many potential output formats for one thing. But you can write a very simple script that does exactly what you need. Something like this should work on windows and unix:

#!/usr/bin/env node

var zip = require('bestzip');

var dest = new Date()).toString() + '.zip' ;

zip({ 
  source: 'build/*', 
  destination: dest,
}).then(() => {
  console.log(`saved to ${dest}`)
});
AdrianoCahete commented 5 years ago

there's too many potential output formats

To be honest, the only output acceptable as default (or for a first interaction) is to use ISO 8601.

But works with that script, thanks!