plano-cli 0.0.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Plano CLI
2
+
3
+ A CLI and programmatic API for generating files from templates with context values and helper functions.
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1 @@
1
+ import e from"chalk";import{Command as t}from"commander";import r from"inquirer";import{uniq as a}from"lodash-es";import{z as o}from"zod";var s=class e extends Error{constructor(t){super(function(e){return e.join("\n")}(t)),Object.setPrototypeOf(this,e.prototype)}};import{existsSync as p,readdirSync as i}from"fs";import{resolve as n}from"path";import{homedir as m}from"os";var l=`${m()}/plano-templates`;import{mkdirSync as c,readFileSync as f,writeFileSync as h}from"fs";import{resolve as d}from"path";import{globSync as u}from"glob";import g from"handlebars";import{camelCase as b,upperFirst as w}from"lodash-es";var y={pascalCase:function(e){return w(b(e))}};Object.entries(y).map((([e,t])=>g.registerHelper(e,t)));import{resolve as v}from"path";import{z as j}from"zod";var x=j.array(j.object({message:j.string(),name:j.string(),required:j.boolean(),type:j.union([j.literal("input"),j.literal("select")])})),P=j.record(j.function(j.tuple([j.string()]),j.string()));var $=new t;$.name("plano").description("CLI to scaffold files and directories from templates").version("0.0.1"),$.command("generate").description("Generate files or directories from a template").argument("<name>","template name").option("-p, --templates-paths <path...>",'Paths to templates, must be directory named "plano-templates"',[]).action((async(t,m)=>{try{const w=o.string().parse(t),y=o.object({templatesPaths:o.array(o.string())}).parse(m),j=(b=y.templatesPaths,[l,...b].map((e=>n(e))).filter((e=>p(e))).map((e=>i(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((t=>({path:e,template:t.name}))))).flat()),$=j.find((e=>e.template===w));if(!$)throw new s([e.red(`Unable to find template "${w}" at paths:`),...a(j.map((e=>e.path)))]);const{context:F,helpers:O={}}=await async function(e){const{context:t,helpers:r}=await import(v(e,"context.mjs"));return{context:x.parse(t),helpers:P.parse(r)}}(`${$.path}/${w}`);!function({context:e={},helpers:t={},templatePath:{path:r,template:a}}){Object.entries(t).map((([e,t])=>g.registerHelper(e,t)));const o=d(r,a,"template"),p=u(`${o}/**/*`,{withFileTypes:!0});p.forEach((e=>{if(e.isFile()&&!e.name.endsWith(".handlebars"))throw new s(["Template files must end with .handlebars:",e.fullpath()])}));for(let t of p){const r=g.compile(t.fullpath())(e).replace(`${o}/`,"");if(t.isDirectory()&&c(d(process.cwd(),r)),t.isFile()){const a=g.compile(f(t.fullpath(),"utf-8"))(e);h(d(process.cwd(),r.replace(".handlebars","")),a)}}}({context:await r.prompt(F),helpers:O,templatePath:$})}catch(e){e instanceof Error&&console.log(e.message)}var b})),$.parse();
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/index.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "plano-cli",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist",
8
+ "package.json"
9
+ ],
10
+ "bin": {
11
+ "plano": "./dist/cli/plano.js"
12
+ },
13
+ "type": "module",
14
+ "types": "./dist/index.d.ts",
15
+ "main": "./dist/index.js",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "dev": "tsup --watch",
24
+ "build": "tsup",
25
+ "test": "vitest --coverage",
26
+ "typecheck": "tsc"
27
+ },
28
+ "devDependencies": {
29
+ "@types/inquirer": "^9.0.7",
30
+ "@types/lodash-es": "^4.17.12",
31
+ "@types/node": "^20.10.5",
32
+ "@vitest/coverage-v8": "^1.1.0",
33
+ "terser": "^5.26.0",
34
+ "tsup": "^8.0.1",
35
+ "typedoc": "^0.25.4",
36
+ "typescript": "^5.3.3",
37
+ "vitest": "^1.1.0"
38
+ },
39
+ "dependencies": {
40
+ "chalk": "^5.3.0",
41
+ "commander": "^11.1.0",
42
+ "glob": "^10.3.10",
43
+ "handlebars": "^4.7.8",
44
+ "inquirer": "^9.2.12",
45
+ "lodash-es": "^4.17.21",
46
+ "zod": "^3.22.4"
47
+ }
48
+ }