@topwrite/cli 1.0.24-alpha.5 → 1.0.24-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/ttx.js +1 -1
  2. package/package.json +2 -2
package/bin/ttx.js CHANGED
@@ -17,4 +17,4 @@
17
17
  * @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
18
18
  * @see http://sites.google.com/site/murmurhash/
19
19
  */
20
- !function(e){!function(){var t;function r(e,n){var i=this instanceof r?this:t;if(i.reset(n),"string"==typeof e&&e.length>0&&i.hash(e),i!==this)return i}r.prototype.hash=function(e){var t,r,n,i,a;switch(a=e.length,this.len+=a,r=this.k1,n=0,this.rem){case 0:r^=a>n?65535&e.charCodeAt(n++):0;case 1:r^=a>n?(65535&e.charCodeAt(n++))<<8:0;case 2:r^=a>n?(65535&e.charCodeAt(n++))<<16:0;case 3:r^=a>n?(255&e.charCodeAt(n))<<24:0,r^=a>n?(65280&e.charCodeAt(n++))>>8:0}if(this.rem=a+this.rem&3,(a-=this.rem)>0){for(t=this.h1;t=5*(t=(t^=r=13715*(r=(r=11601*r+3432906752*(65535&r)&4294967295)<<15|r>>>17)+461832192*(65535&r)&4294967295)<<13|t>>>19)+3864292196&4294967295,!(n>=a);)r=65535&e.charCodeAt(n++)^(65535&e.charCodeAt(n++))<<8^(65535&e.charCodeAt(n++))<<16,r^=(255&(i=e.charCodeAt(n++)))<<24^(65280&i)>>8;switch(r=0,this.rem){case 3:r^=(65535&e.charCodeAt(n+2))<<16;case 2:r^=(65535&e.charCodeAt(n+1))<<8;case 1:r^=65535&e.charCodeAt(n)}this.h1=t}return this.k1=r,this},r.prototype.result=function(){var e,t;return e=this.k1,t=this.h1,e>0&&(t^=e=13715*(e=(e=11601*e+3432906752*(65535&e)&4294967295)<<15|e>>>17)+461832192*(65535&e)&4294967295),t^=this.len,t=51819*(t^=t>>>16)+2246770688*(65535&t)&4294967295,t=44597*(t^=t>>>13)+3266445312*(65535&t)&4294967295,(t^=t>>>16)>>>0},r.prototype.reset=function(e){return this.h1="number"==typeof e?e:0,this.rem=this.k1=this.len=0,this},t=new r,e.exports=r}()}(gp);var vp={exports:{}},yp={exports:{}};!function(e){e.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"],"win32"!==process.platform&&e.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT"),"linux"===process.platform&&e.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")}(yp);var bp=ce.process;const wp=function(e){return e&&"object"==typeof e&&"function"==typeof e.removeListener&&"function"==typeof e.emit&&"function"==typeof e.reallyExit&&"function"==typeof e.listeners&&"function"==typeof e.kill&&"number"==typeof e.pid&&"function"==typeof e.on};if(wp(bp)){var xp,kp=N.default,Ep=yp.exports,Sp=/^win/i.test(bp.platform),Pp=ae.default;"function"!=typeof Pp&&(Pp=Pp.EventEmitter),bp.__signal_exit_emitter__?xp=bp.__signal_exit_emitter__:((xp=bp.__signal_exit_emitter__=new Pp).count=0,xp.emitted={}),xp.infinite||(xp.setMaxListeners(1/0),xp.infinite=!0),vp.exports=function(e,t){if(wp(ce.process)){kp.equal(typeof e,"function","a callback must be provided for exit handler"),!1===Fp&&Dp();var r="exit";t&&t.alwaysLast&&(r="afterexit");return xp.on(r,e),function(){xp.removeListener(r,e),0===xp.listeners("exit").length&&0===xp.listeners("afterexit").length&&_p()}}};var _p=function(){Fp&&wp(ce.process)&&(Fp=!1,Ep.forEach((function(e){try{bp.removeListener(e,Cp[e])}catch(e){}})),bp.emit=Tp,bp.reallyExit=Op,xp.count-=1)};vp.exports.unload=_p;var Ap=function(e,t,r){xp.emitted[e]||(xp.emitted[e]=!0,xp.emit(e,t,r))},Cp={};Ep.forEach((function(e){Cp[e]=function(){wp(ce.process)&&(bp.listeners(e).length===xp.count&&(_p(),Ap("exit",null,e),Ap("afterexit",null,e),Sp&&"SIGHUP"===e&&(e="SIGINT"),bp.kill(bp.pid,e)))}})),vp.exports.signals=function(){return Ep};var Fp=!1,Dp=function(){!Fp&&wp(ce.process)&&(Fp=!0,xp.count+=1,Ep=Ep.filter((function(e){try{return bp.on(e,Cp[e]),!0}catch(e){return!1}})),bp.emit=Ip,bp.reallyExit=Rp)};vp.exports.load=Dp;var Op=bp.reallyExit,Rp=function(e){wp(ce.process)&&(bp.exitCode=e||0,Ap("exit",bp.exitCode,null),Ap("afterexit",bp.exitCode,null),Op.call(bp,bp.exitCode))},Tp=bp.emit,Ip=function(e,t){if("exit"===e&&wp(ce.process)){void 0!==t&&(bp.exitCode=t);var r=Tp.apply(this,arguments);return Ap("exit",bp.exitCode,null),Ap("afterexit",bp.exitCode,null),r}return Tp.apply(this,arguments)}}else vp.exports=function(){};var jp=zp;zp.strict=Mp,zp.loose=Np;var Lp=Object.prototype.toString,qp={"[object Int8Array]":!0,"[object Int16Array]":!0,"[object Int32Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Uint16Array]":!0,"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0};function zp(e){return Mp(e)||Np(e)}function Mp(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}function Np(e){return qp[Lp.call(e)]}var Bp=jp.strict;mp.exports=function(e,t,r,n){r instanceof Function&&(n=r,r={});const i=async function(e,t,r={}){"string"==typeof r&&(r={encoding:r});let n,i;const a=Vp(Zp((()=>i))),o=Hp.resolve(e);try{await function(e){return new Promise((t=>{Kp[e]||(Kp[e]=[]),Kp[e].push(t),1===Kp[e].length&&t()}))}(o);const s=await Wp($p.realpath)(e).catch((()=>e));if(i=Xp(s),!r.mode||!r.chown){const e=await Wp($p.stat)(s).catch((()=>{}));e&&(null==r.mode&&(r.mode=e.mode),null==r.chown&&process.getuid&&(r.chown={uid:e.uid,gid:e.gid}))}n=await Wp($p.open)(i,"w",r.mode),r.tmpfileCreated&&await r.tmpfileCreated(i),Qp(t)&&(t=Gp(t)),Buffer.isBuffer(t)?await Wp($p.write)(n,t,0,t.length,0):null!=t&&await Wp($p.write)(n,String(t),0,String(r.encoding||"utf8")),!1!==r.fsync&&await Wp($p.fsync)(n),await Wp($p.close)(n),n=null,r.chown&&await Wp($p.chown)(i,r.chown.uid,r.chown.gid).catch((e=>{if(!ed(e))throw e})),r.mode&&await Wp($p.chmod)(i,r.mode).catch((e=>{if(!ed(e))throw e})),await Wp($p.rename)(i,s)}finally{n&&await Wp($p.close)(n).catch((()=>{})),a(),await Wp($p.unlink)(i).catch((()=>{})),Kp[o].shift(),Kp[o].length>0?Kp[o][0]():delete Kp[o]}}(e,t,r);n&&i.then(n,n);return i},mp.exports.sync=function(e,t,r){"string"==typeof r?r={encoding:r}:r||(r={});try{e=$p.realpathSync(e)}catch(e){}const n=Xp(e);if(!r.mode||!r.chown)try{const t=$p.statSync(e);(r=Object.assign({},r)).mode||(r.mode=t.mode),!r.chown&&process.getuid&&(r.chown={uid:t.uid,gid:t.gid})}catch(e){}let i;const a=Zp(n),o=Vp(a);let s=!0;try{if(i=$p.openSync(n,"w",r.mode||438),r.tmpfileCreated&&r.tmpfileCreated(n),Qp(t)&&(t=Gp(t)),Buffer.isBuffer(t)?$p.writeSync(i,t,0,t.length,0):null!=t&&$p.writeSync(i,String(t),0,String(r.encoding||"utf8")),!1!==r.fsync&&$p.fsyncSync(i),$p.closeSync(i),i=null,r.chown)try{$p.chownSync(n,r.chown.uid,r.chown.gid)}catch(e){if(!ed(e))throw e}if(r.mode)try{$p.chmodSync(n,r.mode)}catch(e){if(!ed(e))throw e}$p.renameSync(n,e),s=!1}finally{if(i)try{$p.closeSync(i)}catch(e){}o(),s&&a()}},mp.exports._getTmpname=Xp,mp.exports._cleanupOnExit=Zp;const $p=G.default,Up=gp.exports,Vp=vp.exports,Hp=j.default,Qp=jp,Gp=function(e){if(Bp(e)){var t=Buffer.from(e.buffer);return e.byteLength!==e.buffer.byteLength&&(t=t.slice(e.byteOffset,e.byteOffset+e.byteLength)),t}return Buffer.from(e)},{promisify:Wp}=ie.default,Kp={},Jp=function(){try{return require("worker_threads").threadId}catch(e){return 0}}();let Yp=0;function Xp(e){return e+"."+Up(__filename).hash(String(process.pid)).hash(String(Jp)).hash(String(++Yp)).result()}function Zp(e){return()=>{try{$p.unlinkSync("function"==typeof e?e():e)}catch(e){}}}function ed(e){if("ENOSYS"===e.code)return!0;return!(process.getuid&&0===process.getuid()||"EINVAL"!==e.code&&"EPERM"!==e.code)}var td=mp.exports;const rd=e=>{const t=typeof e;return null!==e&&("object"===t||"function"===t)},nd=new Set(["__proto__","prototype","constructor"]);function id(e){const t=e.split("."),r=[];for(let e=0;e<t.length;e++){let n=t[e];for(;"\\"===n[n.length-1]&&void 0!==t[e+1];)n=n.slice(0,-1)+".",n+=t[++e];r.push(n)}return r.some((e=>nd.has(e)))?[]:r}var ad={get(e,t,r){if(!rd(e)||"string"!=typeof t)return void 0===r?e:r;const n=id(t);if(0!==n.length){for(let t=0;t<n.length;t++)if(e=e[n[t]],null==e){if(t!==n.length-1)return r;break}return void 0===e?r:e}},set(e,t,r){if(!rd(e)||"string"!=typeof t)return e;const n=e,i=id(t);for(let t=0;t<i.length;t++){const n=i[t];rd(e[n])||(e[n]={}),t===i.length-1&&(e[n]=r),e=e[n]}return n},delete(e,t){if(!rd(e)||"string"!=typeof t)return!1;const r=id(t);for(let t=0;t<r.length;t++){const n=r[t];if(t===r.length-1)return delete e[n],!0;if(e=e[n],!rd(e))return!1}},has(e,t){if(!rd(e)||"string"!=typeof t)return!1;const r=id(t);if(0===r.length)return!1;for(let t=0;t<r.length;t++){if(!rd(e))return!1;if(!(r[t]in e))return!1;e=e[r[t]]}return!0}};const od=F.promisify(oe.default.randomBytes),sd="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~".split(""),cd="0123456789".split(""),ud="CDEHKMPRTUWXY012458".split(""),ld="!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".split(""),fd="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),hd=new Set([void 0,"hex","base64","url-safe","numeric","distinguishable","ascii-printable","alphanumeric"]),pd=(e,t)=>({length:r,type:n,characters:i})=>{if(!(r>=0&&Number.isFinite(r)))throw new TypeError("Expected a `length` to be a non-negative finite number");if(void 0!==n&&void 0!==i)throw new TypeError("Expected either `type` or `characters`");if(void 0!==i&&"string"!=typeof i)throw new TypeError("Expected `characters` to be string");if(!hd.has(n))throw new TypeError(`Unknown type: ${n}`);if(void 0===n&&void 0===i&&(n="hex"),"hex"===n||void 0===n&&void 0===i)return t(Math.ceil(.5*r),"hex",r);if("base64"===n)return t(Math.ceil(.75*r),"base64",r);if("url-safe"===n)return e(r,sd);if("numeric"===n)return e(r,cd);if("distinguishable"===n)return e(r,ud);if("ascii-printable"===n)return e(r,ld);if("alphanumeric"===n)return e(r,fd);if(0===i.length)throw new TypeError("Expected `characters` string length to be greater than or equal to 1");if(i.length>65536)throw new TypeError("Expected `characters` string length to be less or equal to 65536");return e(r,i.split(""))},dd=pd(((e,t)=>{const r=t.length,n=Math.floor(65536/r)*r-1,i=2*Math.ceil(1.1*e);let a="",o=0;for(;o<e;){const s=oe.default.randomBytes(i);let c=0;for(;c<i&&o<e;){const e=s.readUInt16LE(c);c+=2,e>n||(a+=t[e%r],o++)}}return a}),((e,t,r)=>oe.default.randomBytes(e).toString(t).slice(0,r)));dd.async=pd((async(e,t)=>{const r=t.length,n=Math.floor(65536/r)*r-1,i=2*Math.ceil(1.1*e);let a="",o=0;for(;o<e;){const s=await od(i);let c=0;for(;c<i&&o<e;){const e=s.readUInt16LE(c);c+=2,e>n||(a+=t[e%r],o++)}}return a}),(async(e,t,r)=>(await od(e)).toString(t).slice(0,r)));const md=hp||j.default.join(re.default.tmpdir(),dd({length:32})),gd={mode:448,recursive:!0},vd={mode:384};const yd=new class{constructor(e,t,r={}){const n=r.globalConfigPath?j.default.join(e,"config.json"):j.default.join("configstore",`${e}.json`);this._path=r.configPath||j.default.join(md,n),t&&(this.all={...t,...this.all})}get all(){try{return JSON.parse(cp.readFileSync(this._path,"utf8"))}catch(e){if("ENOENT"===e.code)return{};if("EACCES"===e.code&&(e.message=`${e.message}\nYou don't have access to this file.\n`),"SyntaxError"===e.name)return td.sync(this._path,"",vd),{};throw e}}set all(e){try{cp.mkdirSync(j.default.dirname(this._path),gd),td.sync(this._path,JSON.stringify(e,void 0,"\t"),vd)}catch(e){throw"EACCES"===e.code&&(e.message=`${e.message}\nYou don't have access to this file.\n`),e}}get size(){return Object.keys(this.all||{}).length}get(e){return ad.get(this.all,e)}set(e,t){const r=this.all;if(1===arguments.length)for(const t of Object.keys(e))ad.set(r,t,e[t]);else ad.set(r,e,t);this.all=r}has(e){return ad.has(this.all,e)}delete(e){const t=this.all;ad.delete(t,e),this.all=t}clear(){this.all={}}get path(){return this._path}}("ttx",{plugins_host:"https://plugins.x.topthink.com"});function bd(e){return e?yd.get(e):yd.all}fe.Summary.prototype.toObject=function(){return this.parts.map((function(e){return e.toObject()}))},fe.SummaryPart.prototype.toObject=function(){return{title:this.title,articles:this.articles.map((function(e){return e.toObject()}))}},fe.SummaryArticle.prototype.toObject=function(){return{title:this.title,ref:this.ref,path:this.path,children:this.children.map((function(e){return e.toObject()}))}};const wd=require("../package.json"),xd=new e.Command;xd.version(wd.version),xd.name("ttx"),xd.option("-d, --debug","output extra debugging"),xd.on("option:debug",(function(){se.level=n.LogLevel.Debug})),xd.command("build <id> <dir> <format> [dest]").option("--lfs <lfs>","lfs cdn url").option("--plugins_host <plugins_host>","plugins host").option("--preset_plugins <preset_plugins>","reset plugins").option("--no-clean","not clean").description("build book").action((async function(e,t,r,n,i){i.clean&&I.default.setGracefulCleanup(),se.info(`cli version ${wd.version}`);const a=j.default.resolve(t);n=n?j.default.resolve(n):j.default.join(a,"book.tar.gz");try{se.debug(i.preset_plugins);const a=i.preset_plugins?JSON.parse(i.preset_plugins):{},o={plugins:{host:i.plugins_host||bd("plugins_host"),preset:a}};i.lfs&&(o.lfs={url:i.lfs,files:{}});const s=await async function(e,t,r,n,i){if(void 0===jh[r])throw new Error("unsupported format: "+r);const a=jh[r],o=new Dh(t),s=fe.Config.createFromObject(await o.readAsObject(fe.Config.file)),c=o.resolve(s.getValue("root","")),u=I.default.dirSync({unsafeCleanup:!0}).name,l=new Dh(u);await J.default.copy(c,u),await J.default.copy(j.default.resolve(__dirname,"../templates/.bookignore"),l.resolve(".bookignore"));const f=fe.Summary.createFromText(await l.readAsString(s.getStructure("summary")));return new a(new fe.Book(e,s,f),o,l,n,i)}(e,t,r,o,n);await s.generate(),process.exit(0)}catch(e){se.error(e),process.exit(1)}}));const kd=xd.command("config");kd.command("list").action((function(){console.log(bd())})),kd.command("set <key> <value>").action((function(e,t){!function(e,t){yd.set(e,t)}(e,t)})),xd.parse(process.argv);
20
+ !function(e){!function(){var t;function r(e,n){var i=this instanceof r?this:t;if(i.reset(n),"string"==typeof e&&e.length>0&&i.hash(e),i!==this)return i}r.prototype.hash=function(e){var t,r,n,i,a;switch(a=e.length,this.len+=a,r=this.k1,n=0,this.rem){case 0:r^=a>n?65535&e.charCodeAt(n++):0;case 1:r^=a>n?(65535&e.charCodeAt(n++))<<8:0;case 2:r^=a>n?(65535&e.charCodeAt(n++))<<16:0;case 3:r^=a>n?(255&e.charCodeAt(n))<<24:0,r^=a>n?(65280&e.charCodeAt(n++))>>8:0}if(this.rem=a+this.rem&3,(a-=this.rem)>0){for(t=this.h1;t=5*(t=(t^=r=13715*(r=(r=11601*r+3432906752*(65535&r)&4294967295)<<15|r>>>17)+461832192*(65535&r)&4294967295)<<13|t>>>19)+3864292196&4294967295,!(n>=a);)r=65535&e.charCodeAt(n++)^(65535&e.charCodeAt(n++))<<8^(65535&e.charCodeAt(n++))<<16,r^=(255&(i=e.charCodeAt(n++)))<<24^(65280&i)>>8;switch(r=0,this.rem){case 3:r^=(65535&e.charCodeAt(n+2))<<16;case 2:r^=(65535&e.charCodeAt(n+1))<<8;case 1:r^=65535&e.charCodeAt(n)}this.h1=t}return this.k1=r,this},r.prototype.result=function(){var e,t;return e=this.k1,t=this.h1,e>0&&(t^=e=13715*(e=(e=11601*e+3432906752*(65535&e)&4294967295)<<15|e>>>17)+461832192*(65535&e)&4294967295),t^=this.len,t=51819*(t^=t>>>16)+2246770688*(65535&t)&4294967295,t=44597*(t^=t>>>13)+3266445312*(65535&t)&4294967295,(t^=t>>>16)>>>0},r.prototype.reset=function(e){return this.h1="number"==typeof e?e:0,this.rem=this.k1=this.len=0,this},t=new r,e.exports=r}()}(gp);var vp={exports:{}},yp={exports:{}};!function(e){e.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"],"win32"!==process.platform&&e.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT"),"linux"===process.platform&&e.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")}(yp);var bp=ce.process;const wp=function(e){return e&&"object"==typeof e&&"function"==typeof e.removeListener&&"function"==typeof e.emit&&"function"==typeof e.reallyExit&&"function"==typeof e.listeners&&"function"==typeof e.kill&&"number"==typeof e.pid&&"function"==typeof e.on};if(wp(bp)){var xp,kp=N.default,Ep=yp.exports,Sp=/^win/i.test(bp.platform),Pp=ae.default;"function"!=typeof Pp&&(Pp=Pp.EventEmitter),bp.__signal_exit_emitter__?xp=bp.__signal_exit_emitter__:((xp=bp.__signal_exit_emitter__=new Pp).count=0,xp.emitted={}),xp.infinite||(xp.setMaxListeners(1/0),xp.infinite=!0),vp.exports=function(e,t){if(wp(ce.process)){kp.equal(typeof e,"function","a callback must be provided for exit handler"),!1===Fp&&Dp();var r="exit";t&&t.alwaysLast&&(r="afterexit");return xp.on(r,e),function(){xp.removeListener(r,e),0===xp.listeners("exit").length&&0===xp.listeners("afterexit").length&&_p()}}};var _p=function(){Fp&&wp(ce.process)&&(Fp=!1,Ep.forEach((function(e){try{bp.removeListener(e,Cp[e])}catch(e){}})),bp.emit=Tp,bp.reallyExit=Op,xp.count-=1)};vp.exports.unload=_p;var Ap=function(e,t,r){xp.emitted[e]||(xp.emitted[e]=!0,xp.emit(e,t,r))},Cp={};Ep.forEach((function(e){Cp[e]=function(){wp(ce.process)&&(bp.listeners(e).length===xp.count&&(_p(),Ap("exit",null,e),Ap("afterexit",null,e),Sp&&"SIGHUP"===e&&(e="SIGINT"),bp.kill(bp.pid,e)))}})),vp.exports.signals=function(){return Ep};var Fp=!1,Dp=function(){!Fp&&wp(ce.process)&&(Fp=!0,xp.count+=1,Ep=Ep.filter((function(e){try{return bp.on(e,Cp[e]),!0}catch(e){return!1}})),bp.emit=Ip,bp.reallyExit=Rp)};vp.exports.load=Dp;var Op=bp.reallyExit,Rp=function(e){wp(ce.process)&&(bp.exitCode=e||0,Ap("exit",bp.exitCode,null),Ap("afterexit",bp.exitCode,null),Op.call(bp,bp.exitCode))},Tp=bp.emit,Ip=function(e,t){if("exit"===e&&wp(ce.process)){void 0!==t&&(bp.exitCode=t);var r=Tp.apply(this,arguments);return Ap("exit",bp.exitCode,null),Ap("afterexit",bp.exitCode,null),r}return Tp.apply(this,arguments)}}else vp.exports=function(){};var jp=zp;zp.strict=Mp,zp.loose=Np;var Lp=Object.prototype.toString,qp={"[object Int8Array]":!0,"[object Int16Array]":!0,"[object Int32Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Uint16Array]":!0,"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0};function zp(e){return Mp(e)||Np(e)}function Mp(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}function Np(e){return qp[Lp.call(e)]}var Bp=jp.strict;mp.exports=function(e,t,r,n){r instanceof Function&&(n=r,r={});const i=async function(e,t,r={}){"string"==typeof r&&(r={encoding:r});let n,i;const a=Vp(Zp((()=>i))),o=Hp.resolve(e);try{await function(e){return new Promise((t=>{Kp[e]||(Kp[e]=[]),Kp[e].push(t),1===Kp[e].length&&t()}))}(o);const s=await Wp($p.realpath)(e).catch((()=>e));if(i=Xp(s),!r.mode||!r.chown){const e=await Wp($p.stat)(s).catch((()=>{}));e&&(null==r.mode&&(r.mode=e.mode),null==r.chown&&process.getuid&&(r.chown={uid:e.uid,gid:e.gid}))}n=await Wp($p.open)(i,"w",r.mode),r.tmpfileCreated&&await r.tmpfileCreated(i),Qp(t)&&(t=Gp(t)),Buffer.isBuffer(t)?await Wp($p.write)(n,t,0,t.length,0):null!=t&&await Wp($p.write)(n,String(t),0,String(r.encoding||"utf8")),!1!==r.fsync&&await Wp($p.fsync)(n),await Wp($p.close)(n),n=null,r.chown&&await Wp($p.chown)(i,r.chown.uid,r.chown.gid).catch((e=>{if(!ed(e))throw e})),r.mode&&await Wp($p.chmod)(i,r.mode).catch((e=>{if(!ed(e))throw e})),await Wp($p.rename)(i,s)}finally{n&&await Wp($p.close)(n).catch((()=>{})),a(),await Wp($p.unlink)(i).catch((()=>{})),Kp[o].shift(),Kp[o].length>0?Kp[o][0]():delete Kp[o]}}(e,t,r);n&&i.then(n,n);return i},mp.exports.sync=function(e,t,r){"string"==typeof r?r={encoding:r}:r||(r={});try{e=$p.realpathSync(e)}catch(e){}const n=Xp(e);if(!r.mode||!r.chown)try{const t=$p.statSync(e);(r=Object.assign({},r)).mode||(r.mode=t.mode),!r.chown&&process.getuid&&(r.chown={uid:t.uid,gid:t.gid})}catch(e){}let i;const a=Zp(n),o=Vp(a);let s=!0;try{if(i=$p.openSync(n,"w",r.mode||438),r.tmpfileCreated&&r.tmpfileCreated(n),Qp(t)&&(t=Gp(t)),Buffer.isBuffer(t)?$p.writeSync(i,t,0,t.length,0):null!=t&&$p.writeSync(i,String(t),0,String(r.encoding||"utf8")),!1!==r.fsync&&$p.fsyncSync(i),$p.closeSync(i),i=null,r.chown)try{$p.chownSync(n,r.chown.uid,r.chown.gid)}catch(e){if(!ed(e))throw e}if(r.mode)try{$p.chmodSync(n,r.mode)}catch(e){if(!ed(e))throw e}$p.renameSync(n,e),s=!1}finally{if(i)try{$p.closeSync(i)}catch(e){}o(),s&&a()}},mp.exports._getTmpname=Xp,mp.exports._cleanupOnExit=Zp;const $p=G.default,Up=gp.exports,Vp=vp.exports,Hp=j.default,Qp=jp,Gp=function(e){if(Bp(e)){var t=Buffer.from(e.buffer);return e.byteLength!==e.buffer.byteLength&&(t=t.slice(e.byteOffset,e.byteOffset+e.byteLength)),t}return Buffer.from(e)},{promisify:Wp}=ie.default,Kp={},Jp=function(){try{return require("worker_threads").threadId}catch(e){return 0}}();let Yp=0;function Xp(e){return e+"."+Up(__filename).hash(String(process.pid)).hash(String(Jp)).hash(String(++Yp)).result()}function Zp(e){return()=>{try{$p.unlinkSync("function"==typeof e?e():e)}catch(e){}}}function ed(e){if("ENOSYS"===e.code)return!0;return!(process.getuid&&0===process.getuid()||"EINVAL"!==e.code&&"EPERM"!==e.code)}var td=mp.exports;const rd=e=>{const t=typeof e;return null!==e&&("object"===t||"function"===t)},nd=new Set(["__proto__","prototype","constructor"]);function id(e){const t=e.split("."),r=[];for(let e=0;e<t.length;e++){let n=t[e];for(;"\\"===n[n.length-1]&&void 0!==t[e+1];)n=n.slice(0,-1)+".",n+=t[++e];r.push(n)}return r.some((e=>nd.has(e)))?[]:r}var ad={get(e,t,r){if(!rd(e)||"string"!=typeof t)return void 0===r?e:r;const n=id(t);if(0!==n.length){for(let t=0;t<n.length;t++)if(e=e[n[t]],null==e){if(t!==n.length-1)return r;break}return void 0===e?r:e}},set(e,t,r){if(!rd(e)||"string"!=typeof t)return e;const n=e,i=id(t);for(let t=0;t<i.length;t++){const n=i[t];rd(e[n])||(e[n]={}),t===i.length-1&&(e[n]=r),e=e[n]}return n},delete(e,t){if(!rd(e)||"string"!=typeof t)return!1;const r=id(t);for(let t=0;t<r.length;t++){const n=r[t];if(t===r.length-1)return delete e[n],!0;if(e=e[n],!rd(e))return!1}},has(e,t){if(!rd(e)||"string"!=typeof t)return!1;const r=id(t);if(0===r.length)return!1;for(let t=0;t<r.length;t++){if(!rd(e))return!1;if(!(r[t]in e))return!1;e=e[r[t]]}return!0}};const od=F.promisify(oe.default.randomBytes),sd="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~".split(""),cd="0123456789".split(""),ud="CDEHKMPRTUWXY012458".split(""),ld="!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".split(""),fd="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),hd=new Set([void 0,"hex","base64","url-safe","numeric","distinguishable","ascii-printable","alphanumeric"]),pd=(e,t)=>({length:r,type:n,characters:i})=>{if(!(r>=0&&Number.isFinite(r)))throw new TypeError("Expected a `length` to be a non-negative finite number");if(void 0!==n&&void 0!==i)throw new TypeError("Expected either `type` or `characters`");if(void 0!==i&&"string"!=typeof i)throw new TypeError("Expected `characters` to be string");if(!hd.has(n))throw new TypeError(`Unknown type: ${n}`);if(void 0===n&&void 0===i&&(n="hex"),"hex"===n||void 0===n&&void 0===i)return t(Math.ceil(.5*r),"hex",r);if("base64"===n)return t(Math.ceil(.75*r),"base64",r);if("url-safe"===n)return e(r,sd);if("numeric"===n)return e(r,cd);if("distinguishable"===n)return e(r,ud);if("ascii-printable"===n)return e(r,ld);if("alphanumeric"===n)return e(r,fd);if(0===i.length)throw new TypeError("Expected `characters` string length to be greater than or equal to 1");if(i.length>65536)throw new TypeError("Expected `characters` string length to be less or equal to 65536");return e(r,i.split(""))},dd=pd(((e,t)=>{const r=t.length,n=Math.floor(65536/r)*r-1,i=2*Math.ceil(1.1*e);let a="",o=0;for(;o<e;){const s=oe.default.randomBytes(i);let c=0;for(;c<i&&o<e;){const e=s.readUInt16LE(c);c+=2,e>n||(a+=t[e%r],o++)}}return a}),((e,t,r)=>oe.default.randomBytes(e).toString(t).slice(0,r)));dd.async=pd((async(e,t)=>{const r=t.length,n=Math.floor(65536/r)*r-1,i=2*Math.ceil(1.1*e);let a="",o=0;for(;o<e;){const s=await od(i);let c=0;for(;c<i&&o<e;){const e=s.readUInt16LE(c);c+=2,e>n||(a+=t[e%r],o++)}}return a}),(async(e,t,r)=>(await od(e)).toString(t).slice(0,r)));const md=hp||j.default.join(re.default.tmpdir(),dd({length:32})),gd={mode:448,recursive:!0},vd={mode:384};const yd=new class{constructor(e,t,r={}){const n=r.globalConfigPath?j.default.join(e,"config.json"):j.default.join("configstore",`${e}.json`);this._path=r.configPath||j.default.join(md,n),t&&(this.all={...t,...this.all})}get all(){try{return JSON.parse(cp.readFileSync(this._path,"utf8"))}catch(e){if("ENOENT"===e.code)return{};if("EACCES"===e.code&&(e.message=`${e.message}\nYou don't have access to this file.\n`),"SyntaxError"===e.name)return td.sync(this._path,"",vd),{};throw e}}set all(e){try{cp.mkdirSync(j.default.dirname(this._path),gd),td.sync(this._path,JSON.stringify(e,void 0,"\t"),vd)}catch(e){throw"EACCES"===e.code&&(e.message=`${e.message}\nYou don't have access to this file.\n`),e}}get size(){return Object.keys(this.all||{}).length}get(e){return ad.get(this.all,e)}set(e,t){const r=this.all;if(1===arguments.length)for(const t of Object.keys(e))ad.set(r,t,e[t]);else ad.set(r,e,t);this.all=r}has(e){return ad.has(this.all,e)}delete(e){const t=this.all;ad.delete(t,e),this.all=t}clear(){this.all={}}get path(){return this._path}}("ttx",{plugins_host:"https://plugins.x.topthink.com"});function bd(e){return e?yd.get(e):yd.all}fe.Summary.prototype.toObject=function(){return this.parts.map((function(e){return e.toObject()}))},fe.SummaryPart.prototype.toObject=function(){return{id:this.id,title:this.title,articles:this.articles.map((function(e){return e.toObject()}))}},fe.SummaryArticle.prototype.toObject=function(){return{title:this.title,ref:this.ref,path:this.path,children:this.children.map((function(e){return e.toObject()}))}};const wd=require("../package.json"),xd=new e.Command;xd.version(wd.version),xd.name("ttx"),xd.option("-d, --debug","output extra debugging"),xd.on("option:debug",(function(){se.level=n.LogLevel.Debug})),xd.command("build <id> <dir> <format> [dest]").option("--lfs <lfs>","lfs cdn url").option("--plugins_host <plugins_host>","plugins host").option("--preset_plugins <preset_plugins>","reset plugins").option("--no-clean","not clean").description("build book").action((async function(e,t,r,n,i){i.clean&&I.default.setGracefulCleanup(),se.info(`cli version ${wd.version}`);const a=j.default.resolve(t);n=n?j.default.resolve(n):j.default.join(a,"book.tar.gz");try{se.debug(i.preset_plugins);const a=i.preset_plugins?JSON.parse(i.preset_plugins):{},o={plugins:{host:i.plugins_host||bd("plugins_host"),preset:a}};i.lfs&&(o.lfs={url:i.lfs,files:{}});const s=await async function(e,t,r,n,i){if(void 0===jh[r])throw new Error("unsupported format: "+r);const a=jh[r],o=new Dh(t),s=fe.Config.createFromObject(await o.readAsObject(fe.Config.file)),c=o.resolve(s.getValue("root","")),u=I.default.dirSync({unsafeCleanup:!0}).name,l=new Dh(u);await J.default.copy(c,u),await J.default.copy(j.default.resolve(__dirname,"../templates/.bookignore"),l.resolve(".bookignore"));const f=fe.Summary.createFromText(await l.readAsString(s.getStructure("summary")));return new a(new fe.Book(e,s,f),o,l,n,i)}(e,t,r,o,n);await s.generate(),process.exit(0)}catch(e){se.error(e),process.exit(1)}}));const kd=xd.command("config");kd.command("list").action((function(){console.log(bd())})),kd.command("set <key> <value>").action((function(e,t){!function(e,t){yd.set(e,t)}(e,t)})),xd.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topwrite/cli",
3
- "version": "1.0.24-alpha.5+6e3a33c",
3
+ "version": "1.0.24-alpha.6+1b19e7c",
4
4
  "author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
5
5
  "files": [
6
6
  "bin",
@@ -68,5 +68,5 @@
68
68
  "bin": {
69
69
  "ttx": "./bin/ttx.js"
70
70
  },
71
- "gitHead": "6e3a33caa7ff6423e65580393a54c218a6ca4cb4"
71
+ "gitHead": "1b19e7c93afb758d04d3041f48b4f6b967aa31cc"
72
72
  }