plano-cli 0.0.4 → 0.0.5

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/cli/plano.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import e from"chalk";import{Command as t}from"commander";import r from"inquirer";import{uniq as a}from"lodash-es";import{z as o}from"zod";var s=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};import{existsSync as n,readdirSync as p}from"fs";import{resolve as i}from"path";import{homedir as m}from"os";var l=`${m()}/plano-templates`;import{mkdirSync as c,readFileSync as f,writeFileSync as h}from"fs";import{resolve as u}from"path";import{globSync as d}from"glob";import b from"handlebars";import{camelCase as C}from"lodash-es";import{kebabCase as w}from"lodash-es";import{camelCase as g,upperFirst as y}from"lodash-es";import{snakeCase as v}from"lodash-es";import{snakeCase as j}from"lodash-es";var k={camelCase:function(e){return C(e)},kebabCase:function(e){return w(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return y(g(e))},snakeCase:function(e){return v(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return j(e).toUpperCase()}};Object.entries(k).map((([e,t])=>b.registerHelper(e,t)));import{resolve as x}from"path";import{z as P}from"zod";var $=P.array(P.object({message:P.string(),name:P.string(),required:P.boolean(),type:P.union([P.literal("input"),P.literal("select")])})),F=P.record(P.function(P.tuple([P.string()]),P.string()));var O=new t;O.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.4"),O.command("generate").description("Generate files or directories from a template").argument("<name>","template name").option("-p, --templates-paths <path...>",'Paths to templates, must be directory named "plano-templates"',[]).action((async(t,m)=>{try{const w=o.string().parse(t),g=o.object({templatesPaths:o.array(o.string())}).parse(m),y=(C=g.templatesPaths,[l,...C].map((e=>i(e))).filter((e=>n(e))).map((e=>p(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((t=>({path:e,template:t.name}))))).flat()),v=y.find((e=>e.template===w));if(!v)throw new s([e.red(`Unable to find template "${w}" at paths:`),...a(y.map((e=>e.path)))]);const{context:j,helpers:k={}}=await async function(e){const{context:t,helpers:r}=await import(x(e,"context.mjs"));return{context:$.parse(t),helpers:F.parse(r)}}(`${v.path}/${w}`);!function({context:e={},helpers:t={},templatePath:{path:r,template:a}}){Object.entries(t).map((([e,t])=>b.registerHelper(e,t)));const o=u(r,a,"template"),n=d(`${o}/**/*`,{withFileTypes:!0});n.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new s(["Template files must end with .handlebars:",e.fullpath()])}));for(let t of n){const r=b.compile(t.fullpath())(e).replace(`${o}/`,"");if(t.isDirectory()&&c(u(process.cwd(),r)),t.isFile()){const a=b.compile(f(t.fullpath(),"utf-8"))(e);h(u(process.cwd(),r.replace(".handlebars","")),a)}}}({context:await r.prompt(j),helpers:k,templatePath:v})}catch(e){e instanceof Error&&console.log(e.message)}var C})),O.parse();
2
+ import{Command as e}from"commander";import{z as t}from"zod";import{mkdirSync as r,readFileSync as a,writeFileSync as o}from"fs";import{resolve as s}from"path";import{globSync as n}from"glob";import p from"handlebars";import{camelCase as i}from"lodash-es";import{kebabCase as m}from"lodash-es";import{camelCase as l,upperFirst as c}from"lodash-es";import{snakeCase as f}from"lodash-es";import{snakeCase as h}from"lodash-es";var u={camelCase:function(e){return i(e)},kebabCase:function(e){return m(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return c(l(e))},snakeCase:function(e){return f(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return h(e).toUpperCase()}};var d=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};Object.entries(u).map((([e,t])=>p.registerHelper(e,t)));import{existsSync as b,readdirSync as C}from"fs";import{homedir as w}from"os";import{resolve as g}from"path";import y from"chalk";import{uniq as v}from"lodash-es";var j="plano-templates";function k({name:e,paths:t}){const r=function(e){return[`${w()}/${j}`,...e].map((e=>g(e))).filter((e=>b(e))).map((e=>C(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((t=>({path:e,template:t.name}))))).flat()}(t),a=r.find((t=>t.template===e));if(!a)throw new d([y.red(`Unable to find template "${e}" at paths:`),...v(r.map((e=>e.path)))]);return a}import{resolve as $}from"path";import x from"inquirer";import{z as F}from"zod";var O=F.array(F.object({message:F.string(),name:F.string(),required:F.boolean(),type:F.union([F.literal("input"),F.literal("select")])})),P=F.record(F.function(F.tuple([F.string()]),F.string()));var z=new e;z.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.5"),z.command("generate").description("Generate files or directories from a template").argument("<name>","template name").option("-p, --paths <path...>",'Paths to templates, must be directory named "plano-templates"',[]).action((async(e,i)=>{try{const m=t.string().parse(e),{paths:l}=t.object({paths:t.array(t.string())}).parse(i),c=k({name:m,paths:l}),{context:f,helpers:h={}}=await async function(e){const{prompts:t,helpers:r}=await import($(e,"context.mjs")),a=O.parse(t),o=P.parse(r);return{context:await x.prompt(a),helpers:o}}(`${c.path}/${m}`);!function({context:e={},helpers:t={},templatePath:{path:i,template:m}}){Object.entries(t).map((([e,t])=>p.registerHelper(e,t)));const l=s(i,m,"template"),c=n(`${l}/**/*`,{withFileTypes:!0});c.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new d(["Template files must end with .handlebars:",e.fullpath()])}));for(let t of c){const n=p.compile(t.fullpath())(e).replace(`${l}/`,"");if(t.isDirectory()&&r(s(process.cwd(),n)),t.isFile()){const r=p.compile(a(t.fullpath(),"utf-8"))(e);o(s(process.cwd(),n.replace(".handlebars","")),r)}}}({context:f,helpers:h,templatePath:c})}catch(e){e instanceof Error&&console.log(e.message)}})),z.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plano-cli",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [