plano-cli 0.0.14 → 0.0.16
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/dist/chunk-SQ2YSPC5.js +1 -0
- package/dist/cli/plano.cjs +2 -0
- package/dist/cli/plano.d.cts +1 -0
- package/dist/cli/plano.js +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +63 -0
- package/dist/index.js +1 -1
- package/package.json +3 -4
- package/dist/chunk-Z3TEVRP3.js +0 -1
|
@@ -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()&&!e.name.startsWith(".git"))).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};
|
|
@@ -0,0 +1,2 @@
|
|
|
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,o=(o,i,p)=>(p=null!=o?e(s(o)):{},((e,s,o,i)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let p of a(s))n.call(e,p)||p===o||t(e,p,{get:()=>s[p],enumerable:!(i=r(s,p))||i.enumerable});return e})(!i&&o&&o.__esModule?p:t(p,"default",{value:o,enumerable:!0}),o)),i=require("commander"),p=require("zod"),l=require("fs"),c=require("path"),u=require("glob"),m=o(require("handlebars"),1);var f=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}},h=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,h.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()}};Object.entries(z).map((([e,t])=>m.default.registerHelper(e,t)));var g=o(require("chalk"),1),v=require("lodash-es"),w=require("fs"),C=require("os"),j=require("path"),O="plano-templates";function x(e){return[`${(0,C.homedir)()}/${O}`,...e].map((e=>(0,j.resolve)(e))).filter((e=>(0,w.existsSync)(e))).map((e=>(0,w.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}var S=o(require("inquirer"),1),k=require("path"),P=require("zod"),F=require("fs"),$=P.z.optional(P.z.array(P.z.object({message:P.z.string(),name:P.z.string(),required:P.z.boolean(),type:P.z.union([P.z.literal("input"),P.z.literal("select")])}))),T=P.z.optional(P.z.record(P.z.function(P.z.tuple([P.z.string()]),P.z.string())));async function U(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,k.resolve)(`${e}/${t}`,"context.mjs");if(!(0,F.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:s}=await import(r);return{prompts:$.parse(a)||[],helpers:T.parse(s)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await S.default.prompt(t)||{},helpers:r}}var D=o(require("inquirer"),1),E=require("lodash-es");var H=new i.Command;H.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.16","-v, --version"),H.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(e,t)=>{try{let r=p.z.optional(p.z.string()).parse(e);const{paths:a}=p.z.object({paths:p.z.array(p.z.string())}).parse(t);void 0===r&&(r=await async function(e){const t=x(e),{template:r}=await D.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,E.sortedUniq)(t.map((({template:e})=>e)))}]);return r}(a));const s=function({name:e,paths:t}){const r=x(t),a=r.find((t=>t.template===e));if(!a)throw new f([g.default.red(`Unable to find template "${e}" at paths:`),...(0,v.uniq)(r.map((e=>e.path)))]);return a}({name:r,paths:a}),{context:n,helpers:o={}}=await U({template:s});!function({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:s}}){Object.entries(r).map((([e,t])=>m.default.registerHelper(e,t)));const n=(0,c.resolve)(a,s,"template"),o=(0,u.globSync)(`${n}/**/*`,{withFileTypes:!0});o.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new f(["Template files must end with .handlebars:",e.fullpath()])}));for(let r of o){const a=m.default.compile(r.fullpath())(t).replace(`${n}/`,"");if(r.isDirectory()&&(0,l.mkdirSync)((0,c.resolve)(e,a)),r.isFile()){const s=m.default.compile((0,l.readFileSync)(r.fullpath(),"utf-8"))(t);(0,l.writeFileSync)((0,c.resolve)(e,a.replace(".handlebars","")),s)}}}({context:n,helpers:o,template:s})}catch(e){e instanceof Error&&console.log(e.message)}})),H.parse();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
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-SQ2YSPC5.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.16","-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.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t=Object.create,r=Object.defineProperty,a=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,i=(e,t,s,i)=>{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:!(i=a(t,l))||i.enumerable});return e},l=(e,a,n)=>(n=null!=e?t(s(e)):{},i(!a&&e&&e.__esModule?n:r(n,"default",{value:e,enumerable:!0}),e)),p={};((e,t)=>{for(var a in t)r(e,a,{get:t[a],enumerable:!0})})(p,{generate:()=>H,getAllPaths:()=>O,getContextPrompts:()=>y,getTemplate:()=>A,promptForContext:()=>b,promptForTemplate:()=>j}),module.exports=(e=p,i(r({},"__esModule",{value:!0}),e));var u=l(require("inquirer"),1),c=require("path"),m=require("zod"),f=require("fs"),h=m.z.optional(m.z.array(m.z.object({message:m.z.string(),name:m.z.string(),required:m.z.boolean(),type:m.z.union([m.z.literal("input"),m.z.literal("select")])}))),d=m.z.optional(m.z.record(m.z.function(m.z.tuple([m.z.string()]),m.z.string())));async function y({template:{path:e,template:t}}){const r=(0,c.resolve)(`${e}/${t}`,"context.mjs");if(!(0,f.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=l(require("inquirer"),1),g=require("lodash-es"),v=require("fs"),w=require("os"),C=require("path"),z="plano-templates";function O(e){return[`${(0,w.homedir)()}/${z}`,...e].map((e=>(0,C.resolve)(e))).filter((e=>(0,v.existsSync)(e))).map((e=>(0,v.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}async function j(e){const t=O(e),{template:r}=await q.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,g.sortedUniq)(t.map((({template:e})=>e)))}]);return r}var x=require("fs"),F=require("path"),P=require("glob"),S=l(require("handlebars"),1);var k=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}},$=require("lodash-es");var T=require("lodash-es");var U=require("lodash-es");var _=require("lodash-es");var D=require("lodash-es");var E={camelCase:function(e){return(0,$.camelCase)(e)},kebabCase:function(e){return(0,T.kebabCase)(e)},lowerCase:function(e){return e.toLowerCase()},pascalCase:function(e){return(0,U.upperFirst)((0,U.camelCase)(e))},snakeCase:function(e){return(0,_.snakeCase)(e)},upperCase:function(e){return e.toUpperCase()},upperSnakeCase:function(e){return(0,D.snakeCase)(e).toUpperCase()}};function H({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:n}}){Object.entries(r).map((([e,t])=>S.default.registerHelper(e,t)));const s=(0,F.resolve)(a,n,"template"),o=(0,P.globSync)(`${s}/**/*`,{withFileTypes:!0});o.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new k(["Template files must end with .handlebars:",e.fullpath()])}));for(let r of o){const a=S.default.compile(r.fullpath())(t).replace(`${s}/`,"");if(r.isDirectory()&&(0,x.mkdirSync)((0,F.resolve)(e,a)),r.isFile()){const n=S.default.compile((0,x.readFileSync)(r.fullpath(),"utf-8"))(t);(0,x.writeFileSync)((0,F.resolve)(e,a.replace(".handlebars","")),n)}}}Object.entries(E).map((([e,t])=>S.default.registerHelper(e,t)));var M=l(require("chalk"),1),W=require("lodash-es");function A({name:e,paths:t}){const r=O(t),a=r.find((t=>t.template===e));if(!a)throw new k([M.default.red(`Unable to find template "${e}" at paths:`),...(0,W.uniq)(r.map((e=>e.path)))]);return a}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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: Record<string, unknown>;
|
|
11
|
+
helpers: Record<string, (args_0: string) => string>;
|
|
12
|
+
}>;
|
|
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
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Prompt which template should be used for generation.
|
|
32
|
+
*
|
|
33
|
+
* @param paths - paths to search for templates
|
|
34
|
+
* @returns selected template name
|
|
35
|
+
*/
|
|
36
|
+
declare function promptForTemplate(paths: string[]): Promise<string>;
|
|
37
|
+
|
|
38
|
+
interface GenerateOptions {
|
|
39
|
+
copyToPath?: string;
|
|
40
|
+
template: {
|
|
41
|
+
path: string;
|
|
42
|
+
template: string;
|
|
43
|
+
};
|
|
44
|
+
helpers: Record<string, HelperDelegate>;
|
|
45
|
+
context: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
declare function generate({ copyToPath, context, helpers, template: { path, template }, }: GenerateOptions): void;
|
|
48
|
+
|
|
49
|
+
declare function getAllPaths(paths: string[]): {
|
|
50
|
+
path: string;
|
|
51
|
+
template: string;
|
|
52
|
+
}[];
|
|
53
|
+
|
|
54
|
+
interface GetTemplateOptions {
|
|
55
|
+
name: string;
|
|
56
|
+
paths: string[];
|
|
57
|
+
}
|
|
58
|
+
declare function getTemplate({ name, paths }: GetTemplateOptions): {
|
|
59
|
+
path: string;
|
|
60
|
+
template: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { generate, getAllPaths, getContextPrompts, getTemplate, promptForContext, promptForTemplate };
|
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 S}from"./chunk-SQ2YSPC5.js";export{o as generate,r as getAllPaths,m as getContextPrompts,p as getTemplate,t as promptForContext,S as promptForTemplate};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plano-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -11,12 +11,11 @@
|
|
|
11
11
|
"plano": "./dist/cli/plano.js"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
|
-
"main": "./dist/index.js",
|
|
16
14
|
"exports": {
|
|
17
15
|
".": {
|
|
18
16
|
"types": "./dist/index.d.ts",
|
|
19
|
-
"import": "./dist/index.js"
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
20
19
|
}
|
|
21
20
|
},
|
|
22
21
|
"scripts": {
|
package/dist/chunk-Z3TEVRP3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|