plano-cli 0.2.0 → 0.3.1

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"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};
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-XHSKHXW7.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.2.0","-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,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();
package/dist/index.d.ts CHANGED
@@ -1,45 +1,150 @@
1
+ import { z } from 'zod';
1
2
  import { HelperDelegate } from 'handlebars';
2
3
 
3
- interface PromptForContextOptions {
4
- template: {
5
- path: string;
6
- template: string;
7
- };
8
- }
9
- declare function promptForContext(options: PromptForContextOptions): Promise<{
10
- context: Record<string, unknown>;
4
+ declare const promptsSchema: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<z.objectUtil.extendShape<{
5
+ message: z.ZodString;
6
+ name: z.ZodString;
7
+ required: z.ZodBoolean;
8
+ }, {
9
+ type: z.ZodLiteral<"checkbox">;
10
+ choices: z.ZodArray<z.ZodObject<{
11
+ value: z.ZodString;
12
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
13
+ value: z.ZodString;
14
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
15
+ value: z.ZodString;
16
+ }, z.ZodTypeAny, "passthrough">>, "many">;
17
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
18
+ message: z.ZodString;
19
+ name: z.ZodString;
20
+ required: z.ZodBoolean;
21
+ }, {
22
+ type: z.ZodLiteral<"checkbox">;
23
+ choices: z.ZodArray<z.ZodObject<{
24
+ value: z.ZodString;
25
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
26
+ value: z.ZodString;
27
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
28
+ value: z.ZodString;
29
+ }, z.ZodTypeAny, "passthrough">>, "many">;
30
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
31
+ message: z.ZodString;
32
+ name: z.ZodString;
33
+ required: z.ZodBoolean;
34
+ }, {
35
+ type: z.ZodLiteral<"checkbox">;
36
+ choices: z.ZodArray<z.ZodObject<{
37
+ value: z.ZodString;
38
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
39
+ value: z.ZodString;
40
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
41
+ value: z.ZodString;
42
+ }, z.ZodTypeAny, "passthrough">>, "many">;
43
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
44
+ message: z.ZodString;
45
+ name: z.ZodString;
46
+ required: z.ZodBoolean;
47
+ }, {
48
+ type: z.ZodLiteral<"input">;
49
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
50
+ message: z.ZodString;
51
+ name: z.ZodString;
52
+ required: z.ZodBoolean;
53
+ }, {
54
+ type: z.ZodLiteral<"input">;
55
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
56
+ message: z.ZodString;
57
+ name: z.ZodString;
58
+ required: z.ZodBoolean;
59
+ }, {
60
+ type: z.ZodLiteral<"input">;
61
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
62
+ message: z.ZodString;
63
+ name: z.ZodString;
64
+ required: z.ZodBoolean;
65
+ }, {
66
+ type: z.ZodLiteral<"select">;
67
+ choices: z.ZodArray<z.ZodObject<{
68
+ value: z.ZodString;
69
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
70
+ value: z.ZodString;
71
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
72
+ value: z.ZodString;
73
+ }, z.ZodTypeAny, "passthrough">>, "many">;
74
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
75
+ message: z.ZodString;
76
+ name: z.ZodString;
77
+ required: z.ZodBoolean;
78
+ }, {
79
+ type: z.ZodLiteral<"select">;
80
+ choices: z.ZodArray<z.ZodObject<{
81
+ value: z.ZodString;
82
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
83
+ value: z.ZodString;
84
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
85
+ value: z.ZodString;
86
+ }, z.ZodTypeAny, "passthrough">>, "many">;
87
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
88
+ message: z.ZodString;
89
+ name: z.ZodString;
90
+ required: z.ZodBoolean;
91
+ }, {
92
+ type: z.ZodLiteral<"select">;
93
+ choices: z.ZodArray<z.ZodObject<{
94
+ value: z.ZodString;
95
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
96
+ value: z.ZodString;
97
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
98
+ value: z.ZodString;
99
+ }, z.ZodTypeAny, "passthrough">>, "many">;
100
+ }>, z.ZodTypeAny, "passthrough">>]>, "many">>;
101
+ type PromptsSchema = z.infer<typeof promptsSchema>;
102
+ declare function getContextPrompts({ template: { path, template }, preprocessContext, }: PromptForContextOptions): Promise<{
103
+ prompts: (z.objectOutputType<z.objectUtil.extendShape<{
104
+ message: z.ZodString;
105
+ name: z.ZodString;
106
+ required: z.ZodBoolean;
107
+ }, {
108
+ type: z.ZodLiteral<"checkbox">;
109
+ choices: z.ZodArray<z.ZodObject<{
110
+ value: z.ZodString;
111
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
112
+ value: z.ZodString;
113
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
114
+ value: z.ZodString;
115
+ }, z.ZodTypeAny, "passthrough">>, "many">;
116
+ }>, z.ZodTypeAny, "passthrough"> | z.objectOutputType<z.objectUtil.extendShape<{
117
+ message: z.ZodString;
118
+ name: z.ZodString;
119
+ required: z.ZodBoolean;
120
+ }, {
121
+ type: z.ZodLiteral<"input">;
122
+ }>, z.ZodTypeAny, "passthrough"> | z.objectOutputType<z.objectUtil.extendShape<{
123
+ message: z.ZodString;
124
+ name: z.ZodString;
125
+ required: z.ZodBoolean;
126
+ }, {
127
+ type: z.ZodLiteral<"select">;
128
+ choices: z.ZodArray<z.ZodObject<{
129
+ value: z.ZodString;
130
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
131
+ value: z.ZodString;
132
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
133
+ value: z.ZodString;
134
+ }, z.ZodTypeAny, "passthrough">>, "many">;
135
+ }>, z.ZodTypeAny, "passthrough">)[];
11
136
  helpers: Record<string, (args_0: string) => string>;
12
137
  }>;
