task-pipeliner 0.3.8 → 0.3.9
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/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/index.cjs +2 -2
- package/package.json +1 -1
package/README.ko.md
CHANGED
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@ ${c}`;return`
|
|
|
10
10
|
${(0,Zt.default)(f,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0,left:0,right:0},borderColor:"cyan"})}`}function jr(o){let e=[],t=new Map,r=1e3;for(let i of o){let n;i.context.branchIndex!==void 0&&i.context.stepIndex>=r?n=Math.floor(i.context.stepIndex/r):n=i.context.stepIndex,t.has(n)||t.set(n,[]);let a=t.get(n);a&&a.push(i)}let s=Array.from(t.keys()).sort((i,n)=>i-n);for(let i of s){let n=t.get(i);if(n){let a=n.filter(l=>l.context.branchIndex!==void 0&&l.context.stepIndex>=r);if(a.length>0){a.sort((c,d)=>{let f=c.context.branchIndex??-1,m=d.context.branchIndex??-1;return f-m}),e.push(a);let l=n.filter(c=>(c.context.branchIndex===void 0||c.context.stepIndex<r)&&!("parallel"in c.step));l.length>0&&(l.sort((c,d)=>c.context.stepIndex-d.context.stepIndex),e.push(l))}else n.sort((l,c)=>l.context.stepIndex-c.context.stepIndex),e.push(n)}}return e}function Yt(o){let e=o.step,t=28;if("run"in e){let r=o.resolvedCommand??e.run;return r.length>t?`${r.substring(0,t-2)}..`:r}else if("choose"in e){let r=e.choose.message;return r.length>t?`${r.substring(0,t-2)}..`:r}else if("prompt"in e){let r=e.prompt.message;return r.length>t?`${r.substring(0,t-2)}..`:r}else{if("parallel"in e)return"Parallel";if("fail"in e){let r=e.fail.message;return r.length>t?`${r.substring(0,t-2)}..`:r}}return"Unknown"}function Jt(o,e){return Te(o)<=e}function Ar(o,e,t){let r=process.stdout.columns||80,s=36,i=4,n=36,a=8,l=8,d=n+a+l+9,m=r-s-i-d,g=Math.max(40,Math.max(0,m-5)),w=[],y=2+n+3+a+3+l+3+g+2,k=r-s-8,$=(R,P,Z=!1)=>{let Re=Te(R);if(Re===P)return R;if(Re>P)return De(R,P);let ne=P-Re;if(Z){let se=R.lastIndexOf("\u2524"),fe=R.lastIndexOf("\u253C",se-1);if(fe>0&&se>fe){let Le=R.slice(0,fe+1),at=R.slice(fe+1,se),Fe=R.slice(se);return Le+at+"\u2500".repeat(ne)+Fe}return R.slice(0,-1)+"\u2500".repeat(ne)+R.slice(-1)}let Oe=R.lastIndexOf("\u2502");return Oe>0?R.slice(0,Oe)+" ".repeat(ne)+R.slice(Oe):R+" ".repeat(ne)},I="\u2500".repeat(n),H="\u2500".repeat(a),A="\u2500".repeat(l),ot="\u2500".repeat(g),rt=`\u250C\u2500${I}\u2500\u252C\u2500${H}\u2500\u252C\u2500${A}\u2500\u252C\u2500${ot}\u2500\u2510`;rt=$(rt,y,!0),w.push(rt);let cr=ue("Step / Task",n),ur=J("Start",a),pr=ue("Duration",l),dr=ue("Timeline",g),nt=`\u2502 ${C.default.bold(cr)} \u2502 ${C.default.bold(ur)} \u2502 ${C.default.bold(pr)} \u2502 ${C.default.bold(dr)} \u2502`;nt=$(nt,y),w.push(nt);let mr="\u2500".repeat(n),fr="\u2500".repeat(a),hr="\u2500".repeat(l),gr="\u2500".repeat(g),st=`\u251C\u2500${mr}\u2500\u253C\u2500${fr}\u2500\u253C\u2500${hr}\u2500\u253C\u2500${gr}\u2500\u2524`;st=$(st,y,!0),w.push(st);let Be=new Map;for(let R=0;R<o.length;R++){let P=o[R],Z=Math.round(P.startTime);Be.has(Z)||Be.set(Z,[]),Be.get(Z)?.push(R)}for(let R=0;R<o.length;R++){let P=o[R],Z=(P.startTime/1e3).toFixed(1),Re=(P.duration/1e3).toFixed(1),ne=`${C.default.cyan(`Step ${P.stepNumber}`)}: ${P.name}`,se=qt(P.duration,t)(`${Re}s`),fe=Math.round(P.startTime),Le=Be.get(fe)??[],at=Le.indexOf(R),Fe=Gt(P.startTime,P.duration,e,g,P.duration,t,!1,at,Le.length,P.isParallel),ie=`\u2502 ${ue(ne,n)} \u2502 ${J(`${Z}s`,a)} \u2502 ${J(se,l)} \u2502 ${Fe} \u2502`;if(ie=$(ie,y),!Jt(ie,k)){let ae=De(ne,n);ie=`\u2502 ${ue(ae,n)} \u2502 ${J(`${Z}s`,a)} \u2502 ${J(se,l)} \u2502 ${Fe} \u2502`,ie=$(ie,y)}if(w.push(ie),P.isParallel&&P.parallelBranches&&P.parallelBranches.length>0)for(let ae=0;ae<P.parallelBranches.length;ae++){let X=P.parallelBranches[ae],Ot=(X.startTime/1e3).toFixed(1),xr=(X.duration/1e3).toFixed(1),Lt=Gt(X.startTime,X.duration,e,g,X.duration,t,!0,0,1,!1),Ft=ae===0?"\u2502 \u23A7 ":ae===P.parallelBranches.length-1?"\u2502 \u23A9 ":"\u2502 \u251C ",lt=n-3,kr=ue(C.default.blue(X.name),lt),Wt=qt(X.duration,t)(`${xr}s`),le=`${Ft}${kr} \u2502 ${J(`${Ot}s`,a)} \u2502 ${J(Wt,l)} \u2502 ${Lt} \u2502`;if(le=$(le,y),!Jt(le,k)){let vr=De(C.default.blue(X.name),lt-3);le=`${Ft}${ue(vr,lt)} \u2502 ${J(`${Ot}s`,a)} \u2502 ${J(Wt,l)} \u2502 ${Lt} \u2502`,le=$(le,y)}w.push(le)}}let wr="\u2500".repeat(n),br="\u2500".repeat(a),yr="\u2500".repeat(l),Sr="\u2500".repeat(g),it=`\u2514\u2500${wr}\u2500\u2534\u2500${br}\u2500\u2534\u2500${yr}\u2500\u2534\u2500${Sr}\u2500\u2518`;return it=$(it,y,!0),w.push(it),w.join(`
|
|
11
11
|
`)}function qt(o,e){if(o===0)return C.default.gray;let t=o/e;return t>=.8?C.default.red:t>=.5?C.default.yellow:C.default.green}function Gt(o,e,t,r,s,i,n=!1,a=0,l=1,c=!1){let d=o/t,m=(o+e)/t,p=Math.round(d*r),h=Math.round(m*r);if(l>1&&e===0){let A=a*1e-4;p=Math.round((d+A)*r),h=p+1}else h<=p&&(h=p+1);p=Math.max(0,Math.min(p,r-1)),h=Math.max(p+1,Math.min(h,r));let g;if(n)g=C.default.cyan;else if(c)g=C.default.blue;else if(s===0)g=C.default.gray;else{let A=s/i;A>=.8?g=C.default.red:A>=.5?g=C.default.yellow:g=C.default.green}let y=m>=.99||h>=r?r:h,k="";for(let A=0;A<p;A++)k+=C.default.gray("\u2591");let $=y-p,I="\u2588".repeat($);k+=g(I);let H=r-y;for(let A=0;A<H;A++)k+=C.default.gray("\u2591");return k}function Te(o){return(0,ht.default)(o)}function De(o,e){if(Te(o)<=e)return o;let s=e-2;if(s<1)return"..";let i=/\u001b\[[0-9;]*m/g,n=[],a;for(;(a=i.exec(o))!==null;)n.push(a[0]);let l=o.replace(i,""),c="",d=0;for(let f=0;f<l.length;f++){let m=l[f],p=(0,ht.default)(m);if(d+p>s)break;c+=m,d+=p}return c+="..",n.length>0&&c.length>0?n[0]+c+(n[n.length-1]??""):c}function ue(o,e){let t=Te(o);return t>=e?De(o,e):o+" ".repeat(e-t)}function J(o,e){let t=Te(o);return t>=e?De(o,e):" ".repeat(e-t)+o}var _e=S(require("boxen"),1),we=S(require("chalk"),1);function gt(o,e,t,r={}){let{borderColor:s="cyan",isNested:i=!1}=r,n;e!==void 0&&(t?n=`line ${e} in ${t}`:n=`line ${e}`);let a=i?`\u2502 ${o}`:`> ${o}`;return(0,_e.default)(a,{title:n,borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0,left:0,right:0},borderColor:s})}function be(o,e=!1,t){let r=o?"\u2713 Completed":"\u2717 Failed",s=o?we.default.green(r):we.default.red(r);if(t!==void 0){let i=ye(t);return`${s} ${we.default.gray(`(${i})`)}`}return s}function Ie(o){return(0,_e.default)(`\u2717 ${o}`,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0,left:0,right:0},borderColor:"red"})}function Xt(o){return(0,_e.default)(`> Starting parallel execution (${o} branches)`,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0,left:0,right:0},borderColor:"yellow"})}function Kt(o){let e=o?"\u2713 All parallel branches completed":"\u2717 Some parallel branches failed";return o?we.default.green(e):we.default.red(e)}function wt(o,e=!1){return`${e?"| \u2502 ":"\u2502 "}${o}`}function ye(o){return`${(o/1e3).toFixed(3)}s`}var Qt=require("fs"),eo=require("path"),pe=class{constructor(e){this.workspace=e}evaluate(e){return"var"in e||"has"in e?this.evaluateVarExists(e):"file"in e?this.evaluateFileExists(e):"choice"in e?this.evaluateChoice(e):"all"in e?this.evaluateAll(e):"any"in e?this.evaluateAny(e):"not"in e?this.evaluateNot(e):!1}evaluateVarExists(e){if(e.has)return this.workspace.hasVariable(e.has)||this.workspace.hasFact(e.has);if(!e.var)return!1;if(typeof e.var=="object"){for(let[r,s]of Object.entries(e.var)){let i=this.workspace.getVariable(r),n=this.workspace.getFact(r),a=i??(n!==void 0?n.toString():void 0);if(a===void 0||a!==s)return!1}return!0}let t=e.var;return this.workspace.hasVariable(t)||this.workspace.hasFact(t)}evaluateFileExists(e){try{let t=e.file.trim(),r=(0,eo.resolve)(process.cwd(),t);return(0,Qt.existsSync)(r)}catch{return!1}}evaluateChoice(e){return this.workspace.hasChoice(e.choice)}evaluateAll(e){return e.all.every(t=>this.evaluate(t))}evaluateAny(e){return e.any.some(t=>this.evaluate(t))}evaluateNot(e){return!this.evaluate(e.not)}};var bt=S(require("log-update"),1);var yt=1e3;function Br(o,e,t){return e.parallel.map((r,s)=>({workspace:o.workspace.clone(),stepIndex:t.stepIndex*yt+s,branchIndex:s,lineNumber:t.lineNumber,fileName:t.fileName}))}function to(o,e){return"run"in o?o.run:"choose"in o?`Choose: ${o.choose.message}`:"prompt"in o?`Prompt: ${o.prompt.message}`:"fail"in o?`Fail: ${o.fail.message}`:`Branch ${e+1}`}function Or(o,e){let t=0;for(let r=0;r<o.length;r++){let s=o[r],i=e[r];s.when&&!new pe(i.workspace).evaluate(s.when)||t++}return t}function Ue(o,e,t=!1){let r=o.map(s=>{let i=s.index+1,n="",a="";switch(s.status){case"pending":n="\u25CB",a=`Branch ${i}: ${s.name} - Pending`;break;case"running":n=e,a=`Branch ${i}: ${s.name} - Running...`;break;case"success":n="\u2713",a=`Branch ${i}: ${s.name} - Completed`;break;case"failed":n="\u2717",a=`Branch ${i}: ${s.name} - Failed${s.error?`: ${s.error}`:""}`;break}return`${n} ${a}`});(0,bt.default)(r.join(`
|
|
12
12
|
`))}async function Lr(o,e,t,r){let s=[],i=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],n=0;for(let d=0;d<t.length;d++){let f=t[d],m=r[d];if(f.when&&!new pe(m.workspace).evaluate(f.when))continue;let p=e(f,d);s.push({index:d,name:p,status:"pending"})}let a=setInterval(()=>{n=(n+1)%i.length,Ue(s,i[n])},100),l=s.map(async d=>{let{index:f}=d,m=t[f],p=r[f];d.status="running";try{let h=await o.executeStep(m,p,!0);if(d.status="success",Ue(s,i[n]),o.recordBranch){let g="run"in m?{resolvedCommand:m.run}:void 0;o.recordBranch(m,p,h,"success",g)}return{index:f,result:h,context:p}}catch(h){p.workspace.setStepResult(p.stepIndex,!1);let g=h instanceof Error?h.message:String(h);if(d.status="failed",d.error=g,Ue(s,i[n]),o.recordBranch){let w="run"in m?{resolvedCommand:m.run}:void 0;o.recordBranch(m,p,void 0,"failure",w)}return{index:f,error:h,context:p}}}),c=await Promise.all(l);return clearInterval(a),Ue(s,"",!0),bt.default.done(),c}function Fr(o,e,t,r,s){let i=!0,n=!1;console.log("");for(let l of t){if(!l)continue;n=!0;let{index:c,result:d,error:f,context:m}=l;if(f){i=!1;let p=`Branch ${c+1} failed: ${f instanceof Error?f.message:String(f)}`,h=Ie(p);console.error(h)}else if(d&&typeof d=="object"&&"stdout"in d){let p=d;if(i=i&&p.success,p.stdout.length>0||p.stderr.length>0||!p.success){let h=r[c],g=e(h,c);o.taskRunner.displayBufferedOutput(p,g,!1,m.lineNumber,m.fileName)}}}n||console.log("\u26A0\uFE0F All parallel branches were skipped (conditions not met)");let a=Kt(i);return console.log(a),i}function Wr(o,e){for(let t of e){let r=t.workspace.getAllFacts(),s=t.workspace.getAllVariables();for(let[i,n]of r)o.workspace.setFact(i,n);for(let[i,n]of s)o.workspace.setVariable(i,n)}}async function oo(o,e,t){let r=Br(o,e,t),s=Or(e.parallel,r),i=Xt(s);console.log(i);let n=await Lr(o,to,e.parallel,r),a=Fr(o,to,n,e.parallel,t);if(o.setStepResult(t.stepIndex,a),!a){let l=t.lineNumber?` (line ${t.lineNumber})`:"";throw new Error(`Parallel step ${t.stepIndex}${l} failed: one or more branches failed`)}Wr(o,r)}var St=require("jsonpath-plus"),ro=require("yaml");function no(o,e){try{let t=e.join(`
|
|
13
|
-
`);if(!("regex"in o)&&!("json"in o)&&!("yaml"in o)&&!("yml"in o)&&!("kv"in o)&&!("after"in o)&&!("before"in o)&&!("line"in o))return t;if("regex"in o){let r=new RegExp(o.regex),s=t.match(r);return s&&s[1]?s[1]:null}if("json"in o)try{let r=JSON.parse(t),s=(0,St.JSONPath)({path:o.json,json:r});if(s&&s.length>0){let i=s[0];return typeof i=="string"?i:JSON.stringify(i)}return null}catch{return null}if("yaml"in o||"yml"in o)try{let r=(0,ro.parse)(t),s="yaml"in o?o.yaml:o.yml,i=(0,St.JSONPath)({path:s,json:r});if(i&&i.length>0){let n=i[0];return typeof n=="string"?n:JSON.stringify(n)}return null}catch{return null}if("kv"in o){let r=o.kv;for(let s of e){let i=s.trim();if(!i||i.startsWith("#"))continue;let n=`^${r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*=\\s*(.+)$`,a=i.match(new RegExp(n));if(a&&a[1])return a[1].trim().replace(/^["']|["']$/g,"")}return null}if("after"in o||"before"in o){let r="after"in o?o.after:"",s="before"in o?o.before:void 0;if(r){let i=t.indexOf(r);if(i===-1)return null;let n=i+r.length,a=t.length;if(s){let l=t.indexOf(s,n);if(l===-1)return null;a=l}return t.substring(n,a).trim()}if(s){let i=t.indexOf(s);return i===-1?null:t.substring(0,i).trim()}}if("line"in o){let{from:r,to:s}=o.line,i=Math.max(0,r-1),n=Math.min(e.length,s);return i>=e.length||n<=i||i<0||s<r?null:e.slice(i,n).join(`
|
|
13
|
+
`);if(!("regex"in o)&&!("json"in o)&&!("yaml"in o)&&!("yml"in o)&&!("kv"in o)&&!("after"in o)&&!("before"in o)&&!("line"in o))return t;if("regex"in o){let r=new RegExp(o.regex),s=t.match(r);return s&&s[1]?s[1]:null}if("json"in o)try{let r=JSON.parse(t),s=(0,St.JSONPath)({path:o.json,json:r});if(s&&s.length>0){let i=s[0];return typeof i=="string"?i:JSON.stringify(i)}return null}catch{return null}if("yaml"in o||"yml"in o)try{let r=(0,ro.parse)(t),s="yaml"in o?o.yaml:o.yml,i=(0,St.JSONPath)({path:s,json:r});if(i&&i.length>0){let n=i[0];return typeof n=="string"?n:JSON.stringify(n)}return null}catch{return null}if("kv"in o&&typeof o.kv=="string"){let r=o.kv.trim();if(!r)return null;for(let s of e){let i=s.trim();if(!i||i.startsWith("#"))continue;let n=`^${r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*=\\s*(.+)$`,a=i.match(new RegExp(n));if(a&&a[1])return a[1].trim().replace(/^["']|["']$/g,"")}return null}if("after"in o||"before"in o){let r="after"in o?o.after:"",s="before"in o?o.before:void 0;if(r){let i=t.indexOf(r);if(i===-1)return null;let n=i+r.length,a=t.length;if(s){let l=t.indexOf(s,n);if(l===-1)return null;a=l}return t.substring(n,a).trim()}if(s){let i=t.indexOf(s);return i===-1?null:t.substring(0,i).trim()}}if("line"in o){let{from:r,to:s}=o.line,i=Math.max(0,r-1),n=Math.min(e.length,s);return i>=e.length||n<=i||i<0||s<r?null:e.slice(i,n).join(`
|
|
14
14
|
`)}return null}catch{return null}}function Hr(o,e,t){if(e.hasVariable(o))return e.getVariable(o)??t;if(e.hasFact(o)){let r=e.getFact(o);return typeof r=="string"?r:String(r)}return e.hasChoice(o)?e.getChoice(o)??t:t}function de(o,e){let t=/\{\{\s*(\w+)\s*\}\}/g;return o.replace(t,(r,s)=>Hr(s,e,r))}async function so(o,e,t,r,s){let{workspace:i,taskRunner:n,baseDir:a,globalShell:l,calculateBaseStepIndex:c}=o,d=c(t),f=de(e.run.trim(),i),m=e.shell??l,p=e.retry??0,h=p==="Infinity"||p===1/0,g=typeof p=="number"?p:0,w=e.timeout,y=!1,k=0,$=e.run.trim()!==f?`${f}
|
|
15
15
|
(template: ${e.run})`:f;for(;h||k<=g;){let I=await n.run(f,d,$,t.branchIndex,r,s,t.lineNumber,t.fileName,a,w,m),H=typeof I=="boolean"?I:I.success;if(y=I,H||!h&&k>=g)break;if(k++,h||k<=g){let A=Math.min(1e3*Math.pow(2,k-1),1e4);await new Promise(ot=>setTimeout(ot,A))}}return y}async function io(o,e,t,r,s){let i=await so(o,{run:e.run,timeout:e.timeout,retry:e.retry,shell:void 0},t,r,s);return(typeof i=="boolean"?i:i.success)||!e.onError?i:io(o,e.onError,t,r,s)}async function ao(o,e,t,r=!1,s=!1){let{workspace:i}=o,n=!!(r===!0||e.captures&&e.captures.length>0),a=await so(o,{run:e.run,timeout:e.timeout,retry:e.retry,shell:e.shell},t,n,s),l=typeof a=="boolean"?a:a.success;if(i.setStepResult(t.stepIndex,l),n&&typeof a=="object"&&"stdout"in a){let f=de(e.run.trim(),i),m=e.run.trim()!==f?`${f}
|
|
16
16
|
(template: ${e.run})`:f;o.taskRunner.displayBufferedOutput(a,m,!1,t.lineNumber,t.fileName)}if(e.captures&&typeof a=="object"&&"stdout"in a){let f=a.stdout||[];for(let m of e.captures){let p=no(m,f);p!==null&&m.as&&i.setVariable(m.as,p)}}if(l||!e.onError)return a;let c={run:e.onError.run,timeout:e.onError.timeout,retry:e.onError.retry,onError:e.onError.onError??void 0};return await io(o,c,t,r,s)}var V=require("fs/promises"),lo=require("os"),me=require("path"),co=S(require("dayjs"),1),Se=(0,me.join)((0,lo.homedir)(),".pipeliner","workflow-history"),xe=class{constructor(){}async saveHistory(e){await(0,V.mkdir)(Se,{recursive:!0});let t=(0,co.default)().format("YYYY-MM-DD_HH-mm-ss"),r=Math.random().toString(36).slice(2,6),s=(0,me.join)(Se,`workflow-${t}-${r}.json`);return await(0,V.writeFile)(s,JSON.stringify(e,null,2),{encoding:"utf8"}),s}async clearAllHistories(){await(0,V.rm)(Se,{recursive:!0,force:!0})}async removeHistory(e){await(0,V.rm)((0,me.join)(Se,e),{force:!0})}async getHistoryNames(){try{let t=(await(0,V.readdir)(Se)).map(r=>(0,me.basename)(r));return t.sort((r,s)=>{let i=l=>{let c=l.match(/workflow-(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})-/);return c?c[1]:""},n=i(r),a=i(s);return n===a?s.localeCompare(r):a.localeCompare(n)}),t}catch(e){if(e instanceof Error&&"code"in e&&e.code==="ENOENT")return[];throw e}}async getHistory(e){let t=await(0,V.readFile)((0,me.join)(Se,e),{encoding:"utf8"});return JSON.parse(t)}};var ze=class{records=[];initialTimestamp=Date.now();recordStartTimestamp=Date.now();constructor(){this.records=[]}recordStart(){this.recordStartTimestamp=Date.now()}recordEnd(e,t,r,s,i){let n=this.getDuration();return this.records.push({step:e,context:t,output:r,duration:n,status:s,...i}),n}reset(){this.records=[],this.initialTimestamp=Date.now()}async save(){let e=new xe,t={initialTimestamp:this.initialTimestamp,records:this.records};return await e.saveHistory(t)}getDuration(){return Date.now()-this.recordStartTimestamp}getHistory(){return{initialTimestamp:this.initialTimestamp,records:this.records}}};var xt=require("child_process");var Ye=class{async run(e,t,r,s,i=!1,n=!1,a,l,c,d,f){return i?this.runBuffered(e,c,d,f):this.runRealtime(e,r??e,n,a,l,c,d,f)}async runBuffered(e,t,r,s){return new Promise((i,n)=>{let a=this.spawnWithShell(e,t,s),l=[],c=[],d="",f="",m=null;r&&r>0&&(m=setTimeout(()=>{a.kill("SIGTERM");let p=`Command timed out after ${r} seconds`;c.push(p),i({success:!1,stdout:l,stderr:c})},r*1e3)),a.stdout?.on("data",p=>{let h=p.toString(),{lines:g,remaining:w}=this.processStreamBuffer(h,d);l.push(...g),d=w}),a.stderr?.on("data",p=>{let h=p.toString(),{lines:g,remaining:w}=this.processStreamBuffer(h,f);c.push(...g),f=w}),a.on("close",p=>{m&&clearTimeout(m),d.trim()&&l.push(d),f.trim()&&c.push(f),i({success:p===0,stdout:l,stderr:c})}),a.on("error",p=>{m&&clearTimeout(m);let h=`Error: ${p.message}`;i({success:!1,stdout:l,stderr:[...c,h]})})})}async runRealtime(e,t,r,s,i,n,a,l){let d=gt(t,s,i,{borderColor:r?"green":"cyan"});console.log(d);let f=Date.now();return new Promise(m=>{let p=this.spawnWithShell(e,n,l),h="",g="",w=null;a&&a>0&&(w=setTimeout(()=>{p.kill("SIGTERM");let y=`Command timed out after ${a} seconds`,k=Ie(y);console.error(k);let $=Date.now()-f,I=be(!1,!1,$);console.log(I),m(!1)},a*1e3)),p.stdout?.on("data",y=>{let k=y.toString(),{lines:$,remaining:I}=this.processStreamBuffer(k,h);$.forEach(H=>process.stdout.write(`\u2502 ${H}
|
|
@@ -62,7 +62,7 @@ ${s}`)}throw r}}extractStepLineNumbers(e){let t=new Map,r=e.split(`
|
|
|
62
62
|
`);console.log(x.default.red(" Errors:")),console.log(e)}}var Ko=require("commander");var Lo=require("child_process"),Ke=require("fs"),Fo=require("fs/promises"),j=require("path"),Wo=S(require("boxen"),1),D=S(require("chalk"),1),Qe=S(require("inquirer"),1),Ho=S(require("node-cron"),1);ge();var Co=require("fs/promises"),Do=require("path"),To=require("yaml"),Io=require("zod");var L=require("zod"),Sn=L.z.object({name:L.z.string().min(1,"Schedule name must be non-empty"),cron:L.z.string().min(1,"Cron expression is required"),workflow:L.z.string().min(1,"Workflow path is required"),baseDir:L.z.string().optional(),timezone:L.z.union([L.z.string(),L.z.number()]).transform(String).optional(),silent:L.z.boolean().optional(),profile:L.z.string().optional()}),xn=L.z.object({schedules:L.z.array(Sn).min(1,"Schedule file must have at least one schedule")});function Po(o){return xn.parse(o)}async function Mo(o){let e=await(0,Co.readFile)(o,"utf-8"),t=(0,Do.extname)(o).toLowerCase(),r;try{if(t===".yaml"||t===".yml")r=(0,To.parse)(e);else if(t===".json")r=JSON.parse(e);else throw new Error(`Unsupported file format: ${t}. Use .yaml, .yml, or .json`)}catch(s){if(s instanceof Error&&s.message.startsWith("Unsupported"))throw s;let i=t===".json"?"JSON":"YAML";throw new Error(`Invalid ${i} format: ${s instanceof Error?s.message:String(s)}`)}try{return Po(r)}catch(s){if(s instanceof Io.ZodError){let i=s.issues.map(n=>` - ${n.message} (${n.path.join(".")})`).join(`
|
|
63
63
|
`);throw new Error(`Invalid schedule file structure:
|
|
64
64
|
${i}`)}throw s}}var No=S(require("boxen"),1),E=S(require("chalk"),1),jo=S(require("cronstrue"),1),Tt=S(require("dayjs"),1),It=S(require("node-cron"),1);function Mt(o){try{return jo.default.toString(o)}catch{return null}}function kn(o){if(!It.default.validate(o.cron))return null;try{let e={},t=Ge(o.timezone);t&&(e.timezone=t);let r=It.default.createTask(o.cron,()=>{},e),s=r.getNextRun();return r.destroy(),s}catch{return null}}function ee(o,e){let t=o,{daemonRunning:r,emphasizeState:s}=e,i=t.enabled?s?E.default.bold.green("ENABLED"):E.default.green("enabled"):s?E.default.bold.gray("DISABLED"):E.default.gray("disabled"),n=r&&t.enabled,a=n?E.default.green("\u25CF active"):E.default.gray("\u25CB inactive"),l=s?t.enabled?E.default.bold.green(" [ENABLED]"):E.default.bold.gray(" [DISABLED]"):"",c=E.default.bold(t.name??t.workflowPath),d=kn(t),f=d?(0,Tt.default)(d).format("YYYY-MM-DD HH:mm:ss"):E.default.dim("\u2014"),m=t.lastRun?(0,Tt.default)(t.lastRun).format("YYYY-MM-DD HH:mm:ss"):E.default.dim("never"),p=Mt(t.cron),h=t.timezone?t.timezone.startsWith("+")||t.timezone.startsWith("-")?`UTC${t.timezone}`:`UTC+${t.timezone}`:null,g=h??"local",w=p?`${t.cron} ${E.default.dim(`\u2192 ${p} (${g})`)}`:t.cron,y=[[E.default.gray("Enabled"),i],[E.default.gray("Cron"),w],[E.default.gray("Timezone"),h??E.default.dim("local")],[E.default.gray("Workflow"),t.workflowPath],...t.profile?[[E.default.gray("Profile"),E.default.cyan(t.profile)]]:[],...t.silent?[[E.default.gray("Silent"),E.default.yellow("yes")]]:[],[E.default.gray("Last run"),m],[E.default.gray("Next run"),f]],k=[`${c} ${a}${l}`,...y.map(([I,H])=>` ${I.padEnd(10)} ${H}`)].join(`
|
|
65
|
-
`);return(0,No.default)(k,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0,left:0,right:0},borderColor:n?"green":"gray"})}var q=require("fs"),O=require("path"),Nt=require("url"),Ao={};function Bo(){console.log=()=>{},console.error=()=>{},console.warn=()=>{},console.info=()=>{},process.stdout.write=()=>!0,process.stderr.write=()=>!0}function Oo(){return"0.3.
|
|
65
|
+
`);return(0,No.default)(k,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0,left:0,right:0},borderColor:n?"green":"gray"})}var q=require("fs"),O=require("path"),Nt=require("url"),Ao={};function Bo(){console.log=()=>{},console.error=()=>{},console.warn=()=>{},console.info=()=>{},process.stdout.write=()=>!0,process.stderr.write=()=>!0}function Oo(){return"0.3.9"}function Xe(o){let e=o?(0,O.resolve)(o):process.cwd(),t=50,r=0;for(;r<t;){let s=(0,O.resolve)(e,"tp");try{if((0,q.existsSync)(s)&&(0,q.statSync)(s).isDirectory())return s}catch{}let i=(0,O.dirname)(e);if(i===e)break;e=i,r++}return null}function jt(o,e){let t=e.workflow;if((0,j.isAbsolute)(t))return t;let r=e.baseDir?(0,j.resolve)(e.baseDir):(0,j.dirname)(o);return(0,j.resolve)(r,t)}function Vo(o,e="plain"){let t=o.name??"(no alias)",r=(0,j.basename)(o.workflowPath),s=Mt(o.cron)??o.cron,i=e==="color"?o.enabled?D.default.green("Enabled"):D.default.dim("Disabled"):o.enabled?"\u2713":"\u2717";return`${t} \xB7 ${r} \xB7 ${o.cron} \xB7 ${s} \xB7 ${i}`}async function _o(o){let e=new W;if(!o){let l=Xe();l||(console.error(D.default.red(`
|
|
66
66
|
\u2717 No tp directory found`)),process.exit(1));let c=(0,j.join)(l,"schedules");(0,Ke.existsSync)(c)||(console.error(D.default.red(`
|
|
67
67
|
\u2717 No schedules directory found at ${c}`)),process.exit(1));let f=(await(0,Fo.readdir)(c)).filter(g=>{let w=(0,j.extname)(g).toLowerCase();return[".yaml",".yml",".json"].includes(w)});f.length===0&&(console.error(D.default.red(`
|
|
68
68
|
\u2717 No schedule files found in ${c}`)),process.exit(1));let m=f.map(g=>({id:(0,j.join)(c,g),label:g}));o=(await new B(!0).prompt("Select a schedule file to add",m)).id}let t=(0,j.resolve)(o);(0,Ke.existsSync)(t)||(console.error(`\u2717 File not found: ${t}`),process.exit(1));let r;try{r=await Mo(t)}catch(l){console.error(`\u2717 Failed to parse schedule file: ${l instanceof Error?l.message:String(l)}`),process.exit(1)}let s=r.schedules.filter(l=>!Ho.default.validate(l.cron));if(s.length>0){console.error("\u2717 Invalid cron expression(s):");for(let l of s)console.error(` - ${l.name}: "${l.cron}"`);process.exit(1)}let i=r.schedules.filter(l=>{let c=jt(t,l);return!(0,Ke.existsSync)(c)});if(i.length>0){console.error("\u2717 Workflow file(s) not found:");for(let l of i){let c=jt(t,l);console.error(` - ${l.name}: ${l.workflow} (resolved: ${c})`)}process.exit(1)}console.log(`
|