plano-cli 0.0.14 → 0.0.15
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/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/package.json +3 -4
|
@@ -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,n=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,o=(o,i,p)=>(p=null!=o?e(n(o)):{},((e,n,o,i)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let p of a(n))s.call(e,p)||p===o||t(e,p,{get:()=>n[p],enumerable:!(i=r(n,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 v=o(require("chalk"),1),w=require("lodash-es"),g=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,g.existsSync)(e))).map((e=>(0,g.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).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:n}=await import(r);return{prompts:$.parse(a)||[],helpers:T.parse(n)||{}}}(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.15","-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 n=function({name:e,paths:t}){const r=x(t),a=r.find((t=>t.template===e));if(!a)throw new f([v.default.red(`Unable to find template "${e}" at paths:`),...(0,w.uniq)(r.map((e=>e.path)))]);return a}({name:r,paths:a}),{context:s,helpers:o={}}=await U({template:n});!function({copyToPath:e=process.cwd(),context:t={},helpers:r={},template:{path:a,template:n}}){Object.entries(r).map((([e,t])=>m.default.registerHelper(e,t)));const s=(0,c.resolve)(a,n,"template"),o=(0,u.globSync)(`${s}/**/*`,{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(`${s}/`,"");if(r.isDirectory()&&(0,l.mkdirSync)((0,c.resolve)(e,a)),r.isFile()){const n=m.default.compile((0,l.readFileSync)(r.fullpath(),"utf-8"))(t);(0,l.writeFileSync)((0,c.resolve)(e,a.replace(".handlebars","")),n)}}}({context:s,helpers:o,template:n})}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-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.
|
|
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.15","-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,l=(e,t,s,l)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let i of n(t))o.call(e,i)||i===s||r(e,i,{get:()=>t[i],enumerable:!(l=a(t,i))||l.enumerable});return e},i=(e,a,n)=>(n=null!=e?t(s(e)):{},l(!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:()=>L,promptForContext:()=>b,promptForTemplate:()=>j}),module.exports=(e=p,l(r({},"__esModule",{value:!0}),e));var u=i(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=i(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())).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=i(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=i(require("chalk"),1),A=require("lodash-es");function L({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,A.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plano-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
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": {
|