plano-cli 0.0.9 → 0.0.11
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 +42 -0
- package/dist/chunk-55Y2JSK6.js +1 -0
- package/dist/cli/plano.js +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-RIM3OUHY.js +0 -1
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
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolve as e}from"path";import t from"inquirer";import{z as r}from"zod";import{existsSync as a}from"fs";var o=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 p({template:{path:r,template:p}}){const n=e(`${r}/${p}`,"context.mjs");if(!a(n))return{context:{},helpers:{}};const{prompts:i,helpers:m}=await import(n),l=o.parse(i)||[],c=s.parse(m)||{};return{context:await t.prompt(l)||{},helpers:c}}import n from"inquirer";import{sortedUniq as i}from"lodash-es";import{existsSync as m,readdirSync as l}from"fs";import{homedir as c}from"os";import{resolve as f}from"path";var u="plano-templates";function h(e){return[`${c()}/${u}`,...e].map((e=>f(e))).filter((e=>m(e))).map((e=>l(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((t=>({path:e,template:t.name}))))).flat()}async function d(e){const t=h(e),{template:r}=await n.prompt([{name:"template",message:"Select a template",type:"list",choices:i(t.map((({template:e})=>e)))}]);return r}import{mkdirSync as b,readFileSync as C,writeFileSync as w}from"fs";import{resolve as y}from"path";import{globSync as g}from"glob";import k from"handlebars";var x=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};import{camelCase as $}from"lodash-es";import{kebabCase as j}from"lodash-es";import{camelCase as v,upperFirst as F}from"lodash-es";import{snakeCase as O}from"lodash-es";import{snakeCase as q}from"lodash-es";var S={camelCase:function(e){return $(e)},kebabCase:function(e){return j(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return F(v(e))},snakeCase:function(e){return O(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return q(e).toUpperCase()}};function T({context:e={},helpers:t={},template:{path:r,template:a}}){Object.entries(t).map((([e,t])=>k.registerHelper(e,t)));const o=y(r,a,"template"),s=g(`${o}/**/*`,{withFileTypes:!0});s.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new x(["Template files must end with .handlebars:",e.fullpath()])}));for(let t of s){const r=k.compile(t.fullpath())(e).replace(`${o}/`,"");if(t.isDirectory()&&b(y(process.cwd(),r)),t.isFile()){const a=k.compile(C(t.fullpath(),"utf-8"))(e);w(y(process.cwd(),r.replace(".handlebars","")),a)}}}Object.entries(S).map((([e,t])=>k.registerHelper(e,t)));import U from"chalk";import{uniq as D}from"lodash-es";function E({name:e,paths:t}){const r=h(t),a=r.find((t=>t.template===e));if(!a)throw new x([U.red(`Unable to find template "${e}" at paths:`),...D(r.map((e=>e.path)))]);return a}export{p as promptForContext,d as promptForTemplate,T as generate,E 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-
|
|
2
|
+
import{generate as e,getTemplate as t,promptForContext as a,promptForTemplate as o}from"../chunk-55Y2JSK6.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.11","-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();
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,14 @@ declare function promptForContext({ template: { path, template }, }: PromptForCo
|
|
|
11
11
|
helpers: Record<string, (args_0: string) => string>;
|
|
12
12
|
}>;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Prompt which template should be used for generation.
|
|
16
|
+
*
|
|
17
|
+
* @param paths - paths to search for templates
|
|
18
|
+
* @returns selected template name
|
|
19
|
+
*/
|
|
20
|
+
declare function promptForTemplate(paths: string[]): Promise<string>;
|
|
21
|
+
|
|
14
22
|
interface GenerateOptions {
|
|
15
23
|
template: {
|
|
16
24
|
path: string;
|
|
@@ -30,4 +38,4 @@ declare function getTemplate({ name, paths }: GetTemplateOptions): {
|
|
|
30
38
|
template: string;
|
|
31
39
|
};
|
|
32
40
|
|
|
33
|
-
export { generate, getTemplate, promptForContext };
|
|
41
|
+
export { generate, getTemplate, promptForContext, promptForTemplate };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{generate as o,getTemplate as r,promptForContext as m}from"./chunk-
|
|
1
|
+
import{generate as o,getTemplate as r,promptForContext as m,promptForTemplate as p}from"./chunk-55Y2JSK6.js";export{o as generate,r as getTemplate,m as promptForContext,p as promptForTemplate};
|
package/package.json
CHANGED
package/dist/chunk-RIM3OUHY.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|