makecjs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env node
  2. const header = `
  3. //
  4. // THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT BY HAND!
  5. //
  6. ;(function(global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined'
  8. ? module.exports = factory()
  9. : typeof define === 'function' && define.amd
  10. ? define(factory) :
  11. // cf. https://github.com/dankogai/js-base64/issues/119
  12. (function() {
  13. // existing version for noConflict()
  14. const _Base64 = global.Base64;
  15. const gBase64 = factory();
  16. gBase64.noConflict = () => {
  17. global.Base64 = _Base64;
  18. return gBase64;
  19. };
  20. if (global.Meteor) { // Meteor.js
  21. Base64 = gBase64;
  22. }
  23. global.Base64 = gBase64;
  24. })();
  25. }((typeof self !== 'undefined' ? self
  26. : typeof window !== 'undefined' ? window
  27. : typeof global !== 'undefined' ? global
  28. : this
  29. ), function() {
  30. 'use strict';
  31. `;
  32. const footer = `
  33. //
  34. // export Base64 to the namespace
  35. //
  36. // ES5 is yet to have Object.assign() that may make transpilers unhappy.
  37. // gBase64.Base64 = Object.assign({}, gBase64);
  38. gBase64.Base64 = {};
  39. Object.keys(gBase64).forEach(k => gBase64.Base64[k] = gBase64[k]);
  40. return gBase64;
  41. }));
  42. `;
  43. require('fs').readFile(process.argv[2], 'utf8', (err, data) => {
  44. if (err) {
  45. return console.log(err);
  46. }
  47. const body = data.replace(/\n\/\/ makecjs:CUT \/\/.+$/s, '');
  48. console.log(`
  49. ${header}
  50. ${body}
  51. ${footer}
  52. `);
  53. });