info.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. module.exports = exports = info;
  3. exports.usage = 'Lists all published binaries (requires aws-sdk)';
  4. const log = require('npmlog');
  5. const versioning = require('./util/versioning.js');
  6. const s3_setup = require('./util/s3_setup.js');
  7. function info(gyp, argv, callback) {
  8. const package_json = gyp.package_json;
  9. const opts = versioning.evaluate(package_json, gyp.opts);
  10. const config = {};
  11. s3_setup.detect(opts, config);
  12. const s3 = s3_setup.get_s3(config);
  13. const s3_opts = {
  14. Bucket: config.bucket,
  15. Prefix: config.prefix
  16. };
  17. s3.listObjects(s3_opts, (err, meta) => {
  18. if (err && err.code === 'NotFound') {
  19. return callback(new Error('[' + package_json.name + '] Not found: https://' + s3_opts.Bucket + '.s3.amazonaws.com/' + config.prefix));
  20. } else if (err) {
  21. return callback(err);
  22. } else {
  23. log.verbose(JSON.stringify(meta, null, 1));
  24. if (meta && meta.Contents) {
  25. meta.Contents.forEach((obj) => {
  26. console.log(obj.Key);
  27. });
  28. } else {
  29. console.error('[' + package_json.name + '] No objects found at https://' + s3_opts.Bucket + '.s3.amazonaws.com/' + config.prefix);
  30. }
  31. return callback();
  32. }
  33. });
  34. }