derived-cli 0.0.20 → 0.0.21

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/bundle.js +2 -2
  2. package/package.json +1 -1
package/dist/bundle.js CHANGED
@@ -70,7 +70,7 @@ ${c.default.gray(M)} ${n}
70
70
  `);process.stdout.write(X.cursor.move(-999,E.length-1)),process.stdout.write(X.erase.down(E.length))},ut=E=>E.replace(/\.+$/,""),It=E=>{let _=(performance.now()-E)/1e3,y=Math.floor(_/60),T=Math.floor(_%60);return y>0?`[${y}m ${T}s]`:`[${T}s]`},Me=(E="")=>{u=!0,s=Ce(),o=ut(E),h=performance.now(),process.stdout.write(`${c.default.gray(F)}
71
71
  `);let _=0,y=0;g(),r=setInterval(()=>{if(i&&o===l)return;Pt(),l=o;let T=c.default.magenta(t[_]);if(i)process.stdout.write(`${T} ${o}...`);else if(n==="timer")process.stdout.write(`${T} ${o} ${It(h)}`);else{let We=".".repeat(Math.floor(y)).slice(0,3);process.stdout.write(`${T} ${o}${We}`)}_=_+1<t.length?_+1:0,y=y<t.length?y+.125:0},e)},Mt=(E="",_=0)=>{u=!1,clearInterval(r),Pt();let y=_===0?c.default.green(Tt):_===1?c.default.red(ge):c.default.red(Ee);o=ut(E??o),n==="timer"?process.stdout.write(`${y} ${o} ${It(h)}
72
72
  `):process.stdout.write(`${y} ${o}
