plano-cli 0.0.17 → 0.0.18

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 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.
@@ -0,0 +1 @@
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};
@@ -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,o=(o,i,p)=>(p=null!=o?e(s(o)):{},((e,s,o,i)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let p of a(s))n.call(e,p)||p===o||t(e,p,{get:()=>s[p],enumerable:!(i=r(s,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()}};Object.entries(z).map((([e,t])=>m.default.registerHelper(e,t)));var g=o(require("chalk"),1),v=require("lodash-es"),w=require("fs"),C=require("os"),j=require("path"),O="plano-templates";function x(e){return[`${(0,C.homedir)()}/${O}`,...e].map((e=>(0,j.resolve)(e))).filter((e=>(0,w.existsSync)(e))).map((e=>(0,w.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}var S=o(require("inquirer"),1),k=require("path"),P=require("zod"),F=require("fs"),$=P.z.optional(P.z.array(P.z.object({message:P.z.string(),name:P.z.string(),required:P.z.boolean(),type:P.z.union([P.z.literal("input"),P.z.literal("select")])}))),T=P.z.optional(P.z.record(P.z.function(P.z.tuple([P.z.string()]),P.z.string())));async function U(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,k.resolve)(`${e}/${t}`,"context.mjs");if(!(0,F.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:s}=await import(r);return{prompts:$.parse(a)||[],helpers:T.parse(s)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await S.default.prompt(t)||{},helpers:r}}var D=o(require("inquirer"),1),E=require("lodash-es");var H=new i.Command;H.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.17","-v, --version"),H.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=x(e),{template:r}=await D.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,E.sortedUniq)(t.map((({template:e})=>e)))}]);return r}(a));const s=function({name:e,paths:t}){const r=x(t),a=r.find((t=>t.template===e));if(!a)throw new f([g.default.red(`Unable to find template "${e}" at paths:`),...(0,v.uniq)(r.map((e=>e.path)))]);return a}({name:r,paths:a}),{context:n,helpers:o={}}=await U({template:s});!function({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:s}}){Object.entries(r).map((([e,t])=>m.default.registerHelper(e,t)));const n=(0,c.resolve)(a,s,"template"),o=(0,u.globSync)(`${n}/**/*`,{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(`${n}/`,"");if(r.isDirectory()&&(0,l.mkdirSync)((0,c.resolve)(e,a)),r.isFile()){const s=m.default.compile((0,l.readFileSync)(r.fullpath(),"utf-8"))(t);(0,l.writeFileSync)((0,c.resolve)(e,a.replace(".handlebars","")),s)}}}({context:n,helpers:o,template:s})}catch(e){e instanceof Error&&console.log(e.message)}})),H.parse();
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();
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-SQ2YSPC5.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.17","-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{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();
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,{generate:()=>H,getAllPaths:()=>O,getContextPrompts:()=>y,getTemplate:()=>A,promptForContext:()=>b,promptForTemplate:()=>j}),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 y({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 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=l(require("inquirer"),1),g=require("lodash-es"),v=require("fs"),w=require("os"),C=require("path"),z="plano-templates";function O(e){return[`${(0,w.homedir)()}/${z}`,...e].map((e=>(0,C.resolve)(e))).filter((e=>(0,v.existsSync)(e))).map((e=>(0,v.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}async function j(e){const t=O(e),{template:r}=await q.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,g.sortedUniq)(t.map((({template:e})=>e)))}]);return r}var x=require("fs"),F=require("path"),P=require("glob"),S=l(require("handlebars"),1);var k=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}},$=require("lodash-es");var T=require("lodash-es");var U=require("lodash-es");var _=require("lodash-es");var D=require("lodash-es");var E={camelCase:function(e){return(0,$.camelCase)(e)},kebabCase:function(e){return(0,T.kebabCase)(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return(0,U.upperFirst)((0,U.camelCase)(e))},snakeCase:function(e){return(0,_.snakeCase)(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return(0,D.snakeCase)(e).toUpperCase()}};function H({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:n}}){Object.entries(r).map((([e,t])=>S.default.registerHelper(e,t)));const s=(0,F.resolve)(a,n,"template"),o=(0,P.globSync)(`${s}/**/*`,{withFileTypes:!0});o.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new k(["Template files must end with .handlebars:",e.fullpath()])}));for(let r of o){const a=S.default.compile(r.fullpath())(t).replace(`${s}/`,"");if(r.isDirectory()&&(0,x.mkdirSync)((0,F.resolve)(e,a)),r.isFile()){const n=S.default.compile((0,x.readFileSync)(r.fullpath(),"utf-8"))(t);(0,x.writeFileSync)((0,F.resolve)(e,a.replace(".handlebars","")),n)}}}Object.entries(E).map((([e,t])=>S.default.registerHelper(e,t)));var M=l(require("chalk"),1),W=require("lodash-es");function A({name:e,paths:t}){const r=O(t),a=r.find((t=>t.template===e));if(!a)throw new k([M.default.red(`Unable to find template "${e}" at paths:`),...(0,W.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,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}
package/dist/index.d.cts CHANGED
@@ -27,6 +27,12 @@ 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
+ path: string;
33
+ }
34
+ declare function compileTemplate({ context, path }: CompileTemplate): string;
35
+
30
36
  /**
31
37
  * Prompt which template should be used for generation.
32
38
  *
@@ -60,4 +66,4 @@ declare function getTemplate({ name, paths }: GetTemplateOptions): {
60
66
  template: string;
61
67
  };
62
68
 
63
- export { generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
69
+ export { compileTemplate, generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,12 @@ 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
+ path: string;
33
+ }
34
+ declare function compileTemplate({ context, path }: CompileTemplate): string;
35
+
30
36
  /**
31
37
  * Prompt which template should be used for generation.
32
38
  *
@@ -60,4 +66,4 @@ declare function getTemplate({ name, paths }: GetTemplateOptions): {
60
66
  template: string;
61
67
  };
62
68
 
63
- export { generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
69
+ export { compileTemplate, generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{generate as o,getAllPaths as r,getContextPrompts as m,getTemplate as p,promptForContext as t,promptForTemplate as S}from"./chunk-SQ2YSPC5.js";export{o as generate,r as getAllPaths,m as getContextPrompts,p as getTemplate,t as promptForContext,S 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-OPEC5HIS.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.17",
3
+ "version": "0.0.18",
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",
@@ -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};