task-pipeliner 0.2.6 → 0.2.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.
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/index.cjs +38 -38
- package/dist/index.js +32 -32
- package/package.json +3 -2
package/README.ko.md
CHANGED
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
3
|
-
`)),y=
|
|
4
|
-
`)),C=
|
|
2
|
+
"use strict";var Pe=Object.create;var ie=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var Ie=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ne(e))!Ae.call(n,o)&&o!==t&&ie(n,o,{get:()=>e[o],enumerable:!(r=Me(e,o))||r.enumerable});return n};var b=(n,e,t)=>(t=n!=null?Pe(Te(n)):{},Ie(e||!n||!n.__esModule?ie(t,"default",{value:n,enumerable:!0}):t,n));var ve=require("child_process"),ke=require("fs"),Re=require("path"),Ce=require("util"),ae=b(require("boxen"),1),u=b(require("chalk"),1),$e=require("commander"),Ee=b(require("dayjs"),1);var T=require("path"),de=b(require("chalk"),1),Z=b(require("log-update"),1);var K=b(require("chalk"),1),Q=b(require("inquirer"),1),A=class{async prompt(e,t){let{choice:r}=await Q.default.prompt([{type:"list",name:"choice",message:K.default.cyan(e),choices:t.map(s=>({name:s.label,value:s.id}))}]),o=t.find(s=>s.id===r);if(!o)throw new Error(`Invalid choice: ${r}`);return o}},V=class{async prompt(e,t){let{value:r}=await Q.default.prompt([{type:"input",name:"value",message:K.default.cyan(e),default:t}]);return r}};var _=b(require("boxen"),1),I=b(require("chalk"),1);function ee(n,e,t,r={}){let{borderColor:o="cyan",isNested:s=!1}=r,a;e!==void 0&&(t?a=`line ${e} in ${t}`:a=`line ${e}`);let i=s?`\u2502 ${n}`:`> ${n}`;return(0,_.default)(i,{title:a,borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0},borderColor:o})}function B(n,e=!1,t){let r=n?"\u2713 Completed":"\u2717 Failed",o=n?I.default.green(r):I.default.red(r);if(t!==void 0){let s=D(t);return`${o} ${I.default.gray(`(${s})`)}`}return o}function H(n){return(0,_.default)(`\u2717 ${n}`,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0},borderColor:"red"})}function le(n){return(0,_.default)(`> Starting parallel execution (${n} branches)`,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0},borderColor:"yellow"})}function ce(n){let e=n?"\u2713 All parallel branches completed":"\u2717 Some parallel branches failed";return n?I.default.green(e):I.default.red(e)}function te(n,e=!1){return`${e?"| \u2502 ":"\u2502 "}${n}`}function D(n){return`${(n/1e3).toFixed(3)}s`}var ue=require("fs"),pe=require("path"),j=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,o]of Object.entries(e.var)){let s=this.workspace.getVariable(r),a=this.workspace.getFact(r),i=s??(a!==void 0?a.toString():void 0);if(i===void 0||i!==o)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,pe.resolve)(process.cwd(),t);return(0,ue.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 S=require("fs/promises"),me=require("os"),N=require("path"),fe=b(require("dayjs"),1),L=(0,N.join)((0,me.homedir)(),".pipeliner","workflow-history"),F=class{constructor(){}async saveHistory(e){await(0,S.mkdir)(L,{recursive:!0});let t=(0,fe.default)().format("YYYY-MM-DD_HH-mm-ss"),r=Math.random().toString(36).slice(2,6),o=(0,N.join)(L,`workflow-${t}-${r}.json`);return await(0,S.writeFile)(o,JSON.stringify(e,null,2),{encoding:"utf8"}),o}async clearAllHistories(){await(0,S.rm)(L,{recursive:!0,force:!0})}async removeHistory(e){await(0,S.rm)((0,N.join)(L,e),{force:!0})}async getHistoryNames(){try{let t=(await(0,S.readdir)(L)).map(r=>(0,N.basename)(r));return t.sort((r,o)=>{let s=p=>{let c=p.match(/workflow-(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})-/);return c?c[1]:""},a=s(r),i=s(o);return a===i?o.localeCompare(r):i.localeCompare(a)}),t}catch(e){if(e instanceof Error&&"code"in e&&e.code==="ENOENT")return[];throw e}}async getHistory(e){let t=await(0,S.readFile)((0,N.join)(L,e),{encoding:"utf8"});return JSON.parse(t)}};var J=class{records=[];initialTimestamp=Date.now();recordStartTimestamp=Date.now();constructor(){this.records=[]}recordStart(){this.recordStartTimestamp=Date.now()}recordEnd(e,t,r,o){let s=this.getDuration();return this.records.push({step:e,context:t,output:r,duration:s,status:o}),s}reset(){this.records=[],this.initialTimestamp=Date.now()}async save(){let e=new F,t={initialTimestamp:this.initialTimestamp,records:this.records};return await e.saveHistory(t)}getDuration(){return Date.now()-this.recordStartTimestamp}};var Y=class{async run(e,t,r,o,s=!1,a=!1,i,p,c,m){return s?this.runBuffered(e,c,m):this.runRealtime(e,r||e,a,i,p,c,m)}async runBuffered(e,t,r){let{spawn:o}=await import("child_process"),[s,...a]=this.parseCommand(e),i=this.createSpawnOptions(t);return new Promise((p,c)=>{let m=o(s,a,i),h=[],f=[],d="",w="",v=null;r&&r>0&&(v=setTimeout(()=>{m.kill("SIGTERM");let g=`Command timed out after ${r} seconds`;f.push(g),p({success:!1,stdout:h,stderr:f})},r*1e3)),m.stdout?.on("data",g=>{let y=g.toString(),{lines:C,remaining:k}=this.processStreamBuffer(y,d);h.push(...C),d=k}),m.stderr?.on("data",g=>{let y=g.toString(),{lines:C,remaining:k}=this.processStreamBuffer(y,w);f.push(...C),w=k}),m.on("close",g=>{v&&clearTimeout(v),d.trim()&&h.push(d),w.trim()&&f.push(w),p({success:g===0,stdout:h,stderr:f})}),m.on("error",g=>{v&&clearTimeout(v);let y=`Error: ${g.message}`;p({success:!1,stdout:h,stderr:[...f,y]})})})}async runRealtime(e,t,r,o,s,a,i){let{spawn:p}=await import("child_process"),[c,...m]=this.parseCommand(e),h=this.createSpawnOptions(a),d=ee(t,o,s,{borderColor:r?"green":"cyan"});console.log(d);let w=Date.now();return new Promise(v=>{let g=p(c,m,h),y="",C="",k=null;i&&i>0&&(k=setTimeout(()=>{g.kill("SIGTERM");let R=`Command timed out after ${i} seconds`,x=H(R);console.error(x);let P=Date.now()-w,M=B(!1,!1,P);console.log(M),v(!1)},i*1e3)),g.stdout?.on("data",R=>{let x=R.toString(),{lines:P,remaining:M}=this.processStreamBuffer(x,y);P.forEach(q=>process.stdout.write(`\u2502 ${q}
|
|
3
|
+
`)),y=M}),g.stderr?.on("data",R=>{let x=R.toString(),{lines:P,remaining:M}=this.processStreamBuffer(x,C);P.forEach(q=>process.stderr.write(`\u2502 ${q}
|
|
4
|
+
`)),C=M}),g.on("close",R=>{k&&clearTimeout(k),y.trim()&&process.stdout.write(`\u2502 ${y}
|
|
5
5
|
`),C.trim()&&process.stderr.write(`\u2502 ${C}
|
|
6
|
-
`);let x=R===0,
|
|
7
|
-
`);){let a=
|
|
8
|
-
`),i=
|
|
9
|
-
`).forEach(r=>{r.trim()&&console.log(`| ${r}`)}):console.log(e)}displayBufferedOutput(e,t,r=!1,o,
|
|
10
|
-
`)}),e.stderr.forEach(p=>{let c=
|
|
11
|
-
`)});let i=
|
|
12
|
-
Total execution time: ${
|
|
13
|
-
`)):(0,
|
|
14
|
-
`))}displayParallelResults(e,t,r){let o=!0,
|
|
6
|
+
`);let x=R===0,P=Date.now()-w,M=B(x,!1,P);console.log(M),v(x)}),g.on("error",R=>{k&&clearTimeout(k);let x=H(`Error: ${R.message}`);console.error(x),v(!1)})})}parseCommand(e){let t=e.split(" ");return[t[0],...t.slice(1)]}createSpawnOptions(e){let t={stdio:["inherit","pipe","pipe"],shell:!0};return e&&(t.cwd=e),t}processStreamBuffer(e,t){let r=t+e,o=[],s=r;for(;s.includes(`
|
|
7
|
+
`);){let a=s.indexOf(`
|
|
8
|
+
`),i=s.substring(0,a);s=s.substring(a+1),o.push(i)}return{lines:o,remaining:s}}formatNestedOutput(e,t){t?e.split(`
|
|
9
|
+
`).forEach(r=>{r.trim()&&console.log(`| ${r}`)}):console.log(e)}displayBufferedOutput(e,t,r=!1,o,s){let a=ee(t,o,s,{borderColor:"cyan",isNested:r});this.formatNestedOutput(a,r),e.stdout.forEach(p=>{let c=te(p,r);process.stdout.write(`${c}
|
|
10
|
+
`)}),e.stderr.forEach(p=>{let c=te(p,r);process.stderr.write(`${c}
|
|
11
|
+
`)});let i=B(e.success,r);console.log(i)}};function Be(n,e,t){if(e.hasVariable(n))return e.getVariable(n)||t;if(e.hasFact(n)){let r=e.getFact(n);return typeof r=="string"?r:String(r)}return e.hasChoice(n)&&e.getChoice(n)||t}function z(n,e){let t=/\{\{(\w+)\}\}/g;return n.replace(t,(r,o)=>Be(o,e,r))}var U=class n{state;constructor(){this.state={facts:new Map,choices:new Map,variables:new Map,stepResults:new Map,lastStepIndex:-1}}hasFact(e){return this.state.facts.has(e)}getFact(e){return this.state.facts.get(e)}setFact(e,t){this.state.facts.set(e,t)}getFactStatus(e){if(!this.hasFact(e))return"pending";let t=this.getFact(e);return t===!1||t==="failed"?"failed":"ready"}getAllFacts(){return new Map(this.state.facts)}hasChoice(e){return this.state.choices.has(e)}getChoice(e){return this.state.choices.get(e)}setChoice(e,t){this.state.choices.set(e,t)}hasVariable(e){return this.state.variables.has(e)}getVariable(e){return this.state.variables.get(e)}setVariable(e,t){this.state.variables.set(e,t)}getAllVariables(){return new Map(this.state.variables)}setStepResult(e,t,r){this.state.stepResults.set(e,{success:t,exitCode:r}),this.state.lastStepIndex=e}getStepResult(e){return this.state.stepResults.get(e)}getLastStepResult(){if(this.state.lastStepIndex!==-1)return this.state.stepResults.get(this.state.lastStepIndex)}clone(){let e=new n;return e.state.facts=new Map(this.state.facts),e.state.choices=new Map(this.state.choices),e.state.variables=new Map(this.state.variables),e.state.stepResults=new Map(this.state.stepResults),e.state.lastStepIndex=this.state.lastStepIndex,e}};var G=class n{static PARALLEL_STEP_INDEX_MULTIPLIER=1e3;workspace;taskRunner;choicePrompt;textPrompt;baseDir;constructor(){this.workspace=new U,this.taskRunner=new Y,this.choicePrompt=new A,this.textPrompt=new V}resolveBaseDir(e){if(e.baseDir)if((0,T.isAbsolute)(e.baseDir))this.baseDir=e.baseDir;else if(e._filePath){let t=(0,T.dirname)(e._filePath);this.baseDir=(0,T.resolve)(t,e.baseDir)}else this.baseDir=(0,T.resolve)(process.cwd(),e.baseDir)}createStepContext(e,t){let r={workspace:this.workspace,stepIndex:e};return t._lineNumbers&&(r.lineNumber=t._lineNumbers.get(e)),t._fileName&&(r.fileName=t._fileName),r}evaluateStepCondition(e){return e.when?new j(this.workspace).evaluate(e.when):!0}calculateBaseStepIndex(e){return e.branchIndex===void 0?e.stepIndex:Math.floor(e.stepIndex/n.PARALLEL_STEP_INDEX_MULTIPLIER)}isRunStep(e){return"run"in e}async execute(e){this.resolveBaseDir(e);let t=new J,r=Date.now();for(let a=0;a<e.steps.length;a++){let i=e.steps[a],p=this.createStepContext(a,e),c=!!i.when;if(this.evaluateStepCondition(i)){t.recordStart();try{let m=await this.executeStep(i,p,!1,c);this.handleStepResult(i,p,a,m,t)}catch(m){throw this.handleStepError(i,p,a,m,t),m}}}let o=Date.now()-r,s=D(o);console.log(de.default.cyan(`
|
|
12
|
+
Total execution time: ${s}`)),await t.save(),t.reset()}isStepSuccessful(e,t){return"run"in t?typeof e=="boolean"?e:e&&typeof e=="object"&&"success"in e?e.success:!1:!0}handleStepResult(e,t,r,o,s){let a=this.isRunStep(e)?(()=>{let c=this.workspace.getStepResult(r);return c?c.success:!0})():this.isStepSuccessful(o,e),i=a?"success":"failure",p=s.recordEnd(e,t,o,i);if(!this.isRunStep(e)){let c=B(a,!1,p);console.log(c)}if(this.isRunStep(e)){if(e.continue===!1){let c=t.lineNumber?` (line ${t.lineNumber})`:"",m=a?`Step ${r}${c} completed, but workflow stopped due to continue: false`:`Step ${r}${c} failed`;throw new Error(m)}if(!a&&e.continue!==!0){let c=t.lineNumber?` (line ${t.lineNumber})`:"";throw new Error(`Step ${r}${c} failed`)}}}handleStepError(e,t,r,o,s){this.workspace.setStepResult(r,!1);let a=o instanceof Error?o.message:String(o),i={success:!1,stdout:[],stderr:[a]};s.recordEnd(e,t,i,"failure")}fixMalformedStep(e){let r=e;return"choose"in e&&r.choose===null&&"message"in e&&"options"in e?{choose:{message:r.message,options:r.options,as:r.as},when:r.when}:"prompt"in e&&r.prompt===null&&"message"in e&&"as"in e?{prompt:{message:r.message,as:r.as,default:r.default},when:r.when}:e}async executeStep(e,t,r=!1,o=!1){if(e=this.fixMalformedStep(e),"run"in e){let s=await this.executeRunStep(e,t,r,o);return r&&typeof s=="object"&&"stdout"in s,s}if("choose"in e){await this.executeChooseStep(e,t);return}if("prompt"in e){await this.executePromptStep(e,t);return}if("parallel"in e){await this.executeParallelStep(e,t);return}if("fail"in e){await this.executeFailStep(e,t);return}}async executeSingleRun(e,t,r=!1,o=!1){let s=this.calculateBaseStepIndex(t),a=z(e.run,this.workspace),i=e.retry??0,p=e.timeout,c=!1,m=0;for(;m<=i;){let h=await this.taskRunner.run(a,s,a,t.branchIndex,r,o,t.lineNumber,t.fileName,this.baseDir,p),f=typeof h=="boolean"?h:h.success;if(c=h,f||m>=i)break;if(m++,m<=i){let d=Math.min(1e3*Math.pow(2,m-1),1e4);await new Promise(w=>setTimeout(w,d))}}return c}async executeRunStep(e,t,r=!1,o=!1){let s=await this.executeSingleRun({run:e.run,timeout:e.timeout,retry:e.retry},t,r,o),a=typeof s=="boolean"?s:s.success;if(this.workspace.setStepResult(t.stepIndex,a),a||!e.onError)return s;let i={run:e.onError.run,timeout:e.onError.timeout,retry:e.onError.retry,onError:e.onError.onError??void 0};return await this.executeRunChain(i,t,r,o)}async executeRunChain(e,t,r,o){let s=await this.executeSingleRun({run:e.run,timeout:e.timeout,retry:e.retry},t,r,o);return(typeof s=="boolean"?s:s.success)||!e.onError?s:this.executeRunChain(e.onError,t,r,o)}async executeChooseStep(e,t){let r=await this.choicePrompt.prompt(e.choose.message,e.choose.options);if(!r?.id)throw new Error(`Invalid choice result: ${JSON.stringify(r)}`);let o=e.choose.as??r.id;this.workspace.setChoice(r.id,r.id),this.workspace.setVariable(o,r.id),this.workspace.setStepResult(t.stepIndex,!0)}async executePromptStep(e,t){let r=z(e.prompt.message,this.workspace),o=e.prompt.default?z(e.prompt.default,this.workspace):void 0,s=await this.textPrompt.prompt(r,o);this.workspace.setVariable(e.prompt.as,s),this.workspace.setFact(e.prompt.as,s),this.workspace.setStepResult(t.stepIndex,!0)}createParallelContexts(e,t){return e.parallel.map((r,o)=>({workspace:this.workspace.clone(),stepIndex:t.stepIndex*n.PARALLEL_STEP_INDEX_MULTIPLIER+o,branchIndex:o,lineNumber:t.lineNumber,fileName:t.fileName}))}getBranchDisplayName(e,t){return"run"in e?e.run:"choose"in e?`Choose: ${e.choose.message}`:"prompt"in e?`Prompt: ${e.prompt.message}`:"fail"in e?`Fail: ${e.fail.message}`:`Branch ${t+1}`}async executeParallelBranches(e,t){let r=[],o=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],s=0;for(let c=0;c<e.length;c++){let m=e[c],h=t[c];if(m.when&&!new j(h.workspace).evaluate(m.when))continue;let f=this.getBranchDisplayName(m,c);r.push({index:c,name:f,status:"pending"})}let a=setInterval(()=>{s=(s+1)%o.length,this.updateParallelBranchesDisplay(r,o[s])},100),i=r.map(async c=>{let{index:m}=c,h=e[m],f=t[m];c.status="running";try{let d=await this.executeStep(h,f,!0);return c.status="success",this.updateParallelBranchesDisplay(r,o[s]),{index:m,result:d,context:f}}catch(d){f.workspace.setStepResult(f.stepIndex,!1);let w=d instanceof Error?d.message:String(d);return c.status="failed",c.error=w,this.updateParallelBranchesDisplay(r,o[s]),{index:m,error:d,context:f}}}),p=await Promise.all(i);return clearInterval(a),this.updateParallelBranchesDisplay(r,"",!0),Z.default.done(),p}updateParallelBranchesDisplay(e,t,r=!1){let o=e.map(s=>{let a=s.index+1,i="",p="";switch(s.status){case"pending":i="\u25CB",p=`Branch ${a}: ${s.name} - Pending`;break;case"running":i=t,p=`Branch ${a}: ${s.name} - Running...`;break;case"success":i="\u2713",p=`Branch ${a}: ${s.name} - Completed`;break;case"failed":i="\u2717",p=`Branch ${a}: ${s.name} - Failed${s.error?`: ${s.error}`:""}`;break}return`${i} ${p}`});r?(0,Z.default)(o.join(`
|
|
13
|
+
`)):(0,Z.default)(o.join(`
|
|
14
|
+
`))}displayParallelResults(e,t,r){let o=!0,s=!1;console.log("");for(let i of e){if(!i)continue;s=!0;let{index:p,result:c,error:m,context:h}=i;if(m){o=!1;let f=`Branch ${p+1} failed: ${m instanceof Error?m.message:String(m)}`,d=H(f);console.error(d)}else if(c&&typeof c=="object"&&"stdout"in c){let f=c;if(o=o&&f.success,f.stdout.length>0||f.stderr.length>0||!f.success){let d=t[p],w=this.getBranchDisplayName(d,p);this.taskRunner.displayBufferedOutput(f,w,!1,h.lineNumber,h.fileName)}}}s||console.log("\u26A0\uFE0F All parallel branches were skipped (conditions not met)");let a=ce(o);return console.log(a),o}mergeParallelResults(e){for(let t of e){let r=t.workspace.getAllFacts(),o=t.workspace.getAllVariables();for(let[s,a]of r)this.workspace.setFact(s,a);for(let[s,a]of o)this.workspace.setVariable(s,a)}}countExecutableBranches(e,t){let r=0;for(let o=0;o<e.length;o++){let s=e[o],a=t[o];s.when&&!new j(a.workspace).evaluate(s.when)||r++}return r}async executeParallelStep(e,t){let r=this.createParallelContexts(e,t),o=this.countExecutableBranches(e.parallel,r),s=le(o);console.log(s);let a=await this.executeParallelBranches(e.parallel,r),i=this.displayParallelResults(a,e.parallel,t);if(this.workspace.setStepResult(t.stepIndex,i),!i){let p=t.lineNumber?` (line ${t.lineNumber})`:"";throw new Error(`Parallel step ${t.stepIndex}${p} failed: one or more branches failed`)}this.mergeParallelResults(r)}async executeFailStep(e,t){let r=new Error(e.fail.message);throw r.stack=void 0,r}};var we=require("yaml"),ne=require("zod");var l=require("zod"),De=l.z.object({file:l.z.string()}),je=l.z.object({var:l.z.union([l.z.string(),l.z.record(l.z.string(),l.z.string())]).optional(),has:l.z.string().optional()}),Le=l.z.object({status:l.z.object({fact:l.z.string(),is:l.z.enum(["ready","failed","pending"])})}),Fe=l.z.object({step:l.z.object({success:l.z.boolean()}).optional(),last_step:l.z.enum(["success","failure"]).optional()}),We=l.z.object({choice:l.z.string()}),He=l.z.union([De,We,je,Le,Fe]),$=l.z.lazy(()=>l.z.union([He,l.z.object({all:l.z.array($)}),l.z.object({any:l.z.array($)}),l.z.object({not:$})])),he=l.z.lazy(()=>l.z.object({run:l.z.string(),timeout:l.z.number().optional(),retry:l.z.number().optional(),onError:he.optional()})),Oe=l.z.object({run:l.z.string(),when:$.optional(),timeout:l.z.number().optional(),retry:l.z.number().optional(),continue:l.z.boolean().optional(),onError:he.optional()}),Ve=l.z.object({choose:l.z.object({message:l.z.string(),options:l.z.array(l.z.object({id:l.z.string(),label:l.z.string()})),as:l.z.string().optional()}),when:$.optional()}),_e=l.z.object({prompt:l.z.object({message:l.z.string(),as:l.z.string(),default:l.z.string().optional(),validate:l.z.string().optional()}),when:$.optional()}),ge=l.z.lazy(()=>l.z.union([Oe,Ve,_e,l.z.object({parallel:l.z.array(ge),when:$.optional()}),l.z.object({fail:l.z.object({message:l.z.string()}),when:$.optional()})])),Je=l.z.object({name:l.z.string().optional(),baseDir:l.z.string().optional(),steps:l.z.array(ge).min(1,"Workflow must have at least one step")});function re(n){return Je.parse(n)}function se(n){let e=n;return"choose"in e&&(e.choose===null||e.choose===void 0)&&"message"in e&&"options"in e?{choose:{message:e.message,options:e.options,as:e.as},when:e.when}:"prompt"in e&&(e.prompt===null||e.prompt===void 0)&&"message"in e&&"as"in e?{prompt:{message:e.message,as:e.as,default:e.default,validate:e.validate},when:e.when}:"parallel"in e&&Array.isArray(e.parallel)?{...e,parallel:e.parallel.map(t=>se(t))}:n}var X=class{parse(e){let t;try{t=(0,we.parse)(e)}catch(r){throw new Error(`Invalid YAML format: ${r instanceof Error?r.message:String(r)}`)}if(t&&typeof t=="object"&&"steps"in t){let r=t;Array.isArray(r.steps)&&(r.steps=r.steps.map(o=>se(o)))}try{return re(t)}catch(r){if(r instanceof ne.ZodError){let o=r.issues.map(s=>{let a=s.path.length>0?` at ${s.path.join(".")}`:"";return` - ${s.message}${a}`}).join(`
|
|
15
15
|
`);throw new Error(`Invalid workflow structure:
|
|
16
16
|
${o}`)}throw r}}extractStepLineNumbers(e){let t=new Map,r=e.split(`
|
|
17
|
-
`),o=0,
|
|
17
|
+
`),o=0,s=!1;for(let a=0;a<r.length;a++){let i=r[a].trim();if(i==="steps:"||i.startsWith("steps:")){s=!0;continue}s&&i.startsWith("-")&&t.set(o++,a+1)}return t}},oe=class{parse(e){let t;try{t=JSON.parse(e)}catch(r){throw new Error(`Invalid JSON format: ${r instanceof Error?r.message:String(r)}`)}if(t&&typeof t=="object"&&"steps"in t){let r=t;Array.isArray(r.steps)&&(r.steps=r.steps.map(o=>se(o)))}try{return re(t)}catch(r){if(r instanceof ne.ZodError){let o=r.issues.map(s=>{let a=s.path.length>0?` at ${s.path.join(".")}`:"";return` - ${s.message}${a}`}).join(`
|
|
18
18
|
`);throw new Error(`Invalid workflow structure:
|
|
19
19
|
${o}`)}throw r}}extractStepLineNumbers(e){let t=new Map,r=e.split(`
|
|
20
|
-
`),o=0,
|
|
20
|
+
`),o=0,s=!1,a=!1;for(let i=0;i<r.length;i++){let c=r[i].trim();if(c.startsWith('"steps"')||c.startsWith("'steps'")){s=!0,c.includes("[")&&(a=!0);continue}if(s&&c==="["){a=!0;continue}if(a&&c==="]"){a=!1,s=!1;continue}a&&c.startsWith("{")&&t.set(o++,i+1)}return t}};function be(n){switch(n.toLowerCase().split(".").pop()){case"yaml":case"yml":return new X;case"json":return new oe;default:return new X}}var W=require("fs"),E=require("path"),ye=require("url"),Ye={};function Se(){console.log=()=>{},console.error=()=>{},console.warn=()=>{},console.info=()=>{},process.stdout.write=()=>!0,process.stderr.write=()=>!0}function xe(){let n=process,e=typeof process<"u"&&n.pkg!==void 0;try{if(e){let t=[(0,E.resolve)((0,E.dirname)(process.execPath),"package.json"),"/snapshot/task-pipeliner/package.json",n.pkg?.entrypoint?(0,E.resolve)((0,E.dirname)(n.pkg.entrypoint),"package.json"):null].filter(r=>r!==null);for(let r of t)try{if((0,W.existsSync)(r))return JSON.parse((0,W.readFileSync)(r,"utf-8")).version??"0.0.0"}catch{continue}}else try{let t=(0,ye.fileURLToPath)(Ye.url),r=(0,E.dirname)(t),o=(0,E.resolve)(r,"../../package.json");if((0,W.existsSync)(o))return JSON.parse((0,W.readFileSync)(o,"utf-8")).version??"0.0.0"}catch{}}catch{}return"0.0.0"}var ze=(0,Ce.promisify)(ve.exec),O=new $e.Command;O.name("task-pipeliner").description(`A powerful task pipeline runner with condition-based workflow execution.
|
|
21
21
|
|
|
22
22
|
Define workflows in YAML or JSON files with conditional execution, parallel tasks,
|
|
23
23
|
interactive prompts, and variable substitution.
|
|
@@ -55,7 +55,7 @@ Quick Start:
|
|
|
55
55
|
tp history remove # Remove a specific history
|
|
56
56
|
tp history remove-all # Remove all histories
|
|
57
57
|
|
|
58
|
-
`).version(
|
|
58
|
+
`).version(xe()).addHelpText("after",`
|
|
59
59
|
Examples:
|
|
60
60
|
$ tp run workflow.yaml
|
|
61
61
|
$ tp run examples/simple-project/workflow.yaml
|
|
@@ -68,7 +68,7 @@ Resources:
|
|
|
68
68
|
\u{1F4DA} Documentation: https://task-pipeliner.racgoo.com/
|
|
69
69
|
\u{1F3A8} Visual Generator: https://task-pipeliner-generator.racgoo.com/
|
|
70
70
|
|
|
71
|
-
See README.md for complete DSL reference.`);
|
|
71
|
+
See README.md for complete DSL reference.`);O.command("run").description("Run a workflow from a YAML or JSON file").argument("<file>","Path to the workflow file (YAML or JSON, relative or absolute)").option("-s, --silent","Run in silent mode (suppress console output)").addHelpText("after",`
|
|
72
72
|
Examples:
|
|
73
73
|
$ tp run workflow.yaml
|
|
74
74
|
$ tp run workflow.json
|
|
@@ -92,36 +92,36 @@ Workflow File Structure:
|
|
|
92
92
|
\u2022 all/any/not: Combine conditions
|
|
93
93
|
|
|
94
94
|
Supported formats: YAML (.yaml, .yml) and JSON (.json)
|
|
95
|
-
See README.md for complete DSL documentation.`).action(async(
|
|
96
|
-
`)),await new
|
|
95
|
+
See README.md for complete DSL documentation.`).action(async(n,e)=>{e.silent&&Se();try{let t=be(n);console.log(u.default.blue(`Loading workflow from ${n}...`));let r=(0,ke.readFileSync)(n,"utf-8"),o=t.parse(r);if(!o.steps||!Array.isArray(o.steps))throw new Error("Invalid workflow: steps array is required");o._lineNumbers=t.extractStepLineNumbers(r),o._fileName=Ze(n),o._filePath=(0,Re.resolve)(n),console.log(u.default.green(`Starting workflow execution...
|
|
96
|
+
`)),await new G().execute(o),console.log(u.default.green(`
|
|
97
97
|
\u2713 Workflow completed successfully`))}catch(t){let r=t instanceof Error?t.message:String(t);console.error(u.default.red(`
|
|
98
|
-
\u2717 Workflow failed: ${r}`)),process.exit(1)}});
|
|
98
|
+
\u2717 Workflow failed: ${r}`)),process.exit(1)}});O.command("open").description("Open generator or docs website in browser").argument("<target>",'Target to open: "generator" or "docs"').addHelpText("after",`
|
|
99
99
|
Examples:
|
|
100
100
|
$ tp open generator
|
|
101
101
|
$ tp open docs
|
|
102
102
|
|
|
103
103
|
Targets:
|
|
104
104
|
generator Open the visual workflow generator (https://task-pipeliner-generator.racgoo.com/)
|
|
105
|
-
docs Open the documentation site (https://task-pipeliner.racgoo.com/)`).action(async
|
|
106
|
-
\u2717 Invalid target: ${
|
|
107
|
-
Valid targets:`)),console.log(u.default.yellow(" \u2022 generator - Open the visual workflow generator")),console.log(u.default.yellow(" \u2022 docs - Open the documentation site")),process.exit(1));try{let r=process.platform,o;r==="darwin"?o=`open "${t}"`:r==="win32"?o=`start "${t}"`:o=`xdg-open "${t}"`,await
|
|
108
|
-
\u2713 Opening ${
|
|
105
|
+
docs Open the documentation site (https://task-pipeliner.racgoo.com/)`).action(async n=>{let t={generator:"https://task-pipeliner-generator.racgoo.com/",docs:"https://task-pipeliner.racgoo.com/"}[n.toLowerCase()];t||(console.error(u.default.red(`
|
|
106
|
+
\u2717 Invalid target: ${n}`)),console.log(u.default.yellow(`
|
|
107
|
+
Valid targets:`)),console.log(u.default.yellow(" \u2022 generator - Open the visual workflow generator")),console.log(u.default.yellow(" \u2022 docs - Open the documentation site")),process.exit(1));try{let r=process.platform,o;r==="darwin"?o=`open "${t}"`:r==="win32"?o=`start "${t}"`:o=`xdg-open "${t}"`,await ze(o),console.log(u.default.green(`
|
|
108
|
+
\u2713 Opening ${n==="generator"?"generator":"documentation"} in browser...`)),console.log(u.default.blue(` ${t}`))}catch(r){let o=r instanceof Error?r.message:String(r);console.error(u.default.red(`
|
|
109
109
|
\u2717 Failed to open browser: ${o}`)),console.log(u.default.yellow(`
|
|
110
|
-
Please visit manually: ${t}`)),process.exit(1)}});var
|
|
111
|
-
\u2717 Invalid choice`)),process.exit(1));let t=new
|
|
112
|
-
\u26A0 No history found`));return}let o=await
|
|
113
|
-
\u2717 Invalid choice`)),process.exit(1));try{let
|
|
110
|
+
Please visit manually: ${t}`)),process.exit(1)}});var Ue=O.command("history").description("Manage workflow execution history");Ue.action(async()=>{let n=new A,e=await n.prompt("Select an action",[{id:"show",label:"Show - View and select a history to view"},{id:"remove",label:"Remove - Delete a specific history file"},{id:"remove-all",label:"Remove All - Delete all history files"}]);e?.id||(console.error(u.default.red(`
|
|
111
|
+
\u2717 Invalid choice`)),process.exit(1));let t=new F;switch(e.id){case"show":{let r=await t.getHistoryNames();if(r.length===0){console.log(u.default.yellow(`
|
|
112
|
+
\u26A0 No history found`));return}let o=await n.prompt("Select a history to view",r.map(s=>({id:s,label:s})));o?.id||(console.error(u.default.red(`
|
|
113
|
+
\u2717 Invalid choice`)),process.exit(1));try{let s=await t.getHistory(o.id);Ge(s,o.id)}catch(s){let a=s instanceof Error?s.message:String(s);console.error(u.default.red(`
|
|
114
114
|
\u2717 Failed to load history: ${a}`)),process.exit(1)}break}case"remove":{let r=await t.getHistoryNames();if(r.length===0){console.log(u.default.yellow(`
|
|
115
|
-
\u26A0 No history found`));return}let o=await
|
|
115
|
+
\u26A0 No history found`));return}let o=await n.prompt("Select a history to remove",r.map(s=>({id:s,label:s})));o?.id||(console.error(u.default.red(`
|
|
116
116
|
\u2717 Invalid choice`)),process.exit(1));try{await t.removeHistory(o.id),console.log(u.default.green(`
|
|
117
|
-
\u2713 Removed history: ${o.id}`))}catch(
|
|
118
|
-
\u2717 Failed to remove history: ${a}`)),process.exit(1)}break}case"remove-all":{if((await
|
|
117
|
+
\u2713 Removed history: ${o.id}`))}catch(s){let a=s instanceof Error?s.message:String(s);console.error(u.default.red(`
|
|
118
|
+
\u2717 Failed to remove history: ${a}`)),process.exit(1)}break}case"remove-all":{if((await n.prompt("Are you sure you want to remove all histories?",[{id:"yes",label:"Yes, remove all"},{id:"no",label:"No, cancel"}]))?.id!=="yes"){console.log(u.default.yellow(`
|
|
119
119
|
\u2717 Cancelled`));return}try{await t.clearAllHistories(),console.log(u.default.green(`
|
|
120
|
-
\u2713 All histories removed`))}catch(o){let
|
|
121
|
-
\u2717 Failed to remove histories: ${
|
|
122
|
-
\u2717 Unknown action: ${e.id}`)),process.exit(1)}});function
|
|
123
|
-
`);let t=
|
|
124
|
-
`);console.log((0,
|
|
125
|
-
`);console.log((0,
|
|
126
|
-
`);console.log(u.default.green(" Output:")),console.log(e)}if(
|
|
127
|
-
`);console.log(u.default.red(" Errors:")),console.log(e)}}
|
|
120
|
+
\u2713 All histories removed`))}catch(o){let s=o instanceof Error?o.message:String(o);console.error(u.default.red(`
|
|
121
|
+
\u2717 Failed to remove histories: ${s}`)),process.exit(1)}break}default:console.error(u.default.red(`
|
|
122
|
+
\u2717 Unknown action: ${e.id}`)),process.exit(1)}});function Ze(n){return n.split("/").pop()??n}function Ge(n,e){console.log(`
|
|
123
|
+
`);let t=n.records.reduce((c,m)=>c+m.duration,0),r=n.records.filter(c=>c.status==="success").length,o=n.records.filter(c=>c.status==="failure").length,s=(0,Ee.default)(n.initialTimestamp).format("YYYY-MM-DD HH:mm:ss"),i=D(t),p=[u.default.bold("Workflow Execution History"),"",`${u.default.cyan("File:")} ${e}`,`${u.default.cyan("Started:")} ${s}`,`${u.default.cyan("Total Duration:")} ${i}`,`${u.default.cyan("Total Steps:")} ${n.records.length}`,`${u.default.green("\u2713 Successful:")} ${r}`,o>0?`${u.default.red("\u2717 Failed:")} ${o}`:""].filter(Boolean).join(`
|
|
124
|
+
`);console.log((0,ae.default)(p,{borderStyle:"round",padding:{top:1,bottom:1,left:2,right:2},margin:{top:0,bottom:1},borderColor:"cyan"})),n.records.forEach((c,m)=>{Xe(c,m+1,n.records.length)}),console.log("")}function Xe(n,e,t){let r=qe(n.step),o=Ke(n.step),s=n.status==="success"?u.default.green("\u2713"):u.default.red("\u2717"),a=n.status==="success"?u.default.green("Success"):u.default.red("Failed"),i=D(n.duration),p=[`${s} ${u.default.bold(`Step ${e}/${t}`)} - ${u.default.cyan(r)}`,`${u.default.gray("Duration:")} ${i} | ${u.default.gray("Status:")} ${a}`,"",u.default.white(o)].join(`
|
|
125
|
+
`);console.log((0,ae.default)(p,{borderStyle:"round",padding:{top:1,bottom:1,left:2,right:2},margin:{top:0,bottom:1},borderColor:n.status==="success"?"green":"red"})),Qe(n.output)&&et(n.output)}function qe(n){return"run"in n?"Run":"choose"in n?"Choose":"prompt"in n?"Prompt":"parallel"in n?"Parallel":"fail"in n?"Fail":"Unknown"}function Ke(n){return"run"in n?`Command: ${u.default.yellow(n.run)}`:"choose"in n?`Message: ${u.default.yellow(n.choose.message)}`:"prompt"in n?`Message: ${u.default.yellow(n.prompt.message)} | Variable: ${u.default.cyan(n.prompt.as)}`:"parallel"in n?`Parallel execution with ${n.parallel.length} branches`:"fail"in n?`Error: ${u.default.red(n.fail.message)}`:"Unknown step type"}function Qe(n){return typeof n=="object"&&n!==null&&"success"in n&&"stdout"in n&&"stderr"in n}function et(n){if(n.stdout.length>0){let e=n.stdout.map(t=>u.default.gray(` ${t}`)).join(`
|
|
126
|
+
`);console.log(u.default.green(" Output:")),console.log(e)}if(n.stderr.length>0){let e=n.stderr.map(t=>u.default.gray(` ${t}`)).join(`
|
|
127
|
+
`);console.log(u.default.red(" Errors:")),console.log(e)}}O.parse();
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{exec as
|
|
3
|
-
`)),b=$}),g.stderr?.on("data",v=>{let y=v.toString(),{lines:C,remaining:$}=this.processStreamBuffer(y,k);C.forEach(
|
|
2
|
+
import{exec as He}from"child_process";import{readFileSync as Oe}from"fs";import{resolve as Ve}from"path";import{promisify as _e}from"util";import de from"boxen";import u from"chalk";import{Command as Je}from"commander";import Ye from"dayjs";import{resolve as se,isAbsolute as Ce,dirname as $e}from"path";import Ee from"chalk";import Z from"log-update";import ee from"chalk";import te from"inquirer";var E=class{async prompt(e,t){let{choice:r}=await te.prompt([{type:"list",name:"choice",message:ee.cyan(e),choices:t.map(n=>({name:n.label,value:n.id}))}]),o=t.find(n=>n.id===r);if(!o)throw new Error(`Invalid choice: ${r}`);return o}},j=class{async prompt(e,t){let{value:r}=await te.prompt([{type:"input",name:"value",message:ee.cyan(e),default:t}]);return r}};import Y from"boxen";import I from"chalk";function z(s,e,t,r={}){let{borderColor:o="cyan",isNested:n=!1}=r,a;e!==void 0&&(t?a=`line ${e} in ${t}`:a=`line ${e}`);let i=n?`\u2502 ${s}`:`> ${s}`;return Y(i,{title:a,borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0},borderColor:o})}function P(s,e=!1,t){let r=s?"\u2713 Completed":"\u2717 Failed",o=s?I.green(r):I.red(r);if(t!==void 0){let n=M(t);return`${o} ${I.gray(`(${n})`)}`}return o}function B(s){return Y(`\u2717 ${s}`,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0},borderColor:"red"})}function re(s){return Y(`> Starting parallel execution (${s} branches)`,{borderStyle:"round",padding:{top:0,bottom:0,left:1,right:1},margin:{top:0,bottom:0},borderColor:"yellow"})}function oe(s){let e=s?"\u2713 All parallel branches completed":"\u2717 Some parallel branches failed";return s?I.green(e):I.red(e)}function U(s,e=!1){return`${e?"| \u2502 ":"\u2502 "}${s}`}function M(s){return`${(s/1e3).toFixed(3)}s`}import{existsSync as he}from"fs";import{resolve as ge}from"path";var N=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,o]of Object.entries(e.var)){let n=this.workspace.getVariable(r),a=this.workspace.getFact(r),i=n??(a!==void 0?a.toString():void 0);if(i===void 0||i!==o)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=ge(process.cwd(),t);return he(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)}};import{mkdir as we,readdir as be,readFile as ye,rm as ne,writeFile as Se}from"fs/promises";import{homedir as xe}from"os";import{basename as ve,join as L}from"path";import ke from"dayjs";var T=L(xe(),".pipeliner","workflow-history"),A=class{constructor(){}async saveHistory(e){await we(T,{recursive:!0});let t=ke().format("YYYY-MM-DD_HH-mm-ss"),r=Math.random().toString(36).slice(2,6),o=L(T,`workflow-${t}-${r}.json`);return await Se(o,JSON.stringify(e,null,2),{encoding:"utf8"}),o}async clearAllHistories(){await ne(T,{recursive:!0,force:!0})}async removeHistory(e){await ne(L(T,e),{force:!0})}async getHistoryNames(){try{let t=(await be(T)).map(r=>ve(r));return t.sort((r,o)=>{let n=p=>{let c=p.match(/workflow-(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})-/);return c?c[1]:""},a=n(r),i=n(o);return a===i?o.localeCompare(r):i.localeCompare(a)}),t}catch(e){if(e instanceof Error&&"code"in e&&e.code==="ENOENT")return[];throw e}}async getHistory(e){let t=await ye(L(T,e),{encoding:"utf8"});return JSON.parse(t)}};var F=class{records=[];initialTimestamp=Date.now();recordStartTimestamp=Date.now();constructor(){this.records=[]}recordStart(){this.recordStartTimestamp=Date.now()}recordEnd(e,t,r,o){let n=this.getDuration();return this.records.push({step:e,context:t,output:r,duration:n,status:o}),n}reset(){this.records=[],this.initialTimestamp=Date.now()}async save(){let e=new A,t={initialTimestamp:this.initialTimestamp,records:this.records};return await e.saveHistory(t)}getDuration(){return Date.now()-this.recordStartTimestamp}};var W=class{async run(e,t,r,o,n=!1,a=!1,i,p,c,m){return n?this.runBuffered(e,c,m):this.runRealtime(e,r||e,a,i,p,c,m)}async runBuffered(e,t,r){let{spawn:o}=await import("child_process"),[n,...a]=this.parseCommand(e),i=this.createSpawnOptions(t);return new Promise((p,c)=>{let m=o(n,a,i),h=[],f=[],d="",w="",S=null;r&&r>0&&(S=setTimeout(()=>{m.kill("SIGTERM");let g=`Command timed out after ${r} seconds`;f.push(g),p({success:!1,stdout:h,stderr:f})},r*1e3)),m.stdout?.on("data",g=>{let b=g.toString(),{lines:k,remaining:x}=this.processStreamBuffer(b,d);h.push(...k),d=x}),m.stderr?.on("data",g=>{let b=g.toString(),{lines:k,remaining:x}=this.processStreamBuffer(b,w);f.push(...k),w=x}),m.on("close",g=>{S&&clearTimeout(S),d.trim()&&h.push(d),w.trim()&&f.push(w),p({success:g===0,stdout:h,stderr:f})}),m.on("error",g=>{S&&clearTimeout(S);let b=`Error: ${g.message}`;p({success:!1,stdout:h,stderr:[...f,b]})})})}async runRealtime(e,t,r,o,n,a,i){let{spawn:p}=await import("child_process"),[c,...m]=this.parseCommand(e),h=this.createSpawnOptions(a),d=z(t,o,n,{borderColor:r?"green":"cyan"});console.log(d);let w=Date.now();return new Promise(S=>{let g=p(c,m,h),b="",k="",x=null;i&&i>0&&(x=setTimeout(()=>{g.kill("SIGTERM");let v=`Command timed out after ${i} seconds`,y=B(v);console.error(y);let C=Date.now()-w,$=P(!1,!1,C);console.log($),S(!1)},i*1e3)),g.stdout?.on("data",v=>{let y=v.toString(),{lines:C,remaining:$}=this.processStreamBuffer(y,b);C.forEach(J=>process.stdout.write(`\u2502 ${J}
|
|
3
|
+
`)),b=$}),g.stderr?.on("data",v=>{let y=v.toString(),{lines:C,remaining:$}=this.processStreamBuffer(y,k);C.forEach(J=>process.stderr.write(`\u2502 ${J}
|
|
4
4
|
`)),k=$}),g.on("close",v=>{x&&clearTimeout(x),b.trim()&&process.stdout.write(`\u2502 ${b}
|
|
5
5
|
`),k.trim()&&process.stderr.write(`\u2502 ${k}
|
|
6
|
-
`);let y=v===0,C=Date.now()-w,$=P(y,!1,C);console.log($),S(y)}),g.on("error",v=>{x&&clearTimeout(x);let y=B(`Error: ${v.message}`);console.error(y),S(!1)})})}parseCommand(e){let t=e.split(" ");return[t[0],...t.slice(1)]}createSpawnOptions(e){let t={stdio:["inherit","pipe","pipe"],shell:!0};return e&&(t.cwd=e),t}processStreamBuffer(e,t){let r=t+e,
|
|
7
|
-
`);){let a=
|
|
8
|
-
`),i=
|
|
9
|
-
`).forEach(r=>{r.trim()&&console.log(`| ${r}`)}):console.log(e)}displayBufferedOutput(e,t,r=!1,n
|
|
6
|
+
`);let y=v===0,C=Date.now()-w,$=P(y,!1,C);console.log($),S(y)}),g.on("error",v=>{x&&clearTimeout(x);let y=B(`Error: ${v.message}`);console.error(y),S(!1)})})}parseCommand(e){let t=e.split(" ");return[t[0],...t.slice(1)]}createSpawnOptions(e){let t={stdio:["inherit","pipe","pipe"],shell:!0};return e&&(t.cwd=e),t}processStreamBuffer(e,t){let r=t+e,o=[],n=r;for(;n.includes(`
|
|
7
|
+
`);){let a=n.indexOf(`
|
|
8
|
+
`),i=n.substring(0,a);n=n.substring(a+1),o.push(i)}return{lines:o,remaining:n}}formatNestedOutput(e,t){t?e.split(`
|
|
9
|
+
`).forEach(r=>{r.trim()&&console.log(`| ${r}`)}):console.log(e)}displayBufferedOutput(e,t,r=!1,o,n){let a=z(t,o,n,{borderColor:"cyan",isNested:r});this.formatNestedOutput(a,r),e.stdout.forEach(p=>{let c=U(p,r);process.stdout.write(`${c}
|
|
10
10
|
`)}),e.stderr.forEach(p=>{let c=U(p,r);process.stderr.write(`${c}
|
|
11
|
-
`)});let i=P(e.success,r);console.log(i)}};function
|
|
12
|
-
Total execution time: ${
|
|
13
|
-
`)):Z(
|
|
14
|
-
`))}displayParallelResults(e,t,r){let
|
|
11
|
+
`)});let i=P(e.success,r);console.log(i)}};function Re(s,e,t){if(e.hasVariable(s))return e.getVariable(s)||t;if(e.hasFact(s)){let r=e.getFact(s);return typeof r=="string"?r:String(r)}return e.hasChoice(s)&&e.getChoice(s)||t}function H(s,e){let t=/\{\{(\w+)\}\}/g;return s.replace(t,(r,o)=>Re(o,e,r))}var O=class s{state;constructor(){this.state={facts:new Map,choices:new Map,variables:new Map,stepResults:new Map,lastStepIndex:-1}}hasFact(e){return this.state.facts.has(e)}getFact(e){return this.state.facts.get(e)}setFact(e,t){this.state.facts.set(e,t)}getFactStatus(e){if(!this.hasFact(e))return"pending";let t=this.getFact(e);return t===!1||t==="failed"?"failed":"ready"}getAllFacts(){return new Map(this.state.facts)}hasChoice(e){return this.state.choices.has(e)}getChoice(e){return this.state.choices.get(e)}setChoice(e,t){this.state.choices.set(e,t)}hasVariable(e){return this.state.variables.has(e)}getVariable(e){return this.state.variables.get(e)}setVariable(e,t){this.state.variables.set(e,t)}getAllVariables(){return new Map(this.state.variables)}setStepResult(e,t,r){this.state.stepResults.set(e,{success:t,exitCode:r}),this.state.lastStepIndex=e}getStepResult(e){return this.state.stepResults.get(e)}getLastStepResult(){if(this.state.lastStepIndex!==-1)return this.state.stepResults.get(this.state.lastStepIndex)}clone(){let e=new s;return e.state.facts=new Map(this.state.facts),e.state.choices=new Map(this.state.choices),e.state.variables=new Map(this.state.variables),e.state.stepResults=new Map(this.state.stepResults),e.state.lastStepIndex=this.state.lastStepIndex,e}};var V=class s{static PARALLEL_STEP_INDEX_MULTIPLIER=1e3;workspace;taskRunner;choicePrompt;textPrompt;baseDir;constructor(){this.workspace=new O,this.taskRunner=new W,this.choicePrompt=new E,this.textPrompt=new j}resolveBaseDir(e){if(e.baseDir)if(Ce(e.baseDir))this.baseDir=e.baseDir;else if(e._filePath){let t=$e(e._filePath);this.baseDir=se(t,e.baseDir)}else this.baseDir=se(process.cwd(),e.baseDir)}createStepContext(e,t){let r={workspace:this.workspace,stepIndex:e};return t._lineNumbers&&(r.lineNumber=t._lineNumbers.get(e)),t._fileName&&(r.fileName=t._fileName),r}evaluateStepCondition(e){return e.when?new N(this.workspace).evaluate(e.when):!0}calculateBaseStepIndex(e){return e.branchIndex===void 0?e.stepIndex:Math.floor(e.stepIndex/s.PARALLEL_STEP_INDEX_MULTIPLIER)}isRunStep(e){return"run"in e}async execute(e){this.resolveBaseDir(e);let t=new F,r=Date.now();for(let a=0;a<e.steps.length;a++){let i=e.steps[a],p=this.createStepContext(a,e),c=!!i.when;if(this.evaluateStepCondition(i)){t.recordStart();try{let m=await this.executeStep(i,p,!1,c);this.handleStepResult(i,p,a,m,t)}catch(m){throw this.handleStepError(i,p,a,m,t),m}}}let o=Date.now()-r,n=M(o);console.log(Ee.cyan(`
|
|
12
|
+
Total execution time: ${n}`)),await t.save(),t.reset()}isStepSuccessful(e,t){return"run"in t?typeof e=="boolean"?e:e&&typeof e=="object"&&"success"in e?e.success:!1:!0}handleStepResult(e,t,r,o,n){let a=this.isRunStep(e)?(()=>{let c=this.workspace.getStepResult(r);return c?c.success:!0})():this.isStepSuccessful(o,e),i=a?"success":"failure",p=n.recordEnd(e,t,o,i);if(!this.isRunStep(e)){let c=P(a,!1,p);console.log(c)}if(this.isRunStep(e)){if(e.continue===!1){let c=t.lineNumber?` (line ${t.lineNumber})`:"",m=a?`Step ${r}${c} completed, but workflow stopped due to continue: false`:`Step ${r}${c} failed`;throw new Error(m)}if(!a&&e.continue!==!0){let c=t.lineNumber?` (line ${t.lineNumber})`:"";throw new Error(`Step ${r}${c} failed`)}}}handleStepError(e,t,r,o,n){this.workspace.setStepResult(r,!1);let a=o instanceof Error?o.message:String(o),i={success:!1,stdout:[],stderr:[a]};n.recordEnd(e,t,i,"failure")}fixMalformedStep(e){let r=e;return"choose"in e&&r.choose===null&&"message"in e&&"options"in e?{choose:{message:r.message,options:r.options,as:r.as},when:r.when}:"prompt"in e&&r.prompt===null&&"message"in e&&"as"in e?{prompt:{message:r.message,as:r.as,default:r.default},when:r.when}:e}async executeStep(e,t,r=!1,o=!1){if(e=this.fixMalformedStep(e),"run"in e){let n=await this.executeRunStep(e,t,r,o);return r&&typeof n=="object"&&"stdout"in n,n}if("choose"in e){await this.executeChooseStep(e,t);return}if("prompt"in e){await this.executePromptStep(e,t);return}if("parallel"in e){await this.executeParallelStep(e,t);return}if("fail"in e){await this.executeFailStep(e,t);return}}async executeSingleRun(e,t,r=!1,o=!1){let n=this.calculateBaseStepIndex(t),a=H(e.run,this.workspace),i=e.retry??0,p=e.timeout,c=!1,m=0;for(;m<=i;){let h=await this.taskRunner.run(a,n,a,t.branchIndex,r,o,t.lineNumber,t.fileName,this.baseDir,p),f=typeof h=="boolean"?h:h.success;if(c=h,f||m>=i)break;if(m++,m<=i){let d=Math.min(1e3*Math.pow(2,m-1),1e4);await new Promise(w=>setTimeout(w,d))}}return c}async executeRunStep(e,t,r=!1,o=!1){let n=await this.executeSingleRun({run:e.run,timeout:e.timeout,retry:e.retry},t,r,o),a=typeof n=="boolean"?n:n.success;if(this.workspace.setStepResult(t.stepIndex,a),a||!e.onError)return n;let i={run:e.onError.run,timeout:e.onError.timeout,retry:e.onError.retry,onError:e.onError.onError??void 0};return await this.executeRunChain(i,t,r,o)}async executeRunChain(e,t,r,o){let n=await this.executeSingleRun({run:e.run,timeout:e.timeout,retry:e.retry},t,r,o);return(typeof n=="boolean"?n:n.success)||!e.onError?n:this.executeRunChain(e.onError,t,r,o)}async executeChooseStep(e,t){let r=await this.choicePrompt.prompt(e.choose.message,e.choose.options);if(!r?.id)throw new Error(`Invalid choice result: ${JSON.stringify(r)}`);let o=e.choose.as??r.id;this.workspace.setChoice(r.id,r.id),this.workspace.setVariable(o,r.id),this.workspace.setStepResult(t.stepIndex,!0)}async executePromptStep(e,t){let r=H(e.prompt.message,this.workspace),o=e.prompt.default?H(e.prompt.default,this.workspace):void 0,n=await this.textPrompt.prompt(r,o);this.workspace.setVariable(e.prompt.as,n),this.workspace.setFact(e.prompt.as,n),this.workspace.setStepResult(t.stepIndex,!0)}createParallelContexts(e,t){return e.parallel.map((r,o)=>({workspace:this.workspace.clone(),stepIndex:t.stepIndex*s.PARALLEL_STEP_INDEX_MULTIPLIER+o,branchIndex:o,lineNumber:t.lineNumber,fileName:t.fileName}))}getBranchDisplayName(e,t){return"run"in e?e.run:"choose"in e?`Choose: ${e.choose.message}`:"prompt"in e?`Prompt: ${e.prompt.message}`:"fail"in e?`Fail: ${e.fail.message}`:`Branch ${t+1}`}async executeParallelBranches(e,t){let r=[],o=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],n=0;for(let c=0;c<e.length;c++){let m=e[c],h=t[c];if(m.when&&!new N(h.workspace).evaluate(m.when))continue;let f=this.getBranchDisplayName(m,c);r.push({index:c,name:f,status:"pending"})}let a=setInterval(()=>{n=(n+1)%o.length,this.updateParallelBranchesDisplay(r,o[n])},100),i=r.map(async c=>{let{index:m}=c,h=e[m],f=t[m];c.status="running";try{let d=await this.executeStep(h,f,!0);return c.status="success",this.updateParallelBranchesDisplay(r,o[n]),{index:m,result:d,context:f}}catch(d){f.workspace.setStepResult(f.stepIndex,!1);let w=d instanceof Error?d.message:String(d);return c.status="failed",c.error=w,this.updateParallelBranchesDisplay(r,o[n]),{index:m,error:d,context:f}}}),p=await Promise.all(i);return clearInterval(a),this.updateParallelBranchesDisplay(r,"",!0),Z.done(),p}updateParallelBranchesDisplay(e,t,r=!1){let o=e.map(n=>{let a=n.index+1,i="",p="";switch(n.status){case"pending":i="\u25CB",p=`Branch ${a}: ${n.name} - Pending`;break;case"running":i=t,p=`Branch ${a}: ${n.name} - Running...`;break;case"success":i="\u2713",p=`Branch ${a}: ${n.name} - Completed`;break;case"failed":i="\u2717",p=`Branch ${a}: ${n.name} - Failed${n.error?`: ${n.error}`:""}`;break}return`${i} ${p}`});r?Z(o.join(`
|
|
13
|
+
`)):Z(o.join(`
|
|
14
|
+
`))}displayParallelResults(e,t,r){let o=!0,n=!1;console.log("");for(let i of e){if(!i)continue;n=!0;let{index:p,result:c,error:m,context:h}=i;if(m){o=!1;let f=`Branch ${p+1} failed: ${m instanceof Error?m.message:String(m)}`,d=B(f);console.error(d)}else if(c&&typeof c=="object"&&"stdout"in c){let f=c;if(o=o&&f.success,f.stdout.length>0||f.stderr.length>0||!f.success){let d=t[p],w=this.getBranchDisplayName(d,p);this.taskRunner.displayBufferedOutput(f,w,!1,h.lineNumber,h.fileName)}}}n||console.log("\u26A0\uFE0F All parallel branches were skipped (conditions not met)");let a=oe(o);return console.log(a),o}mergeParallelResults(e){for(let t of e){let r=t.workspace.getAllFacts(),o=t.workspace.getAllVariables();for(let[n,a]of r)this.workspace.setFact(n,a);for(let[n,a]of o)this.workspace.setVariable(n,a)}}countExecutableBranches(e,t){let r=0;for(let o=0;o<e.length;o++){let n=e[o],a=t[o];n.when&&!new N(a.workspace).evaluate(n.when)||r++}return r}async executeParallelStep(e,t){let r=this.createParallelContexts(e,t),o=this.countExecutableBranches(e.parallel,r),n=re(o);console.log(n);let a=await this.executeParallelBranches(e.parallel,r),i=this.displayParallelResults(a,e.parallel,t);if(this.workspace.setStepResult(t.stepIndex,i),!i){let p=t.lineNumber?` (line ${t.lineNumber})`:"";throw new Error(`Parallel step ${t.stepIndex}${p} failed: one or more branches failed`)}this.mergeParallelResults(r)}async executeFailStep(e,t){let r=new Error(e.fail.message);throw r.stack=void 0,r}};import{parse as Fe}from"yaml";import{ZodError as le}from"zod";import{z as l}from"zod";var Pe=l.object({file:l.string()}),Me=l.object({var:l.union([l.string(),l.record(l.string(),l.string())]).optional(),has:l.string().optional()}),Ne=l.object({status:l.object({fact:l.string(),is:l.enum(["ready","failed","pending"])})}),Te=l.object({step:l.object({success:l.boolean()}).optional(),last_step:l.enum(["success","failure"]).optional()}),Ae=l.object({choice:l.string()}),Ie=l.union([Pe,Ae,Me,Ne,Te]),R=l.lazy(()=>l.union([Ie,l.object({all:l.array(R)}),l.object({any:l.array(R)}),l.object({not:R})])),ae=l.lazy(()=>l.object({run:l.string(),timeout:l.number().optional(),retry:l.number().optional(),onError:ae.optional()})),Be=l.object({run:l.string(),when:R.optional(),timeout:l.number().optional(),retry:l.number().optional(),continue:l.boolean().optional(),onError:ae.optional()}),De=l.object({choose:l.object({message:l.string(),options:l.array(l.object({id:l.string(),label:l.string()})),as:l.string().optional()}),when:R.optional()}),je=l.object({prompt:l.object({message:l.string(),as:l.string(),default:l.string().optional(),validate:l.string().optional()}),when:R.optional()}),ie=l.lazy(()=>l.union([Be,De,je,l.object({parallel:l.array(ie),when:R.optional()}),l.object({fail:l.object({message:l.string()}),when:R.optional()})])),Le=l.object({name:l.string().optional(),baseDir:l.string().optional(),steps:l.array(ie).min(1,"Workflow must have at least one step")});function G(s){return Le.parse(s)}function q(s){let e=s;return"choose"in e&&(e.choose===null||e.choose===void 0)&&"message"in e&&"options"in e?{choose:{message:e.message,options:e.options,as:e.as},when:e.when}:"prompt"in e&&(e.prompt===null||e.prompt===void 0)&&"message"in e&&"as"in e?{prompt:{message:e.message,as:e.as,default:e.default,validate:e.validate},when:e.when}:"parallel"in e&&Array.isArray(e.parallel)?{...e,parallel:e.parallel.map(t=>q(t))}:s}var _=class{parse(e){let t;try{t=Fe(e)}catch(r){throw new Error(`Invalid YAML format: ${r instanceof Error?r.message:String(r)}`)}if(t&&typeof t=="object"&&"steps"in t){let r=t;Array.isArray(r.steps)&&(r.steps=r.steps.map(o=>q(o)))}try{return G(t)}catch(r){if(r instanceof le){let o=r.issues.map(n=>{let a=n.path.length>0?` at ${n.path.join(".")}`:"";return` - ${n.message}${a}`}).join(`
|
|
15
15
|
`);throw new Error(`Invalid workflow structure:
|
|
16
|
-
${
|
|
17
|
-
`),
|
|
16
|
+
${o}`)}throw r}}extractStepLineNumbers(e){let t=new Map,r=e.split(`
|
|
17
|
+
`),o=0,n=!1;for(let a=0;a<r.length;a++){let i=r[a].trim();if(i==="steps:"||i.startsWith("steps:")){n=!0;continue}n&&i.startsWith("-")&&t.set(o++,a+1)}return t}},X=class{parse(e){let t;try{t=JSON.parse(e)}catch(r){throw new Error(`Invalid JSON format: ${r instanceof Error?r.message:String(r)}`)}if(t&&typeof t=="object"&&"steps"in t){let r=t;Array.isArray(r.steps)&&(r.steps=r.steps.map(o=>q(o)))}try{return G(t)}catch(r){if(r instanceof le){let o=r.issues.map(n=>{let a=n.path.length>0?` at ${n.path.join(".")}`:"";return` - ${n.message}${a}`}).join(`
|
|
18
18
|
`);throw new Error(`Invalid workflow structure:
|
|
19
|
-
${
|
|
20
|
-
`),
|
|
19
|
+
${o}`)}throw r}}extractStepLineNumbers(e){let t=new Map,r=e.split(`
|
|
20
|
+
`),o=0,n=!1,a=!1;for(let i=0;i<r.length;i++){let c=r[i].trim();if(c.startsWith('"steps"')||c.startsWith("'steps'")){n=!0,c.includes("[")&&(a=!0);continue}if(n&&c==="["){a=!0;continue}if(a&&c==="]"){a=!1,n=!1;continue}a&&c.startsWith("{")&&t.set(o++,i+1)}return t}};function ce(s){switch(s.toLowerCase().split(".").pop()){case"yaml":case"yml":return new _;case"json":return new X;default:return new _}}import{readFileSync as ue,existsSync as pe}from"fs";import{resolve as K,dirname as Q}from"path";import{fileURLToPath as We}from"url";function me(){console.log=()=>{},console.error=()=>{},console.warn=()=>{},console.info=()=>{},process.stdout.write=()=>!0,process.stderr.write=()=>!0}function fe(){let s=process,e=typeof process<"u"&&s.pkg!==void 0;try{if(e){let t=[K(Q(process.execPath),"package.json"),"/snapshot/task-pipeliner/package.json",s.pkg?.entrypoint?K(Q(s.pkg.entrypoint),"package.json"):null].filter(r=>r!==null);for(let r of t)try{if(pe(r))return JSON.parse(ue(r,"utf-8")).version??"0.0.0"}catch{continue}}else try{let t=We(import.meta.url),r=Q(t),o=K(r,"../../package.json");if(pe(o))return JSON.parse(ue(o,"utf-8")).version??"0.0.0"}catch{}}catch{}return"0.0.0"}var ze=_e(He),D=new Je;D.name("task-pipeliner").description(`A powerful task pipeline runner with condition-based workflow execution.
|
|
21
21
|
|
|
22
22
|
Define workflows in YAML or JSON files with conditional execution, parallel tasks,
|
|
23
23
|
interactive prompts, and variable substitution.
|
|
@@ -55,7 +55,7 @@ Quick Start:
|
|
|
55
55
|
tp history remove # Remove a specific history
|
|
56
56
|
tp history remove-all # Remove all histories
|
|
57
57
|
|
|
58
|
-
`).version(
|
|
58
|
+
`).version(fe()).addHelpText("after",`
|
|
59
59
|
Examples:
|
|
60
60
|
$ tp run workflow.yaml
|
|
61
61
|
$ tp run examples/simple-project/workflow.yaml
|
|
@@ -92,8 +92,8 @@ Workflow File Structure:
|
|
|
92
92
|
\u2022 all/any/not: Combine conditions
|
|
93
93
|
|
|
94
94
|
Supported formats: YAML (.yaml, .yml) and JSON (.json)
|
|
95
|
-
See README.md for complete DSL documentation.`).action(async(s,e)=>{e.silent&&
|
|
96
|
-
`)),await new V().execute(
|
|
95
|
+
See README.md for complete DSL documentation.`).action(async(s,e)=>{e.silent&&me();try{let t=ce(s);console.log(u.blue(`Loading workflow from ${s}...`));let r=Oe(s,"utf-8"),o=t.parse(r);if(!o.steps||!Array.isArray(o.steps))throw new Error("Invalid workflow: steps array is required");o._lineNumbers=t.extractStepLineNumbers(r),o._fileName=Ze(s),o._filePath=Ve(s),console.log(u.green(`Starting workflow execution...
|
|
96
|
+
`)),await new V().execute(o),console.log(u.green(`
|
|
97
97
|
\u2713 Workflow completed successfully`))}catch(t){let r=t instanceof Error?t.message:String(t);console.error(u.red(`
|
|
98
98
|
\u2717 Workflow failed: ${r}`)),process.exit(1)}});D.command("open").description("Open generator or docs website in browser").argument("<target>",'Target to open: "generator" or "docs"').addHelpText("after",`
|
|
99
99
|
Examples:
|
|
@@ -104,24 +104,24 @@ Targets:
|
|
|
104
104
|
generator Open the visual workflow generator (https://task-pipeliner-generator.racgoo.com/)
|
|
105
105
|
docs Open the documentation site (https://task-pipeliner.racgoo.com/)`).action(async s=>{let t={generator:"https://task-pipeliner-generator.racgoo.com/",docs:"https://task-pipeliner.racgoo.com/"}[s.toLowerCase()];t||(console.error(u.red(`
|
|
106
106
|
\u2717 Invalid target: ${s}`)),console.log(u.yellow(`
|
|
107
|
-
Valid targets:`)),console.log(u.yellow(" \u2022 generator - Open the visual workflow generator")),console.log(u.yellow(" \u2022 docs - Open the documentation site")),process.exit(1));try{let r=process.platform,
|
|
108
|
-
\u2713 Opening ${s==="generator"?"generator":"documentation"} in browser...`)),console.log(u.blue(` ${t}`))}catch(r){let
|
|
109
|
-
\u2717 Failed to open browser: ${
|
|
110
|
-
Please visit manually: ${t}`)),process.exit(1)}});var
|
|
107
|
+
Valid targets:`)),console.log(u.yellow(" \u2022 generator - Open the visual workflow generator")),console.log(u.yellow(" \u2022 docs - Open the documentation site")),process.exit(1));try{let r=process.platform,o;r==="darwin"?o=`open "${t}"`:r==="win32"?o=`start "${t}"`:o=`xdg-open "${t}"`,await ze(o),console.log(u.green(`
|
|
108
|
+
\u2713 Opening ${s==="generator"?"generator":"documentation"} in browser...`)),console.log(u.blue(` ${t}`))}catch(r){let o=r instanceof Error?r.message:String(r);console.error(u.red(`
|
|
109
|
+
\u2717 Failed to open browser: ${o}`)),console.log(u.yellow(`
|
|
110
|
+
Please visit manually: ${t}`)),process.exit(1)}});var Ue=D.command("history").description("Manage workflow execution history");Ue.action(async()=>{let s=new E,e=await s.prompt("Select an action",[{id:"show",label:"Show - View and select a history to view"},{id:"remove",label:"Remove - Delete a specific history file"},{id:"remove-all",label:"Remove All - Delete all history files"}]);e?.id||(console.error(u.red(`
|
|
111
111
|
\u2717 Invalid choice`)),process.exit(1));let t=new A;switch(e.id){case"show":{let r=await t.getHistoryNames();if(r.length===0){console.log(u.yellow(`
|
|
112
|
-
\u26A0 No history found`));return}let
|
|
113
|
-
\u2717 Invalid choice`)),process.exit(1));try{let
|
|
112
|
+
\u26A0 No history found`));return}let o=await s.prompt("Select a history to view",r.map(n=>({id:n,label:n})));o?.id||(console.error(u.red(`
|
|
113
|
+
\u2717 Invalid choice`)),process.exit(1));try{let n=await t.getHistory(o.id);Ge(n,o.id)}catch(n){let a=n instanceof Error?n.message:String(n);console.error(u.red(`
|
|
114
114
|
\u2717 Failed to load history: ${a}`)),process.exit(1)}break}case"remove":{let r=await t.getHistoryNames();if(r.length===0){console.log(u.yellow(`
|
|
115
|
-
\u26A0 No history found`));return}let
|
|
116
|
-
\u2717 Invalid choice`)),process.exit(1));try{await t.removeHistory(
|
|
117
|
-
\u2713 Removed history: ${
|
|
115
|
+
\u26A0 No history found`));return}let o=await s.prompt("Select a history to remove",r.map(n=>({id:n,label:n})));o?.id||(console.error(u.red(`
|
|
116
|
+
\u2717 Invalid choice`)),process.exit(1));try{await t.removeHistory(o.id),console.log(u.green(`
|
|
117
|
+
\u2713 Removed history: ${o.id}`))}catch(n){let a=n instanceof Error?n.message:String(n);console.error(u.red(`
|
|
118
118
|
\u2717 Failed to remove history: ${a}`)),process.exit(1)}break}case"remove-all":{if((await s.prompt("Are you sure you want to remove all histories?",[{id:"yes",label:"Yes, remove all"},{id:"no",label:"No, cancel"}]))?.id!=="yes"){console.log(u.yellow(`
|
|
119
119
|
\u2717 Cancelled`));return}try{await t.clearAllHistories(),console.log(u.green(`
|
|
120
|
-
\u2713 All histories removed`))}catch(
|
|
121
|
-
\u2717 Failed to remove histories: ${
|
|
122
|
-
\u2717 Unknown action: ${e.id}`)),process.exit(1)}});function
|
|
123
|
-
`);let t=s.records.reduce((c,m)=>c+m.duration,0),r=s.records.filter(c=>c.status==="success").length,
|
|
124
|
-
`);console.log(
|
|
125
|
-
`);console.log(
|
|
120
|
+
\u2713 All histories removed`))}catch(o){let n=o instanceof Error?o.message:String(o);console.error(u.red(`
|
|
121
|
+
\u2717 Failed to remove histories: ${n}`)),process.exit(1)}break}default:console.error(u.red(`
|
|
122
|
+
\u2717 Unknown action: ${e.id}`)),process.exit(1)}});function Ze(s){return s.split("/").pop()??s}function Ge(s,e){console.log(`
|
|
123
|
+
`);let t=s.records.reduce((c,m)=>c+m.duration,0),r=s.records.filter(c=>c.status==="success").length,o=s.records.filter(c=>c.status==="failure").length,n=Ye(s.initialTimestamp).format("YYYY-MM-DD HH:mm:ss"),i=M(t),p=[u.bold("Workflow Execution History"),"",`${u.cyan("File:")} ${e}`,`${u.cyan("Started:")} ${n}`,`${u.cyan("Total Duration:")} ${i}`,`${u.cyan("Total Steps:")} ${s.records.length}`,`${u.green("\u2713 Successful:")} ${r}`,o>0?`${u.red("\u2717 Failed:")} ${o}`:""].filter(Boolean).join(`
|
|
124
|
+
`);console.log(de(p,{borderStyle:"round",padding:{top:1,bottom:1,left:2,right:2},margin:{top:0,bottom:1},borderColor:"cyan"})),s.records.forEach((c,m)=>{Xe(c,m+1,s.records.length)}),console.log("")}function Xe(s,e,t){let r=qe(s.step),o=Ke(s.step),n=s.status==="success"?u.green("\u2713"):u.red("\u2717"),a=s.status==="success"?u.green("Success"):u.red("Failed"),i=M(s.duration),p=[`${n} ${u.bold(`Step ${e}/${t}`)} - ${u.cyan(r)}`,`${u.gray("Duration:")} ${i} | ${u.gray("Status:")} ${a}`,"",u.white(o)].join(`
|
|
125
|
+
`);console.log(de(p,{borderStyle:"round",padding:{top:1,bottom:1,left:2,right:2},margin:{top:0,bottom:1},borderColor:s.status==="success"?"green":"red"})),Qe(s.output)&&et(s.output)}function qe(s){return"run"in s?"Run":"choose"in s?"Choose":"prompt"in s?"Prompt":"parallel"in s?"Parallel":"fail"in s?"Fail":"Unknown"}function Ke(s){return"run"in s?`Command: ${u.yellow(s.run)}`:"choose"in s?`Message: ${u.yellow(s.choose.message)}`:"prompt"in s?`Message: ${u.yellow(s.prompt.message)} | Variable: ${u.cyan(s.prompt.as)}`:"parallel"in s?`Parallel execution with ${s.parallel.length} branches`:"fail"in s?`Error: ${u.red(s.fail.message)}`:"Unknown step type"}function Qe(s){return typeof s=="object"&&s!==null&&"success"in s&&"stdout"in s&&"stderr"in s}function et(s){if(s.stdout.length>0){let e=s.stdout.map(t=>u.gray(` ${t}`)).join(`
|
|
126
126
|
`);console.log(u.green(" Output:")),console.log(e)}if(s.stderr.length>0){let e=s.stderr.map(t=>u.gray(` ${t}`)).join(`
|
|
127
127
|
`);console.log(u.red(" Errors:")),console.log(e)}}D.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "task-pipeliner",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "A task pipeline runner with condition-based workflow execution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -72,7 +72,8 @@
|
|
|
72
72
|
"assets": [
|
|
73
73
|
"dist/**/*.node",
|
|
74
74
|
"dist/**/*.js",
|
|
75
|
-
"dist/**/*.json"
|
|
75
|
+
"dist/**/*.json",
|
|
76
|
+
"package.json"
|
|
76
77
|
],
|
|
77
78
|
"scripts": [
|
|
78
79
|
"dist/**/*.js"
|