UNPKG

2.1 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getLicenseFiles = exports.getNotLocalizedLicenseFile = exports.getLicenseAssets = void 0;
4const path = require("path");
5const langs_1 = require("./langs");
6function getLicenseAssets(fileNames, packager) {
7 return fileNames
8 .sort((a, b) => {
9 const aW = a.includes("_en") ? 0 : 100;
10 const bW = b.includes("_en") ? 0 : 100;
11 return aW === bW ? a.localeCompare(b) : aW - bW;
12 })
13 .map(file => {
14 let lang = /_([^.]+)\./.exec(file)[1];
15 let langWithRegion;
16 if (lang.includes("_")) {
17 langWithRegion = lang;
18 lang = langWithRegion.substring(0, lang.indexOf("_"));
19 }
20 else {
21 lang = lang.toLowerCase();
22 langWithRegion = (0, langs_1.toLangWithRegion)(lang);
23 }
24 return { file: path.join(packager.buildResourcesDir, file), lang, langWithRegion, langName: langs_1.langIdToName[lang] };
25 });
26}
27exports.getLicenseAssets = getLicenseAssets;
28async function getNotLocalizedLicenseFile(custom, packager, supportedExtension = ["rtf", "txt", "html"]) {
29 const possibleFiles = [];
30 for (const name of ["license", "eula"]) {
31 for (const ext of supportedExtension) {
32 possibleFiles.push(`${name}.${ext}`);
33 possibleFiles.push(`${name.toUpperCase()}.${ext}`);
34 possibleFiles.push(`${name}.${ext.toUpperCase()}`);
35 possibleFiles.push(`${name.toUpperCase()}.${ext.toUpperCase()}`);
36 }
37 }
38 return await packager.getResource(custom, ...possibleFiles);
39}
40exports.getNotLocalizedLicenseFile = getNotLocalizedLicenseFile;
41async function getLicenseFiles(packager) {
42 return getLicenseAssets((await packager.resourceList).filter(it => {
43 const name = it.toLowerCase();
44 return (name.startsWith("license_") || name.startsWith("eula_")) && (name.endsWith(".rtf") || name.endsWith(".txt") || name.endsWith(".html"));
45 }), packager);
46}
47exports.getLicenseFiles = getLicenseFiles;
48//# sourceMappingURL=license.js.map
\No newline at end of file