diff --git a/dist/index.js b/dist/index.js index f438d85..6fece75 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3,7 +3,7 @@ var b=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var M=b(k=>{"use s `&&e[s]!=="\r";s++)o+=e[s];if(o=o.trim(),o[o.length-1]==="/"&&(o=o.substring(0,o.length-1),s--),!Pt(o)){let c;return o.trim().length===0?c="There is an unnecessary space between tag name and backward slash '0)return g("InvalidTag","Closing tag '"+o+"' can't have attributes or invalid starting.",C(e,s));{let c=r.pop();if(o!==c)return g("InvalidTag","Closing tag '"+c+"' is expected inplace of '"+o+"'.",C(e,s));r.length==0&&(i=!0)}}else return g("InvalidTag","Closing tag '"+o+"' doesn't have proper closing.",C(e,s));else{let c=Te(l,t);if(c!==!0)return g(c.err.code,c.err.msg,C(e,s-l.length+c.err.line));if(i===!0)return g("InvalidXml","Multiple possible root nodes found.",C(e,s));r.push(o),n=!0}for(s++;s0)return g("InvalidXml","Invalid '"+JSON.stringify(r,null,4).replace(/\r?\n/g,"")+"' found.",1)}else return g("InvalidXml","Start tag expected.",1);return!0};function Ce(e,t){for(var r=t;t5&&n==="xml")return g("InvalidXml","XML declaration allowed only at the start of the document.",C(e,t));if(e[t]=="?"&&e[t+1]==">"){t++;break}else continue}return t}function ye(e,t){if(e.length>t+5&&e[t+1]==="-"&&e[t+2]==="-"){for(t+=3;t"){t+=2;break}}else if(e.length>t+8&&e[t+1]==="D"&&e[t+2]==="O"&&e[t+3]==="C"&&e[t+4]==="T"&&e[t+5]==="Y"&&e[t+6]==="P"&&e[t+7]==="E"){let r=1;for(t+=8;t"&&(r--,r===0))break}else if(e.length>t+9&&e[t+1]==="["&&e[t+2]==="C"&&e[t+3]==="D"&&e[t+4]==="A"&&e[t+5]==="T"&&e[t+6]==="A"&&e[t+7]==="["){for(t+=8;t"){t+=2;break}}return t}var It='"',St="'";function _t(e,t){let r="",n="",i=!1;for(;t"&&n===""){i=!0;break}r+=e[t]}return n!==""?!1:{value:r,index:t,tagClosed:i}}var Vt=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function Te(e,t){let r=R.getAllMatches(e,Vt),n={};for(let i=0;i{"use strict";var v=function(e){return String.fromCharCode(e)},h={nilChar:v(176),missingChar:v(201),nilPremitive:v(175),missingPremitive:v(200),emptyChar:v(178),emptyValue:v(177),boundryChar:v(179),objStart:v(198),arrStart:v(204),arrayEnd:v(185)},qt=[h.nilChar,h.nilPremitive,h.missingChar,h.missingPremitive,h.boundryChar,h.emptyChar,h.emptyValue,h.arrayEnd,h.objStart,h.arrStart],S=function(e,t,r){if(typeof t=="string")return e&&e[0]&&e[0].val!==void 0?U(e[0].val,t):U(e,t);{let n=$t(e);if(n===!0){let i="";if(Array.isArray(t)){i+=h.arrStart;let s=t[0],a=e.length;if(typeof s=="string")for(let o=0;o{"use strict";var x=T(),xt=T().buildOptions,Ie=I(),Bt=function(e,t){return t=xt(t,Ie.defaultOptions,Ie.props),t.indentBy=t.indentBy||"",H(e,t,0)},H=function(e,t,r){let n="{",i=Object.keys(e.child);for(let o=0;o1){n+='"'+s+'" : [ ';for(var a in e.child[s])n+=H(e.child[s][a],t)+" , ";n=n.substr(0,n.length-1)+" ] "}else n+='"'+s+'" : '+H(e.child[s][0],t)+" ,"}return x.merge(n,e.attrsMap),x.isEmptyObject(n)?x.isExist(e.val)?e.val:"":(x.isExist(e.val)&&(typeof e.val=="string"&&(e.val===""||e.val===t.cdataPositionChar)||(n+='"'+t.textNodeName+'" : '+kt(e.val))),n[n.length-1]===","&&(n=n.substr(0,n.length-2)),n+"}")};function kt(e){return e===!0||e===!1||!isNaN(e)?e:'"'+e+'"'}Pe.convertToJsonString=Bt});var qe=b((Pr,Ve)=>{"use strict";var Gt=T().buildOptions,Jt={attributeNamePrefix:"@_",attrNodeName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataTagName:!1,cdataPositionChar:"\\c",format:!1,indentBy:" ",supressEmptyNode:!1,tagValueProcessor:function(e){return e},attrValueProcessor:function(e){return e}},Ut=["attributeNamePrefix","attrNodeName","textNodeName","ignoreAttributes","cdataTagName","cdataPositionChar","format","indentBy","supressEmptyNode","tagValueProcessor","attrValueProcessor"];function X(e){this.options=Gt(e,Jt,Ut),this.options.ignoreAttributes||this.options.attrNodeName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Kt),this.options.cdataTagName?this.isCDATA=Qt:this.isCDATA=function(){return!1},this.replaceCDATAstr=jt,this.replaceCDATAarr=Ht,this.options.format?(this.indentate=zt,this.tagEndChar=`> `,this.newLine=` -`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine=""),this.options.supressEmptyNode?(this.buildTextNode=Yt,this.buildObjNode=Xt):(this.buildTextNode=Fe,this.buildObjNode=Me),this.buildTextValNode=Fe,this.buildObjectNode=Me}X.prototype.parse=function(e){return this.j2x(e,0).val};X.prototype.j2x=function(e,t){let r="",n="",i=Object.keys(e),s=i.length;for(let a=0;a");return e+this.newLine}function Me(e,t,r,n){return r&&!e.includes("<")?this.indentate(n)+"<"+t+r+">"+e+""+this.options.tagValueProcessor(e)+"{"use strict";var $e=de(),Re=I(),Le=I(),Wt=T().buildOptions,xe=ve();y.parse=function(e,t,r){if(r){r===!0&&(r={});let i=xe.validate(e,r);if(i!==!0)throw Error(i.err.msg)}t=Wt(t,Le.defaultOptions,Le.props);let n=Re.getTraversalObj(e,t);return $e.convertToJson(n,t)};y.convertTonimn=we().convert2nimn;y.getTraversalObj=Re.getTraversalObj;y.convertToJson=$e.convertToJson;y.convertToJsonString=Se().convertToJsonString;y.validate=xe.validate;y.j2xParser=qe();y.parseToNimn=function(e,t,r){return y.convertTonimn(y.getTraversalObj(e,r),t,r)}});var Ge=b((Sr,ke)=>{var{spawn:Zt}=require("child_process"),Dt=(e,t=[],r={})=>new Promise((n,i)=>{let s="",a={...r};a.stdio||Object.assign(a,{stdio:["inherit","inherit","inherit"]});let o=Zt(e,t,a);o.stdout&&o.stdout.on("data",function(u){s+=u.toString()}),o.on("close",u=>u!==0?i({code:u,outputData:s}):n({code:u,outputData:s})),o.on("error",()=>i({code:1,outputData:s}))});ke.exports=Dt});var er=require("https"),Je=require("fs"),p=ae(),tr=Be(),V=Ge(),rr=p.getInput("goodreads_user_id"),nr=p.getInput("shelf"),sr=Number.parseInt(p.getInput("max_books_count")),B=p.getInput("readme_file_path"),ir=p.getInput("output_only").toLowerCase()==="true",or=p.getInput("template")||"- [$title]($url) by $author (\u2B50\uFE0F$average_rating)",ur="Synced and updated with user's goodreads book lists",ar="goodreads-books-bot",cr="goodreads-books-bot@example.com";lr(rr,nr).then(async e=>{try{let t=e.rss.channel.item.slice(0,sr),r=Je.readFileSync(B,"utf8"),n=fr(r,t);r!==n&&(p.info(`Writing to ${B}`),p.startGroup("New books found for update"),t.forEach(i=>p.info(JSON.stringify(i))),p.endGroup(),Je.writeFileSync(B,n),ir?(p.setOutput("books",t),p.info("OUTPUT_ONLY: set `results` variable. Readme not committed.")):await dr())}catch(t){p.error(t),process.exit(1)}}).then(()=>{process.exit(0)}).catch(e=>{p.error(e),process.exit(1)});function lr(e,t){return new Promise((r,n)=>{er.request({host:"www.goodreads.com",path:`/review/list_rss/${e}?shelf=${t}`},i=>{let s="";i.on("data",a=>s+=a),i.on("end",()=>r(tr.parse(s))),i.on("error",a=>n(a))}).end()})}function fr(e,t){let r=p.getInput("comment_tag_name")||"GOODREADS-LIST",n=``,i=``;if(![n,i].every(a=>e.match(new RegExp(a,"gm"))))p.error(`Cannot find the required comment tags (${n} and ${i}) to inject book titles.`),process.exit(1);else{let a=e.indexOf(n),o=e.indexOf(i),u=hr(t);return[e.substring(0,a+n.length),` +`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine=""),this.options.supressEmptyNode?(this.buildTextNode=Yt,this.buildObjNode=Xt):(this.buildTextNode=Fe,this.buildObjNode=Me),this.buildTextValNode=Fe,this.buildObjectNode=Me}X.prototype.parse=function(e){return this.j2x(e,0).val};X.prototype.j2x=function(e,t){let r="",n="",i=Object.keys(e),s=i.length;for(let a=0;a");return e+this.newLine}function Me(e,t,r,n){return r&&!e.includes("<")?this.indentate(n)+"<"+t+r+">"+e+""+this.options.tagValueProcessor(e)+"{"use strict";var $e=de(),Re=I(),Le=I(),Wt=T().buildOptions,xe=ve();y.parse=function(e,t,r){if(r){r===!0&&(r={});let i=xe.validate(e,r);if(i!==!0)throw Error(i.err.msg)}t=Wt(t,Le.defaultOptions,Le.props);let n=Re.getTraversalObj(e,t);return $e.convertToJson(n,t)};y.convertTonimn=we().convert2nimn;y.getTraversalObj=Re.getTraversalObj;y.convertToJson=$e.convertToJson;y.convertToJsonString=Se().convertToJsonString;y.validate=xe.validate;y.j2xParser=qe();y.parseToNimn=function(e,t,r){return y.convertTonimn(y.getTraversalObj(e,r),t,r)}});var Ge=b((Sr,ke)=>{var{spawn:Zt}=require("child_process"),Dt=(e,t=[],r={})=>new Promise((n,i)=>{let s="",a={...r};a.stdio||Object.assign(a,{stdio:["inherit","inherit","inherit"]});let o=Zt(e,t,a);o.stdout&&o.stdout.on("data",function(u){s+=u.toString()}),o.on("close",u=>u!==0?i({code:u,outputData:s}):n({code:u,outputData:s})),o.on("error",()=>i({code:1,outputData:s}))});ke.exports=Dt});var er=require("https"),Je=require("fs"),p=ae(),tr=Be(),V=Ge(),rr=p.getInput("goodreads_user_id"),nr=p.getInput("shelf"),sr=Number.parseInt(p.getInput("max_books_count")),B=p.getInput("readme_file_path"),ir=p.getInput("output_only").toLowerCase()==="true",or=p.getInput("template")||"- [$title]($url) by $author (\u2B50\uFE0F$average_rating)",ur="Synced and updated with user's goodreads book lists",ar="goodreads-books-bot",cr="goodreads-books-bot@example.com";lr(rr,nr).then(async e=>{try{if(!e.rss.channel.item)return;let r=(Array.isArray(e.rss.channel.item)?e.rss.channel.item:[e.rss.channel.item]).slice(0,sr),n=Je.readFileSync(B,"utf8"),i=fr(n,r);n!==i&&(p.info(`Writing to ${B}`),p.startGroup("New books found for update"),r.forEach(s=>p.info(JSON.stringify(s))),p.endGroup(),Je.writeFileSync(B,i),ir?(p.setOutput("books",r),p.info("OUTPUT_ONLY: set `results` variable. Readme not committed.")):await dr())}catch(t){p.error(t),process.exit(1)}}).then(()=>{process.exit(0)}).catch(e=>{p.error(e),process.exit(1)});function lr(e,t){return console.log("shelf",t),new Promise((r,n)=>{er.request({host:"www.goodreads.com",path:`/review/list_rss/${e}?shelf=${t}`},i=>{let s="";i.on("data",a=>s+=a),i.on("end",()=>r(tr.parse(s))),i.on("error",a=>n(a))}).end()})}function fr(e,t){let r=p.getInput("comment_tag_name")||"GOODREADS-LIST",n=``,i=``;if(![n,i].every(a=>e.match(new RegExp(a,"gm"))))p.error(`Cannot find the required comment tags (${n} and ${i}) to inject book titles.`),process.exit(1);else{let a=e.indexOf(n),o=e.indexOf(i),u=hr(t);return[e.substring(0,a+n.length),` `,u,` `,e.substring(o)].join("")}}function hr(e){return e.map(t=>gr(or,{title:t.title,url:t.link,author:t.author_name,published_year:t.book_published,average_rating:t.average_rating,my_rating:t.user_rating,my_rating_stars:t.user_rating?"\u2B50".repeat(Number.parseInt(t.user_rating||"0")):"unrated"})).join(` `)}function gr(e,t){let r=/\$([a-zA-Z_]*)/g;return e.replace(r,(n,i)=>t[i]||"")}async function dr(){await V("git",["config","--global","user.email",cr]),await V("git",["config","--global","user.name",ar]),await V("git",["add",B]),await V("git",["commit","-m",ur]),await V("git",["push"]),p.info("Readme updated successfully in the upstream repository"),process.exit(0)}