plano-cli 0.0.13 → 0.0.14
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{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
|
|
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 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};
|
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-Z3TEVRP3.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.14","-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
|
@@ -36,6 +36,7 @@ declare function getContextPrompts({ template: { path, template }, }: GetContext
|
|
|
36
36
|
declare function promptForTemplate(paths: string[]): Promise<string>;
|
|
37
37
|
|
|
38
38
|
interface GenerateOptions {
|
|
39
|
+
copyToPath?: string;
|
|
39
40
|
template: {
|
|
40
41
|
path: string;
|
|
41
42
|
template: string;
|
|
@@ -43,7 +44,7 @@ interface GenerateOptions {
|
|
|
43
44
|
helpers: Record<string, HelperDelegate>;
|
|
44
45
|
context: Record<string, unknown>;
|
|
45
46
|
}
|
|
46
|
-
declare function generate({ context, helpers, template: { path, template }, }: GenerateOptions): void;
|
|
47
|
+
declare function generate({ copyToPath, context, helpers, template: { path, template }, }: GenerateOptions): void;
|
|
47
48
|
|
|
48
49
|
declare function getAllPaths(paths: string[]): {
|
|
49
50
|
path: string;
|
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
|
|
1
|
+
import{generate as o,getAllPaths as r,getContextPrompts as m,getTemplate as p,promptForContext as t,promptForTemplate as c}from"./chunk-Z3TEVRP3.js";export{o as generate,r as getAllPaths,m as getContextPrompts,p as getTemplate,t as promptForContext,c as promptForTemplate};
|