gulp-remapPaths.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. var through = require('through2');
  3. var PluginError = require('plugin-error');
  4. function modifyPath(str, opts) {
  5. // opts = opts || {};
  6. // str += "";
  7. // // Start process by extracting all lines.
  8. // let lines = str.split('\n');
  9. // // Let's go line by line and replace the imports sources by their resolved locations
  10. // for (let index = 0; index < lines.length; index++) {
  11. // let line = lines[index];
  12. // // Replace Static Readonly declaration for Legacy TS Version compat
  13. // var regexVar = /(.*)import .*"(.*)";/g;
  14. // var match = regexVar.exec(line);
  15. // if (!match) {
  16. // continue;
  17. // }
  18. // // Extract the typescript node based import location
  19. // const location = match[2];
  20. // const newLocation = location;
  21. // // Adds file relative path
  22. // if (!location.startsWith(".")) {
  23. // }
  24. // // Adds Extension
  25. // // Replace the location by the new one
  26. // line = line.replace('"' + location + '"', '"' + newLocation + '"');
  27. // lines[index] = line;
  28. // }
  29. // // Recreate the file.
  30. // str = lines.join('\n');
  31. return Date.now() + str;
  32. }
  33. function main(options, func) {
  34. return through.obj(function (file, enc, cb) {
  35. if (file.isNull()) {
  36. cb(null, file);
  37. return;
  38. }
  39. if (file.isStream()) {
  40. cb(new PluginError("Modify Import Paths", "Streaming not supported."));
  41. }
  42. file.contents = Buffer.from(func(file.contents.toString(), options));
  43. this.push(file);
  44. return cb();
  45. });
  46. }
  47. function gulpModifyPath(options) {
  48. return main(options, modifyPath);
  49. }
  50. module.exports = gulpModifyPath;