@jerryc05/hi-tools 0.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jerryc05
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Installation
2
+ ```sh
3
+ pnpm add -g https://github.com/jerryc05/hi-tools.git
4
+ ```
5
+
6
+ # Help
7
+ ```
8
+ hi/0.0.2-beta.13
9
+
10
+ Usage:
11
+ $ hi
12
+
13
+ Commands:
14
+ upgrade Upgrade to latest version (default using pnpm)
15
+ mm [M]erge [M]aster: Update local master to remote's, then merge into current branch
16
+ mmm [M]erge [M]aster (don't [M]odify local master): Merge remote's master into current branch, without updating local master
17
+ tschk My ts-check rules
18
+ wup [W]ait for pkg publish, [U]pdate target repo, and [P]ush
19
+ ips Show current machine's IP addrs
20
+ mdns Show mdns hostname.local
21
+ bm <target> [B]ranch [M]erge: merge current HEAD into target branch without switching
22
+ tt-npm-pub <repoID> [PUB]lish current hash of current repo to Luban
23
+ tt-bam Update BAM code-gen
24
+ tt-gecko Show gecko info by bits URL
25
+ tt-i18n I18n scan and sort
26
+ Print help message
27
+
28
+ For more info, run any command with the `--help` flag:
29
+ $ hi upgrade --help
30
+ $ hi mm --help
31
+ $ hi mmm --help
32
+ $ hi tschk --help
33
+ $ hi wup --help
34
+ $ hi ips --help
35
+ $ hi mdns --help
36
+ $ hi bm --help
37
+ $ hi tt-npm-pub --help
38
+ $ hi tt-bam --help
39
+ $ hi tt-gecko --help
40
+ $ hi tt-i18n --help
41
+ $ hi --help
42
+
43
+ Options:
44
+ --quiet Silently quit
45
+ -v, --version Display version number
46
+ -h, --help Display this message
47
+ ```
package/bin/cli.mjs ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ import module from 'node:module';
4
+
5
+ // https://nodejs.org/api/module.html#module-compile-cache
6
+ if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
7
+ try {
8
+ module.enableCompileCache();
9
+ } catch {
10
+ // Ignore errors
11
+ }
12
+ }
13
+
14
+ await import('../dist/index.js')
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ var V=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});typeof globalThis.CustomEvent>"u"&&(globalThis.CustomEvent=class extends Event{constructor(t,n={}){super(t,n),this.detail=n.detail}});import{readFile as ae,writeFile as ce}from"node:fs/promises";import{tmpdir as me}from"node:os";import{join as pe}from"node:path";var l={name:"@jerryc05/hi-tools",version:"0.0.3",scripts:{build:"node build.js",prepare:"husky"},publishConfig:{registry:"https://npm.pkg.github.com"},repository:{type:"git",url:"git+https://github.com/jerryc05/hi-tools.git"},bin:{hi:"bin/cli.mjs"},files:["bin","dist/*.js"],dependencies:{"@byted/aipaas-auth":"^0.1.0",cac:"^7.0.0",execa:"^9.6.1",picocolors:"^1.1.1",qrcode:"^1.5.4"},devDependencies:{"@types/cli-progress":"^3.11.6","@types/node":"^25.6.0","@types/qrcode":"^1.5.6","cli-progress":"^3.12.0",esbuild:"^0.28.0","fast-glob":"^3.3.3",husky:"^9.1.7","p-map":"^7.0.4",trash:"^10.1.1","xxhash-wasm":"^1.1.0"},type:"module"};var C=[{cmd:{name:"bm <target>",desc:"[B]ranch [M]erge: merge current HEAD into target branch without switching"},action:async e=>{throw console.log(`\u{1F680} Starting silent merge: HEAD -> ${e}`),new Error("Not implemeted!")}}];import{networkInterfaces as W}from"node:os";var $=[{cmd:{name:"ips",desc:"Show current machine's IP addrs"},options:[{name:"-4, --onlyIpv4",desc:"IPv4 only"},{name:"-6, --onlyIpv6",desc:"IPv6 only"}],action:({onlyIpv4:e,onlyIpv6:t})=>{let n=W(),r={};for(let[o,i]of Object.entries(n))i=i?.filter(c=>e?c.family==="IPv4":t?c.family==="IPv6":!0),i?.length&&(r[o]=i.map(c=>c.address));console.log(r)}}];async function Q({repoID:e,hash:t,branch:n}){let r="SCM_USERNAME",o="SCM_PASSWORD",i=process.env[r],c=process.env[o];(!i||!c)&&(console.log(`Missing ${i?o:r} in env var.
3
+ Go to https://luban.bytedance.net/npm/publish and get your personal SCM username + password.`),process.exit(1));let{execa:m}=await import("execa");try{let s=m`git log -1 --pretty=%s`,p,d;n?n===!0?d=(await m`git branch --show-current`).stdout.trim():d=n:t&&(t===!0?p=(await m`git rev-parse HEAD`).stdout.trim():p=t);let f={repos:e,create_user:i,pub_base:p?"commit_base":"branch_base",base_commit_hash:p??"",branch_name:d??"",desc:`[${l?.version}] ${(await s).stdout.trim()}`,has_version_stage:!1};console.log(`\u2139\uFE0F ${f.create_user} is publishing ${l?.name}@${l?.version} to repoID=${f.repos}
4
+ ${p?`hash=${p}`:`brch=${d}`}
5
+ desc=${f.desc}`);let h=await fetch("https://scm.byted.org/api/v2/npm_versions/",{method:"POST",headers:{Authorization:`Basic ${Buffer.from(`${i}:${c}`).toString("base64")}`,Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(f)});if(!h.ok){let _=await h.text();console.log(`\u274C HTTP ${h.status} Error: ${_}`),process.exit(1)}let x=await h.json();console.log("\u{1F389} Successfully published:",x)}catch(s){console.error("\u274C Execution Failed:",s),process.exit(1)}}var I=[{cmd:{name:"tt-npm-pub <repoID>",desc:"[PUB]lish current hash of current repo to Luban"},options:[{name:"--hash [hash]",desc:"Publish pkg by hash (default)"},{name:"-b, --branch [branch]",desc:"Publish pkg by branch"}],action:Q}];import{hostname as X}from"node:os";var k=[{cmd:{name:"mdns",desc:"Show mdns hostname.local"},action:()=>{let e=X();console.log(e.toLowerCase().endsWith(".local")?e:`${e}.local`)}}];import a from"picocolors";var u=e=>console.log(a.underline(a.blue(`\u23F3 ${e}`))),P=()=>console.log(a.bold(a.underline(a.green("\u{1F389} DONE!")))),v=e=>console.log(a.underline(`
6
+ \u274C ${a.bold(a.bgRed(e))}`)),S=e=>console.log(a.bold(a.underline(a.green(`\u2705 ${e}`)))),y=e=>console.log(a.underline(a.yellow(`\u2139\uFE0F ${e}`))),H=e=>console.log(a.bold(a.underline(a.green(`\u{1F44B} ${e}`))));async function E(){let{execa:e}=await import("execa");try{let{stdout:t}=await e`git rev-parse --abbrev-ref --symbolic-full-name @{u}`;return t.split("/")[0]||"origin"}catch{return"origin"}}async function j(e){u(`${e?"Updating":"Fetching"} master...`);let{execa:t}=await import("execa");await t({stdio:"inherit",env:{GIT_TRACE:"1"}})`git fetch ${await E()} master${e?":master":""}`,u("Merging ..."),await t({stdio:"inherit",env:{GIT_TRACE:"1"}})`git merge ${await E()}/master --no-verify --no-edit`,P()}var T=[{cmd:{name:"mm",desc:"[M]erge [M]aster: Update local master to remote's, then merge into current branch"},action:()=>j(!0)},{cmd:{name:"mmm",desc:"[M]erge [M]aster (don't [M]odify local master): Merge remote's master into current branch, without updating local master"},action:()=>j(!1)}];var D=[{cmd:{name:"tschk",desc:"My ts-check rules"},action:async()=>{u("Running custom tsc type-check...");let e=["2322","2339","2551","6133","6192","18048"],{execa:t}=await import("execa");try{let{stdout:n}=await t({reject:!1,stderr:"ignore"})`npx tsc --noEmit --emitDeclarationOnly false`,r=n.split(`
7
+ `).filter(o=>{if(o.includes("/node_modules/"))return!1;let i=o.match(/error TS(\d+):/);return!(!i?.[1]||e.includes(i[1]))});r.length>0?(r.map(o=>console.log(o)),v("Type-check failed!"),process.exit(1)):S("Type-check passed!")}catch(n){v("Type-check: Unexpected err:"),console.error(n),process.exit(1)}}}];var R=[{cmd:{name:"tt-bam",desc:"Update BAM code-gen"},action:async()=>{let{execa:e}=await import("execa");await e({stdio:"inherit"})`pnpm dlx @byted-arch-fe/bam-code-generator update`}}];import{cac as Z}from"cac";var g=Z("hi");function b(e){return new Intl.DateTimeFormat("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"short"}).format(e)}var w;async function A(){if(u("Logging in..."),!w){let{AIPaaSAuth:n}=await import("@byted/aipaas-auth");w=new n("cn")}let e=await w.getJwt(),t=await w.getUserInfo();return H(`Hi ${t.username} from ${t.scope} ${t.work_country}`),y(` Login will expire on ${b(new Date(t.exp*1e3))}`),{jwtStr:e,jwtObj:t}}var Y="https://bits.bytedance.net";function ee(e){let t=/\bpipelineId=(\d+)\b/,n=e.match(t);return n?.[1]?n[1]:null}async function te(e,t,n){let r=`${Y}/api/v1/pipelines/runs?pipelineId=${e}&pageSize=1&pageNum=1`,o=await fetch(r,{method:"GET",headers:{"Content-Type":"application/json","X-jwt-token":t,username:n}});if(!o.ok)throw new Error(`\u83B7\u53D6\u8FD0\u884C\u5217\u8868\u5931\u8D25: ${o.status} ${o.statusText}
8
+ ${await o.text()}`);let i=await o.json();if(i.count<=0)throw new Error(`\u63A5\u53E3\u8FD4\u56DE\u5F02\u5E38: count <= 0
9
+ ${JSON.stringify(i,null,1)}`);return i.pipelineRuns.flatMap(m=>m.jobs.map(s=>{try{let p=JSON.parse(s.jobAtom.output?.GECKO_packageInfo??""),{qrCodeScheme:d,region:f,candidatePackage:h,channel:x,updatedAt:_,creator:J,distributeRule:G}=p.package,{scmVersion:B}=h,q=b(new Date(Number.parseInt(_,10)*1e3)),F=G.envLaneList.flatMap(K=>K.values);return{qrCodeScheme:d,region:f,scmVersion:B,channel:x,updatedDate:q,creator:J,envs:F}}catch{return null}}).filter(s=>!!s)).filter(m=>!!m)}async function oe({pipelineId:e,url:t,region:n}){let{jwtStr:r,jwtObj:o}=await A(),i=e;if(!i){let s=ee(t);if(!s)throw new Error("Unable to extract [pipelineId] from URL");i=s}let c=(await te(i,r,o.username)).filter(s=>s?.region.includes(n)),{default:m}=await import("qrcode");for(let s=0;s<c.length;s++){let p=c[s];try{let d=await m.toString(p?.qrCodeScheme??"",{type:"terminal",small:!0,errorCorrectionLevel:"L"});console.log(`
10
+
11
+ ${d}`),console.dir(p),s<c.length-1&&console.log(`
12
+
13
+ -----------------
14
+
15
+ `)}catch(d){console.error("Failed to generate QR:",d)}}}var U=[{cmd:{name:"tt-gecko",desc:"Show gecko info by bits URL"},options:[{name:"-p,--pipelineId <pipelineId>",desc:"Pipeline ID (Overrides URL)"},{name:"-u,--url <url>",desc:"Bits URL"},{name:"-r,--region <region>",desc:"Region kw filter"}],examples:[`${g.name} tt-gecko -r us -u 'https://bits.bytedance.net/devops/201134696450/develop/detail/2276839/flow?devops_space_type=server_fe&pipelineId=1139212901634&stage=dev_gatekeeper_stage'`],action:oe}];import{access as ne,constants as ie}from"node:fs/promises";var O=[{cmd:{name:"tt-i18n",desc:"I18n scan and sort"},action:async()=>{let e="starling.config.js",t="combine-lang.js";for(let o of[e,t])try{await ne(o,ie.R_OK)}catch(i){console.error(`tt i18n: Failed to read ${o}
16
+ `,i),process.exit(1)}let{execa:n,execaNode:r}=await import("execa");await n({stdio:"inherit"})`pnpm dlx @ies/starling-cli scan -c ${e} --fallback --disable-browser`,await r({stdio:"inherit"})`${e}`,await n({stdio:"inherit"})`pnpm --package=json-sort-cli dlx sortjson ./src/lang`.catch(o=>console.error("tt i18n sortjson error:",o))}}];var L=[...R,...U,...O];async function re({npm:e,global:t}){let{execa:n}=await import("execa");await n({stdio:"inherit"})`${e?"npm":"pnpm"} add ${t?"-g":""} https://github.com/jerryc05/hi-tools.git`}var M=[{cmd:{name:"upgrade",desc:"Upgrade to latest version (default using pnpm)"},options:[{name:"--npm",desc:"Use npm instead of default"},{name:"-g,--global",desc:"Pass -g flag to pkg mgr"}],action:re}];var se=e=>new Promise(t=>setTimeout(t,e)),N=[{cmd:{name:"wup",desc:"[W]ait for pkg publish, [U]pdate target repo, and [P]ush"},options:[{name:"-t, --target <path>",desc:"Target repository path"},{name:"-c, --cmdPrefix <prefix>",desc:"Pkg install command prefix",config:{default:"pnpm add"}},{name:"--timeout <limit>",desc:"Timeout limit in seconds",config:{default:300}}],examples:[`${g.name} wup -t "/tmp/otherRepoPath" -c "emo add"`,`${g.name} wup -t "/tmp/otherRepoPath" -c "rush add --make-consistent -p"`],action:async({target:e,cmdPrefix:t,timeout:n})=>{l||(console.log("\u274C Unable to parse package.json!"),process.exit(1)),e||(console.log("\u274C Missing target repo path"),process.exit(1));let r=l.version,o=`${l.name}@${r}`,i=1e4,c=[...t.split(" "),o];console.log(`\u{1F680} Monitoring ${o}...`),console.log(`\u{1F4C2} Target: ${e}`),console.log(`\u{1F6E0} Install cmd: ${c.join(" ")}`);let{execa:m}=await import("execa");try{console.log("\u{1F4E5} Pulling latest changes in target repo..."),await m({cwd:e,stdio:"inherit",env:{GIT_TRACE:"1"}})`git pull`;let s=Date.now();for(;;){let{exitCode:p}=await m({reject:!1,stdio:"inherit"})`npm view ${o} version`;if(p===0){console.log(`
17
+ \u2705 v${r} is live! Installing...`);try{await m({cwd:e,stdio:"inherit"})`${c}`,console.log(`
18
+ \u{1F389} [SUCCESS] ${o} installed!`);break}catch{console.log(`
19
+ \u26A0\uFE0F Registry updated but installation failed, retrying...`)}}else process.stdout.write(".");(Date.now()-s)/1e3>=n&&(console.error(`
20
+ \u274C [ERROR] Timed out after ${n}s.`),process.exit(1)),await se(i)}console.log("\u{1F4DD} Committing changes..."),await m({stdio:"inherit"})`git commit -am 'chore: upd ${o}`,console.log("\u{1F4E4} Pushing to remote..."),await m({stdio:"inherit"})`git push`,console.log("\u{1F389} DONE!")}catch(s){console.error(`
21
+ \u274C Task failed:`,s),process.exit(1)}}}];process.argv.includes("--quiet")&&process.exit(0);l&&(console.log(),y(`${l.name} v${l.version}
22
+
23
+ `));var le=[...M,...T,...D,...N,...$,...k,...C,...I,...L];for(let{cmd:e,options:t,examples:n,action:r}of le){let o=g.command(e.name,e.desc);for(let i of t??[])o=o.option(i.name,i.desc,i.config);for(let i of n??[])o=o.example(i);o.action(r)}g.version(l.version).help();g.command("","Print help message").option("--quiet","Silently quit").action(({quiet:e})=>{e||g.outputHelp()});g.parse();async function de(){if(process.env.DISABLE_AUTO_UPDATE==="1")return;let e=pe(me(),".hi-tools___last-upd-check.txt"),t=1800*1e3,n=[],r=Date.now();try{let o=parseInt(await ae(e,"utf-8")||"0",10);if(r-o<t)return}catch{}n.push(ce(e,r.toString()));try{if(process.argv[1]){let{spawn:o}=V("node:child_process");o(process.argv0,[process.argv[1],"-g","upgrade"],{stdio:"ignore",windowsHide:!0}).unref()}}catch{}await Promise.all(n)}de();export{l as PKG_JSON_OBJ};
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@jerryc05/hi-tools",
3
+ "version": "0.0.3",
4
+ "scripts": {
5
+ "pub": "npm publish --access public --registry https://registry.npmjs.org",
6
+ "build": "node build.js",
7
+ "prepare": "husky"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/jerryc05/hi-tools.git"
12
+ },
13
+ "bin": {
14
+ "hi": "bin/cli.mjs"
15
+ },
16
+ "files": [
17
+ "bin",
18
+ "dist/*.js"
19
+ ],
20
+ "dependencies": {
21
+ "@byted/aipaas-auth": "^0.1.0",
22
+ "cac": "^7.0.0",
23
+ "execa": "^9.6.1",
24
+ "picocolors": "^1.1.1",
25
+ "qrcode": "^1.5.4"
26
+ },
27
+ "devDependencies": {
28
+ "@types/cli-progress": "^3.11.6",
29
+ "@types/node": "^25.6.0",
30
+ "@types/qrcode": "^1.5.6",
31
+ "cli-progress": "^3.12.0",
32
+ "esbuild": "^0.28.0",
33
+ "fast-glob": "^3.3.3",
34
+ "husky": "^9.1.7",
35
+ "p-map": "^7.0.4",
36
+ "trash": "^10.1.1",
37
+ "xxhash-wasm": "^1.1.0"
38
+ },
39
+ "type": "module"
40
+ }