plano-cli 0.0.11 → 0.0.12
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.
|
@@ -1 +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
|
|
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};
|
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-
|
|
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();
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,11 @@ interface GenerateOptions {
|
|
|
29
29
|
}
|
|
30
30
|
declare function generate({ context, helpers, template: { path, template }, }: GenerateOptions): void;
|
|
31
31
|
|
|
32
|
+
declare function getAllPaths(paths: string[]): {
|
|
33
|
+
path: string;
|
|
34
|
+
template: string;
|
|
35
|
+
}[];
|
|
36
|
+
|
|
32
37
|
interface GetTemplateOptions {
|
|
33
38
|
name: string;
|
|
34
39
|
paths: string[];
|
|
@@ -38,4 +43,4 @@ declare function getTemplate({ name, paths }: GetTemplateOptions): {
|
|
|
38
43
|
template: string;
|
|
39
44
|
};
|
|
40
45
|
|
|
41
|
-
export { generate, getTemplate, promptForContext, promptForTemplate };
|
|
46
|
+
export { generate, getAllPaths, getTemplate, promptForContext, promptForTemplate };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{generate as o,
|
|
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};
|