UNPKG

@frontitude/cli

Version:

The Frontitude CLI enables product teams to integrate their code with Frontitude (frontitude.com), thus creating a single source of truth for their product copy, from design to development.

1 lines 3.28 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.pullProjectsTextsIntoCodebase=exports.getXliffVersion=exports.setXliffVersion=exports.getIsLibraryConnected=exports.setIsLibraryConnected=exports.getConnectedProjects=exports.setConnectedProjects=exports.isOutputFileTypeSupported=void 0;const tslib_1=require("tslib"),lodash_merge_1=tslib_1.__importDefault(require("lodash.merge")),config=tslib_1.__importStar(require("../../common/config")),ErrorNames=tslib_1.__importStar(require("../../common/constants/ErrorNames")),projects_1=require("../projects"),workspace_1=require("../workspace"),files_1=require("../../utils/files"),stringsFileHandler=tslib_1.__importStar(require("./stringsFileHandler")),constants_1=require("../constants"),SUPPORTED_FILE_TYPES=stringsFileHandler.getSupportedFileTypes(),isOutputFileTypeSupported=e=>{if(!e)return!1;const{fileType:t,fileNameWithoutExtension:s}=(0,files_1.getFileDetails)(e);return s&&-1!==SUPPORTED_FILE_TYPES.indexOf(t)};exports.isOutputFileTypeSupported=isOutputFileTypeSupported;const setConnectedProjects=async e=>{config.local.set("projects",e)};exports.setConnectedProjects=setConnectedProjects;const getConnectedProjects=async()=>config.local.get("projects")||[];exports.getConnectedProjects=getConnectedProjects;const setIsLibraryConnected=async e=>{config.local.set("library",e)};exports.setIsLibraryConnected=setIsLibraryConnected;const getIsLibraryConnected=async()=>config.local.get("library")||!1;exports.getIsLibraryConnected=getIsLibraryConnected;const setXliffVersion=async e=>{config.local.set("xliffVersion",e)};exports.setXliffVersion=setXliffVersion;const getXliffVersion=async()=>config.local.get("xliffVersion")||constants_1.XliffVersions.xliff_1_2;exports.getXliffVersion=getXliffVersion;const convertTagNamesToIdsAndCheckAllExist=async e=>{const t=await(0,workspace_1.mapWorkspaceTagNamesToIds)(e),s=Object.keys(t),r=e.filter((e=>!s.includes(e)));if(r.length>0){const e=new Error(r.join(", "));throw e.name=ErrorNames.TAGS_NOT_EXIST_IN_WORKSPACE,e}return Object.values(t)},pullProjectsTextsIntoCodebase=async(e,t=!1)=>{const s=await(0,exports.getIsLibraryConnected)(),r=await(0,exports.getConnectedProjects)();if(!s&&0===r.length){const e=new Error("missing sources in config");throw e.name=ErrorNames.NO_CONFIGURED_SOURCES,e}const o=config.local.get("filePath");if(!o&&!t){const e=new Error("missing output file in config");throw e.name=ErrorNames.NO_CONFIGURED_OUTPUT_FILE,e}const{tagNames:n}=e;if(n&&n.length>0){const t=await convertTagNamesToIdsAndCheckAllExist(n);e.tagIds=t}const i=r.map((({id:e})=>e)),a=stringsFileHandler.extendTextsPullOptions(o,e),c=i.length>0?await(0,projects_1.pullProjectsTexts)(i,a):{},l=s?await(0,workspace_1.pullCopyLibrary)(a):{},p=(0,lodash_merge_1.default)(c,l),g=await stringsFileHandler.formatTextsForOutputFileType(o,p),f=await(0,workspace_1.getSourceLanguageLocaleId)();if(f&&g[f]&&(g.source=g[f],delete g[f]),t){return await stringsFileHandler.getDryRunResult(o,g)}const u=(0,files_1.getFileDetails)(o),d={};for(const e of Object.keys(g)){const t=(0,files_1.getTargetLanguageFilePath)(o,u,e);d[t]=await stringsFileHandler.updateFileWithData(t,g[e],e,g.source,f)}return d};exports.pullProjectsTextsIntoCodebase=pullProjectsTextsIntoCodebase;