mdat 0.3.2 → 0.5.0
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 +30 -32
- package/dist/api.d.ts +6 -15
- package/dist/config.d.ts +0 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +26 -28
- package/dist/processors.d.ts +11 -0
- package/dist/readme/api.d.ts +8 -11
- package/dist/readme/config.d.ts +8 -0
- 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/dist/readme/utilities.d.ts +10 -0
- package/dist/utilities.d.ts +1 -10
- package/package.json +2 -2
- package/readme.md +44 -30
- 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 Je(t,e){let n=On(e);t=t.filter((o,a)=>!n.includes(a)),e=e.map(o=>o.filter((a,r)=>!n.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
12
|
`;for(let o of e)i+=`| ${o.join(" | ")} |
|
|
14
|
-
`;return i}function
|
|
15
|
-
${o.message}
|
|
16
|
-
`)}if(n===void 0||n==="")throw new Error(`No result from running CLI help command: ${e}
|
|
17
|
-
`);let i;try{let o=yt(n);i=wt(o)}catch(o){o instanceof Error&&(i=void 0,Ct.warn(`Error parsing help output for command: ${t}
|
|
18
|
-
${o.message}`),Ct.warn("Falling back to basic cli help text output."))}return i===void 0?$n(n):vn(t,i)}async function vn(t,e){let n=(e.commands&&e.commands.some(a=>a.default))??!1,i=bt(e,n),o=t.split(" ")[0];if(e.commands)for(let a of e.commands){if(!a.parentCommandName||!a.commandName)continue;let r=await Be(`${o} ${a.commandName}`);i+=`
|
|
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
|
-
[${n}](license.txt) \xA9 ${e.name}`},order:16,required:!0}};import{getSoleRule as
|
|
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[o,
|
|
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="${n}" src="${
|
|
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 v={"Mdat Readme":{content:{compound:At,explicit:Dt},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:It,explicit:Mt},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:Ut,explicit:Vt},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 Jt,group as Zn,intro as Qn,note as Bt,outro as Xn,select as Ye}from"@clack/prompts";import P from"chalk";import eo from"node:fs/promises";import ce from"node:path";import{deepMergeDefined as to}from"remark-mdat";import{write as no}from"to-vfile";async function qt(){let t=await G(),e=await Y();return{packageDirectory:e===void 0?void 0:ce.dirname(ce.resolve(e)),readmePath:t}}async function Ht(){let{packageDirectory:t,readmePath:e}=await qt(),n=ce.resolve(process.cwd());Qn(`Running ${P.bold("mdat readme init")} interactively`);let i=await Zn({overwrite:async()=>e===void 0||await Jt({message:`Found an existing readme at "${P.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?Ye({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: "${P.blue(t)}"`,value:t},{label:`Create in current working directory: "${P.blue(n)}"`,value:n}]}):n,template:async()=>Ye({message:"Which template would you like to use?",options:io()}),compound:async()=>Ye({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 ${P.green("<!-- title -->")} and ${P.green("<!-- badges -->")} in a single ${P.green("<!-- header -->")} comment.`,value:!0},{label:"No: Use individual `mdat` expansion comments for each section.",value:!1}]}),expand:async()=>t===void 0?!1:Jt({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 Ke(i);return t===void 0&&Bt("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."),Bt(`Readme created: "${P.bold.blue(o)}"`),Xn("Done!"),o}async function Ke(t){let{packageDirectory:e}=await qt(),n=to({compound:!0,output:e??process.cwd(),overwrite:!0,expand:e!==void 0,template:Object.keys(v)[0]},t??{}),i=oo(n.template,n.compound),o=ce.join(n.output,"readme.md");await eo.writeFile(o,i,"utf8");let a=await j(void 0,void 0,{readmeFile:o});return await no(a),o}function oo(t,e){let i=v[t].content[e?"compound":"explicit"];if(i===void 0||i==="")throw new Error(`No template found for "${t}"`);return i}function io(){return Object.entries(v).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"}},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"}},A={output:{alias:"o",defaultDescription:"Same directory as input file.",description:"Output file directory.",type:"string"}},E={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"}},pe=["files",{array:!0,demandOption:!0,describe:"Markdown file(s) with `mdat` placeholder comments to collapse.",type:"string"}];var le={readme:{defaultDescription:"The closest readme.md file is used by default.",description:"Path to the readme.md file to expand.",type:"string"}},Ze={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}},Qe={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"}},Wt={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"}},Gt={expand:{alias:"e",default:!0,description:"Automatically run `mdat readme` immediately after creating the readme template.",type:"boolean"}},Yt={template:{alias:"t",choices:Object.keys(v),default:Object.keys(v)[0],description:"Specify a template to use for the new readme.",type:"string"}},Kt={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"}};import D from"chalk";import L from"pretty-ms";import{getMdatReports as ro,log as l,reporterMdat as I}from"remark-mdat";import{write as ue}from"to-vfile";import ao from"yargs";import{hideBin as so}from"yargs/helpers";var T=performance.now(),Zt=ao(so(process.argv));try{await Zt.scriptName("mdat").usage("$0 [command] [options]","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(z).option(A).option(q).option(B).option(E).option(H).option(O),async({config:t,files:e,meta:n,name:i,output:o,prefix:a,print:r,rules:s,verbose:d})=>{l.verbose=d,fe({name:i,output:o,print:r});let m=ge(e),c=M(t,{addMetaComment:n,keywordPrefix:a}),p=await X(m,i,o,c,s);for(let u of p)r?process.stdout.write(u.toString()):await ue(u);I(p),l.info(`Expanded comments in ${L(performance.now()-T)}.`),process.exitCode=U(p)}).command("check <files..> [options]","Validate a markdown file with `mdat` placeholder comments.",t=>t.positional(...pe).option($).option(z).option(B).option(E).option(O),async({config:t,files:e,meta:n,prefix:i,rules:o,verbose:a})=>{l.verbose=a;let r=ge(e),s=M(t,{addMetaComment:n,keywordPrefix:i}),d=await X(r,void 0,void 0,s,o);I(d),l.info(`Checked comments in ${L(performance.now()-T)}.`),process.exitCode=U(d)}).command("clean <files..> [options]","Collapse `mdat` placeholder comments.",t=>t.positional(...pe).option($).option(A).option(q).option(E).option(H).option(O),async({config:t,files:e,name:n,output:i,prefix:o,print:a,verbose:r})=>{l.verbose=r,fe({name:n,output:i,print:a});let s=ge(e),d=M(t,{keywordPrefix:o}),m=await ke(s,void 0,void 0,d);for(let c of m)a?process.stdout.write(c.toString()):await ue(c);I(m),l.info(`Cleaned comments in ${L(performance.now()-T)}.`),process.exitCode=U(m)}).command("readme [command] [options]","Work with `mdat` comments in your readme.md.",t=>t.command(["$0 [options]","expand [options]"],"Expand `mdat` comment placeholders in your readme.md using a collection of helpful built-in expansion rules.",e=>e.option($).option(z).option(A).option(q).option(le).option(Ze).option(Qe).option(E).option(B).option(H).option(O),async({assets:e,config:n,meta:i,name:o,output:a,package:r,prefix:s,print:d,readme:m,rules:c,verbose:p})=>{l.verbose=p,fe({name:o,output:a,print:d});let u=M(n,{addMetaComment:i,assetsPath:e,keywordPrefix:s,packageFile:r,readmeFile:m}),g=await j(o,a,u,c);d?process.stdout.write(g.toString()):await ue(g),I([g]);let{packageFile:C,readmeFile:he}=await w();l.info(`Expanded comments in readme: ${D.bold.blue(he)}`),l.info(`Pulled package metadata from: ${D.bold.blue(C)}`),l.info(`Expanded readme in ${L(performance.now()-T)}.`),process.exitCode=U([g])}).command("check [options]","Validate `mdat` placeholder comments in your readme.md.",e=>e.option($).option(z).option(le).option(Ze).option(Qe).option(E).option(B).option(O),async({assets:e,config:n,meta:i,package:o,prefix:a,readme:r,rules:s,verbose:d})=>{l.verbose=d;let m=M(n,{addMetaComment:i,assetsPath:e,keywordPrefix:a,packageFile:o,readmeFile:r}),c=await j(void 0,void 0,m,s);I([c]);let{packageFile:p,readmeFile:u}=await w();l.info(`Checked comments in readme: ${D.bold.blue(u)}`),l.info(`Pulled package metadata from: ${D.bold.blue(p)}`),l.info(`Checked readme in ${L(performance.now()-T)}.`),process.exitCode=U([c])}).command("clean [options]","Collapse `mdat` placeholder comments in your readme.md.",e=>e.option(A).option(q).option(H).option($).option(le).option(E).option(O),async({config:e,name:n,output:i,prefix:o,print:a,readme:r,verbose:s})=>{l.verbose=s,fe({name:n,output:i,print:a});let d=M(e,{keywordPrefix:o,readmeFile:r}),m=await We(d);a?process.stdout.write(m.toString()):await ue(m),I([m]);let{readmeFile:c}=await w();l.info(`Cleaned comments in readme: ${D.bold.blue(c)}`),l.info(`Cleaned readme in ${L(performance.now()-T)}.`),process.exitCode=U([m])}).command("init [options]","Interactively create a new readme.md file with sensible `mdat` comment placeholders.",e=>e.option(zt).option(Wt).option(A).option(Gt).option(Yt).option(Kt).option(O),async({compound:e,expand:n,interactive:i,output:o,overwrite:a,template:r,verbose:s})=>{if(l.verbose=s,i)await Ht();else{let d=await Ke({compound:e,expand:n,output:o,overwrite:a,template:r});l.info(`Created readme at "${D.blue(d)}" in ${L(performance.now()-T)}.`)}process.exitCode=0}),()=>{l.error("Root mdat readme command should be unreachable.")}).help().alias("h","help").version().alias("v","version").wrap(process.stdout.isTTY?Math.min(120,Zt.terminalWidth()):0).fail(!1).parse()}catch(t){t instanceof Error&&l.error(t.message),process.exitCode=1}function fe(t){t.print&&t.output&&l.warn("Ignoring --output option because --print is set"),t.print&&t.name&&l.warn("Ignoring --name option because --print is set")}function ge(t){return t==null?[]:Array.isArray(t)?t:[t]}function M(t,e){return[...ge(t),e]}function U(t){return ro(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 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/api.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import { type ConfigToLoad, type RulesToLoad } from './config';
|
|
2
|
-
import { VFile } from 'vfile';
|
|
2
|
+
import { type VFile } from 'vfile';
|
|
3
3
|
/**
|
|
4
4
|
* Writing is the responsibility of the caller (e.g. via `await write(result)`)
|
|
5
5
|
*/
|
|
6
|
-
export declare function expandFiles(files: string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
7
|
-
/**
|
|
8
|
-
* Writing is the responsibility of the caller (e.g. via `await write(result)`)
|
|
9
|
-
*/
|
|
10
|
-
export declare function expandFile(file: string, name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
|
6
|
+
export declare function expandFiles(files: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
11
7
|
export declare function expandString(markdown: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export declare function
|
|
16
|
-
/**
|
|
17
|
-
* Writing is the responsibility of the caller (e.g. via `await write(result)`)
|
|
18
|
-
*/
|
|
19
|
-
export declare function cleanFile(file: string, name?: string, output?: string, config?: ConfigToLoad): Promise<VFile>;
|
|
20
|
-
export declare function cleanString(markdown: string, config: ConfigToLoad): Promise<VFile>;
|
|
8
|
+
export declare function checkFiles(files: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
9
|
+
export declare function checkString(markdown: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
|
10
|
+
export declare function collapseFiles(files: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
11
|
+
export declare function collapseString(markdown: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
package/dist/config.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { type Options, type Rules } from 'remark-mdat';
|
|
|
3
3
|
export type Config = {
|
|
4
4
|
assetsPath?: string;
|
|
5
5
|
packageFile?: string;
|
|
6
|
-
readmeFile?: string;
|
|
7
6
|
} & Options;
|
|
8
7
|
export type ConfigLoaded = {
|
|
9
8
|
addMetaComment: boolean;
|
|
@@ -12,7 +11,6 @@ export type ConfigLoaded = {
|
|
|
12
11
|
keywordPrefix: string;
|
|
13
12
|
metaCommentIdentifier: string;
|
|
14
13
|
packageFile: string | undefined;
|
|
15
|
-
readmeFile: string | undefined;
|
|
16
14
|
rules: Rules;
|
|
17
15
|
};
|
|
18
16
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { checkFiles, checkString, collapseFiles, collapseString, expandFiles, expandString, } from './api';
|
|
2
2
|
export { type Config, loadConfig } from './config';
|
|
3
|
-
export {
|
|
3
|
+
export { checkReadmeFiles, checkReadmeString, collapseReadmeFiles, expandReadmeFiles, expandReadmeString, } from './readme/api';
|
|
4
|
+
export { loadConfigReadme } from './readme/config';
|
|
4
5
|
export { type Rules } 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
|
-
${s.parentCommandName}${s.arguments?` ${s.arguments.join(" ")}`:""}
|
|
6
|
-
\`\`\``),t.commands=(a=t.commands)==null?void 0:a.filter(d=>d!==s)}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(ye(["Positional Argument","Description","Type","Default"],t.positionals.map(r=>[r.arguments?[r.arguments.map(s=>`\`${s}\``)].join(" "):"",`${r.description??""}${r.required?" _(Required.)_":" _(Optional.)_"}`,r.type?`\`${r.type}\``:"",r.defaultValue?r.defaultValue.includes(" ")?r.defaultValue:`\`${r.defaultValue}\``:""]))),t.commands&&n.push(ye(["Command","Argument","Description"],t.commands.map(r=>{var s;return[`\`${r.commandName??(r.default?"[default]":"")}\``,r.arguments?(s=r.arguments)==null?void 0:s.map(m=>`\`${m}\``).join(" "):"",`${r.description??""}${r.default?" _(Default command.)_":""}`]}))),t.options&&!e&&n.push(ye(["Option","Alias","Argument","Description","Type","Default"],t.options.map(r=>[r.flags?r.flags.map(s=>`\`${s}\``).join(" "):"",r.aliases?r.aliases.map(s=>`\`${s}\``).join(" "):"",r.arguments?r.arguments.map(s=>`\`${s}\``).join(" "):"",r.description??"",r.type?`\`${r.type}\``:"",r.defaultValue?r.defaultValue.includes(" ")?r.defaultValue:`\`${r.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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
${
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
${o.message}`),He.warn("Falling back to basic cli help text output."))}return i===void 0?_t(n):Ut(t,i)}async function Ut(t,e){let n=(e.commands&&e.commands.some(a=>a.default))??!1,i=Be(e,n),o=t.split(" ")[0];if(e.commands)for(let a of e.commands){if(!a.parentCommandName||!a.commandName)continue;let r=await we(`${o} ${a.commandName}`);i+=`
|
|
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(" | ")} |
|
|
10
|
+
`,r+=`| ${t.map(()=>"---").join(" | ")} |
|
|
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+=`
|
|
18
13
|
|
|
19
|
-
${
|
|
14
|
+
${m}`}return o}function Rn(t){return`\`\`\`txt
|
|
20
15
|
${t}
|
|
21
|
-
\`\`\``}
|
|
22
|
-
${
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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}
|
|
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(`
|
|
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)}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};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ConfigLoaded, type ConfigToLoad, type RulesToLoad, type loadConfig } from './config';
|
|
2
|
+
import { type Root } from 'mdast';
|
|
3
|
+
import { VFile } from 'vfile';
|
|
4
|
+
type Loader = typeof loadConfig;
|
|
5
|
+
type ProcessorGetter = typeof getCleanProcessor | typeof getExpandProcessor;
|
|
6
|
+
export declare function processFiles(files: string | string[], loader: Loader, processorGetter: ProcessorGetter, name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
7
|
+
export declare function processString(markdown: string, loader: Loader, processorGetter: ProcessorGetter, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
|
8
|
+
export declare function getExpandProcessor(options: ConfigLoaded): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
9
|
+
export declare function getCleanProcessor(options: ConfigLoaded): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
10
|
+
export declare function getCheckProcessor(options: ConfigLoaded): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
11
|
+
export {};
|
package/dist/readme/api.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type Simplify } from 'type-fest';
|
|
1
|
+
import { type ConfigToLoad, type RulesToLoad } from '../config';
|
|
3
2
|
import { type VFile } from 'vfile';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readmeFile: string;
|
|
7
|
-
} & ConfigLoaded>;
|
|
8
|
-
export declare function expandReadme(name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
|
3
|
+
export declare function expandReadme(config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
4
|
+
export declare function expandReadmeFiles(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
9
5
|
export declare function expandReadmeString(markdown: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
|
10
|
-
export declare function
|
|
11
|
-
|
|
12
|
-
export declare function
|
|
13
|
-
export
|
|
6
|
+
export declare function checkReadme(config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
7
|
+
export declare function checkReadmeFiles(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
8
|
+
export declare function checkReadmeString(markdown: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
|
9
|
+
export declare function collapseReadme(config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
10
|
+
export declare function collapseReadmeFiles(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ConfigLoaded, loadConfig } from '../config';
|
|
2
|
+
import { type Simplify } from 'type-fest';
|
|
3
|
+
type ReadmeConfigLoaded = Simplify<{
|
|
4
|
+
packageFile: string;
|
|
5
|
+
} & ConfigLoaded>;
|
|
6
|
+
type LoadConfigOptions = Parameters<typeof loadConfig>[0];
|
|
7
|
+
export declare function loadConfigReadme(options?: LoadConfigOptions): Promise<ReadmeConfigLoaded>;
|
|
8
|
+
export {};
|
|
@@ -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>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Searches for a readme file in the following order:
|
|
3
|
+
* 1. Searches the current working directly for readme.md
|
|
4
|
+
* 2. If there's no readme.md in the current directory, search up to the closest package directory
|
|
5
|
+
* 3. Give up and return undefined if no readme is found
|
|
6
|
+
*
|
|
7
|
+
* @returns The path to the readme file or undefined if not found
|
|
8
|
+
*/
|
|
9
|
+
export declare function findReadme(): Promise<string | undefined>;
|
|
10
|
+
export declare function findReadmeThrows(): Promise<string>;
|
package/dist/utilities.d.ts
CHANGED
|
@@ -9,14 +9,5 @@ export declare function getInputOutputPath(input: string, output: string | undef
|
|
|
9
9
|
output: string;
|
|
10
10
|
};
|
|
11
11
|
export declare function expandPath(file: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* Searches for a readme file in the following order:
|
|
14
|
-
* 1. Searches the current working directly for readme.md
|
|
15
|
-
* 2. If there's no readme.md in the current directory, search up to the closest package directory
|
|
16
|
-
* 3. Give up and return undefined if no readme is found
|
|
17
|
-
*
|
|
18
|
-
* @returns The path to the readme file
|
|
19
|
-
* @throws If no readme is found
|
|
20
|
-
*/
|
|
21
|
-
export declare function findReadme(): Promise<string | undefined>;
|
|
22
12
|
export declare function findPackage(): Promise<string | undefined>;
|
|
13
|
+
export declare function ensureArray<T>(value: T | T[] | undefined): T[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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.0"
|
|
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
|
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
- [Features](#features)
|
|
23
23
|
- [1. Minimalist syntax](#1-minimalist-syntax)
|
|
24
24
|
- [2. Single-comment placeholders](#2-single-comment-placeholders)
|
|
25
|
-
- [3. Familiar JSON
|
|
25
|
+
- [3. Familiar JSON arguments](#3-familiar-json-arguments)
|
|
26
26
|
- [4. Flexible rule system](#4-flexible-rule-system)
|
|
27
27
|
- [5. TypeScript native](#5-typescript-native)
|
|
28
28
|
- [6. Validation](#6-validation)
|
|
@@ -137,7 +137,7 @@ When you're roughing out a readme, you can drop in a single opening comment, and
|
|
|
137
137
|
<!-- title -->
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
### 3. Familiar JSON
|
|
140
|
+
### 3. Familiar JSON arguments
|
|
141
141
|
|
|
142
142
|
In the rare instances when you want to pass extra data or configuration into a comment template, you just use a bit of JSON. No need to grok a custom syntax:
|
|
143
143
|
|
|
@@ -197,7 +197,7 @@ You can also treat any JSON file as a rule set. `mdat` will flatten it to allow
|
|
|
197
197
|
|
|
198
198
|
### 5. TypeScript native
|
|
199
199
|
|
|
200
|
-
`mdat` exports definitions for rule types, and
|
|
200
|
+
`mdat` exports definitions for rule types, and configuration / rule sets may be written directly in TypeScript.
|
|
201
201
|
|
|
202
202
|
### 6. Validation
|
|
203
203
|
|
|
@@ -239,15 +239,15 @@ If no command is provided, `mdat expand` is run by default.
|
|
|
239
239
|
Usage:
|
|
240
240
|
|
|
241
241
|
```txt
|
|
242
|
-
mdat [command]
|
|
242
|
+
mdat [command]
|
|
243
243
|
```
|
|
244
244
|
|
|
245
|
-
| Command
|
|
246
|
-
|
|
|
247
|
-
| `expand`
|
|
248
|
-
| `check`
|
|
249
|
-
| `
|
|
250
|
-
| `readme`
|
|
245
|
+
| Command | Argument | Description |
|
|
246
|
+
| ---------- | ----------------------- | ---------------------------------------------------------- |
|
|
247
|
+
| `expand` | `<files..>` `[options]` | Expand `mdat` placeholder comments. _(Default command.)_ |
|
|
248
|
+
| `check` | `<files..>` `[options]` | Validate a markdown file with `mdat` placeholder comments. |
|
|
249
|
+
| `collapse` | `<files..>` `[options]` | Collapse `mdat` placeholder comments. |
|
|
250
|
+
| `readme` | `[command]` | Work with `mdat` comments in your readme.md. |
|
|
251
251
|
|
|
252
252
|
_See the sections below for more information on each subcommand._
|
|
253
253
|
|
|
@@ -302,14 +302,14 @@ mdat check <files..> [options]
|
|
|
302
302
|
| `--help` | `-h` | Show help | `boolean` | |
|
|
303
303
|
| `--version` | `-v` | Show version number | `boolean` | |
|
|
304
304
|
|
|
305
|
-
#### Subcommand: `mdat
|
|
305
|
+
#### Subcommand: `mdat collapse`
|
|
306
306
|
|
|
307
307
|
Collapse `mdat` placeholder comments.
|
|
308
308
|
|
|
309
309
|
Usage:
|
|
310
310
|
|
|
311
311
|
```txt
|
|
312
|
-
mdat
|
|
312
|
+
mdat collapse <files..> [options]
|
|
313
313
|
```
|
|
314
314
|
|
|
315
315
|
| Positional Argument | Description | Type |
|
|
@@ -327,20 +327,26 @@ mdat clean <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
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
|
343
|
-
|
|
|
340
|
+
```txt
|
|
341
|
+
mdat readme [command]
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
| Command | Argument | Description |
|
|
345
|
+
| ----------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
346
|
+
| `readme expand` | `[files..]` `[options]` | Expand `mdat` comment placeholders in your readme.md using a collection of helpful built-in expansion rules. _(Default command.)_ |
|
|
347
|
+
| `readme check` | `[files..]` `[options]` | Validate `mdat` placeholder comments in your readme.md. |
|
|
348
|
+
| `readme collapse` | `[files..]` `[options]` | Collapse `mdat` placeholder comments in your readme.md. |
|
|
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
|
|
|
@@ -351,16 +357,19 @@ Expand `mdat` comment placeholders in your readme.md using a collection of helpf
|
|
|
351
357
|
Usage:
|
|
352
358
|
|
|
353
359
|
```txt
|
|
354
|
-
mdat readme expand [options]
|
|
360
|
+
mdat readme expand [files..] [options]
|
|
355
361
|
```
|
|
356
362
|
|
|
363
|
+
| Positional Argument | Description | Type |
|
|
364
|
+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
|
365
|
+
| `files` | Readme file(s) with `mdat` placeholder comments to collapse. If not provided, the closest readme.md file is used. _(Optional.)_ | `string` |
|
|
366
|
+
|
|
357
367
|
| Option | Alias | Description | Type | Default |
|
|
358
368
|
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------------------------------------------------------------------------- |
|
|
359
369
|
| `--config` | | Path(s) to files containing mdat configs. | `array` | Configuration is loaded if found from the usual places, or defaults are used. |
|
|
360
370
|
| `--rules` | `-r` | Path(s) to files containing `mdat` comment expansion rules. | `array` | |
|
|
361
371
|
| `--output` | `-o` | Output file directory. | `string` | Same directory as input file. |
|
|
362
372
|
| `--name` | `-n` | Output file name. | `string` | Same name as input file. Overwrites the input file. |
|
|
363
|
-
| `--readme` | | Path to the readme.md file to expand. | `string` | The closest readme.md file is used by default. |
|
|
364
373
|
| `--package` | | Path to the package.json file to use to populate the readme. | `string` | The closest package.json file is used by default. |
|
|
365
374
|
| `--assets` | | Path to find and save readme-related assets. | `string` | `./assets` |
|
|
366
375
|
| `--prefix` | | 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. | `string` | |
|
|
@@ -377,14 +386,17 @@ Validate `mdat` placeholder comments in your readme.md.
|
|
|
377
386
|
Usage:
|
|
378
387
|
|
|
379
388
|
```txt
|
|
380
|
-
mdat readme check [options]
|
|
389
|
+
mdat readme check [files..] [options]
|
|
381
390
|
```
|
|
382
391
|
|
|
392
|
+
| Positional Argument | Description | Type |
|
|
393
|
+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
|
394
|
+
| `files` | Readme file(s) with `mdat` placeholder comments to collapse. If not provided, the closest readme.md file is used. _(Optional.)_ | `string` |
|
|
395
|
+
|
|
383
396
|
| Option | Alias | Description | Type | Default |
|
|
384
397
|
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------------------------------------------------------------------------- |
|
|
385
398
|
| `--config` | | Path(s) to files containing mdat configs. | `array` | Configuration is loaded if found from the usual places, or defaults are used. |
|
|
386
399
|
| `--rules` | `-r` | Path(s) to files containing `mdat` comment expansion rules. | `array` | |
|
|
387
|
-
| `--readme` | | Path to the readme.md file to expand. | `string` | The closest readme.md file is used by default. |
|
|
388
400
|
| `--package` | | Path to the package.json file to use to populate the readme. | `string` | The closest package.json file is used by default. |
|
|
389
401
|
| `--assets` | | Path to find and save readme-related assets. | `string` | `./assets` |
|
|
390
402
|
| `--prefix` | | 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. | `string` | |
|
|
@@ -393,23 +405,26 @@ mdat readme check [options]
|
|
|
393
405
|
| `--help` | `-h` | Show help | `boolean` | |
|
|
394
406
|
| `--version` | `-v` | Show version number | `boolean` | |
|
|
395
407
|
|
|
396
|
-
#### Subcommand: `mdat readme
|
|
408
|
+
#### Subcommand: `mdat readme collapse`
|
|
397
409
|
|
|
398
410
|
Collapse `mdat` placeholder comments in your readme.md.
|
|
399
411
|
|
|
400
412
|
Usage:
|
|
401
413
|
|
|
402
414
|
```txt
|
|
403
|
-
mdat readme
|
|
415
|
+
mdat readme collapse [files..] [options]
|
|
404
416
|
```
|
|
405
417
|
|
|
418
|
+
| Positional Argument | Description | Type |
|
|
419
|
+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
|
420
|
+
| `files` | Readme file(s) with `mdat` placeholder comments to collapse. If not provided, the closest readme.md file is used. _(Optional.)_ | `string` |
|
|
421
|
+
|
|
406
422
|
| Option | Alias | Description | Type | Default |
|
|
407
423
|
| ----------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------------------------------------------------------------------------- |
|
|
408
424
|
| `--output` | `-o` | Output file directory. | `string` | Same directory as input file. |
|
|
409
425
|
| `--name` | `-n` | Output file name. | `string` | Same name as input file. Overwrites the input file. |
|
|
410
426
|
| `--print` | | Print the expanded Markdown to stdout instead of saving to a file. Ignores `--output` and `--name` options. | `boolean` | |
|
|
411
427
|
| `--config` | | Path(s) to files containing mdat configs. | `array` | Configuration is loaded if found from the usual places, or defaults are used. |
|
|
412
|
-
| `--readme` | | Path to the readme.md file to expand. | `string` | The closest readme.md file is used by default. |
|
|
413
428
|
| `--prefix` | | 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. | `string` | |
|
|
414
429
|
| `--verbose` | | Enable verbose logging. All verbose logs and prefixed with their log level and are printed to stderr for ease of redirection. | `boolean` | |
|
|
415
430
|
| `--help` | `-h` | Show help | `boolean` | |
|
|
@@ -417,7 +432,7 @@ mdat readme clean [options]
|
|
|
417
432
|
|
|
418
433
|
#### Subcommand: `mdat readme init`
|
|
419
434
|
|
|
420
|
-
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.
|
|
421
436
|
|
|
422
437
|
Usage:
|
|
423
438
|
|
|
@@ -595,7 +610,6 @@ The `mdat` configuration file is a record object allowing you to customize aspec
|
|
|
595
610
|
type Config = {
|
|
596
611
|
assetsPath?: string // where asset-generating rules should store their output, defaults to './assets'
|
|
597
612
|
packageFile?: string // used by readme rules, found dynamically if undefined
|
|
598
|
-
readmeFile?: string // used by readme commands, found dynamically if undefined
|
|
599
613
|
addMetaComment?: boolean // defaults to true
|
|
600
614
|
closingPrefix?: string // defaults to '/'
|
|
601
615
|
keywordPrefix?: string // defaults to ''
|
|
@@ -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 {};
|