plano-cli 0.0.18 → 0.0.20

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/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Plano CLI
2
2
 
3
- A CLI and programmatic API for generating files from templates with context values and helper functions.
3
+ A CLI and programmatic API for generating files, directories, and snippets from
4
+ templates with context values and helper functions.
4
5
 
5
6
  ## Getting Started
6
7
 
@@ -14,32 +15,40 @@ npm install plano-cli
14
15
 
15
16
  ## Quick Start
16
17
 
17
- Create a directory named `plano-templates`. See the [examples](https://github.com/matthewwolfe/plano-cli/tree/main/examples) for more info. By default Plano will look for templates in the home directory, typically `~`.
18
+ Create a directory named `plano`. See the [examples](https://github.com/matthewwolfe/plano-cli/tree/main/examples) for more info. By default Plano will look for templates in the home directory, typically `~`.
18
19
  Additional paths can be specified.
19
20
 
20
21
  ### Generate
21
22
 
22
23
  ```
23
- Usage: plano generate [options] [name]
24
+ Usage: plano [options] [command]
24
25
 
25
- Generate files or directories from a template
26
-
27
- Arguments:
28
- name template name
26
+ CLI to scaffold files and directories from templates
29
27
 
30
28
  Options:
31
- -p, --paths <path...> Paths to templates, must be directory named "plano-templates" (default: [])
32
- -h, --help display help for command
29
+ -v, --version output the version number
30
+ -h, --help display help for command
31
+
32
+ Commands:
33
+ generate [options] [name] Generate files or directories from a template
34
+ snippet [options] [name] Generate a snippet from a template
35
+ help [command] display help for command
33
36
  ```
34
37
 
35
- #### Example
38
+ #### File/Directory Example
36
39
 
37
40
  ```
38
41
  plano generate react-component
39
42
  ```
40
43
 
44
+ #### Snippet Example
45
+
46
+ ```
47
+ plano snippet vitest-test
48
+ ```
49
+
41
50
  #### Example with paths
42
51
 
43
52
  ```
44
- plano generate react-component -p ./path/to/plano-templates
53
+ plano generate react-component -p ./path/to/plano
45
54
  ```
@@ -0,0 +1 @@
1
+ import{resolve as t}from"path";import{z as e}from"zod";import{existsSync as r}from"fs";var a=e.optional(e.array(e.object({message:e.string(),name:e.string(),required:e.boolean(),type:e.union([e.literal("input"),e.literal("select")])}))),o=e.optional(e.record(e.function(e.tuple([e.string()]),e.string())));async function s({template:{path:e,template:s}}){const p=t(`${e}/${s}`,"context.mjs");if(!r(p))return{prompts:[],helpers:{}};const{prompts:n,helpers:i}=await import(p);return{prompts:a.parse(n)||[],helpers:o.parse(i)||{}}}import p from"inquirer";async function n(t){const{prompts:e,helpers:r}=await s(t);if(!e)return{context:{},helpers:r};return{context:await p.prompt(e)||{},helpers:r}}import{readFileSync as i}from"fs";import m from"handlebars";function l({context:t={},helpers:e={},path:r}){return m.compile(i(r,"utf-8"))(t)}import{existsSync as f,readdirSync as c}from"fs";import{homedir as h}from"os";import{resolve as u}from"path";var d="plano",y="file-templates",w="snippet-templates";var b=class t extends Error{constructor(e){super(function(t){return t.join("\n")}(e)),Object.setPrototypeOf(this,t.prototype)}};function C({paths:t,type:e}){const r=function(t){switch(t){case"file":return`${h()}/${d}/${y}`;case"snippet":return`${h()}/${d}/${w}`;default:throw new b([`Unable to get default template path for type: ${t}`])}}(e);return[r,...t].map((t=>u(t))).filter((t=>f(t))).map((t=>c(t,{withFileTypes:!0}).filter((t=>t.isDirectory()&&!t.name.startsWith(".git"))).map((e=>({path:t,template:e.name}))))).flat()}import $ from"inquirer";import{sortedUniq as g}from"lodash-es";async function x({paths:t,type:e}){const r=C({paths:t,type:e}),{template:a}=await $.prompt([{name:"template",message:"Select a template",type:"list",choices:g(r.map((({template:t})=>t)))}]);return a}import{mkdirSync as k,writeFileSync as v}from"fs";import{resolve as j}from"path";import{globSync as F}from"glob";import T from"handlebars";import{camelCase as U}from"lodash-es";import{kebabCase as q}from"lodash-es";import{camelCase as O,upperFirst as S}from"lodash-es";import{snakeCase as D}from"lodash-es";import{snakeCase as E}from"lodash-es";var P={camelCase:function(t){return U(t)},kebabCase:function(t){return q(t)},lowerCase:function(t){return t.toLowerCase()},pascalCase:function(t){return S(O(t))},snakeCase:function(t){return D(t)},upperCase:function(t){return t.toUpperCase()},upperSnakeCase:function(t){return E(t).toUpperCase()}};function W({copyToPath:t=process.cwd(),context:e={},helpers:r={},template:{path:a,template:o}}){Object.entries({...P,...r}).map((([t,e])=>T.registerHelper(t,e)));const s=j(a,o,"template"),p=F(`${s}/**/*`,{withFileTypes:!0});p.forEach((t=>{if(t.isFile()&&!t.name.endsWith(".handlebars"))throw new b(["Template files must end with .handlebars:",t.fullpath()])}));for(let a of p){const o=T.compile(a.fullpath())(e).replace(`${s}/`,"");if(a.isDirectory()&&k(j(t,o)),a.isFile()){const s=l({context:e,helpers:r,path:a.fullpath()});v(j(t,o.replace(".handlebars","")),s)}}}import z from"chalk";import{uniq as H}from"lodash-es";function L({name:t,paths:e,type:r}){const a=C({paths:e,type:r}),o=a.find((e=>e.template===t));if(!o)throw new b([z.red(`Unable to find template "${t}" at paths:`),...H(a.map((t=>t.path)))]);return o}export{s as getContextPrompts,n as promptForContext,l as compileTemplate,C as getAllPaths,x as promptForTemplate,W as generate,L as getTemplate};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var e=Object.create,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,n=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,o=(o,i,p)=>(p=null!=o?e(n(o)):{},((e,n,o,i)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let p of a(n))s.call(e,p)||p===o||t(e,p,{get:()=>n[p],enumerable:!(i=r(n,p))||i.enumerable});return e})(!i&&o&&o.__esModule?p:t(p,"default",{value:o,enumerable:!0}),o)),i=require("commander"),p=require("zod"),l=require("fs"),c=require("path"),u=require("glob"),m=o(require("handlebars"),1);var f=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}},h=require("lodash-es");var d=require("lodash-es");var y=require("lodash-es");var b=require("lodash-es");var q=require("lodash-es");var z={camelCase:function(e){return(0,h.camelCase)(e)},kebabCase:function(e){return(0,d.kebabCase)(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return(0,y.upperFirst)((0,y.camelCase)(e))},snakeCase:function(e){return(0,b.snakeCase)(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return(0,q.snakeCase)(e).toUpperCase()}},g=require("fs"),v=o(require("handlebars"),1);function w({context:e={},path:t}){return v.default.compile((0,g.readFileSync)(t,"utf-8"))(e)}Object.entries(z).map((([e,t])=>m.default.registerHelper(e,t)));var C=o(require("chalk"),1),j=require("lodash-es"),O=require("fs"),x=require("os"),S=require("path"),k="plano-templates";function P(e){return[`${(0,x.homedir)()}/${k}`,...e].map((e=>(0,S.resolve)(e))).filter((e=>(0,O.existsSync)(e))).map((e=>(0,O.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}var F=o(require("inquirer"),1),$=require("path"),T=require("zod"),U=require("fs"),D=T.z.optional(T.z.array(T.z.object({message:T.z.string(),name:T.z.string(),required:T.z.boolean(),type:T.z.union([T.z.literal("input"),T.z.literal("select")])}))),E=T.z.optional(T.z.record(T.z.function(T.z.tuple([T.z.string()]),T.z.string())));async function H(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,$.resolve)(`${e}/${t}`,"context.mjs");if(!(0,U.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:n}=await import(r);return{prompts:D.parse(a)||[],helpers:E.parse(n)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await F.default.prompt(t)||{},helpers:r}}var L=o(require("inquirer"),1),W=require("lodash-es");var _=new i.Command;_.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.18","-v, --version"),_.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,t)=>{try{let r=p.z.optional(p.z.string()).parse(e);const{paths:a}=p.z.object({paths:p.z.array(p.z.string())}).parse(t);void 0===r&&(r=await async function(e){const t=P(e),{template:r}=await L.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,W.sortedUniq)(t.map((({template:e})=>e)))}]);return r}(a));const n=function({name:e,paths:t}){const r=P(t),a=r.find((t=>t.template===e));if(!a)throw new f([C.default.red(`Unable to find template "${e}" at paths:`),...(0,j.uniq)(r.map((e=>e.path)))]);return a}({name:r,paths:a}),{context:s,helpers:o={}}=await H({template:n});!function({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:n}}){Object.entries(r).map((([e,t])=>m.default.registerHelper(e,t)));const s=(0,c.resolve)(a,n,"template"),o=(0,u.globSync)(`${s}/**/*`,{withFileTypes:!0});o.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new f(["Template files must end with .handlebars:",e.fullpath()])}));for(let r of o){const a=m.default.compile(r.fullpath())(t).replace(`${s}/`,"");if(r.isDirectory()&&(0,l.mkdirSync)((0,c.resolve)(e,a)),r.isFile()){const n=w({context:t,path:r.fullpath()});(0,l.writeFileSync)((0,c.resolve)(e,a.replace(".handlebars","")),n)}}}({context:s,helpers:o,template:n})}catch(e){e instanceof Error&&console.log(e.message)}})),_.parse();
2
+ "use strict";var e=Object.create,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,s=Object.getPrototypeOf,n=Object.prototype.hasOwnProperty,p=(p,o,i)=>(i=null!=p?e(s(p)):{},((e,s,p,o)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let i of a(s))n.call(e,i)||i===p||t(e,i,{get:()=>s[i],enumerable:!(o=r(s,i))||o.enumerable});return e})(!o&&p&&p.__esModule?i:t(i,"default",{value:p,enumerable:!0}),p)),o=require("commander"),i=require("zod"),l=require("fs"),c=require("path"),u=require("glob"),m=p(require("handlebars"),1);var h=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}},f=require("lodash-es");var d=require("lodash-es");var y=require("lodash-es");var b=require("lodash-es");var q=require("lodash-es");var z={camelCase:function(e){return(0,f.camelCase)(e)},kebabCase:function(e){return(0,d.kebabCase)(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return(0,y.upperFirst)((0,y.camelCase)(e))},snakeCase:function(e){return(0,b.snakeCase)(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return(0,q.snakeCase)(e).toUpperCase()}},g=require("fs"),w=p(require("handlebars"),1);function v({context:e={},helpers:t={},path:r}){return w.default.compile((0,g.readFileSync)(r,"utf-8"))(e)}var C=p(require("chalk"),1),j=require("lodash-es"),$=require("fs"),O=require("os"),x=require("path"),P="plano",S="file-templates",k="snippet-templates";function F({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${(0,O.homedir)()}/${P}/${S}`;case"snippet":return`${(0,O.homedir)()}/${P}/${k}`;default:throw new h([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>(0,x.resolve)(e))).filter((e=>(0,$.existsSync)(e))).map((e=>(0,$.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}function U({name:e,paths:t,type:r}){const a=F({paths:t,type:r}),s=a.find((t=>t.template===e));if(!s)throw new h([C.default.red(`Unable to find template "${e}" at paths:`),...(0,j.uniq)(a.map((e=>e.path)))]);return s}var E=p(require("inquirer"),1),T=require("path"),D=require("zod"),G=require("fs"),L=D.z.optional(D.z.array(D.z.object({message:D.z.string(),name:D.z.string(),required:D.z.boolean(),type:D.z.union([D.z.literal("input"),D.z.literal("select")])}))),W=D.z.optional(D.z.record(D.z.function(D.z.tuple([D.z.string()]),D.z.string())));async function _(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,T.resolve)(`${e}/${t}`,"context.mjs");if(!(0,G.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:s}=await import(r);return{prompts:L.parse(a)||[],helpers:W.parse(s)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await E.default.prompt(t)||{},helpers:r}}var H=p(require("inquirer"),1),I=require("lodash-es");async function M({paths:e,type:t}){const r=F({paths:e,type:t}),{template:a}=await H.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,I.sortedUniq)(r.map((({template:e})=>e)))}]);return a}var N=new o.Command;N.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.20","-v, --version"),N.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(e,t)=>{try{let r=i.z.optional(i.z.string()).parse(e);const{paths:a}=i.z.object({paths:i.z.array(i.z.string())}).parse(t);void 0===r&&(r=await M({paths:a,type:"file"}));const s=U({name:r,paths:a,type:"file"}),{context:n,helpers:p={}}=await _({template:s});!function({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:s}}){Object.entries({...z,...r}).map((([e,t])=>m.default.registerHelper(e,t)));const n=(0,c.resolve)(a,s,"template"),p=(0,u.globSync)(`${n}/**/*`,{withFileTypes:!0});p.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new h(["Template files must end with .handlebars:",e.fullpath()])}));for(let a of p){const s=m.default.compile(a.fullpath())(t).replace(`${n}/`,"");if(a.isDirectory()&&(0,l.mkdirSync)((0,c.resolve)(e,s)),a.isFile()){const n=v({context:t,helpers:r,path:a.fullpath()});(0,l.writeFileSync)((0,c.resolve)(e,s.replace(".handlebars","")),n)}}}({context:n,helpers:p,template:s})}catch(e){e instanceof Error&&console.log(e.message)}})),N.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,t)=>{try{let r=i.z.optional(i.z.string()).parse(e);const{paths:a}=i.z.object({paths:i.z.array(i.z.string())}).parse(t);void 0===r&&(r=await M({paths:a,type:"snippet"}));const s=U({name:r,paths:a,type:"snippet"});process.stdout.write(v({context:{},path:`${s.path}/${s.template}/snippet.handlebars`}))}catch(e){e instanceof Error&&console.log(e.message)}})),N.parse();
package/dist/cli/plano.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{generate as e,getTemplate as t,promptForContext as a,promptForTemplate as o}from"../chunk-OPEC5HIS.js";import{Command as r}from"commander";import{z as s}from"zod";var n=new r;n.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.18","-v, --version"),n.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,n)=>{try{let m=s.optional(s.string()).parse(r);const{paths:p}=s.object({paths:s.array(s.string())}).parse(n);void 0===m&&(m=await o(p));const i=t({name:m,paths:p}),{context:c,helpers:l={}}=await a({template:i});e({context:c,helpers:l,template:i})}catch(e){e instanceof Error&&console.log(e.message)}})),n.parse();
2
+ import{compileTemplate as t,generate as e,getTemplate as a,promptForContext as o,promptForTemplate as s}from"../chunk-TSMFHBY6.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.0.20","-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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.create,r=Object.defineProperty,a=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,i=(e,t,s,i)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let l of n(t))o.call(e,l)||l===s||r(e,l,{get:()=>t[l],enumerable:!(i=a(t,l))||i.enumerable});return e},l=(e,a,n)=>(n=null!=e?t(s(e)):{},i(!a&&e&&e.__esModule?n:r(n,"default",{value:e,enumerable:!0}),e)),p={};((e,t)=>{for(var a in t)r(e,a,{get:t[a],enumerable:!0})})(p,{compileTemplate:()=>v,generate:()=>A,getAllPaths:()=>F,getContextPrompts:()=>b,getTemplate:()=>B,promptForContext:()=>y,promptForTemplate:()=>P}),module.exports=(e=p,i(r({},"__esModule",{value:!0}),e));var u=l(require("inquirer"),1),c=require("path"),m=require("zod"),f=require("fs"),h=m.z.optional(m.z.array(m.z.object({message:m.z.string(),name:m.z.string(),required:m.z.boolean(),type:m.z.union([m.z.literal("input"),m.z.literal("select")])}))),d=m.z.optional(m.z.record(m.z.function(m.z.tuple([m.z.string()]),m.z.string())));async function b({template:{path:e,template:t}}){const r=(0,c.resolve)(`${e}/${t}`,"context.mjs");if(!(0,f.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:n}=await import(r);return{prompts:h.parse(a)||[],helpers:d.parse(n)||{}}}async function y(e){const{prompts:t,helpers:r}=await b(e);if(!t)return{context:{},helpers:r};return{context:await u.default.prompt(t)||{},helpers:r}}var q=require("fs"),g=l(require("handlebars"),1);function v({context:e={},path:t}){return g.default.compile((0,q.readFileSync)(t,"utf-8"))(e)}var w=l(require("inquirer"),1),C=require("lodash-es"),z=require("fs"),O=require("os"),j=require("path"),x="plano-templates";function F(e){return[`${(0,O.homedir)()}/${x}`,...e].map((e=>(0,j.resolve)(e))).filter((e=>(0,z.existsSync)(e))).map((e=>(0,z.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}async function P(e){const t=F(e),{template:r}=await w.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,C.sortedUniq)(t.map((({template:e})=>e)))}]);return r}var S=require("fs"),k=require("path"),T=require("glob"),$=l(require("handlebars"),1);var U=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}},_=require("lodash-es");var D=require("lodash-es");var E=require("lodash-es");var H=require("lodash-es");var M=require("lodash-es");var W={camelCase:function(e){return(0,_.camelCase)(e)},kebabCase:function(e){return(0,D.kebabCase)(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return(0,E.upperFirst)((0,E.camelCase)(e))},snakeCase:function(e){return(0,H.snakeCase)(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return(0,M.snakeCase)(e).toUpperCase()}};function A({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:n}}){Object.entries(r).map((([e,t])=>$.default.registerHelper(e,t)));const s=(0,k.resolve)(a,n,"template"),o=(0,T.globSync)(`${s}/**/*`,{withFileTypes:!0});o.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new U(["Template files must end with .handlebars:",e.fullpath()])}));for(let r of o){const a=$.default.compile(r.fullpath())(t).replace(`${s}/`,"");if(r.isDirectory()&&(0,S.mkdirSync)((0,k.resolve)(e,a)),r.isFile()){const n=v({context:t,path:r.fullpath()});(0,S.writeFileSync)((0,k.resolve)(e,a.replace(".handlebars","")),n)}}}Object.entries(W).map((([e,t])=>$.default.registerHelper(e,t)));var L=l(require("chalk"),1),N=require("lodash-es");function B({name:e,paths:t}){const r=F(t),a=r.find((t=>t.template===e));if(!a)throw new U([L.default.red(`Unable to find template "${e}" at paths:`),...(0,N.uniq)(r.map((e=>e.path)))]);return a}
1
+ "use strict";var e,t=Object.create,r=Object.defineProperty,a=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,p=(e,t,s,p)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let l of n(t))o.call(e,l)||l===s||r(e,l,{get:()=>t[l],enumerable:!(p=a(t,l))||p.enumerable});return e},l=(e,a,n)=>(n=null!=e?t(s(e)):{},p(!a&&e&&e.__esModule?n:r(n,"default",{value:e,enumerable:!0}),e)),i={};((e,t)=>{for(var a in t)r(e,a,{get:t[a],enumerable:!0})})(i,{compileTemplate:()=>g,generate:()=>N,getAllPaths:()=>S,getContextPrompts:()=>y,getTemplate:()=>I,promptForContext:()=>b,promptForTemplate:()=>k}),module.exports=(e=i,p(r({},"__esModule",{value:!0}),e));var u=l(require("inquirer"),1),c=require("path"),f=require("zod"),m=require("fs"),h=f.z.optional(f.z.array(f.z.object({message:f.z.string(),name:f.z.string(),required:f.z.boolean(),type:f.z.union([f.z.literal("input"),f.z.literal("select")])}))),d=f.z.optional(f.z.record(f.z.function(f.z.tuple([f.z.string()]),f.z.string())));async function y({template:{path:e,template:t}}){const r=(0,c.resolve)(`${e}/${t}`,"context.mjs");if(!(0,m.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:n}=await import(r);return{prompts:h.parse(a)||[],helpers:d.parse(n)||{}}}async function b(e){const{prompts:t,helpers:r}=await y(e);if(!t)return{context:{},helpers:r};return{context:await u.default.prompt(t)||{},helpers:r}}var q=require("fs"),w=l(require("handlebars"),1);function g({context:e={},helpers:t={},path:r}){return w.default.compile((0,q.readFileSync)(r,"utf-8"))(e)}var v=l(require("inquirer"),1),C=require("lodash-es"),z=require("fs"),O=require("os"),j=require("path"),x="plano",$="file-templates",F="snippet-templates";var P=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};function S({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${(0,O.homedir)()}/${x}/${$}`;case"snippet":return`${(0,O.homedir)()}/${x}/${F}`;default:throw new P([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>(0,j.resolve)(e))).filter((e=>(0,z.existsSync)(e))).map((e=>(0,z.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}async function k({paths:e,type:t}){const r=S({paths:e,type:t}),{template:a}=await v.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,C.sortedUniq)(r.map((({template:e})=>e)))}]);return a}var T=require("fs"),U=require("path"),_=require("glob"),D=l(require("handlebars"),1),E=require("lodash-es");var M=require("lodash-es");var W=require("lodash-es");var A=require("lodash-es");var H=require("lodash-es");var L={camelCase:function(e){return(0,E.camelCase)(e)},kebabCase:function(e){return(0,M.kebabCase)(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return(0,W.upperFirst)((0,W.camelCase)(e))},snakeCase:function(e){return(0,A.snakeCase)(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return(0,H.snakeCase)(e).toUpperCase()}};function N({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:n}}){Object.entries({...L,...r}).map((([e,t])=>D.default.registerHelper(e,t)));const s=(0,U.resolve)(a,n,"template"),o=(0,_.globSync)(`${s}/**/*`,{withFileTypes:!0});o.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new P(["Template files must end with .handlebars:",e.fullpath()])}));for(let a of o){const n=D.default.compile(a.fullpath())(t).replace(`${s}/`,"");if(a.isDirectory()&&(0,T.mkdirSync)((0,U.resolve)(e,n)),a.isFile()){const s=g({context:t,helpers:r,path:a.fullpath()});(0,T.writeFileSync)((0,U.resolve)(e,n.replace(".handlebars","")),s)}}}var B=l(require("chalk"),1),G=require("lodash-es");function I({name:e,paths:t,type:r}){const a=S({paths:t,type:r}),n=a.find((t=>t.template===e));if(!n)throw new P([B.default.red(`Unable to find template "${e}" at paths:`),...(0,G.uniq)(a.map((e=>e.path)))]);return n}
package/dist/index.d.cts CHANGED
@@ -29,17 +29,24 @@ declare function getContextPrompts({ template: { path, template }, }: GetContext
29
29
 
30
30
  interface CompileTemplate {
31
31
  context?: Record<string, unknown>;
32
+ helpers?: Record<string, HelperDelegate>;
32
33
  path: string;
33
34
  }
34
- declare function compileTemplate({ context, path }: CompileTemplate): string;
35
+ declare function compileTemplate({ context, helpers, path, }: CompileTemplate): string;
35
36
 
37
+ type TemplateType = 'file' | 'snippet';
38
+
39
+ interface PromptForTemplateOptions {
40
+ paths: string[];
41
+ type: TemplateType;
42
+ }
36
43
  /**
37
44
  * Prompt which template should be used for generation.
38
45
  *
39
46
  * @param paths - paths to search for templates
40
47
  * @returns selected template name
41
48
  */
42
- declare function promptForTemplate(paths: string[]): Promise<string>;
49
+ declare function promptForTemplate({ paths, type }: PromptForTemplateOptions): Promise<string>;
43
50
 
44
51
  interface GenerateOptions {
45
52
  copyToPath?: string;
@@ -52,7 +59,11 @@ interface GenerateOptions {
52
59
  }
53
60
  declare function generate({ copyToPath, context, helpers, template: { path, template }, }: GenerateOptions): void;
54
61
 
55
- declare function getAllPaths(paths: string[]): {
62
+ interface GetAllPathsOptions {
63
+ paths: string[];
64
+ type: TemplateType;
65
+ }
66
+ declare function getAllPaths({ paths, type }: GetAllPathsOptions): {
56
67
  path: string;
57
68
  template: string;
58
69
  }[];
@@ -60,8 +71,9 @@ declare function getAllPaths(paths: string[]): {
60
71
  interface GetTemplateOptions {
61
72
  name: string;
62
73
  paths: string[];
74
+ type: TemplateType;
63
75
  }
64
- declare function getTemplate({ name, paths }: GetTemplateOptions): {
76
+ declare function getTemplate({ name, paths, type }: GetTemplateOptions): {
65
77
  path: string;
66
78
  template: string;
67
79
  };
package/dist/index.d.ts CHANGED
@@ -29,17 +29,24 @@ declare function getContextPrompts({ template: { path, template }, }: GetContext
29
29
 
30
30
  interface CompileTemplate {
31
31
  context?: Record<string, unknown>;
32
+ helpers?: Record<string, HelperDelegate>;
32
33
  path: string;
33
34
  }
34
- declare function compileTemplate({ context, path }: CompileTemplate): string;
35
+ declare function compileTemplate({ context, helpers, path, }: CompileTemplate): string;
35
36
 
37
+ type TemplateType = 'file' | 'snippet';
38
+
39
+ interface PromptForTemplateOptions {
40
+ paths: string[];
41
+ type: TemplateType;
42
+ }
36
43
  /**
37
44
  * Prompt which template should be used for generation.
38
45
  *
39
46
  * @param paths - paths to search for templates
40
47
  * @returns selected template name
41
48
  */
42
- declare function promptForTemplate(paths: string[]): Promise<string>;
49
+ declare function promptForTemplate({ paths, type }: PromptForTemplateOptions): Promise<string>;
43
50
 
44
51
  interface GenerateOptions {
45
52
  copyToPath?: string;
@@ -52,7 +59,11 @@ interface GenerateOptions {
52
59
  }
53
60
  declare function generate({ copyToPath, context, helpers, template: { path, template }, }: GenerateOptions): void;
54
61
 
55
- declare function getAllPaths(paths: string[]): {
62
+ interface GetAllPathsOptions {
63
+ paths: string[];
64
+ type: TemplateType;
65
+ }
66
+ declare function getAllPaths({ paths, type }: GetAllPathsOptions): {
56
67
  path: string;
57
68
  template: string;
58
69
  }[];
@@ -60,8 +71,9 @@ declare function getAllPaths(paths: string[]): {
60
71
  interface GetTemplateOptions {
61
72
  name: string;
62
73
  paths: string[];
74
+ type: TemplateType;
63
75
  }
64
- declare function getTemplate({ name, paths }: GetTemplateOptions): {
76
+ declare function getTemplate({ name, paths, type }: GetTemplateOptions): {
65
77
  path: string;
66
78
  template: string;
67
79
  };
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-OPEC5HIS.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 c,promptForTemplate as e}from"./chunk-TSMFHBY6.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.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -30,21 +30,20 @@
30
30
  "devDependencies": {
31
31
  "@types/inquirer": "^9.0.7",
32
32
  "@types/lodash-es": "^4.17.12",
33
- "@types/node": "^20.10.5",
34
- "@vitest/coverage-v8": "^1.1.0",
35
- "prettier": "^3.2.2",
36
- "terser": "^5.26.0",
37
- "tsup": "^8.0.1",
38
- "typedoc": "^0.25.4",
39
- "typescript": "^5.3.3",
40
- "vitest": "^1.1.0"
33
+ "@types/node": "^20.11.30",
34
+ "@vitest/coverage-v8": "^1.4.0",
35
+ "prettier": "^3.2.5",
36
+ "terser": "^5.29.2",
37
+ "tsup": "^8.0.2",
38
+ "typescript": "^5.4.2",
39
+ "vitest": "^1.2.2"
41
40
  },
42
41
  "dependencies": {
43
42
  "chalk": "^5.3.0",
44
- "commander": "^11.1.0",
43
+ "commander": "^12.0.0",
45
44
  "glob": "^10.3.10",
46
45
  "handlebars": "^4.7.8",
47
- "inquirer": "^9.2.12",
46
+ "inquirer": "^9.2.16",
48
47
  "lodash-es": "^4.17.21",
49
48
  "zod": "^3.22.4"
50
49
  }
@@ -1 +0,0 @@
1
- import{resolve as e}from"path";import{z as t}from"zod";import{existsSync as r}from"fs";var o=t.optional(t.array(t.object({message:t.string(),name:t.string(),required:t.boolean(),type:t.union([t.literal("input"),t.literal("select")])}))),a=t.optional(t.record(t.function(t.tuple([t.string()]),t.string())));async function s({template:{path:t,template:s}}){const p=e(`${t}/${s}`,"context.mjs");if(!r(p))return{prompts:[],helpers:{}};const{prompts:n,helpers:i}=await import(p);return{prompts:o.parse(n)||[],helpers:a.parse(i)||{}}}import p from"inquirer";async function n(e){const{prompts:t,helpers:r}=await s(e);if(!t)return{context:{},helpers:r};return{context:await p.prompt(t)||{},helpers:r}}import{readFileSync as i}from"fs";import m from"handlebars";function l({context:e={},path:t}){return m.compile(i(t,"utf-8"))(e)}import{existsSync as c,readdirSync as f}from"fs";import{homedir as u}from"os";import{resolve as h}from"path";var d="plano-templates";function b(e){return[`${u()}/${d}`,...e].map((e=>h(e))).filter((e=>c(e))).map((e=>f(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}import C from"inquirer";import{sortedUniq as w}from"lodash-es";async function y(e){const t=b(e),{template:r}=await C.prompt([{name:"template",message:"Select a template",type:"list",choices:w(t.map((({template:e})=>e)))}]);return r}import{mkdirSync as g,writeFileSync as x}from"fs";import{resolve as k}from"path";import{globSync as $}from"glob";import j from"handlebars";var v=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};import{camelCase as F}from"lodash-es";import{kebabCase as O}from"lodash-es";import{camelCase as T,upperFirst as q}from"lodash-es";import{snakeCase as S}from"lodash-es";import{snakeCase as U}from"lodash-es";var D={camelCase:function(e){return F(e)},kebabCase:function(e){return O(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return q(T(e))},snakeCase:function(e){return S(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return U(e).toUpperCase()}};function E({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:o,template:a}}){Object.entries(r).map((([e,t])=>j.registerHelper(e,t)));const s=k(o,a,"template"),p=$(`${s}/**/*`,{withFileTypes:!0});p.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new v(["Template files must end with .handlebars:",e.fullpath()])}));for(let r of p){const o=j.compile(r.fullpath())(t).replace(`${s}/`,"");if(r.isDirectory()&&g(k(e,o)),r.isFile()){const a=l({context:t,path:r.fullpath()});x(k(e,o.replace(".handlebars","")),a)}}}Object.entries(D).map((([e,t])=>j.registerHelper(e,t)));import H from"chalk";import{uniq as P}from"lodash-es";function W({name:e,paths:t}){const r=b(t),o=r.find((t=>t.template===e));if(!o)throw new v([H.red(`Unable to find template "${e}" at paths:`),...P(r.map((e=>e.path)))]);return o}export{s as getContextPrompts,n as promptForContext,l as compileTemplate,b as getAllPaths,y as promptForTemplate,E as generate,W as getTemplate};