mdat 0.4.0 → 0.5.1
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 +31 -33
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -25
- package/dist/readme/rules/cli-help/index.d.ts +1 -1
- package/dist/readme/rules/cli-help/utilities/get-help-markdown.d.ts +1 -1
- package/dist/readme/rules/cli-help/utilities/help-object-to-markdown.d.ts +2 -7
- package/dist/readme/rules/cli-help/utilities/help-string-to-object.d.ts +2 -0
- package/dist/readme/rules/cli-help/utilities/{help-cst-to-object.d.ts → parsers/index.d.ts} +14 -6
- package/dist/readme/rules/cli-help/utilities/parsers/meow.d.ts +2 -0
- package/dist/readme/rules/cli-help/utilities/parsers/yargs.d.ts +2 -0
- package/dist/readme/rules/index.d.ts +1 -1
- package/package.json +2 -2
- package/readme.md +14 -8
- package/dist/readme/rules/cli-help/utilities/help-string-to-cst.d.ts +0 -13
package/bin/cli.js
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{defaultLoaders as
|
|
3
|
-
${JSON.stringify(t,void 0,2)}`)}function
|
|
4
|
-
${JSON.stringify(t,void 0,2)}`)}var
|
|
5
|
-
`)},order:3,required:!1}};import{globby as
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`)}function Ve(t,e){let o=$o(e);t=t.filter((n,s)=>!o.includes(s)),e=e.map(n=>n.filter((s,r)=>!o.includes(r)));let i="";i+=`| ${t.join(" | ")} |
|
|
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:
|
|
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(`[](https://npmjs.com/package/${i})`);let{license:r}=n;if(r!==void 0&&o.push(`[](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(`[](${d})`);return o.join(`
|
|
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``},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
|
+
|
|
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:
|
|
8
|
+
\`\`\`txt
|
|
9
|
+
${e.fullCommandName}${n}
|
|
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(" | ")} |
|
|
12
11
|
`,i+=`| ${t.map(()=>"---").join(" | ")} |
|
|
13
|
-
`;for(let
|
|
14
|
-
`;return i}function
|
|
15
|
-
${n.message}
|
|
16
|
-
`)}if(o===void 0||o==="")throw new Error(`No result from running CLI help command: ${e}
|
|
17
|
-
`);let i;try{let n=wt(o);i=bt(n)}catch(n){n instanceof Error&&(i=void 0,xt.warn(`Error parsing help output for command: ${t}
|
|
18
|
-
${n.message}`),xt.warn("Falling back to basic cli help text output."))}return i===void 0?_o(o):No(t,i)}async function No(t,e){let o=(e.commands&&e.commands.some(s=>s.default))??!1,i=Ct(e,o),n=t.split(" ")[0];if(e.commands)for(let s of e.commands){if(!s.parentCommandName||!s.commandName)continue;let r=await Je(`${n} ${s.commandName}`);i+=`
|
|
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+=`
|
|
19
14
|
|
|
20
|
-
${
|
|
15
|
+
${s}`}return o}function uo(t){return`\`\`\`txt
|
|
21
16
|
${t}
|
|
22
|
-
\`\`\``}
|
|
17
|
+
\`\`\``}async function fo(t){let e;try{let{stderr:n,stdout:i}=await po(t);e=i,(e===void 0||e==="")&&(e=n)}catch(n){if(n instanceof Error)throw new TypeError(`Error running CLI help command: "${t}"
|
|
18
|
+
${n.message}
|
|
19
|
+
`)}if(e===void 0||e==="")throw new Error(`No result from running CLI help command: "${t}"
|
|
20
|
+
`);return e}import{isExecutable as go}from"is-executable";import ho from"node:path";import{log as yo}from"remark-mdat";import wo from"which";async function Kt(t){return t??=await bo(),Po(t)}async function bo(){let t=await h();if(t!=null&&t.bin){let e=typeof t.bin=="string"?t.bin:String(Object.values(t.bin).at(0));if(Co(e))return yo.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 Co(t){let e=ho.parse(t);return e.root!==""||e.dir!==""}async function Po(t){let e=await wo(t,{nothrow:!0});if(e===null&&(e=await Oo(t)??void 0),e!==void 0&&await go(e))return e;throw new Error(`The cli-help rule noticed that "${e}" is not executable.`)}async function Oo(t){var n;let e=await h();return((n=e==null?void 0:e.bin)==null?void 0:n[t])??void 0}import{z as ce}from"zod";var Wt={"cli-help":{async content(t){let e=ce.object({cliCommand:ce.string().optional(),depth:ce.number().optional(),helpFlag:ce.string().optional()}).parse(t),n=await Kt(e==null?void 0:e.cliCommand);return rt(n,e.helpFlag,e.depth)}}};import xo from"node:fs/promises";import Yt from"node:path";import{z as at}from"zod";var Zt={code:{async content(t){let e=at.object({file:at.string(),language:at.string().optional()}).parse(t),n=Yt.extname(e.file)??"",i=await xo.readFile(Yt.join(process.cwd(),e.file),"utf8");return`\`\`\`${n}
|
|
23
21
|
${i}
|
|
24
|
-
\`\`\``}}};var
|
|
25
|
-
[Issues](${e}) and pull requests are welcome.`},order:15,required:!0}};var
|
|
26
|
-
[${
|
|
22
|
+
\`\`\``}}};var pe={contributing:{async content(){var n;let t=await h(),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
|
|
23
|
+
[Issues](${e}) and pull requests are welcome.`},order:15,required:!0}};var le={license:{async content(){let t=await h(),{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
|
|
24
|
+
[${n}](license.txt) \xA9 ${e.name}`},order:16,required:!0}};import{getSoleRule as Xt}from"remark-mdat";var Qt={footer:{content:[Xt(pe),Xt(le)],order:17}};var ue={"short-description":{async content(){let t=await h();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 fe}from"zod";var ge={title:{applicationOrder:2,async content(t){let{postfix:e,prefix:n,titleCase:i}=fe.object({postfix:fe.string().optional().default(""),prefix:fe.string().optional().default(""),titleCase:fe.boolean().optional().default(!1)}).parse(t??{}),{name:o}=await h();return`# ${n}${i?Ro(o):o}${e}`},order:1,required:!0}};function Ro(t){return t.split(/[ _-]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}import{getSoleRule as he}from"remark-mdat";var en={header:{applicationOrder:2,content:[he(ge),he(ae),he(ie),he(ue)],order:1}};import{toc as So}from"mdast-util-toc";import{remark as ko}from"remark";import Eo from"remark-gfm";import{z as S}from"zod";var ye={"table-of-contents":{applicationOrder:1,async content(t,e){let n=S.object({maxDepth:S.union([S.literal(1),S.literal(2),S.literal(3),S.literal(4),S.literal(5),S.literal(6)]).optional()}).optional().parse(t),i=So(e,{heading:null,maxDepth:(n==null?void 0:n.maxDepth)??3,tight:!0}),o="## Table of contents";if(i.map===void 0)throw new Error("Could not generate table of contents");let r={children:i.map.children,type:"root"},a=ko().use(Eo).stringify(r).replaceAll(`
|
|
27
25
|
|
|
28
26
|
`,`
|
|
29
|
-
`);return[
|
|
30
|
-
`)},order:6}};import{tldrawToImage as
|
|
31
|
-
<source media="(prefers-color-scheme: dark)" srcset="${
|
|
32
|
-
<source media="(prefers-color-scheme: light)" srcset="${
|
|
33
|
-
<img alt="${
|
|
34
|
-
</picture>`}async function
|
|
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>
|
|
29
|
+
<source media="(prefers-color-scheme: dark)" srcset="${C.relative(o,e)}">
|
|
30
|
+
<source media="(prefers-color-scheme: light)" srcset="${r}">
|
|
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 -->
|
|
35
33
|
|
|
36
34
|
<!-- table-of-contents -->
|
|
37
35
|
|
|
@@ -76,7 +74,7 @@ _List maintainer(s) for a repository, along with one way of contacting them (e.g
|
|
|
76
74
|
_State anyone or anything that significantly helped with the development of your project. State public contact hyper-links if applicable._
|
|
77
75
|
|
|
78
76
|
<!-- footer -->
|
|
79
|
-
`;var
|
|
77
|
+
`;var fn=`<!-- title -->
|
|
80
78
|
|
|
81
79
|
<!-- banner -->
|
|
82
80
|
|
|
@@ -129,7 +127,7 @@ _State anyone or anything that significantly helped with the development of your
|
|
|
129
127
|
<!-- contributing -->
|
|
130
128
|
|
|
131
129
|
<!-- license -->
|
|
132
|
-
`;var
|
|
130
|
+
`;var gn=`<!-- header -->
|
|
133
131
|
|
|
134
132
|
## Install
|
|
135
133
|
|
|
@@ -145,7 +143,7 @@ Consider using the <!-- code { src: "path/to/example.ts" } --> comment as well.
|
|
|
145
143
|
\`\`\`
|
|
146
144
|
|
|
147
145
|
<!-- footer -->
|
|
148
|
-
`;var
|
|
146
|
+
`;var hn=`<!-- title -->
|
|
149
147
|
|
|
150
148
|
<!-- short-description -->
|
|
151
149
|
|
|
@@ -167,7 +165,7 @@ Consider using the <!-- code { src: "path/to/example.ts" } --> comment as well.
|
|
|
167
165
|
<!-- contributing -->
|
|
168
166
|
|
|
169
167
|
<!-- license -->
|
|
170
|
-
`;var
|
|
168
|
+
`;var yn=`<!-- header -->
|
|
171
169
|
|
|
172
170
|
_Long description goes here._
|
|
173
171
|
|
|
@@ -230,7 +228,7 @@ _List maintainer(s) for a repository, along with one way of contacting them (e.g
|
|
|
230
228
|
_State anyone or anything that significantly helped with the development of your project. State public contact hyper-links if applicable._
|
|
231
229
|
|
|
232
230
|
<!-- footer -->
|
|
233
|
-
`;var
|
|
231
|
+
`;var wn=`<!-- title -->
|
|
234
232
|
|
|
235
233
|
<!-- banner -->
|
|
236
234
|
|
|
@@ -301,4 +299,4 @@ _State anyone or anything that significantly helped with the development of your
|
|
|
301
299
|
<!-- contributing -->
|
|
302
300
|
|
|
303
301
|
<!-- license -->
|
|
304
|
-
`;var L={"Mdat Readme":{content:{compound:Vt,explicit:Jt},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:Bt,explicit:qt},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:Ht,explicit:zt},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 Gt,group as nn,intro as rn,note as Wt,outro as sn,select as We}from"@clack/prompts";import R from"chalk";import an from"node:fs/promises";import le from"node:path";import{deepMergeDefined as dn}from"remark-mdat";import{write as cn}from"to-vfile";async function Yt(){let t=await ze(),e=await W();return{packageDirectory:e===void 0?void 0:le.dirname(le.resolve(e)),readmePath:t}}async function Kt(){let{packageDirectory:t,readmePath:e}=await Yt(),o=le.resolve(process.cwd());rn(`Running ${R.bold("mdat readme init")} interactively`);let i=await nn({overwrite:async()=>e===void 0||await Gt({message:`Found an existing readme at "${R.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!==o?We({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: "${R.blue(t)}"`,value:t},{label:`Create in current working directory: "${R.blue(o)}"`,value:o}]}):o,template:async()=>We({message:"Which template would you like to use?",options:pn()}),compound:async()=>We({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 ${R.green("<!-- title -->")} and ${R.green("<!-- badges -->")} in a single ${R.green("<!-- header -->")} comment.`,value:!0},{label:"No: Use individual `mdat` expansion comments for each section.",value:!1}]}),expand:async()=>t===void 0?!1:Gt({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")}}),n=await Ye(i);return t===void 0&&Wt("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."),Wt(`Readme created: "${R.bold.blue(n)}"`),sn("Done!"),n}async function Ye(t){let{packageDirectory:e}=await Yt(),o=dn({compound:!0,output:e??process.cwd(),overwrite:!0,expand:e!==void 0,template:Object.keys(L)[0]},t??{}),i=mn(o.template,o.compound),n=le.join(o.output,"readme.md");await an.writeFile(n,i,"utf8");let s=await It(void 0,void 0,{readmeFile:n});return await cn(s),n}function mn(t,e){let i=L[t].content[e?"compound":"explicit"];if(i===void 0||i==="")throw new Error(`No template found for "${t}"`);return i}function pn(){return Object.entries(L).map(([t,e])=>({label:t,hint:e.description,value:t}))}var E={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"}},B={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"}},q={name:{alias:"n",defaultDescription:"Same name as input file. Overwrites the input file.",description:"Output file name.",type:"string"}},D={output:{alias:"o",defaultDescription:"Same directory as input file.",description:"Output file directory.",type:"string"}},$={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"}},H={print:{description:"Print the expanded Markdown to stdout instead of saving to a file. Ignores `--output` and `--name` options.",type:"boolean"}},z={rules:{alias:"r",description:"Path(s) to files containing `mdat` comment expansion rules.",string:!0,type:"array"}},O={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"}},ue=["files",{array:!0,demandOption:!0,describe:"Markdown file(s) with `mdat` placeholder comments to collapse.",type:"string"}];var Ke={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}},Ze={assets:{defaultDescription:"./assets",description:"Path to find and save readme-related assets.",string:!0}},Zt={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"}},Qt={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"}},Xt={expand:{alias:"e",default:!0,description:"Automatically run `mdat readme` immediately after creating the readme template.",type:"boolean"}},eo={template:{alias:"t",choices:Object.keys(L),default:Object.keys(L)[0],description:"Specify a template to use for the new readme.",type:"string"}},to={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"}},fe=["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 Qe from"chalk";import T from"pretty-ms";import{getMdatReports as ln,log as u,reporterMdat as I}from"remark-mdat";import{write as ge}from"to-vfile";import un from"yargs";import{hideBin as fn}from"yargs/helpers";var N=performance.now(),oo=un(fn(process.argv));try{await oo.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(...ue).option(E).option(z).option(D).option(q).option(B).option($).option(H).option(O),async({config:t,files:e,meta:o,name:i,output:n,prefix:s,print:r,rules:a,verbose:c})=>{u.verbose=c??!1,he({name:i,output:n,print:r});let d=M(t,{addMetaComment:o,keywordPrefix:s}),m=await mt(e,i,n,d,a);for(let l of m)r?process.stdout.write(l.toString()):await ge(l);I(m),u.info(`Expanded comments in ${T(performance.now()-N)}.`),process.exitCode=U(m)}).command("check <files..> [options]","Validate a markdown file with `mdat` placeholder comments.",t=>t.positional(...ue).option(E).option(z).option(B).option($).option(O),async({config:t,files:e,meta:o,prefix:i,rules:n,verbose:s})=>{u.verbose=s??!1;let r=M(t,{addMetaComment:o,keywordPrefix:i}),a=await pt(e,void 0,void 0,r,n);I(a),u.info(`Checked comments in ${T(performance.now()-N)}.`),process.exitCode=U(a)}).command("collapse <files..> [options]","Collapse `mdat` placeholder comments.",t=>t.positional(...ue).option(E).option(D).option(q).option($).option(H).option(O),async({config:t,files:e,name:o,output:i,prefix:n,print:s,verbose:r})=>{u.verbose=r??!1,he({name:o,output:i,print:s});let a=M(t,{keywordPrefix:n}),c=await lt(e,void 0,void 0,a);for(let d of c)s?process.stdout.write(d.toString()):await ge(d);I(c),u.info(`Cleaned comments in ${T(performance.now()-N)}.`),process.exitCode=U(c)}).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(...fe).option(E).option(z).option(D).option(q).option(Ke).option(Ze).option($).option(B).option(H).option(O),async({assets:e,config:o,files:i,meta:n,name:s,output:r,package:a,prefix:c,print:d,rules:m,verbose:l})=>{u.verbose=l??!1,he({name:s,output:r,print:d});let f=M(o,{addMetaComment:n,assetsPath:e,keywordPrefix:c,packageFile:a}),h=await Ge(i,s,r,f,m);for(let _ of h)d?process.stdout.write(_.toString()):await ge(_);I(h);let{packageFile:y}=await C();u.info(`Pulled package metadata from: ${Qe.bold.blue(y)}`),u.info(`Expanded readme(s) in ${T(performance.now()-N)}.`),process.exitCode=U(h)}).command("check [files..] [options]","Validate `mdat` placeholder comments in your readme.md.",e=>e.positional(...fe).option(E).option(z).option(Ke).option(Ze).option($).option(B).option(O),async({assets:e,config:o,files:i,meta:n,package:s,prefix:r,rules:a,verbose:c})=>{u.verbose=c??!1;let d=M(o,{addMetaComment:n,assetsPath:e,keywordPrefix:r,packageFile:s}),m=await Mt(i,void 0,void 0,d,a);I(m);let{packageFile:l}=await C();u.info(`Pulled package metadata from: ${Qe.bold.blue(l)}`),u.info(`Checked readme(s) in ${T(performance.now()-N)}.`),process.exitCode=U(m)}).command("collapse [files..] [options]","Collapse `mdat` placeholder comments in your readme.md.",e=>e.positional(...fe).option(D).option(q).option(H).option(E).option($).option(O),async({config:e,files:o,name:i,output:n,prefix:s,print:r,verbose:a})=>{u.verbose=a??!1,he({name:i,output:n,print:r});let c=M(e,{keywordPrefix:s,readmeFile}),d=await Ut(o,void 0,void 0,c);for(let m of d)r?process.stdout.write(m.toString()):await ge(m);I(d),u.info(`Cleaned readme(s) in ${T(performance.now()-N)}.`),process.exitCode=U(d)}).command("init [options]","Interactively create a new readme.md file with sensible default `mdat` comment placeholders.",e=>e.option(Zt).option(Qt).option(D).option(Xt).option(eo).option(to).option(O),async({compound:e,expand:o,interactive:i,output:n,overwrite:s,template:r,verbose:a})=>{if(u.verbose=a??!1,i)await Kt();else{let c=await Ye({compound:e,expand:o,output:n,overwrite:s,template:r});u.info(`Created readme at "${Qe.blue(c)}" in ${T(performance.now()-N)}.`)}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,oo.terminalWidth()):0).fail(!1).parse()}catch(t){t instanceof Error&&u.error(t.message),process.exitCode=1}function he(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 M(t,e){return[...Y(t),e]}function U(t){return ln(t).reduce((i,n)=>i+n.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 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}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { checkFiles, checkString, collapseFiles, collapseString, expandFiles, ex
|
|
|
2
2
|
export { type Config, loadConfig } from './config';
|
|
3
3
|
export { checkReadmeFiles, checkReadmeString, collapseReadmeFiles, expandReadmeFiles, expandReadmeString, } from './readme/api';
|
|
4
4
|
export { loadConfigReadme } from './readme/config';
|
|
5
|
-
export { type Rules } from 'remark-mdat';
|
|
5
|
+
export { type Rules, deepMergeDefined as mergeConfigs } from 'remark-mdat';
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
import{defaultLoaders as
|
|
2
|
-
${JSON.stringify(t,void 0,2)}`)}function
|
|
3
|
-
${JSON.stringify(t,void 0,2)}`)}var
|
|
4
|
-
`)},order:3,required:!1}};import{globby as
|
|
5
|
-
${a.parentCommandName}${a.arguments?` ${a.arguments.join(" ")}`:""}
|
|
6
|
-
\`\`\``),t.commands=(s=t.commands)==null?void 0:s.filter(d=>d!==a)}else n.push(`#### Subcommand: \`${t.commandName} ${t.subcommandName}\``),n.push(t.description),n.push("Usage:"),n.push(`\`\`\`txt
|
|
7
|
-
${t.commandName} ${t.subcommandName}${t.arguments?` ${t.arguments.join(" ")}`:""}
|
|
8
|
-
\`\`\``);return t.positionals&&!e&&n.push(we(["Positional Argument","Description","Type","Default"],t.positionals.map(i=>[i.arguments?[i.arguments.map(a=>`\`${a}\``)].join(" "):"",`${i.description??""}${i.required?" _(Required.)_":" _(Optional.)_"}`,i.type?`\`${i.type}\``:"",i.defaultValue?i.defaultValue.includes(" ")?i.defaultValue:`\`${i.defaultValue}\``:""]))),t.commands&&n.push(we(["Command","Argument","Description"],t.commands.map(i=>{var a;return[`\`${i.commandName??(i.default?"[default]":"")}\``,i.arguments?(a=i.arguments)==null?void 0:a.map(m=>`\`${m}\``).join(" "):"",`${i.description??""}${i.default?" _(Default command.)_":""}`]}))),t.options&&!e&&n.push(we(["Option","Alias","Argument","Description","Type","Default"],t.options.map(i=>[i.flags?i.flags.map(a=>`\`${a}\``).join(" "):"",i.aliases?i.aliases.map(a=>`\`${a}\``).join(" "):"",i.arguments?i.arguments.map(a=>`\`${a}\``).join(" "):"",i.description??"",i.type?`\`${i.type}\``:"",i.defaultValue?i.defaultValue.includes(" ")?i.defaultValue:`\`${i.defaultValue}\``:""]))),e&&n.push("_See the sections below for more information on each subcommand._"),n.join(`
|
|
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:
|
|
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(`[](https://npmjs.com/package/${r})`);let{license:i}=n;if(i!==void 0&&o.push(`[](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(`[](${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``},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(`
|
|
9
5
|
|
|
10
|
-
`)}function
|
|
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:
|
|
7
|
+
\`\`\`txt
|
|
8
|
+
${e.fullCommandName}${n}
|
|
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(" | ")} |
|
|
11
10
|
`,r+=`| ${t.map(()=>"---").join(" | ")} |
|
|
12
11
|
`;for(let o of e)r+=`| ${o.join(" | ")} |
|
|
13
|
-
`;return r}function
|
|
14
|
-
${o.message}
|
|
15
|
-
`)}if(n===void 0||n==="")throw new Error(`No result from running CLI help command: ${e}
|
|
16
|
-
`);let r;try{let o=Je(n);r=Be(o)}catch(o){o instanceof Error&&(r=void 0,ze.warn(`Error parsing help output for command: ${t}
|
|
17
|
-
${o.message}`),ze.warn("Falling back to basic cli help text output."))}return r===void 0?Bt(n):Jt(t,r)}async function Jt(t,e){let n=(e.commands&&e.commands.some(s=>s.default))??!1,r=He(e,n),o=t.split(" ")[0];if(e.commands)for(let s of e.commands){if(!s.parentCommandName||!s.commandName)continue;let i=await Pe(`${o} ${s.commandName}`);r+=`
|
|
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+=`
|
|
18
13
|
|
|
19
|
-
${
|
|
14
|
+
${m}`}return o}function Rn(t){return`\`\`\`txt
|
|
20
15
|
${t}
|
|
21
|
-
\`\`\``}
|
|
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}"
|
|
17
|
+
${n.message}
|
|
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}
|
|
22
20
|
${r}
|
|
23
|
-
\`\`\``}}};var
|
|
24
|
-
[Issues](${e}) and pull requests are welcome.`},order:15,required:!0}};var
|
|
25
|
-
[${n}](license.txt) \xA9 ${e.name}`},order:16,required:!0}};import{getSoleRule as
|
|
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(`
|
|
26
24
|
|
|
27
25
|
`,`
|
|
28
|
-
`);return[o,
|
|
29
|
-
`)},order:6}};import{tldrawToImage as
|
|
30
|
-
<source media="(prefers-color-scheme: dark)" srcset="${
|
|
31
|
-
<source media="(prefers-color-scheme: light)" srcset="${
|
|
32
|
-
<img alt="${n}" src="${
|
|
33
|
-
</picture>`}async function
|
|
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>
|
|
28
|
+
<source media="(prefers-color-scheme: dark)" srcset="${C.relative(o,e)}">
|
|
29
|
+
<source media="(prefers-color-scheme: light)" srcset="${i}">
|
|
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)}import{deepMergeDefined as Li}from"remark-mdat";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,Li as mergeConfigs};
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import { type ProgramInfo } from './
|
|
2
|
-
|
|
3
|
-
* Simple case without subcommands
|
|
4
|
-
* @param programInfo - a ProgramInfo object, likely output from helpCstToObject()
|
|
5
|
-
* @returns - markdown string with help in table form, ready to be rendered
|
|
6
|
-
*/
|
|
7
|
-
export declare function helpObjectToMarkdown(programInfo: ProgramInfo, commandsOnly?: boolean): string;
|
|
1
|
+
import { type ProgramInfo } from './parsers/index';
|
|
2
|
+
export declare function helpObjectToMarkdown(programInfo: ProgramInfo, depthRemaining?: number): string;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { helpStringToObject as helpStringToObjectMeow } from './meow';
|
|
2
|
+
import { helpStringToObject as helpStringToObjectYargs } from './yargs';
|
|
3
|
+
export type Command = {
|
|
3
4
|
arguments?: string[];
|
|
4
5
|
commandName?: string;
|
|
5
6
|
default?: boolean;
|
|
6
7
|
description?: string;
|
|
7
8
|
parentCommandName?: string;
|
|
8
9
|
};
|
|
9
|
-
type Positional = {
|
|
10
|
+
export type Positional = {
|
|
10
11
|
arguments?: string[];
|
|
11
12
|
defaultValue?: string;
|
|
12
13
|
description?: string;
|
|
13
14
|
required?: boolean;
|
|
14
15
|
type?: string;
|
|
15
16
|
};
|
|
16
|
-
type Option = {
|
|
17
|
+
export type Option = {
|
|
17
18
|
aliases?: string[];
|
|
18
19
|
arguments?: string[];
|
|
19
20
|
choices?: string[];
|
|
@@ -31,5 +32,12 @@ export type ProgramInfo = {
|
|
|
31
32
|
positionals?: Positional[];
|
|
32
33
|
subcommandName?: string;
|
|
33
34
|
};
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
declare const _default: {
|
|
36
|
+
meow: typeof helpStringToObjectMeow;
|
|
37
|
+
yargs: typeof helpStringToObjectYargs;
|
|
38
|
+
};
|
|
39
|
+
export default _default;
|
|
40
|
+
export declare function getCommandParts(wholeCommand: string | undefined): {
|
|
41
|
+
command: string;
|
|
42
|
+
subcommand: string | undefined;
|
|
43
|
+
};
|
|
@@ -56,7 +56,7 @@ declare const _default: {
|
|
|
56
56
|
content(options: import("type-fest").JsonValue): Promise<string>;
|
|
57
57
|
};
|
|
58
58
|
'cli-help': {
|
|
59
|
-
content(options
|
|
59
|
+
content(options: import("type-fest").JsonValue): Promise<string>;
|
|
60
60
|
};
|
|
61
61
|
banner: {
|
|
62
62
|
content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
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.
|
|
73
|
+
"remark-mdat": "0.5.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/node": "^20.11.17",
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!--+ Warning: Content in HTML comment blocks generated by mdat on 2024-02-
|
|
1
|
+
<!--+ Warning: Content in HTML comment blocks generated by mdat on 2024-02-10 +-->
|
|
2
2
|
|
|
3
3
|
<!-- header -->
|
|
4
4
|
|
|
@@ -327,20 +327,26 @@ mdat collapse <files..> [options]
|
|
|
327
327
|
| `--help` | `-h` | Show help | `boolean` | |
|
|
328
328
|
| `--version` | `-v` | Show version number | `boolean` | |
|
|
329
329
|
|
|
330
|
-
####
|
|
330
|
+
#### Subcommand: `mdat readme`
|
|
331
|
+
|
|
332
|
+
Work with `mdat` comments in your readme.md.
|
|
331
333
|
|
|
332
334
|
This section lists top-level commands for `mdat readme`.
|
|
333
335
|
|
|
334
|
-
If no command is provided, `mdat readme expand` is run by default.
|
|
336
|
+
If no command is provided, `mdat readme readme expand` is run by default.
|
|
335
337
|
|
|
336
338
|
Usage:
|
|
337
339
|
|
|
340
|
+
```txt
|
|
341
|
+
mdat readme [command]
|
|
342
|
+
```
|
|
343
|
+
|
|
338
344
|
| Command | Argument | Description |
|
|
339
345
|
| ----------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
340
346
|
| `readme expand` | `[files..]` `[options]` | Expand `mdat` comment placeholders in your readme.md using a collection of helpful built-in expansion rules. _(Default command.)_ |
|
|
341
347
|
| `readme check` | `[files..]` `[options]` | Validate `mdat` placeholder comments in your readme.md. |
|
|
342
348
|
| `readme collapse` | `[files..]` `[options]` | Collapse `mdat` placeholder comments in your readme.md. |
|
|
343
|
-
| `readme init` | `[options]` | Interactively create a new readme.md file with sensible `mdat` comment placeholders.
|
|
349
|
+
| `readme init` | `[options]` | Interactively create a new readme.md file with sensible default `mdat` comment placeholders. |
|
|
344
350
|
|
|
345
351
|
_See the sections below for more information on each subcommand._
|
|
346
352
|
|
|
@@ -426,7 +432,7 @@ mdat readme collapse [files..] [options]
|
|
|
426
432
|
|
|
427
433
|
#### Subcommand: `mdat readme init`
|
|
428
434
|
|
|
429
|
-
Interactively create a new readme.md file with sensible `mdat` comment placeholders.
|
|
435
|
+
Interactively create a new readme.md file with sensible default `mdat` comment placeholders.
|
|
430
436
|
|
|
431
437
|
Usage:
|
|
432
438
|
|
|
@@ -741,15 +747,15 @@ Compound rules combine several stand-alone rules under a single keyword, which c
|
|
|
741
747
|
|
|
742
748
|
The `init` command provides a number of "starter readme" templates incorporating `mdat` comment placeholders:
|
|
743
749
|
|
|
744
|
-
-
|
|
750
|
+
- #### Mdat Readme
|
|
745
751
|
|
|
746
752
|
The house style. An expansive starting point. Prune to your context and taste. The readme files in this monorepo started from this template.
|
|
747
753
|
|
|
748
|
-
-
|
|
754
|
+
- #### Standard Readme basic
|
|
749
755
|
|
|
750
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).
|
|
751
757
|
|
|
752
|
-
-
|
|
758
|
+
- #### Standard Readme full
|
|
753
759
|
|
|
754
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).
|
|
755
761
|
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type CstNode, CstParser, type ILexingResult } from 'chevrotain';
|
|
2
|
-
export declare function tokenizeHelp(text: string): ILexingResult;
|
|
3
|
-
declare class CliParser extends CstParser {
|
|
4
|
-
programHelp: import("chevrotain").ParserMethod<[], CstNode>;
|
|
5
|
-
private readonly positionalsSection;
|
|
6
|
-
private readonly commandsSection;
|
|
7
|
-
private readonly optionsSection;
|
|
8
|
-
private readonly sectionRow;
|
|
9
|
-
constructor();
|
|
10
|
-
}
|
|
11
|
-
export declare const parser: CliParser;
|
|
12
|
-
export declare function helpStringToCst(text: string): CstNode;
|
|
13
|
-
export {};
|