New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fill-pot-po

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fill-pot-po - npm Package Compare versions

Comparing version

to
3.0.3

8

dist/index.js

@@ -1,4 +0,4 @@

var he=Object.create;var T=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,Se=Object.prototype.hasOwnProperty;var be=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},ee=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pe(t))!Se.call(e,o)&&o!==r&&T(e,o,{get:()=>t[o],enumerable:!(s=Oe(t,o))||s.enumerable});return e};var m=(e,t,r)=>(r=e!=null?he(ye(e)):{},ee(t||!e||!e.__esModule?T(r,"default",{value:e,enumerable:!0}):r,e)),we=e=>ee(T({},"__esModule",{value:!0}),e);var Ee={};be(Ee,{default:()=>Ae,prepareOptions:()=>v,sync:()=>Q,testOptions:()=>ge});module.exports=we(Ee);var xe=()=>typeof document>"u"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,b=xe();var H=m(require("fs")),N=m(require("vinyl")),me=require("buffer"),B=m(require("gettext-parser")),$=m(require("ansi-colors")),de=m(require("color-support"));var te=m(require("util")),V=m(require("ansi-colors")),re=m(require("color-support")),se=require("fs");V.default.enabled=!!(0,re.default)().hasBasic;var _e=JSON.parse((0,se.readFileSync)(new URL("../package.json",b),"utf-8")),J=class{constructor(t,r=""){this.message=t,this.category=r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()}toString(){return`${V.default.cyan(_e.name)} ${V.default.bold.red(`${this.category}Error`)} ${this.message}`}[te.inspect.custom](){return this.toString()}},S=J;var _=require("path"),le=m(require("vinyl"));var ne=m(require("vinyl"));var x=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]",A=e=>x(e)?!!e.reduce((t,r)=>g(r)&&t,!0):!1,ae=e=>x(e)?!!e.reduce((t,r)=>ne.default.isVinyl(r)&&t,!0):!1,M=(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("/"),a=o.length,l=n.length,u=Math.max(a,l);for(let c=0;c<u;c++){if(c>=l||!n[c])return-1;if(c>=a||!o[c])return 1;let[f,d]=o[c].split(/\.(?=[^.]*$)/g),[h,O]=n[c].split(/\.(?=[^.]*$)/g),j=d&&d!=="",i=O&&O!=="";if(!j&&i)return-1;if(j&&!i||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")}},ve=e=>{if(oe(e)){if("potSources"in e&&!g(e.potSources)&&!A(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)&&!A(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&&!ie(e[s]))throw new P(`Option ${s} should be a boolean.`)}else{if(g(e)||A(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},Re=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=ve(e),e=Re(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"),ce=require("buffer"),Z=require("matched"),C=require("fs"),pe=m(require("gettext-parser")),ue=m(require("vinyl")),y=m(require("ansi-colors")),fe=m(require("color-support"));var q={name:"fill-pot-po",version:"3.0.2",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","build:test":"tsup && jest"},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:">=18"},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.12","@types/vinyl":"^2.0.11","@typescript-eslint/eslint-plugin":"^6.20.0","@typescript-eslint/parser":"^6.20.0","babel-plugin-transform-import-meta":"^2.2.1",eslint:"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-jest":"^27.6.3","eslint-plugin-prettier":"^5.1.3",jest:"^29.7.0","ts-jest":"^29.1.2","ts-node":"^10.9.2",tsup:"^8.0.1",typescript:"^5.3.3","utility-types":"^3.11.0"}};y.default.enabled=!!(0,fe.default)().hasBasic;var E=e=>{if(x(e.potSources)&&e.potSources.length&&g(e.potSources[0])&&(e.potSources=(0,Z.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},I=(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,Z.sync)(n,t.srcGlobOptions).sort(M)},L=(e,t,r,s)=>{let o=JSON.parse(JSON.stringify(e));o=ke(o,t,s);let n=Ce(o,s),a=(0,R.basename)(r);return s.writeFiles&&je(`${s.destDir}${a}`,n),new ue.default({contents:ce.Buffer.from(n),path:a})},ke=(e,t,r)=>{var s,o,n,a,l,u,c,f,d,h,O,j;for(let[i,D]of Object.entries(e.translations))for(let[p,w]of Object.entries(D))t.translations[i]&&t.translations[i][p]&&t.translations[i][p].msgstr.length===w.msgstr.length?e.translations[i][p].msgstr=[...t.translations[i][p].msgstr]:r.defaultContextAsFallback&&t.translations[""]&&t.translations[""][p]&&t.translations[""][p].msgstr.length===w.msgstr.length&&(e.translations[i][p].msgstr=[...t.translations[""][p].msgstr],e.translations[i][p].comments={...((s=e.translations[i][p])==null?void 0:s.comments)??{},flag:["fuzzy",(n=(o=e.translations[i][p])==null?void 0:o.comments)==null?void 0:n.flag].filter(G=>G).join(", ")},t.translations[""][p].comments={...((a=t.translations[""][p])==null?void 0:a.comments)??{},translator:[`NOTE: re-used for same message, but with context '${i}'`,(u=(l=t.translations[""][p])==null?void 0:l.comments)==null?void 0:u.translator].filter(G=>G).join(`
`)});if(r.appendNonIncludedFromPO)for(let[i,D]of Object.entries(t.translations)){e.translations[i]||(e.translations[i]={});for(let[p,w]of Object.entries(D))e.translations[i][p]||(e.translations[i][p]=w,e.translations[i][p].comments={...((c=e.translations[i][p])==null?void 0:c.comments)??{},...(d=(f=e.translations[i][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[i][p])==null?void 0:O.comments)==null?void 0:j.translator)?`DEPRECATED
`+e.translations[i][p].comments.translator:"DEPRECATED"}})}if(r.includePORevisionDate){let i=new Date,D=[`${i.getUTCFullYear()}`,`-${String(i.getUTCMonth()+1).padStart(2,"0")}`,`-${String(i.getUTCDate()).padStart(2,"0")}`,` ${String(i.getUTCHours()).padStart(2,"0")}`,`:${String(i.getUTCMinutes()).padStart(2,"0")}`,"+0000"].join("");e.headers["po-revision-date"]=D}return r.includeGenerator&&(e.headers["X-Generator"]=`${q.name}/${q.version}`),e},Ce=(e,t)=>pe.default.po.compile(e,{foldLength:t.wrapLength,sort:(r,s)=>{var a,l,u,c,f,d;let o=(l=(a=s.comments)==null?void 0:a.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],M(r,s)):1:-1}}),je=(e,t)=>{let r=(0,R.dirname)(e);(0,C.existsSync)(r)||(0,C.mkdirSync)(r,{recursive:!0}),(0,C.writeFileSync)(e,t.toString())},U=(e,t,r,s)=>{e.forEach((o,n)=>{var f,d;let a=(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(a)}`),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(a)}`),console.log(` ${y.default.gray("No PO files found.")}`))}),console.log("")};$.default.enabled=!!(0,de.default)().hasBasic;var De=(e,t,r)=>{H.readFile(e,(s,o)=>{s&&r(s);let n=B.default.po.parse(o);t(n)})},Fe=(e,t,r,s)=>{let o=N.default.isVinyl(e),n=o?e.path:e,a=I(n,t);if(a.length)if(o){t.returnPOT&&t._pot_input_files.push(e);let l=B.default.po.parse(e.contents);r([l,a])}else H.readFile(n,(l,u)=>{l&&s(l),t.returnPOT&&t._pot_input_files.push(new N.default({contents:me.Buffer.from(u),path:n}));let c=B.default.po.parse(u);r([c,a])});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=E(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=N.default.isVinyl(s)?s.relative:s;return new Promise((n,a)=>{Fe(s,r,n,a)}).then(async n=>{if(!n)return r._po_input_files.push([]),[];let a=n[0],l=n[1];return r._po_input_files.push(l),await Promise.all(l.map(c=>new Promise((f,d)=>{De(c,f,d)}).then(f=>L(a,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&&U(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 Y=m(require("fs")),W=m(require("vinyl")),K=m(require("gettext-parser"));var z=[],X=[],F=[],Te=(e,t,r)=>{let s=[];for(let o of e){let n=Y.readFileSync(o).toString(),a=K.default.po.parse(n);s.push(L(t,a,o,r))}F.push(s)},Ve=(e,t)=>{let r=W.default.isVinyl(e),s=r?e.path:e,o=I(s,t);if(X.push(o),o.length){let n="";if(r)t.returnPOT&&z.push(e),n=e.contents.toString();else{let l=Y.readFileSync(s);n=l.toString(),t.returnPOT&&z.push(new W.default({contents:l,path:s}))}let a=K.default.po.parse(n);Te(o,a,t)}else F.push([])},Q=e=>{z=[],X=[],F=[];let t=E(v(e));return t.potSources.forEach(r=>{Ve(r,t)}),t.logResults&&U(t._potFilenames,X,F,t.destDir),t.returnPOT?z:[].concat(...F)};var ge={wrapLength:77,defaultContextAsFallback:!0,appendNonIncludedFromPO:!0,includePORevisionDate:!1,includeGenerator:!1},Ae=k;typeof module<"u"&&(k.sync=Q,k.testOptions=ge,k.prepareOptions=v,module.exports=k,module.exports.default=k);0&&(module.exports={prepareOptions,sync,testOptions});
var he=Object.create;var F=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,Se=Object.prototype.hasOwnProperty;var be=(e,t)=>{for(var r in t)F(e,r,{get:t[r],enumerable:!0})},ee=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pe(t))!Se.call(e,o)&&o!==r&&F(e,o,{get:()=>t[o],enumerable:!(s=Oe(t,o))||s.enumerable});return e};var m=(e,t,r)=>(r=e!=null?he(ye(e)):{},ee(t||!e||!e.__esModule?F(r,"default",{value:e,enumerable:!0}):r,e)),xe=e=>ee(F({},"__esModule",{value:!0}),e);var Ee={};be(Ee,{default:()=>Ae,prepareOptions:()=>_,sync:()=>Q,testOptions:()=>ge});module.exports=xe(Ee);var we=()=>typeof document>"u"?new URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,b=we();var H=m(require("fs")),B=m(require("vinyl")),me=require("buffer"),N=m(require("gettext-parser")),$=m(require("ansi-colors")),de=m(require("color-support"));var te=m(require("util")),V=m(require("ansi-colors")),re=m(require("color-support")),se=require("fs");V.default.enabled=!!(0,re.default)().hasBasic;var ve=JSON.parse((0,se.readFileSync)(new URL("../package.json",b),"utf-8")),J=class{constructor(t,r=""){this.message=t,this.category=r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()}toString(){return`${V.default.cyan(ve.name)} ${V.default.bold.red(`${this.category}Error`)} ${this.message}`}[te.inspect.custom](){return this.toString()}},S=J;var v=require("path"),le=m(require("vinyl"));var ne=m(require("vinyl"));var w=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]",A=e=>w(e)?!!e.reduce((t,r)=>g(r)&&t,!0):!1,ae=e=>w(e)?!!e.reduce((t,r)=>ne.default.isVinyl(r)&&t,!0):!1,M=(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("/"),a=o.length,l=n.length,u=Math.max(a,l);for(let c=0;c<u;c++){if(c>=l||!n[c])return-1;if(c>=a||!o[c])return 1;let[f,d]=o[c].split(/\.(?=[^.]*$)/g),[h,O]=n[c].split(/\.(?=[^.]*$)/g),k=d&&d!=="",i=O&&O!=="";if(!k&&i)return-1;if(k&&!i||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")}},_e=e=>{if(oe(e)){if("potSources"in e&&!g(e.potSources)&&!A(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)&&!A(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&&!ie(e[s]))throw new P(`Option ${s} should be a boolean.`)}else{if(g(e)||A(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},Re=e=>{let t=(0,v.resolve)();return typeof e.potSources<"u"&&(w(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&&(w(e.poSources)||(e.poSources=[e.poSources]),e.poSources=e.poSources.map(r=>r.trim()).filter(r=>r.length>0)),e.srcDir&&(e.srcDir=(0,v.resolve)(e.srcDir.trim()),e.srcDir=`${(0,v.relative)(t,e.srcDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.destDir&&(e.destDir=(0,v.resolve)(e.destDir.trim()),e.destDir=`${(0,v.relative)(t,e.destDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.wrapLength&&(e.wrapLength=Math.ceil(e.wrapLength)),e},_=(e,t=!0)=>{e=_e(e),e=Re(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"),ce=require("buffer"),Z=require("matched"),T=require("fs"),pe=m(require("gettext-parser")),ue=m(require("vinyl")),y=m(require("ansi-colors")),fe=m(require("color-support"));var q={name:"fill-pot-po",version:"3.0.3",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","build:test":"tsup && jest"},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:">=18"},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/gettext-parser":"^4.0.4","@types/jest":"^29.5.12","@types/vinyl":"^2.0.11","@typescript-eslint/eslint-plugin":"^7.1.0","@typescript-eslint/parser":"^7.1.0","babel-plugin-transform-import-meta":"^2.2.1",eslint:"^8.57.0","eslint-config-prettier":"^9.1.0","eslint-plugin-jest":"^27.9.0","eslint-plugin-prettier":"^5.1.3",jest:"^29.7.0","ts-jest":"^29.1.2","ts-node":"^10.9.2",tsup:"^8.0.2",typescript:"^5.3.3","utility-types":"^3.11.0"}};y.default.enabled=!!(0,fe.default)().hasBasic;var E=e=>{if(w(e.potSources)&&e.potSources.length&&g(e.potSources[0])&&(e.potSources=(0,Z.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},I=(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,Z.sync)(n,t.srcGlobOptions).sort(M)},L=(e,t,r,s)=>{let o=JSON.parse(JSON.stringify(e));o=Ce(o,t,s);let n=Te(o,s),a=(0,R.basename)(r);return s.writeFiles&&ke(`${s.destDir}${a}`,n),new ue.default({contents:ce.Buffer.from(n),path:a})},Ce=(e,t,r)=>{var s,o,n,a,l,u,c,f,d,h,O,k;for(let[i,j]of Object.entries(e.translations))for(let[p,x]of Object.entries(j))t.translations[i]&&t.translations[i][p]&&t.translations[i][p].msgstr.length===x.msgstr.length?e.translations[i][p].msgstr=[...t.translations[i][p].msgstr]:r.defaultContextAsFallback&&t.translations[""]&&t.translations[""][p]&&t.translations[""][p].msgstr.length===x.msgstr.length&&(e.translations[i][p].msgstr=[...t.translations[""][p].msgstr],e.translations[i][p].comments={translator:"",reference:"",extracted:"",previous:"",...((s=e.translations[i][p])==null?void 0:s.comments)??{},flag:["fuzzy",(n=(o=e.translations[i][p])==null?void 0:o.comments)==null?void 0:n.flag].filter(G=>G).join(", ")},t.translations[""][p].comments={reference:"",extracted:"",flag:"",previous:"",...((a=t.translations[""][p])==null?void 0:a.comments)??{},translator:[`NOTE: re-used for same message, but with context '${i}'`,(u=(l=t.translations[""][p])==null?void 0:l.comments)==null?void 0:u.translator].filter(G=>G).join(`
`)});if(r.appendNonIncludedFromPO)for(let[i,j]of Object.entries(t.translations)){e.translations[i]||(e.translations[i]={});for(let[p,x]of Object.entries(j))e.translations[i][p]||(e.translations[i][p]=x,e.translations[i][p].comments={translator:"",reference:"",extracted:"",flag:"",previous:"",...((c=e.translations[i][p])==null?void 0:c.comments)??{},...(d=(f=e.translations[i][p])==null?void 0:f.comments)!=null&&d.translator&&((h=x==null?void 0:x.comments)!=null&&h.translator.match(/^DEPRECATED$/gm))?{}:{translator:g((k=(O=e.translations[i][p])==null?void 0:O.comments)==null?void 0:k.translator)?`DEPRECATED
`+e.translations[i][p].comments.translator:"DEPRECATED"}})}if(r.includePORevisionDate){let i=new Date,j=[`${i.getUTCFullYear()}`,`-${String(i.getUTCMonth()+1).padStart(2,"0")}`,`-${String(i.getUTCDate()).padStart(2,"0")}`,` ${String(i.getUTCHours()).padStart(2,"0")}`,`:${String(i.getUTCMinutes()).padStart(2,"0")}`,"+0000"].join("");e.headers["po-revision-date"]=j}return r.includeGenerator&&(e.headers["X-Generator"]=`${q.name}/${q.version}`),e},Te=(e,t)=>pe.default.po.compile(e,{foldLength:t.wrapLength,sort:(r,s)=>{var a,l,u,c,f,d;let o=(l=(a=s.comments)==null?void 0:a.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],M(r,s)):1:-1}}),ke=(e,t)=>{let r=(0,R.dirname)(e);(0,T.existsSync)(r)||(0,T.mkdirSync)(r,{recursive:!0}),(0,T.writeFileSync)(e,t.toString())},U=(e,t,r,s)=>{e.forEach((o,n)=>{var f,d;let a=(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(a)}`),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(a)}`),console.log(` ${y.default.gray("No PO files found.")}`))}),console.log("")};$.default.enabled=!!(0,de.default)().hasBasic;var je=(e,t,r)=>{H.readFile(e,(s,o)=>{s&&r(s);let n=N.default.po.parse(o);t(n)})},De=(e,t,r,s)=>{let o=B.default.isVinyl(e),n=o?e.path:e,a=I(n,t);if(a.length)if(o){t.returnPOT&&t._pot_input_files.push(e);let l=N.default.po.parse(e.contents);r([l,a])}else H.readFile(n,(l,u)=>{l&&s(l),t.returnPOT&&t._pot_input_files.push(new B.default({contents:me.Buffer.from(u),path:n}));let c=N.default.po.parse(u);r([c,a])});else r(null)},C=(e,t)=>{if(typeof e!="function")throw new S("fillPotPo() requires a callback function as first parameter");let r;try{r=E(_(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,a)=>{De(s,r,n,a)}).then(async n=>{if(!n)return r._po_input_files.push([]),[];let a=n[0],l=n[1];return r._po_input_files.push(l),await Promise.all(l.map(c=>new Promise((f,d)=>{je(c,f,d)}).then(f=>L(a,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&&U(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 Y=m(require("fs")),W=m(require("vinyl")),K=m(require("gettext-parser"));var z=[],X=[],D=[],Fe=(e,t,r)=>{let s=[];for(let o of e){let n=Y.readFileSync(o).toString(),a=K.default.po.parse(n);s.push(L(t,a,o,r))}D.push(s)},Ve=(e,t)=>{let r=W.default.isVinyl(e),s=r?e.path:e,o=I(s,t);if(X.push(o),o.length){let n="";if(r)t.returnPOT&&z.push(e),n=e.contents.toString();else{let l=Y.readFileSync(s);n=l.toString(),t.returnPOT&&z.push(new W.default({contents:l,path:s}))}let a=K.default.po.parse(n);Fe(o,a,t)}else D.push([])},Q=e=>{z=[],X=[],D=[];let t=E(_(e));return t.potSources.forEach(r=>{Ve(r,t)}),t.logResults&&U(t._potFilenames,X,D,t.destDir),t.returnPOT?z:[].concat(...D)};var ge={wrapLength:77,defaultContextAsFallback:!0,appendNonIncludedFromPO:!0,includePORevisionDate:!1,includeGenerator:!1},Ae=C;typeof module<"u"&&(C.sync=Q,C.testOptions=ge,C.prepareOptions=_,module.exports=C,module.exports.default=C);0&&(module.exports={prepareOptions,sync,testOptions});
{
"name": "fill-pot-po",
"version": "3.0.2",
"version": "3.0.3",
"description": "Create pre-filled PO files from POT file, using previous PO files.",

@@ -61,10 +61,11 @@ "main": "./dist/index.js",

"devDependencies": {
"@types/gettext-parser": "^4.0.4",
"@types/jest": "^29.5.12",
"@types/vinyl": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-prettier": "^5.1.3",

@@ -74,3 +75,3 @@ "jest": "^29.7.0",

"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"tsup": "^8.0.2",
"typescript": "^5.3.3",

@@ -77,0 +78,0 @@ "utility-types": "^3.11.0"

Sorry, the diff of this file is not supported yet