plano-cli 0.1.1 → 0.3.0

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"node:path";import{z as t}from"zod";import{existsSync as r}from"node:fs";import{z as o}from"zod";import{z as a}from"zod";var s=a.object({message:a.string(),name:a.string(),required:a.boolean()}),p=o.object({value:o.string()}).passthrough(),n=s.extend({type:o.literal("checkbox"),choices:o.array(p)}).passthrough();import{z as i}from"zod";var m=s.extend({type:i.literal("input")}).passthrough();import{z as c}from"zod";var l=c.object({value:c.string()}).passthrough(),f=s.extend({type:c.literal("select"),choices:c.array(l)}).passthrough(),h=t.optional(t.array(t.discriminatedUnion("type",[n,m,f]))),u=t.optional(t.record(t.function(t.tuple([t.string()]),t.string())));async function d({template:{path:t,template:o}}){const a=e(`${t}/${o}`,"context.mjs");if(!r(a))return{prompts:[],helpers:{}};const{prompts:s,helpers:p}=await import(a);return{prompts:h.parse(s)||[],helpers:u.parse(p)||{}}}import{checkbox as y,input as b,select as g}from"@inquirer/prompts";async function w(e){const{prompts:t,helpers:r}=await d(e);if(!t)return{context:{},helpers:r};const o={};for(let e=0;e<t.length;e++){const r=t[e];switch(r.type){case"checkbox":o[r.name]=await y(r);break;case"input":o[r.name]=await b(r);break;case"select":o[r.name]=await g(r)}}return{context:o,helpers:r}}import{readFileSync as C}from"node:fs";import x from"handlebars";function k({context:e={},helpers:t={},path:r}){return x.compile(C(r,"utf-8"))(e)}import{existsSync as v,readdirSync as $}from"node:fs";import{homedir as z}from"node:os";import{resolve as j}from"node:path";var U="plano";var q=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};function F({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${z()}/${U}/file-templates`;case"snippet":return`${z()}/${U}/snippet-templates`;default:throw new q([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>j(e))).filter((e=>v(e))).map((e=>$(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}import{select as O}from"@inquirer/prompts";import{sortedUniq as S}from"lodash-es";async function T({paths:e,type:t}){const r=F({paths:e,type:t});return await O({message:"Select a template",choices:S(r.map((({template:e})=>({value:e}))))})}import{mkdirSync as D,writeFileSync as P,copyFileSync as W}from"node:fs";import{resolve as E}from"node:path";import{globSync as H}from"glob";import L from"handlebars";import{camelCase as A}from"lodash-es";import{kebabCase as B}from"lodash-es";import{camelCase as G,upperFirst as I}from"lodash-es";import{snakeCase as J}from"lodash-es";import{snakeCase as K}from"lodash-es";var M={camelCase:function(e){return A(e)},kebabCase:function(e){return B(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return I(G(e))},snakeCase:function(e){return J(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return K(e).toUpperCase()}};function N({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:o,template:a}}){Object.entries({...M,...r}).map((([e,t])=>L.registerHelper(e,t)));const s=E(o,a,"template"),p=H(`${s}/**/*`,{withFileTypes:!0,dot:!0});for(let o of p){const a=o.fullpath(),p=L.compile(a)(t).replace(`${s}/`,"");if(o.isDirectory()&&D(E(e,p)),o.isFile())if(o.name.endsWith(".handlebars")){const o=k({context:t,helpers:r,path:a});P(E(e,p.replace(".handlebars","")),o)}else{const t=E(e,a).replace(`${s}/`,"");W(a,t)}}}import Q from"chalk";import{uniq as R}from"lodash-es";function V({name:e,paths:t,type:r}){const o=F({paths:t,type:r}),a=o.find((t=>t.template===e));if(!a)throw new q([Q.red(`Unable to find template "${e}" at paths:`),...R(o.map((e=>e.path)))]);return a}export{d as getContextPrompts,w as promptForContext,k as compileTemplate,F as getAllPaths,T as promptForTemplate,N as generate,V as getTemplate};
package/dist/cli/plano.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{compileTemplate as t,generate as e,getTemplate as a,promptForContext as o,promptForTemplate as s}from"../chunk-YSHKHHP5.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.1.1","-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();
2
+ import{compileTemplate as t,generate as e,getTemplate as a,promptForContext as o,promptForTemplate as s}from"../chunk-QIWEIH4Q.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.3.0","-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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { z } from 'zod';
1
2
  import { HelperDelegate } from 'handlebars';
2
3
 
3
4
  interface PromptForContextOptions {
@@ -7,9 +8,7 @@ interface PromptForContextOptions {
7
8
  };
8
9
  }
9
10
  declare function promptForContext(options: PromptForContextOptions): Promise<{
10
- context: {
11
- [x: string]: unknown;
12
- };
11
+ context: Record<string, unknown>;
13
12
  helpers: Record<string, (args_0: string) => string>;
14
13
  }>;
15
14
 
@@ -20,12 +19,39 @@ interface GetContextPromptsOptions {
20
19
  };
21
20
  }
22
21
  declare function getContextPrompts({ template: { path, template }, }: GetContextPromptsOptions): Promise<{
23
- prompts: {
24
- message: string;
25
- type: "input" | "select";
26
- name: string;
27
- required: boolean;
28
- }[];
22
+ prompts: (z.objectOutputType<z.objectUtil.extendShape<{
23
+ message: z.ZodString;
24
+ name: z.ZodString;
25
+ required: z.ZodBoolean;
26
+ }, {
27
+ type: z.ZodLiteral<"checkbox">;
28
+ choices: z.ZodArray<z.ZodObject<{
29
+ value: z.ZodString;
30
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
31
+ value: z.ZodString;
32
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
33
+ value: z.ZodString;
34
+ }, z.ZodTypeAny, "passthrough">>, "many">;
35
+ }>, z.ZodTypeAny, "passthrough"> | z.objectOutputType<z.objectUtil.extendShape<{
36
+ message: z.ZodString;
37
+ name: z.ZodString;
38
+ required: z.ZodBoolean;
39
+ }, {
40
+ type: z.ZodLiteral<"input">;
41
+ }>, z.ZodTypeAny, "passthrough"> | z.objectOutputType<z.objectUtil.extendShape<{
42
+ message: z.ZodString;
43
+ name: z.ZodString;
44
+ required: z.ZodBoolean;
45
+ }, {
46
+ type: z.ZodLiteral<"select">;
47
+ choices: z.ZodArray<z.ZodObject<{
48
+ value: z.ZodString;
49
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
50
+ value: z.ZodString;
51
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
52
+ value: z.ZodString;
53
+ }, z.ZodTypeAny, "passthrough">>, "many">;
54
+ }>, z.ZodTypeAny, "passthrough">)[];
29
55
  helpers: Record<string, (args_0: string) => string>;
30
56
  }>;
31
57
 
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{compileTemplate as o,generate as r,getAllPaths as H,getContextPrompts as m,getTemplate as p,promptForContext as t,promptForTemplate as c}from"./chunk-YSHKHHP5.js";export{o as compileTemplate,r as generate,H as getAllPaths,m as getContextPrompts,p as getTemplate,t as promptForContext,c as promptForTemplate};
1
+ import{compileTemplate as o,generate as r,getAllPaths as m,getContextPrompts as p,getTemplate as t,promptForContext as I,promptForTemplate as Q}from"./chunk-QIWEIH4Q.js";export{o as compileTemplate,r as generate,m as getAllPaths,p as getContextPrompts,t as getTemplate,I as promptForContext,Q as promptForTemplate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plano-cli",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -28,23 +28,22 @@
28
28
  "typecheck": "tsc"
29
29
  },
30
30
  "devDependencies": {
31
- "@types/inquirer": "^9.0.7",
32
31
  "@types/lodash-es": "^4.17.12",
33
- "@types/node": "^22.7.7",
34
- "@vitest/coverage-v8": "^2.1.3",
35
- "prettier": "^3.3.3",
36
- "terser": "^5.36.0",
37
- "tsup": "^8.3.0",
38
- "typescript": "^5.6.3",
32
+ "@types/node": "^22.10.7",
33
+ "@vitest/coverage-v8": "^2.1.8",
34
+ "prettier": "^3.4.2",
35
+ "terser": "^5.37.0",
36
+ "tsup": "^8.3.5",
37
+ "typescript": "^5.7.3",
39
38
  "vitest": "^2.1.1"
40
39
  },
41
40
  "dependencies": {
42
- "chalk": "^5.3.0",
41
+ "@inquirer/prompts": "^7.2.3",
42
+ "chalk": "^5.4.1",
43
43
  "commander": "^12.1.0",
44
- "glob": "^11.0.0",
44
+ "glob": "^11.0.1",
45
45
  "handlebars": "^4.7.8",
46
- "inquirer": "^12.0.0",
47
46
  "lodash-es": "^4.17.21",
48
- "zod": "^3.23.8"
47
+ "zod": "^3.24.1"
49
48
  }
50
49
  }
@@ -1 +0,0 @@
1
- import{resolve as e}from"node:path";import{z as t}from"zod";import{existsSync as r}from"node: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"node:fs";import m from"handlebars";function l({context:e={},helpers:t={},path:r}){return m.compile(i(r,"utf-8"))(e)}import{existsSync as f,readdirSync as c}from"node:fs";import{homedir as h}from"node:os";import{resolve as u}from"node:path";var d="plano";var y=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};function w({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${h()}/${d}/file-templates`;case"snippet":return`${h()}/${d}/snippet-templates`;default:throw new y([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>u(e))).filter((e=>f(e))).map((e=>c(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}import b from"inquirer";import{sortedUniq as C}from"lodash-es";async function g({paths:e,type:t}){const r=w({paths:e,type:t}),{template:o}=await b.prompt([{name:"template",message:"Select a template",type:"list",choices:C(r.map((({template:e})=>e)))}]);return o}import{mkdirSync as $,writeFileSync as x}from"node:fs";import{resolve as k}from"node:path";import{globSync as v}from"glob";import j from"handlebars";import{camelCase as F}from"lodash-es";import{kebabCase as T}from"lodash-es";import{camelCase as U,upperFirst as q}from"lodash-es";import{snakeCase as O}from"lodash-es";import{snakeCase as S}from"lodash-es";var D={camelCase:function(e){return F(e)},kebabCase:function(e){return T(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return q(U(e))},snakeCase:function(e){return O(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return S(e).toUpperCase()}};function E({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:o,template:a}}){Object.entries({...D,...r}).map((([e,t])=>j.registerHelper(e,t)));const s=k(o,a,"template"),p=v(`${s}/**/*`,{withFileTypes:!0});p.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new y(["Template files must end with .handlebars:",e.fullpath()])}));for(let o of p){const a=j.compile(o.fullpath())(t).replace(`${s}/`,"");if(o.isDirectory()&&$(k(e,a)),o.isFile()){const s=l({context:t,helpers:r,path:o.fullpath()});x(k(e,a.replace(".handlebars","")),s)}}}import P from"chalk";import{uniq as W}from"lodash-es";function z({name:e,paths:t,type:r}){const o=w({paths:t,type:r}),a=o.find((t=>t.template===e));if(!a)throw new y([P.red(`Unable to find template "${e}" at paths:`),...W(o.map((e=>e.path)))]);return a}export{s as getContextPrompts,n as promptForContext,l as compileTemplate,w as getAllPaths,g as promptForTemplate,E as generate,z as getTemplate};
@@ -1,2 +0,0 @@
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,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"),O=require("fs"),x=require("os"),$=require("path"),P="plano";function S({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${(0,x.homedir)()}/${P}/file-templates`;case"snippet":return`${(0,x.homedir)()}/${P}/snippet-templates`;default:throw new h([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>(0,$.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()}function k({name:e,paths:t,type:r}){const a=S({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 F=p(require("inquirer"),1),U=require("path"),E=require("zod"),T=require("fs"),D=E.z.optional(E.z.array(E.z.object({message:E.z.string(),name:E.z.string(),required:E.z.boolean(),type:E.z.union([E.z.literal("input"),E.z.literal("select")])}))),G=E.z.optional(E.z.record(E.z.function(E.z.tuple([E.z.string()]),E.z.string())));async function L(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,U.resolve)(`${e}/${t}`,"context.mjs");if(!(0,T.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:s}=await import(r);return{prompts:D.parse(a)||[],helpers:G.parse(s)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await F.default.prompt(t)||{},helpers:r}}var W=p(require("inquirer"),1),_=require("lodash-es");async function H({paths:e,type:t}){const r=S({paths:e,type:t}),{template:a}=await W.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,_.sortedUniq)(r.map((({template:e})=>e)))}]);return a}var I=new o.Command;I.name("plano").description("CLI to scaffold files and directories from templates").version("0.1.1","-v, --version"),I.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 H({paths:a,type:"file"}));const s=k({name:r,paths:a,type:"file"}),{context:n,helpers:p={}}=await L({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)}})),I.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 H({paths:a,type:"snippet"}));const s=k({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)}})),I.parse();
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
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 DELETED
@@ -1,83 +0,0 @@
1
- import { HelperDelegate } from 'handlebars';
2
-
3
- interface PromptForContextOptions {
4
- template: {
5
- path: string;
6
- template: string;
7
- };
8
- }
9
- declare function promptForContext(options: PromptForContextOptions): Promise<{
10
- context: {
11
- [x: string]: unknown;
12
- };
13
- helpers: Record<string, (args_0: string) => string>;
14
- }>;
15
-
16
- interface GetContextPromptsOptions {
17
- template: {
18
- path: string;
19
- template: string;
20
- };
21
- }
22
- declare function getContextPrompts({ template: { path, template }, }: GetContextPromptsOptions): Promise<{
23
- prompts: {
24
- message: string;
25
- type: "input" | "select";
26
- name: string;
27
- required: boolean;
28
- }[];
29
- helpers: Record<string, (args_0: string) => string>;
30
- }>;
31
-
32
- interface CompileTemplate {
33
- context?: Record<string, unknown>;
34
- helpers?: Record<string, HelperDelegate>;
35
- path: string;
36
- }
37
- declare function compileTemplate({ context, helpers, path, }: CompileTemplate): string;
38
-
39
- type TemplateType = 'file' | 'snippet';
40
-
41
- interface PromptForTemplateOptions {
42
- paths: string[];
43
- type: TemplateType;
44
- }
45
- /**
46
- * Prompt which template should be used for generation.
47
- *
48
- * @param paths - paths to search for templates
49
- * @returns selected template name
50
- */
51
- declare function promptForTemplate({ paths, type }: PromptForTemplateOptions): Promise<string>;
52
-
53
- interface GenerateOptions {
54
- copyToPath?: string;
55
- template: {
56
- path: string;
57
- template: string;
58
- };
59
- helpers: Record<string, HelperDelegate>;
60
- context: Record<string, unknown>;
61
- }
62
- declare function generate({ copyToPath, context, helpers, template: { path, template }, }: GenerateOptions): void;
63
-
64
- interface GetAllPathsOptions {
65
- paths: string[];
66
- type: TemplateType;
67
- }
68
- declare function getAllPaths({ paths, type }: GetAllPathsOptions): {
69
- path: string;
70
- template: string;
71
- }[];
72
-
73
- interface GetTemplateOptions {
74
- name: string;
75
- paths: string[];
76
- type: TemplateType;
77
- }
78
- declare function getTemplate({ name, paths, type }: GetTemplateOptions): {
79
- path: string;
80
- template: string;
81
- };
82
-
83
- export { compileTemplate, generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };