plano-cli 0.3.1 → 0.4.0

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{checkbox as e,input as t,select as r}from"@inquirer/prompts";async function o({helpers:o={},prompts:a}){if(!a||!Array.isArray(a))return{context:{},helpers:o};const s={};for(let o=0;o<a.length;o++){const p=a[o];switch(p.type){case"checkbox":s[p.name]=await e(p);break;case"input":s[p.name]=await t(p);break;case"select":s[p.name]=await r(p)}}return{context:s,helpers:o}}import{resolve as a}from"node:path";import{z as s}from"zod";import{existsSync as p}from"node:fs";import{z as n}from"zod";import{z as i}from"zod";var m=i.object({message:i.string(),name:i.string(),required:i.boolean()}),l=n.object({value:n.string()}).passthrough(),c=m.extend({type:n.literal("checkbox"),choices:n.array(l)}).passthrough();import{z as f}from"zod";var h=m.extend({type:f.literal("input")}).passthrough();import{z as u}from"zod";var d=u.object({value:u.string()}).passthrough(),y=m.extend({type:u.literal("select"),choices:u.array(d)}).passthrough(),b=s.optional(s.array(s.discriminatedUnion("type",[c,h,y]))),g=s.optional(s.record(s.function(s.tuple([s.string()]),s.string())));async function w({template:{path:e,template:t}}){const r=a(`${e}/${t}`,"context.mjs");if(!p(r))return{prompts:[],helpers:{}};let{prompts:o,helpers:s}=await import(r);return{prompts:b.parse(o)||[],helpers:g.parse(s)||{}}}import{readFileSync as C}from"node:fs";import x from"handlebars";function k({context:e={},helpers:t={},path:r}){return x.compile(C(r,"utf-8"))(e)}import{existsSync as v,readdirSync as $}from"node:fs";import{homedir as z}from"node:os";import{resolve as j}from"node:path";var U="plano";var q=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};function F({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${z()}/${U}/file-templates`;case"snippet":return`${z()}/${U}/snippet-templates`;default:throw new q([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>j(e))).filter((e=>v(e))).map((e=>$(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}import{select as O}from"@inquirer/prompts";import{sortedUniq as S}from"lodash-es";async function T({paths:e,type:t}){const r=F({paths:e,type:t});return await O({message:"Select a template",choices:S(r.map((({template:e})=>({value:e}))))})}import{mkdirSync as A,writeFileSync as D,copyFileSync as P}from"node:fs";import{resolve as W}from"node:path";import{globSync as E}from"glob";import H from"handlebars";import{camelCase as L}from"lodash-es";import{kebabCase as B}from"lodash-es";import{camelCase as G,upperFirst as I}from"lodash-es";import{snakeCase as J}from"lodash-es";import{snakeCase as K}from"lodash-es";var M={camelCase:function(e){return L(e)},kebabCase:function(e){return B(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return I(G(e))},snakeCase:function(e){return J(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return K(e).toUpperCase()}};function N({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:o,template:a}}){Object.entries({...M,...r}).map((([e,t])=>H.registerHelper(e,t)));const s=W(o,a,"template"),p=E(`${s}/**/*`,{withFileTypes:!0,dot:!0});for(let o of p){const a=o.fullpath(),p=H.compile(a)(t).replace(`${s}/`,"");if(o.isDirectory()&&A(W(e,p)),o.isFile())if(o.name.endsWith(".handlebars")){const o=k({context:t,helpers:r,path:a});D(W(e,p.replace(".handlebars","")),o)}else{const t=W(e,a).replace(`${s}/`,"");P(a,t)}}}import Q from"chalk";import{uniq as R}from"lodash-es";function V({name:e,paths:t,type:r}){const o=F({paths:t,type:r}),a=o.find((t=>t.template===e));if(!a)throw new q([Q.red(`Unable to find template "${e}" at paths:`),...R(o.map((e=>e.path)))]);return a}export{o as promptForContext,w as getContextPrompts,k as compileTemplate,F as getAllPaths,T as promptForTemplate,N as generate,V as getTemplate};
package/dist/cli/plano.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{compileTemplate as t,generate as e,getTemplate as a,promptForContext as o,promptForTemplate as s}from"../chunk-2ZPT4KC5.js";import{Command as p}from"commander";import{z as n}from"zod";var r=new p;r.name("plano").description("CLI to scaffold files and directories from templates").version("0.3.1","-v, --version"),r.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"',[]).action((async(t,p)=>{try{let r=n.optional(n.string()).parse(t);const{paths:i}=n.object({paths:n.array(n.string())}).parse(p);void 0===r&&(r=await s({paths:i,type:"file"}));const m=a({name:r,paths:i,type:"file"}),{context:c,helpers:l={}}=await o({template:m});e({context:c,helpers:l,template:m})}catch(t){t instanceof Error&&console.log(t.message)}})),r.command("snippet").description("Generate a snippet from a template").argument("[name]","template name").option("-p, --paths <path...>",'Paths to snippets, must be directory named "plano"',[]).action((async(e,o)=>{try{let p=n.optional(n.string()).parse(e);const{paths:r}=n.object({paths:n.array(n.string())}).parse(o);void 0===p&&(p=await s({paths:r,type:"snippet"}));const i=a({name:p,paths:r,type:"snippet"});process.stdout.write(t({context:{},path:`${i.path}/${i.template}/snippet.handlebars`}))}catch(t){t instanceof Error&&console.log(t.message)}})),r.parse();
2
+ import{compileTemplate as t,generate as e,getContextPrompts as a,getTemplate as p,promptForContext as s,promptForTemplate as o}from"../chunk-OPO6GWZJ.js";import{Command as n}from"commander";import{z as r}from"zod";var i=new n;i.name("plano").description("CLI to scaffold files and directories from templates").version("0.4.0","-v, --version"),i.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"',[]).action((async(t,n)=>{try{let i=r.optional(r.string()).parse(t);const{paths:m}=r.object({paths:r.array(r.string())}).parse(n);void 0===i&&(i=await o({paths:m,type:"file"}));const c=p({name:i,paths:m,type:"file"}),{helpers:l,prompts:h}=await a({template:c}),{context:d,helpers:f}=await s({helpers:l,prompts:h});e({context:d,helpers:f,template:c})}catch(t){t instanceof Error&&console.log(t.message)}})),i.command("snippet").description("Generate a snippet from a template").argument("[name]","template name").option("-p, --paths <path...>",'Paths to snippets, must be directory named "plano"',[]).action((async(e,a)=>{try{let s=r.optional(r.string()).parse(e);const{paths:n}=r.object({paths:r.array(r.string())}).parse(a);void 0===s&&(s=await o({paths:n,type:"snippet"}));const i=p({name:s,paths:n,type:"snippet"});process.stdout.write(t({context:{},path:`${i.path}/${i.template}/snippet.handlebars`}))}catch(t){t instanceof Error&&console.log(t.message)}})),i.parse();
package/dist/index.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { z } from 'zod';
2
2
  import { HelperDelegate } from 'handlebars';
3
3
 
4
+ interface GetContextPromptsOptions {
5
+ template: {
6
+ path: string;
7
+ template: string;
8
+ };
9
+ }
4
10
  declare const promptsSchema: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<z.objectUtil.extendShape<{
5
11
  message: z.ZodString;
6
12
  name: z.ZodString;
@@ -99,7 +105,9 @@ declare const promptsSchema: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"t
99
105
  }, z.ZodTypeAny, "passthrough">>, "many">;
100
106
  }>, z.ZodTypeAny, "passthrough">>]>, "many">>;
101
107
  type PromptsSchema = z.infer<typeof promptsSchema>;
102
- declare function getContextPrompts({ template: { path, template }, preprocessContext, }: PromptForContextOptions): Promise<{
108
+ declare const helpersSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodFunction<z.ZodTuple<[z.ZodString], null>, z.ZodString>>>;
109
+ type HelpersSchema = z.infer<typeof helpersSchema>;
110
+ declare function getContextPrompts({ template: { path, template }, }: GetContextPromptsOptions): Promise<{
103
111
  prompts: (z.objectOutputType<z.objectUtil.extendShape<{
104
112
  message: z.ZodString;
105
113
  name: z.ZodString;
@@ -137,13 +145,10 @@ declare function getContextPrompts({ template: { path, template }, preprocessCon
137
145
  }>;
138
146
 
139
147
  interface PromptForContextOptions {
140
- template: {
141
- path: string;
142
- template: string;
143
- };
144
- preprocessContext?: (prompts: PromptsSchema) => PromptsSchema;
148
+ helpers: HelpersSchema;
149
+ prompts: PromptsSchema;
145
150
  }
146
- declare function promptForContext(options: PromptForContextOptions): Promise<{
151
+ declare function promptForContext({ helpers, prompts, }: PromptForContextOptions): Promise<{
147
152
  context: Record<string, unknown>;
148
153
  helpers: Record<string, (args_0: string) => string>;
149
154
  }>;
@@ -199,4 +204,4 @@ declare function getTemplate({ name, paths, type }: GetTemplateOptions): {
199
204
  template: string;
200
205
  };
201
206
 
202
- export { type PromptsSchema, compileTemplate, generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
207
+ export { type HelpersSchema, type PromptsSchema, compileTemplate, generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{compileTemplate as o,generate as r,getAllPaths as m,getContextPrompts as p,getTemplate as t,promptForContext as c,promptForTemplate as e}from"./chunk-2ZPT4KC5.js";export{o as compileTemplate,r as generate,m as getAllPaths,p as getContextPrompts,t as getTemplate,c as promptForContext,e as promptForTemplate};
1
+ import{compileTemplate as o,generate as r,getAllPaths as m,getContextPrompts as p,getTemplate as t,promptForContext as O,promptForTemplate as c}from"./chunk-OPO6GWZJ.js";export{o as compileTemplate,r as generate,m as getAllPaths,p as getContextPrompts,t as getTemplate,O as promptForContext,c as promptForTemplate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plano-cli",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -1 +0,0 @@
1
- import{resolve as e}from"node:path";import{z as t}from"zod";import{existsSync as r}from"node:fs";import{z as o}from"zod";import{z as a}from"zod";var s=a.object({message:a.string(),name:a.string(),required:a.boolean()}),p=o.object({value:o.string()}).passthrough(),n=s.extend({type:o.literal("checkbox"),choices:o.array(p)}).passthrough();import{z as i}from"zod";var m=s.extend({type:i.literal("input")}).passthrough();import{z as l}from"zod";var c=l.object({value:l.string()}).passthrough(),f=s.extend({type:l.literal("select"),choices:l.array(c)}).passthrough(),h=t.optional(t.array(t.discriminatedUnion("type",[n,m,f]))),u=t.optional(t.record(t.function(t.tuple([t.string()]),t.string())));async function d({template:{path:t,template:o},preprocessContext:a}){const s=e(`${t}/${o}`,"context.mjs");if(!r(s))return{prompts:[],helpers:{}};let{prompts:p,helpers:n}=await import(s);a&&(p=a(p));return{prompts:h.parse(p)||[],helpers:u.parse(n)||{}}}import{checkbox as y,input as b,select as g}from"@inquirer/prompts";async function w(e){const{prompts:t,helpers:r}=await d(e);if(!t)return{context:{},helpers:r};const o={};for(let e=0;e<t.length;e++){const r=t[e];switch(r.type){case"checkbox":o[r.name]=await y(r);break;case"input":o[r.name]=await b(r);break;case"select":o[r.name]=await g(r)}}return{context:o,helpers:r}}import{readFileSync as C}from"node:fs";import x from"handlebars";function k({context:e={},helpers:t={},path:r}){return x.compile(C(r,"utf-8"))(e)}import{existsSync as v,readdirSync as $}from"node:fs";import{homedir as z}from"node:os";import{resolve as j}from"node:path";var U="plano";var q=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};function F({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${z()}/${U}/file-templates`;case"snippet":return`${z()}/${U}/snippet-templates`;default:throw new q([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>j(e))).filter((e=>v(e))).map((e=>$(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}import{select as O}from"@inquirer/prompts";import{sortedUniq as S}from"lodash-es";async function T({paths:e,type:t}){const r=F({paths:e,type:t});return await O({message:"Select a template",choices:S(r.map((({template:e})=>({value:e}))))})}import{mkdirSync as D,writeFileSync as P,copyFileSync as W}from"node:fs";import{resolve as E}from"node:path";import{globSync as H}from"glob";import L from"handlebars";import{camelCase as A}from"lodash-es";import{kebabCase as B}from"lodash-es";import{camelCase as G,upperFirst as I}from"lodash-es";import{snakeCase as J}from"lodash-es";import{snakeCase as K}from"lodash-es";var M={camelCase:function(e){return A(e)},kebabCase:function(e){return B(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return I(G(e))},snakeCase:function(e){return J(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return K(e).toUpperCase()}};function N({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:o,template:a}}){Object.entries({...M,...r}).map((([e,t])=>L.registerHelper(e,t)));const s=E(o,a,"template"),p=H(`${s}/**/*`,{withFileTypes:!0,dot:!0});for(let o of p){const a=o.fullpath(),p=L.compile(a)(t).replace(`${s}/`,"");if(o.isDirectory()&&D(E(e,p)),o.isFile())if(o.name.endsWith(".handlebars")){const o=k({context:t,helpers:r,path:a});P(E(e,p.replace(".handlebars","")),o)}else{const t=E(e,a).replace(`${s}/`,"");W(a,t)}}}import Q from"chalk";import{uniq as R}from"lodash-es";function V({name:e,paths:t,type:r}){const o=F({paths:t,type:r}),a=o.find((t=>t.template===e));if(!a)throw new q([Q.red(`Unable to find template "${e}" at paths:`),...R(o.map((e=>e.path)))]);return a}export{d as getContextPrompts,w as promptForContext,k as compileTemplate,F as getAllPaths,T as promptForTemplate,N as generate,V as getTemplate};