create-gramstax 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.
Files changed (78) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +0 -0
  3. package/dist/package.json +57 -0
  4. package/dist/src/create-OLD.d.ts +83 -0
  5. package/dist/src/create-OLD.d.ts.map +1 -0
  6. package/dist/src/create-OLD.js +676 -0
  7. package/dist/src/create.d.ts +34 -0
  8. package/dist/src/create.d.ts.map +1 -0
  9. package/dist/src/create.js +367 -0
  10. package/dist/src/index.d.ts +3 -0
  11. package/dist/src/index.d.ts.map +1 -0
  12. package/dist/src/index.js +26 -0
  13. package/dist/src/templates/.env.example +17 -0
  14. package/dist/src/templates/.prettierignore +1 -0
  15. package/dist/src/templates/.prettierrc +23 -0
  16. package/dist/src/templates/LICENSE +0 -0
  17. package/dist/src/templates/README.md +121 -0
  18. package/dist/src/templates/bunfig.toml +2 -0
  19. package/dist/src/templates/ecosystem.config.cjs +26 -0
  20. package/dist/src/templates/package.json +55 -0
  21. package/dist/src/templates/src/base/general.ts +3 -0
  22. package/dist/src/templates/src/base/guard.ts +3 -0
  23. package/dist/src/templates/src/base/page.ts +3 -0
  24. package/dist/src/templates/src/base/repository.ts +1 -0
  25. package/dist/src/templates/src/base/service.ts +1 -0
  26. package/dist/src/templates/src/core/bot.ts +22 -0
  27. package/dist/src/templates/src/db/index.ts +3 -0
  28. package/dist/src/templates/src/env.d.ts +8 -0
  29. package/dist/src/templates/src/guards/user.ts +19 -0
  30. package/dist/src/templates/src/index.ts +17 -0
  31. package/dist/src/templates/src/pages/general-error-input-notfound.ts +34 -0
  32. package/dist/src/templates/src/pages/general-error.ts +51 -0
  33. package/dist/src/templates/src/pages/help.ts +56 -0
  34. package/dist/src/templates/src/pages/start.ts +63 -0
  35. package/dist/src/templates/src/pages/username-notfound.ts +41 -0
  36. package/dist/src/templates/src/repositories/example.ts +5 -0
  37. package/dist/src/templates/src/services/example.ts +4 -0
  38. package/dist/src/templates/src/templates/example.html +7 -0
  39. package/dist/src/templates/src/threads/main.ts +9 -0
  40. package/dist/src/templates/src/utils/log.ts +3 -0
  41. package/dist/src/templates/tsconfig.json +38 -0
  42. package/dist/src/utils/logger.d.ts +3 -0
  43. package/dist/src/utils/logger.d.ts.map +1 -0
  44. package/dist/src/utils/logger.js +2 -0
  45. package/package.json +56 -0
  46. package/src/create-OLD.ts +783 -0
  47. package/src/create.ts +415 -0
  48. package/src/index.ts +28 -0
  49. package/src/templates/.env.example +17 -0
  50. package/src/templates/.prettierignore +1 -0
  51. package/src/templates/.prettierrc +23 -0
  52. package/src/templates/LICENSE +0 -0
  53. package/src/templates/README.md +121 -0
  54. package/src/templates/bunfig.toml +2 -0
  55. package/src/templates/ecosystem.config.cjs +26 -0
  56. package/src/templates/package.json +55 -0
  57. package/src/templates/src/base/general.ts +3 -0
  58. package/src/templates/src/base/guard.ts +3 -0
  59. package/src/templates/src/base/page.ts +3 -0
  60. package/src/templates/src/base/repository.ts +1 -0
  61. package/src/templates/src/base/service.ts +1 -0
  62. package/src/templates/src/core/bot.ts +22 -0
  63. package/src/templates/src/db/index.ts +3 -0
  64. package/src/templates/src/env.d.ts +8 -0
  65. package/src/templates/src/guards/user.ts +19 -0
  66. package/src/templates/src/index.ts +17 -0
  67. package/src/templates/src/pages/general-error-input-notfound.ts +34 -0
  68. package/src/templates/src/pages/general-error.ts +51 -0
  69. package/src/templates/src/pages/help.ts +56 -0
  70. package/src/templates/src/pages/start.ts +63 -0
  71. package/src/templates/src/pages/username-notfound.ts +41 -0
  72. package/src/templates/src/repositories/example.ts +5 -0
  73. package/src/templates/src/services/example.ts +4 -0
  74. package/src/templates/src/templates/example.html +7 -0
  75. package/src/templates/src/threads/main.ts +9 -0
  76. package/src/templates/src/utils/log.ts +3 -0
  77. package/src/templates/tsconfig.json +38 -0
  78. package/src/utils/logger.ts +3 -0
