mdat 0.5.0 → 0.5.2

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.
package/bin/cli.js CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import{defaultLoaders as vn}from"cosmiconfig";function Se(t,e){let n=vn[".json"],i=n(t,e);return ht(i)}function ht(t,e="",n={}){for(let[i,o]of Object.entries(t)){let r=e?`${e}.${i}`:i;typeof o=="object"&&o!==null&&!Array.isArray(o)?ht(o,r,n):o===null?n[r]="null":n[r]=o.toString()}return n}import Tn from"node:fs";import O from"node:path";import{packageUp as $n}from"package-up";import{isFileSync as yt}from"path-type";import Nn from"untildify";function An(t,e){let n=e===0?1:Math.floor(Math.log10(Math.abs(e))+1);return t.toString().padStart(n,"0")}function bt(t,e,n,i){let o=[];for(let[r,a]of t.entries()){let s=n&&t.length>1?`-${An(r+1,t.length+1)}`:"",m=_n(a,e,n,i,s);o.push(m)}return o}function _n(t,e,n,i,o=""){let r=wt(t),a=e?wt(e):void 0;if(!yt(r))throw new Error(`Input file not found: "${r}"`);if(a){if(yt(a))throw new Error(`Output path must be a directory, received a file path: "${a}"`);Tn.mkdirSync(a,{recursive:!0})}let s=n?O.basename(n,O.extname(n)):O.basename(r,O.extname(r)),m=`.${i??(n&&O.extname(n)!==""?O.extname(n):O.extname(t)===""?"":O.extname(t))}`,d=`${s}${o}${m}`,c=a??O.dirname(r);return{input:r,name:d,output:c}}function wt(t){return Nn(t)}async function X(){return $n()}function Q(t){return t==null?[]:Array.isArray(t)?t:[t]}import Ct from"chalk";import{cosmiconfig as Pt}from"cosmiconfig";import In from"node:fs/promises";import Rt from"node:path";import Mn from"plur";import{readPackage as Dn}from"read-pkg";import{deepMergeDefined as ke,log as b,optionsSchema as jn,rulesSchema as Fn}from"remark-mdat";import{z as Ee}from"zod";var Ot=jn.merge(Ee.object({assetsPath:Ee.string().optional(),packageFile:Ee.string().optional()})).describe("Config Extension");async function L(t){let{additionalConfig:e,additionalRules:n,searchFrom:i}=t??{},o={addMetaComment:!1,assetsPath:"./assets",closingPrefix:"/",keywordPrefix:"",metaCommentIdentifier:"+",packageFile:await X(),rules:{mdat:"Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat)."}},r=Pt("mdat"),a=await r.search(i);if(a){let{config:s,filepath:m}=a;b.info(`Using config from "${m}"`);let d=xt(s,Ot);d&&(o=ke(o,d))}if(e!==void 0){let s=Array.isArray(e)?e:[e];for(let m of s){let d;if(typeof m=="string"){let p=await r.load(m);if(p==null)continue;let{config:g,filepath:y}=p;b.info(`Loaded additional config from "${y}"`),d=g}else d=m;if(d===void 0)continue;b.info("Merging configuration object");let c=xt(d,Ot);c!==void 0&&(o=ke(o,c))}}if(n!==void 0){let s=Array.isArray(n)?n:[n],m=Pt("mdat",{loaders:{".json":Se}});for(let d of s){let c;if(typeof d=="string"){let g;if(Rt.basename(d).endsWith("package.json")){let I=await In.readFile(d,"utf8");g={config:Se(d,I),filepath:d}}else g=await m.load(d);if(g==null)continue;let{config:y,filepath:w}=g;b.info(`Loaded additional config from "${w}"`),c=y}else c=d;if(c===void 0)continue;b.info("Merging rules into configuration object");let p=Un(c,Fn);p!==void 0&&(o=ke(o,p))}}if(o.rules){let s=Object.keys(o.rules).sort().map(m=>`"${Ct.bold.green(m)}"`);b.info(`Loaded ${Ct.bold(s.length)} mdat comment expansion ${Mn("rule",s.length)}:`);for(let m of s)b.info(` ${m}`)}else b.error("No rules loaded from additional configurations or rules, using default.");return ee=o,o}function Un(t,e){if(e.safeParse(t).success)return{rules:t};b.error(`Rules object has the wrong shape. Ignoring and using default configuration:
2
+ import{defaultLoaders as vn}from"cosmiconfig";function Se(t,e){let n=vn[".json"],i=n(t,e);return ht(i)}function ht(t,e="",n={}){for(let[i,o]of Object.entries(t)){let r=e?`${e}.${i}`:i;typeof o=="object"&&o!==null&&!Array.isArray(o)?ht(o,r,n):o===null?n[r]="null":n[r]=o.toString()}return n}import Tn from"node:fs";import O from"node:path";import{packageUp as $n}from"package-up";import{isFileSync as yt}from"path-type";import Nn from"untildify";function An(t,e){let n=e===0?1:Math.floor(Math.log10(Math.abs(e))+1);return t.toString().padStart(n,"0")}function bt(t,e,n,i){let o=[];for(let[r,a]of t.entries()){let s=n&&t.length>1?`-${An(r+1,t.length+1)}`:"",d=_n(a,e,n,i,s);o.push(d)}return o}function _n(t,e,n,i,o=""){let r=wt(t),a=e?wt(e):void 0;if(!yt(r))throw new Error(`Input file not found: "${r}"`);if(a){if(yt(a))throw new Error(`Output path must be a directory, received a file path: "${a}"`);Tn.mkdirSync(a,{recursive:!0})}let s=n?O.basename(n,O.extname(n)):O.basename(r,O.extname(r)),d=`.${i??(n&&O.extname(n)!==""?O.extname(n):O.extname(t)===""?"":O.extname(t))}`,m=`${s}${o}${d}`,c=a??O.dirname(r);return{input:r,name:m,output:c}}function wt(t){return Nn(t)}async function X(){return $n()}function Q(t){return t==null?[]:Array.isArray(t)?t:[t]}import Ct from"chalk";import{cosmiconfig as Pt}from"cosmiconfig";import In from"node:fs/promises";import Rt from"node:path";import Mn from"plur";import{readPackage as Dn}from"read-pkg";import{deepMergeDefined as ke,log as b,optionsSchema as jn,rulesSchema as Fn}from"remark-mdat";import{z as Ee}from"zod";var Ot=jn.merge(Ee.object({assetsPath:Ee.string().optional(),packageFile:Ee.string().optional()})).describe("Config Extension");async function L(t){let{additionalConfig:e,additionalRules:n,searchFrom:i}=t??{},o={addMetaComment:!1,assetsPath:"./assets",closingPrefix:"/",keywordPrefix:"",metaCommentIdentifier:"+",packageFile:await X(),rules:{mdat:"Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat)."}},r=Pt("mdat"),a=await r.search(i);if(a){let{config:s,filepath:d}=a;b.info(`Using config from "${d}"`);let m=xt(s,Ot);m&&(o=ke(o,m))}if(e!==void 0){let s=Array.isArray(e)?e:[e];for(let d of s){let m;if(typeof d=="string"){let p=await r.load(d);if(p==null)continue;let{config:g,filepath:y}=p;b.info(`Loaded additional config from "${y}"`),m=g}else m=d;if(m===void 0)continue;b.info("Merging configuration object");let c=xt(m,Ot);c!==void 0&&(o=ke(o,c))}}if(n!==void 0){let s=Array.isArray(n)?n:[n],d=Pt("mdat",{loaders:{".json":Se}});for(let m of s){let c;if(typeof m=="string"){let g;if(Rt.basename(m).endsWith("package.json")){let I=await In.readFile(m,"utf8");g={config:Se(m,I),filepath:m}}else g=await d.load(m);if(g==null)continue;let{config:y,filepath:w}=g;b.info(`Loaded additional config from "${w}"`),c=y}else c=m;if(c===void 0)continue;b.info("Merging rules into configuration object");let p=Un(c,Fn);p!==void 0&&(o=ke(o,p))}}if(o.rules){let s=Object.keys(o.rules).sort().map(d=>`"${Ct.bold.green(d)}"`);b.info(`Loaded ${Ct.bold(s.length)} mdat comment expansion ${Mn("rule",s.length)}:`);for(let d of s)b.info(` ${d}`)}else b.error("No rules loaded from additional configurations or rules, using default.");return ee=o,o}function Un(t,e){if(e.safeParse(t).success)return{rules:t};b.error(`Rules object has the wrong shape. Ignoring and using default configuration:
3
3
  ${JSON.stringify(t,void 0,2)}`)}function xt(t,e){if(e.safeParse(t).success)return t;b.error(`Config object has the wrong shape. Ignoring and using default configuration:
4
- ${JSON.stringify(t,void 0,2)}`)}var ee;async function P(){return ee===void 0&&(b.warn("getConfig(): config was undefined"),ee??=await L()),ee}var Le;async function h(){let{packageFile:t}=await P();if(t===void 0)throw new Error("No packageFile found or set in config");if(Le??=await Dn({cwd:Rt.dirname(t)}),Le===void 0)throw new Error("No package.json found");return Le}import{remark as ve}from"remark";import Te from"remark-gfm";import{mdatCheck as Vn,mdatClean as St,mdatExpand as Bn,mdatSplit as kt}from"remark-mdat";import{read as Jn}from"to-vfile";import{VFile as Ci}from"vfile";async function R(t,e,n,i,o,r,a){let s=await e({additionalConfig:r,additionalRules:a});r=s;let m=Q(t),d=bt(m,o,i,"md"),c=[],p=n(s);for(let{input:g,name:y,output:w}of d){let I=await Jn(g),Z=await p.process(I);Z.dirname=w,Z.basename=y,c.push(Z)}return c}function te(t){return ve().use({settings:{bullet:"-",emphasis:"_"}}).use(Te).use(()=>async function(n,i){kt(n,i),St(n,i,t),await Bn(n,i,t)})}function ne(t){return ve().use({settings:{bullet:"-",emphasis:"_"}}).use(Te).use(()=>function(n,i){kt(n,i),St(n,i,t)})}function oe(t){return ve().use({settings:{bullet:"-",emphasis:"_"}}).use(Te).use(()=>async function(n,i){await Vn(n,i,{...t,paranoid:!1})})}async function Et(t,e,n,i,o){return R(t,L,te,e,n,i,o)}async function Lt(t,e,n,i,o){return R(t,L,oe,e,n,i,o)}async function vt(t,e,n,i,o){return R(t,L,ne,e,n,i,o)}import{z as B}from"zod";var ie={badges:{async content(t){var a;let e=B.object({custom:B.record(B.object({image:B.string(),link:B.string()})).optional()}).optional().parse(t),n=await h(),{name:i}=n,o=[];!n.private&&((a=n.publishConfig)==null?void 0:a.access)==="public"&&o.push(`[![NPM Package](https://img.shields.io/npm/v/${i}.svg)](https://npmjs.com/package/${i})`);let{license:r}=n;if(r!==void 0&&o.push(`[![License: ${r}](https://img.shields.io/badge/License-${r}-yellow.svg)](https://opensource.org/licenses/${r})`),(e==null?void 0:e.custom)!==void 0)for(let[s,{image:m,link:d}]of Object.entries(e.custom))o.push(`[![${s}](${m})](${d})`);return o.join(`
4
+ ${JSON.stringify(t,void 0,2)}`)}var ee;async function P(){return ee===void 0&&(b.warn("getConfig(): config was undefined"),ee??=await L()),ee}var Le;async function h(){let{packageFile:t}=await P();if(t===void 0)throw new Error("No packageFile found or set in config");if(Le??=await Dn({cwd:Rt.dirname(t)}),Le===void 0)throw new Error("No package.json found");return Le}import{remark as ve}from"remark";import Te from"remark-gfm";import{mdatCheck as Vn,mdatClean as St,mdatExpand as Bn,mdatSplit as kt}from"remark-mdat";import{read as Jn}from"to-vfile";import{VFile as Ci}from"vfile";async function R(t,e,n,i,o,r,a){let s=await e({additionalConfig:r,additionalRules:a});r=s;let d=Q(t),m=bt(d,o,i,"md"),c=[],p=n(s);for(let{input:g,name:y,output:w}of m){let I=await Jn(g),Z=await p.process(I);Z.dirname=w,Z.basename=y,c.push(Z)}return c}function te(t){return ve().use({settings:{bullet:"-",emphasis:"_"}}).use(Te).use(()=>async function(n,i){kt(n,i),St(n,i,t),await Bn(n,i,t)})}function ne(t){return ve().use({settings:{bullet:"-",emphasis:"_"}}).use(Te).use(()=>function(n,i){kt(n,i),St(n,i,t)})}function oe(t){return ve().use({settings:{bullet:"-",emphasis:"_"}}).use(Te).use(()=>async function(n,i){await Vn(n,i,{...t,paranoid:!1})})}async function Et(t,e,n,i,o){return R(t,L,te,e,n,i,o)}async function Lt(t,e,n,i,o){return R(t,L,oe,e,n,i,o)}async function vt(t,e,n,i,o){return R(t,L,ne,e,n,i,o)}import{z as B}from"zod";var ie={badges:{async content(t){var a;let e=B.object({custom:B.record(B.object({image:B.string(),link:B.string()})).optional()}).optional().parse(t),n=await h(),{name:i}=n,o=[];!n.private&&((a=n.publishConfig)==null?void 0:a.access)==="public"&&o.push(`[![NPM Package](https://img.shields.io/npm/v/${i}.svg)](https://npmjs.com/package/${i})`);let{license:r}=n;if(r!==void 0&&o.push(`[![License: ${r}](https://img.shields.io/badge/License-${r}-yellow.svg)](https://opensource.org/licenses/${r})`),(e==null?void 0:e.custom)!==void 0)for(let[s,{image:d,link:m}]of Object.entries(e.custom))o.push(`[![${s}](${d})](${m})`);return o.join(`
5
5
  `)},order:3,required:!1}};import{globby as qn}from"globby";import re from"node:path";import{isFile as zn}from"path-type";import{readPackage as Gn}from"read-pkg";import{z as $e}from"zod";async function Kn(t){let{packageFile:e}=await P();if(e===void 0)throw new Error("No package.json found");let n=re.dirname(e),i=t===void 0?[".","assets","media","readme-assets","readme-media","readme","images"]:[t],o=["banner","header","logo","readme","cover","screenshot","screenshots","demo","overview","image","hero"],r=["png","gif","jpg","jpeg","svg","webp"],a=await qn(i.map(s=>re.join(n,s)),{expandDirectories:{extensions:r,files:o}});if(a.length>0)return re.relative(process.cwd(),a[0])}var ae={banner:{async content(t){let e=$e.object({alt:$e.string().optional(),src:$e.string().optional()}).optional().parse(t),{assetsPath:n,packageFile:i}=await P();if(i===void 0)throw new Error("No package.json found");let o=(e==null?void 0:e.src)??await Kn(n);if(o===void 0||!await zn(o))throw new Error(`Banner image not found at ${o===void 0?"any typical location, consider adding something at ./assets/banner.webp":`"${o}"`}`);let r=(e==null?void 0:e.alt)??`${(await Gn({cwd:re.dirname(i)})).name} banner`;if(r===void 0||r==="undefined banner")throw new Error("Banner image alt text not available");return`![${r}](${o})`},order:2}};function Tt(t,e=Number.MAX_SAFE_INTEGER){let n=[],i=Wn(t,e);return n.push(Yn(i)),n.push(Zn(t,i)),i.hasMultipleSubcommands&&i.canRecurse&&n.push(Xn(i.fullCommandName)),i.defaultCommand&&n.push(Qn(i)),n.push(eo(t,i)),t.positionals&&!i.commandsOnly&&n.push(Ne(["Positional Argument","Description","Type","Default"],t.positionals.map(o=>[o.arguments?[o.arguments.map(r=>`\`${r}\``)].join(" "):"",`${o.description??""}${o.required?" _(Required.)_":" _(Optional.)_"}`,o.type?`\`${o.type}\``:"",o.defaultValue?o.defaultValue.includes(" ")?o.defaultValue:`\`${o.defaultValue}\``:""]))),t.commands&&n.push(Ne(["Command","Argument","Description"],t.commands.map(o=>{var r;return[`\`${o.commandName??(o.default?"[default]":"")}\``,o.arguments?(r=o.arguments)==null?void 0:r.map(a=>`\`${a}\``).join(" "):"",`${o.description??""}${o.default?" _(Default command.)_":""}`]}))),t.options&&!i.commandsOnly&&n.push(Ne(["Option","Alias","Argument","Description","Type","Default"],t.options.map(o=>[o.flags?o.flags.map(r=>`\`${r}\``).join(" "):"",o.aliases?o.aliases.map(r=>`\`${r}\``).join(" "):"",o.arguments?o.arguments.map(r=>`\`${r}\``).join(" "):"",o.description??"",o.type?`\`${o.type}\``:"",o.defaultValue?o.defaultValue.includes(" ")?o.defaultValue:`\`${o.defaultValue}\``:""]))),i.commandsOnly&&n.push("_See the sections below for more information on each subcommand._"),n.join(`
6
6
 
7
- `)}function Wn(t,e){var d,c;let n=t.subcommandName===void 0,i=t.commands?t.commands.length>1:!1,o=e>1,r=(d=t.commands)==null?void 0:d.find(p=>p.default),a=(c=t.commands)==null?void 0:c.find(p=>p.commandName===void 0),s=`${t.commandName}${t.subcommandName?` ${t.subcommandName}`:""}`;return{canRecurse:o,commandsOnly:o&&i,defaultCommand:r,fullCommandName:s,hasMultipleSubcommands:i,isTopLevel:n,topLevelCommand:a}}function Yn(t){return`#### ${t.isTopLevel?"Command":"Subcommand"}: \`${t.fullCommandName}\``}function Zn(t,e){var n,i;return e.isTopLevel&&((n=e.topLevelCommand)!=null&&n.description)?(t.commands=(i=t.commands)==null?void 0:i.filter(o=>o!==e.topLevelCommand),e.topLevelCommand.description):t.description??""}function Xn(t){return`This section lists top-level commands for \`${t}\`.`}function Qn(t){var e;return`If no command is provided, \`${t.fullCommandName} ${(e=t.defaultCommand)==null?void 0:e.commandName}\` is run by default.`}function eo(t,e){var i;let n=(i=e.topLevelCommand)!=null&&i.arguments?` ${e.topLevelCommand.arguments.join(" ")}`:`${t.arguments?` ${t.arguments.join(" ")}`:""}`;return`Usage:
7
+ `)}function Wn(t,e){var m,c;let n=t.subcommandName===void 0,i=t.commands?t.commands.length>1:!1,o=e>1,r=(m=t.commands)==null?void 0:m.find(p=>p.default),a=(c=t.commands)==null?void 0:c.find(p=>p.commandName===void 0),s=`${t.commandName}${t.subcommandName?` ${t.subcommandName}`:""}`;return{canRecurse:o,commandsOnly:o&&i,defaultCommand:r,fullCommandName:s,hasMultipleSubcommands:i,isTopLevel:n,topLevelCommand:a}}function Yn(t){return`#### ${t.isTopLevel?"Command":"Subcommand"}: \`${t.fullCommandName}\``}function Zn(t,e){var n,i;return e.isTopLevel&&((n=e.topLevelCommand)!=null&&n.description)?(t.commands=(i=t.commands)==null?void 0:i.filter(o=>o!==e.topLevelCommand),e.topLevelCommand.description):t.description??""}function Xn(t){return`This section lists top-level commands for \`${t}\`.`}function Qn(t){var e;return`If no command is provided, \`${t.fullCommandName} ${(e=t.defaultCommand)==null?void 0:e.commandName}\` is run by default.`}function eo(t,e){var i;let n=(i=e.topLevelCommand)!=null&&i.arguments?` ${e.topLevelCommand.arguments.join(" ")}`:`${t.arguments?` ${t.arguments.join(" ")}`:""}`;return`Usage:
8
8
  \`\`\`txt
9
9
  ${e.fullCommandName}${n}
10
10
  \`\`\``}function Ne(t,e){let n=to(e);t=t.filter((o,r)=>!n.includes(r)),e=e.map(o=>o.filter((r,a)=>!n.includes(a)));let i="";i+=`| ${t.join(" | ")} |
11
11
  `,i+=`| ${t.map(()=>"---").join(" | ")} |
12
12
  `;for(let o of e)i+=`| ${o.join(" | ")} |
13
- `;return i}function to(t){var i;let e=[],n=((i=t[0])==null?void 0:i.length)||0;for(let o=0;o<n;o++){let r=!0;for(let a of t)if(a[o]!==""){r=!1;break}r&&e.push(o)}return e}import{CstParser as no,Lexer as x,createToken as f}from"chevrotain";var de=f({name:"flag",pattern:/--[\w-_]+/}),Ie=f({longer_alt:de,name:"alias",pattern:/-[A-Za-z]/}),$t=f({group:x.SKIPPED,name:"comma",pattern:/,/}),Nt=f({group:x.SKIPPED,name:"dollar",pattern:/\$/}),se=f({group:x.SKIPPED,name:"whiteSpace",pattern:/ /}),At=f({group:x.SKIPPED,name:"newLine",pattern:/\n/}),Me=f({name:"word",pattern:/\S+/}),H=f({name:"argument",pattern:/(<\S+>|\[.+])/}),De=f({name:"programDescription",pattern:/\w.+(?=\n\n {2}Usage)/}),_t=f({group:x.SKIPPED,name:"startUsage",pattern:/ {2}Usage\n/,push_mode:"USAGE_MODE"}),It=f({group:x.SKIPPED,name:"endUsage",pattern:/\n/,pop_mode:!0}),je=f({name:"startOptions",pattern:/ {2}Options\n/,push_mode:"OPTIONS_MODE"}),Fe=f({name:"startRow",pattern:/ {4}/,push_mode:"ROW_MODE"}),Ue=f({name:"rowDescription",pattern:/\w.+/}),Mt=f({group:x.SKIPPED,name:"endRow",pattern:/\n/,pop_mode:!0}),Dt=f({group:x.SKIPPED,name:"endOptions",pattern:/\n/,pop_mode:!0}),oo=new x({defaultMode:"DEFAULT_MODE",modes:{DEFAULT_MODE:[_t,je,De,At,se],OPTIONS_MODE:[Dt,Fe],ROW_MODE:[Mt,Ie,de,$t,H,Ue,se],USAGE_MODE:[It,Nt,H,Me,se]}}),io=[de,Ie,$t,Nt,se,At,Me,H,De,_t,It,je,Fe,Ue,Mt,Dt],Ae=class extends no{programHelp=this.RULE("programHelp",()=>{this.CONSUME(De,{LABEL:"description"}),this.AT_LEAST_ONE(()=>{this.CONSUME(Me,{LABEL:"commandName"})}),this.MANY(()=>{this.CONSUME(H)}),this.OPTION(()=>{this.SUBRULE(this.optionsSection)})});optionsSection=this.RULE("optionsSection",()=>{this.CONSUME(je),this.MANY(()=>{this.SUBRULE(this.sectionRow)})});sectionRow=this.RULE("sectionRow",()=>{this.CONSUME(Fe),this.MANY(()=>{this.OR([{ALT:()=>this.CONSUME(H)},{ALT:()=>this.CONSUME(Ie)},{ALT:()=>this.CONSUME(de)},{ALT:()=>this.CONSUME(Ue,{LABEL:"description"})}])})});constructor(){super(io),this.performSelfAnalysis()}},J=new Ae,_e=class extends J.getBaseCstVisitorConstructor(){constructor(){super(),this.validateVisitor()}programHelp(e){let{command:n,subcommand:i}=me(this.getString(e.commandName));return{arguments:this.getArray(e.argument),commandName:n,description:this.getString(e.description),options:e.optionsSection?this.visit(e.optionsSection):void 0,subcommandName:i}}optionsSection(e){return e.sectionRow.map(n=>this.visit(n))}sectionRow(e){return{aliases:this.getArray(e.alias),arguments:this.getArray(e.argument),description:this.getString(e.description,!0),flags:this.getArray(e.flag)}}getString(e,n=!1){if(e!==void 0)return e.map(i=>n?this.clean(i.image):i.image).join(" ")}getArray(e){if(e!==void 0)return e.map(n=>n.image)}clean(e){return e.replaceAll(/^[\s[]*(default:)?\s*|[\s\]]*$/g,"")}},ro=new _e;function jt(t){let e=oo.tokenize(t);if(e.errors.length>0)throw new Error(`Errors lexing CLI command: ${JSON.stringify(e.errors,void 0,2)}`);J.input=e.tokens;let n=J.programHelp();if(J.errors.length>0)throw new Error(`Errors parsing CLI command help text: ${JSON.stringify(J.errors,void 0,2)}`);let i;try{i=ro.visit(n)}catch(o){if(o instanceof Error)throw new TypeError(`Errors visiting CLI command help text: ${String(o)}`)}if(i===void 0)throw new Error("Could not parse help string");return i}import{CstParser as ao,Lexer as v,createToken as l}from"chevrotain";var He=l({name:"flag",pattern:/--[\w-_]+/}),qe=l({name:"alias",pattern:/-[A-Za-z]/}),Ft=l({group:v.SKIPPED,name:"comma",pattern:/,/}),M=l({name:"word",pattern:/\S+/}),z=l({name:"argument",pattern:/<\S+>|\[\S+]/}),ze=l({name:"type",pattern:/\[(boolean|string|array)]/}),Ge=l({name:"defaultInfo",pattern:/\[default]/}),Ke=l({name:"required",pattern:/\[required]/}),We=l({name:"defaultInfoDescription",pattern:/\[default:\s.+?]/}),Ye=l({name:"choices",pattern:/\[choices:\s.+?]/}),Ve=l({group:v.SKIPPED,name:"whiteSpace",pattern:/\s/}),Ut=l({group:v.SKIPPED,name:"startProgramDescription",pattern:/\n\n/,push_mode:"PROGRAM_DESCRIPTION_MODE"}),Ze=l({name:"programDescription",pattern:/.+/}),Vt=l({group:v.SKIPPED,name:"endProgramDescription",pattern:/\n\n/,pop_mode:!0}),Xe=l({name:"startOptionsSection",pattern:/Options:?\n/,push_mode:"SECTION_MODE"}),Qe=l({name:"startPositionalsSection",pattern:/Positionals:\n/,push_mode:"SECTION_MODE"}),et=l({name:"startCommandsSection",pattern:/Commands:\n/,push_mode:"SECTION_MODE"}),tt=l({name:"startRow",pattern:/ {2,}/,push_mode:"ROW_MODE"}),nt=l({name:"rowDescription",pattern:/ {2}\w.+ {2}/}),ot=l({name:"rowDescriptionTerminal",pattern:/ {2}\w.+/}),Bt=l({group:v.SKIPPED,name:"endRow",pattern:/\n/,pop_mode:!0}),Jt=l({group:v.SKIPPED,name:"endSection",pattern:/\n+/,pop_mode:!0}),so=new v({defaultMode:"DEFAULT_MODE",modes:{DEFAULT_MODE:[Xe,Qe,et,Ut,z,M,Ve],PROGRAM_DESCRIPTION_MODE:[Vt,Ze],ROW_MODE:[Bt,Ft,ze,nt,ot,We,Ge,Ke,Ye,He,qe,z,M,Ve],SECTION_MODE:[tt,Jt]}}),mo=[He,qe,Ft,M,z,ze,Ge,Ke,We,Ye,Ve,Ut,Ze,Vt,Xe,Qe,et,tt,nt,ot,Bt,Jt],Be=class extends ao{programHelp=this.RULE("programHelp",()=>{this.AT_LEAST_ONE(()=>{this.CONSUME(M,{LABEL:"commandName"})}),this.MANY1(()=>{this.CONSUME(z)}),this.OPTION(()=>{this.CONSUME(Ze,{LABEL:"description"})}),this.OPTION1(()=>{this.SUBRULE(this.commandsSection)}),this.OPTION2(()=>{this.SUBRULE(this.positionalsSection)}),this.OPTION3(()=>{this.SUBRULE(this.optionsSection)})});positionalsSection=this.RULE("positionalsSection",()=>{this.CONSUME(Qe),this.MANY(()=>{this.SUBRULE(this.sectionRow)})});commandsSection=this.RULE("commandsSection",()=>{this.CONSUME(et),this.MANY1(()=>{this.SUBRULE1(this.sectionRow)})});optionsSection=this.RULE("optionsSection",()=>{this.CONSUME(Xe),this.MANY2(()=>{this.SUBRULE2(this.sectionRow)})});sectionRow=this.RULE("sectionRow",()=>{this.CONSUME(tt),this.OPTION(()=>{this.CONSUME(M,{LABEL:"parentCommandName"})}),this.MANY(()=>{this.CONSUME1(M,{LABEL:"commandName"})}),this.MANY1(()=>{this.OR([{ALT:()=>this.CONSUME(z)},{ALT:()=>this.CONSUME(qe)},{ALT:()=>this.CONSUME(He)},{ALT:()=>this.CONSUME(nt,{LABEL:"description"})},{ALT:()=>this.CONSUME(ot,{LABEL:"description"})},{ALT:()=>this.CONSUME(ze)},{ALT:()=>this.CONSUME(Ke)},{ALT:()=>this.CONSUME(We)},{ALT:()=>this.CONSUME(Ge)},{ALT:()=>this.CONSUME(Ye)}])})});constructor(){super(mo),this.performSelfAnalysis()}},q=new Be,Je=class extends q.getBaseCstVisitorConstructor(){constructor(){super(),this.validateVisitor()}programHelp(e){let{command:n,subcommand:i}=me(this.getString(e.commandName));return{arguments:this.getArray(e.argument),commandName:n,commands:e.commandsSection?this.visit(e.commandsSection):void 0,description:this.getString(e.description),options:e.optionsSection?this.visit(e.optionsSection):void 0,positionals:e.positionalsSection?this.visit(e.positionalsSection):void 0,subcommandName:i}}positionalsSection(e){return e.sectionRow.map(n=>this.positionalParentCommandToArguments(this.visit(n)))}commandsSection(e){return e.sectionRow.map(n=>this.visit(n))}optionsSection(e){return e.sectionRow.map(n=>this.visit(n))}sectionRow(e){return{aliases:this.getArray(e.alias),arguments:this.getArray(e.argument),choices:this.splitChoices(this.getString(e.choices)),commandName:this.getString(e.commandName),default:e.defaultInfo?!0:void 0,defaultValue:this.getString(e.defaultInfoDescription,!0),description:this.getString(e.description,!0),flags:this.getArray(e.flag),parentCommandName:this.getString(e.parentCommandName),required:e.required?!0:void 0,type:this.getString(e.type,!0)}}positionalParentCommandToArguments(e){let{arguments:n,parentCommandName:i,...o}=e;return i===void 0?e:{arguments:[i,...n??[]],...o}}getString(e,n=!1){if(e!==void 0)return e.map(i=>n?this.clean(i.image):i.image).join(" ")}getArray(e){if(e!==void 0)return e.map(n=>n.image)}clean(e){return e.replaceAll(/^[\s[]*(default:)?\s*|[\s\]]*$/g,"")}splitChoices(e){if(e!==void 0)return this.clean(e.replaceAll(/^\[choices:\s/g,"")).split(", ")}},co=new Je;function Ht(t){let e=so.tokenize(t);if(e.errors.length>0)throw new Error(`Errors lexing CLI command: ${JSON.stringify(e.errors,void 0,2)}`);q.input=e.tokens;let n=q.programHelp();if(q.errors.length>0)throw new Error(`Errors parsing CLI command help text: ${JSON.stringify(q.errors,void 0,2)}`);let i;try{i=co.visit(n)}catch(o){if(o instanceof Error)throw new TypeError(`Errors visiting CLI command help text: ${String(o)}`)}if(i===void 0)throw new Error("Could not parse help string");return i}var qt={meow:jt,yargs:Ht};function me(t){if(t===void 0)throw new Error('Could not find "commandName" entry in help');let e=t.split(" ");if(e.length===0&&t===void 0)throw new Error('Could not find "commandName" entry in help');if(e.length===1)return{command:e[0],subcommand:void 0};let n=e.at(-1);return{command:e.slice(0,-1).join(" "),subcommand:n}}import{log as it}from"remark-mdat";function zt(t){for(let[e,n]of Object.entries(qt)){it.info(`Trying to parse help string with ${e} parser...`);try{return n(t)}catch(i){i instanceof Error&&it.info(`Error in "${e}" parser: ${String(i)}`);continue}}it.error("Could not parse help string with any parser")}import{execaCommand as po}from"execa";import{log as Gt}from"remark-mdat";async function rt(t,e="--help",n){let i=`${t} ${e}`,o=await fo(i),r=zt(o);return r===void 0?(Gt.warn("Falling back to basic cli help text output."),uo(o)):lo(t,e,n??Number.MAX_SAFE_INTEGER,r)}async function lo(t,e,n,i){if(n<=0)return Gt.info("Max CLI command help depth reached, stopping recursion"),"";let o=Tt(i,n),r=t.split(" ")[0];if(i.commands)for(let a of i.commands){if(!a.parentCommandName||!a.commandName)continue;let s=await rt(`${r} ${a.commandName}`,e,n-1);if(s==="")return o;o+=`
13
+ `;return i}function to(t){var i;let e=[],n=((i=t[0])==null?void 0:i.length)||0;for(let o=0;o<n;o++){let r=!0;for(let a of t)if(a[o]!==""){r=!1;break}r&&e.push(o)}return e}import{CstParser as no,Lexer as x,createToken as f}from"chevrotain";var me=f({name:"flag",pattern:/--[\w-_]+/}),Ie=f({longer_alt:me,name:"alias",pattern:/-[A-Za-z]/}),$t=f({group:x.SKIPPED,name:"comma",pattern:/,/}),Nt=f({group:x.SKIPPED,name:"dollar",pattern:/\$/}),se=f({group:x.SKIPPED,name:"whiteSpace",pattern:/ /}),At=f({group:x.SKIPPED,name:"newLine",pattern:/\n/}),Me=f({name:"word",pattern:/\S+/}),H=f({name:"argument",pattern:/(<\S+>|\[.+])/}),De=f({name:"programDescription",pattern:/\w.+(?=\n\n {2}Usage)/}),_t=f({group:x.SKIPPED,name:"startUsage",pattern:/ {2}Usage\n/,push_mode:"USAGE_MODE"}),It=f({group:x.SKIPPED,name:"endUsage",pattern:/\n/,pop_mode:!0}),je=f({name:"startOptions",pattern:/ {2}Options\n/,push_mode:"OPTIONS_MODE"}),Fe=f({name:"startRow",pattern:/ {4}/,push_mode:"ROW_MODE"}),Ue=f({name:"rowDescription",pattern:/\w.+/}),Mt=f({group:x.SKIPPED,name:"endRow",pattern:/\n/,pop_mode:!0}),Dt=f({group:x.SKIPPED,name:"endOptions",pattern:/\n/,pop_mode:!0}),oo=new x({defaultMode:"DEFAULT_MODE",modes:{DEFAULT_MODE:[_t,je,De,At,se],OPTIONS_MODE:[Dt,Fe],ROW_MODE:[Mt,Ie,me,$t,H,Ue,se],USAGE_MODE:[It,Nt,H,Me,se]}}),io=[me,Ie,$t,Nt,se,At,Me,H,De,_t,It,je,Fe,Ue,Mt,Dt],Ae=class extends no{programHelp=this.RULE("programHelp",()=>{this.CONSUME(De,{LABEL:"description"}),this.AT_LEAST_ONE(()=>{this.CONSUME(Me,{LABEL:"commandName"})}),this.MANY(()=>{this.CONSUME(H)}),this.OPTION(()=>{this.SUBRULE(this.optionsSection)})});optionsSection=this.RULE("optionsSection",()=>{this.CONSUME(je),this.MANY(()=>{this.SUBRULE(this.sectionRow)})});sectionRow=this.RULE("sectionRow",()=>{this.CONSUME(Fe),this.MANY(()=>{this.OR([{ALT:()=>this.CONSUME(H)},{ALT:()=>this.CONSUME(Ie)},{ALT:()=>this.CONSUME(me)},{ALT:()=>this.CONSUME(Ue,{LABEL:"description"})}])})});constructor(){super(io),this.performSelfAnalysis()}},J=new Ae,_e=class extends J.getBaseCstVisitorConstructor(){constructor(){super(),this.validateVisitor()}programHelp(e){let{command:n,subcommand:i}=de(this.getString(e.commandName));return{arguments:this.getArray(e.argument),commandName:n,description:this.getString(e.description),options:e.optionsSection?this.visit(e.optionsSection):void 0,subcommandName:i}}optionsSection(e){return e.sectionRow.map(n=>this.visit(n))}sectionRow(e){return{aliases:this.getArray(e.alias),arguments:this.getArray(e.argument),description:this.getString(e.description,!0),flags:this.getArray(e.flag)}}getString(e,n=!1){if(e!==void 0)return e.map(i=>n?this.clean(i.image):i.image).join(" ")}getArray(e){if(e!==void 0)return e.map(n=>n.image)}clean(e){return e.replaceAll(/^[\s[]*(default:)?\s*|[\s\]]*$/g,"")}},ro=new _e;function jt(t){let e=oo.tokenize(t);if(e.errors.length>0)throw new Error(`Errors lexing CLI command: ${JSON.stringify(e.errors,void 0,2)}`);J.input=e.tokens;let n=J.programHelp();if(J.errors.length>0)throw new Error(`Errors parsing CLI command help text: ${JSON.stringify(J.errors,void 0,2)}`);let i;try{i=ro.visit(n)}catch(o){if(o instanceof Error)throw new TypeError(`Errors visiting CLI command help text: ${String(o)}`)}if(i===void 0)throw new Error("Could not parse help string");return i}import{CstParser as ao,Lexer as v,createToken as l}from"chevrotain";var He=l({name:"flag",pattern:/--[\w-_]+/}),qe=l({name:"alias",pattern:/-[A-Za-z]/}),Ft=l({group:v.SKIPPED,name:"comma",pattern:/,/}),M=l({name:"word",pattern:/\S+/}),z=l({name:"argument",pattern:/<\S+>|\[\S+]/}),ze=l({name:"type",pattern:/\[(boolean|string|array)]/}),Ge=l({name:"defaultInfo",pattern:/\[default]/}),Ke=l({name:"required",pattern:/\[required]/}),We=l({name:"defaultInfoDescription",pattern:/\[default:\s.+?]/}),Ye=l({name:"choices",pattern:/\[choices:\s.+?]/}),Ve=l({group:v.SKIPPED,name:"whiteSpace",pattern:/\s/}),Ut=l({group:v.SKIPPED,name:"startProgramDescription",pattern:/\n\n/,push_mode:"PROGRAM_DESCRIPTION_MODE"}),Ze=l({name:"programDescription",pattern:/.+/}),Vt=l({group:v.SKIPPED,name:"endProgramDescription",pattern:/\n\n/,pop_mode:!0}),Xe=l({name:"startOptionsSection",pattern:/Options:?\n/,push_mode:"SECTION_MODE"}),Qe=l({name:"startPositionalsSection",pattern:/Positionals:\n/,push_mode:"SECTION_MODE"}),et=l({name:"startCommandsSection",pattern:/Commands:\n/,push_mode:"SECTION_MODE"}),tt=l({name:"startRow",pattern:/ {2,}/,push_mode:"ROW_MODE"}),nt=l({name:"rowDescription",pattern:/ {2}\w.+ {2}/}),ot=l({name:"rowDescriptionTerminal",pattern:/ {2}\w.+/}),Bt=l({group:v.SKIPPED,name:"endRow",pattern:/\n/,pop_mode:!0}),Jt=l({group:v.SKIPPED,name:"endSection",pattern:/\n+/,pop_mode:!0}),so=new v({defaultMode:"DEFAULT_MODE",modes:{DEFAULT_MODE:[Xe,Qe,et,Ut,z,M,Ve],PROGRAM_DESCRIPTION_MODE:[Vt,Ze],ROW_MODE:[Bt,Ft,ze,nt,ot,We,Ge,Ke,Ye,He,qe,z,M,Ve],SECTION_MODE:[tt,Jt]}}),mo=[He,qe,Ft,M,z,ze,Ge,Ke,We,Ye,Ve,Ut,Ze,Vt,Xe,Qe,et,tt,nt,ot,Bt,Jt],Be=class extends ao{programHelp=this.RULE("programHelp",()=>{this.AT_LEAST_ONE(()=>{this.CONSUME(M,{LABEL:"commandName"})}),this.MANY1(()=>{this.CONSUME(z)}),this.OPTION(()=>{this.CONSUME(Ze,{LABEL:"description"})}),this.OPTION1(()=>{this.SUBRULE(this.commandsSection)}),this.OPTION2(()=>{this.SUBRULE(this.positionalsSection)}),this.OPTION3(()=>{this.SUBRULE(this.optionsSection)})});positionalsSection=this.RULE("positionalsSection",()=>{this.CONSUME(Qe),this.MANY(()=>{this.SUBRULE(this.sectionRow)})});commandsSection=this.RULE("commandsSection",()=>{this.CONSUME(et),this.MANY1(()=>{this.SUBRULE1(this.sectionRow)})});optionsSection=this.RULE("optionsSection",()=>{this.CONSUME(Xe),this.MANY2(()=>{this.SUBRULE2(this.sectionRow)})});sectionRow=this.RULE("sectionRow",()=>{this.CONSUME(tt),this.OPTION(()=>{this.CONSUME(M,{LABEL:"parentCommandName"})}),this.MANY(()=>{this.CONSUME1(M,{LABEL:"commandName"})}),this.MANY1(()=>{this.OR([{ALT:()=>this.CONSUME(z)},{ALT:()=>this.CONSUME(qe)},{ALT:()=>this.CONSUME(He)},{ALT:()=>this.CONSUME(nt,{LABEL:"description"})},{ALT:()=>this.CONSUME(ot,{LABEL:"description"})},{ALT:()=>this.CONSUME(ze)},{ALT:()=>this.CONSUME(Ke)},{ALT:()=>this.CONSUME(We)},{ALT:()=>this.CONSUME(Ge)},{ALT:()=>this.CONSUME(Ye)}])})});constructor(){super(mo),this.performSelfAnalysis()}},q=new Be,Je=class extends q.getBaseCstVisitorConstructor(){constructor(){super(),this.validateVisitor()}programHelp(e){let{command:n,subcommand:i}=de(this.getString(e.commandName));return{arguments:this.getArray(e.argument),commandName:n,commands:e.commandsSection?this.visit(e.commandsSection):void 0,description:this.getString(e.description),options:e.optionsSection?this.visit(e.optionsSection):void 0,positionals:e.positionalsSection?this.visit(e.positionalsSection):void 0,subcommandName:i}}positionalsSection(e){return e.sectionRow.map(n=>this.positionalParentCommandToArguments(this.visit(n)))}commandsSection(e){return e.sectionRow.map(n=>this.visit(n))}optionsSection(e){return e.sectionRow.map(n=>this.visit(n))}sectionRow(e){return{aliases:this.getArray(e.alias),arguments:this.getArray(e.argument),choices:this.splitChoices(this.getString(e.choices)),commandName:this.getString(e.commandName),default:e.defaultInfo?!0:void 0,defaultValue:this.getString(e.defaultInfoDescription,!0),description:this.getString(e.description,!0),flags:this.getArray(e.flag),parentCommandName:this.getString(e.parentCommandName),required:e.required?!0:void 0,type:this.getString(e.type,!0)}}positionalParentCommandToArguments(e){let{arguments:n,parentCommandName:i,...o}=e;return i===void 0?e:{arguments:[i,...n??[]],...o}}getString(e,n=!1){if(e!==void 0)return e.map(i=>n?this.clean(i.image):i.image).join(" ")}getArray(e){if(e!==void 0)return e.map(n=>n.image)}clean(e){return e.replaceAll(/^[\s[]*(default:)?\s*|[\s\]]*$/g,"")}splitChoices(e){if(e!==void 0)return this.clean(e.replaceAll(/^\[choices:\s/g,"")).split(", ")}},co=new Je;function Ht(t){let e=so.tokenize(t);if(e.errors.length>0)throw new Error(`Errors lexing CLI command: ${JSON.stringify(e.errors,void 0,2)}`);q.input=e.tokens;let n=q.programHelp();if(q.errors.length>0)throw new Error(`Errors parsing CLI command help text: ${JSON.stringify(q.errors,void 0,2)}`);let i;try{i=co.visit(n)}catch(o){if(o instanceof Error)throw new TypeError(`Errors visiting CLI command help text: ${String(o)}`)}if(i===void 0)throw new Error("Could not parse help string");return i}var qt={meow:jt,yargs:Ht};function de(t){if(t===void 0)throw new Error('Could not find "commandName" entry in help');let e=t.split(" ");if(e.length===0&&t===void 0)throw new Error('Could not find "commandName" entry in help');if(e.length===1)return{command:e[0],subcommand:void 0};let n=e.at(-1);return{command:e.slice(0,-1).join(" "),subcommand:n}}import{log as it}from"remark-mdat";function zt(t){for(let[e,n]of Object.entries(qt)){it.info(`Trying to parse help string with ${e} parser...`);try{return n(t)}catch(i){i instanceof Error&&it.info(`Error in "${e}" parser: ${String(i)}`);continue}}it.error("Could not parse help string with any parser")}import{execaCommand as po}from"execa";import{log as Gt}from"remark-mdat";async function rt(t,e="--help",n){let i=`${t} ${e}`,o=await fo(i),r=zt(o);return r===void 0?(Gt.warn("Falling back to basic cli help text output."),uo(o)):lo(t,e,n??Number.MAX_SAFE_INTEGER,r)}async function lo(t,e,n,i){if(n<=0)return Gt.info("Max CLI command help depth reached, stopping recursion"),"";let o=Tt(i,n),r=t.split(" ")[0];if(i.commands)for(let a of i.commands){if(!a.parentCommandName||!a.commandName)continue;let s=await rt(`${r} ${a.commandName}`,e,n-1);if(s==="")return o;o+=`
14
14
 
15
15
  ${s}`}return o}function uo(t){return`\`\`\`txt
16
16
  ${t}
@@ -25,11 +25,11 @@ ${i}
25
25
 
26
26
  `,`
27
27
  `);return[o,a].join(`
28
- `)},order:6}};import{tldrawToImage as tn}from"@kitschpatrol/tldraw-cli";import Lo from"node:crypto";import D from"node:fs/promises";import C from"node:path";import{isFile as st}from"path-type";import{z as dt}from"zod";var an={tldraw:{async content(t){let{alt:e="tldraw diagram",src:n}=dt.object({alt:dt.string().optional(),src:dt.string()}).parse(t),{assetsPath:i}=await P();if(i===void 0)throw new Error("No assets path found");await D.mkdir(i,{recursive:!0});let o=await st(n)?await on(n):void 0;if(o!==void 0){let d=C.basename(n,C.extname(n)),c=C.join(i,`${d}-${o}-light.svg`),p=C.join(i,`${d}-${o}-dark.svg`);if(await st(c)&&await st(p))return nn(c,p,e)}let[r]=await tn(n,{dark:!1,format:"svg",output:i,transparent:!0});o??=await on(r);let a=`${rn(r)}-${o}-light.svg`;await D.rename(r,a);let[s]=await tn(n,{dark:!0,format:"svg",output:i,transparent:!0}),m=`${rn(s)}-${o}-dark.svg`;if(await D.rename(s,m),o!==void 0){let d=C.basename(m),c=C.basename(a),p=c.replace(`${o}-light.svg`,""),g=await D.readdir(i);for(let y of g){let w=C.basename(y);w!==d&&w!==c&&w.startsWith(p)&&w.endsWith(".svg")&&await D.rm(C.join(i,w))}}return nn(a,m,e)}}};async function nn(t,e,n){let{packageFile:i}=await P();if(i===void 0)throw new Error("No package file found");let o=C.dirname(i),r=C.relative(o,t);return`<picture>
28
+ `)},order:6}};import{tldrawToImage as tn}from"@kitschpatrol/tldraw-cli";import Lo from"node:crypto";import D from"node:fs/promises";import C from"node:path";import{isFile as st}from"path-type";import{z as mt}from"zod";var an={tldraw:{async content(t){let{alt:e="tldraw diagram",src:n}=mt.object({alt:mt.string().optional(),src:mt.string()}).parse(t),{assetsPath:i}=await P();if(i===void 0)throw new Error("No assets path found");await D.mkdir(i,{recursive:!0});let o=await st(n)?await on(n):void 0;if(o!==void 0){let m=C.basename(n,C.extname(n)),c=C.join(i,`${m}-${o}-light.svg`),p=C.join(i,`${m}-${o}-dark.svg`);if(await st(c)&&await st(p))return nn(c,p,e)}let[r]=await tn(n,{dark:!1,format:"svg",output:i,transparent:!0});o??=await on(r);let a=`${rn(r)}-${o}-light.svg`;await D.rename(r,a);let[s]=await tn(n,{dark:!0,format:"svg",output:i,transparent:!0}),d=`${rn(s)}-${o}-dark.svg`;if(await D.rename(s,d),o!==void 0){let m=C.basename(d),c=C.basename(a),p=c.replace(`${o}-light.svg`,""),g=await D.readdir(i);for(let y of g){let w=C.basename(y);w!==m&&w!==c&&w.startsWith(p)&&w.endsWith(".svg")&&await D.rm(C.join(i,w))}}return nn(a,d,e)}}};async function nn(t,e,n){let{packageFile:i}=await P();if(i===void 0)throw new Error("No package file found");let o=C.dirname(i),r=C.relative(o,t);return`<picture>
29
29
  <source media="(prefers-color-scheme: dark)" srcset="${C.relative(o,e)}">
30
30
  <source media="(prefers-color-scheme: light)" srcset="${r}">
31
31
  <img alt="${n}" src="${r}">
32
- </picture>`}async function on(t){let e=await D.readFile(t),n=Lo.createHash("sha1");return n.update(e),n.digest("hex").slice(0,8)}function rn(t){return t.replace(/\.[^./]+$/,"")}import{getSoleRule as vo}from"remark-mdat";var sn={toc:{applicationOrder:1,content:[vo(ye)]}};var dn={...ie,...ae,...Wt,...Zt,...pe,...Qt,...en,...le,...ue,...ye,...an,...sn,...ge};async function we(t){let e={addMetaComment:!0,rules:dn},{additionalConfig:n=[],...i}=t??{},o=Array.isArray(n)?n:[n],r=await L({additionalConfig:[e,...o],...i});if(r.packageFile===void 0)throw new Error("Package file path is required in `mdat readme` config");return r}import{findUp as To}from"find-up";import{packageDirectory as $o}from"pkg-dir";import{log as mn}from"remark-mdat";async function mt(){mn.info("Searching for package directory...");let t=await $o()??process.cwd(),e=await To("readme.md",{stopAt:t,type:"file"});if(e!==void 0)return mn.info(`Found closest readme at "${e}"`),e}async function be(){let t=await mt();if(t===void 0)throw new Error("No readme found");return t}async function cn(t,e){return ct(void 0,void 0,void 0,t,e)}async function ct(t,e,n,i,o){return t??=await be(),R(t,we,te,e,n,i,o)}async function pn(t,e,n,i,o){return t??=await be(),R(t,we,oe,e,n,i,o)}async function ln(t,e,n,i,o){return t??=await be(),R(t,we,ne,e,n,i,o)}var un=`<!-- header -->
32
+ </picture>`}async function on(t){let e=await D.readFile(t),n=Lo.createHash("sha1");return n.update(e),n.digest("hex").slice(0,8)}function rn(t){return t.replace(/\.[^./]+$/,"")}import{getSoleRule as vo}from"remark-mdat";var sn={toc:{applicationOrder:1,content:[vo(ye)]}};var mn={...ie,...ae,...Wt,...Zt,...pe,...Qt,...en,...le,...ue,...ye,...an,...sn,...ge};async function we(t){let e={addMetaComment:!0,rules:mn},{additionalConfig:n=[],...i}=t??{},o=Array.isArray(n)?n:[n],r=await L({additionalConfig:[e,...o],...i});if(r.packageFile===void 0)throw new Error("Package file path is required in `mdat readme` config");return r}import{findUp as To}from"find-up";import{packageDirectory as $o}from"pkg-dir";import{log as dn}from"remark-mdat";async function dt(){dn.info("Searching for package directory...");let t=await $o()??process.cwd(),e=await To("readme.md",{stopAt:t,type:"file"});if(e!==void 0)return dn.info(`Found closest readme at "${e}"`),e}async function be(){let t=await dt();if(t===void 0)throw new Error("No readme found");return t}async function cn(t,e){return ct(void 0,void 0,void 0,t,e)}async function ct(t,e,n,i,o){return t??=await be(),R(t,we,te,e,n,i,o)}async function pn(t,e,n,i,o){return t??=await be(),R(t,we,oe,e,n,i,o)}async function ln(t,e,n,i,o){return t??=await be(),R(t,we,ne,e,n,i,o)}var un=`<!-- header -->
33
33
 
34
34
  <!-- table-of-contents -->
35
35
 
@@ -299,4 +299,4 @@ _State anyone or anything that significantly helped with the development of your
299
299
  <!-- contributing -->
300
300
 
301
301
  <!-- license -->
302
- `;var T={"Mdat Readme":{content:{compound:un,explicit:fn},description:"The house style. An expansive starting point. Prune to your context and taste.",exampleLink:"https://github.com/kitschpatrol/mdat/blob/main/readme.md"},"Standard Readme Basic":{content:{compound:gn,explicit:hn},description:'Includes only the "required" sections from the Standard Readme specification.',exampleLink:"https://github.com/RichardLitt/standard-readme/blob/main/example-readmes/minimal-readme.md"},"Standard Readme Full":{content:{compound:yn,explicit:wn},description:"Includes all sections from the Standard Readme specification.",exampleLink:"https://github.com/RichardLitt/standard-readme/blob/main/example-readmes/maximal-readme.md"}};import{confirm as bn,group as jo,intro as Fo,note as Cn,outro as Uo,select as pt}from"@clack/prompts";import k from"chalk";import Vo from"node:fs/promises";import Ce from"node:path";import{deepMergeDefined as Bo}from"remark-mdat";import{write as Jo}from"to-vfile";async function Pn(){let t=await mt(),e=await X();return{packageDirectory:e===void 0?void 0:Ce.dirname(Ce.resolve(e)),readmePath:t}}async function On(){let{packageDirectory:t,readmePath:e}=await Pn(),n=Ce.resolve(process.cwd());Fo(`Running ${k.bold("mdat readme init")} interactively`);let i=await jo({overwrite:async()=>e===void 0||await bn({message:`Found an existing readme at "${k.blue(e)}". Do you want to overwrite it?`,active:"Overwrite",inactive:"Exit"})?!0:(()=>{throw new Error("`mdat readme init` was cancelled to avoid an overwrite - no changes were made")})(),output:async()=>t!==void 0&&t!==n?pt({initialValue:t,message:"There's a root package directory nearby, do you want to create the readme there instead of the current directory?",options:[{label:`Create in the current package root: "${k.blue(t)}"`,value:t},{label:`Create in current working directory: "${k.blue(n)}"`,value:n}]}):n,template:async()=>pt({message:"Which template would you like to use?",options:qo()}),compound:async()=>pt({message:'Do you want to use "compound comments" where possible, which combine several expansions into a single comment block?',options:[{label:`Yes: Combine things like ${k.green("<!-- title -->")} and ${k.green("<!-- badges -->")} in a single ${k.green("<!-- header -->")} comment.`,value:!0},{label:"No: Use individual `mdat` expansion comments for each section.",value:!1}]}),expand:async()=>t===void 0?!1:bn({initialValue:!0,message:"Do you want to run `mdat readme` now to expand the template with content from your package.json?"})},{onCancel(){throw new Error("`mdat readme init` was cancelled - no changes were made")}}),o=await lt(i);return t===void 0&&Cn("No package.json was found. Once you've created one, you can run `mdat readme` to expand the template with content from your package.json."),Cn(`Readme created: "${k.bold.blue(o)}"`),Uo("Done!"),o}async function lt(t){let{packageDirectory:e}=await Pn(),n=Bo({compound:!0,output:e??process.cwd(),overwrite:!0,expand:e!==void 0,template:Object.keys(T)[0]},t??{}),i=Ho(n.template,n.compound),o=Ce.join(n.output,"readme.md");await Vo.writeFile(o,i,"utf8");let r=await cn(void 0,void 0,{readmeFile:o});return await Jo(r),o}function Ho(t,e){let i=T[t].content[e?"compound":"explicit"];if(i===void 0||i==="")throw new Error(`No template found for "${t}"`);return i}function qo(){return Object.entries(T).map(([t,e])=>({label:t,hint:e.description,value:t}))}var $={config:{defaultDescription:"Configuration is loaded if found from the usual places, or defaults are used.",description:"Path(s) to files containing mdat configs.",string:!0,type:"array"}},G={meta:{alias:"m",description:"Embed an extra comment at the top of the generated Markdown noting the date of generation and warning editors that certain sections of the document have been generated dynamically.",type:"boolean"}},K={name:{alias:"n",defaultDescription:"Same name as input file. Overwrites the input file.",description:"Output file name.",type:"string"}},j={output:{alias:"o",defaultDescription:"Same directory as input file.",description:"Output file directory.",type:"string"}},N={prefix:{description:"Require a string prefix before all comments to be considered for expansion. Useful if you have a bunch of non-`mdat` comments in your Markdown file, or if you're willing to trade some verbosity for safety.",type:"string"}},W={print:{description:"Print the expanded Markdown to stdout instead of saving to a file. Ignores `--output` and `--name` options.",type:"boolean"}},Y={rules:{alias:"r",description:"Path(s) to files containing `mdat` comment expansion rules.",string:!0,type:"array"}},E={verbose:{describe:"Enable verbose logging. All verbose logs and prefixed with their log level and are printed to stderr for ease of redirection.",type:"boolean"}},Pe=["files",{array:!0,demandOption:!0,describe:"Markdown file(s) with `mdat` placeholder comments to collapse.",type:"string"}];var ut={package:{defaultDescription:"The closest package.json file is used by default.",description:"Path to the package.json file to use to populate the readme.",string:!0}},ft={assets:{defaultDescription:"./assets",description:"Path to find and save readme-related assets.",string:!0}},xn={interactive:{alias:"i",default:!0,description:"Run the guided interactive `init` process. Set explicitly to `false` to use default values and skip the prompt.",type:"boolean"}},Rn={overwrite:{default:!1,defaultDescription:"`false`, if an existing readme is found, don't touch it.",description:"Replace an existing readme file if one is found.",type:"boolean"}},Sn={expand:{alias:"e",default:!0,description:"Automatically run `mdat readme` immediately after creating the readme template.",type:"boolean"}},kn={template:{alias:"t",choices:Object.keys(T),default:Object.keys(T)[0],description:"Specify a template to use for the new readme.",type:"string"}},En={compound:{alias:"c",default:!0,description:"Use compound comment version of the template to replace several individual comment placeholders where possible. This combines things like `<!-- title -->`, `<!-- badges -->`, etc. in a single `<!-- header -->` comment. It's less clutter when you're editing, but it's also less explicit. The final readme.md output is identical.",type:"boolean"}},Oe=["files",{array:!0,demandOption:!1,describe:"Readme file(s) with `mdat` placeholder comments to collapse. If not provided, the closest readme.md file is used.",type:"string"}];import gt from"chalk";import A from"pretty-ms";import{getMdatReports as zo,log as u,reporterMdat as F}from"remark-mdat";import{write as xe}from"to-vfile";import Go from"yargs";import{hideBin as Ko}from"yargs/helpers";var _=performance.now(),Ln=Go(Ko(process.argv));try{await Ln.scriptName("mdat").usage("$0 [command]","Work with `mdat` placeholder comments in any Markdown file.").command(["$0 <files..> [options]","expand <files..> [options]"],"Expand `mdat` placeholder comments.",t=>t.positional(...Pe).option($).option(Y).option(j).option(K).option(G).option(N).option(W).option(E),async({config:t,files:e,meta:n,name:i,output:o,prefix:r,print:a,rules:s,verbose:m})=>{u.verbose=m??!1,Re({name:i,output:o,print:a});let d=U(t,{addMetaComment:n,keywordPrefix:r}),c=await Et(e,i,o,d,s);for(let p of c)a?process.stdout.write(p.toString()):await xe(p);F(c),u.info(`Expanded comments in ${A(performance.now()-_)}.`),process.exitCode=V(c)}).command("check <files..> [options]","Validate a markdown file with `mdat` placeholder comments.",t=>t.positional(...Pe).option($).option(Y).option(G).option(N).option(E),async({config:t,files:e,meta:n,prefix:i,rules:o,verbose:r})=>{u.verbose=r??!1;let a=U(t,{addMetaComment:n,keywordPrefix:i}),s=await Lt(e,void 0,void 0,a,o);F(s),u.info(`Checked comments in ${A(performance.now()-_)}.`),process.exitCode=V(s)}).command("collapse <files..> [options]","Collapse `mdat` placeholder comments.",t=>t.positional(...Pe).option($).option(j).option(K).option(N).option(W).option(E),async({config:t,files:e,name:n,output:i,prefix:o,print:r,verbose:a})=>{u.verbose=a??!1,Re({name:n,output:i,print:r});let s=U(t,{keywordPrefix:o}),m=await vt(e,void 0,void 0,s);for(let d of m)r?process.stdout.write(d.toString()):await xe(d);F(m),u.info(`Cleaned comments in ${A(performance.now()-_)}.`),process.exitCode=V(m)}).command("readme [command]","Work with `mdat` comments in your readme.md.",t=>t.command(["$0 [files..] [options]","expand [files..] [options]"],"Expand `mdat` comment placeholders in your readme.md using a collection of helpful built-in expansion rules.",e=>e.positional(...Oe).option($).option(Y).option(j).option(K).option(ut).option(ft).option(N).option(G).option(W).option(E),async({assets:e,config:n,files:i,meta:o,name:r,output:a,package:s,prefix:m,print:d,rules:c,verbose:p})=>{u.verbose=p??!1,Re({name:r,output:a,print:d});let g=U(n,{addMetaComment:o,assetsPath:e,keywordPrefix:m,packageFile:s}),y=await ct(i,r,a,g,c);for(let I of y)d?process.stdout.write(I.toString()):await xe(I);F(y);let{packageFile:w}=await P();u.info(`Pulled package metadata from: ${gt.bold.blue(w)}`),u.info(`Expanded readme(s) in ${A(performance.now()-_)}.`),process.exitCode=V(y)}).command("check [files..] [options]","Validate `mdat` placeholder comments in your readme.md.",e=>e.positional(...Oe).option($).option(Y).option(ut).option(ft).option(N).option(G).option(E),async({assets:e,config:n,files:i,meta:o,package:r,prefix:a,rules:s,verbose:m})=>{u.verbose=m??!1;let d=U(n,{addMetaComment:o,assetsPath:e,keywordPrefix:a,packageFile:r}),c=await pn(i,void 0,void 0,d,s);F(c);let{packageFile:p}=await P();u.info(`Pulled package metadata from: ${gt.bold.blue(p)}`),u.info(`Checked readme(s) in ${A(performance.now()-_)}.`),process.exitCode=V(c)}).command("collapse [files..] [options]","Collapse `mdat` placeholder comments in your readme.md.",e=>e.positional(...Oe).option(j).option(K).option(W).option($).option(N).option(E),async({config:e,files:n,name:i,output:o,prefix:r,print:a,verbose:s})=>{u.verbose=s??!1,Re({name:i,output:o,print:a});let m=U(e,{keywordPrefix:r}),d=await ln(n,void 0,void 0,m);for(let c of d)a?process.stdout.write(c.toString()):await xe(c);F(d),u.info(`Cleaned readme(s) in ${A(performance.now()-_)}.`),process.exitCode=V(d)}).command("init [options]","Interactively create a new readme.md file with sensible default `mdat` comment placeholders.",e=>e.option(xn).option(Rn).option(j).option(Sn).option(kn).option(En).option(E),async({compound:e,expand:n,interactive:i,output:o,overwrite:r,template:a,verbose:s})=>{if(u.verbose=s??!1,i)await On();else{let m=await lt({compound:e,expand:n,output:o,overwrite:r,template:a});u.info(`Created readme at "${gt.blue(m)}" in ${A(performance.now()-_)}.`)}process.exitCode=0}),()=>{u.error("Root mdat readme command should be unreachable.")}).help().alias("h","help").version().alias("v","version").wrap(process.stdout.isTTY?Math.min(120,Ln.terminalWidth()):0).fail(!1).parse()}catch(t){t instanceof Error&&u.error(t.message),process.exitCode=1}function Re(t){t.print&&t.output&&u.warn("Ignoring --output option because --print is set"),t.print&&t.name&&u.warn("Ignoring --name option because --print is set")}function U(t,e){return[...Q(t),e]}function V(t){return zo(t).reduce((i,o)=>i+o.errors.length,0)>0?1:0}
302
+ `;var T={"Mdat Readme":{content:{compound:un,explicit:fn},description:"The house style. An expansive starting point. Prune to your context and taste.",exampleLink:"https://github.com/kitschpatrol/mdat/blob/main/readme.md"},"Standard Readme Basic":{content:{compound:gn,explicit:hn},description:'Includes only the "required" sections from the Standard Readme specification.',exampleLink:"https://github.com/RichardLitt/standard-readme/blob/main/example-readmes/minimal-readme.md"},"Standard Readme Full":{content:{compound:yn,explicit:wn},description:"Includes all sections from the Standard Readme specification.",exampleLink:"https://github.com/RichardLitt/standard-readme/blob/main/example-readmes/maximal-readme.md"}};import{confirm as bn,group as jo,intro as Fo,note as Cn,outro as Uo,select as pt}from"@clack/prompts";import k from"chalk";import Vo from"node:fs/promises";import Ce from"node:path";import{deepMergeDefined as Bo}from"remark-mdat";import{write as Jo}from"to-vfile";async function Pn(){let t=await dt(),e=await X();return{packageDirectory:e===void 0?void 0:Ce.dirname(Ce.resolve(e)),readmePath:t}}async function On(){let{packageDirectory:t,readmePath:e}=await Pn(),n=Ce.resolve(process.cwd());Fo(`Running ${k.bold("mdat readme init")} interactively`);let i=await jo({overwrite:async()=>e===void 0||await bn({message:`Found an existing readme at "${k.blue(e)}". Do you want to overwrite it?`,active:"Overwrite",inactive:"Exit"})?!0:(()=>{throw new Error("`mdat readme init` was cancelled to avoid an overwrite - no changes were made")})(),output:async()=>t!==void 0&&t!==n?pt({initialValue:t,message:"There's a root package directory nearby, do you want to create the readme there instead of the current directory?",options:[{label:`Create in the current package root: "${k.blue(t)}"`,value:t},{label:`Create in current working directory: "${k.blue(n)}"`,value:n}]}):n,template:async()=>pt({message:"Which template would you like to use?",options:qo()}),compound:async()=>pt({message:'Do you want to use "compound comments" where possible, which combine several expansions into a single comment block?',options:[{label:`Yes: Combine things like ${k.green("<!-- title -->")} and ${k.green("<!-- badges -->")} in a single ${k.green("<!-- header -->")} comment.`,value:!0},{label:"No: Use individual `mdat` expansion comments for each section.",value:!1}]}),expand:async()=>t===void 0?!1:bn({initialValue:!0,message:"Do you want to run `mdat readme` now to expand the template with content from your package.json?"})},{onCancel(){throw new Error("`mdat readme init` was cancelled - no changes were made")}}),o=await lt(i);return t===void 0&&Cn("No package.json was found. Once you've created one, you can run `mdat readme` to expand the template with content from your package.json."),Cn(`Readme created: "${k.bold.blue(o)}"`),Uo("Done!"),o}async function lt(t){let{packageDirectory:e}=await Pn(),n=Bo({compound:!0,output:e??process.cwd(),overwrite:!0,expand:e!==void 0,template:Object.keys(T)[0]},t??{}),i=Ho(n.template,n.compound),o=Ce.join(n.output,"readme.md");await Vo.writeFile(o,i,"utf8");let r=await cn(void 0,void 0,{readmeFile:o});return await Jo(r),o}function Ho(t,e){let i=T[t].content[e?"compound":"explicit"];if(i===void 0||i==="")throw new Error(`No template found for "${t}"`);return i}function qo(){return Object.entries(T).map(([t,e])=>({label:t,hint:e.description,value:t}))}var $={config:{defaultDescription:"Configuration is loaded if found from the usual places, or defaults are used.",description:"Path(s) to files containing mdat configs.",string:!0,type:"array"}},G={meta:{alias:"m",description:"Embed an extra comment at the top of the generated Markdown noting the date of generation and warning editors that certain sections of the document have been generated dynamically.",type:"boolean"}},K={name:{alias:"n",defaultDescription:"Same name as input file. Overwrites the input file.",description:"Output file name.",type:"string"}},j={output:{alias:"o",defaultDescription:"Same directory as input file.",description:"Output file directory.",type:"string"}},N={prefix:{description:"Require a string prefix before all comments to be considered for expansion. Useful if you have a bunch of non-`mdat` comments in your Markdown file, or if you're willing to trade some verbosity for safety.",type:"string"}},W={print:{description:"Print the expanded Markdown to stdout instead of saving to a file. Ignores `--output` and `--name` options.",type:"boolean"}},Y={rules:{alias:"r",description:"Path(s) to files containing `mdat` comment expansion rules.",string:!0,type:"array"}},E={verbose:{describe:"Enable verbose logging. All verbose logs and prefixed with their log level and are printed to stderr for ease of redirection.",type:"boolean"}},Pe=["files",{array:!0,demandOption:!0,describe:"Markdown file(s) with `mdat` placeholder comments to collapse.",type:"string"}];var ut={package:{defaultDescription:"The closest package.json file is used by default.",description:"Path to the package.json file to use to populate the readme.",string:!0}},ft={assets:{defaultDescription:"./assets",description:"Path to find and save readme-related assets.",string:!0}},xn={interactive:{alias:"i",default:!0,description:"Run the guided interactive `init` process. Set explicitly to `false` to use default values and skip the prompt.",type:"boolean"}},Rn={overwrite:{default:!1,defaultDescription:"`false`, if an existing readme is found, don't touch it.",description:"Replace an existing readme file if one is found.",type:"boolean"}},Sn={expand:{alias:"e",default:!0,description:"Automatically run `mdat readme` immediately after creating the readme template.",type:"boolean"}},kn={template:{alias:"t",choices:Object.keys(T),default:Object.keys(T)[0],description:"Specify a template to use for the new readme.",type:"string"}},En={compound:{alias:"c",default:!0,description:"Use compound comment version of the template to replace several individual comment placeholders where possible. This combines things like `<!-- title -->`, `<!-- badges -->`, etc. in a single `<!-- header -->` comment. It's less clutter when you're editing, but it's also less explicit. The final readme.md output is identical.",type:"boolean"}},Oe=["files",{array:!0,demandOption:!1,describe:"Readme file(s) with `mdat` placeholder comments to collapse. If not provided, the closest readme.md file is used.",type:"string"}];import gt from"chalk";import A from"pretty-ms";import{getMdatReports as zo,log as u,reporterMdat as F}from"remark-mdat";import{write as xe}from"to-vfile";import Go from"yargs";import{hideBin as Ko}from"yargs/helpers";var _=performance.now(),Ln=Go(Ko(process.argv));try{await Ln.scriptName("mdat").usage("$0 [command]","Work with `mdat` placeholder comments in any Markdown file.").command(["$0 <files..> [options]","expand <files..> [options]"],"Expand `mdat` placeholder comments.",t=>t.positional(...Pe).option($).option(Y).option(j).option(K).option(G).option(N).option(W).option(E),async({config:t,files:e,meta:n,name:i,output:o,prefix:r,print:a,rules:s,verbose:d})=>{u.verbose=d??!1,Re({name:i,output:o,print:a});let m=U(t,{addMetaComment:n,keywordPrefix:r}),c=await Et(e,i,o,m,s);for(let p of c)a?process.stdout.write(p.toString()):await xe(p);F(c),u.info(`Expanded comments in ${A(performance.now()-_)}.`),process.exitCode=V(c)}).command("check <files..> [options]","Validate a markdown file with `mdat` placeholder comments.",t=>t.positional(...Pe).option($).option(Y).option(G).option(N).option(E),async({config:t,files:e,meta:n,prefix:i,rules:o,verbose:r})=>{u.verbose=r??!1;let a=U(t,{addMetaComment:n,keywordPrefix:i}),s=await Lt(e,void 0,void 0,a,o);F(s),u.info(`Checked comments in ${A(performance.now()-_)}.`),process.exitCode=V(s)}).command("collapse <files..> [options]","Collapse `mdat` placeholder comments.",t=>t.positional(...Pe).option($).option(j).option(K).option(N).option(W).option(E),async({config:t,files:e,name:n,output:i,prefix:o,print:r,verbose:a})=>{u.verbose=a??!1,Re({name:n,output:i,print:r});let s=U(t,{keywordPrefix:o}),d=await vt(e,void 0,void 0,s);for(let m of d)r?process.stdout.write(m.toString()):await xe(m);F(d),u.info(`Cleaned comments in ${A(performance.now()-_)}.`),process.exitCode=V(d)}).command("readme [command]","Work with `mdat` comments in your readme.md.",t=>t.command(["$0 [files..] [options]","expand [files..] [options]"],"Expand `mdat` comment placeholders in your readme.md using a collection of helpful built-in expansion rules.",e=>e.positional(...Oe).option($).option(Y).option(j).option(K).option(ut).option(ft).option(N).option(G).option(W).option(E),async({assets:e,config:n,files:i,meta:o,name:r,output:a,package:s,prefix:d,print:m,rules:c,verbose:p})=>{u.verbose=p??!1,Re({name:r,output:a,print:m});let g=U(n,{addMetaComment:o,assetsPath:e,keywordPrefix:d,packageFile:s}),y=await ct(i,r,a,g,c);for(let I of y)m?process.stdout.write(I.toString()):await xe(I);F(y);let{packageFile:w}=await P();u.info(`Pulled package metadata from: ${gt.bold.blue(w)}`),u.info(`Expanded readme(s) in ${A(performance.now()-_)}.`),process.exitCode=V(y)}).command("check [files..] [options]","Validate `mdat` placeholder comments in your readme.md.",e=>e.positional(...Oe).option($).option(Y).option(ut).option(ft).option(N).option(G).option(E),async({assets:e,config:n,files:i,meta:o,package:r,prefix:a,rules:s,verbose:d})=>{u.verbose=d??!1;let m=U(n,{addMetaComment:o,assetsPath:e,keywordPrefix:a,packageFile:r}),c=await pn(i,void 0,void 0,m,s);F(c);let{packageFile:p}=await P();u.info(`Pulled package metadata from: ${gt.bold.blue(p)}`),u.info(`Checked readme(s) in ${A(performance.now()-_)}.`),process.exitCode=V(c)}).command("collapse [files..] [options]","Collapse `mdat` placeholder comments in your readme.md.",e=>e.positional(...Oe).option(j).option(K).option(W).option($).option(N).option(E),async({config:e,files:n,name:i,output:o,prefix:r,print:a,verbose:s})=>{u.verbose=s??!1,Re({name:i,output:o,print:a});let d=U(e,{keywordPrefix:r}),m=await ln(n,void 0,void 0,d);for(let c of m)a?process.stdout.write(c.toString()):await xe(c);F(m),u.info(`Cleaned readme(s) in ${A(performance.now()-_)}.`),process.exitCode=V(m)}).command("init [options]","Interactively create a new readme.md file with sensible default `mdat` comment placeholders.",e=>e.option(xn).option(Rn).option(j).option(Sn).option(kn).option(En).option(E),async({compound:e,expand:n,interactive:i,output:o,overwrite:r,template:a,verbose:s})=>{if(u.verbose=s??!1,i)await On();else{let d=await lt({compound:e,expand:n,output:o,overwrite:r,template:a});u.info(`Created readme at "${gt.blue(d)}" in ${A(performance.now()-_)}.`)}process.exitCode=0}),()=>{u.error("Root mdat readme command should be unreachable.")}).help().alias("h","help").version().alias("v","version").wrap(process.stdout.isTTY?Math.min(120,Ln.terminalWidth()):0).fail(!1).parse()}catch(t){t instanceof Error&&u.error(t.message),process.exitCode=1}function Re(t){t.print&&t.output&&u.warn("Ignoring --output option because --print is set"),t.print&&t.name&&u.warn("Ignoring --name option because --print is set")}function U(t,e){return[...Q(t),e]}function V(t){return zo(t).reduce((i,o)=>i+o.errors.length,0)>0?1:0}
package/dist/config.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { type NormalizedPackageJson } from 'read-pkg';
2
2
  import { type Options, type Rules } from 'remark-mdat';
3
- export type Config = {
3
+ import { type Simplify } from 'type-fest';
4
+ export type Config = Simplify<{
4
5
  assetsPath?: string;
5
6
  packageFile?: string;
6
- } & Options;
7
+ } & Options>;
7
8
  export type ConfigLoaded = {
8
9
  addMetaComment: boolean;
9
10
  assetsPath: string;
@@ -52,3 +53,8 @@ export declare function loadConfig(options?: {
52
53
  }): Promise<ConfigLoaded>;
53
54
  export declare function getConfig(): Promise<ConfigLoaded>;
54
55
  export declare function getPackageJson(): Promise<NormalizedPackageJson>;
56
+ /**
57
+ * Convenience function for merging configs
58
+ * Performs a deep merge, with the rightmost object taking precedence
59
+ */
60
+ export declare function mergeConfigs(a: Config, b: Config): Config;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { checkFiles, checkString, collapseFiles, collapseString, expandFiles, expandString, } from './api';
2
- export { type Config, loadConfig } from './config';
2
+ export { type Config, loadConfig, mergeConfigs } from './config';
3
3
  export { checkReadmeFiles, checkReadmeString, collapseReadmeFiles, expandReadmeFiles, expandReadmeString, } from './readme/api';
4
4
  export { loadConfigReadme } from './readme/config';
5
5
  export { type Rules } from 'remark-mdat';
package/dist/index.js CHANGED
@@ -1,31 +1,31 @@
1
- import{defaultLoaders as Mt}from"cosmiconfig";function oe(t,e){let n=Mt[".json"],r=n(t,e);return Ve(r)}function Ve(t,e="",n={}){for(let[r,o]of Object.entries(t)){let i=e?`${e}.${r}`:r;typeof o=="object"&&o!==null&&!Array.isArray(o)?Ve(o,i,n):o===null?n[i]="null":n[i]=o.toString()}return n}import Ft from"node:fs";import P from"node:path";import{packageUp as Dt}from"package-up";import{isFileSync as Je}from"path-type";import jt from"untildify";function vt(t,e){let n=e===0?1:Math.floor(Math.log10(Math.abs(e))+1);return t.toString().padStart(n,"0")}function He(t,e,n,r){let o=[];for(let[i,s]of t.entries()){let m=n&&t.length>1?`-${vt(i+1,t.length+1)}`:"",d=Ut(s,e,n,r,m);o.push(d)}return o}function Ut(t,e,n,r,o=""){let i=Be(t),s=e?Be(e):void 0;if(!Je(i))throw new Error(`Input file not found: "${i}"`);if(s){if(Je(s))throw new Error(`Output path must be a directory, received a file path: "${s}"`);Ft.mkdirSync(s,{recursive:!0})}let m=n?P.basename(n,P.extname(n)):P.basename(i,P.extname(i)),d=`.${r??(n&&P.extname(n)!==""?P.extname(n):P.extname(t)===""?"":P.extname(t))}`,a=`${m}${o}${d}`,p=s??P.dirname(i);return{input:i,name:a,output:p}}function Be(t){return jt(t)}async function ze(){return Dt()}function qe(t){return t==null?[]:Array.isArray(t)?t:[t]}import Ke from"chalk";import{cosmiconfig as Ge}from"cosmiconfig";import It from"node:fs/promises";import Ze from"node:path";import _t from"plur";import{readPackage as Vt}from"read-pkg";import{deepMergeDefined as re,log as h,optionsSchema as Jt,rulesSchema as Bt}from"remark-mdat";import{z as ie}from"zod";var Ye=Jt.merge(ie.object({assetsPath:ie.string().optional(),packageFile:ie.string().optional()})).describe("Config Extension");async function y(t){let{additionalConfig:e,additionalRules:n,searchFrom:r}=t??{},o={addMetaComment:!1,assetsPath:"./assets",closingPrefix:"/",keywordPrefix:"",metaCommentIdentifier:"+",packageFile:await ze(),rules:{mdat:"Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat)."}},i=Ge("mdat"),s=await i.search(r);if(s){let{config:m,filepath:d}=s;h.info(`Using config from "${d}"`);let a=We(m,Ye);a&&(o=re(o,a))}if(e!==void 0){let m=Array.isArray(e)?e:[e];for(let d of m){let a;if(typeof d=="string"){let u=await i.load(d);if(u==null)continue;let{config:g,filepath:L}=u;h.info(`Loaded additional config from "${L}"`),a=g}else a=d;if(a===void 0)continue;h.info("Merging configuration object");let p=We(a,Ye);p!==void 0&&(o=re(o,p))}}if(n!==void 0){let m=Array.isArray(n)?n:[n],d=Ge("mdat",{loaders:{".json":oe}});for(let a of m){let p;if(typeof a=="string"){let g;if(Ze.basename(a).endsWith("package.json")){let ne=await It.readFile(a,"utf8");g={config:oe(a,ne),filepath:a}}else g=await d.load(a);if(g==null)continue;let{config:L,filepath:w}=g;h.info(`Loaded additional config from "${w}"`),p=L}else p=a;if(p===void 0)continue;h.info("Merging rules into configuration object");let u=Ht(p,Bt);u!==void 0&&(o=re(o,u))}}if(o.rules){let m=Object.keys(o.rules).sort().map(d=>`"${Ke.bold.green(d)}"`);h.info(`Loaded ${Ke.bold(m.length)} mdat comment expansion ${_t("rule",m.length)}:`);for(let d of m)h.info(` ${d}`)}else h.error("No rules loaded from additional configurations or rules, using default.");return _=o,o}function Ht(t,e){if(e.safeParse(t).success)return{rules:t};h.error(`Rules object has the wrong shape. Ignoring and using default configuration:
1
+ import{defaultLoaders as Mt}from"cosmiconfig";function re(t,e){let n=Mt[".json"],r=n(t,e);return Ve(r)}function Ve(t,e="",n={}){for(let[r,o]of Object.entries(t)){let i=e?`${e}.${r}`:r;typeof o=="object"&&o!==null&&!Array.isArray(o)?Ve(o,i,n):o===null?n[i]="null":n[i]=o.toString()}return n}import Ft from"node:fs";import P from"node:path";import{packageUp as Dt}from"package-up";import{isFileSync as Je}from"path-type";import jt from"untildify";function vt(t,e){let n=e===0?1:Math.floor(Math.log10(Math.abs(e))+1);return t.toString().padStart(n,"0")}function He(t,e,n,r){let o=[];for(let[i,s]of t.entries()){let m=n&&t.length>1?`-${vt(i+1,t.length+1)}`:"",d=Ut(s,e,n,r,m);o.push(d)}return o}function Ut(t,e,n,r,o=""){let i=Be(t),s=e?Be(e):void 0;if(!Je(i))throw new Error(`Input file not found: "${i}"`);if(s){if(Je(s))throw new Error(`Output path must be a directory, received a file path: "${s}"`);Ft.mkdirSync(s,{recursive:!0})}let m=n?P.basename(n,P.extname(n)):P.basename(i,P.extname(i)),d=`.${r??(n&&P.extname(n)!==""?P.extname(n):P.extname(t)===""?"":P.extname(t))}`,a=`${m}${o}${d}`,p=s??P.dirname(i);return{input:i,name:a,output:p}}function Be(t){return jt(t)}async function ze(){return Dt()}function qe(t){return t==null?[]:Array.isArray(t)?t:[t]}import Ke from"chalk";import{cosmiconfig as Ge}from"cosmiconfig";import It from"node:fs/promises";import Ze from"node:path";import _t from"plur";import{readPackage as Vt}from"read-pkg";import{deepMergeDefined as _,log as h,optionsSchema as Jt,rulesSchema as Bt}from"remark-mdat";import{z as ie}from"zod";var Ye=Jt.merge(ie.object({assetsPath:ie.string().optional(),packageFile:ie.string().optional()})).describe("Config Extension");async function y(t){let{additionalConfig:e,additionalRules:n,searchFrom:r}=t??{},o={addMetaComment:!1,assetsPath:"./assets",closingPrefix:"/",keywordPrefix:"",metaCommentIdentifier:"+",packageFile:await ze(),rules:{mdat:"Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat)."}},i=Ge("mdat"),s=await i.search(r);if(s){let{config:m,filepath:d}=s;h.info(`Using config from "${d}"`);let a=We(m,Ye);a&&(o=_(o,a))}if(e!==void 0){let m=Array.isArray(e)?e:[e];for(let d of m){let a;if(typeof d=="string"){let f=await i.load(d);if(f==null)continue;let{config:g,filepath:L}=f;h.info(`Loaded additional config from "${L}"`),a=g}else a=d;if(a===void 0)continue;h.info("Merging configuration object");let p=We(a,Ye);p!==void 0&&(o=_(o,p))}}if(n!==void 0){let m=Array.isArray(n)?n:[n],d=Ge("mdat",{loaders:{".json":re}});for(let a of m){let p;if(typeof a=="string"){let g;if(Ze.basename(a).endsWith("package.json")){let oe=await It.readFile(a,"utf8");g={config:re(a,oe),filepath:a}}else g=await d.load(a);if(g==null)continue;let{config:L,filepath:w}=g;h.info(`Loaded additional config from "${w}"`),p=L}else p=a;if(p===void 0)continue;h.info("Merging rules into configuration object");let f=Ht(p,Bt);f!==void 0&&(o=_(o,f))}}if(o.rules){let m=Object.keys(o.rules).sort().map(d=>`"${Ke.bold.green(d)}"`);h.info(`Loaded ${Ke.bold(m.length)} mdat comment expansion ${_t("rule",m.length)}:`);for(let d of m)h.info(` ${d}`)}else h.error("No rules loaded from additional configurations or rules, using default.");return V=o,o}function Ht(t,e){if(e.safeParse(t).success)return{rules:t};h.error(`Rules object has the wrong shape. Ignoring and using default configuration:
2
2
  ${JSON.stringify(t,void 0,2)}`)}function We(t,e){if(e.safeParse(t).success)return t;h.error(`Config object has the wrong shape. Ignoring and using default configuration:
3
- ${JSON.stringify(t,void 0,2)}`)}var _;async function b(){return _===void 0&&(h.warn("getConfig(): config was undefined"),_??=await y()),_}var se;async function l(){let{packageFile:t}=await b();if(t===void 0)throw new Error("No packageFile found or set in config");if(se??=await Vt({cwd:Ze.dirname(t)}),se===void 0)throw new Error("No package.json found");return se}import{remark as ae}from"remark";import me from"remark-gfm";import{mdatCheck as zt,mdatClean as Xe,mdatExpand as qt,mdatSplit as Qe}from"remark-mdat";import{read as Kt}from"to-vfile";import{VFile as Gt}from"vfile";async function E(t,e,n,r,o,i,s){let m=await e({additionalConfig:i,additionalRules:s});i=m;let d=qe(t),a=He(d,o,r,"md"),p=[],u=n(m);for(let{input:g,name:L,output:w}of a){let ne=await Kt(g),I=await u.process(ne);I.dirname=w,I.basename=L,p.push(I)}return p}async function O(t,e,n,r,o){let i=await e({additionalConfig:r,additionalRules:o});return r=i,n(i).process(new Gt(t))}function T(t){return ae().use({settings:{bullet:"-",emphasis:"_"}}).use(me).use(()=>async function(n,r){Qe(n,r),Xe(n,r,t),await qt(n,r,t)})}function M(t){return ae().use({settings:{bullet:"-",emphasis:"_"}}).use(me).use(()=>function(n,r){Qe(n,r),Xe(n,r,t)})}function x(t){return ae().use({settings:{bullet:"-",emphasis:"_"}}).use(me).use(()=>async function(n,r){await zt(n,r,{...t,paranoid:!1})})}async function Yt(t,e,n,r,o){return E(t,y,T,e,n,r,o)}async function Wt(t,e,n){return O(t,y,T,e,n)}async function Zt(t,e,n,r,o){return E(t,y,x,e,n,r,o)}async function Xt(t,e,n){return O(t,y,x,e,n)}async function Qt(t,e,n,r,o){return E(t,y,M,e,n,r,o)}async function en(t,e,n){return O(t,y,M,e,n)}import{z as F}from"zod";var V={badges:{async content(t){var s;let e=F.object({custom:F.record(F.object({image:F.string(),link:F.string()})).optional()}).optional().parse(t),n=await l(),{name:r}=n,o=[];!n.private&&((s=n.publishConfig)==null?void 0:s.access)==="public"&&o.push(`[![NPM Package](https://img.shields.io/npm/v/${r}.svg)](https://npmjs.com/package/${r})`);let{license:i}=n;if(i!==void 0&&o.push(`[![License: ${i}](https://img.shields.io/badge/License-${i}-yellow.svg)](https://opensource.org/licenses/${i})`),(e==null?void 0:e.custom)!==void 0)for(let[m,{image:d,link:a}]of Object.entries(e.custom))o.push(`[![${m}](${d})](${a})`);return o.join(`
4
- `)},order:3,required:!1}};import{globby as tn}from"globby";import J from"node:path";import{isFile as nn}from"path-type";import{readPackage as on}from"read-pkg";import{z as de}from"zod";async function rn(t){let{packageFile:e}=await b();if(e===void 0)throw new Error("No package.json found");let n=J.dirname(e),r=t===void 0?[".","assets","media","readme-assets","readme-media","readme","images"]:[t],o=["banner","header","logo","readme","cover","screenshot","screenshots","demo","overview","image","hero"],i=["png","gif","jpg","jpeg","svg","webp"],s=await tn(r.map(m=>J.join(n,m)),{expandDirectories:{extensions:i,files:o}});if(s.length>0)return J.relative(process.cwd(),s[0])}var B={banner:{async content(t){let e=de.object({alt:de.string().optional(),src:de.string().optional()}).optional().parse(t),{assetsPath:n,packageFile:r}=await b();if(r===void 0)throw new Error("No package.json found");let o=(e==null?void 0:e.src)??await rn(n);if(o===void 0||!await nn(o))throw new Error(`Banner image not found at ${o===void 0?"any typical location, consider adding something at ./assets/banner.webp":`"${o}"`}`);let i=(e==null?void 0:e.alt)??`${(await on({cwd:J.dirname(r)})).name} banner`;if(i===void 0||i==="undefined banner")throw new Error("Banner image alt text not available");return`![${i}](${o})`},order:2}};function et(t,e=Number.MAX_SAFE_INTEGER){let n=[],r=sn(t,e);return n.push(an(r)),n.push(mn(t,r)),r.hasMultipleSubcommands&&r.canRecurse&&n.push(dn(r.fullCommandName)),r.defaultCommand&&n.push(cn(r)),n.push(pn(t,r)),t.positionals&&!r.commandsOnly&&n.push(ce(["Positional Argument","Description","Type","Default"],t.positionals.map(o=>[o.arguments?[o.arguments.map(i=>`\`${i}\``)].join(" "):"",`${o.description??""}${o.required?" _(Required.)_":" _(Optional.)_"}`,o.type?`\`${o.type}\``:"",o.defaultValue?o.defaultValue.includes(" ")?o.defaultValue:`\`${o.defaultValue}\``:""]))),t.commands&&n.push(ce(["Command","Argument","Description"],t.commands.map(o=>{var i;return[`\`${o.commandName??(o.default?"[default]":"")}\``,o.arguments?(i=o.arguments)==null?void 0:i.map(s=>`\`${s}\``).join(" "):"",`${o.description??""}${o.default?" _(Default command.)_":""}`]}))),t.options&&!r.commandsOnly&&n.push(ce(["Option","Alias","Argument","Description","Type","Default"],t.options.map(o=>[o.flags?o.flags.map(i=>`\`${i}\``).join(" "):"",o.aliases?o.aliases.map(i=>`\`${i}\``).join(" "):"",o.arguments?o.arguments.map(i=>`\`${i}\``).join(" "):"",o.description??"",o.type?`\`${o.type}\``:"",o.defaultValue?o.defaultValue.includes(" ")?o.defaultValue:`\`${o.defaultValue}\``:""]))),r.commandsOnly&&n.push("_See the sections below for more information on each subcommand._"),n.join(`
3
+ ${JSON.stringify(t,void 0,2)}`)}var V;async function b(){return V===void 0&&(h.warn("getConfig(): config was undefined"),V??=await y()),V}var se;async function l(){let{packageFile:t}=await b();if(t===void 0)throw new Error("No packageFile found or set in config");if(se??=await Vt({cwd:Ze.dirname(t)}),se===void 0)throw new Error("No package.json found");return se}function zt(t,e){return _(t,e)}import{remark as ae}from"remark";import me from"remark-gfm";import{mdatCheck as qt,mdatClean as Xe,mdatExpand as Kt,mdatSplit as Qe}from"remark-mdat";import{read as Gt}from"to-vfile";import{VFile as Yt}from"vfile";async function E(t,e,n,r,o,i,s){let m=await e({additionalConfig:i,additionalRules:s});i=m;let d=qe(t),a=He(d,o,r,"md"),p=[],f=n(m);for(let{input:g,name:L,output:w}of a){let oe=await Gt(g),I=await f.process(oe);I.dirname=w,I.basename=L,p.push(I)}return p}async function O(t,e,n,r,o){let i=await e({additionalConfig:r,additionalRules:o});return r=i,n(i).process(new Yt(t))}function T(t){return ae().use({settings:{bullet:"-",emphasis:"_"}}).use(me).use(()=>async function(n,r){Qe(n,r),Xe(n,r,t),await Kt(n,r,t)})}function M(t){return ae().use({settings:{bullet:"-",emphasis:"_"}}).use(me).use(()=>function(n,r){Qe(n,r),Xe(n,r,t)})}function x(t){return ae().use({settings:{bullet:"-",emphasis:"_"}}).use(me).use(()=>async function(n,r){await qt(n,r,{...t,paranoid:!1})})}async function Wt(t,e,n,r,o){return E(t,y,T,e,n,r,o)}async function Zt(t,e,n){return O(t,y,T,e,n)}async function Xt(t,e,n,r,o){return E(t,y,x,e,n,r,o)}async function Qt(t,e,n){return O(t,y,x,e,n)}async function en(t,e,n,r,o){return E(t,y,M,e,n,r,o)}async function tn(t,e,n){return O(t,y,M,e,n)}import{z as F}from"zod";var J={badges:{async content(t){var s;let e=F.object({custom:F.record(F.object({image:F.string(),link:F.string()})).optional()}).optional().parse(t),n=await l(),{name:r}=n,o=[];!n.private&&((s=n.publishConfig)==null?void 0:s.access)==="public"&&o.push(`[![NPM Package](https://img.shields.io/npm/v/${r}.svg)](https://npmjs.com/package/${r})`);let{license:i}=n;if(i!==void 0&&o.push(`[![License: ${i}](https://img.shields.io/badge/License-${i}-yellow.svg)](https://opensource.org/licenses/${i})`),(e==null?void 0:e.custom)!==void 0)for(let[m,{image:d,link:a}]of Object.entries(e.custom))o.push(`[![${m}](${d})](${a})`);return o.join(`
4
+ `)},order:3,required:!1}};import{globby as nn}from"globby";import B from"node:path";import{isFile as on}from"path-type";import{readPackage as rn}from"read-pkg";import{z as de}from"zod";async function sn(t){let{packageFile:e}=await b();if(e===void 0)throw new Error("No package.json found");let n=B.dirname(e),r=t===void 0?[".","assets","media","readme-assets","readme-media","readme","images"]:[t],o=["banner","header","logo","readme","cover","screenshot","screenshots","demo","overview","image","hero"],i=["png","gif","jpg","jpeg","svg","webp"],s=await nn(r.map(m=>B.join(n,m)),{expandDirectories:{extensions:i,files:o}});if(s.length>0)return B.relative(process.cwd(),s[0])}var H={banner:{async content(t){let e=de.object({alt:de.string().optional(),src:de.string().optional()}).optional().parse(t),{assetsPath:n,packageFile:r}=await b();if(r===void 0)throw new Error("No package.json found");let o=(e==null?void 0:e.src)??await sn(n);if(o===void 0||!await on(o))throw new Error(`Banner image not found at ${o===void 0?"any typical location, consider adding something at ./assets/banner.webp":`"${o}"`}`);let i=(e==null?void 0:e.alt)??`${(await rn({cwd:B.dirname(r)})).name} banner`;if(i===void 0||i==="undefined banner")throw new Error("Banner image alt text not available");return`![${i}](${o})`},order:2}};function et(t,e=Number.MAX_SAFE_INTEGER){let n=[],r=an(t,e);return n.push(mn(r)),n.push(dn(t,r)),r.hasMultipleSubcommands&&r.canRecurse&&n.push(cn(r.fullCommandName)),r.defaultCommand&&n.push(pn(r)),n.push(fn(t,r)),t.positionals&&!r.commandsOnly&&n.push(ce(["Positional Argument","Description","Type","Default"],t.positionals.map(o=>[o.arguments?[o.arguments.map(i=>`\`${i}\``)].join(" "):"",`${o.description??""}${o.required?" _(Required.)_":" _(Optional.)_"}`,o.type?`\`${o.type}\``:"",o.defaultValue?o.defaultValue.includes(" ")?o.defaultValue:`\`${o.defaultValue}\``:""]))),t.commands&&n.push(ce(["Command","Argument","Description"],t.commands.map(o=>{var i;return[`\`${o.commandName??(o.default?"[default]":"")}\``,o.arguments?(i=o.arguments)==null?void 0:i.map(s=>`\`${s}\``).join(" "):"",`${o.description??""}${o.default?" _(Default command.)_":""}`]}))),t.options&&!r.commandsOnly&&n.push(ce(["Option","Alias","Argument","Description","Type","Default"],t.options.map(o=>[o.flags?o.flags.map(i=>`\`${i}\``).join(" "):"",o.aliases?o.aliases.map(i=>`\`${i}\``).join(" "):"",o.arguments?o.arguments.map(i=>`\`${i}\``).join(" "):"",o.description??"",o.type?`\`${o.type}\``:"",o.defaultValue?o.defaultValue.includes(" ")?o.defaultValue:`\`${o.defaultValue}\``:""]))),r.commandsOnly&&n.push("_See the sections below for more information on each subcommand._"),n.join(`
5
5
 
6
- `)}function sn(t,e){var a,p;let n=t.subcommandName===void 0,r=t.commands?t.commands.length>1:!1,o=e>1,i=(a=t.commands)==null?void 0:a.find(u=>u.default),s=(p=t.commands)==null?void 0:p.find(u=>u.commandName===void 0),m=`${t.commandName}${t.subcommandName?` ${t.subcommandName}`:""}`;return{canRecurse:o,commandsOnly:o&&r,defaultCommand:i,fullCommandName:m,hasMultipleSubcommands:r,isTopLevel:n,topLevelCommand:s}}function an(t){return`#### ${t.isTopLevel?"Command":"Subcommand"}: \`${t.fullCommandName}\``}function mn(t,e){var n,r;return e.isTopLevel&&((n=e.topLevelCommand)!=null&&n.description)?(t.commands=(r=t.commands)==null?void 0:r.filter(o=>o!==e.topLevelCommand),e.topLevelCommand.description):t.description??""}function dn(t){return`This section lists top-level commands for \`${t}\`.`}function cn(t){var e;return`If no command is provided, \`${t.fullCommandName} ${(e=t.defaultCommand)==null?void 0:e.commandName}\` is run by default.`}function pn(t,e){var r;let n=(r=e.topLevelCommand)!=null&&r.arguments?` ${e.topLevelCommand.arguments.join(" ")}`:`${t.arguments?` ${t.arguments.join(" ")}`:""}`;return`Usage:
6
+ `)}function an(t,e){var a,p;let n=t.subcommandName===void 0,r=t.commands?t.commands.length>1:!1,o=e>1,i=(a=t.commands)==null?void 0:a.find(f=>f.default),s=(p=t.commands)==null?void 0:p.find(f=>f.commandName===void 0),m=`${t.commandName}${t.subcommandName?` ${t.subcommandName}`:""}`;return{canRecurse:o,commandsOnly:o&&r,defaultCommand:i,fullCommandName:m,hasMultipleSubcommands:r,isTopLevel:n,topLevelCommand:s}}function mn(t){return`#### ${t.isTopLevel?"Command":"Subcommand"}: \`${t.fullCommandName}\``}function dn(t,e){var n,r;return e.isTopLevel&&((n=e.topLevelCommand)!=null&&n.description)?(t.commands=(r=t.commands)==null?void 0:r.filter(o=>o!==e.topLevelCommand),e.topLevelCommand.description):t.description??""}function cn(t){return`This section lists top-level commands for \`${t}\`.`}function pn(t){var e;return`If no command is provided, \`${t.fullCommandName} ${(e=t.defaultCommand)==null?void 0:e.commandName}\` is run by default.`}function fn(t,e){var r;let n=(r=e.topLevelCommand)!=null&&r.arguments?` ${e.topLevelCommand.arguments.join(" ")}`:`${t.arguments?` ${t.arguments.join(" ")}`:""}`;return`Usage:
7
7
  \`\`\`txt
8
8
  ${e.fullCommandName}${n}
9
9
  \`\`\``}function ce(t,e){let n=un(e);t=t.filter((o,i)=>!n.includes(i)),e=e.map(o=>o.filter((i,s)=>!n.includes(s)));let r="";r+=`| ${t.join(" | ")} |
10
10
  `,r+=`| ${t.map(()=>"---").join(" | ")} |
11
11
  `;for(let o of e)r+=`| ${o.join(" | ")} |
12
- `;return r}function un(t){var r;let e=[],n=((r=t[0])==null?void 0:r.length)||0;for(let o=0;o<n;o++){let i=!0;for(let s of t)if(s[o]!==""){i=!1;break}i&&e.push(o)}return e}import{CstParser as fn,Lexer as S,createToken as f}from"chevrotain";var z=f({name:"flag",pattern:/--[\w-_]+/}),fe=f({longer_alt:z,name:"alias",pattern:/-[A-Za-z]/}),tt=f({group:S.SKIPPED,name:"comma",pattern:/,/}),nt=f({group:S.SKIPPED,name:"dollar",pattern:/\$/}),H=f({group:S.SKIPPED,name:"whiteSpace",pattern:/ /}),ot=f({group:S.SKIPPED,name:"newLine",pattern:/\n/}),le=f({name:"word",pattern:/\S+/}),j=f({name:"argument",pattern:/(<\S+>|\[.+])/}),ge=f({name:"programDescription",pattern:/\w.+(?=\n\n {2}Usage)/}),rt=f({group:S.SKIPPED,name:"startUsage",pattern:/ {2}Usage\n/,push_mode:"USAGE_MODE"}),it=f({group:S.SKIPPED,name:"endUsage",pattern:/\n/,pop_mode:!0}),he=f({name:"startOptions",pattern:/ {2}Options\n/,push_mode:"OPTIONS_MODE"}),ye=f({name:"startRow",pattern:/ {4}/,push_mode:"ROW_MODE"}),Ce=f({name:"rowDescription",pattern:/\w.+/}),st=f({group:S.SKIPPED,name:"endRow",pattern:/\n/,pop_mode:!0}),at=f({group:S.SKIPPED,name:"endOptions",pattern:/\n/,pop_mode:!0}),ln=new S({defaultMode:"DEFAULT_MODE",modes:{DEFAULT_MODE:[rt,he,ge,ot,H],OPTIONS_MODE:[at,ye],ROW_MODE:[st,fe,z,tt,j,Ce,H],USAGE_MODE:[it,nt,j,le,H]}}),gn=[z,fe,tt,nt,H,ot,le,j,ge,rt,it,he,ye,Ce,st,at],pe=class extends fn{programHelp=this.RULE("programHelp",()=>{this.CONSUME(ge,{LABEL:"description"}),this.AT_LEAST_ONE(()=>{this.CONSUME(le,{LABEL:"commandName"})}),this.MANY(()=>{this.CONSUME(j)}),this.OPTION(()=>{this.SUBRULE(this.optionsSection)})});optionsSection=this.RULE("optionsSection",()=>{this.CONSUME(he),this.MANY(()=>{this.SUBRULE(this.sectionRow)})});sectionRow=this.RULE("sectionRow",()=>{this.CONSUME(ye),this.MANY(()=>{this.OR([{ALT:()=>this.CONSUME(j)},{ALT:()=>this.CONSUME(fe)},{ALT:()=>this.CONSUME(z)},{ALT:()=>this.CONSUME(Ce,{LABEL:"description"})}])})});constructor(){super(gn),this.performSelfAnalysis()}},D=new pe,ue=class extends D.getBaseCstVisitorConstructor(){constructor(){super(),this.validateVisitor()}programHelp(e){let{command:n,subcommand:r}=q(this.getString(e.commandName));return{arguments:this.getArray(e.argument),commandName:n,description:this.getString(e.description),options:e.optionsSection?this.visit(e.optionsSection):void 0,subcommandName:r}}optionsSection(e){return e.sectionRow.map(n=>this.visit(n))}sectionRow(e){return{aliases:this.getArray(e.alias),arguments:this.getArray(e.argument),description:this.getString(e.description,!0),flags:this.getArray(e.flag)}}getString(e,n=!1){if(e!==void 0)return e.map(r=>n?this.clean(r.image):r.image).join(" ")}getArray(e){if(e!==void 0)return e.map(n=>n.image)}clean(e){return e.replaceAll(/^[\s[]*(default:)?\s*|[\s\]]*$/g,"")}},hn=new ue;function mt(t){let e=ln.tokenize(t);if(e.errors.length>0)throw new Error(`Errors lexing CLI command: ${JSON.stringify(e.errors,void 0,2)}`);D.input=e.tokens;let n=D.programHelp();if(D.errors.length>0)throw new Error(`Errors parsing CLI command help text: ${JSON.stringify(D.errors,void 0,2)}`);let r;try{r=hn.visit(n)}catch(o){if(o instanceof Error)throw new TypeError(`Errors visiting CLI command help text: ${String(o)}`)}if(r===void 0)throw new Error("Could not parse help string");return r}import{CstParser as yn,Lexer as k,createToken as c}from"chevrotain";var Ee=c({name:"flag",pattern:/--[\w-_]+/}),Re=c({name:"alias",pattern:/-[A-Za-z]/}),dt=c({group:k.SKIPPED,name:"comma",pattern:/,/}),$=c({name:"word",pattern:/\S+/}),U=c({name:"argument",pattern:/<\S+>|\[\S+]/}),Le=c({name:"type",pattern:/\[(boolean|string|array)]/}),be=c({name:"defaultInfo",pattern:/\[default]/}),Oe=c({name:"required",pattern:/\[required]/}),ke=c({name:"defaultInfoDescription",pattern:/\[default:\s.+?]/}),Ne=c({name:"choices",pattern:/\[choices:\s.+?]/}),we=c({group:k.SKIPPED,name:"whiteSpace",pattern:/\s/}),ct=c({group:k.SKIPPED,name:"startProgramDescription",pattern:/\n\n/,push_mode:"PROGRAM_DESCRIPTION_MODE"}),Te=c({name:"programDescription",pattern:/.+/}),pt=c({group:k.SKIPPED,name:"endProgramDescription",pattern:/\n\n/,pop_mode:!0}),xe=c({name:"startOptionsSection",pattern:/Options:?\n/,push_mode:"SECTION_MODE"}),$e=c({name:"startPositionalsSection",pattern:/Positionals:\n/,push_mode:"SECTION_MODE"}),Ae=c({name:"startCommandsSection",pattern:/Commands:\n/,push_mode:"SECTION_MODE"}),Me=c({name:"startRow",pattern:/ {2,}/,push_mode:"ROW_MODE"}),Fe=c({name:"rowDescription",pattern:/ {2}\w.+ {2}/}),De=c({name:"rowDescriptionTerminal",pattern:/ {2}\w.+/}),ut=c({group:k.SKIPPED,name:"endRow",pattern:/\n/,pop_mode:!0}),ft=c({group:k.SKIPPED,name:"endSection",pattern:/\n+/,pop_mode:!0}),Cn=new k({defaultMode:"DEFAULT_MODE",modes:{DEFAULT_MODE:[xe,$e,Ae,ct,U,$,we],PROGRAM_DESCRIPTION_MODE:[pt,Te],ROW_MODE:[ut,dt,Le,Fe,De,ke,be,Oe,Ne,Ee,Re,U,$,we],SECTION_MODE:[Me,ft]}}),wn=[Ee,Re,dt,$,U,Le,be,Oe,ke,Ne,we,ct,Te,pt,xe,$e,Ae,Me,Fe,De,ut,ft],Pe=class extends yn{programHelp=this.RULE("programHelp",()=>{this.AT_LEAST_ONE(()=>{this.CONSUME($,{LABEL:"commandName"})}),this.MANY1(()=>{this.CONSUME(U)}),this.OPTION(()=>{this.CONSUME(Te,{LABEL:"description"})}),this.OPTION1(()=>{this.SUBRULE(this.commandsSection)}),this.OPTION2(()=>{this.SUBRULE(this.positionalsSection)}),this.OPTION3(()=>{this.SUBRULE(this.optionsSection)})});positionalsSection=this.RULE("positionalsSection",()=>{this.CONSUME($e),this.MANY(()=>{this.SUBRULE(this.sectionRow)})});commandsSection=this.RULE("commandsSection",()=>{this.CONSUME(Ae),this.MANY1(()=>{this.SUBRULE1(this.sectionRow)})});optionsSection=this.RULE("optionsSection",()=>{this.CONSUME(xe),this.MANY2(()=>{this.SUBRULE2(this.sectionRow)})});sectionRow=this.RULE("sectionRow",()=>{this.CONSUME(Me),this.OPTION(()=>{this.CONSUME($,{LABEL:"parentCommandName"})}),this.MANY(()=>{this.CONSUME1($,{LABEL:"commandName"})}),this.MANY1(()=>{this.OR([{ALT:()=>this.CONSUME(U)},{ALT:()=>this.CONSUME(Re)},{ALT:()=>this.CONSUME(Ee)},{ALT:()=>this.CONSUME(Fe,{LABEL:"description"})},{ALT:()=>this.CONSUME(De,{LABEL:"description"})},{ALT:()=>this.CONSUME(Le)},{ALT:()=>this.CONSUME(Oe)},{ALT:()=>this.CONSUME(ke)},{ALT:()=>this.CONSUME(be)},{ALT:()=>this.CONSUME(Ne)}])})});constructor(){super(wn),this.performSelfAnalysis()}},v=new Pe,Se=class extends v.getBaseCstVisitorConstructor(){constructor(){super(),this.validateVisitor()}programHelp(e){let{command:n,subcommand:r}=q(this.getString(e.commandName));return{arguments:this.getArray(e.argument),commandName:n,commands:e.commandsSection?this.visit(e.commandsSection):void 0,description:this.getString(e.description),options:e.optionsSection?this.visit(e.optionsSection):void 0,positionals:e.positionalsSection?this.visit(e.positionalsSection):void 0,subcommandName:r}}positionalsSection(e){return e.sectionRow.map(n=>this.positionalParentCommandToArguments(this.visit(n)))}commandsSection(e){return e.sectionRow.map(n=>this.visit(n))}optionsSection(e){return e.sectionRow.map(n=>this.visit(n))}sectionRow(e){return{aliases:this.getArray(e.alias),arguments:this.getArray(e.argument),choices:this.splitChoices(this.getString(e.choices)),commandName:this.getString(e.commandName),default:e.defaultInfo?!0:void 0,defaultValue:this.getString(e.defaultInfoDescription,!0),description:this.getString(e.description,!0),flags:this.getArray(e.flag),parentCommandName:this.getString(e.parentCommandName),required:e.required?!0:void 0,type:this.getString(e.type,!0)}}positionalParentCommandToArguments(e){let{arguments:n,parentCommandName:r,...o}=e;return r===void 0?e:{arguments:[r,...n??[]],...o}}getString(e,n=!1){if(e!==void 0)return e.map(r=>n?this.clean(r.image):r.image).join(" ")}getArray(e){if(e!==void 0)return e.map(n=>n.image)}clean(e){return e.replaceAll(/^[\s[]*(default:)?\s*|[\s\]]*$/g,"")}splitChoices(e){if(e!==void 0)return this.clean(e.replaceAll(/^\[choices:\s/g,"")).split(", ")}},Pn=new Se;function lt(t){let e=Cn.tokenize(t);if(e.errors.length>0)throw new Error(`Errors lexing CLI command: ${JSON.stringify(e.errors,void 0,2)}`);v.input=e.tokens;let n=v.programHelp();if(v.errors.length>0)throw new Error(`Errors parsing CLI command help text: ${JSON.stringify(v.errors,void 0,2)}`);let r;try{r=Pn.visit(n)}catch(o){if(o instanceof Error)throw new TypeError(`Errors visiting CLI command help text: ${String(o)}`)}if(r===void 0)throw new Error("Could not parse help string");return r}var gt={meow:mt,yargs:lt};function q(t){if(t===void 0)throw new Error('Could not find "commandName" entry in help');let e=t.split(" ");if(e.length===0&&t===void 0)throw new Error('Could not find "commandName" entry in help');if(e.length===1)return{command:e[0],subcommand:void 0};let n=e.at(-1);return{command:e.slice(0,-1).join(" "),subcommand:n}}import{log as je}from"remark-mdat";function ht(t){for(let[e,n]of Object.entries(gt)){je.info(`Trying to parse help string with ${e} parser...`);try{return n(t)}catch(r){r instanceof Error&&je.info(`Error in "${e}" parser: ${String(r)}`);continue}}je.error("Could not parse help string with any parser")}import{execaCommand as Sn}from"execa";import{log as yt}from"remark-mdat";async function ve(t,e="--help",n){let r=`${t} ${e}`,o=await Ln(r),i=ht(o);return i===void 0?(yt.warn("Falling back to basic cli help text output."),Rn(o)):En(t,e,n??Number.MAX_SAFE_INTEGER,i)}async function En(t,e,n,r){if(n<=0)return yt.info("Max CLI command help depth reached, stopping recursion"),"";let o=et(r,n),i=t.split(" ")[0];if(r.commands)for(let s of r.commands){if(!s.parentCommandName||!s.commandName)continue;let m=await ve(`${i} ${s.commandName}`,e,n-1);if(m==="")return o;o+=`
12
+ `;return r}function un(t){var r;let e=[],n=((r=t[0])==null?void 0:r.length)||0;for(let o=0;o<n;o++){let i=!0;for(let s of t)if(s[o]!==""){i=!1;break}i&&e.push(o)}return e}import{CstParser as ln,Lexer as S,createToken as u}from"chevrotain";var q=u({name:"flag",pattern:/--[\w-_]+/}),ue=u({longer_alt:q,name:"alias",pattern:/-[A-Za-z]/}),tt=u({group:S.SKIPPED,name:"comma",pattern:/,/}),nt=u({group:S.SKIPPED,name:"dollar",pattern:/\$/}),z=u({group:S.SKIPPED,name:"whiteSpace",pattern:/ /}),ot=u({group:S.SKIPPED,name:"newLine",pattern:/\n/}),le=u({name:"word",pattern:/\S+/}),j=u({name:"argument",pattern:/(<\S+>|\[.+])/}),ge=u({name:"programDescription",pattern:/\w.+(?=\n\n {2}Usage)/}),rt=u({group:S.SKIPPED,name:"startUsage",pattern:/ {2}Usage\n/,push_mode:"USAGE_MODE"}),it=u({group:S.SKIPPED,name:"endUsage",pattern:/\n/,pop_mode:!0}),he=u({name:"startOptions",pattern:/ {2}Options\n/,push_mode:"OPTIONS_MODE"}),ye=u({name:"startRow",pattern:/ {4}/,push_mode:"ROW_MODE"}),Ce=u({name:"rowDescription",pattern:/\w.+/}),st=u({group:S.SKIPPED,name:"endRow",pattern:/\n/,pop_mode:!0}),at=u({group:S.SKIPPED,name:"endOptions",pattern:/\n/,pop_mode:!0}),gn=new S({defaultMode:"DEFAULT_MODE",modes:{DEFAULT_MODE:[rt,he,ge,ot,z],OPTIONS_MODE:[at,ye],ROW_MODE:[st,ue,q,tt,j,Ce,z],USAGE_MODE:[it,nt,j,le,z]}}),hn=[q,ue,tt,nt,z,ot,le,j,ge,rt,it,he,ye,Ce,st,at],pe=class extends ln{programHelp=this.RULE("programHelp",()=>{this.CONSUME(ge,{LABEL:"description"}),this.AT_LEAST_ONE(()=>{this.CONSUME(le,{LABEL:"commandName"})}),this.MANY(()=>{this.CONSUME(j)}),this.OPTION(()=>{this.SUBRULE(this.optionsSection)})});optionsSection=this.RULE("optionsSection",()=>{this.CONSUME(he),this.MANY(()=>{this.SUBRULE(this.sectionRow)})});sectionRow=this.RULE("sectionRow",()=>{this.CONSUME(ye),this.MANY(()=>{this.OR([{ALT:()=>this.CONSUME(j)},{ALT:()=>this.CONSUME(ue)},{ALT:()=>this.CONSUME(q)},{ALT:()=>this.CONSUME(Ce,{LABEL:"description"})}])})});constructor(){super(hn),this.performSelfAnalysis()}},D=new pe,fe=class extends D.getBaseCstVisitorConstructor(){constructor(){super(),this.validateVisitor()}programHelp(e){let{command:n,subcommand:r}=K(this.getString(e.commandName));return{arguments:this.getArray(e.argument),commandName:n,description:this.getString(e.description),options:e.optionsSection?this.visit(e.optionsSection):void 0,subcommandName:r}}optionsSection(e){return e.sectionRow.map(n=>this.visit(n))}sectionRow(e){return{aliases:this.getArray(e.alias),arguments:this.getArray(e.argument),description:this.getString(e.description,!0),flags:this.getArray(e.flag)}}getString(e,n=!1){if(e!==void 0)return e.map(r=>n?this.clean(r.image):r.image).join(" ")}getArray(e){if(e!==void 0)return e.map(n=>n.image)}clean(e){return e.replaceAll(/^[\s[]*(default:)?\s*|[\s\]]*$/g,"")}},yn=new fe;function mt(t){let e=gn.tokenize(t);if(e.errors.length>0)throw new Error(`Errors lexing CLI command: ${JSON.stringify(e.errors,void 0,2)}`);D.input=e.tokens;let n=D.programHelp();if(D.errors.length>0)throw new Error(`Errors parsing CLI command help text: ${JSON.stringify(D.errors,void 0,2)}`);let r;try{r=yn.visit(n)}catch(o){if(o instanceof Error)throw new TypeError(`Errors visiting CLI command help text: ${String(o)}`)}if(r===void 0)throw new Error("Could not parse help string");return r}import{CstParser as Cn,Lexer as k,createToken as c}from"chevrotain";var Ee=c({name:"flag",pattern:/--[\w-_]+/}),Re=c({name:"alias",pattern:/-[A-Za-z]/}),dt=c({group:k.SKIPPED,name:"comma",pattern:/,/}),$=c({name:"word",pattern:/\S+/}),U=c({name:"argument",pattern:/<\S+>|\[\S+]/}),Le=c({name:"type",pattern:/\[(boolean|string|array)]/}),be=c({name:"defaultInfo",pattern:/\[default]/}),Oe=c({name:"required",pattern:/\[required]/}),ke=c({name:"defaultInfoDescription",pattern:/\[default:\s.+?]/}),Ne=c({name:"choices",pattern:/\[choices:\s.+?]/}),we=c({group:k.SKIPPED,name:"whiteSpace",pattern:/\s/}),ct=c({group:k.SKIPPED,name:"startProgramDescription",pattern:/\n\n/,push_mode:"PROGRAM_DESCRIPTION_MODE"}),Te=c({name:"programDescription",pattern:/.+/}),pt=c({group:k.SKIPPED,name:"endProgramDescription",pattern:/\n\n/,pop_mode:!0}),xe=c({name:"startOptionsSection",pattern:/Options:?\n/,push_mode:"SECTION_MODE"}),$e=c({name:"startPositionalsSection",pattern:/Positionals:\n/,push_mode:"SECTION_MODE"}),Ae=c({name:"startCommandsSection",pattern:/Commands:\n/,push_mode:"SECTION_MODE"}),Me=c({name:"startRow",pattern:/ {2,}/,push_mode:"ROW_MODE"}),Fe=c({name:"rowDescription",pattern:/ {2}\w.+ {2}/}),De=c({name:"rowDescriptionTerminal",pattern:/ {2}\w.+/}),ft=c({group:k.SKIPPED,name:"endRow",pattern:/\n/,pop_mode:!0}),ut=c({group:k.SKIPPED,name:"endSection",pattern:/\n+/,pop_mode:!0}),wn=new k({defaultMode:"DEFAULT_MODE",modes:{DEFAULT_MODE:[xe,$e,Ae,ct,U,$,we],PROGRAM_DESCRIPTION_MODE:[pt,Te],ROW_MODE:[ft,dt,Le,Fe,De,ke,be,Oe,Ne,Ee,Re,U,$,we],SECTION_MODE:[Me,ut]}}),Pn=[Ee,Re,dt,$,U,Le,be,Oe,ke,Ne,we,ct,Te,pt,xe,$e,Ae,Me,Fe,De,ft,ut],Pe=class extends Cn{programHelp=this.RULE("programHelp",()=>{this.AT_LEAST_ONE(()=>{this.CONSUME($,{LABEL:"commandName"})}),this.MANY1(()=>{this.CONSUME(U)}),this.OPTION(()=>{this.CONSUME(Te,{LABEL:"description"})}),this.OPTION1(()=>{this.SUBRULE(this.commandsSection)}),this.OPTION2(()=>{this.SUBRULE(this.positionalsSection)}),this.OPTION3(()=>{this.SUBRULE(this.optionsSection)})});positionalsSection=this.RULE("positionalsSection",()=>{this.CONSUME($e),this.MANY(()=>{this.SUBRULE(this.sectionRow)})});commandsSection=this.RULE("commandsSection",()=>{this.CONSUME(Ae),this.MANY1(()=>{this.SUBRULE1(this.sectionRow)})});optionsSection=this.RULE("optionsSection",()=>{this.CONSUME(xe),this.MANY2(()=>{this.SUBRULE2(this.sectionRow)})});sectionRow=this.RULE("sectionRow",()=>{this.CONSUME(Me),this.OPTION(()=>{this.CONSUME($,{LABEL:"parentCommandName"})}),this.MANY(()=>{this.CONSUME1($,{LABEL:"commandName"})}),this.MANY1(()=>{this.OR([{ALT:()=>this.CONSUME(U)},{ALT:()=>this.CONSUME(Re)},{ALT:()=>this.CONSUME(Ee)},{ALT:()=>this.CONSUME(Fe,{LABEL:"description"})},{ALT:()=>this.CONSUME(De,{LABEL:"description"})},{ALT:()=>this.CONSUME(Le)},{ALT:()=>this.CONSUME(Oe)},{ALT:()=>this.CONSUME(ke)},{ALT:()=>this.CONSUME(be)},{ALT:()=>this.CONSUME(Ne)}])})});constructor(){super(Pn),this.performSelfAnalysis()}},v=new Pe,Se=class extends v.getBaseCstVisitorConstructor(){constructor(){super(),this.validateVisitor()}programHelp(e){let{command:n,subcommand:r}=K(this.getString(e.commandName));return{arguments:this.getArray(e.argument),commandName:n,commands:e.commandsSection?this.visit(e.commandsSection):void 0,description:this.getString(e.description),options:e.optionsSection?this.visit(e.optionsSection):void 0,positionals:e.positionalsSection?this.visit(e.positionalsSection):void 0,subcommandName:r}}positionalsSection(e){return e.sectionRow.map(n=>this.positionalParentCommandToArguments(this.visit(n)))}commandsSection(e){return e.sectionRow.map(n=>this.visit(n))}optionsSection(e){return e.sectionRow.map(n=>this.visit(n))}sectionRow(e){return{aliases:this.getArray(e.alias),arguments:this.getArray(e.argument),choices:this.splitChoices(this.getString(e.choices)),commandName:this.getString(e.commandName),default:e.defaultInfo?!0:void 0,defaultValue:this.getString(e.defaultInfoDescription,!0),description:this.getString(e.description,!0),flags:this.getArray(e.flag),parentCommandName:this.getString(e.parentCommandName),required:e.required?!0:void 0,type:this.getString(e.type,!0)}}positionalParentCommandToArguments(e){let{arguments:n,parentCommandName:r,...o}=e;return r===void 0?e:{arguments:[r,...n??[]],...o}}getString(e,n=!1){if(e!==void 0)return e.map(r=>n?this.clean(r.image):r.image).join(" ")}getArray(e){if(e!==void 0)return e.map(n=>n.image)}clean(e){return e.replaceAll(/^[\s[]*(default:)?\s*|[\s\]]*$/g,"")}splitChoices(e){if(e!==void 0)return this.clean(e.replaceAll(/^\[choices:\s/g,"")).split(", ")}},Sn=new Se;function lt(t){let e=wn.tokenize(t);if(e.errors.length>0)throw new Error(`Errors lexing CLI command: ${JSON.stringify(e.errors,void 0,2)}`);v.input=e.tokens;let n=v.programHelp();if(v.errors.length>0)throw new Error(`Errors parsing CLI command help text: ${JSON.stringify(v.errors,void 0,2)}`);let r;try{r=Sn.visit(n)}catch(o){if(o instanceof Error)throw new TypeError(`Errors visiting CLI command help text: ${String(o)}`)}if(r===void 0)throw new Error("Could not parse help string");return r}var gt={meow:mt,yargs:lt};function K(t){if(t===void 0)throw new Error('Could not find "commandName" entry in help');let e=t.split(" ");if(e.length===0&&t===void 0)throw new Error('Could not find "commandName" entry in help');if(e.length===1)return{command:e[0],subcommand:void 0};let n=e.at(-1);return{command:e.slice(0,-1).join(" "),subcommand:n}}import{log as je}from"remark-mdat";function ht(t){for(let[e,n]of Object.entries(gt)){je.info(`Trying to parse help string with ${e} parser...`);try{return n(t)}catch(r){r instanceof Error&&je.info(`Error in "${e}" parser: ${String(r)}`);continue}}je.error("Could not parse help string with any parser")}import{execaCommand as En}from"execa";import{log as yt}from"remark-mdat";async function ve(t,e="--help",n){let r=`${t} ${e}`,o=await bn(r),i=ht(o);return i===void 0?(yt.warn("Falling back to basic cli help text output."),Ln(o)):Rn(t,e,n??Number.MAX_SAFE_INTEGER,i)}async function Rn(t,e,n,r){if(n<=0)return yt.info("Max CLI command help depth reached, stopping recursion"),"";let o=et(r,n),i=t.split(" ")[0];if(r.commands)for(let s of r.commands){if(!s.parentCommandName||!s.commandName)continue;let m=await ve(`${i} ${s.commandName}`,e,n-1);if(m==="")return o;o+=`
13
13
 
14
- ${m}`}return o}function Rn(t){return`\`\`\`txt
14
+ ${m}`}return o}function Ln(t){return`\`\`\`txt
15
15
  ${t}
16
- \`\`\``}async function Ln(t){let e;try{let{stderr:n,stdout:r}=await Sn(t);e=r,(e===void 0||e==="")&&(e=n)}catch(n){if(n instanceof Error)throw new TypeError(`Error running CLI help command: "${t}"
16
+ \`\`\``}async function bn(t){let e;try{let{stderr:n,stdout:r}=await En(t);e=r,(e===void 0||e==="")&&(e=n)}catch(n){if(n instanceof Error)throw new TypeError(`Error running CLI help command: "${t}"
17
17
  ${n.message}
18
18
  `)}if(e===void 0||e==="")throw new Error(`No result from running CLI help command: "${t}"
19
- `);return e}import{isExecutable as bn}from"is-executable";import On from"node:path";import{log as kn}from"remark-mdat";import Nn from"which";async function Ct(t){return t??=await Tn(),$n(t)}async function Tn(){let t=await l();if(t!=null&&t.bin){let e=typeof t.bin=="string"?t.bin:String(Object.values(t.bin).at(0));if(xn(e))return kn.info(`Inferred <!-- cli-help --> command to run from package.json: ${e}`),e}throw new Error(`Could not infer which command to run for the <!-- cli-help --> rule. Please pass a "cliCommand" option to the expansion comment, e.g. <!-- cli-help {cliCommend: './dist/bin.js'} -->`)}function xn(t){let e=On.parse(t);return e.root!==""||e.dir!==""}async function $n(t){let e=await Nn(t,{nothrow:!0});if(e===null&&(e=await An(t)??void 0),e!==void 0&&await bn(e))return e;throw new Error(`The cli-help rule noticed that "${e}" is not executable.`)}async function An(t){var n;let e=await l();return((n=e==null?void 0:e.bin)==null?void 0:n[t])??void 0}import{z as K}from"zod";var wt={"cli-help":{async content(t){let e=K.object({cliCommand:K.string().optional(),depth:K.number().optional(),helpFlag:K.string().optional()}).parse(t),n=await Ct(e==null?void 0:e.cliCommand);return ve(n,e.helpFlag,e.depth)}}};import Mn from"node:fs/promises";import Pt from"node:path";import{z as Ue}from"zod";var St={code:{async content(t){let e=Ue.object({file:Ue.string(),language:Ue.string().optional()}).parse(t),n=Pt.extname(e.file)??"",r=await Mn.readFile(Pt.join(process.cwd(),e.file),"utf8");return`\`\`\`${n}
19
+ `);return e}import{isExecutable as On}from"is-executable";import kn from"node:path";import{log as Nn}from"remark-mdat";import Tn from"which";async function Ct(t){return t??=await xn(),An(t)}async function xn(){let t=await l();if(t!=null&&t.bin){let e=typeof t.bin=="string"?t.bin:String(Object.values(t.bin).at(0));if($n(e))return Nn.info(`Inferred <!-- cli-help --> command to run from package.json: ${e}`),e}throw new Error(`Could not infer which command to run for the <!-- cli-help --> rule. Please pass a "cliCommand" option to the expansion comment, e.g. <!-- cli-help {cliCommend: './dist/bin.js'} -->`)}function $n(t){let e=kn.parse(t);return e.root!==""||e.dir!==""}async function An(t){let e=await Tn(t,{nothrow:!0});if(e===null&&(e=await Mn(t)??void 0),e!==void 0&&await On(e))return e;throw new Error(`The cli-help rule noticed that "${e}" is not executable.`)}async function Mn(t){var n;let e=await l();return((n=e==null?void 0:e.bin)==null?void 0:n[t])??void 0}import{z as G}from"zod";var wt={"cli-help":{async content(t){let e=G.object({cliCommand:G.string().optional(),depth:G.number().optional(),helpFlag:G.string().optional()}).parse(t),n=await Ct(e==null?void 0:e.cliCommand);return ve(n,e.helpFlag,e.depth)}}};import Fn from"node:fs/promises";import Pt from"node:path";import{z as Ue}from"zod";var St={code:{async content(t){let e=Ue.object({file:Ue.string(),language:Ue.string().optional()}).parse(t),n=Pt.extname(e.file)??"",r=await Fn.readFile(Pt.join(process.cwd(),e.file),"utf8");return`\`\`\`${n}
20
20
  ${r}
21
- \`\`\``}}};var G={contributing:{async content(){var n;let t=await l(),e=(n=t==null?void 0:t.bugs)==null?void 0:n.url;if(e===void 0)throw new Error('Could not find "bugs.url" entry in package.json');return`## Contributing
22
- [Issues](${e}) and pull requests are welcome.`},order:15,required:!0}};var Y={license:{async content(){let t=await l(),{author:e,license:n}=t;if((e==null?void 0:e.name)===void 0)throw new Error('Could not find "author.name" entry in package.json');if(n===void 0)throw new Error('Could not find "license" entry in package.json');return`## License
23
- [${n}](license.txt) \xA9 ${e.name}`},order:16,required:!0}};import{getSoleRule as Et}from"remark-mdat";var Rt={footer:{content:[Et(G),Et(Y)],order:17}};var W={"short-description":{async content(){let t=await l();if(t.description===void 0)throw new Error('Could not find "description" entry in package.json');return`**${t.description}**`},order:4,required:!0}};import{z as Z}from"zod";var X={title:{applicationOrder:2,async content(t){let{postfix:e,prefix:n,titleCase:r}=Z.object({postfix:Z.string().optional().default(""),prefix:Z.string().optional().default(""),titleCase:Z.boolean().optional().default(!1)}).parse(t??{}),{name:o}=await l();return`# ${n}${r?Fn(o):o}${e}`},order:1,required:!0}};function Fn(t){return t.split(/[ _-]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}import{getSoleRule as Q}from"remark-mdat";var Lt={header:{applicationOrder:2,content:[Q(X),Q(B),Q(V),Q(W)],order:1}};import{toc as Dn}from"mdast-util-toc";import{remark as jn}from"remark";import vn from"remark-gfm";import{z as R}from"zod";var ee={"table-of-contents":{applicationOrder:1,async content(t,e){let n=R.object({maxDepth:R.union([R.literal(1),R.literal(2),R.literal(3),R.literal(4),R.literal(5),R.literal(6)]).optional()}).optional().parse(t),r=Dn(e,{heading:null,maxDepth:(n==null?void 0:n.maxDepth)??3,tight:!0}),o="## Table of contents";if(r.map===void 0)throw new Error("Could not generate table of contents");let i={children:r.map.children,type:"root"},s=jn().use(vn).stringify(i).replaceAll(`
21
+ \`\`\``}}};var Y={contributing:{async content(){var n;let t=await l(),e=(n=t==null?void 0:t.bugs)==null?void 0:n.url;if(e===void 0)throw new Error('Could not find "bugs.url" entry in package.json');return`## Contributing
22
+ [Issues](${e}) and pull requests are welcome.`},order:15,required:!0}};var W={license:{async content(){let t=await l(),{author:e,license:n}=t;if((e==null?void 0:e.name)===void 0)throw new Error('Could not find "author.name" entry in package.json');if(n===void 0)throw new Error('Could not find "license" entry in package.json');return`## License
23
+ [${n}](license.txt) \xA9 ${e.name}`},order:16,required:!0}};import{getSoleRule as Et}from"remark-mdat";var Rt={footer:{content:[Et(Y),Et(W)],order:17}};var Z={"short-description":{async content(){let t=await l();if(t.description===void 0)throw new Error('Could not find "description" entry in package.json');return`**${t.description}**`},order:4,required:!0}};import{z as X}from"zod";var Q={title:{applicationOrder:2,async content(t){let{postfix:e,prefix:n,titleCase:r}=X.object({postfix:X.string().optional().default(""),prefix:X.string().optional().default(""),titleCase:X.boolean().optional().default(!1)}).parse(t??{}),{name:o}=await l();return`# ${n}${r?Dn(o):o}${e}`},order:1,required:!0}};function Dn(t){return t.split(/[ _-]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}import{getSoleRule as ee}from"remark-mdat";var Lt={header:{applicationOrder:2,content:[ee(Q),ee(H),ee(J),ee(Z)],order:1}};import{toc as jn}from"mdast-util-toc";import{remark as vn}from"remark";import Un from"remark-gfm";import{z as R}from"zod";var te={"table-of-contents":{applicationOrder:1,async content(t,e){let n=R.object({maxDepth:R.union([R.literal(1),R.literal(2),R.literal(3),R.literal(4),R.literal(5),R.literal(6)]).optional()}).optional().parse(t),r=jn(e,{heading:null,maxDepth:(n==null?void 0:n.maxDepth)??3,tight:!0}),o="## Table of contents";if(r.map===void 0)throw new Error("Could not generate table of contents");let i={children:r.map.children,type:"root"},s=vn().use(Un).stringify(i).replaceAll(`
24
24
 
25
25
  `,`
26
26
  `);return[o,s].join(`
27
- `)},order:6}};import{tldrawToImage as bt}from"@kitschpatrol/tldraw-cli";import Un from"node:crypto";import A from"node:fs/promises";import C from"node:path";import{isFile as Ie}from"path-type";import{z as _e}from"zod";var Tt={tldraw:{async content(t){let{alt:e="tldraw diagram",src:n}=_e.object({alt:_e.string().optional(),src:_e.string()}).parse(t),{assetsPath:r}=await b();if(r===void 0)throw new Error("No assets path found");await A.mkdir(r,{recursive:!0});let o=await Ie(n)?await kt(n):void 0;if(o!==void 0){let a=C.basename(n,C.extname(n)),p=C.join(r,`${a}-${o}-light.svg`),u=C.join(r,`${a}-${o}-dark.svg`);if(await Ie(p)&&await Ie(u))return Ot(p,u,e)}let[i]=await bt(n,{dark:!1,format:"svg",output:r,transparent:!0});o??=await kt(i);let s=`${Nt(i)}-${o}-light.svg`;await A.rename(i,s);let[m]=await bt(n,{dark:!0,format:"svg",output:r,transparent:!0}),d=`${Nt(m)}-${o}-dark.svg`;if(await A.rename(m,d),o!==void 0){let a=C.basename(d),p=C.basename(s),u=p.replace(`${o}-light.svg`,""),g=await A.readdir(r);for(let L of g){let w=C.basename(L);w!==a&&w!==p&&w.startsWith(u)&&w.endsWith(".svg")&&await A.rm(C.join(r,w))}}return Ot(s,d,e)}}};async function Ot(t,e,n){let{packageFile:r}=await b();if(r===void 0)throw new Error("No package file found");let o=C.dirname(r),i=C.relative(o,t);return`<picture>
27
+ `)},order:6}};import{tldrawToImage as bt}from"@kitschpatrol/tldraw-cli";import In from"node:crypto";import A from"node:fs/promises";import C from"node:path";import{isFile as Ie}from"path-type";import{z as _e}from"zod";var Tt={tldraw:{async content(t){let{alt:e="tldraw diagram",src:n}=_e.object({alt:_e.string().optional(),src:_e.string()}).parse(t),{assetsPath:r}=await b();if(r===void 0)throw new Error("No assets path found");await A.mkdir(r,{recursive:!0});let o=await Ie(n)?await kt(n):void 0;if(o!==void 0){let a=C.basename(n,C.extname(n)),p=C.join(r,`${a}-${o}-light.svg`),f=C.join(r,`${a}-${o}-dark.svg`);if(await Ie(p)&&await Ie(f))return Ot(p,f,e)}let[i]=await bt(n,{dark:!1,format:"svg",output:r,transparent:!0});o??=await kt(i);let s=`${Nt(i)}-${o}-light.svg`;await A.rename(i,s);let[m]=await bt(n,{dark:!0,format:"svg",output:r,transparent:!0}),d=`${Nt(m)}-${o}-dark.svg`;if(await A.rename(m,d),o!==void 0){let a=C.basename(d),p=C.basename(s),f=p.replace(`${o}-light.svg`,""),g=await A.readdir(r);for(let L of g){let w=C.basename(L);w!==a&&w!==p&&w.startsWith(f)&&w.endsWith(".svg")&&await A.rm(C.join(r,w))}}return Ot(s,d,e)}}};async function Ot(t,e,n){let{packageFile:r}=await b();if(r===void 0)throw new Error("No package file found");let o=C.dirname(r),i=C.relative(o,t);return`<picture>
28
28
  <source media="(prefers-color-scheme: dark)" srcset="${C.relative(o,e)}">
29
29
  <source media="(prefers-color-scheme: light)" srcset="${i}">
30
30
  <img alt="${n}" src="${i}">
31
- </picture>`}async function kt(t){let e=await A.readFile(t),n=Un.createHash("sha1");return n.update(e),n.digest("hex").slice(0,8)}function Nt(t){return t.replace(/\.[^./]+$/,"")}import{getSoleRule as In}from"remark-mdat";var xt={toc:{applicationOrder:1,content:[In(ee)]}};var $t={...V,...B,...wt,...St,...G,...Rt,...Lt,...Y,...W,...ee,...Tt,...xt,...X};async function N(t){let e={addMetaComment:!0,rules:$t},{additionalConfig:n=[],...r}=t??{},o=Array.isArray(n)?n:[n],i=await y({additionalConfig:[e,...o],...r});if(i.packageFile===void 0)throw new Error("Package file path is required in `mdat readme` config");return i}import{findUp as _n}from"find-up";import{packageDirectory as Vn}from"pkg-dir";import{log as At}from"remark-mdat";async function Jn(){At.info("Searching for package directory...");let t=await Vn()??process.cwd(),e=await _n("readme.md",{stopAt:t,type:"file"});if(e!==void 0)return At.info(`Found closest readme at "${e}"`),e}async function te(){let t=await Jn();if(t===void 0)throw new Error("No readme found");return t}async function Bn(t,e,n,r,o){return t??=await te(),E(t,N,T,e,n,r,o)}async function Hn(t,e,n){return O(t,N,T,e,n)}async function zn(t,e,n,r,o){return t??=await te(),E(t,N,x,e,n,r,o)}async function qn(t,e,n){return O(t,N,x,e,n)}async function Kn(t,e,n,r,o){return t??=await te(),E(t,N,M,e,n,r,o)}export{Zt as checkFiles,zn as checkReadmeFiles,qn as checkReadmeString,Xt as checkString,Qt as collapseFiles,Kn as collapseReadmeFiles,en as collapseString,Yt as expandFiles,Bn as expandReadmeFiles,Hn as expandReadmeString,Wt as expandString,y as loadConfig,N as loadConfigReadme};
31
+ </picture>`}async function kt(t){let e=await A.readFile(t),n=In.createHash("sha1");return n.update(e),n.digest("hex").slice(0,8)}function Nt(t){return t.replace(/\.[^./]+$/,"")}import{getSoleRule as _n}from"remark-mdat";var xt={toc:{applicationOrder:1,content:[_n(te)]}};var $t={...J,...H,...wt,...St,...Y,...Rt,...Lt,...W,...Z,...te,...Tt,...xt,...Q};async function N(t){let e={addMetaComment:!0,rules:$t},{additionalConfig:n=[],...r}=t??{},o=Array.isArray(n)?n:[n],i=await y({additionalConfig:[e,...o],...r});if(i.packageFile===void 0)throw new Error("Package file path is required in `mdat readme` config");return i}import{findUp as Vn}from"find-up";import{packageDirectory as Jn}from"pkg-dir";import{log as At}from"remark-mdat";async function Bn(){At.info("Searching for package directory...");let t=await Jn()??process.cwd(),e=await Vn("readme.md",{stopAt:t,type:"file"});if(e!==void 0)return At.info(`Found closest readme at "${e}"`),e}async function ne(){let t=await Bn();if(t===void 0)throw new Error("No readme found");return t}async function Hn(t,e,n,r,o){return t??=await ne(),E(t,N,T,e,n,r,o)}async function zn(t,e,n){return O(t,N,T,e,n)}async function qn(t,e,n,r,o){return t??=await ne(),E(t,N,x,e,n,r,o)}async function Kn(t,e,n){return O(t,N,x,e,n)}async function Gn(t,e,n,r,o){return t??=await ne(),E(t,N,M,e,n,r,o)}export{Xt as checkFiles,qn as checkReadmeFiles,Kn as checkReadmeString,Qt as checkString,en as collapseFiles,Gn as collapseReadmeFiles,tn as collapseString,Wt as expandFiles,Hn as expandReadmeFiles,zn as expandReadmeString,Zt as expandString,y as loadConfig,N as loadConfigReadme,zt as mergeConfigs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdat",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "description": "CLI tool and library for using comments as content templates in Markdown files, with helpful presets for readmes.",
6
6
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "which": "^4.0.0",
71
71
  "yargs": "^17.7.2",
72
72
  "zod": "^3.22.4",
73
- "remark-mdat": "0.5.0"
73
+ "remark-mdat": "0.5.2"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/node": "^20.11.17",
package/readme.md CHANGED
@@ -747,15 +747,15 @@ Compound rules combine several stand-alone rules under a single keyword, which c
747
747
 
748
748
  The `init` command provides a number of "starter readme" templates incorporating `mdat` comment placeholders:
749
749
 
750
- - ##### Mdat Readme
750
+ - #### Mdat Readme
751
751
 
752
752
  The house style. An expansive starting point. Prune to your context and taste. The readme files in this monorepo started from this template.
753
753
 
754
- - ##### Standard Readme basic
754
+ - #### Standard Readme basic
755
755
 
756
756
  Includes only the "required" sections from the [Standard Readme](https://github.com/RichardLitt/standard-readme/blob/main/spec.md) specification. [See an example](https://github.com/RichardLitt/standard-readme/blob/main/example-readmes/minimal-readme.md).
757
757
 
758
- - ##### Standard Readme full
758
+ - #### Standard Readme full
759
759
 
760
760
  Includes all sections from the [Standard Readme](https://github.com/RichardLitt/standard-readme/blob/main/spec.md) specification. [See an example](https://github.com/RichardLitt/standard-readme/blob/main/example-readmes/maximal-readme.md).
761
761