plano-cli 0.0.9 → 0.0.10

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,3 +1,45 @@
1
1
  # Plano CLI
2
2
 
3
3
  A CLI and programmatic API for generating files from templates with context values and helper functions.
4
+
5
+ ## Getting Started
6
+
7
+ ### Installation
8
+
9
+ It is recommended to install globally if using the CLI.
10
+
11
+ ```
12
+ npm install plano-cli
13
+ ```
14
+
15
+ ## Quick Start
16
+
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
+ Additional paths can be specified.
19
+
20
+ ### Generate
21
+
22
+ ```
23
+ Usage: plano generate [options] <name>
24
+
25
+ Generate files or directories from a template
26
+
27
+ Arguments:
28
+ name template name
29
+
30
+ Options:
31
+ -p, --paths <path...> Paths to templates, must be directory named "plano-templates" (default: [])
32
+ -h, --help display help for command
33
+ ```
34
+
35
+ #### Example
36
+
37
+ ```
38
+ plano generate react-component
39
+ ```
40
+
41
+ #### Example with paths
42
+
43
+ ```
44
+ plano generate react-component -p ./path/to/plano-templates
45
+ ```
@@ -1 +1 @@
1
- import{resolve as e}from"path";import t from"inquirer";import{z as r}from"zod";import{existsSync as o}from"fs";var a=r.optional(r.array(r.object({message:r.string(),name:r.string(),required:r.boolean(),type:r.union([r.literal("input"),r.literal("select")])}))),s=r.optional(r.record(r.function(r.tuple([r.string()]),r.string())));async function n({template:{path:r,template:n}}){const p=e(`${r}/${n}`,"context.mjs");if(!o(p))return{context:{},helpers:{}};const{prompts:i,helpers:m}=await import(p),l=a.parse(i)||[],f=s.parse(m)||{};return{context:await t.prompt(l)||{},helpers:f}}import{mkdirSync as p,readFileSync as i,writeFileSync as m}from"fs";import{resolve as l}from"path";import{globSync as f}from"glob";import c from"handlebars";var u=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};import{camelCase as h}from"lodash-es";import{kebabCase as d}from"lodash-es";import{camelCase as b,upperFirst as C}from"lodash-es";import{snakeCase as w}from"lodash-es";import{snakeCase as y}from"lodash-es";var g={camelCase:function(e){return h(e)},kebabCase:function(e){return d(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return C(b(e))},snakeCase:function(e){return w(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return y(e).toUpperCase()}};function k({context:e={},helpers:t={},template:{path:r,template:o}}){Object.entries(t).map((([e,t])=>c.registerHelper(e,t)));const a=l(r,o,"template"),s=f(`${a}/**/*`,{withFileTypes:!0});s.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new u(["Template files must end with .handlebars:",e.fullpath()])}));for(let t of s){const r=c.compile(t.fullpath())(e).replace(`${a}/`,"");if(t.isDirectory()&&p(l(process.cwd(),r)),t.isFile()){const o=c.compile(i(t.fullpath(),"utf-8"))(e);m(l(process.cwd(),r.replace(".handlebars","")),o)}}}Object.entries(g).map((([e,t])=>c.registerHelper(e,t)));import{existsSync as x,readdirSync as $}from"fs";import{homedir as j}from"os";import{resolve as v}from"path";import F from"chalk";import{uniq as O}from"lodash-es";var T="plano-templates";function U({name:e,paths:t}){const r=function(e){return[`${j()}/${T}`,...e].map((e=>v(e))).filter((e=>x(e))).map((e=>$(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((t=>({path:e,template:t.name}))))).flat()}(t),o=r.find((t=>t.template===e));if(!o)throw new u([F.red(`Unable to find template "${e}" at paths:`),...O(r.map((e=>e.path)))]);return o}export{n as promptForContext,k as generate,U as getTemplate};
1
+ import{resolve as e}from"path";import t from"inquirer";import{z as r}from"zod";import{existsSync as o}from"fs";var a=r.optional(r.array(r.object({message:r.string(),name:r.string(),required:r.boolean(),type:r.union([r.literal("input"),r.literal("select")])}))),s=r.optional(r.record(r.function(r.tuple([r.string()]),r.string())));async function n({template:{path:r,template:n}}){const p=e(`${r}/${n}`,"context.mjs");if(!o(p))return{context:{},helpers:{}};const{prompts:i,helpers:m}=await import(p),l=a.parse(i)||[],f=s.parse(m)||{};return{context:await t.prompt(l)||{},helpers:f}}import{mkdirSync as p,readFileSync as i,writeFileSync as m}from"fs";import{resolve as l}from"path";import{globSync as f}from"glob";import c from"handlebars";var u=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};import{camelCase as h}from"lodash-es";import{kebabCase as d}from"lodash-es";import{camelCase as b,upperFirst as C}from"lodash-es";import{snakeCase as w}from"lodash-es";import{snakeCase as y}from"lodash-es";var g={camelCase:function(e){return h(e)},kebabCase:function(e){return d(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return C(b(e))},snakeCase:function(e){return w(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return y(e).toUpperCase()}};function k({context:e={},helpers:t={},template:{path:r,template:o}}){Object.entries(t).map((([e,t])=>c.registerHelper(e,t)));const a=l(r,o,"template"),s=f(`${a}/**/*`,{withFileTypes:!0});s.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new u(["Template files must end with .handlebars:",e.fullpath()])}));for(let t of s){const r=c.compile(t.fullpath())(e).replace(`${a}/`,"");if(t.isDirectory()&&p(l(process.cwd(),r)),t.isFile()){const o=c.compile(i(t.fullpath(),"utf-8"))(e);m(l(process.cwd(),r.replace(".handlebars","")),o)}}}Object.entries(g).map((([e,t])=>c.registerHelper(e,t)));import x from"chalk";import{uniq as $}from"lodash-es";import{existsSync as j,readdirSync as v}from"fs";import{homedir as F}from"os";import{resolve as O}from"path";var T="plano-templates";function U(e){return[`${F()}/${T}`,...e].map((e=>O(e))).filter((e=>j(e))).map((e=>v(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((t=>({path:e,template:t.name}))))).flat()}function q({name:e,paths:t}){const r=U(t),o=r.find((t=>t.template===e));if(!o)throw new u([x.red(`Unable to find template "${e}" at paths:`),...$(r.map((e=>e.path)))]);return o}export{n as promptForContext,k as generate,U as getAllPaths,q as getTemplate};
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}from"../chunk-RIM3OUHY.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.9","-v, --version"),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();
2
+ import{generate as e,getAllPaths as t,getTemplate as a,promptForContext as o}from"../chunk-KWPQWHSQ.js";import{Command as r}from"commander";import{z as s}from"zod";import m from"inquirer";import{sortedUniq as n}from"lodash-es";var p=new r;p.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.10","-v, --version"),p.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,p)=>{try{let i=s.optional(s.string()).parse(r);const{paths:c}=s.object({paths:s.array(s.string())}).parse(p);void 0===i&&(i=await async function(e){const a=t(e),{template:o}=await m.prompt([{name:"template",message:"Select a template",type:"list",choices:n(a.map((({template:e})=>e)))}]);return o}(c));const l=a({name:i,paths:c}),{context:d,helpers:f={}}=await o({template:l});e({context:d,helpers:f,template:l})}catch(e){e instanceof Error&&console.log(e.message)}})),p.parse();
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{generate as o,getTemplate as r,promptForContext as m}from"./chunk-RIM3OUHY.js";export{o as generate,r as getTemplate,m as promptForContext};
1
+ import{generate as o,getTemplate as r,promptForContext as m}from"./chunk-KWPQWHSQ.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.9",
3
+ "version": "0.0.10",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [