create-enpage
Advanced tools
Comparing version 0.0.0-alpha.6e815f5 to 0.0.0-alpha.bdd781c
#!/usr/bin/env node | ||
import v from"degit";import{program as m}from"commander";import{resolve as s}from"path";import b from"path";import r from"chalk";import{existsSync as k,mkdirSync as S,lstatSync as x,readdirSync as E,readFileSync as D,writeFileSync as O,rmSync as $}from"fs";import{input as a,select as N}from"@inquirer/prompts";import{execSync as A}from"child_process";m.description("Create a new Enpage template").argument("[directory]","Directory to create the template in",".").action(async o=>{let e=s(process.cwd(),o);k(e)?x(e).isDirectory()?C(e)||(console.log(r.red(`Directory ${e} is not empty. Aborting.`)),process.exit(1)):(console.log(r.red(`${e} exists but is not a directory. Aborting.`)),process.exit(1)):(process.stdout.write(`Creating directory ${e}... `),S(e,{recursive:!0}),console.log(r.cyan("OK"))),process.stdout.write("Cloning template example... "),await v("enpage/enpage/packages/template-example",{cache:!1}).clone(e),$(s(e,"CHANGELOG.md")),console.log(r.cyan("OK")),console.log(""),console.log("Let's set up your new template:");let u=await a({message:"Name your template",validate(n){return n.length>0?!0:"Name cannot be empty"}}),d=await a({message:"Enter a template description",validate(n){return n.length>0?!0:"Description cannot be empty"}}),y=await a({message:"Enter the author's name",validate(n){return n.length>0?!0:"Author name cannot be empty"}}),i=await N({message:"Choose the visibility of the template",choices:[{name:"Private",value:"private",description:"For your eyes only"},{name:"Public",value:"public",description:"To be available on Enpage (paid or free users)"}]});i==="public"&&console.log(` > You will need to publish your template to make it available on Enpage. | ||
`);let f=await a({message:"Enter tags for the template (optional, comma separated)"}),c=await a({message:"Enter a homepage URL (optional)",validate(n){if(n.length===0)return!0;try{return new URL(n),!0}catch{}return"Homepage URL must start with https://"}}),h=f.split(",").map(n=>n.trim()),l=s(e,"package.json"),t=JSON.parse(D(l,"utf-8"));for(let n of["dependencies","devDependencies","peerDependencies","optionalDependencies"])if(t[n])for(let[g,w]of Object.entries(t[n]))w.startsWith("workspace:")&&(t[n][g]="latest");t.name=`enpage-template-${b.basename(e)}`,t.author=y,t.keywords=[...new Set([...t.keywords,...h])],t.license="UNLICENSED",t.homepage=c.length>0?c:void 0,t.enpage={name:u,description:d},i==="private"&&(t.enpage.private=!0,t.private=!0),delete t.scripts.lint,delete t.scripts["ci:lint"],process.stdout.write("Writing package.json... "),O(l,JSON.stringify(t,null,2)),console.log(r.cyan("OK")),console.log("Installing dependencies... ");let p=L();A(`${p} install`,{cwd:e,stdio:"inherit"}),console.log(` | ||
${r.cyan("All done!")} | ||
import h from"degit";import{program as g}from"commander";import{resolve as i}from"path";import w from"path";import a from"chalk";import{existsSync as v,mkdirSync as b,lstatSync as k,readdirSync as S,readFileSync as x,writeFileSync as E,rmSync as $}from"fs";import{input as r,select as N}from"@inquirer/prompts";import{execSync as O}from"child_process";g.description("Create a new Enpage template").argument("[directory]","Directory to create the template in",".").action(async o=>{let e=i(process.cwd(),o);v(e)?k(e).isDirectory()?A(e)||(console.log(a.red(`Directory ${e} is not empty. Aborting.`)),process.exit(1)):(console.log(a.red(`${e} exists but is not a directory. Aborting.`)),process.exit(1)):(process.stdout.write(`Creating directory ${e}... `),b(e,{recursive:!0}),console.log(a.cyan("OK"))),process.stdout.write("Cloning template example... "),await h("enpage/enpage/packages/template-example",{cache:!1}).clone(e),$(i(e,"CHANGELOG.md")),console.log(a.cyan("OK")),console.log(""),console.log("Let's set up your new template:");let m=await r({message:"Name your template",validate(n){return n.length>0?!0:"Name cannot be empty"}}),u=await r({message:"Enter a template description",validate(n){return n.length>0?!0:"Description cannot be empty"}}),d=await r({message:"Enter the author's name",validate(n){return n.length>0?!0:"Author name cannot be empty"}}),s=await N({message:"Choose the visibility of the template",choices:[{name:"Private",value:"private",description:"For your eyes only"},{name:"Public",value:"public",description:"To be available on Enpage (paid or free users)"}]});s==="public"&&console.log(` > You will need to publish your template to make it available on Enpage. | ||
`);let y=await r({message:"Enter tags for the template (optional, comma separated)"}),c=await r({message:"Enter a homepage URL (optional)",validate(n){if(n.length===0)return!0;try{return new URL(n),!0}catch{}return"Homepage URL must start with https://"}}),f=y.split(",").map(n=>n.trim()).filter(n=>n.length>0),l=i(e,"package.json"),t=JSON.parse(x(l,"utf-8"));t.name=`enpage-template-${w.basename(e)}`,t.author=d,t.keywords=[...new Set([...t.keywords,...f])],t.license="UNLICENSED",t.homepage=c.length>0?c:void 0,t.enpage={name:m,description:u},s==="private"&&(t.enpage.private=!0,t.private=!0),delete t.scripts.lint,delete t.scripts["ci:lint"],process.stdout.write("Writing package.json... "),E(l,JSON.stringify(t,null,2)),console.log(a.cyan("OK")),console.log("Installing dependencies... ");let p=C();O(`${p} install`,{cwd:e,stdio:"inherit"}),console.log(` | ||
${a.cyan("All done!")} | ||
`),console.log(`You can now develop your template: | ||
`),console.log(r.cyan(` cd ${o}`)),console.log(r.cyan(` ${p} start | ||
`)),process.exit(0)});m.parse();function C(o){return E(o).length===0}function L(){let o;if(process.env.npm_config_user_agent){let e=process.env.npm_config_user_agent.split(" ")[0];o=e.slice(0,e.lastIndexOf("/"))}return o||(console.log("Warning: could not detect package manager"),o="npm"),o} | ||
`),console.log(a.cyan(` cd ${o}`)),console.log(a.cyan(` ${p} start | ||
`)),process.exit(0)});g.parse();function A(o){return S(o).length===0}function C(){let o;if(process.env.npm_config_user_agent){let e=process.env.npm_config_user_agent.split(" ")[0];o=e.slice(0,e.lastIndexOf("/"))}return o||(console.log("Warning: could not detect package manager"),o="npm"),o} |
{ | ||
"name": "create-enpage", | ||
"version": "0.0.0-alpha.6e815f5", | ||
"version": "0.0.0-alpha.bdd781c", | ||
"description": "A CLI for creating Enpage templates.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
36846