@soybeanjs/cli 0.8.2 → 0.8.4

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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- "use strict";const process=require("node:process"),p=require("cac"),path=require("node:path"),node_fs=require("node:fs"),l$1=require("enquirer"),kolorist=require("kolorist"),cryptoJs=require("crypto-js"),rimraf=require("rimraf"),changelog=require("@soybeanjs/changelog"),e$1=require("bumpp"),fs=require("node:fs/promises"),c12=require("c12");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const process__default=_interopDefaultCompat(process),p__default=_interopDefaultCompat(p),path__default=_interopDefaultCompat(path),l__default=_interopDefaultCompat(l$1),e__default=_interopDefaultCompat(e$1),version="0.8.2";var c=Object.defineProperty,a$1=(t,o,i)=>o in t?c(t,o,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[o]=i,n=(t,o,i)=>(a$1(t,typeof o!="symbol"?o+"":o,i),i);async function execCommand(t,o,i){const{execa:s}=await import("execa");return(await s(t,o,i))?.stdout?.trim()||""}class Crypto{constructor(o){n(this,"secret"),this.secret=o}enCrypto(o){const i=JSON.stringify(o);return cryptoJs.AES.encrypt(i,this.secret).toString()}deCrypto(o){const i=cryptoJs.AES.decrypt(o,this.secret).toString(cryptoJs.enc.Utf8);if(i)try{return JSON.parse(i)}catch{return null}return null}}async function gitCommit(t,o){const i=t.map(([u,h])=>{const f=`${`${u}:`.padEnd(12)}${h}`;return{name:u,message:f}}),s=o.map(([u,h])=>({name:u,message:`${u.padEnd(30)} (${h})`})),r=await l__default.prompt([{name:"types",type:"select",message:"Please select a type",choices:i},{name:"scopes",type:"select",message:"Please select a scope",choices:s},{name:"description",type:"text",message:"Please enter a description"}]),g=`${r.types}(${r.scopes}): ${r.description}`;await execCommand("git",["commit","-m",g],{stdio:"inherit"})}async function gitCommitVerify(){const t=await execCommand("git",["rev-parse","--show-toplevel"]),o=path__default.join(t,".git","COMMIT_EDITMSG"),i=node_fs.readFileSync(o,"utf8").trim();if(!/(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i.test(i))throw new Error(`${kolorist.bgRed(" ERROR ")} ${kolorist.red("git commit message must match the Conventional Commits standard!")}
2
+ "use strict";const process=require("node:process"),p=require("cac"),path=require("node:path"),node_fs=require("node:fs"),l$1=require("enquirer"),kolorist=require("kolorist"),cryptoJs=require("crypto-js"),rimraf=require("rimraf"),changelog=require("@soybeanjs/changelog"),e=require("bumpp"),consola=require("consola"),fs=require("node:fs/promises"),c12=require("c12");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const process__default=_interopDefaultCompat(process),p__default=_interopDefaultCompat(p),path__default=_interopDefaultCompat(path),l__default=_interopDefaultCompat(l$1),e__default=_interopDefaultCompat(e),name="@soybeanjs/cli",type="module",version="0.8.4",packageManager="pnpm@8.11.0",description="SoybeanJS's command line tools",author={name:"Soybean",email:"soybeanjs@outlook.com",url:"https://github.com/soybeanjs"},license="MIT",homepage="https://github.com/soybeanjs/cli",repository={url:"https://github.com/soybeanjs/cli.git"},bugs={url:"https://github.com/soybeanjs/cli/issues"},publishConfig={registry:"https://registry.npmjs.org/"},exports$1={".":{types:"./dist/index.d.ts",import:"./dist/index.mjs",require:"./dist/index.cjs"}},main="dist/index.cjs",module$1="dist/index.mjs",types="dist/index.d.ts",bin={soybean:"dist/index.cjs",soy:"dist/index.cjs"},files=["dist"],scripts={stub:"pnpm -r run stub",build:"run-s typecheck build-only build-pkg","build-only":"unbuild","build-pkg":"pnpm -r --filter='./packages/*' run build",lint:"eslint . --fix",commit:"soy git-commit",cleanup:"soy cleanup","update-pkg":"soy ncu",typecheck:"tsc --noEmit --skipLibCheck","publish-pkg":"pnpm -r publish --access public","release-pkg":"soy release",release:"run-s release-pkg build publish-pkg",prepare:"pnpm build-only && simple-git-hooks"},dependencies={"@soybeanjs/changelog":"0.3.4",bumpp:"9.2.0",c12:"1.5.1",cac:"6.7.14",consola:"3.2.3","crypto-js":"4.2.0",enquirer:"2.4.1",execa:"8.0.1",kolorist:"1.8.0",minimist:"1.2.8","npm-check-updates":"16.14.11",rimraf:"5.0.5"},devDependencies={"@soybeanjs/cli":"link:","@soybeanjs/eslint-config":"1.0.5","@types/crypto-js":"4.2.1","@types/node":"20.10.4",eslint:"8.55.0","lint-staged":"15.2.0","npm-run-all":"4.1.5","simple-git-hooks":"2.9.0",tsx:"4.6.2",typescript:"5.3.3",unbuild:"2.0.0"},a$2={name,type,version,packageManager,description,author,license,homepage,repository,bugs,publishConfig,exports:exports$1,main,module:module$1,types,bin,files,scripts,dependencies,devDependencies,"simple-git-hooks":{"commit-msg":"pnpm soy git-commit-verify","pre-commit":"pnpm typecheck && pnpm lint-staged"},"lint-staged":{"*":"eslint --fix"}};var c=Object.defineProperty,a$1=(t,o,s)=>o in t?c(t,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[o]=s,n=(t,o,s)=>(a$1(t,typeof o!="symbol"?o+"":o,s),s);async function execCommand(t,o,s){const{execa:u}=await import("execa");return(await u(t,o,s))?.stdout?.trim()||""}class Crypto{constructor(o){n(this,"secret"),this.secret=o}enCrypto(o){const s=JSON.stringify(o);return cryptoJs.AES.encrypt(s,this.secret).toString()}deCrypto(o){const s=cryptoJs.AES.decrypt(o,this.secret).toString(cryptoJs.enc.Utf8);if(s)try{return JSON.parse(s)}catch{return null}return null}}async function gitCommit(t,o){const s=t.map(([y,h])=>{const w=`${`${y}:`.padEnd(12)}${h}`;return{name:y,message:w}}),u=o.map(([y,h])=>({name:y,message:`${y.padEnd(30)} (${h})`})),f=await l__default.prompt([{name:"types",type:"select",message:"Please select a type",choices:s},{name:"scopes",type:"select",message:"Please select a scope",choices:u},{name:"description",type:"text",message:"Please enter a description"}]),g=`${f.types}(${f.scopes}): ${f.description}`;await execCommand("git",["commit","-m",g],{stdio:"inherit"})}async function gitCommitVerify(){const t=await execCommand("git",["rev-parse","--show-toplevel"]),o=path__default.join(t,".git","COMMIT_EDITMSG"),s=node_fs.readFileSync(o,"utf8").trim();if(!/(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i.test(s))throw new Error(`${kolorist.bgRed(" ERROR ")} ${kolorist.red("git commit message must match the Conventional Commits standard!")}
3
3
 
4
- ${kolorist.green("Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org")}`)}async function cleanup(t){await rimraf.rimraf(t,{glob:!0})}async function initSimpleGitHooks(t=process__default.cwd()){const o=path__default.join(t,".husky"),i=node_fs.existsSync(o),s=path__default.join(t,".git","hooks");i&&(await rimraf.rimraf(o),await execCommand("git",["config","core.hooksPath",s],{stdio:"inherit"})),await rimraf.rimraf(s),await execCommand("npx",["simple-git-hooks"],{stdio:"inherit"})}async function ncu(t=["--deep","-u"]){execCommand("npx",["ncu",...t],{stdio:"inherit"})}async function prettierWrite(t){await execCommand("npx",["prettier","--write",".",...t],{stdio:"inherit"})}async function eslintPrettier(){await execCommand("npx",["eslint",".","--fix"],{stdio:"inherit"}),await execCommand("npx",["soy","prettier-format"],{stdio:"inherit"})}async function execLintStaged(t){const o=(await import("./chunks/index.cjs").then(function(i){return i.index})).default;return o({config:t,allowEmpty:!0})}async function genChangelog(t,o=!1){o?await changelog.generateTotalChangelog(t):await changelog.generateChangelog(t)}async function release(){await e__default({files:["**/package.json","!**/node_modules"],execute:"npx soy changelog",all:!0,tag:!0,commit:"chore(projects): release v%s",push:!0})}const a="*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}",l={cwd:process__default.cwd(),cleanupDirs:["**/dist","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/node_modules","!node_modules/**"],gitCommitTypes:[["feat","A new feature"],["fix","A bug fix"],["docs","Documentation only changes"],["style","Changes that do not affect the meaning of the code"],["refactor","A code change that neither fixes a bug nor adds a feature"],["perf","A code change that improves performance"],["test","Adding missing tests or correcting existing tests"],["build","Changes that affect the build system or external dependencies"],["ci","Changes to our CI configuration files and scripts"],["chore","Other changes that don't modify src or test files"],["revert","Reverts a previous commit"]],gitCommitScopes:[["projects","project"],["components","components"],["hooks","hook functions"],["utils","utils functions"],["types","TS declaration"],["styles","style"],["deps","project dependencies"],["release","release project"],["other","other changes"]],ncuCommandArgs:["--deep","-u"],changelogOptions:{},prettierWriteGlob:[`!**/${a}`,"!*.min.*","!CHANGELOG.md","!dist","!LICENSE*","!output","!coverage","!public","!temp","!package-lock.json","!pnpm-lock.yaml","!yarn.lock","!.github","!__snapshots__","!node_modules"],lintStagedConfig:{[a]:"eslint --fix","*":"soy prettier-write"}},m="U2FsdGVkX18dc7x8PmAq30sl+nyGmi5VJJwninmYBRs8vVILEIjY+kT/F8ajm/6gRTMbDAEmx5WKInQBzeNSig==";async function loadCliOptions(t,o=process__default.cwd()){const{config:i}=await c12.loadConfig({name:"soybean",defaults:l,overrides:t,cwd:o,packageJson:!0}),s=await d(o);if(i&&s){const r=new Crypto("SOYBEAN_JS");i.changelogOptions={...i.changelogOptions,github:{repo:"",token:r.deCrypto(m)||""}}}return i}async function d(t){let o=!1;const i="soybean";try{const s=await fs.readFile(`${t}/package.json`,"utf-8"),r=JSON.parse(s);o=r.name?.includes(i)||r.repository?.url?.includes(i)||r.author?.includes(i)||r.author?.name?.includes(i)||r.author?.url?.includes(i)}catch{}return o}const e="the command is deprecated, it will be removed in the next major version 1.0.0";async function k(){const t=await loadCliOptions(),o=p__default("soybean");o.version(version).option("--total","Generate changelog by total tags").help();const i={cleanup:{desc:"delete dirs: node_modules, dist, etc.",action:async()=>{await cleanup(t.cleanupDirs)}},ncu:{desc:"npm-check-updates, it can update package.json dependencies to the latest version",action:async()=>{await ncu(t.ncuCommandArgs)}},"git-commit":{desc:"git commit, generate commit message which match Conventional Commits standard",action:async()=>{await gitCommit(t.gitCommitTypes,t.gitCommitScopes)}},"git-commit-verify":{desc:"verify git commit message, make sure it match Conventional Commits standard",action:async()=>{await gitCommitVerify()}},changelog:{desc:"generate changelog",action:async s=>{await genChangelog(t.changelogOptions,s?.total)}},release:{desc:"release: update version, generate changelog, commit code",action:async()=>{await release()}},"prettier-write":{desc:`run prettier --write (${e})`,action:async()=>{await prettierWrite(t.prettierWriteGlob)}},"lint-staged":{desc:`run lint-staged (${e})`,action:async()=>{const s=await execLintStaged(t.lintStagedConfig).catch(()=>{process__default.exitCode=1});process__default.exitCode=s?0:1}},"init-simple-git-hooks":{desc:`init simple-git-hooks and remove husky (${e})`,action:async()=>{await initSimpleGitHooks(t.cwd)}},"init-git-hooks":{desc:`same as init-simple-git-hooks (${e})`,action:async()=>{await initSimpleGitHooks(t.cwd)}},"update-pkg":{desc:`same as ncu (${e})`,action:async()=>{await ncu(t.ncuCommandArgs)}},"prettier-format":{desc:`same as prettier-write (${e})`,action:async()=>{await prettierWrite(t.prettierWriteGlob)}},"eslint-prettier":{desc:e,action:async()=>{await eslintPrettier()}}};for await(const[s,{desc:r,action:g}]of Object.entries(i))o.command(s,r).action(g);o.parse()}k();function defineConfig(t){return t}exports.defineConfig=defineConfig;
4
+ ${kolorist.green("Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org")}`)}async function cleanup(t){await rimraf.rimraf(t,{glob:!0})}async function ncu(t=["--deep","-u"]){execCommand("npx",["ncu",...t],{stdio:"inherit"})}async function genChangelog(t,o=!1){o?await changelog.generateTotalChangelog(t):await changelog.generateChangelog(t)}async function release(){await e__default({files:["**/package.json","!**/node_modules"],execute:"npx soy changelog",all:!0,tag:!0,commit:"chore(projects): release v%s",push:!0})}const suspectProtoRx=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,suspectConstructorRx=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,JsonSigRx=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function jsonParseTransform(t,o){if(t==="__proto__"||t==="constructor"&&o&&typeof o=="object"&&"prototype"in o){warnKeyDropped(t);return}return o}function warnKeyDropped(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}function destr(t,o={}){if(typeof t!="string")return t;const s=t.trim();if(t[0]==='"'&&t.at(-1)==='"'&&!t.includes("\\"))return s.slice(1,-1);if(s.length<=9){const u=s.toLowerCase();if(u==="true")return!0;if(u==="false")return!1;if(u==="undefined")return;if(u==="null")return null;if(u==="nan")return Number.NaN;if(u==="infinity")return Number.POSITIVE_INFINITY;if(u==="-infinity")return Number.NEGATIVE_INFINITY}if(!JsonSigRx.test(t)){if(o.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(suspectProtoRx.test(t)||suspectConstructorRx.test(t)){if(o.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,jsonParseTransform)}return JSON.parse(t)}catch(u){if(o.strict)throw u;return t}}const HASH_RE=/#/g,AMPERSAND_RE=/&/g,EQUAL_RE=/=/g,PLUS_RE=/\+/g,ENC_CARET_RE=/%5e/gi,ENC_BACKTICK_RE=/%60/gi,ENC_PIPE_RE=/%7c/gi,ENC_SPACE_RE=/%20/gi;function encode(t){return encodeURI(""+t).replace(ENC_PIPE_RE,"|")}function encodeQueryValue(t){return encode(typeof t=="string"?t:JSON.stringify(t)).replace(PLUS_RE,"%2B").replace(ENC_SPACE_RE,"+").replace(HASH_RE,"%23").replace(AMPERSAND_RE,"%26").replace(ENC_BACKTICK_RE,"`").replace(ENC_CARET_RE,"^")}function encodeQueryKey(t){return encodeQueryValue(t).replace(EQUAL_RE,"%3D")}function decode(t=""){try{return decodeURIComponent(""+t)}catch{return""+t}}function decodeQueryKey(t){return decode(t.replace(PLUS_RE," "))}function decodeQueryValue(t){return decode(t.replace(PLUS_RE," "))}function parseQuery(t=""){const o={};t[0]==="?"&&(t=t.slice(1));for(const s of t.split("&")){const u=s.match(/([^=]+)=?(.*)/)||[];if(u.length<2)continue;const f=decodeQueryKey(u[1]);if(f==="__proto__"||f==="constructor")continue;const g=decodeQueryValue(u[2]||"");o[f]===void 0?o[f]=g:Array.isArray(o[f])?o[f].push(g):o[f]=[o[f],g]}return o}function encodeQueryItem(t,o){return(typeof o=="number"||typeof o=="boolean")&&(o=String(o)),o?Array.isArray(o)?o.map(s=>`${encodeQueryKey(t)}=${encodeQueryValue(s)}`).join("&"):`${encodeQueryKey(t)}=${encodeQueryValue(o)}`:encodeQueryKey(t)}function stringifyQuery(t){return Object.keys(t).filter(o=>t[o]!==void 0).map(o=>encodeQueryItem(o,t[o])).filter(Boolean).join("&")}const PROTOCOL_STRICT_REGEX=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,PROTOCOL_REGEX=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,PROTOCOL_RELATIVE_REGEX=/^([/\\]\s*){2,}[^/\\]/;function hasProtocol(t,o={}){return typeof o=="boolean"&&(o={acceptRelative:o}),o.strict?PROTOCOL_STRICT_REGEX.test(t):PROTOCOL_REGEX.test(t)||(o.acceptRelative?PROTOCOL_RELATIVE_REGEX.test(t):!1)}const TRAILING_SLASH_RE=/\/$|\/\?|\/#/;function hasTrailingSlash(t="",o){return o?TRAILING_SLASH_RE.test(t):t.endsWith("/")}function withoutTrailingSlash(t="",o){if(!o)return(hasTrailingSlash(t)?t.slice(0,-1):t)||"/";if(!hasTrailingSlash(t,!0))return t||"/";let s=t,u="";const f=t.indexOf("#");f>=0&&(s=t.slice(0,f),u=t.slice(f));const[g,...y]=s.split("?");return(g.slice(0,-1)||"/")+(y.length>0?`?${y.join("?")}`:"")+u}function withTrailingSlash(t="",o){if(!o)return t.endsWith("/")?t:t+"/";if(hasTrailingSlash(t,!0))return t||"/";let s=t,u="";const f=t.indexOf("#");if(f>=0&&(s=t.slice(0,f),u=t.slice(f),!s))return u;const[g,...y]=s.split("?");return g+"/"+(y.length>0?`?${y.join("?")}`:"")+u}function withBase(t,o){if(isEmptyURL(o)||hasProtocol(t))return t;const s=withoutTrailingSlash(o);return t.startsWith(s)?t:joinURL(s,t)}function withQuery(t,o){const s=parseURL(t),u={...parseQuery(s.search),...o};return s.search=stringifyQuery(u),stringifyParsedURL(s)}function isEmptyURL(t){return!t||t==="/"}function isNonEmptyURL(t){return t&&t!=="/"}const JOIN_LEADING_SLASH_RE=/^\.?\//;function joinURL(t,...o){let s=t||"";for(const u of o.filter(f=>isNonEmptyURL(f)))if(s){const f=u.replace(JOIN_LEADING_SLASH_RE,"");s=withTrailingSlash(s)+f}else s=u;return s}function parseURL(t="",o){const s=t.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(s){const[,C,b=""]=s;return{protocol:C.toLowerCase(),pathname:b,href:C+b,auth:"",host:"",search:"",hash:""}}if(!hasProtocol(t,{acceptRelative:!0}))return o?parseURL(o+t):parsePath(t);const[,u="",f,g=""]=t.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[],[,y="",h=""]=g.match(/([^#/?]*)(.*)?/)||[],{pathname:w,search:_,hash:r}=parsePath(h.replace(/\/(?=[A-Za-z]:)/,""));return{protocol:u.toLowerCase(),auth:f?f.slice(0,Math.max(0,f.length-1)):"",host:y,pathname:w,search:_,hash:r}}function parsePath(t=""){const[o="",s="",u=""]=(t.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:o,search:s,hash:u}}function stringifyParsedURL(t){const o=t.pathname||"",s=t.search?(t.search.startsWith("?")?"":"?")+t.search:"",u=t.hash||"",f=t.auth?t.auth+"@":"",g=t.host||"";return(t.protocol?t.protocol+"//":"")+f+g+o+s+u}var __defProp=Object.defineProperty,__defNormalProp=(t,o,s)=>o in t?__defProp(t,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[o]=s,__publicField=(t,o,s)=>(__defNormalProp(t,typeof o!="symbol"?o+"":o,s),s);class FetchError extends Error{constructor(){super(...arguments),__publicField(this,"name","FetchError"),__publicField(this,"request"),__publicField(this,"response"),__publicField(this,"data"),__publicField(this,"status"),__publicField(this,"statusText"),__publicField(this,"statusCode"),__publicField(this,"statusMessage")}}function createFetchError(t,o,s){let u="";o&&(u=o.message),t&&s?u=`${u} (${s.status} ${s.statusText} (${t.toString()}))`:t&&(u=`${u} (${t.toString()})`);const f=new FetchError(u);return Object.defineProperty(f,"request",{get(){return t}}),Object.defineProperty(f,"response",{get(){return s}}),Object.defineProperty(f,"data",{get(){return s&&s._data}}),Object.defineProperty(f,"status",{get(){return s&&s.status}}),Object.defineProperty(f,"statusText",{get(){return s&&s.statusText}}),Object.defineProperty(f,"statusCode",{get(){return s&&s.status}}),Object.defineProperty(f,"statusMessage",{get(){return s&&s.statusText}}),f}const payloadMethods=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function isPayloadMethod(t="GET"){return payloadMethods.has(t.toUpperCase())}function isJSONSerializable(t){if(t===void 0)return!1;const o=typeof t;return o==="string"||o==="number"||o==="boolean"||o===null?!0:o!=="object"?!1:Array.isArray(t)?!0:t.constructor&&t.constructor.name==="Object"||typeof t.toJSON=="function"}const textTypes=new Set(["image/svg","application/xml","application/xhtml","application/html"]),JSON_RE=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function detectResponseType(t=""){if(!t)return"json";const o=t.split(";").shift()||"";return JSON_RE.test(o)?"json":textTypes.has(o)||o.startsWith("text/")?"text":"blob"}function mergeFetchOptions(t,o,s=globalThis.Headers){const u={...o,...t};if(o?.params&&t?.params&&(u.params={...o?.params,...t?.params}),o?.query&&t?.query&&(u.query={...o?.query,...t?.query}),o?.headers&&t?.headers){u.headers=new s(o?.headers||{});for(const[f,g]of new s(t?.headers||{}))u.headers.set(f,g)}return u}const retryStatusCodes=new Set([408,409,425,429,500,502,503,504]);function createFetch(t={}){const{fetch:o=globalThis.fetch,Headers:s=globalThis.Headers,AbortController:u=globalThis.AbortController}=t;async function f(h){const w=h.error&&h.error.name==="AbortError"&&!h.options.timeout||!1;if(h.options.retry!==!1&&!w){let r;typeof h.options.retry=="number"?r=h.options.retry:r=isPayloadMethod(h.options.method)?0:1;const C=h.response&&h.response.status||500;if(r>0&&retryStatusCodes.has(C)){const b=h.options.retryDelay||0;return b>0&&await new Promise(E=>setTimeout(E,b)),g(h.request,{...h.options,retry:r-1,timeout:h.options.timeout})}}const _=createFetchError(h.request,h.error,h.response);throw Error.captureStackTrace&&Error.captureStackTrace(_,g),_}const g=async function(w,_={}){const r={request:w,options:mergeFetchOptions(_,t.defaults,s),response:void 0,error:void 0};if(r.options.method=r.options.method?.toUpperCase(),r.options.onRequest&&await r.options.onRequest(r),typeof r.request=="string"&&(r.options.baseURL&&(r.request=withBase(r.request,r.options.baseURL)),(r.options.query||r.options.params)&&(r.request=withQuery(r.request,{...r.options.params,...r.options.query})),r.options.body&&isPayloadMethod(r.options.method)&&isJSONSerializable(r.options.body)&&(r.options.body=typeof r.options.body=="string"?r.options.body:JSON.stringify(r.options.body),r.options.headers=new s(r.options.headers||{}),r.options.headers.has("content-type")||r.options.headers.set("content-type","application/json"),r.options.headers.has("accept")||r.options.headers.set("accept","application/json"))),!r.options.signal&&r.options.timeout){const b=new u;setTimeout(()=>b.abort(),r.options.timeout),r.options.signal=b.signal}try{r.response=await o(r.request,r.options)}catch(b){return r.error=b,r.options.onRequestError&&await r.options.onRequestError(r),await f(r)}const C=(r.options.parseResponse?"json":r.options.responseType)||detectResponseType(r.response.headers.get("content-type")||"");if(C==="json"){const b=await r.response.text(),E=r.options.parseResponse||destr;r.response._data=E(b)}else C==="stream"?r.response._data=r.response.body:r.response._data=await r.response[C]();return r.options.onResponse&&await r.options.onResponse(r),!r.options.ignoreResponseError&&r.response.status>=400&&r.response.status<600?(r.options.onResponseError&&await r.options.onResponseError(r),await f(r)):r.response},y=async function(w,_){return(await g(w,_))._data};return y.raw=g,y.native=o,y.create=(h={})=>createFetch({...t,defaults:{...t.defaults,...h}}),y}const _globalThis=function(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;throw new Error("unable to locate global object")}(),fetch=_globalThis.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),Headers=_globalThis.Headers,AbortController=_globalThis.AbortController,ofetch=createFetch({fetch,Headers,AbortController});async function syncNpmmirror(t=a$2.name,o=!0){const s=`https://registry-direct.npmmirror.com/${t}/sync?sync_upstream=true`,{logId:u=""}=await ofetch(s,{method:"PUT"});if(!u)return;const f=`https://registry.npmmirror.com/-/package/${t}/syncs/${u}/log`,g=`Sync ${t} success`;let y="",h=setInterval(async()=>{try{y=await ofetch(f,{method:"GET"}),o&&consola.consola.log(y),y.includes(g)&&h&&(clearInterval(h),h=null)}catch{}},2e3)}async function execLintStaged(t){const o=(await import("./chunks/index.cjs").then(function(s){return s.index})).default;return o({config:t,allowEmpty:!0})}async function initSimpleGitHooks(t=process__default.cwd()){const o=path__default.join(t,".husky"),s=node_fs.existsSync(o),u=path__default.join(t,".git","hooks");s&&(await rimraf.rimraf(o),await execCommand("git",["config","core.hooksPath",u],{stdio:"inherit"})),await rimraf.rimraf(u),await execCommand("npx",["simple-git-hooks"],{stdio:"inherit"})}async function prettierWrite(t){await execCommand("npx",["prettier","--write",".",...t],{stdio:"inherit"})}async function eslintPrettier(){await execCommand("npx",["eslint",".","--fix"],{stdio:"inherit"}),await execCommand("npx",["soy","prettier-format"],{stdio:"inherit"})}const a="*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}",l={cwd:process__default.cwd(),cleanupDirs:["**/dist","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/node_modules","!node_modules/**"],gitCommitTypes:[["feat","A new feature"],["fix","A bug fix"],["docs","Documentation only changes"],["style","Changes that do not affect the meaning of the code"],["refactor","A code change that neither fixes a bug nor adds a feature"],["perf","A code change that improves performance"],["test","Adding missing tests or correcting existing tests"],["build","Changes that affect the build system or external dependencies"],["ci","Changes to our CI configuration files and scripts"],["chore","Other changes that don't modify src or test files"],["revert","Reverts a previous commit"]],gitCommitScopes:[["projects","project"],["components","components"],["hooks","hook functions"],["utils","utils functions"],["types","TS declaration"],["styles","style"],["deps","project dependencies"],["release","release project"],["other","other changes"]],ncuCommandArgs:["--deep","-u"],changelogOptions:{},prettierWriteGlob:[`!**/${a}`,"!*.min.*","!CHANGELOG.md","!dist","!LICENSE*","!output","!coverage","!public","!temp","!package-lock.json","!pnpm-lock.yaml","!yarn.lock","!.github","!__snapshots__","!node_modules"],lintStagedConfig:{[a]:"eslint --fix","*":"soy prettier-write"}},m="U2FsdGVkX18dc7x8PmAq30sl+nyGmi5VJJwninmYBRs8vVILEIjY+kT/F8ajm/6gRTMbDAEmx5WKInQBzeNSig==";async function loadCliOptions(t,o=process__default.cwd()){const{config:s}=await c12.loadConfig({name:"soybean",defaults:l,overrides:t,cwd:o,packageJson:!0}),u=await d(o);if(s&&u){const f=new Crypto("SOYBEAN_JS");s.changelogOptions={...s.changelogOptions,github:{repo:"",token:f.deCrypto(m)||""}}}return s}async function d(t){let o=!1;const s="soybean";try{const u=await fs.readFile(`${t}/package.json`,"utf-8"),f=JSON.parse(u);o=f.name?.includes(s)||f.repository?.url?.includes(s)||f.author?.includes(s)||f.author?.name?.includes(s)||f.author?.url?.includes(s)}catch{}return o}const i="the command is deprecated, it will be removed in the next major version 1.0.0";async function A(){const t=await loadCliOptions(),o=p__default("soybean");o.version(version).option("--total","Generate changelog by total tags").help();const s={cleanup:{desc:"delete dirs: node_modules, dist, etc.",action:async()=>{await cleanup(t.cleanupDirs)}},ncu:{desc:"npm-check-updates, it can update package.json dependencies to the latest version",action:async()=>{await ncu(t.ncuCommandArgs)}},"git-commit":{desc:"git commit, generate commit message which match Conventional Commits standard",action:async()=>{await gitCommit(t.gitCommitTypes,t.gitCommitScopes)}},"git-commit-verify":{desc:"verify git commit message, make sure it match Conventional Commits standard",action:async()=>{await gitCommitVerify()}},changelog:{desc:"generate changelog",action:async u=>{await genChangelog(t.changelogOptions,u?.total)}},release:{desc:"release: update version, generate changelog, commit code",action:async()=>{await release()}},"sync-npmmirror":{desc:"sync npmmirror",action:async u=>{await syncNpmmirror(u?.syncName,u?.syncLog)}},"prettier-write":{desc:`run prettier --write (${i})`,action:async()=>{await prettierWrite(t.prettierWriteGlob)}},"lint-staged":{desc:`run lint-staged (${i})`,action:async()=>{const u=await execLintStaged(t.lintStagedConfig).catch(()=>{process__default.exitCode=1});process__default.exitCode=u?0:1}},"init-simple-git-hooks":{desc:`init simple-git-hooks and remove husky (${i})`,action:async()=>{await initSimpleGitHooks(t.cwd)}},"init-git-hooks":{desc:`same as init-simple-git-hooks (${i})`,action:async()=>{await initSimpleGitHooks(t.cwd)}},"update-pkg":{desc:`same as ncu (${i})`,action:async()=>{await ncu(t.ncuCommandArgs)}},"prettier-format":{desc:`same as prettier-write (${i})`,action:async()=>{await prettierWrite(t.prettierWriteGlob)}},"eslint-prettier":{desc:i,action:async()=>{await eslintPrettier()}}};for await(const[u,{desc:f,action:g}]of Object.entries(s))o.command(u,f).action(g);o.parse()}A();function defineConfig(t){return t}exports.defineConfig=defineConfig;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import r from"node:process";import C from"cac";import d from"node:path";import{readFileSync as k,existsSync as v}from"node:fs";import b from"enquirer";import{bgRed as x,red as j,green as $}from"kolorist";import{AES as g,enc as S}from"crypto-js";import{rimraf as l}from"rimraf";import{generateTotalChangelog as O,generateChangelog as A}from"@soybeanjs/changelog";import E from"bumpp";import{readFile as G}from"node:fs/promises";import{loadConfig as _}from"c12";const R="0.8.2";var T=Object.defineProperty,I=(e,t,n)=>t in e?T(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,J=(e,t,n)=>(I(e,typeof t!="symbol"?t+"":t,n),n);async function a(e,t,n){const{execa:i}=await import("execa");return(await i(e,t,n))?.stdout?.trim()||""}class N{constructor(t){J(this,"secret"),this.secret=t}enCrypto(t){const n=JSON.stringify(t);return g.encrypt(n,this.secret).toString()}deCrypto(t){const n=g.decrypt(t,this.secret).toString(S.Utf8);if(n)try{return JSON.parse(n)}catch{return null}return null}}async function P(e,t){const n=e.map(([c,p])=>{const w=`${`${c}:`.padEnd(12)}${p}`;return{name:c,message:w}}),i=t.map(([c,p])=>({name:c,message:`${c.padEnd(30)} (${p})`})),o=await b.prompt([{name:"types",type:"select",message:"Please select a type",choices:n},{name:"scopes",type:"select",message:"Please select a scope",choices:i},{name:"description",type:"text",message:"Please enter a description"}]),m=`${o.types}(${o.scopes}): ${o.description}`;await a("git",["commit","-m",m],{stdio:"inherit"})}async function D(){const e=await a("git",["rev-parse","--show-toplevel"]),t=d.join(e,".git","COMMIT_EDITMSG"),n=k(t,"utf8").trim();if(!/(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i.test(n))throw new Error(`${x(" ERROR ")} ${j("git commit message must match the Conventional Commits standard!")}
2
+ import g from"node:process";import F from"cac";import b from"node:path";import{readFileSync as G,existsSync as J}from"node:fs";import U from"enquirer";import{bgRed as D,red as M,green as H}from"kolorist";import{AES as S,enc as Q}from"crypto-js";import{rimraf as w}from"rimraf";import{generateTotalChangelog as W,generateChangelog as V}from"@soybeanjs/changelog";import B from"bumpp";import{consola as K}from"consola";import{readFile as z}from"node:fs/promises";import{loadConfig as Y}from"c12";const X="@soybeanjs/cli",Z="module",T="0.8.4",tt="pnpm@8.11.0",et="SoybeanJS's command line tools",ot={name:"Soybean",email:"soybeanjs@outlook.com",url:"https://github.com/soybeanjs"},nt="MIT",st="https://github.com/soybeanjs/cli",rt={url:"https://github.com/soybeanjs/cli.git"},it={url:"https://github.com/soybeanjs/cli/issues"},at={registry:"https://registry.npmjs.org/"},ct={".":{types:"./dist/index.d.ts",import:"./dist/index.mjs",require:"./dist/index.cjs"}},pt="dist/index.cjs",ut="dist/index.mjs",lt="dist/index.d.ts",mt={soybean:"dist/index.cjs",soy:"dist/index.cjs"},dt=["dist"],ft={stub:"pnpm -r run stub",build:"run-s typecheck build-only build-pkg","build-only":"unbuild","build-pkg":"pnpm -r --filter='./packages/*' run build",lint:"eslint . --fix",commit:"soy git-commit",cleanup:"soy cleanup","update-pkg":"soy ncu",typecheck:"tsc --noEmit --skipLibCheck","publish-pkg":"pnpm -r publish --access public","release-pkg":"soy release",release:"run-s release-pkg build publish-pkg",prepare:"pnpm build-only && simple-git-hooks"},ht={"@soybeanjs/changelog":"0.3.4",bumpp:"9.2.0",c12:"1.5.1",cac:"6.7.14",consola:"3.2.3","crypto-js":"4.2.0",enquirer:"2.4.1",execa:"8.0.1",kolorist:"1.8.0",minimist:"1.2.8","npm-check-updates":"16.14.11",rimraf:"5.0.5"},gt={"@soybeanjs/cli":"link:","@soybeanjs/eslint-config":"1.0.5","@types/crypto-js":"4.2.1","@types/node":"20.10.4",eslint:"8.55.0","lint-staged":"15.2.0","npm-run-all":"4.1.5","simple-git-hooks":"2.9.0",tsx:"4.6.2",typescript:"5.3.3",unbuild:"2.0.0"},yt={name:X,type:Z,version:T,packageManager:tt,description:et,author:ot,license:nt,homepage:st,repository:rt,bugs:it,publishConfig:at,exports:ct,main:pt,module:ut,types:lt,bin:mt,files:dt,scripts:ft,dependencies:ht,devDependencies:gt,"simple-git-hooks":{"commit-msg":"pnpm soy git-commit-verify","pre-commit":"pnpm typecheck && pnpm lint-staged"},"lint-staged":{"*":"eslint --fix"}};var bt=Object.defineProperty,wt=(t,e,o)=>e in t?bt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,Et=(t,e,o)=>(wt(t,typeof e!="symbol"?e+"":e,o),o);async function d(t,e,o){const{execa:s}=await import("execa");return(await s(t,e,o))?.stdout?.trim()||""}class Ct{constructor(e){Et(this,"secret"),this.secret=e}enCrypto(e){const o=JSON.stringify(e);return S.encrypt(o,this.secret).toString()}deCrypto(e){const o=S.decrypt(e,this.secret).toString(Q.Utf8);if(o)try{return JSON.parse(o)}catch{return null}return null}}async function jt(t,e){const o=t.map(([c,i])=>{const u=`${`${c}:`.padEnd(12)}${i}`;return{name:c,message:u}}),s=e.map(([c,i])=>({name:c,message:`${c.padEnd(30)} (${i})`})),r=await U.prompt([{name:"types",type:"select",message:"Please select a type",choices:o},{name:"scopes",type:"select",message:"Please select a scope",choices:s},{name:"description",type:"text",message:"Please enter a description"}]),a=`${r.types}(${r.scopes}): ${r.description}`;await d("git",["commit","-m",a],{stdio:"inherit"})}async function _t(){const t=await d("git",["rev-parse","--show-toplevel"]),e=b.join(t,".git","COMMIT_EDITMSG"),o=G(e,"utf8").trim();if(!/(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i.test(o))throw new Error(`${D(" ERROR ")} ${M("git commit message must match the Conventional Commits standard!")}
3
3
 
4
- ${$("Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org")}`)}async function W(e){await l(e,{glob:!0})}async function u(e=r.cwd()){const t=d.join(e,".husky"),n=v(t),i=d.join(e,".git","hooks");n&&(await l(t),await a("git",["config","core.hooksPath",i],{stdio:"inherit"})),await l(i),await a("npx",["simple-git-hooks"],{stdio:"inherit"})}async function h(e=["--deep","-u"]){a("npx",["ncu",...e],{stdio:"inherit"})}async function f(e){await a("npx",["prettier","--write",".",...e],{stdio:"inherit"})}async function F(){await a("npx",["eslint",".","--fix"],{stdio:"inherit"}),await a("npx",["soy","prettier-format"],{stdio:"inherit"})}async function L(e){const t=(await import("./chunks/index.mjs").then(function(n){return n.i})).default;return t({config:e,allowEmpty:!0})}async function M(e,t=!1){t?await O(e):await A(e)}async function V(){await E({files:["**/package.json","!**/node_modules"],execute:"npx soy changelog",all:!0,tag:!0,commit:"chore(projects): release v%s",push:!0})}const y="*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}",B={cwd:r.cwd(),cleanupDirs:["**/dist","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/node_modules","!node_modules/**"],gitCommitTypes:[["feat","A new feature"],["fix","A bug fix"],["docs","Documentation only changes"],["style","Changes that do not affect the meaning of the code"],["refactor","A code change that neither fixes a bug nor adds a feature"],["perf","A code change that improves performance"],["test","Adding missing tests or correcting existing tests"],["build","Changes that affect the build system or external dependencies"],["ci","Changes to our CI configuration files and scripts"],["chore","Other changes that don't modify src or test files"],["revert","Reverts a previous commit"]],gitCommitScopes:[["projects","project"],["components","components"],["hooks","hook functions"],["utils","utils functions"],["types","TS declaration"],["styles","style"],["deps","project dependencies"],["release","release project"],["other","other changes"]],ncuCommandArgs:["--deep","-u"],changelogOptions:{},prettierWriteGlob:[`!**/${y}`,"!*.min.*","!CHANGELOG.md","!dist","!LICENSE*","!output","!coverage","!public","!temp","!package-lock.json","!pnpm-lock.yaml","!yarn.lock","!.github","!__snapshots__","!node_modules"],lintStagedConfig:{[y]:"eslint --fix","*":"soy prettier-write"}},Y="U2FsdGVkX18dc7x8PmAq30sl+nyGmi5VJJwninmYBRs8vVILEIjY+kT/F8ajm/6gRTMbDAEmx5WKInQBzeNSig==";async function z(e,t=r.cwd()){const{config:n}=await _({name:"soybean",defaults:B,overrides:e,cwd:t,packageJson:!0}),i=await H(t);if(n&&i){const o=new N("SOYBEAN_JS");n.changelogOptions={...n.changelogOptions,github:{repo:"",token:o.deCrypto(Y)||""}}}return n}async function H(e){let t=!1;const n="soybean";try{const i=await G(`${e}/package.json`,"utf-8"),o=JSON.parse(i);t=o.name?.includes(n)||o.repository?.url?.includes(n)||o.author?.includes(n)||o.author?.name?.includes(n)||o.author?.url?.includes(n)}catch{}return t}const s="the command is deprecated, it will be removed in the next major version 1.0.0";async function U(){const e=await z(),t=C("soybean");t.version(R).option("--total","Generate changelog by total tags").help();const n={cleanup:{desc:"delete dirs: node_modules, dist, etc.",action:async()=>{await W(e.cleanupDirs)}},ncu:{desc:"npm-check-updates, it can update package.json dependencies to the latest version",action:async()=>{await h(e.ncuCommandArgs)}},"git-commit":{desc:"git commit, generate commit message which match Conventional Commits standard",action:async()=>{await P(e.gitCommitTypes,e.gitCommitScopes)}},"git-commit-verify":{desc:"verify git commit message, make sure it match Conventional Commits standard",action:async()=>{await D()}},changelog:{desc:"generate changelog",action:async i=>{await M(e.changelogOptions,i?.total)}},release:{desc:"release: update version, generate changelog, commit code",action:async()=>{await V()}},"prettier-write":{desc:`run prettier --write (${s})`,action:async()=>{await f(e.prettierWriteGlob)}},"lint-staged":{desc:`run lint-staged (${s})`,action:async()=>{const i=await L(e.lintStagedConfig).catch(()=>{r.exitCode=1});r.exitCode=i?0:1}},"init-simple-git-hooks":{desc:`init simple-git-hooks and remove husky (${s})`,action:async()=>{await u(e.cwd)}},"init-git-hooks":{desc:`same as init-simple-git-hooks (${s})`,action:async()=>{await u(e.cwd)}},"update-pkg":{desc:`same as ncu (${s})`,action:async()=>{await h(e.ncuCommandArgs)}},"prettier-format":{desc:`same as prettier-write (${s})`,action:async()=>{await f(e.prettierWriteGlob)}},"eslint-prettier":{desc:s,action:async()=>{await F()}}};for await(const[i,{desc:o,action:m}]of Object.entries(n))t.command(i,o).action(m);t.parse()}U();function q(e){return e}export{q as defineConfig};
4
+ ${H("Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org")}`)}async function Rt(t){await w(t,{glob:!0})}async function k(t=["--deep","-u"]){d("npx",["ncu",...t],{stdio:"inherit"})}async function St(t,e=!1){e?await W(t):await V(t)}async function Tt(){await B({files:["**/package.json","!**/node_modules"],execute:"npx soy changelog",all:!0,tag:!0,commit:"chore(projects): release v%s",push:!0})}const kt=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,xt=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,$t=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function Ot(t,e){if(t==="__proto__"||t==="constructor"&&e&&typeof e=="object"&&"prototype"in e){At(t);return}return e}function At(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}function Pt(t,e={}){if(typeof t!="string")return t;const o=t.trim();if(t[0]==='"'&&t.at(-1)==='"'&&!t.includes("\\"))return o.slice(1,-1);if(o.length<=9){const s=o.toLowerCase();if(s==="true")return!0;if(s==="false")return!1;if(s==="undefined")return;if(s==="null")return null;if(s==="nan")return Number.NaN;if(s==="infinity")return Number.POSITIVE_INFINITY;if(s==="-infinity")return Number.NEGATIVE_INFINITY}if(!$t.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(kt.test(t)||xt.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,Ot)}return JSON.parse(t)}catch(s){if(e.strict)throw s;return t}}const Nt=/#/g,It=/&/g,vt=/=/g,E=/\+/g,Lt=/%5e/gi,qt=/%60/gi,Ft=/%7c/gi,Gt=/%20/gi;function Jt(t){return encodeURI(""+t).replace(Ft,"|")}function C(t){return Jt(typeof t=="string"?t:JSON.stringify(t)).replace(E,"%2B").replace(Gt,"+").replace(Nt,"%23").replace(It,"%26").replace(qt,"`").replace(Lt,"^")}function j(t){return C(t).replace(vt,"%3D")}function x(t=""){try{return decodeURIComponent(""+t)}catch{return""+t}}function Ut(t){return x(t.replace(E," "))}function Dt(t){return x(t.replace(E," "))}function Mt(t=""){const e={};t[0]==="?"&&(t=t.slice(1));for(const o of t.split("&")){const s=o.match(/([^=]+)=?(.*)/)||[];if(s.length<2)continue;const r=Ut(s[1]);if(r==="__proto__"||r==="constructor")continue;const a=Dt(s[2]||"");e[r]===void 0?e[r]=a:Array.isArray(e[r])?e[r].push(a):e[r]=[e[r],a]}return e}function Ht(t,e){return(typeof e=="number"||typeof e=="boolean")&&(e=String(e)),e?Array.isArray(e)?e.map(o=>`${j(t)}=${C(o)}`).join("&"):`${j(t)}=${C(e)}`:j(t)}function Qt(t){return Object.keys(t).filter(e=>t[e]!==void 0).map(e=>Ht(e,t[e])).filter(Boolean).join("&")}const Wt=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Vt=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,Bt=/^([/\\]\s*){2,}[^/\\]/;function $(t,e={}){return typeof e=="boolean"&&(e={acceptRelative:e}),e.strict?Wt.test(t):Vt.test(t)||(e.acceptRelative?Bt.test(t):!1)}const Kt=/\/$|\/\?|\/#/;function _(t="",e){return e?Kt.test(t):t.endsWith("/")}function zt(t="",e){if(!e)return(_(t)?t.slice(0,-1):t)||"/";if(!_(t,!0))return t||"/";let o=t,s="";const r=t.indexOf("#");r>=0&&(o=t.slice(0,r),s=t.slice(r));const[a,...c]=o.split("?");return(a.slice(0,-1)||"/")+(c.length>0?`?${c.join("?")}`:"")+s}function Yt(t="",e){if(!e)return t.endsWith("/")?t:t+"/";if(_(t,!0))return t||"/";let o=t,s="";const r=t.indexOf("#");if(r>=0&&(o=t.slice(0,r),s=t.slice(r),!o))return s;const[a,...c]=o.split("?");return a+"/"+(c.length>0?`?${c.join("?")}`:"")+s}function Xt(t,e){if(te(e)||$(t))return t;const o=zt(e);return t.startsWith(o)?t:ne(o,t)}function Zt(t,e){const o=O(t),s={...Mt(o.search),...e};return o.search=Qt(s),se(o)}function te(t){return!t||t==="/"}function ee(t){return t&&t!=="/"}const oe=/^\.?\//;function ne(t,...e){let o=t||"";for(const s of e.filter(r=>ee(r)))if(o){const r=s.replace(oe,"");o=Yt(o)+r}else o=s;return o}function O(t="",e){const o=t.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(o){const[,m,p=""]=o;return{protocol:m.toLowerCase(),pathname:p,href:m+p,auth:"",host:"",search:"",hash:""}}if(!$(t,{acceptRelative:!0}))return e?O(e+t):A(t);const[,s="",r,a=""]=t.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[],[,c="",i=""]=a.match(/([^#/?]*)(.*)?/)||[],{pathname:u,search:l,hash:n}=A(i.replace(/\/(?=[A-Za-z]:)/,""));return{protocol:s.toLowerCase(),auth:r?r.slice(0,Math.max(0,r.length-1)):"",host:c,pathname:u,search:l,hash:n}}function A(t=""){const[e="",o="",s=""]=(t.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:e,search:o,hash:s}}function se(t){const e=t.pathname||"",o=t.search?(t.search.startsWith("?")?"":"?")+t.search:"",s=t.hash||"",r=t.auth?t.auth+"@":"",a=t.host||"";return(t.protocol?t.protocol+"//":"")+r+a+e+o+s}var re=Object.defineProperty,ie=(t,e,o)=>e in t?re(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,f=(t,e,o)=>(ie(t,typeof e!="symbol"?e+"":e,o),o);class ae extends Error{constructor(){super(...arguments),f(this,"name","FetchError"),f(this,"request"),f(this,"response"),f(this,"data"),f(this,"status"),f(this,"statusText"),f(this,"statusCode"),f(this,"statusMessage")}}function ce(t,e,o){let s="";e&&(s=e.message),t&&o?s=`${s} (${o.status} ${o.statusText} (${t.toString()}))`:t&&(s=`${s} (${t.toString()})`);const r=new ae(s);return Object.defineProperty(r,"request",{get(){return t}}),Object.defineProperty(r,"response",{get(){return o}}),Object.defineProperty(r,"data",{get(){return o&&o._data}}),Object.defineProperty(r,"status",{get(){return o&&o.status}}),Object.defineProperty(r,"statusText",{get(){return o&&o.statusText}}),Object.defineProperty(r,"statusCode",{get(){return o&&o.status}}),Object.defineProperty(r,"statusMessage",{get(){return o&&o.statusText}}),r}const pe=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function P(t="GET"){return pe.has(t.toUpperCase())}function ue(t){if(t===void 0)return!1;const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(t)?!0:t.constructor&&t.constructor.name==="Object"||typeof t.toJSON=="function"}const le=new Set(["image/svg","application/xml","application/xhtml","application/html"]),me=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function de(t=""){if(!t)return"json";const e=t.split(";").shift()||"";return me.test(e)?"json":le.has(e)||e.startsWith("text/")?"text":"blob"}function fe(t,e,o=globalThis.Headers){const s={...e,...t};if(e?.params&&t?.params&&(s.params={...e?.params,...t?.params}),e?.query&&t?.query&&(s.query={...e?.query,...t?.query}),e?.headers&&t?.headers){s.headers=new o(e?.headers||{});for(const[r,a]of new o(t?.headers||{}))s.headers.set(r,a)}return s}const he=new Set([408,409,425,429,500,502,503,504]);function N(t={}){const{fetch:e=globalThis.fetch,Headers:o=globalThis.Headers,AbortController:s=globalThis.AbortController}=t;async function r(i){const u=i.error&&i.error.name==="AbortError"&&!i.options.timeout||!1;if(i.options.retry!==!1&&!u){let n;typeof i.options.retry=="number"?n=i.options.retry:n=P(i.options.method)?0:1;const m=i.response&&i.response.status||500;if(n>0&&he.has(m)){const p=i.options.retryDelay||0;return p>0&&await new Promise(y=>setTimeout(y,p)),a(i.request,{...i.options,retry:n-1,timeout:i.options.timeout})}}const l=ce(i.request,i.error,i.response);throw Error.captureStackTrace&&Error.captureStackTrace(l,a),l}const a=async function(u,l={}){const n={request:u,options:fe(l,t.defaults,o),response:void 0,error:void 0};if(n.options.method=n.options.method?.toUpperCase(),n.options.onRequest&&await n.options.onRequest(n),typeof n.request=="string"&&(n.options.baseURL&&(n.request=Xt(n.request,n.options.baseURL)),(n.options.query||n.options.params)&&(n.request=Zt(n.request,{...n.options.params,...n.options.query})),n.options.body&&P(n.options.method)&&ue(n.options.body)&&(n.options.body=typeof n.options.body=="string"?n.options.body:JSON.stringify(n.options.body),n.options.headers=new o(n.options.headers||{}),n.options.headers.has("content-type")||n.options.headers.set("content-type","application/json"),n.options.headers.has("accept")||n.options.headers.set("accept","application/json"))),!n.options.signal&&n.options.timeout){const p=new s;setTimeout(()=>p.abort(),n.options.timeout),n.options.signal=p.signal}try{n.response=await e(n.request,n.options)}catch(p){return n.error=p,n.options.onRequestError&&await n.options.onRequestError(n),await r(n)}const m=(n.options.parseResponse?"json":n.options.responseType)||de(n.response.headers.get("content-type")||"");if(m==="json"){const p=await n.response.text(),y=n.options.parseResponse||Pt;n.response._data=y(p)}else m==="stream"?n.response._data=n.response.body:n.response._data=await n.response[m]();return n.options.onResponse&&await n.options.onResponse(n),!n.options.ignoreResponseError&&n.response.status>=400&&n.response.status<600?(n.options.onResponseError&&await n.options.onResponseError(n),await r(n)):n.response},c=async function(u,l){return(await a(u,l))._data};return c.raw=a,c.native=e,c.create=(i={})=>N({...t,defaults:{...t.defaults,...i}}),c}const R=function(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;throw new Error("unable to locate global object")}(),ge=R.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),ye=R.Headers,be=R.AbortController,I=N({fetch:ge,Headers:ye,AbortController:be});async function we(t=yt.name,e=!0){const o=`https://registry-direct.npmmirror.com/${t}/sync?sync_upstream=true`,{logId:s=""}=await I(o,{method:"PUT"});if(!s)return;const r=`https://registry.npmmirror.com/-/package/${t}/syncs/${s}/log`,a=`Sync ${t} success`;let c="",i=setInterval(async()=>{try{c=await I(r,{method:"GET"}),e&&K.log(c),c.includes(a)&&i&&(clearInterval(i),i=null)}catch{}},2e3)}async function Ee(t){const e=(await import("./chunks/index.mjs").then(function(o){return o.i})).default;return e({config:t,allowEmpty:!0})}async function v(t=g.cwd()){const e=b.join(t,".husky"),o=J(e),s=b.join(t,".git","hooks");o&&(await w(e),await d("git",["config","core.hooksPath",s],{stdio:"inherit"})),await w(s),await d("npx",["simple-git-hooks"],{stdio:"inherit"})}async function L(t){await d("npx",["prettier","--write",".",...t],{stdio:"inherit"})}async function Ce(){await d("npx",["eslint",".","--fix"],{stdio:"inherit"}),await d("npx",["soy","prettier-format"],{stdio:"inherit"})}const q="*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}",je={cwd:g.cwd(),cleanupDirs:["**/dist","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/node_modules","!node_modules/**"],gitCommitTypes:[["feat","A new feature"],["fix","A bug fix"],["docs","Documentation only changes"],["style","Changes that do not affect the meaning of the code"],["refactor","A code change that neither fixes a bug nor adds a feature"],["perf","A code change that improves performance"],["test","Adding missing tests or correcting existing tests"],["build","Changes that affect the build system or external dependencies"],["ci","Changes to our CI configuration files and scripts"],["chore","Other changes that don't modify src or test files"],["revert","Reverts a previous commit"]],gitCommitScopes:[["projects","project"],["components","components"],["hooks","hook functions"],["utils","utils functions"],["types","TS declaration"],["styles","style"],["deps","project dependencies"],["release","release project"],["other","other changes"]],ncuCommandArgs:["--deep","-u"],changelogOptions:{},prettierWriteGlob:[`!**/${q}`,"!*.min.*","!CHANGELOG.md","!dist","!LICENSE*","!output","!coverage","!public","!temp","!package-lock.json","!pnpm-lock.yaml","!yarn.lock","!.github","!__snapshots__","!node_modules"],lintStagedConfig:{[q]:"eslint --fix","*":"soy prettier-write"}},_e="U2FsdGVkX18dc7x8PmAq30sl+nyGmi5VJJwninmYBRs8vVILEIjY+kT/F8ajm/6gRTMbDAEmx5WKInQBzeNSig==";async function Re(t,e=g.cwd()){const{config:o}=await Y({name:"soybean",defaults:je,overrides:t,cwd:e,packageJson:!0}),s=await Se(e);if(o&&s){const r=new Ct("SOYBEAN_JS");o.changelogOptions={...o.changelogOptions,github:{repo:"",token:r.deCrypto(_e)||""}}}return o}async function Se(t){let e=!1;const o="soybean";try{const s=await z(`${t}/package.json`,"utf-8"),r=JSON.parse(s);e=r.name?.includes(o)||r.repository?.url?.includes(o)||r.author?.includes(o)||r.author?.name?.includes(o)||r.author?.url?.includes(o)}catch{}return e}const h="the command is deprecated, it will be removed in the next major version 1.0.0";async function Te(){const t=await Re(),e=F("soybean");e.version(T).option("--total","Generate changelog by total tags").help();const o={cleanup:{desc:"delete dirs: node_modules, dist, etc.",action:async()=>{await Rt(t.cleanupDirs)}},ncu:{desc:"npm-check-updates, it can update package.json dependencies to the latest version",action:async()=>{await k(t.ncuCommandArgs)}},"git-commit":{desc:"git commit, generate commit message which match Conventional Commits standard",action:async()=>{await jt(t.gitCommitTypes,t.gitCommitScopes)}},"git-commit-verify":{desc:"verify git commit message, make sure it match Conventional Commits standard",action:async()=>{await _t()}},changelog:{desc:"generate changelog",action:async s=>{await St(t.changelogOptions,s?.total)}},release:{desc:"release: update version, generate changelog, commit code",action:async()=>{await Tt()}},"sync-npmmirror":{desc:"sync npmmirror",action:async s=>{await we(s?.syncName,s?.syncLog)}},"prettier-write":{desc:`run prettier --write (${h})`,action:async()=>{await L(t.prettierWriteGlob)}},"lint-staged":{desc:`run lint-staged (${h})`,action:async()=>{const s=await Ee(t.lintStagedConfig).catch(()=>{g.exitCode=1});g.exitCode=s?0:1}},"init-simple-git-hooks":{desc:`init simple-git-hooks and remove husky (${h})`,action:async()=>{await v(t.cwd)}},"init-git-hooks":{desc:`same as init-simple-git-hooks (${h})`,action:async()=>{await v(t.cwd)}},"update-pkg":{desc:`same as ncu (${h})`,action:async()=>{await k(t.ncuCommandArgs)}},"prettier-format":{desc:`same as prettier-write (${h})`,action:async()=>{await L(t.prettierWriteGlob)}},"eslint-prettier":{desc:h,action:async()=>{await Ce()}}};for await(const[s,{desc:r,action:a}]of Object.entries(o))e.command(s,r).action(a);e.parse()}Te();function ke(t){return t}export{ke as defineConfig};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soybeanjs/cli",
3
3
  "type": "module",
4
- "version": "0.8.2",
4
+ "version": "0.8.4",
5
5
  "packageManager": "pnpm@8.11.0",
6
6
  "description": "SoybeanJS's command line tools",
7
7
  "author": {