derived-cli 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -69,7 +69,7 @@ ${c.default.gray(Yu+_t.repeat(s+2)+Zu)}
|
|
|
69
69
|
`):process.stdout.write(`${w} ${o}
|
|
70
70
|
`),y(),s()};return{start:Lt,stop:Re,message:(E="")=>{o=se(E??o)}}};var Mt=require("child_process"),k=require("fs"),jt=require("os"),Wt=require("path");var P=A(require("fs")),He=A(require("path")),St=r=>{let e=[],t=[],i=[];for(let s of r){let n=He.default.join(process.cwd(),s.resolvedPath);if(!s.isNotEnabled)try{if(P.default.mkdirSync(He.default.dirname(n),{recursive:!0}),s.templateType==="add")if(P.default.existsSync(n)&&P.default.lstatSync(n).isFile()){i.push(`File already exists: ${n}`);continue}else{if(s.pathError||s.templateError){i.push(`Failed to create file: ${n} because of error: ${s.templateError}`);continue}P.default.writeFileSync(n,s.resolvedTemplate),e.push(n)}else s.templateType==="modify"&&(s.modifiedFileContent?(P.default.writeFileSync(n,s.modifiedFileContent),t.push(n)):i.push(`Failed to modify file: ${n} because of error: ${s.templateError}`))}catch(u){i.push(u instanceof Error?u.message:String(u))}}return{addResults:e,modifyResults:t,errors:i}};var Gt=A(Vt());var je=A(L());function Pt(r){let e={name:"root",type:"directory",children:[],path:""},t=r.map(i=>i.replace(/^\//,"").replace(/\\/g,"/")).sort();for(let i of t){let s=i.split("/").filter(Boolean),n=e;s.forEach((u,o)=>{let l=o===s.length-1,h=n.children?.find(D=>D.name===u);if(h)n=h;else{let D={name:u,type:l?"file":"directory",children:l?void 0:[],path:s.slice(0,o+1).join("/")};n.children||(n.children=[]),n.children.push(D),n=D}})}return e}function ue(r,e="",t=!0,i=!0){if(i&&r.children)return r.children.map((l,h)=>ue(l,"",h===r.children.length-1,!1)).join(`
|
|
71
71
|
`);let s=t?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",n=r.type==="directory"?"\u{1F4C1} ":"\u{1F4C4} ",u=r.type==="directory"?je.default.cyan(r.name+"/"):je.default.green(r.name),o=e+s+n+u+`
|
|
72
|
-
`;if(r.children&&r.children.length>0){let l=e+(t?" ":"\u2502 ");r.children.forEach((h,D)=>{o+=ue(h,l,D===r.children.length-1,!1)})}return o}var ie=new st,We=new Gt.default;async function ai(r){let e=(0,Wt.join)((0,jt.tmpdir)(),`cli-edit-${Date.now()}.json`);(0,k.writeFileSync)(e,JSON.stringify(r,null,2));let t=process.env.VISUAL||process.env.EDITOR||"nano";return new Promise((i,s)=>{(0,Mt.spawn)(t,[e],{stdio:"inherit"}).on("exit",u=>{if(u===0)try{let o=(0,k.readFileSync)(e,"utf-8"),l=JSON.parse(o);(0,k.unlinkSync)(e),i(l)}catch{(0,k.unlinkSync)(e),s(new Error("Invalid JSON format"))}else(0,k.unlinkSync)(e),s(new Error("Editor closed without saving"))})})}async function Ht(r,e){let t=M();t.start(`Modifying block input for ${e}`);let i=await We.getBlockInputFromUserQuery(JSON.stringify(r),e);return t.stop("Block input modified"),Nt(i.result,"Refined Block Input"),i.result}function Nt(r,e="Block Input"){Pe(JSON.stringify(r,null,2),e)}function Rt(r,e){return We.resolveMultipleTemplates(r,e)}async function qt(r,e){let i=(await Rt(r,e)).result.files.map(u=>u.resolvedPath),s=Pt(i),n=ue(s);Pe(n,"\u{1F4E6} Files to be created:")}async function It(r,e){let t=M();t.start("Resolving Files...");let i=await Rt(r,e),s=St(i.result.files);t.stop(`${s.addResults.length} files added, ${s.modifyResults.length} files modified, ${s.errors.length} errors`)}async function li(r,e,t){Ot(`Add block: ${r}`);let i=!1,s=!1,n=M();n.start("Fetching block...");let u=await We.fetchBlock(r);if(u?.result?.id)n.stop(`Block Found '${u.result.name}' ${u.result.input?"with input":""}`);else{n.stop("Block Not Found");return}let o=t||u.result.input;for(t&&(It(r,t),i=!0),o&&e&&!t&&(o=Ht(o,e),s=!0);!i&&o&&!e;){Nt(o);let h=await wt({message:"What would you like to do?",options:[{value:"refine",label:"Edit (AI)"},{value:"edit",label:"Edit (Editor)"},{value:"restart",label:"Start over"},{value:"showFiles",label:"Show files to be created"},{value:"done",label:"Insert Files \u2705"}]});if(Q(h)&&(xt("Operation cancelled."),process.exit(0)),h==="refine"){let D=await yt({message:"Describe what to refine:"});o=await Ht(o,D),s=!0}h==="edit"&&(o=await ai(o)),h==="done"&&(await It(r,o),i=!0),h==="showFiles"&&qt(r,o),h==="restart"&&(i=!1,s=!1,o=u.result.input)}}ie.command("help").description("List all commands and usage").action(()=>{console.log(`
|
|
72
|
+
`;if(r.children&&r.children.length>0){let l=e+(t?" ":"\u2502 ");r.children.forEach((h,D)=>{o+=ue(h,l,D===r.children.length-1,!1)})}return o}var ie=new st,We=new Gt.default;async function ai(r){let e=(0,Wt.join)((0,jt.tmpdir)(),`cli-edit-${Date.now()}.json`);(0,k.writeFileSync)(e,JSON.stringify(r,null,2));let t=process.env.VISUAL||process.env.EDITOR||"nano";return new Promise((i,s)=>{(0,Mt.spawn)(t,[e],{stdio:"inherit"}).on("exit",u=>{if(u===0)try{let o=(0,k.readFileSync)(e,"utf-8"),l=JSON.parse(o);(0,k.unlinkSync)(e),i(l)}catch{(0,k.unlinkSync)(e),s(new Error("Invalid JSON format"))}else(0,k.unlinkSync)(e),s(new Error("Editor closed without saving"))})})}async function Ht(r,e){let t=M();t.start(`Modifying block input for ${e}`);let i=await We.getBlockInputFromUserQuery(JSON.stringify(r),e);return t.stop("Block input modified"),Nt(i.result,"Refined Block Input"),i.result}function Nt(r,e="Block Input"){Pe(JSON.stringify(r,null,2),e)}function Rt(r,e){return We.resolveMultipleTemplates(r,e)}async function qt(r,e){let i=(await Rt(r,e)).result.files.map(u=>u.resolvedPath),s=Pt(i),n=ue(s);Pe(n,"\u{1F4E6} Files to be created:")}async function It(r,e){let t=M();t.start("Resolving Files...");let i=await Rt(r,e),s=St(i.result.files);s.errors?.length&&console.log(s.errors,"errors"),t.stop(`${s.addResults.length} files added, ${s.modifyResults.length} files modified, ${s.errors.length} errors`)}async function li(r,e,t){Ot(`Add block: ${r}`);let i=!1,s=!1,n=M();n.start("Fetching block...");let u=await We.fetchBlock(r);if(u?.result?.id)n.stop(`Block Found '${u.result.name}' ${u.result.input?"with input":""}`);else{n.stop("Block Not Found");return}let o=t||u.result.input;for(t&&(It(r,t),i=!0),o&&e&&!t&&(o=Ht(o,e),s=!0);!i&&o&&!e;){Nt(o);let h=await wt({message:"What would you like to do?",options:[{value:"refine",label:"Edit (AI)"},{value:"edit",label:"Edit (Editor)"},{value:"restart",label:"Start over"},{value:"showFiles",label:"Show files to be created"},{value:"done",label:"Insert Files \u2705"}]});if(Q(h)&&(xt("Operation cancelled."),process.exit(0)),h==="refine"){let D=await yt({message:"Describe what to refine:"});o=await Ht(o,D),s=!0}h==="edit"&&(o=await ai(o)),h==="done"&&(await It(r,o),i=!0),h==="showFiles"&&qt(r,o),h==="restart"&&(i=!1,s=!1,o=u.result.input)}}ie.command("help").description("List all commands and usage").action(()=>{console.log(`
|
|
73
73
|
Available commands:
|
|
74
74
|
|
|
75
75
|
add <block-id>
|