fill-pot-po
Advanced tools
Comparing version
@@ -1,4 +0,4 @@ | ||
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.5",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.5.0","@typescript-eslint/parser":"^7.5.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.4.4","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}); | ||
import*as Z from"fs";import J from"vinyl";import{Buffer as Re}from"buffer";import M from"gettext-parser";import R from"ansi-colors";import $e from"color-support";import*as K from"util";import N from"ansi-colors";import ue from"color-support";var k={name:"fill-pot-po",version:"4.0.0",description:"Create pre-filled PO files from POT file, using previous PO files.",type:"module",main:"./dist/index.mjs",types:"./dist/index.d.ts",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":"^8.0.0",matched:"^5.0.1",vinyl:"^3.0.0"},devDependencies:{"@types/color-support":"^1.1.4","@types/gettext-parser":"^4.0.4","@types/jest":"^29.5.12","@types/vinyl":"^2.0.12","@typescript-eslint/eslint-plugin":"^7.16.0","@typescript-eslint/parser":"^7.16.0","babel-plugin-transform-import-meta":"^2.2.1",eslint:"^8.57.0","eslint-config-prettier":"^9.1.0","eslint-plugin-jest":"^28.6.0","eslint-plugin-prettier":"^5.1.3",jest:"^29.7.0","ts-jest":"^29.2.1","ts-node":"^10.9.2",tsup:"^8.1.0",typescript:"^5.5.3","utility-types":"^3.11.0"}};var Y=ue();N.enabled=Y&&Y.hasBasic;var B=class{constructor(t,r=""){this.message=t,this.category=r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()}toString(){return`${N.cyan(k.name)} ${N.bold.red(`${this.category}Error`)} ${this.message}`}[K.inspect.custom](){return this.toString()}},y=B;import{resolve as z,relative as re}from"path";import me from"vinyl";import fe from"vinyl";var b=e=>Object.prototype.toString.call(e)==="[object Array]",Q=e=>Object.prototype.toString.call(e)==="[object Object]",d=e=>Object.prototype.toString.call(e)==="[object String]",ee=e=>Object.prototype.toString.call(e)==="[object Boolean]",F=e=>b(e)?!!e.reduce((t,r)=>d(r)&&t,!0):!1,te=e=>b(e)?!!e.reduce((t,r)=>fe.isVinyl(r)&&t,!0):!1,U=(e,t)=>{if(!d(e)||!d(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 n=e.split("/"),o=t.split("/"),i=n.length,l=o.length,u=Math.max(i,l);for(let p=0;p<u;p++){if(p>=l||!o[p])return-1;if(p>=i||!n[p])return 1;let[f,m]=n[p].split(/\.(?=[^.]*$)/g),[g,h]=o[p].split(/\.(?=[^.]*$)/g),$=m&&m!=="",C=h&&h!=="";if(!$&&C)return-1;if($&&!C||f.toUpperCase()>g.toUpperCase())return 1;if(f.toUpperCase()<g.toUpperCase())return-1;if(m&&h){if(m.toUpperCase()>h.toUpperCase())return 1;if(m.toUpperCase()<h.toUpperCase())return-1}}return 0};var O=class extends y{constructor(t){super(t,"options")}},de=e=>{if(Q(e)){if("potSources"in e&&!d(e.potSources)&&!F(e.potSources)&&!me.isVinyl(e.potSources)&&!te(e.potSources))throw new O("Option potSources should be a string or Vinyl object, or an array of those.");if("poSources"in e&&e.poSources!==null&&!d(e.poSources)&&!F(e.poSources))throw new O("Option poSources should be a glob string or glob array.");if("wrapLength"in e&&(typeof e.wrapLength!="number"||0>=e.wrapLength))throw new O("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(d(e[s])){if(e[s].match(/\n/))throw new O(`Option ${s} can't contain newline characters.`)}else throw new O(`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&&!ee(e[s]))throw new O(`Option ${s} should be a boolean.`)}else{if(d(e)||F(e))return{poSources:e};if(typeof e!="undefined")throw new O("Options should be an object of options, glob string or glob array.");return{}}return e},ge=e=>{let t=z();return typeof e.potSources!="undefined"&&(b(e.potSources)||(e.potSources=[e.potSources]),e.potSources=e.potSources.map(r=>d(r)?r.trim():r).filter(r=>!d(r)||r.length>0)),typeof e.poSources!="undefined"&&e.poSources!==null&&(b(e.poSources)||(e.poSources=[e.poSources]),e.poSources=e.poSources.map(r=>r.trim()).filter(r=>r.length>0)),e.srcDir&&(e.srcDir=z(e.srcDir.trim()),e.srcDir=`${re(t,e.srcDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.destDir&&(e.destDir=z(e.destDir.trim()),e.destDir=`${re(t,e.destDir)}/`.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/(?<!\.)\.\//g,"").replace(/^\//g,"")),e.wrapLength&&(e.wrapLength=Math.ceil(e.wrapLength)),e},_=(e,t=!0)=>{e=de(e),e=ge(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 O("Option domain should be a non-empty string when domainFromPOTPath is false and domainInPOPath is true.");if(s.returnPOT&&!s.writeFiles)throw new O("If option returnPOT is true, option writeFiles must be true or no PO files will be generated.");return s};import{basename as G,dirname as oe}from"path";import{Buffer as he}from"buffer";import{sync as ne}from"matched";import{existsSync as Oe,mkdirSync as Pe,writeFileSync as ye}from"fs";import Se from"gettext-parser";import be from"vinyl";import P from"ansi-colors";import we from"color-support";var se=we();P.enabled=se&&se.hasBasic;var j=e=>{if(b(e.potSources)&&e.potSources.length&&d(e.potSources[0])&&(e.potSources=ne(e.potSources)),e._potFilenames=e.potSources.map(t=>d(t)?t:t.path),0>=e.potSources.length)throw new y("No POT files found to process.");if(1<e.potSources.length&&e.poSources)throw new y(`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},V=(e,t)=>{let r=G(e,".pot"),s=t.domainFromPOTPath?r:t.domain,n=t.srcDir?t.srcDir:`${oe(e)}/`,o=[];if(t.poSources)o.push(...t.poSources);else{let l="[a-z][a-z]?([a-z])?(_[A-Z][A-Z]?([A-Z]))?(_formal)",u=t.domainInPOPath?`${s}-`:"";o.push(`${n}${u}${l}.po`)}return ne(o,t.srcGlobOptions).sort(U)},A=(e,t,r,s)=>{let n=JSON.parse(JSON.stringify(e));n=xe(n,t,s);let o=ve(n,s),i=G(r);return s.writeFiles&&_e(`${s.destDir}${i}`,o),new be({contents:he.from(o),path:i})},xe=(e,t,r)=>{var s,n,o,i,l,u,p,f,m,g,h,$,C,W,X;for(let[a,T]of Object.entries(e.translations))for(let[c,S]of Object.entries(T))t.translations[a]&&t.translations[a][c]&&t.translations[a][c].msgstr.length===S.msgstr.length?e.translations[a][c].msgstr=[...t.translations[a][c].msgstr]:r.defaultContextAsFallback&&t.translations[""]&&t.translations[""][c]&&t.translations[""][c].msgstr.length===S.msgstr.length&&(e.translations[a][c].msgstr=[...t.translations[""][c].msgstr],e.translations[a][c].comments={translator:"",reference:"",extracted:"",previous:"",...(n=(s=e.translations[a][c])==null?void 0:s.comments)!=null?n:{},flag:["fuzzy",(i=(o=e.translations[a][c])==null?void 0:o.comments)==null?void 0:i.flag].filter(L=>L).join(", ")},t.translations[""][c].comments={reference:"",extracted:"",flag:"",previous:"",...(u=(l=t.translations[""][c])==null?void 0:l.comments)!=null?u:{},translator:[`NOTE: re-used for same message, but with context '${a}'`,(f=(p=t.translations[""][c])==null?void 0:p.comments)==null?void 0:f.translator].filter(L=>L).join(` | ||
`)});if(r.appendNonIncludedFromPO)for(let[a,T]of Object.entries(t.translations)){e.translations[a]||(e.translations[a]={});for(let[c,S]of Object.entries(T))e.translations[a][c]||(e.translations[a][c]=S,e.translations[a][c].comments={translator:"",reference:"",extracted:"",flag:"",previous:"",...(g=(m=e.translations[a][c])==null?void 0:m.comments)!=null?g:{},...($=(h=e.translations[a][c])==null?void 0:h.comments)!=null&&$.translator&&((C=S==null?void 0:S.comments)!=null&&C.translator.match(/^DEPRECATED$/gm))?{}:{translator:d((X=(W=e.translations[a][c])==null?void 0:W.comments)==null?void 0:X.translator)?`DEPRECATED | ||
`+e.translations[a][c].comments.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"]=`${k.name}/${k.version}`),e},ve=(e,t)=>Se.po.compile(e,{foldLength:t.wrapLength,sort:(r,s)=>{var i,l,u,p,f,m;let n=(l=(i=s.comments)==null?void 0:i.translator)==null?void 0:l.match(/^DEPRECATED$/gm),o=(p=(u=r.comments)==null?void 0:u.translator)==null?void 0:p.match(/^DEPRECATED$/gm);return!o&&n?-1:o&&!n?1:(f=s.comments)!=null&&f.reference?(m=r.comments)!=null&&m.reference?(r=r.comments.reference.trim().split(/\s+/)[0],s=s.comments.reference.trim().split(/\s+/)[0],U(r,s)):1:-1}}),_e=(e,t)=>{let r=oe(e);Oe(r)||Pe(r,{recursive:!0}),ye(e,t.toString())},E=(e,t,r,s)=>{e.forEach((n,o)=>{var f,m;let i=G(n),l=(f=t[o])==null?void 0:f.map(g=>g),u=(m=r[o])==null?void 0:m.map(g=>g.path),p=l.reduce((g,h)=>Math.max(h.length,g),0);console.log(""),u&&u.length?(console.log(` ${P.bold.green("\u25A0")} ${P.white(i)}`),u.forEach((g,h)=>{console.log([" ",`${P.cyan(l[h].padEnd(p," "))}`,` ${P.gray("\u2014\u25BA")} `,`${P.yellow(s)}${P.yellow(g)}`].join(""))})):(console.log(` ${P.gray("\u25A0")} ${P.white(i)}`),console.log(` ${P.gray("No PO files found.")}`))}),console.log("")};var ie=$e();R.enabled=ie&&ie.hasBasic;var Ce=(e,t,r)=>{Z.readFile(e,(s,n)=>{s&&r(s);let o=M.po.parse(n);t(o)})},Te=(e,t,r,s)=>{let n=J.isVinyl(e),o=n?e.path:e,i=V(o,t);if(i.length)if(n){t.returnPOT&&t._pot_input_files.push(e);let l=M.po.parse(e.contents);r([l,i])}else Z.readFile(o,(l,u)=>{l&&s(l),t.returnPOT&&t._pot_input_files.push(new J({contents:Re.from(u),path:o}));let p=M.po.parse(u);r([p,i])});else r(null)},w=(e,t)=>{if(typeof e!="function")throw new y("fillPotPo() requires a callback function as first parameter");let r;try{r=j(_(t))}catch(s){e([!1,s.toString()]);return}r._pot_input_files=[],r._po_input_files=[],Promise.all(r.potSources.map(s=>{let n=J.isVinyl(s)?s.relative:s;return new Promise((o,i)=>{Te(s,r,o,i)}).then(async o=>{if(!o)return r._po_input_files.push([]),[];let i=o[0],l=o[1];return r._po_input_files.push(l),await Promise.all(l.map(p=>new Promise((f,m)=>{Ce(p,f,m)}).then(f=>A(i,f,p,r)).catch(f=>{throw new y(`${R.bold(f.message)} ${R.gray(`(PO ${R.white(p)})`)}`)})))}).catch(o=>{throw new y(`${o.message} ${R.gray(`(POT ${R.white(n)})`)}`)})})).then(s=>{if(r.logResults&&E(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=[]})};import*as H from"fs";import ae from"vinyl";import le from"gettext-parser";var I=[],q=[],D=[],ke=(e,t,r)=>{let s=[];for(let n of e){let o=H.readFileSync(n).toString(),i=le.po.parse(o);s.push(A(t,i,n,r))}D.push(s)},De=(e,t)=>{let r=ae.isVinyl(e),s=r?e.path:e,n=V(s,t);if(q.push(n),n.length){let o="";if(r)t.returnPOT&&I.push(e),o=e.contents.toString();else{let l=H.readFileSync(s);o=l.toString(),t.returnPOT&&I.push(new ae({contents:l,path:s}))}let i=le.po.parse(o);ke(n,i,t)}else D.push([])},pe=e=>{I=[],q=[],D=[];let t=j(_(e));return t.potSources.forEach(r=>{De(r,t)}),t.logResults&&E(t._potFilenames,q,D,t.destDir),t.returnPOT?I:[].concat(...D)};var Fe={wrapLength:77,defaultContextAsFallback:!0,appendNonIncludedFromPO:!0,includePORevisionDate:!1,includeGenerator:!1},Vt=w;typeof module!="undefined"&&(w.sync=pe,w.testOptions=Fe,w.prepareOptions=_,module.exports=w,module.exports.default=w);export{Vt as default,_ as prepareOptions,pe as sync,Fe as testOptions}; |
{ | ||
"name": "fill-pot-po", | ||
"version": "3.0.5", | ||
"version": "4.0.0", | ||
"description": "Create pre-filled PO files from POT file, using previous PO files.", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"type": "module", | ||
"main": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"scripts": { | ||
@@ -56,3 +49,3 @@ "dev": "npm run build -- --watch src", | ||
"color-support": "^1.1.3", | ||
"gettext-parser": "^7.0.1", | ||
"gettext-parser": "^8.0.0", | ||
"matched": "^5.0.1", | ||
@@ -62,19 +55,20 @@ "vinyl": "^3.0.0" | ||
"devDependencies": { | ||
"@types/color-support": "^1.1.4", | ||
"@types/gettext-parser": "^4.0.4", | ||
"@types/jest": "^29.5.12", | ||
"@types/vinyl": "^2.0.11", | ||
"@typescript-eslint/eslint-plugin": "^7.5.0", | ||
"@typescript-eslint/parser": "^7.5.0", | ||
"@types/vinyl": "^2.0.12", | ||
"@typescript-eslint/eslint-plugin": "^7.16.0", | ||
"@typescript-eslint/parser": "^7.16.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-jest": "^28.6.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.2", | ||
"ts-jest": "^29.2.1", | ||
"ts-node": "^10.9.2", | ||
"tsup": "^8.0.2", | ||
"typescript": "^5.4.4", | ||
"tsup": "^8.1.0", | ||
"typescript": "^5.5.3", | ||
"utility-types": "^3.11.0" | ||
} | ||
} |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
-100%4
-55.56%Yes
NaN31994
-33.06%17
6.25%5
-28.57%102
-35.03%+ Added
- Removed
Updated