a zip code crypto-currency system good for red ONLY

DescriptionFilePlugin.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. /*
  3. MIT License http://www.opensource.org/licenses/mit-license.php
  4. Author Tobias Koppers @sokra
  5. */
  6. const createInnerCallback = require("./createInnerCallback");
  7. const DescriptionFileUtils = require("./DescriptionFileUtils");
  8. class DescriptionFilePlugin {
  9. constructor(source, filenames, target) {
  10. this.source = source;
  11. this.filenames = [].concat(filenames);
  12. this.target = target;
  13. }
  14. apply(resolver) {
  15. const filenames = this.filenames;
  16. const target = this.target;
  17. resolver.plugin(this.source, (request, callback) => {
  18. const directory = request.path;
  19. DescriptionFileUtils.loadDescriptionFile(resolver, directory, filenames, ((err, result) => {
  20. if(err) return callback(err);
  21. if(!result) {
  22. if(callback.missing) {
  23. filenames.forEach((filename) => {
  24. callback.missing.push(resolver.join(directory, filename));
  25. });
  26. }
  27. if(callback.log) callback.log("No description file found");
  28. return callback();
  29. }
  30. const relativePath = "." + request.path.substr(result.directory.length).replace(/\\/g, "/");
  31. const obj = Object.assign({}, request, {
  32. descriptionFilePath: result.path,
  33. descriptionFileData: result.content,
  34. descriptionFileRoot: result.directory,
  35. relativePath: relativePath
  36. });
  37. resolver.doResolve(target, obj, "using description file: " + result.path + " (relative path: " + relativePath + ")", createInnerCallback((err, result) => {
  38. if(err) return callback(err);
  39. if(result) return callback(null, result);
  40. // Don't allow other description files or none at all
  41. callback(null, null);
  42. }, callback));
  43. }));
  44. });
  45. }
  46. }
  47. module.exports = DescriptionFilePlugin;