index.js 717 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. var through = require('through2');
  3. var normalizePath = require('normalize-path');
  4. var generate = require('./lib/generate');
  5. function identityMap() {
  6. function transform(file, _, cb) {
  7. if (!file.sourceMap || !file.isBuffer()) {
  8. return cb(null, file);
  9. }
  10. var sourcePath = normalizePath(file.relative);
  11. var contents = file.contents.toString();
  12. switch (file.extname) {
  13. case '.js': {
  14. file.sourceMap = generate.js(sourcePath, contents);
  15. break;
  16. }
  17. case '.css': {
  18. file.sourceMap = generate.css(sourcePath, contents);
  19. break;
  20. }
  21. }
  22. cb(null, file);
  23. }
  24. return through.obj(transform);
  25. }
  26. module.exports = identityMap;