source: trip-planner-front/node_modules/license-webpack-plugin/dist/LicenseTextReader.js@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.7 KB
Line 
1"use strict";
2var __values = (this && this.__values) || function(o) {
3 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4 if (m) return m.call(o);
5 if (o && typeof o.length === "number") return {
6 next: function () {
7 if (o && i >= o.length) o = void 0;
8 return { value: o && o[i++], done: !o };
9 }
10 };
11 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.LicenseTextReader = void 0;
15var LicenseTextReader = /** @class */ (function () {
16 function LicenseTextReader(logger, fileSystem, fileOverrides, textOverrides, templateDir, handleMissingLicenseText) {
17 this.logger = logger;
18 this.fileSystem = fileSystem;
19 this.fileOverrides = fileOverrides;
20 this.textOverrides = textOverrides;
21 this.templateDir = templateDir;
22 this.handleMissingLicenseText = handleMissingLicenseText;
23 }
24 LicenseTextReader.prototype.readLicense = function (compilation, module, licenseType) {
25 if (this.textOverrides[module.name]) {
26 return this.textOverrides[module.name];
27 }
28 if (this.fileOverrides[module.name]) {
29 return this.readText(module.directory, this.fileOverrides[module.name]);
30 }
31 if (licenseType && licenseType.indexOf('SEE LICENSE IN ') === 0) {
32 var filename = licenseType.split(' ')[3];
33 return this.fileSystem.isFileInDirectory(filename, module.directory)
34 ? this.readText(module.directory, filename)
35 : null;
36 }
37 var pathsInModuleDirectory = this.fileSystem.listPaths(module.directory);
38 var guessedLicenseFilename = this.guessLicenseFilename(pathsInModuleDirectory, module.directory);
39 if (guessedLicenseFilename !== null) {
40 return this.readText(module.directory, guessedLicenseFilename);
41 }
42 if (this.templateDir) {
43 var templateFilename = licenseType + ".txt";
44 var templateFilePath = this.fileSystem.join(this.templateDir, templateFilename);
45 if (this.fileSystem.isFileInDirectory(templateFilePath, this.templateDir)) {
46 return this.fileSystem
47 .readFileAsUtf8(templateFilePath)
48 .replace(/\r\n/g, '\n');
49 }
50 }
51 this.logger.warn(compilation, "could not find any license file for " + module.name + ". Use the licenseTextOverrides option to add the license text if desired.");
52 return this.handleMissingLicenseText(module.name, licenseType);
53 };
54 LicenseTextReader.prototype.readText = function (directory, filename) {
55 return this.fileSystem
56 .readFileAsUtf8(this.fileSystem.join(directory, filename))
57 .replace(/\r\n/g, '\n');
58 };
59 LicenseTextReader.prototype.guessLicenseFilename = function (paths, modulePath) {
60 var e_1, _a;
61 try {
62 for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
63 var path = paths_1_1.value;
64 var filePath = this.fileSystem.join(modulePath, path);
65 if (/^licen[cs]e/i.test(path) && !this.fileSystem.isDirectory(filePath)) {
66 return path;
67 }
68 }
69 }
70 catch (e_1_1) { e_1 = { error: e_1_1 }; }
71 finally {
72 try {
73 if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
74 }
75 finally { if (e_1) throw e_1.error; }
76 }
77 return null;
78 };
79 return LicenseTextReader;
80}());
81exports.LicenseTextReader = LicenseTextReader;
Note: See TracBrowser for help on using the repository browser.