@r5n/sisyphus 0.0.1-rc.0 → 0.2.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +22 -1
- package/package.json +6 -4
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,23 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{blue as St,bold as d,cyanBright as j,dim as P,green as jt,italic as w,magenta as Mt,underline as G,whiteBright as Ct,yellow as z}from"picocolors";var q="0.2.0-rc.1";function D(e){let t=[];switch(e){case"init":t=[Ct(`Initialises Sisyphus with config, by creating ${w(".sisyphus/config.json")} file in the root of the workspace.`),"",d("Flags:"),p("--single",`Initialises config in a single package mode. Sisyphus will work for root ${P(w("package.json"))} file only`),p("--overwrite",["Overrides existing config.","It will remove existing one and creates new one with default values or given options"]),p("--tag","Initialises config with a specific tag"),p("--ignore",`Array of packages to ignore. Can be used as array: ${G(w("bunx @r5n/sisyphus init -i pkg1 -i pkg2"))}`),"",d("Examples:"),$("Usual monorepo setup with multiple packages","init",""),$("Single package setup","init","--single"),$("Setup with a specific tag","init","--tag v1.0.0"),$("Setup with ignored packages","init","-i pkg1 -i pkg2")];break;case"version":{t=["Generates a stone from interactive mode. It will ask you about version bump, release message, changelog generation etc.","",d("Flags:"),p("--bump",["Predefined semantic version of bump for selected packages.",`Available types: ${G(w("major, minor, patch"))}. ${d(w(`Can't be used with ${j("--snapshot")} option`))}`]),p("--tag","Version tag for release. Given string will be used as a tagged version for selected packages"),p("--filter","Sisyphus will only update packages that match the given filter"),p("--snapshot",[`Create a snapshot release with version of given tag and timestamp. ${d(w(`Can't be used with ${j("--bump")} option`))}`,"Useful for creating a release from a specific point in time for analysis, debugging or nightly builds"]),p("--yes","Sisyphus will not ask for confirmation before creating a stone"),"",d("Examples:"),$("Base usage","version",""),$("Generate stone with predefined version bump","version","--bump major"),$("Generate stone with snapshot release","version","--snapshot"),$("Confirm stone creation automatically","version","--yes")];break}case"roll":{t=["Creates a release from a specific point in time. It's based on stones created by Sisyphus.","With proper flags it will publish to NPM, create a release on GitHub, generate a changelog and more.","",d("Flags:"),p("--changelog","Creates a changelog from a specific point in time"),p(["-r","--changelogRoot"],"Creates a combined changelog for the monorepo. Useful for release notes."),p("--npm","Publishes packages to NPM"),p("--github","Creates a release on GitHub. Can be configured via `github` in config."),p(["-t","--withTags"],"Creates git tags for release"),p(["","--rootTag"],"Creates a tag of given string. Useful for creating a release from a specific point in time."),p(["","--npmToken"],["NPM token to use for publishing.",`By default it's read from ${d(w("NPM_TOKEN"))} environment variable`]),p(["","--githubToken"],["GitHub token to use for creating a release & tags.",`By default it's read from ${d(w("GITHUB_TOKEN"))} environment variable`]),p("--dryRun","Roll will not make any changes, it will only show what it would do"),"",d("Examples:"),$("Base usage of roll command to generate tags, changelog and npm release","roll","-n -c -t"),$("Generate changelog on release","roll","--changelog"),$("Creates release and publish packages to NPM","roll","--npm"),$("Enables GitHub release creation","roll","--github"),$("Creates release with git tags per package","roll","--withTags"),$("Creates release with a specific tag","roll","--rootTag v1.0.0"),$("Roll with dry run to check for changes","roll","--dryRun")];break}default:t=["",w(P(`Run ${G(w("bunx @r5n/sisyphus <command> --help"))} for more info on command usage`)),"",d("Commands:"),N("help","Show this help information"),N("init","Initialise Sisyphus config"),N("roll","Release packages, tags, changelogs etc. based on generated stones"),N("version","Create stone from interactive mode"),""]}console.info(`
|
|
3
|
+
${Mt(`${d("Sisyphus ")}${G(w(`v${q}`))}`)}
|
|
4
|
+
|
|
5
|
+
Usage: bunx @r5n/sisyphus ${z(w(e&&!e.includes("help")?`${e} ${j("[...flags]")}`:"<command>"))}
|
|
6
|
+
${t.join("\n ")}
|
|
7
|
+
${P("Any issues & ideas can be reported at https://github.com/r5n-labs/Typescript-Monorepo/issues/new/choose")}
|
|
8
|
+
`)}function $(e,t,i){return` ${P(e)}
|
|
9
|
+
${jt("bunx @r5n/sisyphus")}${z(` ${t} `)}${j(i)}
|
|
10
|
+
`}function p(e,t,i=40){const[o,n]=Array.isArray(e)?e:[e.slice(1,3),e],s=j(d(`${o?`${o}, `:""}${n}`)),a=Array.isArray(t)?t.map((r,l)=>`${j(d("")).padEnd(l===0?0:i+4," ")}${P(r)}`).join("\n"):P(t);return` ${s.padEnd(i," ")}${a}`}function N(e,t,i=32){return` ${St(d(e)).padEnd(i," ")}${P(t)}`}import{parseArgs as Ft}from"util";import{note as Ht}from"@clack/prompts";import{green as Ot,reset as Dt}from"picocolors";import{mkdirSync as Y,readdirSync as _t,rmdirSync as Gt}from"fs";import{cancel as Nt,note as Rt}from"@clack/prompts";var{Glob:At}=globalThis.Bun;import{bold as Et,green as V,italic as xt,yellow as Ut}from"picocolors";function C(e){if(typeof e==="function")e();else Nt(e||"Operation cancelled by user");process.exit(0)}async function k({overwrite:e,tag:t,...i}={}){const n=await Bun.file("./.sisyphus/config.json").exists(),s=n&&e;if(!n||s){const a=Bun.spawnSync(["git","rev-parse","HEAD"]).stdout.toString().trim();if(a.length===0)throw new Error("Couldn't find git repository. Have you initialized git repository?");if(s)Gt(".sisyphus",{recursive:!0});const r={...i,tag:t||"latest",lastStone:{commit:a,date:new Date().toISOString().split(".")[0]||""},ignore:[],stones:[]};Y(".sisyphus"),await Bun.write(".sisyphus/config.json",`${JSON.stringify(r,null,2)}\n`)}return Bun.file(".sisyphus/config.json").json()}async function X({dryRun:e,...t}){const i=await k();if(e)console.info(`${Et(Ut("[dry-run]"))}
|
|
11
|
+
${xt(".sisyphus/config.json")} would be updated to
|
|
12
|
+
${JSON.stringify({...i,...t},null,2)}`);else await Bun.write(".sisyphus/config.json",`${JSON.stringify({...i,...t},null,2)}\n`),Rt(`${V("Sisyphus config updated!")}`)}function E({name:e,version:t,bump:i,tag:o}){return`${e}@${t} => ${V(_({version:t,bump:i,tag:o}))} ${A[i]}`}function Z(e){const t=e.map((o)=>J.indexOf(o)),i=Math.max(...t);return J[i]||"patch"}function _({version:e="",bump:t,tag:i}){const[o="0.0.0",n=""]=e.split("-"),[s="0",a="0",r="0"]=o.split("."),[l="",u="0"]=n.split(".");if(t==="snapshot"){const f=new Date().toISOString().replaceAll(/[.ZT:-]/g,"").slice(0,14);return`0.0.0-${i||"nightly"}-${f}`}if(i||t==="dependency"&&l)return`${o}-${i||l}.${Number.parseInt(u)+1}`;const c=t==="major"?`${s}.0.0`:t==="minor"?`${s}.${a}.0`:`${s}.${a}.${r}`;if(l&&o===c)return c;switch(t){case"major":return`${Number.parseInt(s)+1}.0.0`;case"minor":return`${s}.${Number.parseInt(a)+1}.0`;case"patch":return`${s}.${a}.${Number.parseInt(r)+1}`;default:return e}}function x(){try{return _t(".sisyphus/stones").map((e)=>e.replace(".md",""))}catch{return Y(".sisyphus/stones"),[]}}async function U({filter:e,single:t}){const i=process.cwd(),o={};let n=[];try{n=(await Bun.file("package.json").json())?.workspaces||[]}catch(r){throw new Error("Couldn't find package.json for this project.",{cause:r})}if(!t&&n.length===0)throw new Error(`Seems like package.json doesn't have \`workspaces\` field or it's empty. Are you sure you are in the root of the workspace? (cwd: ${i})\n
|
|
13
|
+
If you want to run Sisyphus in single package, use --single flag or set \`"single": true\` in .sisyphus/config.json.`);const s={};for(let r of n){const l=new At(`${r}/package.json`).scanSync({cwd:i});for(let u of l){const{name:c,version:f,dependencies:h,devDependencies:m}=await Bun.file(u).json(),v=Object.entries({...h??{},...m??{}}).map(([g,y])=>y.startsWith("workspace")?g:"").filter(Boolean);for(let g of v)if(s[g]||=[],!s[g].includes(c))s[g].push(c);o[c]={name:c,version:f,file:u,dependencyOf:[]}}}for(let[r,l]of Object.entries(s))if(o[r])o[r].dependencyOf=l;const a=Object.keys(o);return{packages:o,packageNames:e?a.filter((r)=>r.includes(e)):a}}var R="#@!",M="***",J=["dependency","patch","minor","major","snapshot"],A={dependency:"\uD83D\uDCE6",patch:"\uD83D\uDC1B",minor:"\u2728",major:"\uD83D\uDEA8",snapshot:"\uD83D\uDCF8"};async function T(){const{values:{overwrite:e,tag:t,single:i,ignore:o}}=Ft({allowPositionals:!0,args:Bun.argv,strict:!0,options:{single:{default:!1,type:"boolean",short:"s"},ignore:{default:[],type:"string",short:"i",multiple:!0},overwrite:{default:!1,type:"boolean",short:"o"},tag:{default:"latest",type:"string",short:"t"}}}),n=await k({single:i,ignore:o,overwrite:e,tag:t});console.info(n),Ht(Dt(Ot("Sisyphus is setup to roll stones.")))}import{rmSync as Vt}from"fs";import{parseArgs as Xt}from"util";import{note as Zt}from"@clack/prompts";import{bold as ct,green as Tt,redBright as te,reset as lt,yellow as gt}from"picocolors";import{bold as tt,yellow as et}from"picocolors";async function nt({changelogRoot:e,commit:t,dryRun:i=!1,stones:o}){const n=[""],{lastStone:{commit:s=""}}=await k(),a=Kt({stones:o});for(let[r,{bump:l,path:u,changelog:c}]of a.entries()){const f=[`# ${r}`,"",...c,ot({lastCommit:s,commit:t})];if(i)console.info(`${tt(et("[dry-run]"))}\n${f.join("\n")}`);else await Bun.write(u,f.join("\n"));const[h="",,,m=""]=c;if(!n.includes(m))n.unshift(m);n.push(`### ${A[l]} ${r}@${h.slice(7)}`)}if(e){const r=Bun.file("CHANGELOG.md"),l=await r.exists(),[u,...c]=l?(await r.text()).split("\n"):["# Changelog"],f=[u,"",...n,...c,ot({root:!0,lastCommit:s,commit:t}),M,""];if(i)console.info(`${tt(et("[dry-run]"))}\nRoot changelog:\n${f.join("\n")}`);else await Bun.write(r,f.join("\n"))}}function Kt({stones:e}){const t=new Map;for(let{tag:i,packages:o,message:n}of e)for(let{file:s,name:a,version:r,bump:l}of o){const u=_({version:r,tag:i,bump:l}),{bump:c,path:f,changelog:h}=t.get(a)??{path:s.replace("package.json","CHANGELOG.md"),changelog:[],bump:l},[m="",,,b=""]=h,v=[m.replace("### ","")||"0.0.0",u].sort(Bun.semver.order)[1],g=[`### ${A[l]} ${v}`,"",h.length>0?"__Stones:__":"__Stone:__",`_${n}${b?`, ${b.replaceAll("_","")}_`:"_"}`];t.set(a,{bump:c,path:f,changelog:g})}return t}function ot({root:e,lastCommit:t,commit:i}){const o=Bun.spawnSync(["git","log",`--pretty=format:%H${R}%s${R}%cn`,`${t}..${i}`]).stdout.toString().split("\n").map((n)=>{if(n.length===0)return;const[s,a,r]=n.split(R);return{hash:s,message:a,author:r}}).filter(Boolean);return`
|
|
14
|
+
<details><summary>${o.length} ${e?"Commits in this release":"Commits since last stone"}:</summary>
|
|
15
|
+
|
|
16
|
+
${o.map(({hash:n,message:s,author:a})=>`- ${n} ${s} (by @${a})`).join("\n")}
|
|
17
|
+
|
|
18
|
+
</details>
|
|
19
|
+
`}import{note as Bt}from"@clack/prompts";import{bold as Lt,cyanBright as It,green as Wt,redBright as qt,reset as zt}from"picocolors";function it({packages:e,withTags:t,githubToken:i,github:o,rootTag:n}){if(t)for(let{name:s,version:a}of Object.values(e)){const r=`${s}@${a}`;Bun.spawnSync(["git","tag",r,"-m",`Release ${r}`,"-f"])}if(n)Bun.spawnSync(["git","tag",n,"-m","Release","-f"]);if(o){if(!(i||process.env.GITHUB_TOKEN))return Bt(zt(Lt(`${qt("No Github token found.")}
|
|
20
|
+
Please provide one by using ${It("--githubToken")} flag or by setting ${Wt("GITHUB_TOKEN")} environment variable.`)));console.info("TODO: Creating Github release",{withTags:t,githubToken:i})}}import{note as Jt}from"@clack/prompts";import{bold as K,cyanBright as Qt,green as st,magenta as B,redBright as rt,reset as Yt}from"picocolors";function at({packages:e,dryRun:t,npmToken:i}){if(!(i||process.env.NPM_TOKEN))return Jt(Yt(K(`${rt("No NPM token found.")}
|
|
21
|
+
Please provide one by using ${Qt("--npmToken")} flag or by setting ${st("NPM_TOKEN")} environment variable.`)));const n=["npm","publish","--registry","https://registry.npmjs.org"].concat(t?["--dry-run"]:[]);for(let{name:s,file:a}of Object.values(e)){console.info(`Publishing ${B(s)}...`);try{Bun.spawnSync(n,{cwd:a.replace("package.json","")}),console.info(K(`${st("Published")} ${B(s)}`))}catch(r){console.error(K(`${rt("Failed to publish")} ${B(s)}`)),console.error(r)}}}async function ut(){const{values:e}=Xt({allowPositionals:!0,args:Bun.argv,strict:!0,options:{changelog:{default:!0,type:"boolean",short:"c"},changelogRoot:{default:!1,type:"boolean",short:"r"},dryRun:{default:!1,type:"boolean",short:"d"},github:{default:!1,type:"boolean",short:"g"},githubToken:{type:"string"},npm:{default:!1,type:"boolean",short:"n"},npmToken:{type:"string"},rootTag:{type:"string"},withTags:{default:!1,type:"boolean",short:"t"}}}),t=Bun.spawnSync(["git","rev-parse","HEAD"]).stdout.toString().trim(),i=new Date().toISOString().split(".")[0]||"",{dryRun:o,npmToken:n,changelogRoot:s}=e;let a=[];try{a=await ee()}catch{}if(a.length===0)return Zt(lt(ct(`${te("No stones found.")}
|
|
22
|
+
${lt(`Run ${Tt("bunx @r5n/sisyphus")}${gt(" version")} and create some first.`)}`)));const r=await oe({dryRun:o,configs:a});if(e.changelog)await nt({dryRun:o,changelogRoot:s,commit:t,stones:a});if(e.npm)at({dryRun:o,packages:r,npmToken:n});if(e.github)it({...e,packages:r});if(await X({dryRun:o,stones:[],lastStone:{commit:t,date:i}}),!e.dryRun)Vt(".sisyphus/stones",{recursive:!0,force:!0})}async function ee(){const e=x(),{packages:t}=await U({}),i=[];for(let o of e)try{const n=await Bun.file(`.sisyphus/stones/${o}.md`).text(),[s="",a=""]=n.split(M),[r="",,l=""]=a.trim().split("|\n|"),[u="",c=""]=s.split("\n");console.info({bumpTypesInfo:r,packagesInfo:l,releaseInfo:a,stoneContent:n,tag:c,title:u,titleAndTag:s});const f=r.slice(2).split("|").map((b)=>b.trim()),m=l.trim().slice(0,-2).split("|").map((b)=>b.split(",").map((v)=>v.trim())).flatMap((b,v)=>b.map((g)=>t[g]?{...t[g],bump:f[v]}:void 0)).filter(Boolean);i.push({message:u.replace("###","").trim(),name:o,packages:m,tag:c})}catch(n){console.error(`Error processing stone ${o}`),console.error(n)}return i}async function oe({configs:e,dryRun:t=!1}){const i=[],o=e.reduce((n,{message:s,packages:a})=>{i.push(s);for(let{bump:r,name:l,...u}of a)n[l]||={...u,name:l,bump:r},n[l].bump=Z([r,n[l].bump]),n[l].version=_({version:n[l].version,bump:r});return n},{});if(t)console.info(`${ct(gt("[dry-run]"))}\nConfig for next release:\n${i.join("\n")}\n${JSON.stringify(o,null,2)}`);else for(let{version:n,file:s}of Object.values(o)){const a=await Bun.file(s).json();await Bun.write(s,`${JSON.stringify({...a,version:n},null,2)}\n`)}return o}import{parseArgs as ue}from"util";import{confirm as fe,isCancel as he}from"@clack/prompts";import{bold as dt,cyanBright as bt,italic as wt,yellow as me}from"picocolors";import{group as ne,multiselect as ie,text as se}from"@clack/prompts";import{bold as S,dim as ft,italic as ht,magenta as L,underline as F,whiteBright as H}from"picocolors";import{object as re,string as O}from"zod";async function mt({packages:e,packageNames:t,tag:i}){function o({message:h,bump:m,packageNames:b,filterPackages:v}){const g=b.filter((y)=>!v?.includes(y)).map((y)=>({value:y,label:E({tag:i,name:y,version:e[y]?.version||"",bump:m})}));return g.length>0?ie({required:!1,initialValues:void 0,message:h,options:g}):void 0}const n=`\n - ${ft(ht(`Press ${F(S(H("a")))} to select/unselect all, ${F(S(H("SPACE")))} to select/unselect, ${F(S(H("ARROWS")))} to move, ${F(S(H("ENTER")))} to confirm`))}\n`,s=await ne({message:()=>se({placeholder:"New feature",message:`Name of the stone. ${ft(ht("Default prefix or message can be configured in config."))}`}),majorPackages:()=>o({message:`Select packages for ${S(L("major"))} bump.${n}`,bump:"major",packageNames:t,filterPackages:[]}),minorPackages:({results:{majorPackages:h}})=>o({message:`Select packages for ${S(L("minor"))} bump.`,bump:"minor",packageNames:t,filterPackages:h||[]}),patchPackages:({results:{majorPackages:h,minorPackages:m}})=>o({message:`Select packages for ${S(L("patch"))} bump.`,bump:"patch",packageNames:t,filterPackages:(h||[]).concat(m||[])})},{onCancel:()=>C()}),{success:a,error:r,data:{message:l="stone",majorPackages:u=[],minorPackages:c=[],patchPackages:f=[]}={}}=re({message:O().optional(),majorPackages:O().array().optional(),minorPackages:O().array().optional(),patchPackages:O().array().optional()}).safeParse(s);if(!a)return C(r.message);return{message:l,majorPackages:u,minorPackages:c,patchPackages:f}}import{randomUUID as ae}from"crypto";import{note as le}from"@clack/prompts";import{bold as pt,green as I,italic as ce,yellow as ge}from"picocolors";async function $t({dryRun:e=!1,majorPackages:t,message:i,minorPackages:o,packages:n,patchPackages:s,tag:a}){const l=`${`${x().length+1}`.padStart(4,"0")}-${ae().slice(0,8)}`,u=[...t,...o,...s],c=u.flatMap((g)=>n[g]?.dependencyOf||[]),f=[t,o,s,c.filter((g)=>!u.includes(g))],h=f.flatMap((g,y)=>g.length>0&&W[y]).filter(Boolean),m=[`### ${i}`,a?`_${a}_`:"",M,"",`| ${h.join(" | ")} |`,`| ${h.map(()=>":---:").join(" | ")} |`,`| ${h.map((g)=>f[W.indexOf(g)]?.join(", ")).join(" | ")} |`,""],b=await k();if(b.stones.push(l),e)console.info(`${pt(ge("[dry-run]"))}\nStone file preview:\n${m.join("\n")}`);else await Bun.write(`.sisyphus/stones/${l}.md`,m.join("\n")),await Bun.write(".sisyphus/config.json",`${JSON.stringify(b,null,2)}\n`),le(`Now you can run ${I("bunx @r5n/sisyphus roll")} to release packages
|
|
23
|
+
or create another stone with ${I("bunx @r5n/sisyphus version")}`,`${pt("Stone ")}${ce(`${l}.md`)} ${I("created!")}`);return f.flatMap((g,y)=>g.map((Pt)=>({...n[Pt],bump:W[y]}))).filter(Boolean)}var W=["major","minor","patch","dependency"];async function yt(){const{values:{bump:e,dryRun:t,filter:i,tag:o,snapshot:n,yes:s}}=ue({allowPositionals:!0,args:Bun.argv,strict:!0,options:{bump:{default:"",type:"string",short:"b"},dryRun:{default:!1,type:"boolean",short:"d"},filter:{default:"",type:"string",short:"f"},snapshot:{default:!1,type:"boolean",short:"s"},tag:{default:"",type:"string",short:"t"},yes:{default:!1,type:"boolean",short:"y"}}});if(n&&e)return C(`Cannot use both ${bt("--snapshot")} and ${bt("--bump")} options, pick one.`);const{packages:a,packageNames:r}=await U({filter:i}),{message:l,majorPackages:u,minorPackages:c,patchPackages:f}=await mt({packages:a,packageNames:r,tag:o}),h=await $t({dryRun:t,message:l,packages:a,tag:o,majorPackages:u,minorPackages:c,patchPackages:f});if(console.info([`${t?dt(me("[dry-run]\n")):""}${wt("Changes preview:")}\n`,`${wt("Stone: ")}${dt(l)}`,...h.map(E)].join("\n")),!(s||t)){const m=await fe({message:"Are you sure you want to create a new stone?",active:"Yes, continue",inactive:"No, cancel"});if(!m||he(m))return C("Operation cancelled by user")}}function vt({method:e}){if(Bun.argv.includes("--help"))return D(e);switch(e){case"init":return T();case"version":return yt();case"roll":return ut();default:return D()}}var[pe]=process.argv.slice(2);vt({method:pe});
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": "
|
|
3
|
-
"bin":
|
|
2
|
+
"author": "@ice-chillios",
|
|
3
|
+
"bin": {
|
|
4
|
+
"@r5n/sisyphus": "./dist/cli.js"
|
|
5
|
+
},
|
|
4
6
|
"dependencies": {
|
|
5
7
|
"@clack/prompts": "0.7.0",
|
|
6
8
|
"picocolors": "1.1.0",
|
|
@@ -20,7 +22,7 @@
|
|
|
20
22
|
"url": "git+https://github.com/r5n-dev/Typescript-Monorepo.git"
|
|
21
23
|
},
|
|
22
24
|
"scripts": {
|
|
23
|
-
"build": "rm -rf ./dist && bun
|
|
25
|
+
"build": "rm -rf ./dist && bun ./build.ts",
|
|
24
26
|
"clean": "rm -rf ./dist ./node_modules",
|
|
25
27
|
"dev": "bun run build; rm -rf ./temp; bun run --bun ./cli.ts",
|
|
26
28
|
"lint": "biome check --write",
|
|
@@ -28,5 +30,5 @@
|
|
|
28
30
|
"type-check": "bun tsc --noEmit"
|
|
29
31
|
},
|
|
30
32
|
"types": "./cli.ts",
|
|
31
|
-
"version": "0.0
|
|
33
|
+
"version": "0.2.0-rc.1"
|
|
32
34
|
}
|