plano-cli 0.0.12 → 0.0.13

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.
@@ -0,0 +1 @@
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())).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 w,readFileSync as C,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 q}from"lodash-es";import{snakeCase as S}from"lodash-es";var T={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 q(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return S(e).toUpperCase()}};function U({context:e={},helpers:t={},template:{path:r,template:a}}){Object.entries(t).map((([e,t])=>x.registerHelper(e,t)));const o=g(r,a,"template"),s=k(`${o}/**/*`,{withFileTypes:!0});s.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new $(["Template files must end with .handlebars:",e.fullpath()])}));for(let t of s){const r=x.compile(t.fullpath())(e).replace(`${o}/`,"");if(t.isDirectory()&&w(g(process.cwd(),r)),t.isFile()){const a=x.compile(C(t.fullpath(),"utf-8"))(e);y(g(process.cwd(),r.replace(".handlebars","")),a)}}}Object.entries(T).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};
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-4ZXXXZBC.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.12","-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-CNXKNBAQ.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.13","-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
@@ -6,11 +6,27 @@ interface PromptForContextOptions {
6
6
  template: string;
7
7
  };
8
8
  }
9
- declare function promptForContext({ template: { path, template }, }: PromptForContextOptions): Promise<{
9
+ declare function promptForContext(options: PromptForContextOptions): Promise<{
10
10
  context: Record<string, unknown>;
11
11
  helpers: Record<string, (args_0: string) => string>;
12
12
  }>;
13
13
 
14
+ interface GetContextPromptsOptions {
15
+ template: {
16
+ path: string;
17
+ template: string;
18
+ };
19
+ }
20
+ declare function getContextPrompts({ template: { path, template }, }: GetContextPromptsOptions): Promise<{
21
+ prompts: {
22
+ message: string;
23
+ type: "input" | "select";
24
+ name: string;
25
+ required: boolean;
26
+ }[];
27
+ helpers: Record<string, (args_0: string) => string>;
28
+ }>;
29
+
14
30
  /**
15
31
  * Prompt which template should be used for generation.
16
32
  *
@@ -43,4 +59,4 @@ declare function getTemplate({ name, paths }: GetTemplateOptions): {
43
59
  template: string;
44
60
  };
45
61
 
46
- export { generate, getAllPaths, getTemplate, promptForContext, promptForTemplate };
62
+ export { generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{generate as o,getAllPaths as r,getTemplate as X,promptForContext as m,promptForTemplate as p}from"./chunk-4ZXXXZBC.js";export{o as generate,r as getAllPaths,X as getTemplate,m as promptForContext,p as promptForTemplate};
1
+ import{generate as o,getAllPaths as r,getContextPrompts as m,getTemplate as p,promptForContext as t,promptForTemplate as N}from"./chunk-CNXKNBAQ.js";export{o as generate,r as getAllPaths,m as getContextPrompts,p as getTemplate,t as promptForContext,N as promptForTemplate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plano-cli",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -1 +0,0 @@
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{existsSync as n,readdirSync as i}from"fs";import{homedir as m}from"os";import{resolve as l}from"path";var c="plano-templates";function f(e){return[`${m()}/${c}`,...e].map((e=>l(e))).filter((e=>n(e))).map((e=>i(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((t=>({path:e,template:t.name}))))).flat()}import u from"inquirer";import{sortedUniq as h}from"lodash-es";async function d(e){const t=f(e),{template:r}=await u.prompt([{name:"template",message:"Select a template",type:"list",choices:h(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=f(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,f as getAllPaths,d as promptForTemplate,T as generate,E as getTemplate};