create-gramstax 0.5.21 → 0.6.0
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/src/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var G=Object.create;var h=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var p=(o,e)=>h(o,"name",{value:e,configurable:!0});var J=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of O(e))!q.call(o,s)&&s!==t&&h(o,s,{get:()=>e[s],enumerable:!(n=B(e,s))||n.enumerable});return o};var v=(o,e,t)=>(t=o!=null?G(V(o)):{},J(e||!o||!o.__esModule?h(t,"default",{value:o,enumerable:!0}):t,o));var Y=p(()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,"getImportMetaUrl"),f=Y();var D=require("logging-pretty"),i=new D.LoggingPretty;var r=v(require("fs"),1),a=v(require("path"),1),x=require("url");var E=require("fs");var g=class o{static{p(this,"FsUt")}static DEFAULT_IGNORED_ENTRIES=new Set([".git",".gitignore",".gitkeep",".DS_Store","Thumbs.db"]);static isDirectoryEffectivelyEmpty(e,t=o.DEFAULT_IGNORED_ENTRIES){return(0,E.readdirSync)(e).filter(c=>!t.has(c)).length===0}static resolvePackageManagerCommand(e,t=process.platform){return t!=="win32"||e==="bun"?e:`${e}.cmd`}static resolveInitialWorkingDirectory(e=process.cwd(),t=process.env.INIT_CWD){return t??e}};var j=require("child_process"),P=v(require("enquirer"),1);var z=(0,x.fileURLToPath)(f),H=a.dirname(z),_=class{constructor(e,t){this.projectDirectory=e;this.version=t?.version}static{p(this,"Create")}config;version;printBanner(){let e=`
|
|
3
3
|
$$$$$$\\ $$\\
|
|
4
4
|
$$ __$$\\ $$ |
|
|
5
5
|
$$ / \\__| $$$$$$\\ $$$$$$\\ $$$$$$\\$$$$\\ $$$$$$$\\ $$$$$$\\ $$$$$$\\ $$\\ $$\\
|
|
@@ -10,4 +10,4 @@ $$ | $$ |$$ | $$ __$$ |$$ | $$ | $$ | \\____$$\\ $$ |$$\\ $$ __$$ | $$
|
|
|
10
10
|
\\______/ \\__| \\_______|\\__| \\__| \\__|\\_______/ \\____/ \\_______|\\__/ \\__|
|
|
11
11
|
|
|
12
12
|
`,t=this.version?`v${this.version}`:"v0.0.0";console.log(`${e}${t}
|
|
13
|
-
`)}getPackageManagerCommands(e){return{bun:{install:"bun install",dev:"bun dev",start:"bun start"},npm:{install:"npm install",dev:"npm run dev",start:"npm start"},pnpm:{install:"pnpm install",dev:"pnpm dev",start:"pnpm start"},yarn:{install:"yarn install",dev:"yarn dev",start:"yarn start"}}[e]}copyDirectorySync(e,t,n={}){r.existsSync(t)||r.mkdirSync(t,{recursive:!0});let s=r.readdirSync(e,{withFileTypes:!0});for(let c of s){let
|
|
13
|
+
`)}getPackageManagerCommands(e){return{bun:{install:"bun install",dev:"bun dev",start:"bun start"},npm:{install:"npm install",dev:"npm run dev",start:"npm start"},pnpm:{install:"pnpm install",dev:"pnpm dev",start:"pnpm start"},yarn:{install:"yarn install",dev:"yarn dev",start:"yarn start"}}[e]}copyDirectorySync(e,t,n={}){r.existsSync(t)||r.mkdirSync(t,{recursive:!0});let s=r.readdirSync(e,{withFileTypes:!0});for(let c of s){let m=a.join(e,c.name),l=a.join(t,c.name);if(c.isDirectory())this.copyDirectorySync(m,l,n);else if(c.isFile()){let $=r.readFileSync(m,"utf-8");$=this.replaceTemplateVariables($,n),r.writeFileSync(l,$)}}}replaceTemplateVariables(e,t){let n=e;for(let[s,c]of Object.entries(t))n=n.replace(new RegExp(`{{${s}}}`,"g"),c);return n}async promptForProjectName(){return(await P.default.prompt({type:"input",name:"projectName",message:"What is your project named?",initial:"",validate:p(t=>t===""||/^[a-z0-9-_]+$/i.test(t)?!0:"Project name can only contain letters, numbers, hyphens, and underscores","validate")})).projectName}async promptForConfiguration(){let e=[];e.push({type:"select",name:"packageManager",message:"Which package manager would you like to use?",choices:[{name:"bun",message:"Bun (recommended)",value:"bun"},{name:"npm",message:"npm",value:"npm"},{name:"pnpm",message:"pnpm",value:"pnpm"},{name:"yarn",message:"Yarn",value:"yarn"}],initial:0}),e.push({type:"select",name:"runtime",message:"Which runtime would you like to use?",choices:[{name:"bun",message:"Bun (recommended)",value:"bun"},{name:"node",message:"Node.js",value:"node"}],initial:0}),e.push({type:"confirm",name:"eslint",message:"Would you like to use ESLint?",initial:!0});let t=await P.default.prompt(e);return{packageManager:t.packageManager,runtime:t.runtime,eslint:t.eslint}}async installDependencies(e,t){return await new Promise(n=>{let s=g.resolvePackageManagerCommand(t),m=(0,j.spawn)(s,["install"],{cwd:e,stdio:"inherit",shell:!1});m.on("close",l=>{l===0?n(!0):(i.fail("Dependencies installation failed"),n(!1))}),m.on("error",l=>{i.fail(`Dependencies installation failed: ${l.message}`),n(!1)})})}async gatherProjectConfig(){this.printBanner();let e=this.projectDirectory,t,n=!1,s=g.resolveInitialWorkingDirectory();e?(t=a.resolve(s,e),n=!1):(e=await this.promptForProjectName(),e===""?(e=a.basename(s),t=s,n=!0):(t=a.resolve(s,e),n=!1));let c=await this.promptForConfiguration(),m=c.packageManager,l=c.runtime,$=c.eslint;return i.info(`Project: ${e}`),i.info(`Location: ${t}`),i.info(`Package Manager: ${m}`),i.info(`Runtime: ${l}`),i.info(`ESLint: ${$?"Yes":"No"}`),n?g.isDirectoryEffectivelyEmpty(t)||(i.error("Current directory is not empty!"),process.exit(1)):r.existsSync(t)&&(i.error(`Directory "${e}" already exists!`),process.exit(1)),{projectName:e,projectPath:t,packageManager:m,runtime:l,setupEslint:$}}async executeProjectGeneration(e){let{projectName:t,projectPath:n,packageManager:s,runtime:c,setupEslint:m}=e;i.info("Creating project directory.."),r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),i.info("Copying template files..");let l=a.join(H,"templates"),$=this.getPackageManagerCommands(s),L={projectName:t,installCmd:$.install,runDevCmd:$.dev,runStartCmd:$.start};this.copyDirectorySync(l,n,L),i.info("Creating logs directory.."),r.mkdirSync(a.join(n,"logs"),{recursive:!0}),r.writeFileSync(a.join(n,"logs/.gitkeep"),"");let T=a.join(n,".env"),S=a.join(n,".env.example");if(r.existsSync(S)&&(i.info("Creating .env file.."),r.renameSync(S,T)),c!=="bun"){i.info("Removing bunfig.toml for Node.js runtime..");let d=a.join(n,"bunfig.toml");r.existsSync(d)&&r.unlinkSync(d)}let b=a.join(n,"tsconfig.json"),U=r.readFileSync(b,{encoding:"utf8"}).replace("//{{types}}",c=="bun"?'"bun-types"':"");if(r.writeFileSync(b,U,{encoding:"utf8"}),i.info("Installing dependencies.."),!await this.installDependencies(n,s))return i.fail("Project created failed!"),process.exit();let u=a.join(n,"eslint.config.ts.template"),W=a.join(n,"eslint.config.ts");if(m){i.info("Installing ESLint dependencies..");let d=g.resolvePackageManagerCommand(s),k=s==="yarn"?["add","-D"]:["install","-D"];k.push("eslint","@eslint/js","globals","typescript-eslint"),await new Promise(w=>{let C=(0,j.spawn)(d,k,{cwd:n,stdio:"inherit",shell:!1});C.on("close",()=>w()),C.on("error",A=>{i.fail(`Failed to install ESLint dependencies: ${A.message}`),w()})}),r.existsSync(u)&&r.renameSync(u,W)}else r.existsSync(u)&&r.unlinkSync(u);i.info("Project created successfully!"),i.info(`Next steps: ${e.projectPath!==process.cwd()?`cd ${t} && `:" "}${$.install} && ${$.dev}`),i.info("Done..")}async createProject(){try{this.config=await this.gatherProjectConfig(),await this.executeProjectGeneration(this.config)}catch(e){e instanceof Error?i.error(`Failed to create project: ${e.message}`):i.error(`Failed to create project: ${String(e)}`),process.exit(1)}}};var R=require("commander"),F=require("fs"),y=require("path"),M=require("url"),K=(0,M.fileURLToPath)(f),Q=(0,y.dirname)(K),X=(0,y.join)(Q,"../../package.json"),N=JSON.parse((0,F.readFileSync)(X,"utf-8")).version,I=new R.Command;I.name("create-gramstax").description("CLI to create a new Gramstax Telegram bot project").version(N).argument("[project-directory]","Directory to create the project in").action(async o=>{try{await new _(o,{version:N}).createProject()}catch(e){i.error(`Failed to create project: ${String(e)}`),process.exit(1)}});I.parse();
|
package/dist/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var F=Object.defineProperty;var g=(p,e)=>F(p,"name",{value:e,configurable:!0});import{LoggingPretty as R}from"logging-pretty";var i=new R;import*as r from"fs";import*as s from"path";import{fileURLToPath as T}from"url";import{readdirSync as L}from"fs";var m=class p{static{g(this,"FsUt")}static DEFAULT_IGNORED_ENTRIES=new Set([".git",".gitignore",".gitkeep",".DS_Store","Thumbs.db"]);static isDirectoryEffectivelyEmpty(e,t=p.DEFAULT_IGNORED_ENTRIES){return L(e).filter(o=>!t.has(o)).length===0}static resolvePackageManagerCommand(e,t=process.platform){return t!=="win32"||e==="bun"?e:`${e}.cmd`}static resolveInitialWorkingDirectory(e=process.cwd(),t=process.env.INIT_CWD){return t??e}};import{spawn as P}from"child_process";import S from"enquirer";var I=T(import.meta.url),W=s.dirname(I),d=class{constructor(e,t){this.projectDirectory=e;this.version=t?.version}static{g(this,"Create")}config;version;printBanner(){let e=`
|
|
3
3
|
$$$$$$\\ $$\\
|
|
4
4
|
$$ __$$\\ $$ |
|
|
5
5
|
$$ / \\__| $$$$$$\\ $$$$$$\\ $$$$$$\\$$$$\\ $$$$$$$\\ $$$$$$\\ $$$$$$\\ $$\\ $$\\
|
|
@@ -10,4 +10,4 @@ $$ | $$ |$$ | $$ __$$ |$$ | $$ | $$ | \\____$$\\ $$ |$$\\ $$ __$$ | $$
|
|
|
10
10
|
\\______/ \\__| \\_______|\\__| \\__| \\__|\\_______/ \\____/ \\_______|\\__/ \\__|
|
|
11
11
|
|
|
12
12
|
`,t=this.version?`v${this.version}`:"v0.0.0";console.log(`${e}${t}
|
|
13
|
-
`)}getPackageManagerCommands(e){return{bun:{install:"bun install",dev:"bun dev",start:"bun start"},npm:{install:"npm install",dev:"npm run dev",start:"npm start"},pnpm:{install:"pnpm install",dev:"pnpm dev",start:"pnpm start"},yarn:{install:"yarn install",dev:"yarn dev",start:"yarn start"}}[e]}copyDirectorySync(e,t,n={}){r.existsSync(t)||r.mkdirSync(t,{recursive:!0});let a=r.readdirSync(e,{withFileTypes:!0});for(let o of a){let
|
|
13
|
+
`)}getPackageManagerCommands(e){return{bun:{install:"bun install",dev:"bun dev",start:"bun start"},npm:{install:"npm install",dev:"npm run dev",start:"npm start"},pnpm:{install:"pnpm install",dev:"pnpm dev",start:"pnpm start"},yarn:{install:"yarn install",dev:"yarn dev",start:"yarn start"}}[e]}copyDirectorySync(e,t,n={}){r.existsSync(t)||r.mkdirSync(t,{recursive:!0});let a=r.readdirSync(e,{withFileTypes:!0});for(let o of a){let l=s.join(e,o.name),$=s.join(t,o.name);if(o.isDirectory())this.copyDirectorySync(l,$,n);else if(o.isFile()){let c=r.readFileSync(l,"utf-8");c=this.replaceTemplateVariables(c,n),r.writeFileSync($,c)}}}replaceTemplateVariables(e,t){let n=e;for(let[a,o]of Object.entries(t))n=n.replace(new RegExp(`{{${a}}}`,"g"),o);return n}async promptForProjectName(){return(await S.prompt({type:"input",name:"projectName",message:"What is your project named?",initial:"",validate:g(t=>t===""||/^[a-z0-9-_]+$/i.test(t)?!0:"Project name can only contain letters, numbers, hyphens, and underscores","validate")})).projectName}async promptForConfiguration(){let e=[];e.push({type:"select",name:"packageManager",message:"Which package manager would you like to use?",choices:[{name:"bun",message:"Bun (recommended)",value:"bun"},{name:"npm",message:"npm",value:"npm"},{name:"pnpm",message:"pnpm",value:"pnpm"},{name:"yarn",message:"Yarn",value:"yarn"}],initial:0}),e.push({type:"select",name:"runtime",message:"Which runtime would you like to use?",choices:[{name:"bun",message:"Bun (recommended)",value:"bun"},{name:"node",message:"Node.js",value:"node"}],initial:0}),e.push({type:"confirm",name:"eslint",message:"Would you like to use ESLint?",initial:!0});let t=await S.prompt(e);return{packageManager:t.packageManager,runtime:t.runtime,eslint:t.eslint}}async installDependencies(e,t){return await new Promise(n=>{let a=m.resolvePackageManagerCommand(t),l=P(a,["install"],{cwd:e,stdio:"inherit",shell:!1});l.on("close",$=>{$===0?n(!0):(i.fail("Dependencies installation failed"),n(!1))}),l.on("error",$=>{i.fail(`Dependencies installation failed: ${$.message}`),n(!1)})})}async gatherProjectConfig(){this.printBanner();let e=this.projectDirectory,t,n=!1,a=m.resolveInitialWorkingDirectory();e?(t=s.resolve(a,e),n=!1):(e=await this.promptForProjectName(),e===""?(e=s.basename(a),t=a,n=!0):(t=s.resolve(a,e),n=!1));let o=await this.promptForConfiguration(),l=o.packageManager,$=o.runtime,c=o.eslint;return i.info(`Project: ${e}`),i.info(`Location: ${t}`),i.info(`Package Manager: ${l}`),i.info(`Runtime: ${$}`),i.info(`ESLint: ${c?"Yes":"No"}`),n?m.isDirectoryEffectivelyEmpty(t)||(i.error("Current directory is not empty!"),process.exit(1)):r.existsSync(t)&&(i.error(`Directory "${e}" already exists!`),process.exit(1)),{projectName:e,projectPath:t,packageManager:l,runtime:$,setupEslint:c}}async executeProjectGeneration(e){let{projectName:t,projectPath:n,packageManager:a,runtime:o,setupEslint:l}=e;i.info("Creating project directory.."),r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),i.info("Copying template files..");let $=s.join(W,"templates"),c=this.getPackageManagerCommands(a),w={projectName:t,installCmd:c.install,runDevCmd:c.dev,runStartCmd:c.start};this.copyDirectorySync($,n,w),i.info("Creating logs directory.."),r.mkdirSync(s.join(n,"logs"),{recursive:!0}),r.writeFileSync(s.join(n,"logs/.gitkeep"),"");let C=s.join(n,".env"),y=s.join(n,".env.example");if(r.existsSync(y)&&(i.info("Creating .env file.."),r.renameSync(y,C)),o!=="bun"){i.info("Removing bunfig.toml for Node.js runtime..");let u=s.join(n,"bunfig.toml");r.existsSync(u)&&r.unlinkSync(u)}let _=s.join(n,"tsconfig.json"),D=r.readFileSync(_,{encoding:"utf8"}).replace("//{{types}}",o=="bun"?'"bun-types"':"");if(r.writeFileSync(_,D,{encoding:"utf8"}),i.info("Installing dependencies.."),!await this.installDependencies(n,a))return i.fail("Project created failed!"),process.exit();let f=s.join(n,"eslint.config.ts.template"),E=s.join(n,"eslint.config.ts");if(l){i.info("Installing ESLint dependencies..");let u=m.resolvePackageManagerCommand(a),h=a==="yarn"?["add","-D"]:["install","-D"];h.push("eslint","@eslint/js","globals","typescript-eslint"),await new Promise(v=>{let j=P(u,h,{cwd:n,stdio:"inherit",shell:!1});j.on("close",()=>v()),j.on("error",x=>{i.fail(`Failed to install ESLint dependencies: ${x.message}`),v()})}),r.existsSync(f)&&r.renameSync(f,E)}else r.existsSync(f)&&r.unlinkSync(f);i.info("Project created successfully!"),i.info(`Next steps: ${e.projectPath!==process.cwd()?`cd ${t} && `:" "}${c.install} && ${c.dev}`),i.info("Done..")}async createProject(){try{this.config=await this.gatherProjectConfig(),await this.executeProjectGeneration(this.config)}catch(e){e instanceof Error?i.error(`Failed to create project: ${e.message}`):i.error(`Failed to create project: ${String(e)}`),process.exit(1)}}};import{Command as A}from"commander";import{readFileSync as G}from"fs";import{dirname as B,join as O}from"path";import{fileURLToPath as U}from"url";var V=U(import.meta.url),q=B(V),J=O(q,"../../package.json"),b=JSON.parse(G(J,"utf-8")).version,k=new A;k.name("create-gramstax").description("CLI to create a new Gramstax Telegram bot project").version(b).argument("[project-directory]","Directory to create the project in").action(async p=>{try{await new d(p,{version:b}).createProject()}catch(e){i.error(`Failed to create project: ${String(e)}`),process.exit(1)}});k.parse();
|