13
138
 
14
- interface GetContextPromptsOptions {
139
+ interface PromptForContextOptions {
15
140
  template: {
16
141
  path: string;
17
142
  template: string;
18
143
  };
144
+ preprocessContext?: (prompts: PromptsSchema) => PromptsSchema;
19
145
  }
20
- declare function getContextPrompts({ template: { path, template }, }: GetContextPromptsOptions): Promise<{
21
- prompts: ({
22
- message: string;
23
- name: string;
24
- required: boolean;
25
- type: "checkbox";
26
- choices: {
27
- value: string;
28
- }[];
29
- } | {
30
- message: string;
31
- name: string;
32
- required: boolean;
33
- type: "input";
34
- } | {
35
- message: string;
36
- name: string;
37
- required: boolean;
38
- type: "select";
39
- choices: {
40
- value: string;
41
- }[];
42
- })[];
146
+ declare function promptForContext(options: PromptForContextOptions): Promise<{
147
+ context: Record<string, unknown>;
43
148
  helpers: Record<string, (args_0: string) => string>;
44
149
  }>;
45
150
 
@@ -94,4 +199,4 @@ declare function getTemplate({ name, paths, type }: GetTemplateOptions): {
94
199
  template: string;
95
200
  };
96
201
 
97
- export { compileTemplate, generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
202
+ export { 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 H,promptForTemplate as X}from"./chunk-XHSKHXW7.js";export{o as compileTemplate,r as generate,m as getAllPaths,p as getContextPrompts,t as getTemplate,H as promptForContext,X as promptForTemplate};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plano-cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -29,21 +29,21 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/lodash-es": "^4.17.12",
32
- "@types/node": "^22.7.7",
33
- "@vitest/coverage-v8": "^2.1.3",
34
- "prettier": "^3.3.3",
35
- "terser": "^5.36.0",
36
- "tsup": "^8.3.0",
37
- "typescript": "^5.6.3",
32
+ "@types/node": "^22.10.7",
33
+ "@vitest/coverage-v8": "^2.1.8",
34
+ "prettier": "^3.4.2",
35
+ "terser": "^5.37.0",
36
+ "tsup": "^8.3.5",
37
+ "typescript": "^5.7.3",
38
38
  "vitest": "^2.1.1"
39
39
  },
40
40
  "dependencies": {
41
- "@inquirer/prompts": "^7.2.1",
42
- "chalk": "^5.3.0",
41
+ "@inquirer/prompts": "^7.2.3",
42
+ "chalk": "^5.4.1",
43
43
  "commander": "^12.1.0",
44
- "glob": "^11.0.0",
44
+ "glob": "^11.0.1",
45
45
  "handlebars": "^4.7.8",
46
46
  "lodash-es": "^4.17.21",
47
- "zod": "^3.23.8"
47
+ "zod": "^3.24.1"
48
48
  }
49
49
  }
@@ -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()}),n=o.object({value:o.string()}),p=s.extend({type:o.literal("checkbox"),choices:o.array(n)});import{z as i}from"zod";var m=s.extend({type:i.literal("input")});import{z as c}from"zod";var l=c.object({value:c.string()}),f=s.extend({type:c.literal("select"),choices:c.array(l)}),h=t.optional(t.array(t.discriminatedUnion("type",[p,m,f]))),u=t.optional(t.record(t.function(t.tuple([t.string()]),t.string())));async function d({template:{path:t,template:o}}){const a=e(`${t}/${o}`,"context.mjs");if(!r(a))return{prompts:[],helpers:{}};const{prompts:s,helpers:n}=await import(a);return{prompts:h.parse(s)||[],helpers:u.parse(n)||{}}}import{checkbox as y,input as b,select as w}from"@inquirer/prompts";async function C(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{type:r,...a}=t[e];switch(r){case"checkbox":o[a.name]=await y(a);break;case"input":o[a.name]=await b(a);break;case"select":o[a.name]=await w(a)}}return{context:o,helpers:r}}import{readFileSync as x}from"node:fs";import g from"handlebars";function k({context:e={},helpers:t={},path:r}){return g.compile(x(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"),n=H(`${s}/**/*`,{withFileTypes:!0,dot:!0});for(let o of n){const a=o.fullpath(),n=L.compile(a)(t).replace(`${s}/`,"");if(o.isDirectory()&&D(E(e,n)),o.isFile())if(o.name.endsWith(".handlebars")){const o=k({context:t,helpers:r,path:a});P(E(e,n.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,C as promptForContext,k as compileTemplate,F as getAllPaths,T as promptForTemplate,N as generate,V as getTemplate};