plano-cli 0.4.0 → 0.5.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.
- package/dist/chunk-TZDSR6RM.js +1 -0
- package/dist/cli/plano.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-OPO6GWZJ.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{checkbox as e,input as t,select as r}from"@inquirer/prompts";async function a({helpers:a={},prompts:o}){if(!o||!Array.isArray(o))return{context:{},helpers:a};const s={};for(let a=0;a<o.length;a++){const p=o[a];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:a}}import{resolve as o}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=o(`${e}/${t}`,"context.mjs");if(!p(r))return{prompts:[],helpers:{}};let{prompts:a,helpers:s}=await import(r);return{prompts:b.parse(a)||[],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 D="plano";var P=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};function U({includeDefaultPath:e=!0,paths:t,type:r}){const a=[];return e&&a.push(function(e){switch(e){case"file":return`${z()}/${D}/file-templates`;case"snippet":return`${z()}/${D}/snippet-templates`;default:throw new P([`Unable to get default template path for type: ${e}`])}}(r)),[...a,...t].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 q}from"@inquirer/prompts";import{sortedUniq as F}from"lodash-es";async function O({includeDefaultPath:e,paths:t,type:r}){const a=U({includeDefaultPath:e,paths:t,type:r});return await q({message:"Select a template",choices:F(a.map((({template:e})=>({value:e}))))})}import{mkdirSync as S,writeFileSync as T,copyFileSync as A}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:a,template:o}}){Object.entries({...M,...r}).map((([e,t])=>H.registerHelper(e,t)));const s=W(a,o,"template"),p=E(`${s}/**/*`,{withFileTypes:!0,dot:!0});for(let a of p){const o=a.fullpath(),p=H.compile(o)(t).replace(`${s}/`,"");if(a.isDirectory()&&S(W(e,p)),a.isFile())if(a.name.endsWith(".handlebars")){const a=k({context:t,helpers:r,path:o});T(W(e,p.replace(".handlebars","")),a)}else{const t=W(e,o).replace(`${s}/`,"");A(o,t)}}}import Q from"chalk";import{uniq as R}from"lodash-es";function V({name:e,paths:t,type:r}){const a=U({paths:t,type:r}),o=a.find((t=>t.template===e));if(!o)throw new P([Q.red(`Unable to find template "${e}" at paths:`),...R(a.map((e=>e.path)))]);return o}export{a as promptForContext,w as getContextPrompts,k as compileTemplate,U as getAllPaths,O 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,getContextPrompts as a,getTemplate as p,promptForContext as s,promptForTemplate as o}from"../chunk-
|
|
2
|
+
import{compileTemplate as t,generate as e,getContextPrompts as a,getTemplate as p,promptForContext as s,promptForTemplate as o}from"../chunk-TZDSR6RM.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.5.1","-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
|
@@ -163,6 +163,7 @@ declare function compileTemplate({ context, helpers, path, }: CompileTemplate):
|
|
|
163
163
|
type TemplateType = 'file' | 'snippet';
|
|
164
164
|
|
|
165
165
|
interface PromptForTemplateOptions {
|
|
166
|
+
includeDefaultPath?: boolean;
|
|
166
167
|
paths: string[];
|
|
167
168
|
type: TemplateType;
|
|
168
169
|
}
|
|
@@ -172,7 +173,7 @@ interface PromptForTemplateOptions {
|
|
|
172
173
|
* @param paths - paths to search for templates
|
|
173
174
|
* @returns selected template name
|
|
174
175
|
*/
|
|
175
|
-
declare function promptForTemplate({ paths, type }: PromptForTemplateOptions): Promise<string>;
|
|
176
|
+
declare function promptForTemplate({ includeDefaultPath, paths, type, }: PromptForTemplateOptions): Promise<string>;
|
|
176
177
|
|
|
177
178
|
interface GenerateOptions {
|
|
178
179
|
copyToPath?: string;
|
|
@@ -186,10 +187,11 @@ interface GenerateOptions {
|
|
|
186
187
|
declare function generate({ copyToPath, context, helpers, template: { path, template }, }: GenerateOptions): void;
|
|
187
188
|
|
|
188
189
|
interface GetAllPathsOptions {
|
|
190
|
+
includeDefaultPath?: boolean;
|
|
189
191
|
paths: string[];
|
|
190
192
|
type: TemplateType;
|
|
191
193
|
}
|
|
192
|
-
declare function getAllPaths({ paths, type }: GetAllPathsOptions): {
|
|
194
|
+
declare function getAllPaths({ includeDefaultPath, paths, type, }: GetAllPathsOptions): {
|
|
193
195
|
path: string;
|
|
194
196
|
template: string;
|
|
195
197
|
}[];
|
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
|
|
1
|
+
import{compileTemplate as o,generate as r,getAllPaths as m,getContextPrompts as p,getTemplate as t,promptForContext as R,promptForTemplate as c}from"./chunk-TZDSR6RM.js";export{o as compileTemplate,r as generate,m as getAllPaths,p as getContextPrompts,t as getTemplate,R as promptForContext,c as promptForTemplate};
|
package/package.json
CHANGED
package/dist/chunk-OPO6GWZJ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|