@vue-dnd-kit/components
Version:
Components for Vue DnD Kit
10 lines • 4.69 kB
JavaScript
import {Command}from'commander';import {fileURLToPath}from'url';import l from'path';import d from'fs';import M from'readline';function f(o){return console.log(`\u23F3 ${o}`),{succeed:e=>console.log(`\u2705 ${e}`),fail:e=>console.log(`\u274C ${e}`),stop:()=>{}}}function k(o){try{let e=o;for(let t=0;t<10;t++){let n=l.join(e,"package.json");if(d.existsSync(n))return JSON.parse(d.readFileSync(n,"utf8")).version||"0.0.0";e=l.join(e,"..");}return "0.0.0"}catch(e){return console.error("Error reading package version:",e),"0.0.0"}}function p(o){let e=o,t=l.join(e,"..","templates");if(d.existsSync(t))return t;let n=e;for(let r=0;r<10&&!d.existsSync(l.join(n,"package.json"));r++)n=l.join(n,"..");let i=[l.join(n,"src","templates"),l.join(n,"templates")];for(let r of i)if(d.existsSync(r))return r;return i[0]}var _=fileURLToPath(import.meta.url),w=l.dirname(_),P={command:"debug",description:"Show debug information",action:()=>{console.log("Current directory:",process.cwd()),console.log("__dirname:",w),console.log("CLI file path:",_);let o=p(w);if(console.log("Templates directory:",o),console.log("Exists:",d.existsSync(o)),d.existsSync(o)){let e=d.readdirSync(o);console.log("Templates directory contents:",e);}}};var F=fileURLToPath(import.meta.url),U=l.dirname(F),S={blue:o=>`\x1B[34m${o}\x1B[0m`,green:o=>`\x1B[32m${o}\x1B[0m`,yellow:o=>`\x1B[33m${o}\x1B[0m`},E={command:"list",description:"Show available components",action:()=>{let o=f("Getting component list...");try{let e=p(U);d.existsSync(e)||(o.fail("Templates directory not found"),process.exit(1));let t=d.readdirSync(e).filter(n=>d.statSync(l.join(e,n)).isDirectory());t.length===0&&(console.log(S.yellow("No available components")),process.exit(0)),console.log(S.green(`
Available components:`)),t.forEach(n=>{console.log(` - ${S.blue(n)}`);});}catch(e){o.fail(`Error: ${e.message}`),process.exit(1);}}};function $(o){d.existsSync(o)||d.mkdirSync(o,{recursive:true});}function j(o,e){$(e);let t=d.readdirSync(o,{withFileTypes:true});for(let n of t){let i=l.join(o,n.name),r=l.join(e,n.name);n.isDirectory()?j(i,r):d.copyFileSync(i,r);}}function I(o){let e=M.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{e.question(`${o} (y/n) `,n=>{e.close(),t(n.toLowerCase()==="y");});})}var Y=fileURLToPath(import.meta.url),q=l.dirname(Y),c={blue:o=>`\x1B[34m${o}\x1B[0m`,green:o=>`\x1B[32m${o}\x1B[0m`,red:o=>`\x1B[31m${o}\x1B[0m`,yellow:o=>`\x1B[33m${o}\x1B[0m`,cyan:o=>`\x1B[36m${o}\x1B[0m`},J={command:"add <component>",description:"Add a component to your project",options:[{flags:"-d, --dir <directory>",description:"Directory to install the component",defaultValue:"src/components"}],action:async(o,e)=>{let t=f(`Installing component ${c.blue(o)}...`);(async function(){try{let n=process.cwd(),i=p(q),r=l.join(i,o);if(!d.existsSync(r)){t.fail(`Component ${c.red(o)} not found`);let a=d.readdirSync(i).filter(s=>d.statSync(l.join(i,s)).isDirectory());a.length>0?(console.log(c.yellow(`
Available components:`)),a.forEach(s=>{console.log(` - ${s}`);})):console.log(c.yellow(`
No available components in templates.`)),process.exit(1);}let D=l.join(n,e.dir);$(D),j(r,l.join(D,o));let v=l.join(n,"package.json");if(d.existsSync(v)){let a;try{a=JSON.parse(d.readFileSync(v,"utf8"));}catch(x){console.log(c.yellow(`Warning: unable to read package.json: ${x.message}`)),a={dependencies:{}};}let s=[];if((!a.dependencies||!a.dependencies["@vue-dnd-kit/core"])&&s.push("@vue-dnd-kit/core"),s.length>0){t.stop();try{if(await I(`Missing dependencies detected: ${s.join(", ")}. Install?`)){let N=f("Installing dependencies...");console.log(`
${c.cyan("Run the following command manually:")}`),console.log(`yarn add ${s.join(" ")}
`),N.succeed("Dependency installation instructions provided");}}catch{console.log(c.yellow(`
Missing dependencies detected: ${s.join(", ")}`)),console.log(c.cyan("Run the following command manually:")),console.log(`yarn add ${s.join(" ")}
`);}}}t.succeed(`Component ${c.green(o)} successfully installed in ${c.blue(e.dir+"/"+o)}`);}catch(n){t.fail(`Installation error: ${n.message}`),console.error(n),process.exit(1);}})();}};var L=[P,E,J];var W=fileURLToPath(import.meta.url),z=l.dirname(W),B=k(z),y=new Command;y.name("@vue-dnd-kit/components").description("CLI for installing Vue DnD Kit components").version(B);L.forEach(o=>{let e=y.command(o.command).description(o.description);"options"in o&&o.options&&Array.isArray(o.options)&&o.options.forEach(t=>{e.option(t.flags,t.description,t.defaultValue);}),e.action(o.action);});process.argv.length<=2&&y.outputHelp();y.parse(process.argv);//# sourceMappingURL=cli.js.map
//# sourceMappingURL=cli.js.map