@@ -0,0 +1,34 @@
1
+ export declare class Create {
2
+ private projectDirectory?;
3
+ private version?;
4
+ private config;
5
+ constructor(projectDirectory?: string | undefined, version?: string | undefined);
6
+ printBanner(): void;
7
+ private getPackageManagerCommands;
8
+ /**
9
+ * Recursively copy directory structure
10
+ */
11
+ private copyDirectorySync;
12
+ /**
13
+ * Replace template variables in content
14
+ */
15
+ private replaceTemplateVariables;
16
+ private promptForProjectName;
17
+ private promptForConfiguration;
18
+ private installDependencies;
19
+ /**
20
+ * Step 1: Gather all project configuration through prompts
21
+ * NO EXECUTION - hanya mengumpulkan data dan validasi ringan
22
+ */
23
+ private gatherProjectConfig;
24
+ /**
25
+ * Step 2: Execute project generation based on gathered config
26
+ */
27
+ private executeProjectGeneration;
28
+ private setupEslintConfig;
29
+ /**
30
+ * Main public method: Prompt first, then execute
31
+ */
32
+ createProject(): Promise<void>;
33
+ }
34
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/create.ts"],"names":[],"mappings":"AAgBA,qBAAa,MAAM;IAGE,OAAO,CAAC,gBAAgB,CAAC;IAAU,OAAO,CAAC,OAAO,CAAC;IAFtE,OAAO,CAAC,MAAM,CAA2B;gBAEd,gBAAgB,CAAC,EAAE,MAAM,YAAA,EAAU,OAAO,CAAC,EAAE,MAAM,YAAA;IAIvE,WAAW;IAelB,OAAO,CAAC,yBAAyB;IAkDjC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA4BzB;;OAEG;IACH,OAAO,CAAC,wBAAwB;YAQlB,oBAAoB;YAqBpB,sBAAsB;YAkDtB,mBAAmB;IA0BjC;;;OAGG;YACW,mBAAmB;IAiEjC;;OAEG;YACW,wBAAwB;YAuExB,iBAAiB;IAyB/B;;OAEG;IACU,aAAa;CAgB3B"}
@@ -0,0 +1,367 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { log } from "./utils/logger";
4
+ import { spawn } from "child_process";
5
+ import enquirer from "enquirer";
6
+ export class Create {
7
+ projectDirectory;
8
+ version;
9
+ config;
10
+ constructor(projectDirectory, version) {
11
+ this.projectDirectory = projectDirectory;
12
+ this.version = version;
13
+ // Constructor hanya menerima parameter, tidak melakukan execution
14
+ }
15
+ printBanner() {
16
+ const banner = `
17
+ $$$$$$\\ $$\\
18
+ $$ __$$\\ $$ |
19
+ $$ / \\__| $$$$$$\\ $$$$$$\\ $$$$$$\\$$$$\\ $$$$$$$\\ $$$$$$\\ $$$$$$\\ $$\\ $$\\
20
+ $$ |$$$$\\ $$ __$$\\ \\____$$\\ $$ _$$ _$$\\ $$ _____|\\_$$ _| \\____$$\\ \\$$\\ $$ |
21
+ $$ |\\_$$ |$$ | \\__|$$$$$$$ |$$ / $$ / $$ |\\$$$$$$\\ $$ | $$$$$$$ | \\$$$$ /
22
+ $$ | $$ |$$ | $$ __$$ |$$ | $$ | $$ | \\____$$\\ $$ |$$\\ $$ __$$ | $$ $$<
23
+ \\$$$$$$ |$$ | \\$$$$$$$ |$$ | $$ | $$ |$$$$$$$ | \\$$$$ |\\$$$$$$$ |$$ /\\$$\\
24
+ \\______/ \\__| \\_______|\\__| \\__| \\__|\\_______/ \\____/ \\_______|\\__/ \\__|
25
+
26
+ `;
27
+ console.log(banner);
28
+ }
29
+ getPackageManagerCommands(packageManager) {
30
+ const commands = {
31
+ bun: {
32
+ install: `bun install`,
33
+ dev: `bun dev`,
34
+ start: `bun start`,
35
+ "pm2:start": `bun run pm2:start`,
36
+ "pm2:stop": `bun run pm2:stop`,
37
+ "pm2:restart": `bun run pm2:restart`,
38
+ "pm2:delete": `bun run pm2:delete`,
39
+ "pm2:logs": `bun run pm2:logs`,
40
+ "pm2:monit": `bun run pm2:monit`
41
+ },
42
+ npm: {
43
+ install: `npm install`,
44
+ dev: `npm run dev`,
45
+ start: `npm start`,
46
+ "pm2:start": `npm run pm2:start`,
47
+ "pm2:stop": `npm run pm2:stop`,
48
+ "pm2:restart": `npm run pm2:restart`,
49
+ "pm2:delete": `npm run pm2:delete`,
50
+ "pm2:logs": `npm run pm2:logs`,
51
+ "pm2:monit": `npm run pm2:monit`
52
+ },
53
+ pnpm: {
54
+ install: `pnpm install`,
55
+ dev: `pnpm dev`,
56
+ start: `pnpm start`,
57
+ "pm2:start": `pnpm pm2:start`,
58
+ "pm2:stop": `pnpm pm2:stop`,
59
+ "pm2:restart": `pnpm pm2:restart`,
60
+ "pm2:delete": `pnpm pm2:delete`,
61
+ "pm2:logs": `pnpm pm2:logs`,
62
+ "pm2:monit": `pnpm pm2:monit`
63
+ },
64
+ yarn: {
65
+ install: `yarn install`,
66
+ dev: `yarn dev`,
67
+ start: `yarn start`,
68
+ "pm2:start": `yarn pm2:start`,
69
+ "pm2:stop": `yarn pm2:stop`,
70
+ "pm2:restart": `yarn pm2:restart`,
71
+ "pm2:delete": `yarn pm2:delete`,
72
+ "pm2:logs": `yarn pm2:logs`,
73
+ "pm2:monit": `yarn pm2:monit`
74
+ }
75
+ };
76
+ return commands[packageManager];
77
+ }
78
+ /**
79
+ * Recursively copy directory structure
80
+ */
81
+ copyDirectorySync(source, destination, variables = {}) {
82
+ // Create destination directory if it doesn't exist
83
+ if (!fs.existsSync(destination)) {
84
+ fs.mkdirSync(destination, { recursive: true });
85
+ }
86
+ // Read all items in source directory
87
+ const items = fs.readdirSync(source, { withFileTypes: true });
88
+ for (const item of items) {
89
+ const sourcePath = path.join(source, item.name);
90
+ const destPath = path.join(destination, item.name);
91
+ if (item.isDirectory()) {
92
+ // Recursively copy subdirectories
93
+ this.copyDirectorySync(sourcePath, destPath, variables);
94
+ }
95
+ else if (item.isFile()) {
96
+ // Copy file and replace variables if needed
97
+ let content = fs.readFileSync(sourcePath, `utf-8`);
98
+ // Replace template variables in content
99
+ content = this.replaceTemplateVariables(content, variables);
100
+ fs.writeFileSync(destPath, content);
101
+ }
102
+ }
103
+ }
104
+ /**
105
+ * Replace template variables in content
106
+ */
107
+ replaceTemplateVariables(content, variables) {
108
+ let result = content;
109
+ for (const [key, value] of Object.entries(variables)) {
110
+ result = result.replace(new RegExp(`{{${key}}}`, `g`), value);
111
+ }
112
+ return result;
113
+ }
114
+ async promptForProjectName() {
115
+ const response = await enquirer.prompt({
116
+ type: `input`,
117
+ name: `projectName`,
118
+ message: `What is your project named?`,
119
+ initial: ``,
120
+ validate: (value) => {
121
+ if (value === ``) {
122
+ return true;
123
+ }
124
+ if (!/^[a-z0-9-_]+$/i.test(value)) {
125
+ return `Project name can only contain letters, numbers, hyphens, and underscores`;
126
+ }
127
+ return true;
128
+ }
129
+ });
130
+ return response.projectName;
131
+ }
132
+ async promptForConfiguration() {
133
+ const questions = [];
134
+ // Package manager selection
135
+ questions.push({
136
+ type: `select`,
137
+ name: `packageManager`,
138
+ message: `Which package manager would you like to use?`,
139
+ choices: [
140
+ { name: `bun`, message: `Bun (recommended)`, value: `bun` },
141
+ { name: `npm`, message: `npm`, value: `npm` },
142
+ { name: `pnpm`, message: `pnpm`, value: `pnpm` },
143
+ { name: `yarn`, message: `Yarn`, value: `yarn` }
144
+ ],
145
+ initial: 0
146
+ });
147
+ // Runtime selection
148
+ questions.push({
149
+ type: `select`,
150
+ name: `runtime`,
151
+ message: `Which runtime would you like to use?`,
152
+ choices: [
153
+ { name: `bun`, message: `Bun (recommended)`, value: `bun` },
154
+ { name: `node`, message: `Node.js`, value: `node` }
155
+ ],
156
+ initial: 0
157
+ });
158
+ // ESLint
159
+ questions.push({
160
+ type: `confirm`,
161
+ name: `eslint`,
162
+ message: `Would you like to use ESLint?`,
163
+ initial: true
164
+ });
165
+ const answers = await enquirer.prompt(questions);
166
+ return {
167
+ packageManager: answers.packageManager,
168
+ runtime: answers.runtime,
169
+ eslint: answers.eslint
170
+ };
171
+ }
172
+ async installDependencies(projectPath, packageManager) {
173
+ return await new Promise((resolve, reject) => {
174
+ const installCommand = packageManager;
175
+ const installArgs = [`install`];
176
+ const installProcess = spawn(installCommand, installArgs, {
177
+ cwd: projectPath,
178
+ stdio: `inherit`,
179
+ shell: true
180
+ });
181
+ installProcess.on(`close`, (code) => {
182
+ if (code === 0) {
183
+ resolve(true);
184
+ }
185
+ else {
186
+ log.fail(`Dependencies installation failed`);
187
+ resolve(false);
188
+ }
189
+ });
190
+ installProcess.on(`error`, (error) => {
191
+ log.fail(`Dependencies installation failed: ${error.message}`);
192
+ resolve(false);
193
+ });
194
+ });
195
+ }
196
+ /**
197
+ * Step 1: Gather all project configuration through prompts
198
+ * NO EXECUTION - hanya mengumpulkan data dan validasi ringan
199
+ */
200
+ async gatherProjectConfig() {
201
+ // Display ASCII art banner
202
+ this.printBanner();
203
+ // ========== PHASE 1: GET PROJECT NAME ==========
204
+ let projectName = this.projectDirectory;
205
+ let projectPath;
206
+ let useCurrentDir = false;
207
+ if (!projectName) {
208
+ // PROMPT untuk project name
209
+ projectName = await this.promptForProjectName();
210
+ if (projectName === ``) {
211
+ // Empty name means use current directory
212
+ projectName = path.basename(process.cwd());
213
+ projectPath = process.cwd();
214
+ useCurrentDir = true;
215
+ }
216
+ else {
217
+ projectPath = path.resolve(process.cwd(), projectName);
218
+ useCurrentDir = false;
219
+ }
220
+ }
221
+ else {
222
+ projectPath = path.resolve(process.cwd(), projectName);
223
+ useCurrentDir = false;
224
+ }
225
+ // PROMPT untuk configuration
226
+ const config = await this.promptForConfiguration();
227
+ const packageManager = config.packageManager;
228
+ const runtime = config.runtime;
229
+ const setupEslint = config.eslint;
230
+ // ========== SEMUA PROMPT SELESAI, SEKARANG VALIDASI ==========
231
+ log.info(`Create-gramstax v${this.version}`);
232
+ log.info(`Project: ${projectName}`);
233
+ log.info(`Location: ${projectPath}`);
234
+ log.info(`Package Manager: ${packageManager}`);
235
+ log.info(`Runtime: ${runtime}`);
236
+ log.info(`ESLint: ${setupEslint ? `Yes` : `No`}`);
237
+ // Validasi setelah semua prompt selesai
238
+ if (useCurrentDir) {
239
+ // Check if current directory is empty
240
+ const files = fs.readdirSync(projectPath);
241
+ if (files.length > 0) {
242
+ log.error(`Current directory is not empty!`);
243
+ process.exit(1);
244
+ }
245
+ }
246
+ else {
247
+ // Check if directory already exists
248
+ if (fs.existsSync(projectPath)) {
249
+ log.error(`Directory "${projectName}" already exists!`);
250
+ process.exit(1);
251
+ }
252
+ }
253
+ return {
254
+ projectName,
255
+ projectPath,
256
+ packageManager,
257
+ runtime,
258
+ setupEslint
259
+ };
260
+ }
261
+ /**
262
+ * Step 2: Execute project generation based on gathered config
263
+ */
264
+ async executeProjectGeneration(config) {
265
+ const { projectName, projectPath, packageManager, runtime, setupEslint } = config;
266
+ // Task 1: Create project directory
267
+ log.info(`Creating project directory..`);
268
+ if (!fs.existsSync(projectPath)) {
269
+ fs.mkdirSync(projectPath, { recursive: true });
270
+ }
271
+ // Task 2: Copy template files
272
+ log.info(`Copying template files..`);
273
+ const templatesPath = path.join(__dirname, `templates`);
274
+ const commands = this.getPackageManagerCommands(packageManager);
275
+ const variables = {
276
+ projectName,
277
+ installCmd: commands.install,
278
+ runDevCmd: commands.dev,
279
+ runStartCmd: commands.start,
280
+ runPm2StartCmd: commands[`pm2:start`],
281
+ runPm2StopCmd: commands[`pm2:stop`],
282
+ runPm2RestartCmd: commands[`pm2:restart`],
283
+ runPm2DeleteCmd: commands[`pm2:delete`],
284
+ runPm2LogsCmd: commands[`pm2:logs`],
285
+ runPm2MonitCmd: commands[`pm2:monit`]
286
+ };
287
+ this.copyDirectorySync(templatesPath, projectPath, variables);
288
+ // Task 3: Create logs directory
289
+ log.info(`Creating logs directory..`);
290
+ fs.mkdirSync(path.join(projectPath, `logs`), { recursive: true });
291
+ fs.writeFileSync(path.join(projectPath, `logs/.gitkeep`), ``);
292
+ // Task 4: Create .env.example
293
+ const envPath = path.join(projectPath, `.env`);
294
+ const envExamplePath = path.join(projectPath, `.env.example`);
295
+ if (fs.existsSync(envExamplePath)) {
296
+ log.info(`Creating .env file..`);
297
+ fs.renameSync(envExamplePath, envPath);
298
+ }
299
+ // Task 5: Remove bunfig.toml if runtime is NOT bun
300
+ if (runtime !== `bun`) {
301
+ log.info(`Removing bunfig.toml for Node.js runtime..`);
302
+ const bunfigPath = path.join(projectPath, `bunfig.toml`);
303
+ if (fs.existsSync(bunfigPath)) {
304
+ fs.unlinkSync(bunfigPath);
305
+ }
306
+ }
307
+ // Task 6: Install dependencies
308
+ log.info(`Installing dependencies..`);
309
+ if (!(await this.installDependencies(projectPath, packageManager))) {
310
+ log.fail(`Project created failed!`);
311
+ return process.exit();
312
+ }
313
+ // Task 7: Setup ESLint if requested
314
+ if (setupEslint) {
315
+ log.info(`Setting up ESLint..`);
316
+ await this.setupEslintConfig(projectPath, packageManager);
317
+ }
318
+ // Final success message
319
+ log.info(`Project created successfully!`);
320
+ log.info(`Next steps: ${config.projectPath !== process.cwd() ? `cd ${projectName} && ` : ` `}${commands.install} && ${commands.dev}`);
321
+ log.info(`For production: ${commands[`pm2:start`]}`);
322
+ log.info(`Done..`);
323
+ }
324
+ async setupEslintConfig(projectPath, packageManager) {
325
+ return new Promise((resolve) => {
326
+ const initProcess = spawn(`npm`, [`init`, `@eslint/config@latest`], {
327
+ cwd: projectPath,
328
+ stdio: `inherit`,
329
+ shell: true
330
+ });
331
+ initProcess.on(`close`, (code) => {
332
+ if (code === 0) {
333
+ resolve();
334
+ }
335
+ else {
336
+ log.fail(`ESLint setup failed. You can set it up later with: npm init @eslint/config`);
337
+ resolve();
338
+ }
339
+ });
340
+ initProcess.on(`error`, (error) => {
341
+ log.fail(`ESLint setup failed: ${error.message}`);
342
+ log.info(`You can set it up later with: npm init @eslint/config`);
343
+ resolve();
344
+ });
345
+ });
346
+ }
347
+ /**
348
+ * Main public method: Prompt first, then execute
349
+ */
350
+ async createProject() {
351
+ try {
352
+ // Step 1: Gather all configuration through prompts
353
+ this.config = await this.gatherProjectConfig();
354
+ // Step 2: Execute project generation with the gathered config
355
+ await this.executeProjectGeneration(this.config);
356
+ }
357
+ catch (error) {
358
+ if (error instanceof Error) {
359
+ log.error(`Failed to create project: ${error.message}`);
360
+ }
361
+ else {
362
+ log.error(`Failed to create project: ${String(error)}`);
363
+ }
364
+ process.exit(1);
365
+ }
366
+ }
367
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import { log } from "./utils/logger";
5
+ import { Create } from "./create";
6
+ import { Command } from "commander";
7
+ // Read version from package.json
8
+ const packageJsonPath = path.join(__dirname, `../package.json`);
9
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, `utf-8`));
10
+ const version = packageJson.version || `0.0.0`;
11
+ const program = new Command();
12
+ program
13
+ .name(`create-gramstax`)
14
+ .description(`CLI to create a new Gramstax Telegram bot project`)
15
+ .version(version)
16
+ .argument(`[project-directory]`, `Directory to create the project in`)
17
+ .action(async (projectDirectory) => {
18
+ try {
19
+ await new Create(projectDirectory, version).createProject();
20
+ }
21
+ catch (error) {
22
+ log.error(`Failed to create project: ${String(error)}`);
23
+ process.exit(1);
24
+ }
25
+ });
26
+ program.parse();
@@ -0,0 +1,17 @@
1
+ # Telegram Bot Token
2
+ BOT_TOKEN=your_bot_token_here
3
+
4
+ # Bot Deployment Mode
5
+ # Options:
6
+ # - polling (default, recommended for development)
7
+ # - webhook:https://yourdomain.com (for production)
8
+ BOT_DEPLOY=polling
9
+
10
+ # Environment
11
+ NODE_ENV=development
12
+
13
+ # Cache configuration for session
14
+ # Options:
15
+ # - memory
16
+ # - redis://... (use redis)
17
+ CACHE_SESSION=memory
@@ -0,0 +1 @@
1
+ *.html
@@ -0,0 +1,23 @@
1
+ {
2
+ "overrides": [
3
+ {
4
+ "files": "*.{json,sol}",
5
+ "options": {
6
+ "tabWidth": 2,
7
+ "printWidth": 200
8
+ }
9
+ },
10
+ {
11
+ "files": "*.{ts,js}",
12
+ "options": {
13
+ "printWidth": 300,
14
+ "tabWidth": 2,
15
+ "useTabs": false,
16
+ "semi": false,
17
+ "arrowParens": "always",
18
+ "trailingComma": "none",
19
+ "bracketSameLine": false
20
+ }
21
+ }
22
+ ]
23
+ }
File without changes
@@ -0,0 +1,121 @@
1
+ # {{projectName}}
2
+
3
+ A Telegram bot built with Gramstax framework.
4
+
5
+ ## Getting Started
6
+
7
+ ### Development
8
+
9
+ 1. Install dependencies:
10
+
11
+ ```bash
12
+ {{installCmd}}
13
+ ```
14
+
15
+ 2. Set up your environment variables:
16
+
17
+ Copy `.env.example` to `.env` and add your Telegram bot token:
18
+
19
+ ```bash
20
+ BOT_TOKEN=your_bot_token_here
21
+ ```
22
+
23
+ 3. Run the development server:
24
+
25
+ ```bash
26
+ {{runDevCmd}}
27
+ ```
28
+
29
+ ### Production
30
+
31
+ #### Using PM2 (Recommended)
32
+
33
+ PM2 is a production process manager for Node.js applications with built-in load balancer.
34
+
35
+ 1. Install dependencies:
36
+
37
+ ```bash
38
+ {{installCmd}}
39
+ ```
40
+
41
+ 2. Set up production environment:
42
+
43
+ ```bash
44
+ cp .env.example .env
45
+ # Edit .env with your production BOT_TOKEN
46
+ ```
47
+
48
+ 3. Start with PM2:
49
+
50
+ ```bash
51
+ {{runPm2StartCmd}}
52
+ ```
53
+
54
+ 4. PM2 Management Commands:
55
+
56
+ ```bash
57
+ # View logs
58
+ {{runPm2LogsCmd}}
59
+
60
+ # Monitor processes
61
+ {{runPm2MonitCmd}}
62
+
63
+ # Restart bot
64
+ {{runPm2RestartCmd}}
65
+
66
+ # Stop bot
67
+ {{runPm2StopCmd}}
68
+
69
+ # Delete from PM2
70
+ {{runPm2DeleteCmd}}
71
+ ```
72
+
73
+ 5. Setup PM2 to start on system boot:
74
+
75
+ ```bash
76
+ pm2 startup
77
+ pm2 save
78
+ ```
79
+
80
+ #### Using Bun directly
81
+
82
+ ```bash
83
+ {{runStartCmd}}
84
+ ```
85
+
86
+ ## Project Structure
87
+
88
+ - `src/base/` - Base classes for your bot components
89
+ - `src/core/` - Core bot configuration and hooks
90
+ - `src/pages/` - Bot pages/screens
91
+ - `src/guards/` - Route guards and middleware
92
+ - `src/services/` - Business logic services
93
+ - `src/repositories/` - Data access layer
94
+ - `src/templates/` - Message templates
95
+ - `src/utils/` - Utility functions
96
+ - `logs/` - Application logs (created automatically)
97
+
98
+ ## Configuration
99
+
100
+ ### Environment Variables
101
+
102
+ - `BOT_TOKEN` - Your Telegram bot token (required)
103
+ - `NODE_ENV` - Environment mode (development/production)
104
+ - `CACHE_SESSION` - Cache type configuration (optional)
105
+
106
+ ### PM2 Configuration
107
+
108
+ The `ecosystem.config.cjs` file contains PM2 configuration:
109
+
110
+ - **instances**: Number of instances (default: 1)
111
+ - **exec_mode**: Execution mode (cluster/fork)
112
+ - **max_memory_restart**: Auto-restart if memory exceeds limit
113
+ - **autorestart**: Auto-restart on crash
114
+ - **error_file/out_file**: Log file locations
115
+
116
+ ## Learn More
117
+
118
+ - [Gramstax Documentation](https://github.com/gramstax/gramstax)
119
+ - [Grammy Documentation](https://grammy.dev/)
120
+ - [Telegram Bot API](https://core.telegram.org/bots/api)
121
+ - [PM2 Documentation](https://pm2.keymetrics.io/)
@@ -0,0 +1,2 @@
1
+ [run]
2
+ console.depth = 4
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ apps: [
3
+ {
4
+ name: `{{projectName}}`, // Process name (appears in 'pm2 list')
5
+ script: `bun`, // Main command to run (using Bun runtime)
6
+ args: `src/index.ts`, // Arguments for the command (entry file)
7
+ instances: 1, // Number of instances (use 'max' for multi-core)
8
+ exec_mode: `fork`, // Cluster mode (PM2 will balance across cores)
9
+ autorestart: true, // Automatically restart if the process crashes
10
+ watch: false, // Disable auto-reload on file changes (set true for dev)
11
+ max_memory_restart: undefined, // Restart if memory usage exceeds (default undefined)
12
+ env: {
13
+ NODE_ENV: `production`, // Default environment variables
14
+ },
15
+ env_production: {
16
+ NODE_ENV: `production`, // Environment variables for production mode
17
+ },
18
+ error_file: `./logs/err.log`, // Error log file
19
+ out_file: `./logs/out.log`, // Standard output log file
20
+ log_file: `./logs/combined.log`, // Combined log file
21
+ time: false, // Add timestamps to logs
22
+ merge_logs: false, // Merge logs from multiple instances
23
+ log_date_format: `YYYY-MM-DD HH:mm:ss Z`, // Log date format
24
+ },
25
+ ],
26
+ };