plano-cli 0.0.17 → 0.0.19
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/LICENSE +21 -0
- package/README.md +5 -4
- package/dist/chunk-TSMFHBY6.js +1 -0
- package/dist/cli/plano.cjs +1 -1
- package/dist/cli/plano.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +22 -4
- package/dist/index.d.ts +22 -4
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/dist/chunk-SQ2YSPC5.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Matthew Wolfe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Plano CLI
|
|
2
2
|
|
|
3
|
-
A CLI and programmatic API for generating files
|
|
3
|
+
A CLI and programmatic API for generating files and/or directories from
|
|
4
|
+
templates with context values and helper functions.
|
|
4
5
|
|
|
5
6
|
## Getting Started
|
|
6
7
|
|
|
@@ -14,7 +15,7 @@ npm install plano-cli
|
|
|
14
15
|
|
|
15
16
|
## Quick Start
|
|
16
17
|
|
|
17
|
-
Create a directory named `plano
|
|
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
|
|
@@ -28,7 +29,7 @@ Arguments:
|
|
|
28
29
|
name template name
|
|
29
30
|
|
|
30
31
|
Options:
|
|
31
|
-
-p, --paths <path...> Paths to templates, must be directory named "plano
|
|
32
|
+
-p, --paths <path...> Paths to templates, must be directory named "plano" (default: [])
|
|
32
33
|
-h, --help display help for command
|
|
33
34
|
```
|
|
34
35
|
|
|
@@ -41,5 +42,5 @@ plano generate react-component
|
|
|
41
42
|
#### Example with paths
|
|
42
43
|
|
|
43
44
|
```
|
|
44
|
-
plano generate react-component -p ./path/to/plano
|
|
45
|
+
plano generate react-component -p ./path/to/plano
|
|
45
46
|
```
|
|
@@ -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};
|
package/dist/cli/plano.cjs
CHANGED
|
@@ -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,s=Object.getPrototypeOf,n=Object.prototype.hasOwnProperty,
|
|
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.19","-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
|
|
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.19","-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,
|
|
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
|
@@ -27,13 +27,26 @@ declare function getContextPrompts({ template: { path, template }, }: GetContext
|
|
|
27
27
|
helpers: Record<string, (args_0: string) => string>;
|
|
28
28
|
}>;
|
|
29
29
|
|
|
30
|
+
interface CompileTemplate {
|
|
31
|
+
context?: Record<string, unknown>;
|
|
32
|
+
helpers?: Record<string, HelperDelegate>;
|
|
33
|
+
path: string;
|
|
34
|
+
}
|
|
35
|
+
declare function compileTemplate({ context, helpers, path, }: CompileTemplate): string;
|
|
36
|
+
|
|
37
|
+
type TemplateType = 'file' | 'snippet';
|
|
38
|
+
|
|
39
|
+
interface PromptForTemplateOptions {
|
|
40
|
+
paths: string[];
|
|
41
|
+
type: TemplateType;
|
|
42
|
+
}
|
|
30
43
|
/**
|
|
31
44
|
* Prompt which template should be used for generation.
|
|
32
45
|
*
|
|
33
46
|
* @param paths - paths to search for templates
|
|
34
47
|
* @returns selected template name
|
|
35
48
|
*/
|
|
36
|
-
declare function promptForTemplate(paths:
|
|
49
|
+
declare function promptForTemplate({ paths, type }: PromptForTemplateOptions): Promise<string>;
|
|
37
50
|
|
|
38
51
|
interface GenerateOptions {
|
|
39
52
|
copyToPath?: string;
|
|
@@ -46,7 +59,11 @@ interface GenerateOptions {
|
|
|
46
59
|
}
|
|
47
60
|
declare function generate({ copyToPath, context, helpers, template: { path, template }, }: GenerateOptions): void;
|
|
48
61
|
|
|
49
|
-
|
|
62
|
+
interface GetAllPathsOptions {
|
|
63
|
+
paths: string[];
|
|
64
|
+
type: TemplateType;
|
|
65
|
+
}
|
|
66
|
+
declare function getAllPaths({ paths, type }: GetAllPathsOptions): {
|
|
50
67
|
path: string;
|
|
51
68
|
template: string;
|
|
52
69
|
}[];
|
|
@@ -54,10 +71,11 @@ declare function getAllPaths(paths: string[]): {
|
|
|
54
71
|
interface GetTemplateOptions {
|
|
55
72
|
name: string;
|
|
56
73
|
paths: string[];
|
|
74
|
+
type: TemplateType;
|
|
57
75
|
}
|
|
58
|
-
declare function getTemplate({ name, paths }: GetTemplateOptions): {
|
|
76
|
+
declare function getTemplate({ name, paths, type }: GetTemplateOptions): {
|
|
59
77
|
path: string;
|
|
60
78
|
template: string;
|
|
61
79
|
};
|
|
62
80
|
|
|
63
|
-
export { generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
|
|
81
|
+
export { compileTemplate, generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,13 +27,26 @@ declare function getContextPrompts({ template: { path, template }, }: GetContext
|
|
|
27
27
|
helpers: Record<string, (args_0: string) => string>;
|
|
28
28
|
}>;
|
|
29
29
|
|
|
30
|
+
interface CompileTemplate {
|
|
31
|
+
context?: Record<string, unknown>;
|
|
32
|
+
helpers?: Record<string, HelperDelegate>;
|
|
33
|
+
path: string;
|
|
34
|
+
}
|
|
35
|
+
declare function compileTemplate({ context, helpers, path, }: CompileTemplate): string;
|
|
36
|
+
|
|
37
|
+
type TemplateType = 'file' | 'snippet';
|
|
38
|
+
|
|
39
|
+
interface PromptForTemplateOptions {
|
|
40
|
+
paths: string[];
|
|
41
|
+
type: TemplateType;
|
|
42
|
+
}
|
|
30
43
|
/**
|
|
31
44
|
* Prompt which template should be used for generation.
|
|
32
45
|
*
|
|
33
46
|
* @param paths - paths to search for templates
|
|
34
47
|
* @returns selected template name
|
|
35
48
|
*/
|
|
36
|
-
declare function promptForTemplate(paths:
|
|
49
|
+
declare function promptForTemplate({ paths, type }: PromptForTemplateOptions): Promise<string>;
|
|
37
50
|
|
|
38
51
|
interface GenerateOptions {
|
|
39
52
|
copyToPath?: string;
|
|
@@ -46,7 +59,11 @@ interface GenerateOptions {
|
|
|
46
59
|
}
|
|
47
60
|
declare function generate({ copyToPath, context, helpers, template: { path, template }, }: GenerateOptions): void;
|
|
48
61
|
|
|
49
|
-
|
|
62
|
+
interface GetAllPathsOptions {
|
|
63
|
+
paths: string[];
|
|
64
|
+
type: TemplateType;
|
|
65
|
+
}
|
|
66
|
+
declare function getAllPaths({ paths, type }: GetAllPathsOptions): {
|
|
50
67
|
path: string;
|
|
51
68
|
template: string;
|
|
52
69
|
}[];
|
|
@@ -54,10 +71,11 @@ declare function getAllPaths(paths: string[]): {
|
|
|
54
71
|
interface GetTemplateOptions {
|
|
55
72
|
name: string;
|
|
56
73
|
paths: string[];
|
|
74
|
+
type: TemplateType;
|
|
57
75
|
}
|
|
58
|
-
declare function getTemplate({ name, paths }: GetTemplateOptions): {
|
|
76
|
+
declare function getTemplate({ name, paths, type }: GetTemplateOptions): {
|
|
59
77
|
path: string;
|
|
60
78
|
template: string;
|
|
61
79
|
};
|
|
62
80
|
|
|
63
|
-
export { generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
|
|
81
|
+
export { compileTemplate, generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"@types/lodash-es": "^4.17.12",
|
|
33
33
|
"@types/node": "^20.10.5",
|
|
34
34
|
"@vitest/coverage-v8": "^1.1.0",
|
|
35
|
+
"prettier": "^3.2.2",
|
|
35
36
|
"terser": "^5.26.0",
|
|
36
37
|
"tsup": "^8.0.1",
|
|
37
38
|
"typedoc": "^0.25.4",
|
package/dist/chunk-SQ2YSPC5.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{resolve as e}from"path";import{z as t}from"zod";import{existsSync as r}from"fs";var a=t.optional(t.array(t.object({message:t.string(),name:t.string(),required:t.boolean(),type:t.union([t.literal("input"),t.literal("select")])}))),o=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:a.parse(n)||[],helpers:o.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{existsSync as i,readdirSync as m}from"fs";import{homedir as l}from"os";import{resolve as c}from"path";var f="plano-templates";function u(e){return[`${l()}/${f}`,...e].map((e=>c(e))).filter((e=>i(e))).map((e=>m(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}import h from"inquirer";import{sortedUniq as d}from"lodash-es";async function b(e){const t=u(e),{template:r}=await h.prompt([{name:"template",message:"Select a template",type:"list",choices:d(t.map((({template:e})=>e)))}]);return r}import{mkdirSync as C,readFileSync as w,writeFileSync as y}from"fs";import{resolve as g}from"path";import{globSync as k}from"glob";import x from"handlebars";var $=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};import{camelCase as j}from"lodash-es";import{kebabCase as v}from"lodash-es";import{camelCase as F,upperFirst as O}from"lodash-es";import{snakeCase as T}from"lodash-es";import{snakeCase as q}from"lodash-es";var S={camelCase:function(e){return j(e)},kebabCase:function(e){return v(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return O(F(e))},snakeCase:function(e){return T(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return q(e).toUpperCase()}};function U({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:o}}){Object.entries(r).map((([e,t])=>x.registerHelper(e,t)));const s=g(a,o,"template"),p=k(`${s}/**/*`,{withFileTypes:!0});p.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new $(["Template files must end with .handlebars:",e.fullpath()])}));for(let r of p){const a=x.compile(r.fullpath())(t).replace(`${s}/`,"");if(r.isDirectory()&&C(g(e,a)),r.isFile()){const o=x.compile(w(r.fullpath(),"utf-8"))(t);y(g(e,a.replace(".handlebars","")),o)}}}Object.entries(S).map((([e,t])=>x.registerHelper(e,t)));import D from"chalk";import{uniq as E}from"lodash-es";function H({name:e,paths:t}){const r=u(t),a=r.find((t=>t.template===e));if(!a)throw new $([D.red(`Unable to find template "${e}" at paths:`),...E(r.map((e=>e.path)))]);return a}export{s as getContextPrompts,n as promptForContext,u as getAllPaths,b as promptForTemplate,U as generate,H as getTemplate};
|