plano-cli 0.0.10 → 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 CHANGED
@@ -20,7 +20,7 @@ Additional paths can be specified.
20
20
  ### Generate
21
21
 
22
22
  ```
23
- Usage: plano generate [options] <name>
23
+ Usage: plano generate [options] [name]
24
24
 
25
25
  Generate files or directories from a template
26
26
 
@@ -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,getAllPaths as t,getTemplate as a,promptForContext as o}from"../chunk-KWPQWHSQ.js";import{Command as r}from"commander";import{z as s}from"zod";import m from"inquirer";import{sortedUniq as n}from"lodash-es";var p=new r;p.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.10","-v, --version"),p.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,p)=>{try{let i=s.optional(s.string()).parse(r);const{paths:c}=s.object({paths:s.array(s.string())}).parse(p);void 0===i&&(i=await async function(e){const a=t(e),{template:o}=await m.prompt([{name:"template",message:"Select a template",type:"list",choices:n(a.map((({template:e})=>e)))}]);return o}(c));const l=a({name:i,paths:c}),{context:d,helpers:f={}}=await o({template:l});e({context:d,helpers:f,template:l})}catch(e){e instanceof Error&&console.log(e.message)}})),p.parse();
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-KWPQWHSQ.js";export{o as generate,r as getTemplate,m as promptForContext};
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plano-cli",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
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 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 x from"chalk";import{uniq as $}from"lodash-es";import{existsSync as j,readdirSync as v}from"fs";import{homedir as F}from"os";import{resolve as O}from"path";var T="plano-templates";function U(e){return[`${F()}/${T}`,...e].map((e=>O(e))).filter((e=>j(e))).map((e=>v(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((t=>({path:e,template:t.name}))))).flat()}function q({name:e,paths:t}){const r=U(t),o=r.find((t=>t.template===e));if(!o)throw new u([x.red(`Unable to find template "${e}" at paths:`),...$(r.map((e=>e.path)))]);return o}export{n as promptForContext,k as generate,U as getAllPaths,q as getTemplate};