UNPKG

@nativescript-community/l

Version:

Native internationalization plugin for NativeScript using native capabilities of each platform

60 lines 2.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConverterCommon = void 0; var fs = require("fs"); var mkdirp = require("mkdirp"); var path = require("path"); var ConverterCommon = (function () { function ConverterCommon(dataProvider, logger, platformData, projectData) { this.dataProvider = dataProvider; this.logger = logger; this.platformData = platformData; this.projectData = projectData; this.appResourcesDirectoryPath = path.join(projectData.appResourcesDirectoryPath, platformData.normalizedPlatformName); this.appResourcesDestinationDirectoryPath = platformData.platformProjectService.getAppResourcesDestinationDirectoryPath(projectData); this.i18nDirectoryPath = path.join(projectData.appDirectoryPath, 'i18n'); } ConverterCommon.prototype.run = function () { var _this = this; this.dataProvider.getLanguages().forEach(function (languageI18nEntries, language) { _this.createLanguageResourcesFiles(language, language === _this.dataProvider.getDefaultLanguage(), languageI18nEntries); }); if (fs.existsSync(this.appResourcesDirectoryPath) && fs.statSync(this.appResourcesDirectoryPath).isDirectory()) { this.cleanObsoleteResourcesFiles(this.appResourcesDirectoryPath, this.dataProvider.getLanguages()); } return this; }; ConverterCommon.prototype.createDirectoryIfNeeded = function (directoryPath) { if (!fs.existsSync(directoryPath) || !fs.statSync(directoryPath).isDirectory()) { mkdirp.sync(directoryPath); } return this; }; ConverterCommon.prototype.removeDirectoryIfEmpty = function (directoryPath) { try { fs.rmdirSync(directoryPath); } catch (error) { } return this; }; ConverterCommon.prototype.removeFileIfExists = function (filePath) { try { fs.unlinkSync(filePath); } catch (error) { } return this; }; ConverterCommon.prototype.writeFileSyncIfNeeded = function (filePath, content) { try { if (content === fs.readFileSync(filePath, 'utf8')) { return this; } } catch (error) { } fs.writeFileSync(filePath, content, { encoding: 'utf8' }); return this; }; return ConverterCommon; }()); exports.ConverterCommon = ConverterCommon; //# sourceMappingURL=converter.common.js.map