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,55 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "description": "",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": ""
10
+ },
11
+ "bugs": {
12
+ "url": ""
13
+ },
14
+ "homepage": "",
15
+ "author": "",
16
+ "license": "MIT",
17
+ "main": "./dist/src/index.js",
18
+ "types": "./dist/src/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/src/index.d.ts",
22
+ "import": "./dist/src/index.js",
23
+ "default": "./dist/src/index.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "src"
29
+ ],
30
+ "scripts": {
31
+ "dev": "bun --watch src/index.ts",
32
+ "start": "bun src/index.ts",
33
+ "build": "bun build src/index.ts --outdir dist --target bun",
34
+ "lint": "eslint '**/*.ts'",
35
+ "lint:fix": "eslint '**/*.ts' --fix",
36
+ "pm2:start": "pm2 start ecosystem.config.cjs",
37
+ "pm2:stop": "pm2 stop ecosystem.config.cjs",
38
+ "pm2:restart": "pm2 restart ecosystem.config.cjs",
39
+ "pm2:delete": "pm2 delete ecosystem.config.cjs",
40
+ "pm2:logs": "pm2 logs",
41
+ "pm2:monit": "pm2 monit"
42
+ },
43
+ "dependencies": {
44
+ "gramstax": "latest",
45
+ "grammy": "^1.38.3",
46
+ "logging-pretty": "^3.0.0"
47
+ },
48
+ "peerDependencies": {
49
+ "typescript": "latest"
50
+ },
51
+ "devDependencies": {
52
+ "@types/bun": "latest",
53
+ "pm2": "^5.3.0"
54
+ }
55
+ }
@@ -0,0 +1,3 @@
1
+ import { BaseGeneral } from "gramstax"
2
+
3
+ export abstract class GeneralBase extends BaseGeneral {}
@@ -0,0 +1,3 @@
1
+ import { BaseGuard } from "gramstax"
2
+
3
+ export abstract class GuardBase extends BaseGuard {}
@@ -0,0 +1,3 @@
1
+ import { BasePage } from "gramstax"
2
+
3
+ export abstract class PageBase extends BasePage {}
@@ -0,0 +1 @@
1
+ export abstract class RepositoryBase {}
@@ -0,0 +1 @@
1
+ export abstract class ServiceBase {}
@@ -0,0 +1,22 @@
1
+ import { Gramstax, type Ctx } from "gramstax"
2
+ import { UserGuard } from "../guards/user"
3
+ import { GeneralErrorPage } from "../pages/general-error"
4
+ import { GeneralErrorInputNotFoundPage } from "../pages/general-error-input-notfound"
5
+
6
+ export class BotCore extends Gramstax {
7
+ public async hookBeforeRoute(ctx: Ctx): Promise<boolean> {
8
+ const result = await new UserGuard({ ctx }).ensureValid(true)
9
+ if (result === null) {
10
+ return false
11
+ }
12
+ return true
13
+ }
14
+
15
+ public async hookErrorPage(ctx: Ctx, listenerName: string, error: any, isEdit: boolean): Promise<void> {
16
+ await new GeneralErrorPage(ctx).transition(this.constructor.name, listenerName, error, isEdit)
17
+ }
18
+
19
+ public async hookErrorInputNotFoundPage(ctx: Ctx): Promise<void> {
20
+ await new GeneralErrorInputNotFoundPage(ctx).transition()
21
+ }
22
+ }
@@ -0,0 +1,3 @@
1
+ // YOU CAN DELETE THIS FILE
2
+
3
+ export class Db {}
@@ -0,0 +1,8 @@
1
+ declare namespace NodeJS {
2
+ interface ProcessEnv {
3
+ BOT_TOKEN: string
4
+ BOT_DEPLOY: string
5
+ NODE_ENV?: `development` | `production`
6
+ CACHE_SESSION?: string
7
+ }
8
+ }
@@ -0,0 +1,19 @@
1
+ import { GuardBase } from "../base/guard"
2
+ import { GeneralErrorPage } from "../pages/general-error"
3
+ import { UserNameNotFoundPage } from "../pages/username-notfound"
4
+
5
+ export class UserGuard extends GuardBase {
6
+ public async ensureValid(isEdit: boolean) {
7
+ try {
8
+ if (!this.username || this.username.length == 0) {
9
+ await new UserNameNotFoundPage(this).transition(isEdit)
10
+ return null
11
+ }
12
+
13
+ return { status: true }
14
+ } catch (err) {
15
+ await new GeneralErrorPage(this).transition(this.constructor.name, `ensureValid`, err, isEdit)
16
+ return null
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,17 @@
1
+ import { log } from "./utils/log"
2
+ import { BotCore } from "./core/bot"
3
+ import { MainThread } from "./threads/main"
4
+ import { CacheExternal } from "gramstax"
5
+
6
+ new MainThread(() => {
7
+ log.success(`Bot started..`)
8
+
9
+ const token = process.env.BOT_TOKEN as string
10
+ const deploy = process.env.BOT_DEPLOY as string
11
+ const cache = process.env.CACHE_SESSION as string
12
+ new BotCore({
13
+ token,
14
+ deploy,
15
+ cacheSession: new CacheExternal(cache, `session`, 24 * 60 * 60 * 1000)
16
+ })
17
+ })
@@ -0,0 +1,34 @@
1
+ import { PageBase } from "../base/page"
2
+ import { StartPage } from "./start"
3
+
4
+ export class GeneralErrorInputNotFoundPage extends PageBase {
5
+ public kb() {
6
+ return this.buildInlineKeyboard((kb, arr) => {
7
+ return kb.text(arr[0], StartPage.data.callbackData())
8
+ })
9
+ }
10
+
11
+ public async transition() {
12
+ await this.edit(this.kb())
13
+ }
14
+
15
+ public static template = /*jsx*/ `
16
+ <base>
17
+ <keyboard lang="en" for="inline">.. Home</keyboard>
18
+ <keyboard lang="it" for="inline">.. Casa</keyboard>
19
+ <keyboard lang="id" for="inline">.. Beranda</keyboard>
20
+
21
+ <message lang="en">
22
+ <b>❌ Not Found</b>
23
+ </message>
24
+
25
+ <message lang="it">
26
+ <b>❌ Non Trovato</b>
27
+ </message>
28
+
29
+ <message lang="id">
30
+ <b>❌ Tidak Ditemukan</b>
31
+ </message>
32
+ </base>
33
+ `
34
+ }
@@ -0,0 +1,51 @@
1
+ import { PageBase } from "../base/page"
2
+ import { StartPage } from "./start"
3
+
4
+ export class GeneralErrorPage extends PageBase {
5
+ public kb() {
6
+ return this.buildInlineKeyboard((kb, arr) => {
7
+ return kb.text(arr[0], StartPage.data.callbackData())
8
+ })
9
+ }
10
+
11
+ public async transition(constructorName: string, funcName: string, error: any, isUpdate = true) {
12
+ this.logError(error, constructorName, funcName)
13
+ await this.sessionClear()
14
+
15
+ const kb = this.kb()
16
+ if (isUpdate === true) {
17
+ await this.edit(kb)
18
+ } else {
19
+ await this.reply(kb)
20
+ }
21
+ }
22
+
23
+ public static template = /*jsx*/ `
24
+ <base>
25
+ <keyboard lang="en" for="inline">.. Home</keyboard>
26
+ <keyboard lang="es" for="inline">.. Inicio</keyboard>
27
+ <keyboard lang="id" for="inline">.. Beranda</keyboard>
28
+
29
+ <message lang="en">
30
+ <b>❌ Error</b>
31
+
32
+ An unexpected error occurred.
33
+ Please try again later.
34
+ </message>
35
+
36
+ <message lang="it">
37
+ <b>❌ Errore</b>
38
+
39
+ Si è verificato un errore imprevisto.
40
+ Riprova più tardi.
41
+ </message>
42
+
43
+ <message lang="id">
44
+ <b>❌ Kesalahan</b>
45
+
46
+ Terjadi kesalahan yang tidak diharapkan.
47
+ Silakan coba lagi nanti.
48
+ </message>
49
+ </base>
50
+ `
51
+ }
@@ -0,0 +1,56 @@
1
+ import { PageBase } from "../base/page"
2
+ import { StartPage } from "./start"
3
+
4
+ export class HelpPage extends PageBase {
5
+ public kb() {
6
+ return this.buildInlineKeyboard((kb, arr) => {
7
+ return kb //
8
+ .text(arr[0], StartPage.data.callbackData())
9
+ })
10
+ }
11
+
12
+ public async internal(edit = true) {
13
+ const kb = this.kb()
14
+ if (edit) {
15
+ await this.edit(kb)
16
+ } else {
17
+ await this.reply(kb)
18
+ }
19
+ }
20
+
21
+ public async callback() {
22
+ await this.internal(true)
23
+ }
24
+
25
+ public async text() {
26
+ await this.internal(false)
27
+ }
28
+
29
+ public async textCommand() {
30
+ await this.internal(false)
31
+ }
32
+
33
+ public async textCommandPayload() {
34
+ await this.internal(false)
35
+ }
36
+
37
+ public static template = /*jsx*/ `
38
+ <base>
39
+ <keyboard lang="en" for="inline">.. Back</keyboard>
40
+ <keyboard lang="it" for="inline">.. Ritorno</keyboard>
41
+ <keyboard lang="id" for="inline">.. Kembali</keyboard>
42
+
43
+ <message lang="en">
44
+ <b>Help message</b>
45
+ </message>
46
+
47
+ <message lang="it">
48
+ <b>Ordina aiuto</b>
49
+ </message>
50
+
51
+ <message lang="id">
52
+ <b>Pesan bantuan</b>
53
+ </message>
54
+ </base>
55
+ `
56
+ }
@@ -0,0 +1,63 @@
1
+ import { HelpPage } from "./help"
2
+ import { PageBase } from "../base/page"
3
+
4
+ export class StartPage extends PageBase {
5
+ public kb() {
6
+ return this.buildInlineKeyboard((kb, arr) => {
7
+ return kb //
8
+ .text(arr[0], HelpPage.data.callbackData())
9
+ })
10
+ }
11
+
12
+ public async internal(edit = true) {
13
+ const kb = this.kb()
14
+ const data = { username: this.ctx.username }
15
+ if (edit) {
16
+ await this.edit(kb, data)
17
+ } else {
18
+ await this.reply(kb, data)
19
+ }
20
+ }
21
+
22
+ public async callback() {
23
+ await this.internal(true)
24
+ }
25
+
26
+ public async text() {
27
+ await this.internal(false)
28
+ }
29
+
30
+ public async textCommand() {
31
+ await this.internal(false)
32
+ }
33
+
34
+ public async textCommandPayload() {
35
+ await this.internal(false)
36
+ }
37
+
38
+ public static template = /*jsx*/ `
39
+ <base>
40
+ <keyboard lang="en" for="inline">❓ Help</keyboard>
41
+ <keyboard lang="it" for="inline">❓ Aiuto</keyboard>
42
+ <keyboard lang="id" for="inline">❓ Bantuan</keyboard>
43
+
44
+ <message lang="en">
45
+ <b>Welcome to the bot {{username}}</b>
46
+
47
+ <b>❓ Help</b> - View help
48
+ </message>
49
+
50
+ <message lang="it">
51
+ <b>Benvenuto nel Bot di {{username}}</b>
52
+
53
+ <b>❓ Aiuto</b> - Ottieni assistenza e informazioni
54
+ </message>
55
+
56
+ <message lang="id">
57
+ <b>Selamat datang di bot {{username}}</b>
58
+
59
+ <b>❓ Bantuan</b> - Lihat bantuan
60
+ </message>
61
+ </base>
62
+ `
63
+ }
@@ -0,0 +1,41 @@
1
+ import { HelpPage } from "./help"
2
+ import { PageBase } from "../base/page"
3
+
4
+ export class UserNameNotFoundPage extends PageBase {
5
+ public kb() {
6
+ return this.buildInlineKeyboard((kb, arr) => {
7
+ return kb //
8
+ .text(arr[0], HelpPage.data.callbackData())
9
+ })
10
+ }
11
+
12
+ public async transition(edit = true) {
13
+ const kb = this.kb()
14
+ const data = { username: this.ctx.username }
15
+ if (edit) {
16
+ await this.edit(kb, data)
17
+ } else {
18
+ await this.reply(kb, data)
19
+ }
20
+ }
21
+
22
+ public static template = /*jsx*/ `
23
+ <base>
24
+ <keyboard lang="en" for="inline">.. Home</keyboard>
25
+ <keyboard lang="es" for="inline">.. Inicio</keyboard>
26
+ <keyboard lang="id" for="inline">.. Beranda</keyboard>
27
+
28
+ <message lang="en">
29
+ Please set the username first before using the bot.
30
+ </message>
31
+
32
+ <message lang="it">
33
+ Prima di utilizzare il bot, imposta prima il nome utente.
34
+ </message>
35
+
36
+ <message lang="id">
37
+ Tolong set username dulu sebelum memakai bot
38
+ </message>
39
+ </base>
40
+ `
41
+ }
@@ -0,0 +1,5 @@
1
+ // YOU CAN DELETE THIS FILE
2
+
3
+ import { RepositoryBase } from "../base/repository"
4
+
5
+ export class ExampleRepository extends RepositoryBase {}
@@ -0,0 +1,4 @@
1
+ // YOU CAN DELETE THIS FILE
2
+ import { ServiceBase } from "../base/service"
3
+
4
+ export class ExampleService extends ServiceBase {}
@@ -0,0 +1,7 @@
1
+ <!-- YOU CAN DELETE THIS FILE -->
2
+
3
+ <base>
4
+ <message lang="en">
5
+ Must have file page in /pages/example.ts
6
+ </message>
7
+ </base>
@@ -0,0 +1,9 @@
1
+ import { isMainThread } from "bun"
2
+
3
+ export class MainThread {
4
+ constructor(mainFunc: () => any) {
5
+ if (isMainThread === true) {
6
+ mainFunc()
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,3 @@
1
+ import LoggingPretty from "logging-pretty"
2
+
3
+ export const log = new LoggingPretty()
@@ -0,0 +1,38 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Short relative path
4
+ "baseUrl": ".",
5
+ "paths": {
6
+ "~/*": [
7
+ "./src/*"
8
+ ]
9
+ },
10
+ // Environment setup & latest features
11
+ "lib": [
12
+ "ESNext"
13
+ ],
14
+ "target": "ESNext",
15
+ "module": "Preserve",
16
+ "moduleDetection": "force",
17
+ "types": [
18
+ "bun-types"
19
+ ],
20
+ "jsx": "react-jsx",
21
+ "allowJs": true,
22
+ // Bundler mode
23
+ "moduleResolution": "bundler",
24
+ "allowImportingTsExtensions": true,
25
+ "verbatimModuleSyntax": true,
26
+ "noEmit": true,
27
+ // Best practices
28
+ "strict": true,
29
+ "skipLibCheck": true,
30
+ "noFallthroughCasesInSwitch": true,
31
+ "noUncheckedIndexedAccess": true,
32
+ // Some stricter flags (disabled by default)
33
+ "noImplicitOverride": true,
34
+ "noUnusedLocals": false,
35
+ "noUnusedParameters": false,
36
+ "noPropertyAccessFromIndexSignature": false,
37
+ }
38
+ }
@@ -0,0 +1,3 @@
1
+ import LoggingPretty from "logging-pretty";
2
+ export declare const log: LoggingPretty;
3
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,gBAAgB,CAAA;AAE1C,eAAO,MAAM,GAAG,eAAsB,CAAA"}
@@ -0,0 +1,2 @@
1
+ import LoggingPretty from "logging-pretty";
2
+ export const log = new LoggingPretty();
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "create-gramstax",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "description": "CLI tool to quickly create a new Gramstax Telegram bot project with all the best practices",
6
+ "keywords": [
7
+ "create-gramstax",
8
+ "gramstax",
9
+ "telegram",
10
+ "bot",
11
+ "cli",
12
+ "generator",
13
+ "scaffold",
14
+ "telegram-bot"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/gramstax/gramstax",
19
+ "directory": "packages/create-gramstax"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/gramstax/gramstax/issues"
23
+ },
24
+ "homepage": "https://github.com/gramstax/gramstax",
25
+ "author": "gramstax",
26
+ "license": "MIT",
27
+ "type": "module",
28
+ "main": "./dist/src/index.js",
29
+ "types": "./dist/src/index.d.ts",
30
+ "bin": {
31
+ "create-gramstax": "./dist/src/index.js"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/src/index.d.ts",
36
+ "import": "./dist/src/index.js",
37
+ "default": "./dist/src/index.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "src"
43
+ ],
44
+ "devDependencies": {
45
+ "@types/bun": "latest"
46
+ },
47
+ "peerDependencies": {
48
+ "typescript": "^5"
49
+ },
50
+ "dependencies": {
51
+ "commander": "^14.0.2",
52
+ "enquirer": "^2.4.1",
53
+ "gramstax": "workspace:*",
54
+ "logging-pretty": "^3.0.0"
55
+ }
56
+ }