cleye 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ The intuitive command-line interface (CLI) development tool.
|
|
|
13
13
|
- Command support
|
|
14
14
|
- Help documentation generation (customizable too!)
|
|
15
15
|
|
|
16
|
-
→ Try it out online
|
|
16
|
+
→ [Try it out online](https://stackblitz.com/edit/cleye-demo?devtoolsheight=50&file=examples/greet.ts&view=editor)
|
|
17
17
|
|
|
18
18
|
<sub>Support this project by starring and sharing it. [Follow me](https://github.com/privatenumber) to see what other cool projects I'm working on.</sub>
|
|
19
19
|
|
package/dist/index.js
CHANGED
|
@@ -6,5 +6,5 @@ var M=Object.create;var y=Object.defineProperty,W=Object.defineProperties,Z=Obje
|
|
|
6
6
|
`)),n)return{id:"examples",type:"section",data:{title:"Examples:",body:n}}}function me(t){if(!("alias"in t)||!t.alias)return;let{alias:e}=t,n=Array.isArray(e)?e.join(", "):e;return{id:"aliases",type:"section",data:{title:"Aliases:",body:n}}}var $=t=>[ne,re,ae,se,ie,oe,me].map(e=>e(t)).filter(e=>Boolean(e));var K=A(require("tty")),C=A(require("terminal-columns")),pe=K.default.WriteStream.prototype.hasColors(),b=class{text(e){return e}bold(e){return`[1m${e}[22m`}indentText({text:e,spaces:n}){return e.replace(/^/gm," ".repeat(n))}heading(e){return pe?this.bold(e):e.toLocaleUpperCase()}section({title:e,body:n,indentBody:a=2}){return`${(e?`${this.heading(e)}
|
|
7
7
|
`:"")+(n?this.indentText({text:this.render(n),spaces:a}):"")}
|
|
8
8
|
`}table({tableData:e,tableOptions:n,tableBreakpoints:a}){return(0,C.default)(e.map(r=>r.map(s=>this.render(s))),a?(0,C.breakpoints)(a):n)}flagParameter(e){return e===Boolean?"":e===String?"<string>":e===Number?"<number>":Array.isArray(e)?this.flagParameter(e[0]):"<value>"}flagOperator(){return" "}flagName({flag:e,flagFormatted:n,aliasesEnabled:a,aliasFormatted:r}){let s="";if(r?s+=`${r}, `:a&&(s+=" "),s+=n,"placeholder"in e&&typeof e.placeholder=="string")s+=`${this.flagOperator()}${e.placeholder}`;else{let i=this.flagParameter("type"in e?e.type:e);i&&(s+=`${this.flagOperator()}${i}`)}return s}flagDefault(e){return JSON.stringify(e)}flagDescription({flag:e}){var a;let n="description"in e&&(a=e.description)!=null?a:"";if("default"in e){let{default:r}=e;typeof r=="function"&&(r=r()),r&&(n+=` (default: ${this.flagDefault(r)})`)}return n}render(e){if(typeof e=="string")return e;if(Array.isArray(e))return e.map(n=>this.render(n)).join(`
|
|
9
|
-
`);if("type"in e&&this[e.type]){let n=this[e.type];if(typeof n=="function")return n.call(this,e.data)}throw new Error(`Invalid node type: ${JSON.stringify(e)}`)}};var h=/^[\w
|
|
9
|
+
`);if("type"in e&&this[e.type]){let n=this[e.type];if(typeof n=="function")return n.call(this,e.data)}throw new Error(`Invalid node type: ${JSON.stringify(e)}`)}};var h=/^[\w.-]+$/;var{stringify:m}=JSON,le=/[|\\{}()[\]^$+*?.]/;function de(t){let e=[],n,a;for(let r of t){if(a)throw new Error(`Invalid parameter: Spread parameter ${m(a)} must be last`);let s=r[0],i=r[r.length-1],p;if(s==="<"&&i===">"&&(p=!0,n))throw new Error(`Invalid parameter: Required parameter ${m(r)} cannot come after optional parameter ${m(n)}`);if(s==="["&&i==="]"&&(p=!1,n=r),p===void 0)throw new Error(`Invalid parameter: ${m(r)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let o=r.slice(1,-1),u=o.slice(-3)==="...";u&&(a=r,o=o.slice(0,-3));let g=o.match(le);if(g)throw new Error(`Invalid parameter: ${m(r)}. Invalid character found ${m(g[0])}`);e.push({name:o,required:p,spread:u})}return e}function ce(t){return t===void 0||t!==!1}function L(t,e,n,a){let r=c({},e.flags),s=e.version;s&&(r.version={type:Boolean,description:"Show version"});let{help:i}=e,p=ce(i);p&&!("help"in r)&&(r.help={type:Boolean,alias:"h",description:"Show help"});let o=(0,q.default)(r,a),u=()=>{console.log(e.version)};if(s&&o.flags.version===!0)return u(),process.exit(0);let g=new b,U=p&&(i==null?void 0:i.render)?i.render:l=>g.render(l),P=l=>{let x=$(O(c(c({},e),l?{help:l}:{}),{flags:r}));console.log(U(x,g))};if(p&&o.flags.help===!0)return P(),process.exit(0);if(e.parameters){let l=de(e.parameters),x=o._;for(let f=0;f<l.length;f+=1){let{name:N,required:J,spread:w}=l[f],v=w?o._.slice(f):o._[f];if(w&&(f=l.length),J&&(!v||w&&v.length===0))return console.error(`Error: Missing required parameter ${m(N)}
|
|
10
10
|
`),P(),process.exit(1);x[S(N)]=v}}let H=O(c({},o),{showVersion:u,showHelp:P});return typeof n=="function"&&n(H),c({command:t},H)}function fe(t,e){let n=new Map;for(let a of e){let r=[a.options.name],{alias:s}=a.options;s&&(Array.isArray(s)?r.push(...s):r.push(s));for(let i of r){if(n.has(i))throw new Error(`Duplicate command name found: ${m(i)}`);n.set(i,a)}}return n.get(t)}function V(t,e,n=process.argv.slice(2)){if(!t)throw new Error("Options is required");if("name"in t&&(!t.name||!h.test(t.name)))throw new Error(`Invalid script name: ${m(t.name)}`);let a=n[0];if(t.commands&&h.test(a)){let r=fe(a,t.commands);if(r)return L(r.options.name,O(c({},r.options),{parent:t}),r.callback,n.slice(1))}return L(void 0,t,e,n)}function _(t,e){if(!t)throw new Error("Command options are required");let{name:n}=t;if(t.name===void 0)throw new Error("Command name is required");if(!h.test(n))throw new Error(`Invalid command name ${JSON.stringify(n)}. Command names must be one word.`);return{options:t,callback:e}}module.exports=ee(ue);0&&(module.exports={cli,command});
|
package/dist/index.mjs
CHANGED
|
@@ -6,5 +6,5 @@ var R=Object.defineProperty,j=Object.defineProperties;var K=Object.getOwnPropert
|
|
|
6
6
|
`)),n)return{id:"examples",type:"section",data:{title:"Examples:",body:n}}}function z(t){if(!("alias"in t)||!t.alias)return;let{alias:e}=t,n=Array.isArray(e)?e.join(", "):e;return{id:"aliases",type:"section",data:{title:"Aliases:",body:n}}}var v=t=>[_,U,J,M,W,Z,z].map(e=>e(t)).filter(e=>Boolean(e));import G from"tty";import Q,{breakpoints as X}from"terminal-columns";var Y=G.WriteStream.prototype.hasColors(),C=class{text(e){return e}bold(e){return`[1m${e}[22m`}indentText({text:e,spaces:n}){return e.replace(/^/gm," ".repeat(n))}heading(e){return Y?this.bold(e):e.toLocaleUpperCase()}section({title:e,body:n,indentBody:a=2}){return`${(e?`${this.heading(e)}
|
|
7
7
|
`:"")+(n?this.indentText({text:this.render(n),spaces:a}):"")}
|
|
8
8
|
`}table({tableData:e,tableOptions:n,tableBreakpoints:a}){return Q(e.map(r=>r.map(s=>this.render(s))),a?X(a):n)}flagParameter(e){return e===Boolean?"":e===String?"<string>":e===Number?"<number>":Array.isArray(e)?this.flagParameter(e[0]):"<value>"}flagOperator(){return" "}flagName({flag:e,flagFormatted:n,aliasesEnabled:a,aliasFormatted:r}){let s="";if(r?s+=`${r}, `:a&&(s+=" "),s+=n,"placeholder"in e&&typeof e.placeholder=="string")s+=`${this.flagOperator()}${e.placeholder}`;else{let i=this.flagParameter("type"in e?e.type:e);i&&(s+=`${this.flagOperator()}${i}`)}return s}flagDefault(e){return JSON.stringify(e)}flagDescription({flag:e}){var a;let n="description"in e&&(a=e.description)!=null?a:"";if("default"in e){let{default:r}=e;typeof r=="function"&&(r=r()),r&&(n+=` (default: ${this.flagDefault(r)})`)}return n}render(e){if(typeof e=="string")return e;if(Array.isArray(e))return e.map(n=>this.render(n)).join(`
|
|
9
|
-
`);if("type"in e&&this[e.type]){let n=this[e.type];if(typeof n=="function")return n.call(this,e.data)}throw new Error(`Invalid node type: ${JSON.stringify(e)}`)}};var h=/^[\w
|
|
9
|
+
`);if("type"in e&&this[e.type]){let n=this[e.type];if(typeof n=="function")return n.call(this,e.data)}throw new Error(`Invalid node type: ${JSON.stringify(e)}`)}};var h=/^[\w.-]+$/;var{stringify:m}=JSON,te=/[|\\{}()[\]^$+*?.]/;function ne(t){let e=[],n,a;for(let r of t){if(a)throw new Error(`Invalid parameter: Spread parameter ${m(a)} must be last`);let s=r[0],i=r[r.length-1],p;if(s==="<"&&i===">"&&(p=!0,n))throw new Error(`Invalid parameter: Required parameter ${m(r)} cannot come after optional parameter ${m(n)}`);if(s==="["&&i==="]"&&(p=!1,n=r),p===void 0)throw new Error(`Invalid parameter: ${m(r)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let o=r.slice(1,-1),g=o.slice(-3)==="...";g&&(a=r,o=o.slice(0,-3));let y=o.match(te);if(y)throw new Error(`Invalid parameter: ${m(r)}. Invalid character found ${m(y[0])}`);e.push({name:o,required:p,spread:g})}return e}function re(t){return t===void 0||t!==!1}function S(t,e,n,a){let r=f({},e.flags),s=e.version;s&&(r.version={type:Boolean,description:"Show version"});let{help:i}=e,p=re(i);p&&!("help"in r)&&(r.help={type:Boolean,alias:"h",description:"Show help"});let o=ee(r,a),g=()=>{console.log(e.version)};if(s&&o.flags.version===!0)return g(),process.exit(0);let y=new C,B=p&&(i==null?void 0:i.render)?i.render:l=>y.render(l),b=l=>{let P=v(O(f(f({},e),l?{help:l}:{}),{flags:r}));console.log(B(P,y))};if(p&&o.flags.help===!0)return b(),process.exit(0);if(e.parameters){let l=ne(e.parameters),P=o._;for(let u=0;u<l.length;u+=1){let{name:$,required:I,spread:x}=l[u],w=x?o._.slice(u):o._[u];if(x&&(u=l.length),I&&(!w||x&&w.length===0))return console.error(`Error: Missing required parameter ${m($)}
|
|
10
10
|
`),b(),process.exit(1);P[F($)]=w}}let A=O(f({},o),{showVersion:g,showHelp:b});return typeof n=="function"&&n(A),f({command:t},A)}function ae(t,e){let n=new Map;for(let a of e){let r=[a.options.name],{alias:s}=a.options;s&&(Array.isArray(s)?r.push(...s):r.push(s));for(let i of r){if(n.has(i))throw new Error(`Duplicate command name found: ${m(i)}`);n.set(i,a)}}return n.get(t)}function se(t,e,n=process.argv.slice(2)){if(!t)throw new Error("Options is required");if("name"in t&&(!t.name||!h.test(t.name)))throw new Error(`Invalid script name: ${m(t.name)}`);let a=n[0];if(t.commands&&h.test(a)){let r=ae(a,t.commands);if(r)return S(r.options.name,O(f({},r.options),{parent:t}),r.callback,n.slice(1))}return S(void 0,t,e,n)}function ie(t,e){if(!t)throw new Error("Command options are required");let{name:n}=t;if(t.name===void 0)throw new Error("Command name is required");if(!h.test(n))throw new Error(`Invalid command name ${JSON.stringify(n)}. Command names must be one word.`);return{options:t,callback:e}}export{se as cli,ie as command};
|