@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 • 1.58 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.getDryRunResult=exports.getFileDiff=exports.updateFileWithData=exports.getDataAndFileCombinedResult=void 0;const files_1=require("../../../../utils/files"),i18nStringsFiles=require("i18n-strings-files"),replaceVariablesInString=e=>e.replace(/{{\s*[\w]+\s*}}/g,"%@"),processFrontitudeData=e=>Object.keys(e).reduce(((t,s)=>{const i=e[s];return t[s]={...i,text:replaceVariablesInString(i.text)},t}),{}),readFileAsJson=async e=>{if(!e||!(0,files_1.isPathOrFileExists)(e))return{};return i18nStringsFiles.readFileSync(e,{wantsComments:!0})},getDataAndFileCombinedResult=async(e,t)=>{const s=await readFileAsJson(e),i=processFrontitudeData(t),n={...s,...i};return Object.keys(n).reduce(((e,t)=>{const i=s[t]&&s[t].comment;return e[t]=i?{...n[t],comment:s[t].comment}:n[t],e}),{})};exports.getDataAndFileCombinedResult=getDataAndFileCombinedResult;const updateFileWithData=async(e,t)=>{const s=await readFileAsJson(e),i=Object.keys(t).reduce(((e,s)=>(e[s]={text:t[s]},e)),{}),n=await(0,exports.getDataAndFileCombinedResult)(e,i);return i18nStringsFiles.writeFileSync(e,n,{wantsComments:!0}),(0,exports.getFileDiff)(s,n)};exports.updateFileWithData=updateFileWithData;const getFileDiff=(e,t)=>{const s=[],i=[];for(const n in t){const r=e[n],a=t[n];n in e?JSON.stringify(r)!==JSON.stringify(a)&&i.push(n):s.push(n)}return{added:s.length,edited:i.length}};exports.getFileDiff=getFileDiff;const getDryRunResult=async(e,t)=>await(0,exports.getDataAndFileCombinedResult)(e,t);exports.getDryRunResult=getDryRunResult;