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

node environment cannot use /* #23

Closed Sobranier closed 5 years ago

Sobranier commented 5 years ago

when i use this below directorily, it works fine

2018-09-04 5 38 19

but when i use it in an node file, it crashed

2018-09-04 5 38 13

v1.4.X works v2.0.0 crashed

nfriedly commented 5 years ago

Can you show me your code?

Sobranier commented 5 years ago

const zip = require('bestzip'); const files = [{ source: './build/ios/', target: './build/zip/ios-bundle' }, { source: './build/android/', target: './build/zip/android-bundle' }]; files.forEach(function(item) { zip(item.target, [item.source], function(err) {

 ...

}) })

nfriedly commented 5 years ago

Ok, I think this may be related to the CWD change from 1.x to 2.x (which was the main breaking change).

What directory are you in when you start the node.js command? Are you in the same directory as where the build/ folder is?

I'm going to see if I can add a way to configure the cwd, at least for programmatic usage.

nfriedly commented 5 years ago

Ok, I just pushed some changes, it should be released in v2.1 once CI completes.

I had to change the API to support an options object, so I took this as a good opportunity to move the whole thing to be promise-based (mainly for easier usage with async / await).

(The old API still exists for backwards-compatibility, but doesn't have any to specify the cwd.)

You'll need to do something like this in your code:

const zip = require('bestzip');
const path = require('path');

const files = [{
  cwd: path.join(__dirname, '../build/ios/'), // change this line if necessary
  source: './',
  destination: '../zip/ios-bundle' // note: key changed from 'target' to 'destination'.
}, {
  cwd: path.join(__dirname, '../build/android/'), // ditto
  source: './',
  destination: '../zip/android-bundle' // ditto
}];
files.forEach(function(item) {
  zip(item).then(function() {
    //...
  }).catch(function(err) {
    //...
  });
});
nfriedly commented 5 years ago

Hey, just a quick followup: v2.1.0 had a bug on windows; I just pushed 2.1.1 with the fix.