plano-cli 0.1.0 → 0.1.1

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,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"),O=require("fs"),x=require("os"),$=require("path"),P="plano";function S({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${(0,x.homedir)()}/${P}/file-templates`;case"snippet":return`${(0,x.homedir)()}/${P}/snippet-templates`;default:throw new h([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>(0,$.resolve)(e))).filter((e=>(0,O.existsSync)(e))).map((e=>(0,O.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}function k({name:e,paths:t,type:r}){const a=S({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 F=p(require("inquirer"),1),U=require("path"),E=require("zod"),T=require("fs"),D=E.z.optional(E.z.array(E.z.object({message:E.z.string(),name:E.z.string(),required:E.z.boolean(),type:E.z.union([E.z.literal("input"),E.z.literal("select")])}))),G=E.z.optional(E.z.record(E.z.function(E.z.tuple([E.z.string()]),E.z.string())));async function L(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,U.resolve)(`${e}/${t}`,"context.mjs");if(!(0,T.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:s}=await import(r);return{prompts:D.parse(a)||[],helpers:G.parse(s)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await F.default.prompt(t)||{},helpers:r}}var W=p(require("inquirer"),1),_=require("lodash-es");async function H({paths:e,type:t}){const r=S({paths:e,type:t}),{template:a}=await W.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,_.sortedUniq)(r.map((({template:e})=>e)))}]);return a}var I=new o.Command;I.name("plano").description("CLI to scaffold files and directories from templates").version("0.1.0","-v, --version"),I.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 H({paths:a,type:"file"}));const s=k({name:r,paths:a,type:"file"}),{context:n,helpers:p={}}=await L({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)}})),I.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 H({paths:a,type:"snippet"}));const s=k({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)}})),I.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"),O=require("fs"),x=require("os"),$=require("path"),P="plano";function S({paths:e,type:t}){const r=function(e){switch(e){case"file":return`${(0,x.homedir)()}/${P}/file-templates`;case"snippet":return`${(0,x.homedir)()}/${P}/snippet-templates`;default:throw new h([`Unable to get default template path for type: ${e}`])}}(t);return[r,...e].map((e=>(0,$.resolve)(e))).filter((e=>(0,O.existsSync)(e))).map((e=>(0,O.readdirSync)(e,{withFileTypes:!0}).filter((e=>e.isDirectory()&&!e.name.startsWith(".git"))).map((t=>({path:e,template:t.name}))))).flat()}function k({name:e,paths:t,type:r}){const a=S({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 F=p(require("inquirer"),1),U=require("path"),E=require("zod"),T=require("fs"),D=E.z.optional(E.z.array(E.z.object({message:E.z.string(),name:E.z.string(),required:E.z.boolean(),type:E.z.union([E.z.literal("input"),E.z.literal("select")])}))),G=E.z.optional(E.z.record(E.z.function(E.z.tuple([E.z.string()]),E.z.string())));async function L(e){const{prompts:t,helpers:r}=await async function({template:{path:e,template:t}}){const r=(0,U.resolve)(`${e}/${t}`,"context.mjs");if(!(0,T.existsSync)(r))return{prompts:[],helpers:{}};const{prompts:a,helpers:s}=await import(r);return{prompts:D.parse(a)||[],helpers:G.parse(s)||{}}}(e);if(!t)return{context:{},helpers:r};return{context:await F.default.prompt(t)||{},helpers:r}}var W=p(require("inquirer"),1),_=require("lodash-es");async function H({paths:e,type:t}){const r=S({paths:e,type:t}),{template:a}=await W.default.prompt([{name:"template",message:"Select a template",type:"list",choices:(0,_.sortedUniq)(r.map((({template:e})=>e)))}]);return a}var I=new o.Command;I.name("plano").description("CLI to scaffold files and directories from templates").version("0.1.1","-v, --version"),I.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 H({paths:a,type:"file"}));const s=k({name:r,paths:a,type:"file"}),{context:n,helpers:p={}}=await L({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)}})),I.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 H({paths:a,type:"snippet"}));const s=k({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)}})),I.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-YSHKHHP5.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.1.0","-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-YSHKHHP5.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.1.1","-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.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -30,12 +30,12 @@
30
30
  "devDependencies": {
31
31
  "@types/inquirer": "^9.0.7",
32
32
  "@types/lodash-es": "^4.17.12",
33
- "@types/node": "^20.16.5",
34
- "@vitest/coverage-v8": "^2.1.1",
33
+ "@types/node": "^22.7.7",
34
+ "@vitest/coverage-v8": "^2.1.3",
35
35
  "prettier": "^3.3.3",
36
- "terser": "^5.33.0",
36
+ "terser": "^5.36.0",
37
37
  "tsup": "^8.3.0",
38
- "typescript": "^5.6.2",
38
+ "typescript": "^5.6.3",
39
39
  "vitest": "^2.1.1"
40
40
  },
41
41
  "dependencies": {
@@ -43,7 +43,7 @@
43
43
  "commander": "^12.1.0",
44
44
  "glob": "^11.0.0",
45
45
  "handlebars": "^4.7.8",
46
- "inquirer": "^11.0.2",
46
+ "inquirer": "^12.0.0",
47
47
  "lodash-es": "^4.17.21",
48
48
  "zod": "^3.23.8"
49
49
  }