73
- `),v(),s()};return{start:Me,stop:Mt,message:(E="")=>{o=ut(E??o)}}};var Ve=require("child_process"),k=require("fs"),He=require("os"),Pe=require("path");var tt=class{baseUrl;defaultHeaders;constructor(t,e={}){this.baseUrl=t,this.defaultHeaders=e}buildUrl(t){return`${this.baseUrl.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}async request(t,e,i,s={}){let r=this.buildUrl(e),u=await fetch(r,{method:t,headers:{"Content-Type":"application/json",...this.defaultHeaders,...s},body:i?JSON.stringify(i):void 0});if(!u.ok){let l=await u.text().catch(()=>"");throw new Error(`HTTP ${u.status} ${u.statusText}: ${l||"Request failed"}`)}let o=await u.text();try{return JSON.parse(o)}catch{return o}}get(t,e){return this.request("GET",t,void 0,e)}post(t,e,i){return this.request("POST",t,e,i)}put(t,e,i){return this.request("PUT",t,e,i)}delete(t,e){return this.request("DELETE",t,void 0,e)}};var Vt=new tt("http://127.0.0.1:8080/api/public"),we=async n=>await Vt.get(`/v1/template-group/code/${n}`),xe=async(n,t)=>await Vt.post("/v1/template-group/get-block-input-from-user-query",{blockInput:n,query:t}),Oe=async(n,t)=>await Vt.post("/v1/template-group/resolve-multiple-templates-by-block-code",{blockCode:n,data:t});var H=w(require("fs")),Ht=w(require("path")),Se=n=>{let t=[],e=[],i=[];for(let s of n){let r=Ht.default.join(process.cwd(),s.resolvedPath);if(!s.isNotEnabled)try{if(H.default.mkdirSync(Ht.default.dirname(r),{recursive:!0}),s.templateType==="add")if(H.default.existsSync(r)&&H.default.lstatSync(r).isFile()){i.push(`File already exists: ${r}`);continue}else H.default.writeFileSync(r,s.resolvedTemplate),t.push(r);else s.templateType==="modify"&&(s.modifiedFileContent?(H.default.writeFileSync(r,s.modifiedFileContent),e.push(r)):i.push(`Failed to modify file: ${r} because of error: ${s.templateError}`))}catch(u){i.push(u instanceof Error?u.message:String(u))}}return{addResults:t,modifyResults:e,errors:i}};var et=new Xt;async function Uu(n){let t=(0,Pe.join)((0,He.tmpdir)(),`cli-edit-${Date.now()}.json`);(0,k.writeFileSync)(t,JSON.stringify(n,null,2));let e=process.env.VISUAL||process.env.EDITOR||"nano";return new Promise((i,s)=>{(0,Ve.spawn)(e,[t],{stdio:"inherit"}).on("exit",u=>{if(u===0)try{let o=(0,k.readFileSync)(t,"utf-8"),l=JSON.parse(o);(0,k.unlinkSync)(t),i(l)}catch{(0,k.unlinkSync)(t),s(new Error("Invalid JSON format"))}else(0,k.unlinkSync)(t),s(new Error("Editor closed without saving"))})})}async function ke(n,t){let e=W();e.start(`Modifying block input for ${t}`);let i=await xe(JSON.stringify(n),t);return e.stop("Block input modified"),Ie(i.result,"Refined Block Input"),i.result}function Ie(n,t="Block Input"){Ae(JSON.stringify(n,null,2),t)}async function Te(n,t){let e=W();e.start("Resolving Files...");let i=await Oe(n,t);Se(i.result.files),e.stop(`${i.result.files.length} files resolved`)}async function Ju(n,t,e){ve(`Add block: ${n}`);let i=!1,s=!1,r=W();r.start("Fetching block...");let u=await we(n);if(u?.result?.id)r.stop("Block Found");else{r.stop("Block Not Found");return}let o=e||u.result.input;for(e&&(Te(n,e),i=!0),o&&t&&!e&&(o=ke(o,t),s=!0);!i&&o&&!t;){let h=await _e({message:"What would you like to do?",options:[{value:"refine",label:"Edit (AI)"},{value:"edit",label:"Edit (Editor)"},{value:"restart",label:"Start over"},{value:"preview",label:"Preview Block Input"},{value:"done",label:"Accept"}]});if(Z(h)&&(Be("Operation cancelled."),process.exit(0)),h==="refine"){let a=await $e({message:"Describe what to refine:"});o=await ke(o,a),s=!0}h==="edit"&&(o=await Uu(o)),h==="done"&&(await Te(n,o),ye("Done! \u{1F389}"),i=!0),h==="preview"&&Ie(o),h==="restart"&&(i=!1,s=!1,o=u.result.input)}}et.command("help").description("List all commands and usage").action(()=>{console.log(`
73
+ `),v(),s()};return{start:Me,stop:Mt,message:(E="")=>{o=ut(E??o)}}};var Ve=require("child_process"),k=require("fs"),He=require("os"),Pe=require("path");var tt=class{baseUrl;defaultHeaders;constructor(t,e={}){this.baseUrl=t,this.defaultHeaders=e}buildUrl(t){return`${this.baseUrl.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}async request(t,e,i,s={}){let r=this.buildUrl(e),u=await fetch(r,{method:t,headers:{"Content-Type":"application/json",...this.defaultHeaders,...s},body:i?JSON.stringify(i):void 0});if(!u.ok){let l=await u.text().catch(()=>"");throw new Error(`HTTP ${u.status} ${u.statusText}: ${l||"Request failed"}`)}let o=await u.text();try{return JSON.parse(o)}catch{return o}}get(t,e){return this.request("GET",t,void 0,e)}post(t,e,i){return this.request("POST",t,e,i)}put(t,e,i){return this.request("PUT",t,e,i)}delete(t,e){return this.request("DELETE",t,void 0,e)}};var Vt=new tt("http://127.0.0.1:8080/api/public"),we=async n=>await Vt.get(`/v1/template-group/code/${n}`),xe=async(n,t)=>await Vt.post("/v1/template-group/get-block-input-from-user-query",{blockInput:n,query:t}),Oe=async(n,t)=>await Vt.post("/v1/template-group/resolve-multiple-templates-by-block-code",{blockCode:n,data:t});var H=w(require("fs")),Ht=w(require("path")),Se=n=>{let t=[],e=[],i=[];for(let s of n){let r=Ht.default.join(process.cwd(),s.resolvedPath);if(!s.isNotEnabled)try{if(H.default.mkdirSync(Ht.default.dirname(r),{recursive:!0}),s.templateType==="add")if(H.default.existsSync(r)&&H.default.lstatSync(r).isFile()){i.push(`File already exists: ${r}`);continue}else{if(s.pathError||s.templateError){i.push(`Failed to create file: ${r} because of error: ${s.templateError}`);continue}H.default.writeFileSync(r,s.resolvedTemplate),t.push(r)}else s.templateType==="modify"&&(s.modifiedFileContent?(H.default.writeFileSync(r,s.modifiedFileContent),e.push(r)):i.push(`Failed to modify file: ${r} because of error: ${s.templateError}`))}catch(u){i.push(u instanceof Error?u.message:String(u))}}return{addResults:t,modifyResults:e,errors:i}};var et=new Xt;async function Uu(n){let t=(0,Pe.join)((0,He.tmpdir)(),`cli-edit-${Date.now()}.json`);(0,k.writeFileSync)(t,JSON.stringify(n,null,2));let e=process.env.VISUAL||process.env.EDITOR||"nano";return new Promise((i,s)=>{(0,Ve.spawn)(e,[t],{stdio:"inherit"}).on("exit",u=>{if(u===0)try{let o=(0,k.readFileSync)(t,"utf-8"),l=JSON.parse(o);(0,k.unlinkSync)(t),i(l)}catch{(0,k.unlinkSync)(t),s(new Error("Invalid JSON format"))}else(0,k.unlinkSync)(t),s(new Error("Editor closed without saving"))})})}async function ke(n,t){let e=W();e.start(`Modifying block input for ${t}`);let i=await xe(JSON.stringify(n),t);return e.stop("Block input modified"),Ie(i.result,"Refined Block Input"),i.result}function Ie(n,t="Block Input"){Ae(JSON.stringify(n,null,2),t)}async function Te(n,t){let e=W();e.start("Resolving Files..."),console.log(n,typeof t,"check me");let i=await Oe(n,t),s=Se(i.result.files);e.stop(`${s.addResults.length} files added, ${s.modifyResults.length} files modified, ${s.errors.length} errors`)}async function Ju(n,t,e){ve(`Add block: ${n}`);let i=!1,s=!1,r=W();r.start("Fetching block...");let u=await we(n);if(u?.result?.id)r.stop("Block Found");else{r.stop("Block Not Found");return}let o=e||u.result.input;for(e&&(Te(n,e),i=!0),o&&t&&!e&&(o=ke(o,t),s=!0);!i&&o&&!t;){let h=await _e({message:"What would you like to do?",options:[{value:"refine",label:"Edit (AI)"},{value:"edit",label:"Edit (Editor)"},{value:"restart",label:"Start over"},{value:"preview",label:"Preview Block Input"},{value:"done",label:"Accept"}]});if(Z(h)&&(Be("Operation cancelled."),process.exit(0)),h==="refine"){let a=await $e({message:"Describe what to refine:"});o=await ke(o,a),s=!0}h==="edit"&&(o=await Uu(o)),h==="done"&&(await Te(n,o),ye("Done! \u{1F389}"),i=!0),h==="preview"&&Ie(o),h==="restart"&&(i=!1,s=!1,o=u.result.input)}}et.command("help").description("List all commands and usage").action(()=>{console.log(`
74
74
  Available commands:
75
75
 
76
76
  add <block-id>
@@ -79,4 +79,4 @@ Available commands:
79
79
 
80
80
  help
81
81
  Show this help text.
82
- `)});var Ku=n=>{let t=W();try{t.start("Decoding base64...");let e=Buffer.from(n,"base64").toString("utf8");return t.stop("Decoded input successfully"),JSON.parse(e)}catch{return t.stop("Failed to decode input"),null}};et.command("add <blockCode>").description("Generate and refine a JSON block interactively").option("-q, --query <value>","Optional user input").option("-i, --block-input <value>","Optional block input json schema in base 64").action(async(n,t)=>{let e=t.blockInput?Ku(t.blockInput):null;await Ju(n,t.query,e)});et.command("init <project-id>").description("Initialize a project (no interactive prompts)").action(async n=>{console.log(`\u{1F680} Initializing project: ${n}`),console.log("Creating project folder..."),console.log("Setting up config..."),console.log("Done!")});et.parse();
82
+ `)});var Ku=n=>{let t=W();try{t.start("Decoding base64...");let e=Buffer.from(n,"base64").toString("utf8"),i=JSON.parse(e);for(;typeof i!="object";)i=JSON.parse(i);return t.stop("Decoded input successfully"),i}catch{return t.stop("Failed to decode input"),null}};et.command("add <blockCode>").description("Generate and refine a JSON block interactively").option("-q, --query <value>","Optional user input").option("-i, --block-input <value>","Optional block input json schema in base 64").action(async(n,t)=>{let e=t.blockInput?Ku(t.blockInput):null;console.log(typeof e,e,"parsed block input"),await Ju(n,t.query,e)});et.command("init <project-id>").description("Initialize a project (no interactive prompts)").action(async n=>{console.log(`\u{1F680} Initializing project: ${n}`),console.log("Creating project folder..."),console.log("Setting up config..."),console.log("Done!")});et.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "derived-cli",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "CLI for Derived",
5
5
  "author": "Derived",
6
6
  "license": "MIT",