fill-pot-po
Advanced tools
Comparing version
@@ -1,4 +0,4 @@ | ||
var Pe=Object.create;var A=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty;var _e=(e,t)=>{for(var r in t)A(e,r,{get:t[r],enumerable:!0})},ee=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Se(t))!we.call(e,o)&&o!==r&&A(e,o,{get:()=>t[o],enumerable:!(n=ye(t,o))||n.enumerable});return e};var m=(e,t,r)=>(r=e!=null?Pe(be(e)):{},ee(t||!e||!e.__esModule?A(r,"default",{value:e,enumerable:!0}):r,e)),xe=e=>ee(A({},"__esModule",{value:!0}),e);var Le={};_e(Le,{default:()=>Ee,prepareOptions:()=>R,sync:()=>Q,testOptions:()=>he});module.exports=xe(Le);var Re=()=>typeof document>"u"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,S=Re();var H=m(require("fs")),B=m(require("vinyl")),ge=require("safe-buffer"),z=m(require("gettext-parser")),k=m(require("ansi-colors")),Oe=m(require("color-support"));var te=m(require("util")),j=m(require("ansi-colors")),re=m(require("color-support")),ne=require("fs");j.default.enabled=!!(0,re.default)().hasBasic;var $e=JSON.parse((0,ne.readFileSync)(new URL("../package.json",S),"utf-8")),M=class{constructor(t,r=""){this.message=t,this.category=r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()}toString(){return`${j.default.cyan($e.name)} ${j.default.bold.red(`${this.category}Error`)} ${this.message}`}[te.inspect.custom](){return this.toString()}},b=M;var x=require("path"),le=m(require("vinyl"));var se=m(require("vinyl"));var _=e=>Object.prototype.toString.call(e)==="[object Array]",oe=e=>Object.prototype.toString.call(e)==="[object Object]",g=e=>Object.prototype.toString.call(e)==="[object String]",ie=e=>Object.prototype.toString.call(e)==="[object Boolean]",E=e=>_(e)?!!e.reduce((t,r)=>g(r)&&t,!0):!1,ae=e=>_(e)?!!e.reduce((t,r)=>se.default.isVinyl(r)&&t,!0):!1,Z=(e,t)=>{if(!g(e)||!g(t))throw new Error("pathLineSort: a or b not a string");let r,n;if([e,r]=e.split(":"),[t,n]=t.split(":"),e=e.replace(/(^\/|\/$)/g,""),t=t.replace(/(^\/|\/$)/g,""),e===t){if((!r||r==="")&&n&&n.length)return-1;if((!n||n==="")&&r&&r.length)return 1;if(r&&r.length&&n&&n.length)return parseInt(r)-parseInt(n)}let o=e.split("/"),s=t.split("/"),i=o.length,l=s.length,u=Math.max(i,l);for(let c=0;c<u;c++){if(c>=l||!s[c])return-1;if(c>=i||!o[c])return 1;let[f,d]=o[c].split(/\.(?=[^.]*$)/g),[O,h]=s[c].split(/\.(?=[^.]*$)/g),F=d&&d!=="",D=h&&h!=="";if(!F&&D)return-1;if(F&&!D||f.toUpperCase()>O.toUpperCase())return 1;if(f.toUpperCase()<O.toUpperCase())return-1;if(d&&h){if(d.toUpperCase()>h.toUpperCase())return 1;if(d.toUpperCase()<h.toUpperCase())return-1}}return 0};var P=class extends b{constructor(t){super(t,"options")}},ke=e=>{if(oe(e)){if("potSources"in e&&!g(e.potSources)&&!E(e.potSources)&&!le.default.isVinyl(e.potSources)&&!ae(e.potSources))throw new P("Option potSources should be a string or Vinyl object, or an array of those.");if("poSources"in e&&e.poSources!==null&&!g(e.poSources)&&!E(e.poSources))throw new P("Option poSources should be a glob string or glob array.");if("wrapLength"in e&&(typeof e.wrapLength!="number"||0>=e.wrapLength))throw new P("If set, option wrapLength should be a number higher than 0.");let t=["srcDir","destDir","domain"];for(let n of t)if(n in e)if(g(e[n])){if(e[n].match(/\n/))throw new P(`Option ${n} can't contain newline characters.`)}else throw new P(`Option ${n} should be a string.`);let r=["writeFiles","returnPOT","domainFromPOTPath","domainInPOPath","defaultContextAsFallback","appendNonIncludedFromPO","includePORevisionDate","includeGenerator","logResults"];for(let n of r)if(n in e&&!ie(e[n]))throw new P(`Option ${n} should be a boolean.`)}else{if(g(e)||E(e))return{poSources:e};if(typeof e<"u")throw new P("Options should be an object of options, glob string or glob array.");return{}}return e},ve=e=>{let t=(0,x.resolve)();return typeof e.potSources<"u"&&(_(e.potSources)||(e.potSources=[e.potSources]),e.potSources=e.potSources.map(r=>g(r)?r.trim():r).filter(r=>!g(r)||r.length>0)),typeof e.poSources<"u"&&e.poSources!==null&&(_(e.poSources)||(e.poSources=[e.poSources]),e.poSources=e.poSources.map(r=>r.trim()).filter(r=>r.length>0)),e.srcDir&&(e.srcDir=(0,x.resolve)(e.srcDir.trim()),e.srcDir=`${(0,x.relative)(t,e.srcDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.destDir&&(e.destDir=(0,x.resolve)(e.destDir.trim()),e.destDir=`${(0,x.relative)(t,e.destDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.wrapLength&&(e.wrapLength=Math.ceil(e.wrapLength)),e},R=(e,t=!0)=>{e=ke(e),e=ve(e);let n=Object.assign({},{potSources:["**/*.pot","!node_modules/**"],poSources:null,srcDir:"",domainInPOPath:!0,domainFromPOTPath:!0,domain:"",srcGlobOptions:{},wrapLength:77,defaultContextAsFallback:!1,appendNonIncludedFromPO:!1,includePORevisionDate:!1,includeGenerator:!0,returnPOT:!1,writeFiles:!!t,destDir:"",logResults:!1,_pot_input_files:[],_po_input_files:[]},e);if(n.domainFromPOTPath===!1&&n.domainInPOPath===!0&&0>=n.domain.length)throw new P("Option domain should be a non-empty string when domainFromPOTPath is false and domainInPOPath is true.");if(n.returnPOT&&!n.writeFiles)throw new P("If option returnPOT is true, option writeFiles must be true or no PO files will be generated.");return n};var $=require("path"),pe=require("safe-buffer"),q=require("matched"),C=require("fs"),ue=m(require("gettext-parser")),fe=m(require("vinyl")),y=m(require("ansi-colors")),me=m(require("color-support"));var de=require("fs");y.default.enabled=!!(0,me.default)().hasBasic;var ce=JSON.parse((0,de.readFileSync)(new URL("../package.json",S),"utf-8")),L=e=>{if(_(e.potSources)&&e.potSources.length&&g(e.potSources[0])&&(e.potSources=(0,q.sync)(e.potSources)),e._potFilenames=e.potSources.map(t=>g(t)?t:t.path),0>=e.potSources.length)throw new b("No POT files found to process.");if(1<e.potSources.length&&e.poSources)throw new b(`When processing multiple POT files, leave option poSources empty. | ||
Else, the same generated PO files will be overwritten for each POT file.`,"options");return e},I=(e,t)=>{let r=(0,$.basename)(e,".pot"),n=t.domainFromPOTPath?r:t.domain,o=t.srcDir?t.srcDir:`${(0,$.dirname)(e)}/`,s=[];if(t.poSources)s.push(...t.poSources);else{let l="[a-z][a-z]?([a-z])?(_[A-Z][A-Z]?([A-Z]))?(_formal)",u=t.domainInPOPath?`${n}-`:"";s.push(`${o}${u}${l}.po`)}return(0,q.sync)(s,t.srcGlobOptions).sort(Z)},U=(e,t,r,n)=>{let o=JSON.parse(JSON.stringify(e));o=Ce(o,t,n);let s=Fe(o,n),i=(0,$.basename)(r);return n.writeFiles&&De(`${n.destDir}${i}`,s),new fe.default({contents:pe.Buffer.from(s),path:i})},Ce=(e,t,r)=>{var n,o,s,i,l,u,c,f,d,O,h,F,D;for(let[a,T]of Object.entries(e.translations))for(let[p,w]of Object.entries(T))t.translations[a]&&t.translations[a][p]&&t.translations[a][p].msgstr.length===w.msgstr.length?e.translations[a][p].msgstr=[...t.translations[a][p].msgstr]:r.defaultContextAsFallback&&t.translations[""]&&t.translations[""][p]&&t.translations[""][p].msgstr.length===w.msgstr.length&&(e.translations[a][p].msgstr=[...t.translations[""][p].msgstr],e.translations[a][p].comments={...((n=e.translations[a][p])==null?void 0:n.comments)??{},flag:["fuzzy",(s=(o=e.translations[a][p])==null?void 0:o.comments)==null?void 0:s.flag].filter(J=>J).join(", ")},t.translations[""][p].comments={...((i=t.translations[""][p])==null?void 0:i.comments)??{},translator:[`NOTE: re-used for same message, but with context '${a}'`,(u=(l=t.translations[""][p])==null?void 0:l.comments)==null?void 0:u.translator].filter(J=>J).join(` | ||
`)});if(r.appendNonIncludedFromPO)for(let[a,T]of Object.entries(t.translations)){e.translations[a]||(e.translations[a]={});for(let[p,w]of Object.entries(T))e.translations[a][p]||(e.translations[a][p]=w,e.translations[a][p].comments={...((c=e.translations[a][p])==null?void 0:c.comments)??{},...(d=(f=e.translations[a][p])==null?void 0:f.comments)!=null&&d.translator&&((O=w==null?void 0:w.comments)!=null&&O.translator.match(/^DEPRECATED$/gm))?{}:{translator:g((F=(h=e.translations[a][p])==null?void 0:h.comments)==null?void 0:F.translator)?`DEPRECATED | ||
`+(((D=e.translations[a][p].comments)==null?void 0:D.translator)??""):"DEPRECATED"}})}if(r.includePORevisionDate){let a=new Date,T=[`${a.getUTCFullYear()}`,`-${String(a.getUTCMonth()+1).padStart(2,"0")}`,`-${String(a.getUTCDate()).padStart(2,"0")}`,` ${String(a.getUTCHours()).padStart(2,"0")}`,`:${String(a.getUTCMinutes()).padStart(2,"0")}`,"+0000"].join("");e.headers["po-revision-date"]=T}return r.includeGenerator&&(e.headers["X-Generator"]=`${ce.name}/${ce.version}`),e},Fe=(e,t)=>ue.default.po.compile(e,{foldLength:t.wrapLength,sort:(r,n)=>{var i,l,u,c,f,d;let o=(l=(i=n.comments)==null?void 0:i.translator)==null?void 0:l.match(/^DEPRECATED$/gm),s=(c=(u=r.comments)==null?void 0:u.translator)==null?void 0:c.match(/^DEPRECATED$/gm);return!s&&o?-1:s&&!o?1:(f=n.comments)!=null&&f.reference?(d=r.comments)!=null&&d.reference?(r=r.comments.reference.trim().split(/\s+/)[0],n=n.comments.reference.trim().split(/\s+/)[0],Z(r,n)):1:-1}}),De=(e,t)=>{let r=(0,$.dirname)(e);(0,C.existsSync)(r)||(0,C.mkdirSync)(r,{recursive:!0}),(0,C.writeFileSync)(e,t.toString())},N=(e,t,r,n)=>{e.forEach((o,s)=>{var f,d;let i=(0,$.basename)(o),l=(f=t[s])==null?void 0:f.map(O=>O),u=(d=r[s])==null?void 0:d.map(O=>O.path),c=l.reduce((O,h)=>Math.max(h.length,O),0);console.log(""),u&&u.length?(console.log(` ${y.default.bold.green("\u25A0")} ${y.default.white(i)}`),u.forEach((O,h)=>{console.log([" ",`${y.default.cyan(l[h].padEnd(c," "))}`,` ${y.default.gray("\u2014\u25BA")} `,`${y.default.yellow(n)}${y.default.yellow(O)}`].join(""))})):(console.log(` ${y.default.gray("\u25A0")} ${y.default.white(i)}`),console.log(` ${y.default.gray("No PO files found.")}`))}),console.log("")};k.default.enabled=!!(0,Oe.default)().hasBasic;var Te=(e,t,r)=>{H.readFile(e,(n,o)=>{n&&r(n);let s=z.default.po.parse(o);t(s)})},Ve=(e,t,r,n)=>{let o=B.default.isVinyl(e),s=o?e.path:e,i=I(s,t);if(i.length)if(o){t.returnPOT&&t._pot_input_files.push(e);let l=z.default.po.parse(e.contents);r([l,i])}else H.readFile(s,(l,u)=>{l&&n(l),t.returnPOT&&t._pot_input_files.push(new B.default({contents:ge.Buffer.from(u),path:s}));let c=z.default.po.parse(u);r([c,i])});else r(null)},v=(e,t)=>{if(typeof e!="function")throw new b("fillPotPo() requires a callback function as first parameter");let r;try{r=L(R(t))}catch(n){e([!1,n.toString()]);return}r._pot_input_files=[],r._po_input_files=[],Promise.all(r.potSources.map(n=>{let o=B.default.isVinyl(n)?n.relative:n;return new Promise((s,i)=>{Ve(n,r,s,i)}).then(async s=>{if(!s)return r._po_input_files.push([]),[];let i=s[0],l=s[1];return r._po_input_files.push(l),await Promise.all(l.map(c=>new Promise((f,d)=>{Te(c,f,d)}).then(f=>U(i,f,c,r)).catch(f=>{throw new b(`${k.default.bold(f.message)} ${k.default.gray(`(PO ${k.default.white(c)})`)}`)})))}).catch(s=>{throw new b(`${s.message} ${k.default.gray(`(POT ${k.default.white(o)})`)}`)})})).then(n=>{if(r.logResults&&N(r._potFilenames,r._po_input_files,n,r.destDir),r.returnPOT){e([!0,r._pot_input_files]);return}e([!0,[].concat(...n)])}).catch(n=>{e([!1,n.toString()])}).finally(()=>{r._pot_input_files=[],r._po_input_files=[]})};var Y=m(require("fs")),W=m(require("vinyl")),K=m(require("gettext-parser"));var G=[],X=[],V=[],Ae=(e,t,r)=>{let n=[];for(let o of e){let s=Y.readFileSync(o).toString(),i=K.default.po.parse(s);n.push(U(t,i,o,r))}V.push(n)},je=(e,t)=>{let r=W.default.isVinyl(e),n=r?e.path:e,o=I(n,t);if(X.push(o),o.length){let s="";if(r)t.returnPOT&&G.push(e),s=e.contents;else{let l=Y.readFileSync(n);s=l.toString(),t.returnPOT&&G.push(new W.default({contents:l,path:n}))}let i=K.default.po.parse(s);Ae(o,i,t)}else V.push([])},Q=e=>{G=[],X=[],V=[];let t=L(R(e));return t.potSources.forEach(r=>{je(r,t)}),t.logResults&&N(t._potFilenames,X,V,t.destDir),t.returnPOT?G:[].concat(...V)};var he={wrapLength:77,defaultContextAsFallback:!0,appendNonIncludedFromPO:!0,includePORevisionDate:!1,includeGenerator:!1},Ee=v;typeof module<"u"&&(v.sync=Q,v.testOptions=he,v.prepareOptions=R,module.exports=v,module.exports.default=v);0&&(module.exports={prepareOptions,sync,testOptions}); | ||
var Oe=Object.create;var V=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var Se=Object.getPrototypeOf,be=Object.prototype.hasOwnProperty;var we=(e,t)=>{for(var r in t)V(e,r,{get:t[r],enumerable:!0})},te=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ye(t))!be.call(e,o)&&o!==r&&V(e,o,{get:()=>t[o],enumerable:!(s=Pe(t,o))||s.enumerable});return e};var m=(e,t,r)=>(r=e!=null?Oe(Se(e)):{},te(t||!e||!e.__esModule?V(r,"default",{value:e,enumerable:!0}):r,e)),xe=e=>te(V({},"__esModule",{value:!0}),e);var Ie={};we(Ie,{default:()=>Ee,prepareOptions:()=>v,sync:()=>ee,testOptions:()=>he});module.exports=xe(Ie);var _e=()=>typeof document>"u"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,b=_e();var W=m(require("fs")),B=m(require("vinyl")),de=require("buffer"),z=m(require("gettext-parser")),$=m(require("ansi-colors")),ge=m(require("color-support"));var re=m(require("util")),A=m(require("ansi-colors")),se=m(require("color-support")),ne=require("fs");A.default.enabled=!!(0,se.default)().hasBasic;var ve=JSON.parse((0,ne.readFileSync)(new URL("../package.json",b),"utf-8")),M=class{constructor(t,r=""){this.message=t,this.category=r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()}toString(){return`${A.default.cyan(ve.name)} ${A.default.bold.red(`${this.category}Error`)} ${this.message}`}[re.inspect.custom](){return this.toString()}},S=M;var _=require("path"),ce=m(require("vinyl"));var oe=m(require("vinyl"));var x=e=>Object.prototype.toString.call(e)==="[object Array]",ie=e=>Object.prototype.toString.call(e)==="[object Object]",g=e=>Object.prototype.toString.call(e)==="[object String]",ae=e=>Object.prototype.toString.call(e)==="[object Boolean]",E=e=>x(e)?!!e.reduce((t,r)=>g(r)&&t,!0):!1,le=e=>x(e)?!!e.reduce((t,r)=>oe.default.isVinyl(r)&&t,!0):!1,q=(e,t)=>{if(!g(e)||!g(t))throw new Error("pathLineSort: a or b not a string");let r,s;if([e,r]=e.split(":"),[t,s]=t.split(":"),e=e.replace(/(^\/|\/$)/g,""),t=t.replace(/(^\/|\/$)/g,""),e===t){if((!r||r==="")&&s&&s.length)return-1;if((!s||s==="")&&r&&r.length)return 1;if(r&&r.length&&s&&s.length)return parseInt(r)-parseInt(s)}let o=e.split("/"),n=t.split("/"),i=o.length,l=n.length,u=Math.max(i,l);for(let c=0;c<u;c++){if(c>=l||!n[c])return-1;if(c>=i||!o[c])return 1;let[f,d]=o[c].split(/\.(?=[^.]*$)/g),[h,O]=n[c].split(/\.(?=[^.]*$)/g),j=d&&d!=="",D=O&&O!=="";if(!j&&D)return-1;if(j&&!D||f.toUpperCase()>h.toUpperCase())return 1;if(f.toUpperCase()<h.toUpperCase())return-1;if(d&&O){if(d.toUpperCase()>O.toUpperCase())return 1;if(d.toUpperCase()<O.toUpperCase())return-1}}return 0};var P=class extends S{constructor(t){super(t,"options")}},Re=e=>{if(ie(e)){if("potSources"in e&&!g(e.potSources)&&!E(e.potSources)&&!ce.default.isVinyl(e.potSources)&&!le(e.potSources))throw new P("Option potSources should be a string or Vinyl object, or an array of those.");if("poSources"in e&&e.poSources!==null&&!g(e.poSources)&&!E(e.poSources))throw new P("Option poSources should be a glob string or glob array.");if("wrapLength"in e&&(typeof e.wrapLength!="number"||0>=e.wrapLength))throw new P("If set, option wrapLength should be a number higher than 0.");let t=["srcDir","destDir","domain"];for(let s of t)if(s in e)if(g(e[s])){if(e[s].match(/\n/))throw new P(`Option ${s} can't contain newline characters.`)}else throw new P(`Option ${s} should be a string.`);let r=["writeFiles","returnPOT","domainFromPOTPath","domainInPOPath","defaultContextAsFallback","appendNonIncludedFromPO","includePORevisionDate","includeGenerator","logResults"];for(let s of r)if(s in e&&!ae(e[s]))throw new P(`Option ${s} should be a boolean.`)}else{if(g(e)||E(e))return{poSources:e};if(typeof e<"u")throw new P("Options should be an object of options, glob string or glob array.");return{}}return e},$e=e=>{let t=(0,_.resolve)();return typeof e.potSources<"u"&&(x(e.potSources)||(e.potSources=[e.potSources]),e.potSources=e.potSources.map(r=>g(r)?r.trim():r).filter(r=>!g(r)||r.length>0)),typeof e.poSources<"u"&&e.poSources!==null&&(x(e.poSources)||(e.poSources=[e.poSources]),e.poSources=e.poSources.map(r=>r.trim()).filter(r=>r.length>0)),e.srcDir&&(e.srcDir=(0,_.resolve)(e.srcDir.trim()),e.srcDir=`${(0,_.relative)(t,e.srcDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.destDir&&(e.destDir=(0,_.resolve)(e.destDir.trim()),e.destDir=`${(0,_.relative)(t,e.destDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.wrapLength&&(e.wrapLength=Math.ceil(e.wrapLength)),e},v=(e,t=!0)=>{e=Re(e),e=$e(e);let s=Object.assign({},{potSources:["**/*.pot","!node_modules/**"],poSources:null,srcDir:"",domainInPOPath:!0,domainFromPOTPath:!0,domain:"",srcGlobOptions:{},wrapLength:77,defaultContextAsFallback:!1,appendNonIncludedFromPO:!1,includePORevisionDate:!1,includeGenerator:!0,returnPOT:!1,writeFiles:!!t,destDir:"",logResults:!1,_pot_input_files:[],_po_input_files:[]},e);if(s.domainFromPOTPath===!1&&s.domainInPOPath===!0&&0>=s.domain.length)throw new P("Option domain should be a non-empty string when domainFromPOTPath is false and domainInPOPath is true.");if(s.returnPOT&&!s.writeFiles)throw new P("If option returnPOT is true, option writeFiles must be true or no PO files will be generated.");return s};var R=require("path"),pe=require("buffer"),H=require("matched"),C=require("fs"),ue=m(require("gettext-parser")),fe=m(require("vinyl")),y=m(require("ansi-colors")),me=m(require("color-support"));var Z={name:"fill-pot-po",version:"2.2.6",description:"Create pre-filled PO files from POT file, using previous PO files.",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",require:"./dist/index.js",import:"./dist/index.mjs"}},scripts:{dev:"npm run build -- --watch src",build:"tsup",lint:"eslint src/*.ts test/*.ts","lint:fix":"eslint --fix src/*.ts test/*.ts",test:"jest",coverage:"jest --coverage"},keywords:["pot","po","fill","merge","auto-fill","prefill","pre-fill","generate","create","i18n","l10n","gettext","translation"],repository:"https://github.com/vheemstra/fill-pot-po.git",homepage:"https://github.com/vheemstra/fill-pot-po",bugs:"https://github.com/vheemstra/fill-pot-po/issues",author:{name:"Philip van Heemstra",url:"https://github.com/vheemstra"},engines:{node:">=12"},files:["dist"],license:"MIT",dependencies:{"ansi-colors":"^4.1.3","color-support":"^1.1.3","gettext-parser":"^7.0.1",matched:"^5.0.1",vinyl:"^3.0.0"},devDependencies:{"@types/jest":"^29.5.6","@types/vinyl":"^2.0.9","@typescript-eslint/eslint-plugin":"^6.8.0","@typescript-eslint/parser":"^6.8.0","babel-plugin-transform-import-meta":"^2.2.1",eslint:"^8.52.0","eslint-config-prettier":"^9.0.0","eslint-plugin-jest":"^27.4.3","eslint-plugin-prettier":"^5.0.1",jest:"^29.7.0","ts-jest":"^29.1.1","ts-node":"^10.9.1",tsup:"^7.2.0",typescript:"^5.2.2","utility-types":"^3.10.0"}};y.default.enabled=!!(0,me.default)().hasBasic;var I=e=>{if(x(e.potSources)&&e.potSources.length&&g(e.potSources[0])&&(e.potSources=(0,H.sync)(e.potSources)),e._potFilenames=e.potSources.map(t=>g(t)?t:t.path),0>=e.potSources.length)throw new S("No POT files found to process.");if(1<e.potSources.length&&e.poSources)throw new S(`When processing multiple POT files, leave option poSources empty. | ||
Else, the same generated PO files will be overwritten for each POT file.`,"options");return e},L=(e,t)=>{let r=(0,R.basename)(e,".pot"),s=t.domainFromPOTPath?r:t.domain,o=t.srcDir?t.srcDir:`${(0,R.dirname)(e)}/`,n=[];if(t.poSources)n.push(...t.poSources);else{let l="[a-z][a-z]?([a-z])?(_[A-Z][A-Z]?([A-Z]))?(_formal)",u=t.domainInPOPath?`${s}-`:"";n.push(`${o}${u}${l}.po`)}return(0,H.sync)(n,t.srcGlobOptions).sort(q)},U=(e,t,r,s)=>{let o=JSON.parse(JSON.stringify(e));o=Ce(o,t,s);let n=je(o,s),i=(0,R.basename)(r);return s.writeFiles&&De(`${s.destDir}${i}`,n),new fe.default({contents:pe.Buffer.from(n),path:i})},Ce=(e,t,r)=>{var s,o,n,i,l,u,c,f,d,h,O,j,D;for(let[a,F]of Object.entries(e.translations))for(let[p,w]of Object.entries(F))t.translations[a]&&t.translations[a][p]&&t.translations[a][p].msgstr.length===w.msgstr.length?e.translations[a][p].msgstr=[...t.translations[a][p].msgstr]:r.defaultContextAsFallback&&t.translations[""]&&t.translations[""][p]&&t.translations[""][p].msgstr.length===w.msgstr.length&&(e.translations[a][p].msgstr=[...t.translations[""][p].msgstr],e.translations[a][p].comments={...((s=e.translations[a][p])==null?void 0:s.comments)??{},flag:["fuzzy",(n=(o=e.translations[a][p])==null?void 0:o.comments)==null?void 0:n.flag].filter(J=>J).join(", ")},t.translations[""][p].comments={...((i=t.translations[""][p])==null?void 0:i.comments)??{},translator:[`NOTE: re-used for same message, but with context '${a}'`,(u=(l=t.translations[""][p])==null?void 0:l.comments)==null?void 0:u.translator].filter(J=>J).join(` | ||
`)});if(r.appendNonIncludedFromPO)for(let[a,F]of Object.entries(t.translations)){e.translations[a]||(e.translations[a]={});for(let[p,w]of Object.entries(F))e.translations[a][p]||(e.translations[a][p]=w,e.translations[a][p].comments={...((c=e.translations[a][p])==null?void 0:c.comments)??{},...(d=(f=e.translations[a][p])==null?void 0:f.comments)!=null&&d.translator&&((h=w==null?void 0:w.comments)!=null&&h.translator.match(/^DEPRECATED$/gm))?{}:{translator:g((j=(O=e.translations[a][p])==null?void 0:O.comments)==null?void 0:j.translator)?`DEPRECATED | ||
`+(((D=e.translations[a][p].comments)==null?void 0:D.translator)??""):"DEPRECATED"}})}if(r.includePORevisionDate){let a=new Date,F=[`${a.getUTCFullYear()}`,`-${String(a.getUTCMonth()+1).padStart(2,"0")}`,`-${String(a.getUTCDate()).padStart(2,"0")}`,` ${String(a.getUTCHours()).padStart(2,"0")}`,`:${String(a.getUTCMinutes()).padStart(2,"0")}`,"+0000"].join("");e.headers["po-revision-date"]=F}return r.includeGenerator&&(e.headers["X-Generator"]=`${Z.name}/${Z.version}`),e},je=(e,t)=>ue.default.po.compile(e,{foldLength:t.wrapLength,sort:(r,s)=>{var i,l,u,c,f,d;let o=(l=(i=s.comments)==null?void 0:i.translator)==null?void 0:l.match(/^DEPRECATED$/gm),n=(c=(u=r.comments)==null?void 0:u.translator)==null?void 0:c.match(/^DEPRECATED$/gm);return!n&&o?-1:n&&!o?1:(f=s.comments)!=null&&f.reference?(d=r.comments)!=null&&d.reference?(r=r.comments.reference.trim().split(/\s+/)[0],s=s.comments.reference.trim().split(/\s+/)[0],q(r,s)):1:-1}}),De=(e,t)=>{let r=(0,R.dirname)(e);(0,C.existsSync)(r)||(0,C.mkdirSync)(r,{recursive:!0}),(0,C.writeFileSync)(e,t.toString())},N=(e,t,r,s)=>{e.forEach((o,n)=>{var f,d;let i=(0,R.basename)(o),l=(f=t[n])==null?void 0:f.map(h=>h),u=(d=r[n])==null?void 0:d.map(h=>h.path),c=l.reduce((h,O)=>Math.max(O.length,h),0);console.log(""),u&&u.length?(console.log(` ${y.default.bold.green("\u25A0")} ${y.default.white(i)}`),u.forEach((h,O)=>{console.log([" ",`${y.default.cyan(l[O].padEnd(c," "))}`,` ${y.default.gray("\u2014\u25BA")} `,`${y.default.yellow(s)}${y.default.yellow(h)}`].join(""))})):(console.log(` ${y.default.gray("\u25A0")} ${y.default.white(i)}`),console.log(` ${y.default.gray("No PO files found.")}`))}),console.log("")};$.default.enabled=!!(0,ge.default)().hasBasic;var Fe=(e,t,r)=>{W.readFile(e,(s,o)=>{s&&r(s);let n=z.default.po.parse(o);t(n)})},Te=(e,t,r,s)=>{let o=B.default.isVinyl(e),n=o?e.path:e,i=L(n,t);if(i.length)if(o){t.returnPOT&&t._pot_input_files.push(e);let l=z.default.po.parse(e.contents);r([l,i])}else W.readFile(n,(l,u)=>{l&&s(l),t.returnPOT&&t._pot_input_files.push(new B.default({contents:de.Buffer.from(u),path:n}));let c=z.default.po.parse(u);r([c,i])});else r(null)},k=(e,t)=>{if(typeof e!="function")throw new S("fillPotPo() requires a callback function as first parameter");let r;try{r=I(v(t))}catch(s){e([!1,s.toString()]);return}r._pot_input_files=[],r._po_input_files=[],Promise.all(r.potSources.map(s=>{let o=B.default.isVinyl(s)?s.relative:s;return new Promise((n,i)=>{Te(s,r,n,i)}).then(async n=>{if(!n)return r._po_input_files.push([]),[];let i=n[0],l=n[1];return r._po_input_files.push(l),await Promise.all(l.map(c=>new Promise((f,d)=>{Fe(c,f,d)}).then(f=>U(i,f,c,r)).catch(f=>{throw new S(`${$.default.bold(f.message)} ${$.default.gray(`(PO ${$.default.white(c)})`)}`)})))}).catch(n=>{throw new S(`${n.message} ${$.default.gray(`(POT ${$.default.white(o)})`)}`)})})).then(s=>{if(r.logResults&&N(r._potFilenames,r._po_input_files,s,r.destDir),r.returnPOT){e([!0,r._pot_input_files]);return}e([!0,[].concat(...s)])}).catch(s=>{e([!1,s.toString()])}).finally(()=>{r._pot_input_files=[],r._po_input_files=[]})};var K=m(require("fs")),X=m(require("vinyl")),Q=m(require("gettext-parser"));var G=[],Y=[],T=[],Ve=(e,t,r)=>{let s=[];for(let o of e){let n=K.readFileSync(o).toString(),i=Q.default.po.parse(n);s.push(U(t,i,o,r))}T.push(s)},Ae=(e,t)=>{let r=X.default.isVinyl(e),s=r?e.path:e,o=L(s,t);if(Y.push(o),o.length){let n="";if(r)t.returnPOT&&G.push(e),n=e.contents.toString();else{let l=K.readFileSync(s);n=l.toString(),t.returnPOT&&G.push(new X.default({contents:l,path:s}))}let i=Q.default.po.parse(n);Ve(o,i,t)}else T.push([])},ee=e=>{G=[],Y=[],T=[];let t=I(v(e));return t.potSources.forEach(r=>{Ae(r,t)}),t.logResults&&N(t._potFilenames,Y,T,t.destDir),t.returnPOT?G:[].concat(...T)};var he={wrapLength:77,defaultContextAsFallback:!0,appendNonIncludedFromPO:!0,includePORevisionDate:!1,includeGenerator:!1},Ee=k;typeof module<"u"&&(k.sync=ee,k.testOptions=he,k.prepareOptions=v,module.exports=k,module.exports.default=k);0&&(module.exports={prepareOptions,sync,testOptions}); |
{ | ||
"name": "fill-pot-po", | ||
"version": "2.2.5", | ||
"version": "2.2.6", | ||
"description": "Create pre-filled PO files from POT file, using previous PO files.", | ||
@@ -57,21 +57,21 @@ "main": "./dist/index.js", | ||
"matched": "^5.0.1", | ||
"safe-buffer": "^5.2.1", | ||
"vinyl": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.3", | ||
"@typescript-eslint/eslint-plugin": "^6.2.1", | ||
"@typescript-eslint/parser": "^6.2.1", | ||
"babel-plugin-transform-import-meta": "^2.2.0", | ||
"eslint": "^8.46.0", | ||
"eslint-config-prettier": "^8.9.0", | ||
"eslint-plugin-jest": "^27.2.3", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"jest": "^29.6.2", | ||
"@types/jest": "^29.5.6", | ||
"@types/vinyl": "^2.0.9", | ||
"@typescript-eslint/eslint-plugin": "^6.8.0", | ||
"@typescript-eslint/parser": "^6.8.0", | ||
"babel-plugin-transform-import-meta": "^2.2.1", | ||
"eslint": "^8.52.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-jest": "^27.4.3", | ||
"eslint-plugin-prettier": "^5.0.1", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"tsup": "^7.1.0", | ||
"typescript": "^5.1.6", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2", | ||
"utility-types": "^3.10.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
47329
5.96%5
-16.67%155
7.64%9
-18.18%15
7.14%- Removed