pickier 0.1.65 → 0.1.66
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/dist/bin/cli.js +2 -2
- package/dist/chunk-0byqg5rc.js +2 -0
- package/dist/chunk-nke9r0j5.js +2 -0
- package/dist/chunk-p0j2ra3t.js +31 -0
- package/dist/chunk-p5zbyxq6.js +2 -0
- package/dist/chunk-rg0g2fzg.js +92 -0
- package/dist/chunk-vbmkrdh6.js +226 -0
- package/dist/chunk-zzacmw52.js +2 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/linter.d.ts +9 -0
- package/package.json +1 -1
- package/dist/chunk-awmb5sg5.js +0 -3
- package/dist/chunk-bnbsk67m.js +0 -2
- package/dist/chunk-gy6wyx8t.js +0 -62
- package/dist/chunk-hwa8gmzb.js +0 -156
- package/dist/chunk-qh9cawym.js +0 -2
- package/dist/chunk-sj3ctzyt.js +0 -3
- package/dist/chunk-tskywgx9.js +0 -226
- package/dist/chunk-vdbbvx8x.js +0 -33
- package/dist/chunk-wh52kdr1.js +0 -2
- package/dist/chunk-z7exyj5z.js +0 -2
package/dist/bin/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
|
|
4
|
-
`)}),r.version(
|
|
3
|
+
async function y(){let n=process.argv.slice(2),c=n[0]==="run",w=c?1:0,a=c?"auto":"lint",m=!1,u=!1,d=!1,g=!1,h,p=[],x=!0;for(let t=w;t<n.length;t++){let e=n[t];if(e==="--mode")a=n[++t]||"auto";else if(e==="--format")d=!0,a="format";else if(e==="--check")m=!0;else if(e==="--write")u=!0;else if(e==="--config")h=n[++t];else if(e==="--verbose")g=!0;else if(e==="--ext"||e==="--ignore-path")t++;else if(e==="--fix"||e==="--dry-run"||e==="--reporter"||e==="--max-warnings"||e==="--cache"){x=!1,p.length=0;break}else if(e.startsWith("--"));else p.push(e)}if(x&&(a==="format"||a==="auto"||a==="lint")&&p.length>0){let{runUnified:t}=await import("../chunk-p5zbyxq6.js"),e=await t(p,{mode:a,check:m,write:u,verbose:g,config:h});process.exit(e)}let{CLI:k}=await import("../chunk-p0j2ra3t.js"),{version:b}=await import("../chunk-0byqg5rc.js"),r=new k("pickier"),l=(t)=>{let[e,o]=t;return[Array.isArray(e)?e.filter((f)=>typeof f==="string"):[],o&&typeof o==="object"?o:{}]};r.command("[...globs]","Lint files (default)").option("--fix","Auto-fix lint problems").option("--format","Format files instead of linting").option("--dry-run","Simulate fixes without writing").option("--check","Check formatting without writing (CI-friendly)").option("--max-warnings <n>","Max warnings before non-zero exit",{default:-1}).option("--reporter <name>","stylish|json|compact",{default:"stylish"}).option("--config <path>","Path to pickier config").option("--ignore-path <file>","Ignore file (like .gitignore)").option("--ext <exts>","Comma-separated extensions").option("--cache","Enable cache").option("--verbose","Verbose output").example("pickier .").example("pickier . --fix").example("pickier . --format").example("pickier src --fix --verbose").action(async(...t)=>{let[e,o]=l(t);if(e.length===0){r.outputHelp();return}let{runUnified:s}=await import("../chunk-p5zbyxq6.js"),i;if(o.format){if(i="format",!o.check)o.write=!0}else i="lint";let f=await s(e,{...o,mode:i});process.exit(f)}),r.command("lint [...globs]","[DEPRECATION] Use `pickier [...globs]` instead. Lint files").option("--fix","Auto-fix problems").option("--dry-run","Simulate fixes without writing").option("--max-warnings <n>","Max warnings before non-zero exit",{default:-1}).option("--reporter <name>","stylish|json|compact",{default:"stylish"}).option("--config <path>","Path to pickier config").option("--ignore-path <file>","Ignore file (like .gitignore)").option("--ext <exts>","Comma-separated extensions").option("--cache","Enable cache").option("--verbose","Verbose output").example("pickier lint .").example("pickier lint src --fix").example('pickier lint "src/**/*.{ts,tsx}" --reporter json').action(async(...t)=>{let[e,o]=l(t),{runUnified:s}=await import("../chunk-p5zbyxq6.js"),i=await s(e,{...o,mode:"lint"});process.exit(i)}),r.command("format [...globs]","[DEPRECATION] Use `pickier [...globs] --format` instead. Format files").option("--write","Write changes to files").option("--check","Check without writing (CI-friendly)").option("--config <path>","Path to pickier config").option("--ignore-path <file>","Ignore file").option("--ext <exts>","Comma-separated extensions").option("--verbose","Verbose output").example("pickier format . --write").example("pickier format . --check").action(async(...t)=>{let[e,o]=l(t),{runUnified:s}=await import("../chunk-p5zbyxq6.js"),i=await s(e,{...o,mode:"format"});process.exit(i)}),r.command("run [...globs]","Unified mode (auto, lint, or format)").option("--mode <mode>","auto|lint|format",{default:"auto"}).option("--fix","Auto-fix problems (lint mode)").option("--dry-run","Simulate fixes without writing (lint mode)").option("--max-warnings <n>","Max warnings before non-zero exit (lint mode)",{default:-1}).option("--reporter <name>","stylish|json|compact (lint mode)",{default:"stylish"}).option("--write","Write changes to files (format mode)").option("--check","Check without writing (format mode)").option("--config <path>","Path to pickier config").option("--ignore-path <file>","Ignore file (like .gitignore)").option("--ext <exts>","Comma-separated extensions").option("--cache","Enable cache (lint mode)").option("--verbose","Verbose output").example("pickier run . --mode lint --fix").example("pickier run . --mode format --write").action(async(...t)=>{let[e,o]=l(t),{runUnified:s}=await import("../chunk-p5zbyxq6.js"),i=await s(e,o);process.exit(i)}),r.command("version","Show the version of the CLI").action(async()=>{let{version:t}=await import("../chunk-0byqg5rc.js");process.stdout.write(`${t}
|
|
4
|
+
`)}),r.version(b),r.help(),r.parse()}y().catch((n)=>{let c=n instanceof Error?n.message:String(n);process.stderr.write(`pickier: ${c}
|
|
5
5
|
`),process.exit(1)});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var e="pickier",u="module",t="0.1.66",r="Format, lint and more in a fraction of seconds.",s="Chris Breuer <chris@stacksjs.org>",l="MIT",p="https://github.com/pickier/pickier#readme",b={type:"git",url:"git+https://github.com/pickier/pickier.git"},c={url:"https://github.com/pickier/pickier/issues"},m=["pickier","linter","formatter","bun","fast"],o={".":{types:"./dist/src/index.d.ts",import:"./dist/src/index.js"},"./*":{import:"./dist/*"}},a="./dist/src/index.js",x="./dist/src/index.d.ts",d={pickier:"./dist/bin/cli.js"},w=["README.md","dist"],k={build:"bun --bun build.ts","build:bin":"bun --bun build.ts && bun run compile",compile:"bun build ./bin/cli.ts --compile --minify --outfile bin/pickier","compile:all":"bun run compile:linux-x64 && bun run compile:linux-arm64 && bun run compile:linux-x64-musl && bun run compile:linux-arm64-musl && bun run compile:windows-x64 && bun run compile:windows-arm64 && bun run compile:darwin-x64 && bun run compile:darwin-arm64","compile:linux-x64":"bun build ./bin/cli.ts --compile --minify --target=bun-linux-x64 --outfile bin/pickier-linux-x64","compile:linux-arm64":"bun build ./bin/cli.ts --compile --minify --target=bun-linux-arm64 --outfile bin/pickier-linux-arm64","compile:linux-x64-musl":"bun build ./bin/cli.ts --compile --minify --target=bun-linux-x64-musl --outfile bin/pickier-linux-x64-musl","compile:linux-arm64-musl":"bun build ./bin/cli.ts --compile --minify --target=bun-linux-arm64-musl --outfile bin/pickier-linux-arm64-musl","compile:windows-x64":"bun build ./bin/cli.ts --compile --minify --target=bun-windows-x64 --outfile bin/pickier-windows-x64.exe","compile:windows-arm64":"bun build ./bin/cli.ts --compile --minify --target=bun-windows-arm64 --outfile bin/pickier-windows-arm64.exe","compile:darwin-x64":"bun build ./bin/cli.ts --compile --minify --target=bun-darwin-x64 --outfile bin/pickier-darwin-x64","compile:darwin-arm64":"bun build ./bin/cli.ts --compile --minify --target=bun-darwin-arm64 --outfile bin/pickier-darwin-arm64",zip:"bun run zip:all","zip:all":"bun run zip:linux-x64 && bun run zip:linux-arm64 && bun run zip:linux-x64-musl && bun run zip:linux-arm64-musl && bun run zip:windows-x64 && bun run zip:windows-arm64 && bun run zip:darwin-x64 && bun run zip:darwin-arm64","zip:linux-x64":"zip -j bin/pickier-linux-x64.zip bin/pickier-linux-x64","zip:linux-arm64":"zip -j bin/pickier-linux-arm64.zip bin/pickier-linux-arm64","zip:linux-x64-musl":"zip -j bin/pickier-linux-x64-musl.zip bin/pickier-linux-x64-musl","zip:linux-arm64-musl":"zip -j bin/pickier-linux-arm64-musl.zip bin/pickier-linux-arm64-musl","zip:windows-x64":"zip -j bin/pickier-windows-x64.zip bin/pickier-windows-x64.exe","zip:windows-arm64":"zip -j bin/pickier-windows-arm64.zip bin/pickier-windows-arm64.exe","zip:darwin-x64":"zip -j bin/pickier-darwin-x64.zip bin/pickier-darwin-x64","zip:darwin-arm64":"zip -j bin/pickier-darwin-arm64.zip bin/pickier-darwin-arm64",prepublishOnly:"bun --bun run build && bun run compile:all && bun run zip",test:"PICKIER_NO_AUTO_CONFIG=1 bun test --coverage","test:core":"PICKIER_NO_AUTO_CONFIG=1 bun test test/core","test:format":"PICKIER_NO_AUTO_CONFIG=1 bun test test/format","test:lint":"PICKIER_NO_AUTO_CONFIG=1 bun test test/lint","test:rules":"PICKIER_NO_AUTO_CONFIG=1 bun test test/rules","test:rules:sort":"PICKIER_NO_AUTO_CONFIG=1 bun test test/rules/sort","test:rules:style":"PICKIER_NO_AUTO_CONFIG=1 bun test test/rules/style","test:rules:quality":"PICKIER_NO_AUTO_CONFIG=1 bun test test/rules/quality","test:rules:imports":"PICKIER_NO_AUTO_CONFIG=1 bun test test/rules/imports","test:rules:typescript":"PICKIER_NO_AUTO_CONFIG=1 bun test test/rules/typescript","test:rules:regexp":"PICKIER_NO_AUTO_CONFIG=1 bun test test/rules/regexp","test:plugin":"PICKIER_NO_AUTO_CONFIG=1 bun test test/plugin","test:watch":"PICKIER_NO_AUTO_CONFIG=1 bun test --watch"},I={"@stacksjs/clarity":"^0.3.24","@stacksjs/clapp":"^0.2.3"},O={"@stacksjs/ts-spell-check":"^0.1.0"},_={bunfig:"^0.15.13"},z={name:e,type:u,version:t,description:r,author:s,license:l,homepage:p,repository:b,bugs:c,keywords:m,exports:o,module:a,types:x,bin:d,files:w,scripts:k,dependencies:I,optionalDependencies:O,devDependencies:_};export{s as author,d as bin,c as bugs,z as default,I as dependencies,r as description,_ as devDependencies,o as exports,w as files,p as homepage,m as keywords,l as license,a as module,e as name,O as optionalDependencies,b as repository,k as scripts,u as type,x as types,t as version};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{existsSync as z}from"fs";import O from"fs/promises";import N from"os";import E from"path";import y from"process";import{EventEmitter as Y}from"events";import v from"process";import R from"process";import k from"process";import _ from"process";import C from"process";import W from"tty";import Le,{stdin as at,stdout as lt}from"process";class P{configPath;config=null;events=[];retryCount=0;maxRetries=3;retryDelayMs=1000;constructor(){let e=N.homedir(),t=E.join(e,".config","clapp");this.configPath=E.join(t,"telemetry.json")}async isEnabled(){if(y.env.DO_NOT_TRACK==="1"||y.env.DO_NOT_TRACK==="true")return!1;if(y.env.NO_TELEMETRY==="1"||y.env.NO_TELEMETRY==="true")return!1;return(await this.loadConfig()).enabled}async enable(){let e=await this.loadConfig();if(e.enabled=!0,!e.userId)e.userId=this.generateUserId();await this.saveConfig(e)}async disable(){let e=await this.loadConfig();e.enabled=!1,await this.saveConfig(e)}async track(e,t){if(!await this.isEnabled())return;let i={event:e,...t,timestamp:Date.now(),platform:N.platform(),nodeVersion:y.version};if(this.events.push(i),this.events.length>=10)await this.send()}async trackCommand(e,t){await this.track("command",{command:e,duration:t})}async trackError(e,t){await this.track("error",{error:e,command:t})}async send(){if(!await this.isEnabled()||this.events.length===0)return!0;try{this.events=[],this.retryCount=0;let t=await this.loadConfig();return t.lastSent=Date.now(),await this.saveConfig(t),!0}catch{if(this.retryCount<this.maxRetries){this.retryCount++;let t=this.retryDelayMs*2**(this.retryCount-1);return await this.sleep(t),this.send()}return this.events=[],this.retryCount=0,!1}}async flush(){if(this.events.length===0)return!0;return this.send()}sleep(e){return new Promise((t)=>setTimeout(t,e))}async status(){let e=await this.loadConfig();return{enabled:e.enabled,doNotTrack:y.env.DO_NOT_TRACK==="1"||y.env.DO_NOT_TRACK==="true",eventsQueued:this.events.length,lastSent:e.lastSent}}async loadConfig(){if(this.config)return this.config;try{if(z(this.configPath)){let e=await O.readFile(this.configPath,"utf-8");return this.config=JSON.parse(e),this.config}}catch{}return this.config={enabled:!1},this.config}async saveConfig(e){this.config=e;try{let t=E.dirname(this.configPath);await O.mkdir(t,{recursive:!0}),await O.writeFile(this.configPath,JSON.stringify(e,null,2),"utf-8")}catch{}}generateUserId(){let e=Math.random().toString(36).substring(2,15),t=Date.now().toString(36);return`${e}-${t}`}}var ze=new P;function J(e,t={}){let s={_:[]},i=t.alias||{},r=new Set(t.boolean||[]),a={};for(let o of Object.keys(i))for(let n of i[o])a[n]=o;for(let o of r)if(i[o])for(let n of i[o])r.add(n);function u(o,n){let l=a[o]||o;if(s[l]=n,i[l])for(let c of i[l])s[c]=n;if(a[o]&&i[a[o]])for(let c of i[a[o]])s[c]=n;s[o]=n}for(let o=0;o<e.length;o++){let n=e[o];if(n==="--"){s._.push(...e.slice(o+1));break}if(n.startsWith("--")){let l=n.indexOf("=");if(l!==-1){let c=n.slice(2,l),h=n.slice(l+1);u(c,h)}else{let c=n.slice(2);if(c.startsWith("no-")){let m=c.slice(3);u(m,!1);continue}let h=a[c]||c;if(r.has(h)||r.has(c))u(c,!0);else{let m=e[o+1];if(m!==void 0&&!m.startsWith("-"))u(c,m),o++;else u(c,!0)}}}else if(n.startsWith("-")&&n.length>1){let l=n.slice(1);for(let c=0;c<l.length;c++){let h=l[c],m=a[h]||h;if(c===l.length-1&&!r.has(m)&&!r.has(h)){let d=e[o+1];if(d!==void 0&&!d.startsWith("-"))u(h,d),o++;else u(h,!0)}else u(h,!0)}}else s._.push(n)}return s}function T(e){return e.replace(/[<[].+/,"").trim()}function Q(e){let t=/<([^>]+)>/g,s=/\[([^\]]+)\]/g,i=[],r=(o)=>{let n=!1,l=o[1];if(l.startsWith("..."))l=l.slice(3),n=!0;return{required:o[0].startsWith("<"),value:l,variadic:n}},a;while(a=t.exec(e))i.push(r(a));let u;while(u=s.exec(e))i.push(r(u));return i}function X(e){let t={alias:{},boolean:[]};for(let[s,i]of e.entries()){if(i.names.length>1)t.alias[i.names[0]]=i.names.slice(1);if(i.isBoolean)if(i.negated){if(!e.some((a,u)=>u!==s&&a.names.some((o)=>i.names.includes(o))&&typeof a.required==="boolean"))t.boolean.push(i.names[0])}else t.boolean.push(i.names[0])}return t}function j(e){return e.reduce((t,s)=>t.length>=s.length?t:s,"")}function B(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function Z(e){return e.replace(/([a-z])-([a-z])/g,(t,s,i)=>s+i.toUpperCase())}function ee(e,t,s){let i=0,r=t.length,a=e,u;for(;i<r;++i)u=a[t[i]],a=a[t[i]]=i===r-1?s:u!=null?u:!!~t[i+1].indexOf(".")||!(+t[i+1]>-1)?{}:[]}function te(e,t){for(let s of Object.keys(t)){let i=t[s];if(i.shouldTransform){if(e[s]=Array.prototype.concat.call([],e[s]),typeof i.transformFunction==="function")e[s]=e[s].map(i.transformFunction)}}}function se(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function F(e){return e.split(".").map((t,s)=>s===0?Z(t):t).join(".")}class S extends Error{exitCode=2;isUsageError=!0;constructor(e){super(e);if(this.name=this.constructor.name,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=Error(e).stack}format(e=!1){if(e&&this.stack)return`${this.message}
|
|
3
|
+
|
|
4
|
+
Stack trace:
|
|
5
|
+
${this.stack}`;return this.message}}function ie(){let{env:e}=R,{TERM:t,TERM_PROGRAM:s}=e;if(R.platform!=="win32")return t!=="linux";return Boolean(e.WT_SESSION)||Boolean(e.TERMINUS_SUBLIME)||e.ConEmuTask==="{cmd::Cmder}"||s==="Terminus-Sublime"||s==="vscode"||t==="xterm-256color"||t==="alacritty"||t==="rxvt-unicode"||t==="rxvt-unicode-256color"||e.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var I="\x1B",g=`${I}[`;var L={to(e,t){if(!t)return`${g}${e+1}G`;return`${g}${t+1};${e+1}H`},move(e,t){let s="";if(e<0)s+=`${g}${-e}D`;else if(e>0)s+=`${g}${e}C`;if(t<0)s+=`${g}${-t}A`;else if(t>0)s+=`${g}${t}B`;return s},up:(e=1)=>`${g}${e}A`,down:(e=1)=>`${g}${e}B`,forward:(e=1)=>`${g}${e}C`,backward:(e=1)=>`${g}${e}D`,nextLine:(e=1)=>`${g}E`.repeat(e),prevLine:(e=1)=>`${g}F`.repeat(e),left:`${g}G`,hide:`${g}?25l`,show:`${g}?25h`,save:`${I}7`,restore:`${I}8`};var Xe={screen:`${g}2J`,up:(e=1)=>`${g}1J`.repeat(e),down:(e=1)=>`${g}J`.repeat(e),line:`${g}2K`,lineEnd:`${g}K`,lineStart:`${g}1K`,lines(e){let t="";for(let s=0;s<e;s++)t+=this.line+(s<e-1?L.up():"");if(e)t+=L.left;return t}},Ze={screen:`${I}c`};function ne(e,t){let s=[];for(let i=0;i<=t.length;i++)s[i]=[i];for(let i=0;i<=e.length;i++)s[0][i]=i;for(let i=1;i<=t.length;i++)for(let r=1;r<=e.length;r++)if(t.charAt(i-1)===e.charAt(r-1))s[i][r]=s[i-1][r-1];else s[i][r]=Math.min(s[i-1][r-1]+1,s[i][r-1]+1,s[i-1][r]+1);return s[t.length][e.length]}function H(e,t,s=2,i=3){return t.map((r)=>({cmd:r,distance:ne(e,r)})).filter(({distance:r})=>r<=s).sort((r,a)=>r.distance-a.distance).slice(0,i).map(({cmd:r})=>r)}class U{rawName;description;name;names;isBoolean;required;config;negated;constructor(e,t,s){if(this.rawName=e,this.description=t,this.config=Object.assign({},s),e=e.replace(/\.\*/g,""),this.negated=!1,this.names=T(e).split(",").map((i)=>{let r=i.trim().replace(/^-{1,2}/,"");if(r.startsWith("no-"))this.negated=!0,r=r.replace(/^no-/,"");return F(r)}).sort((i,r)=>i.length>r.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}}var tt=k.argv,re=`${k.platform}-${k.arch} bun-v${typeof Bun<"u"?Bun.version:"unknown"}`,D=_.argv,oe=`${_.platform}-${_.arch} node-${_.version}`;class V{rawName;description;config;cli;options;aliasNames;name;namespace;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;beforeHooks;afterHooks;middleware;constructor(e,t,s,i){this.rawName=e,this.description=t,this.config=s,this.cli=i,this.options=[],this.aliasNames=[],this.name=T(e);let r=T(e),a=r.indexOf(":");if(a>0)this.namespace=r.substring(0,a),this.name=r.substring(a+1);if(this.args=Q(e),this.examples=[],this.beforeHooks=[],this.afterHooks=[],this.middleware=[],!s)this.config={}}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,s){let i=new U(e,t,s);return this.options.push(i),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}before(e){return this.beforeHooks.push(e),this}after(e){return this.afterHooks.push(e),this}use(e){return this.middleware.push(e),this}isMatched(e){if(this.aliasNames.includes(e))return!0;if(this.namespace)return`${this.namespace}:${this.name}`===e;return this.name===e}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof M}get displayName(){return this.namespace?`${this.namespace}:${this.name}`:this.name}hasOption(e){return e=e.split(".")[0],!!this.options.find((t)=>t.names.includes(e))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:s,options:i,helpCallback:r}=this.cli.globalCommand,a=[{body:`${e}${s?`/${s}`:""}`}];if(a.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let n=j(t.map((d)=>d.rawName)),l=new Map,c=[];for(let d of t)if(d.namespace){if(!l.has(d.namespace))l.set(d.namespace,[]);l.get(d.namespace).push(d)}else c.push(d);let h="";if(c.length>0)h+=c.map((d)=>` ${B(d.rawName,n.length)} ${d.description}`).join(`
|
|
6
|
+
`);let m=Array.from(l.keys()).sort();for(let d of m){let q=l.get(d);if(h.length>0)h+=`
|
|
7
|
+
|
|
8
|
+
`;h+=` ${d}:
|
|
9
|
+
`,h+=q.map((A)=>` ${B(A.rawName,n.length-2)} ${A.description}`).join(`
|
|
10
|
+
`)}a.push({title:"Commands",body:h}),a.push({title:"For more info, run any command with the `--help` flag",body:t.map((d)=>` $ ${e}${d.displayName===""?"":` ${d.displayName}`} --help`).join(`
|
|
11
|
+
`)})}let o=this.isGlobalCommand?i:[...this.options,...i||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)o=o.filter((n)=>n.name!=="version");if(o.length>0){let n=j(o.map((l)=>l.rawName));a.push({title:"Options",body:o.map((l)=>` ${B(l.rawName,n.length)} ${l.description} ${l.config.default===void 0?"":`(default: ${l.config.default})`}`).join(`
|
|
12
|
+
`)})}if(this.examples.length>0)a.push({title:"Examples",body:this.examples.map((n)=>{if(typeof n==="function")return n(e);return n}).join(`
|
|
13
|
+
`)});if(r)a=r(a)||a;console.log(a.map((n)=>n.title?`${n.title}:
|
|
14
|
+
${n.body}`:n.body).join(`
|
|
15
|
+
|
|
16
|
+
`))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.log(`${e}/${t} ${typeof Bun<"u"?re:oe}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e){let s=this.args.filter((r)=>r.required).slice(this.cli.args.length),i=s.map((r)=>`<${r.value}>`).join(" ");throw new S(`Missing required argument${s.length>1?"s":""}: ${i}
|
|
17
|
+
|
|
18
|
+
Run \`${this.cli.name} ${this.rawName} --help\` for usage information.`)}}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let s of Object.keys(e))if(s!=="--"&&!this.hasOption(s)&&!t.hasOption(s)){let r=[...t.options,...this.options].flatMap((n)=>n.names),a=s.length>1?`--${s}`:`-${s}`,u=H(s,r),o=`Unknown option \`${a}\``;if(u.length>0)o+=`
|
|
19
|
+
|
|
20
|
+
Did you mean one of these?`,u.forEach((n)=>{let l=n.length>1?`--${n}`:`-${n}`;o+=`
|
|
21
|
+
\u2022 ${l}`});throw o+=`
|
|
22
|
+
|
|
23
|
+
Run \`${this.cli.name} ${this.rawName} --help\` to see available options.`,new S(o)}}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,s=[...t.options,...this.options];for(let i of s){let r=e[i.name.split(".")[0]];if(i.required){let a=s.some((u)=>u.negated&&u.names.includes(i.name));if(r===!0||r===!1&&!a)throw new S(`Option \`${i.rawName}\` requires a value.
|
|
24
|
+
|
|
25
|
+
Example: ${this.cli.name} ${this.rawName} ${i.rawName} <value>`)}}}}class M extends V{constructor(e){super("@@global@@","",{},e)}}var ae=V,w={red:["\x1B[31m","\x1B[39m"],green:["\x1B[32m","\x1B[39m"],blue:["\x1B[34m","\x1B[39m"],yellow:["\x1B[33m","\x1B[39m"],cyan:["\x1B[36m","\x1B[39m"],magenta:["\x1B[35m","\x1B[39m"],white:["\x1B[37m","\x1B[39m"],gray:["\x1B[90m","\x1B[39m"],bgRed:["\x1B[41m","\x1B[49m"],bgGreen:["\x1B[42m","\x1B[49m"],bgBlue:["\x1B[44m","\x1B[49m"],bgYellow:["\x1B[43m","\x1B[49m"],bgCyan:["\x1B[46m","\x1B[49m"],bgMagenta:["\x1B[45m","\x1B[49m"],bold:["\x1B[1m","\x1B[22m"],italic:["\x1B[3m","\x1B[23m"],underline:["\x1B[4m","\x1B[24m"],dim:["\x1B[2m","\x1B[22m"],inverse:["\x1B[7m","\x1B[27m"],hidden:["\x1B[8m","\x1B[28m"],strikethrough:["\x1B[9m","\x1B[29m"]};var b={primary:"blue",secondary:"cyan",success:"green",warning:"yellow",error:"red",info:"magenta",muted:"gray"};function le(){return!0}function ue(){let e={};e.supportsColor=le();function t(i,r=[]){let a=i===""?[]:[...r,i],u=function(n){if(!e.supportsColor)return n;let l="",c="";for(let h of a)if(h in b&&b[h]in w){let m=b[h];l+=w[m][0],c=w[m][1]+c}else if(h in w)l+=w[h][0],c=w[h][1]+c;return l+n+c},o=[...Object.keys(w),...Object.keys(b)];for(let n of o)if(!(n in u))Object.defineProperty(u,n,{get(){return t(n,a)}});return u}let s=[...Object.keys(w),...Object.keys(b)];for(let i of s)if(!(i in e))Object.defineProperty(e,i,{get(){return t(i)}});return e}var x=ue();class ce extends Y{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;enableDidYouMean=!0;signalHandlersSet=!1;isVerbose=!1;isQuiet=!1;isDebug=!1;isNoInteraction=!1;environment;isDryRun=!1;isForce=!1;useEmoji=!0;theme;isNoCache=!1;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new M(this),this.globalCommand.usage("<command> [options]")}handleSignals(e){if(this.signalHandlersSet)return this;let t=async(s)=>{if(console.log(`
|
|
26
|
+
|
|
27
|
+
Received ${s}, cleaning up...`),e)try{await e()}catch(i){console.error("Error during cleanup:",i)}v.exit(0)};return v.on("SIGINT",()=>t("SIGINT")),v.on("SIGTERM",()=>t("SIGTERM")),this.signalHandlersSet=!0,this}didYouMean(e=!0){return this.enableDidYouMean=e,this}verbose(){return this.globalCommand.option("-v, --verbose","Enable verbose output"),this}quiet(){return this.globalCommand.option("-q, --quiet","Suppress non-essential output"),this}debug(){return this.globalCommand.option("--debug","Enable debug mode with detailed error information"),this}noInteraction(){return this.globalCommand.option("-n, --no-interaction","Do not ask any interactive questions (for CI/CD)"),this}env(){return this.globalCommand.option("--env <environment>","Target environment (e.g., production, staging, local)"),this}dryRun(){return this.globalCommand.option("--dry-run","Preview actions without executing them"),this}force(){return this.globalCommand.option("-f, --force","Skip confirmation prompts"),this}emoji(){return this.globalCommand.option("--no-emoji","Disable emoji in output"),this}themes(){return this.globalCommand.option("--theme <theme>","Color theme (default, dracula, nord, solarized, monokai)"),this}cache(){return this.globalCommand.option("--no-cache","Disable caching"),this}usage(e){return this.globalCommand.usage(e),this}command(e,t,s){if(!s)s={};let i=new ae(e,t||"",s,this);return i.globalCommand=this.globalCommand,this.commands.push(i),i}option(e,t,s){return this.globalCommand.option(e,t,s),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},s,i){if(this.args=e,this.options=t,s)this.matchedCommand=s;if(i)this.matchedCommandName=i;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}showCommandNotFound(e){if(console.log(x.red(`
|
|
28
|
+
\u2717 Command "${e}" not found.
|
|
29
|
+
`)),this.enableDidYouMean){let t=[];for(let i of this.commands){if(i.displayName)t.push(i.displayName);if(i.aliasNames)t.push(...i.aliasNames)}let s=H(e,t);if(s.length>0)console.log(x.yellow("Did you mean one of these?")),s.forEach((i)=>console.log(` ${x.dim("\u2022")} ${this.name} ${i}`)),console.log("")}console.log(x.dim("Run"),`${this.name} --help`,x.dim("to see all available commands")),v.exit(1)}async parse(e=D,t={}){let{run:s=!0,exitOnError:i=!1}=t;if(i)try{return await this.parse(e,{run:s})}catch(n){throw this.handleUsageError(n),n}if(this.rawArgs=e,!this.name)this.name=e[1]?se(e[1]):"cli";let r=!0,a=e.slice(2),u=a[0];if(u&&!u.startsWith("-")){for(let n of this.commands)if(n.isMatched(u)){let l=this.mri(a,n);r=!1;let c={...l,args:l.args.slice(1)};this.setParsedInfo(c,n,u),this.emit(`command:${u}`,n);break}}if(r){for(let n of this.commands)if(n.name===""){r=!1;let l=this.mri(a,n);this.setParsedInfo(l,n),this.emit("command:!",n);break}}if(r){let n=this.mri(e.slice(2));this.setParsedInfo(n)}if(this.options.verbose)this.isVerbose=!0;if(this.options.quiet)this.isQuiet=!0;if(this.options.debug)this.isDebug=!0;if(this.options.noInteraction)this.isNoInteraction=!0;if(this.options.env)this.environment=String(this.options.env);if(this.options.dryRun)this.isDryRun=!0;if(this.options.force)this.isForce=!0;if(this.options.noEmoji!==void 0)this.useEmoji=!this.options.noEmoji;if(this.options.theme)this.theme=String(this.options.theme);if(this.options.noCache!==void 0)this.isNoCache=Boolean(this.options.noCache);if(this.options.help&&this.showHelpOnExit)this.outputHelp(),s=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),s=!1,this.unsetMatchedCommand();let o={args:this.args,options:this.options};if(s)await this.runMatchedCommand();if(!this.matchedCommand&&this.args[0]){if(this.emit("command:*"),!(this.listenerCount("command:*")>0))this.showCommandNotFound(this.args[0])}return o}mri(e,t){let s=[...this.globalCommand.options,...t?t.options:[]],i=X(s),r=[],a=e.indexOf("--");if(a>-1)r=e.slice(a+1),e=e.slice(0,a);let u=J(e,i),o={_:u._};for(let m of Object.keys(u))if(m!=="_")o[F(m)]=u[m];let n=o._,l={"--":r},c=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,h=Object.create(null);for(let m of s){if(!c&&m.config.default!==void 0)for(let d of m.names)l[d]=m.config.default;if(Array.isArray(m.config.type)){if(h[m.name]===void 0)h[m.name]={shouldTransform:!0,transformFunction:m.config.type[0]}}}for(let m of Object.keys(o))if(m!=="_"){let d=m.split(".");ee(l,d,o[m]),te(l,h)}return{args:n,options:l}}async run(e=D){return this.parse(e,{run:!0,exitOnError:!0})}handleUsageError(e){if(!(!!e&&typeof e==="object"&&e.name==="ClappError"&&e.isUsageError!==!1))return;let i=e,r=i.message??"command-line error",a=this.name?`${this.name}: `:"",u=/--help/.test(r)?"":`
|
|
30
|
+
Run \`${this.name??"cli"} --help\` for usage.`;v.stderr.write(`${a}${r}${u}
|
|
31
|
+
`),v.exit(i.exitCode??2)}async runMatchedCommand(){let{args:e,options:t,matchedCommand:s}=this;if(!s||!s.commandAction)return;s.checkUnknownOptions(),s.checkOptionValue(),s.checkRequiredArgs();let i=[];s.args.forEach((o,n)=>{if(o.variadic)i.push(e.slice(n));else i.push(e[n])}),i.push(t);let r={command:s,args:i,options:t};for(let o of s.beforeHooks)await o(r);let a,u=async()=>{let o=s.commandAction.apply(this,i);if(o instanceof Promise)a=await o;else a=o;return a};if(s.middleware.length>0){let o=0,n=async()=>{if(o<s.middleware.length){let l=s.middleware[o++];await l({...r,next:n})}else await u()};await n()}else await u();for(let o of s.afterHooks)await o(r);return a}removeSignalHandlers(){if(!this.signalHandlersSet)return this;return v.removeAllListeners("SIGINT"),v.removeAllListeners("SIGTERM"),this.signalHandlersSet=!1,this}destroy(){this.removeSignalHandlers(),this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.matchedCommand=void 0,this.matchedCommandName=void 0,this.removeAllListeners()}}class G{cache;enabled;cleanupInterval=null;hits=0;misses=0;constructor(){this.cache=new Map,this.enabled=!0,this.startCleanupInterval()}startCleanupInterval(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanup()},30000),this.cleanupInterval.unref()}stopCleanup(){if(this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}isEnabled(){return this.enabled}get(e){if(!this.enabled){this.misses++;return}let t=this.cache.get(e);if(!t){this.misses++;return}if(Date.now()-t.timestamp>t.ttl){this.cache.delete(e),this.misses++;return}return this.hits++,t.value}set(e,t,s=5000){if(!this.enabled)return;this.cache.set(e,{value:t,timestamp:Date.now(),ttl:s})}has(e){if(!this.enabled)return!1;let t=this.cache.get(e);if(!t)return!1;if(Date.now()-t.timestamp>t.ttl)return this.cache.delete(e),!1;return!0}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}disable(){this.enabled=!1,this.clear()}enable(){this.enabled=!0}stats(){return{size:this.cache.size,enabled:this.enabled,hits:this.hits,misses:this.misses}}resetStats(){this.hits=0,this.misses=0}keys(){return Array.from(this.cache.keys())}cleanup(){let e=Date.now();for(let[t,s]of this.cache.entries())if(e-s.timestamp>s.ttl)this.cache.delete(t)}destroy(){this.stopCleanup(),this.clear(),this.resetStats()}}var it=new G;function he(){if("FORCE_COLOR"in C.env)return C.env.FORCE_COLOR!=="0";if("NO_COLOR"in C.env||C.env.TERM==="dumb")return!1;if(C.platform==="win32")return!0;return W.isatty(1)&&W.isatty(2)}var K=he();function p(e,t){if(!K)return(s)=>s;return(s)=>e+s+t}var me=p("\x1B[0m","\x1B[0m"),de=p("\x1B[31m","\x1B[39m"),fe=p("\x1B[32m","\x1B[39m"),pe=p("\x1B[33m","\x1B[39m"),ge=p("\x1B[34m","\x1B[39m"),$e=p("\x1B[35m","\x1B[39m"),ve=p("\x1B[36m","\x1B[39m"),we=p("\x1B[37m","\x1B[39m"),ye=p("\x1B[90m","\x1B[39m"),be=p("\x1B[1m","\x1B[22m"),xe=p("\x1B[3m","\x1B[23m"),Ce=p("\x1B[4m","\x1B[24m"),Se=p("\x1B[2m","\x1B[22m"),_e=p("\x1B[7m","\x1B[27m"),Ie=p("\x1B[8m","\x1B[28m"),Oe=p("\x1B[9m","\x1B[29m"),Ee=p("\x1B[41m","\x1B[49m"),Be=p("\x1B[42m","\x1B[49m"),Te=p("\x1B[43m","\x1B[49m"),ke=p("\x1B[44m","\x1B[49m"),Ve=p("\x1B[45m","\x1B[49m"),Me=p("\x1B[46m","\x1B[49m"),Ae=p("\x1B[47m","\x1B[49m"),Ne=K,Re={reset:me,red:de,green:fe,yellow:pe,blue:ge,magenta:$e,cyan:ve,white:we,gray:ye,bold:be,italic:xe,underline:Ce,dim:Se,inverse:_e,hidden:Ie,strikethrough:Oe,bgRed:Ee,bgGreen:Be,bgYellow:Te,bgBlue:ke,bgMagenta:Ve,bgCyan:Me,bgWhite:Ae,isColorSupported:Ne},je=Re,De=["up","down","left","right","space","enter","cancel"],ut={actions:new Set(De),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"}};var ct=Le.platform.startsWith("win"),ht=Symbol("clapp:cancel");var We=ie();var f=(e,t)=>We?e:t,mt=f("\u25C6","*"),dt=f("\u25A0","x"),ft=f("\u25B2","x"),pt=f("\u25C7","o"),gt=f("\u250C","T"),Pe=f("\u2502","|"),$t=f("\u2514","\u2014"),vt=f("\u25CF",">"),wt=f("\u25CB"," "),yt=f("\u25FB","[\u2022]"),bt=f("\u25FC","[+]"),xt=f("\u25FB","[ ]"),Ct=f("\u25AA","\u2022"),St=f("\u2500","-"),_t=f("\u256E","+"),It=f("\u251C","+"),Ot=f("\u256F","+"),Et=f("\u25CF","\u2022"),Bt=f("\u25C6","*"),Tt=f("\u25B2","!"),kt=f("\u25A0","x");var Vt={light:f("\u2500","-"),heavy:f("\u2501","="),block:f("\u2588","#")};function Fe(){return`${je.gray(Pe)} `}var Mt=Fe();export{ce as CLI};
|