plano-cli 0.0.18 → 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/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 +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-OPEC5HIS.js +0 -1
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,
|
|
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
|
@@ -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:
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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-
|
|
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
package/dist/chunk-OPEC5HIS.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 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};
|