78 lines
4.2 KiB
JavaScript
78 lines
4.2 KiB
JavaScript
|
"use strict";
|
||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
|
});
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.convert = void 0;
|
||
|
const fs = require("fs");
|
||
|
const path = require("path");
|
||
|
const converter_1 = require("./converter");
|
||
|
const constants_1 = require("./constants");
|
||
|
const utilities_1 = require("./utilities");
|
||
|
function initialize() {
|
||
|
utilities_1.Utilities.setUpOSFAppTelemetry();
|
||
|
}
|
||
|
function convert(inputXmlFilePath_1, outputJsonFolderPath_1) {
|
||
|
return __awaiter(this, arguments, void 0, function* (inputXmlFilePath, outputJsonFolderPath, imageDownload = false, verbose = false) {
|
||
|
initialize();
|
||
|
utilities_1.Utilities.setInputXmlFilePath(inputXmlFilePath);
|
||
|
if (utilities_1.Utilities.isNullOrUndefined(imageDownload)) {
|
||
|
imageDownload = false;
|
||
|
}
|
||
|
utilities_1.Utilities.setDownloadImages(imageDownload);
|
||
|
var imageUrls = true;
|
||
|
if (utilities_1.Utilities.isNullOrUndefined(imageUrls)) {
|
||
|
imageUrls = false;
|
||
|
}
|
||
|
utilities_1.Utilities.setWriteImageUrls(imageUrls);
|
||
|
if (utilities_1.Utilities.isNullOrUndefined(verbose)) {
|
||
|
verbose = false;
|
||
|
}
|
||
|
utilities_1.Utilities.setVerbosity(verbose);
|
||
|
const inputXml = fs.readFileSync(inputXmlFilePath, 'utf8');
|
||
|
let basename = path.basename(inputXmlFilePath);
|
||
|
if (path.extname(basename).toLowerCase() === '.xml') {
|
||
|
basename = basename.slice(0, -4);
|
||
|
}
|
||
|
let outputFolder = outputJsonFolderPath;
|
||
|
if (utilities_1.Utilities.isNullOrUndefined(outputFolder) || outputFolder.trim().length == 0) {
|
||
|
outputFolder = path.dirname(inputXmlFilePath) + '/' + basename;
|
||
|
}
|
||
|
utilities_1.Utilities.ensureFolder(outputFolder);
|
||
|
const converter = new converter_1.Converter(inputXml, 'en-US');
|
||
|
yield converter.convert();
|
||
|
yield converter.downloadAndStoreIcons(outputFolder);
|
||
|
yield writeMainManifestFile(converter, outputFolder);
|
||
|
yield writeLocaleFiles(converter, outputFolder);
|
||
|
});
|
||
|
}
|
||
|
exports.convert = convert;
|
||
|
function writeMainManifestFile(converter, outputJSONFolderPath) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
const manifestFilePath = outputJSONFolderPath + "/" + constants_1.Constants.JSONManifestFileName;
|
||
|
utilities_1.Utilities.log("manifest file path: " + manifestFilePath);
|
||
|
const jsonResult = converter.getJSON();
|
||
|
yield utilities_1.Utilities.writeFile(manifestFilePath, JSON.stringify(jsonResult, null, 4), 'Error writing file', 'Successfully wrote file: ' + manifestFilePath);
|
||
|
});
|
||
|
}
|
||
|
function writeLocaleFiles(converter, outputJSONPath) {
|
||
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
||
|
let locales = converter.getLocaleBuilder().getLocales();
|
||
|
let promises = [];
|
||
|
utilities_1.Utilities.log("locales seen by legacy parser: " + locales);
|
||
|
for (let i = 0; i < locales.length; i++) {
|
||
|
let locale = locales[i];
|
||
|
let localeFilePath = outputJSONPath + "/" + utilities_1.Utilities.createLocaleFileName(locale);
|
||
|
utilities_1.Utilities.log("locale file path: " + localeFilePath);
|
||
|
promises.push(utilities_1.Utilities.writeFile(localeFilePath, JSON.stringify(converter.getLocaleBuilder().getLocaleFileResources(locale), null, 4), 'Error writing file', 'Successfully wrote file: ' + localeFilePath));
|
||
|
}
|
||
|
yield utilities_1.Utilities.promiseAll(promises, resolve, reject, "writeLocalFiles:Failed");
|
||
|
}));
|
||
|
}
|
||
|
//# sourceMappingURL=main.js.map
|