a zip code crypto-currency system good for red ONLY

LibManifestPlugin.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const path = require("path");
  7. const asyncLib = require("async");
  8. class LibManifestPlugin {
  9. constructor(options) {
  10. this.options = options;
  11. }
  12. apply(compiler) {
  13. compiler.plugin("emit", (compilation, callback) => {
  14. asyncLib.forEach(compilation.chunks, (chunk, callback) => {
  15. if(!chunk.isInitial()) {
  16. callback();
  17. return;
  18. }
  19. const targetPath = compilation.getPath(this.options.path, {
  20. hash: compilation.hash,
  21. chunk
  22. });
  23. const name = this.options.name && compilation.getPath(this.options.name, {
  24. hash: compilation.hash,
  25. chunk
  26. });
  27. const manifest = {
  28. name,
  29. type: this.options.type,
  30. content: chunk.mapModules(module => {
  31. if(module.libIdent) {
  32. const ident = module.libIdent({
  33. context: this.options.context || compiler.options.context
  34. });
  35. if(ident) {
  36. return {
  37. ident,
  38. data: {
  39. id: module.id,
  40. meta: module.meta,
  41. exports: Array.isArray(module.providedExports) ? module.providedExports : undefined
  42. }
  43. };
  44. }
  45. }
  46. }).filter(Boolean).reduce((obj, item) => {
  47. obj[item.ident] = item.data;
  48. return obj;
  49. }, Object.create(null))
  50. };
  51. const content = new Buffer(JSON.stringify(manifest), "utf8"); //eslint-disable-line
  52. compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => {
  53. if(err) return callback(err);
  54. compiler.outputFileSystem.writeFile(targetPath, content, callback);
  55. });
  56. }, callback);
  57. });
  58. }
  59. }
  60. module.exports = LibManifestPlugin;