Guest User

Untitled

a guest
Feb 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. const { resolve, dirname } = require('path');
  2.  
  3. module.exports = function (file, api) {
  4. const j = api.jscodeshift;
  5. const root = j(file.source);
  6. let fileDir = dirname(resolve(file.path));
  7.  
  8. function update (path) {
  9. const argument = path.value.arguments[0].value;
  10. if (argument.indexOf('..') !== 0) return;
  11.  
  12. const realPath = resolve(fileDir, argument);
  13. if (realPath.indexOf('cartodb3') === -1) return;
  14.  
  15. const aliasPath = realPath.replace(/(.+)(cartodb3\/.+)/g, '$2');
  16.  
  17. path.value.arguments[0].value = aliasPath;
  18. }
  19.  
  20. root.find(j.CallExpression, { callee: { name: 'require' } })
  21. .forEach(update);
  22.  
  23. return root.toSource({quote: 'single'});
  24. };
Add Comment
Please, Sign In to add comment