transform-file.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.transformFileAsync = exports.transformFileSync = exports.transformFile = void 0;
  6. function _gensync() {
  7. const data = _interopRequireDefault(require("gensync"));
  8. _gensync = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _config = _interopRequireDefault(require("./config"));
  14. var _transformation = require("./transformation");
  15. var fs = _interopRequireWildcard(require("./gensync-utils/fs"));
  16. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  17. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  18. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  19. ({});
  20. const transformFileRunner = (0, _gensync().default)(function* (filename, opts) {
  21. const options = Object.assign({}, opts, {
  22. filename
  23. });
  24. const config = yield* (0, _config.default)(options);
  25. if (config === null) return null;
  26. const code = yield* fs.readFile(filename, "utf8");
  27. return yield* (0, _transformation.run)(config, code);
  28. });
  29. const transformFile = transformFileRunner.errback;
  30. exports.transformFile = transformFile;
  31. const transformFileSync = transformFileRunner.sync;
  32. exports.transformFileSync = transformFileSync;
  33. const transformFileAsync = transformFileRunner.async;
  34. exports.transformFileAsync = transformFileAsync;