plano-cli 0.0.5 → 0.0.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.
@@ -0,0 +1 @@
1
+ import{resolve as e}from"path";import t from"inquirer";import{z as r}from"zod";var a=r.array(r.object({message:r.string(),name:r.string(),required:r.boolean(),type:r.union([r.literal("input"),r.literal("select")])})),o=r.record(r.function(r.tuple([r.string()]),r.string()));async function s({template:{path:r,template:s}}){const{prompts:p,helpers:n}=await import(e(`${r}/${s}`,"context.mjs")),i=a.parse(p),m=o.parse(n);return{context:await t.prompt(i),helpers:m}}import{mkdirSync as p,readFileSync as n,writeFileSync as i}from"fs";import{resolve as m}from"path";import{globSync as l}from"glob";import f from"handlebars";import{camelCase as c}from"lodash-es";import{kebabCase as u}from"lodash-es";import{camelCase as h,upperFirst as d}from"lodash-es";import{snakeCase as b}from"lodash-es";import{snakeCase as C}from"lodash-es";var w={camelCase:function(e){return c(e)},kebabCase:function(e){return u(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return d(h(e))},snakeCase:function(e){return b(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return C(e).toUpperCase()}};var y=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};function g({context:e={},helpers:t={},template:{path:r,template:a}}){Object.entries(t).map((([e,t])=>f.registerHelper(e,t)));const o=m(r,a,"template"),s=l(`${o}/**/*`,{withFileTypes:!0});s.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new y(["Template files must end with .handlebars:",e.fullpath()])}));for(let t of s){const r=f.compile(t.fullpath())(e).replace(`${o}/`,"");if(t.isDirectory()&&p(m(process.cwd(),r)),t.isFile()){const a=f.compile(n(t.fullpath(),"utf-8"))(e);i(m(process.cwd(),r.replace(".handlebars","")),a)}}}Object.entries(w).map((([e,t])=>f.registerHelper(e,t)));import{existsSync as k,readdirSync as $}from"fs";import{homedir as j}from"os";import{resolve as v}from"path";import x from"chalk";import{uniq as F}from"lodash-es";var O="plano-templates";function T({name:e,paths:t}){const r=function(e){return[`${j()}/${O}`,...e].map((e=>v(e))).filter((e=>k(e))).map((e=>$(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 y([x.red(`Unable to find template "${e}" at paths:`),...F(r.map((e=>e.path)))]);return a}export{s as promptForContext,g as generate,T as getTemplate};
package/dist/cli/plano.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
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();
2
+ import{generate as e,getTemplate as t,promptForContext as a}from"../chunk-5NE677L4.js";import{Command as r}from"commander";import{z as o}from"zod";var s=new r;s.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.7"),s.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(r,s)=>{try{const n=o.string().parse(r),{paths:m}=o.object({paths:o.array(o.string())}).parse(s),p=t({name:n,paths:m}),{context:i,helpers:c={}}=await a({template:p});e({context:i,helpers:c,template:p})}catch(e){e instanceof Error&&console.log(e.message)}})),s.parse();
package/dist/index.d.ts CHANGED
@@ -1,2 +1,33 @@
1
+ import { HelperDelegate } from 'handlebars';
1
2
 
2
- export { }
3
+ interface PromptForContextOptions {
4
+ template: {
5
+ path: string;
6
+ template: string;
7
+ };
8
+ }
9
+ declare function promptForContext({ template: { path, template }, }: PromptForContextOptions): Promise<{
10
+ context: Record<string, unknown>;
11
+ helpers: Record<string, (args_0: string) => string>;
12
+ }>;
13
+
14
+ interface GenerateOptions {
15
+ template: {
16
+ path: string;
17
+ template: string;
18
+ };
19
+ helpers: Record<string, HelperDelegate>;
20
+ context: Record<string, unknown>;
21
+ }
22
+ declare function generate({ context, helpers, template: { path, template }, }: GenerateOptions): void;
23
+
24
+ interface GetTemplateOptions {
25
+ name: string;
26
+ paths: string[];
27
+ }
28
+ declare function getTemplate({ name, paths }: GetTemplateOptions): {
29
+ path: string;
30
+ template: string;
31
+ };
32
+
33
+ export { generate, getTemplate, promptForContext };
package/dist/index.js CHANGED
@@ -0,0 +1 @@
1
+ import{generate as o,getTemplate as r,promptForContext as m}from"./chunk-5NE677L4.js";export{o as generate,r as getTemplate,m as promptForContext};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plano-cli",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [