create-temp-licenses.js 1023 B

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. const fs = require("fs-extra");
  3. const path = require("path");
  4. const pMap = require("p-map");
  5. module.exports.createTempLicenses = createTempLicenses;
  6. /**
  7. * Create temporary license files.
  8. * @param {string} srcLicensePath
  9. * @param {Packages[]} packagesToBeLicensed
  10. */
  11. function createTempLicenses(srcLicensePath, packagesToBeLicensed) {
  12. if (!srcLicensePath || !packagesToBeLicensed.length) {
  13. return Promise.resolve();
  14. }
  15. // license file might have an extension, so let's allow it
  16. const licenseFileName = path.basename(srcLicensePath);
  17. const options = {
  18. // make an effort to keep package contents stable over time
  19. preserveTimestamps: process.arch !== "ia32",
  20. // (give up on 32-bit architecture to avoid fs-extra warning)
  21. };
  22. // store target path for removal later
  23. packagesToBeLicensed.forEach((pkg) => {
  24. pkg.licensePath = path.join(pkg.contents, licenseFileName);
  25. });
  26. return pMap(packagesToBeLicensed, (pkg) => fs.copy(srcLicensePath, pkg.licensePath, options));
  27. }