plano-cli 0.0.19 → 0.0.21

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Plano CLI
2
2
 
3
- A CLI and programmatic API for generating files and/or directories from
3
+ A CLI and programmatic API for generating files, directories, and snippets from
4
4
  templates with context values and helper functions.
5
5
 
6
6
  ## Getting Started
@@ -21,24 +21,32 @@ Additional paths can be specified.
21
21
  ### Generate
22
22
 
23
23
  ```
24
- Usage: plano generate [options] [name]
24
+ Usage: plano [options] [command]
25
25
 
26
- Generate files or directories from a template
27
-
28
- Arguments:
29
- name template name
26
+ CLI to scaffold files and directories from templates
30
27
 
31
28
  Options:
32
- -p, --paths <path...> Paths to templates, must be directory named "plano" (default: [])
33
- -h, --help display help for command
29
+ -v, --version output the version number
30
+ -h, --help display help for command
31
+
32
+ Commands:
33
+ generate [options] [name] Generate files or directories from a template
34
+ snippet [options] [name] Generate a snippet from a template
35
+ help [command] display help for command
34
36
  ```
35
37
 
36
- #### Example
38
+ #### File/Directory Example
37
39
 
38
40
  ```
39
41
  plano generate react-component
40
42
  ```
41
43
 
44
+ #### Snippet Example
45
+
46
+ ```
47
+ plano snippet vitest-test
48
+ ```
49
+
42
50
  #### Example with paths
43
51
 
44
52
  ```
@@ -1,2 +1,2 @@
1
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"),$=require("fs"),O=require("os"),x=require("path"),P="plano",S="file-templates",k="snippet-templates";function F({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${(0,O.homedir)()}/${P}/${S}`;case"snippet":return`${(0,O.homedir)()}/${P}/${k}`;default:throw new h([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>(0,x.resolve)(e))).filter((e=>(0,$.existsSync)(e))).map((e=>(0,$.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}function U({name:e,paths:t,type:r}){const a=F({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 E=p(require("inquirer"),1),T=require("path"),D=require("zod"),G=require("fs"),L=D.z.optional(D.z.array(D.z.object({message:D.z.string(),name:D.z.string(),required:D.z.boolean(),type:D.z.union([D.z.literal("input"),D.z.literal("select")])}))),W=D.z.optional(D.z.record(D.z.function(D.z.tuple([D.z.string()]),D.z.string())));async function _(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,T.resolve)(`${e}/${t}`,"context.mjs");if(!(0,G.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:s}=await import(r);return{prompts:L.parse(a)||[],helpers:W.parse(s)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await E.default.prompt(t)||{},helpers:r}}var H=p(require("inquirer"),1),I=require("lodash-es");async function M({paths:e,type:t}){const r=F({paths:e,type:t}),{template:a}=await H.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,I.sortedUniq)(r.map((({template:e})=>e)))}]);return a}var N=new o.Command;N.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.19","-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"',[]).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 M({paths:a,type:"file"}));const s=U({name:r,paths:a,type:"file"}),{context:n,helpers:p={}}=await _({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)}})),N.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 M({paths:a,type:"snippet"}));const s=U({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)}})),N.parse();
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"),$=require("fs"),O=require("os"),x=require("path"),P="plano",S="file-templates",k="snippet-templates";function F({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${(0,O.homedir)()}/${P}/${S}`;case"snippet":return`${(0,O.homedir)()}/${P}/${k}`;default:throw new h([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>(0,x.resolve)(e))).filter((e=>(0,$.existsSync)(e))).map((e=>(0,$.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}function U({name:e,paths:t,type:r}){const a=F({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 E=p(require("inquirer"),1),T=require("path"),D=require("zod"),G=require("fs"),L=D.z.optional(D.z.array(D.z.object({message:D.z.string(),name:D.z.string(),required:D.z.boolean(),type:D.z.union([D.z.literal("input"),D.z.literal("select")])}))),W=D.z.optional(D.z.record(D.z.function(D.z.tuple([D.z.string()]),D.z.string())));async function _(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,T.resolve)(`${e}/${t}`,"context.mjs");if(!(0,G.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:s}=await import(r);return{prompts:L.parse(a)||[],helpers:W.parse(s)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await E.default.prompt(t)||{},helpers:r}}var H=p(require("inquirer"),1),I=require("lodash-es");async function M({paths:e,type:t}){const r=F({paths:e,type:t}),{template:a}=await H.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,I.sortedUniq)(r.map((({template:e})=>e)))}]);return a}var N=new o.Command;N.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.21","-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"',[]).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 M({paths:a,type:"file"}));const s=U({name:r,paths:a,type:"file"}),{context:n,helpers:p={}}=await _({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)}})),N.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 M({paths:a,type:"snippet"}));const s=U({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)}})),N.parse();
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-TSMFHBY6.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.0.19","-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-TSMFHBY6.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.0.21","-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plano-cli",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -30,22 +30,21 @@
30
30
  "devDependencies": {
31
31
  "@types/inquirer": "^9.0.7",
32
32
  "@types/lodash-es": "^4.17.12",
33
- "@types/node": "^20.10.5",
34
- "@vitest/coverage-v8": "^1.1.0",
35
- "prettier": "^3.2.2",
36
- "terser": "^5.26.0",
37
- "tsup": "^8.0.1",
38
- "typedoc": "^0.25.4",
39
- "typescript": "^5.3.3",
40
- "vitest": "^1.1.0"
33
+ "@types/node": "^20.14.2",
34
+ "@vitest/coverage-v8": "^1.6.0",
35
+ "prettier": "^3.3.1",
36
+ "terser": "^5.31.1",
37
+ "tsup": "^8.1.0",
38
+ "typescript": "^5.4.5",
39
+ "vitest": "^1.2.2"
41
40
  },
42
41
  "dependencies": {
43
42
  "chalk": "^5.3.0",
44
- "commander": "^11.1.0",
45
- "glob": "^10.3.10",
43
+ "commander": "^12.1.0",
44
+ "glob": "^10.4.1",
46
45
  "handlebars": "^4.7.8",
47
- "inquirer": "^9.2.12",
46
+ "inquirer": "^9.2.23",
48
47
  "lodash-es": "^4.17.21",
49
- "zod": "^3.22.4"
48
+ "zod": "^3.23.8"
50
49
  }
51
50
  }