@r5n/sisyphus 0.2.0-rc.6 → 0.2.0-rc.7

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