@dhayalesh/create-ktern-go 1.0.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/bin/cli.js ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const inquirer = require('inquirer');
6
+ const ejs = require('ejs');
7
+ const { promisify } = require('util');
8
+
9
+ const copyFile = promisify(fs.copyFile);
10
+ const mkdir = promisify(fs.mkdir);
11
+ const readdir = promisify(fs.readdir);
12
+ const stat = promisify(fs.stat);
13
+ const writeFile = promisify(fs.writeFile);
14
+ const readFile = promisify(fs.readFile);
15
+
16
+ async function copyTemplate(src, dest, data) {
17
+ const stats = await stat(src);
18
+ if (stats.isDirectory()) {
19
+ if (!fs.existsSync(dest)) {
20
+ await mkdir(dest, { recursive: true });
21
+ }
22
+ const files = await readdir(src);
23
+ for (const file of files) {
24
+ await copyTemplate(path.join(src, file), path.join(dest, file), data);
25
+ }
26
+ } else {
27
+ let content = await readFile(src, 'utf8');
28
+ // Simple template replacement if no EJS variables are found or if we want to use EJS
29
+ try {
30
+ content = ejs.render(content, data);
31
+ } catch (err) {
32
+ // If EJS fails (e.g. invalid syntax in non-template files), just use raw content
33
+ }
34
+
35
+ // Remove .template or .tmpl suffix if present in destination filename
36
+ const finalDest = dest.replace(/\.template$/, '').replace(/\.tmpl$/, '');
37
+ await writeFile(finalDest, content);
38
+ }
39
+ }
40
+
41
+ async function run() {
42
+ console.log('šŸš€ Welcome to the KTERN Generator!');
43
+
44
+ const questions = [
45
+ {
46
+ type: 'input',
47
+ name: 'name',
48
+ message: 'What is the project name?',
49
+ validate: (input) => input.length > 0 || 'Project name is required',
50
+ },
51
+ {
52
+ type: 'input',
53
+ name: 'directory',
54
+ message: 'In which directory should the project be created?',
55
+ default: (answers) => path.join(process.cwd(), answers.name),
56
+ },
57
+ {
58
+ type: 'number',
59
+ name: 'port',
60
+ message: 'What port should the service run on?',
61
+ default: 3000,
62
+ },
63
+ ];
64
+
65
+ const answers = await inquirer.prompt(questions);
66
+ const targetDir = path.resolve(answers.directory);
67
+
68
+ if (fs.existsSync(targetDir)) {
69
+ const { overwrite } = await inquirer.prompt([
70
+ {
71
+ type: 'confirm',
72
+ name: 'overwrite',
73
+ message: `Directory ${targetDir} already exists. Overwrite?`,
74
+ default: false,
75
+ },
76
+ ]);
77
+ if (!overwrite) {
78
+ console.log('Exiting...');
79
+ process.exit(0);
80
+ }
81
+ }
82
+
83
+ console.log(`\nCreating project "${answers.name}" in ${targetDir}...`);
84
+
85
+ const templateDir = path.join(__dirname, '../templates');
86
+ await copyTemplate(templateDir, targetDir, {
87
+ name: answers.name,
88
+ port: answers.port,
89
+ // Add more default variables if needed
90
+ });
91
+
92
+ console.log('\nāœ… Project created successfully!');
93
+ console.log(`\nNext steps:`);
94
+ console.log(` cd ${targetDir}`);
95
+ console.log(` npm install`);
96
+ console.log(` npm start`);
97
+ }
98
+
99
+ run().catch((err) => {
100
+ console.error('āŒ Error:', err.message);
101
+ process.exit(1);
102
+ });
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@dhayalesh/create-ktern-go",
3
+ "version": "1.0.0",
4
+ "description": "Standalone KTERN go generator",
5
+ "bin": {
6
+ "create-ktern-go": "./bin/cli.js"
7
+ },
8
+ "dependencies": {
9
+ "inquirer": "^8.2.4",
10
+ "ejs": "^3.1.8"
11
+ },
12
+ "publishConfig": {
13
+ "access": "restricted"
14
+ }
15
+ }
@@ -0,0 +1,37 @@
1
+ module "<%= name %>"
2
+
3
+ go 1.25.4
4
+
5
+ require (
6
+ github.com/bytedance/gopkg v0.1.3 // indirect
7
+ github.com/bytedance/sonic v1.14.2 // indirect
8
+ github.com/bytedance/sonic/loader v0.4.0 // indirect
9
+ github.com/cloudwego/base64x v0.1.6 // indirect
10
+ github.com/gabriel-vasile/mimetype v1.4.12 // indirect
11
+ github.com/gin-contrib/sse v1.1.0 // indirect
12
+ github.com/gin-gonic/gin v1.11.0 // indirect
13
+ github.com/go-playground/locales v0.14.1 // indirect
14
+ github.com/go-playground/universal-translator v0.18.1 // indirect
15
+ github.com/go-playground/validator/v10 v10.30.0 // indirect
16
+ github.com/goccy/go-json v0.10.5 // indirect
17
+ github.com/goccy/go-yaml v1.19.1 // indirect
18
+ github.com/json-iterator/go v1.1.12 // indirect
19
+ github.com/klauspost/cpuid/v2 v2.3.0 // indirect
20
+ github.com/leodido/go-urn v1.4.0 // indirect
21
+ github.com/mattn/go-isatty v0.0.20 // indirect
22
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
23
+ github.com/modern-go/reflect2 v1.0.2 // indirect
24
+ github.com/pelletier/go-toml/v2 v2.2.4 // indirect
25
+ github.com/quic-go/qpack v0.6.0 // indirect
26
+ github.com/quic-go/quic-go v0.58.0 // indirect
27
+ github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
28
+ github.com/ugorji/go/codec v1.3.1 // indirect
29
+ go.uber.org/mock v0.6.0 // indirect
30
+ golang.org/x/arch v0.23.0 // indirect
31
+ golang.org/x/crypto v0.46.0 // indirect
32
+ golang.org/x/mod v0.31.0 // indirect
33
+ golang.org/x/net v0.48.0 // indirect
34
+ golang.org/x/sys v0.39.0 // indirect
35
+ golang.org/x/text v0.32.0 // indirect
36
+ google.golang.org/protobuf v1.36.11 // indirect
37
+ )
@@ -0,0 +1,5 @@
1
+ package grpc
2
+
3
+ func Register() {
4
+ // gRPC services will be registered here.
5
+ }
@@ -0,0 +1,7 @@
1
+ package http
2
+
3
+ import "github.com/gin-gonic/gin"
4
+
5
+ func HealthHandler(c *gin.Context) {
6
+ c.String(200, "OK")
7
+ }
@@ -0,0 +1,9 @@
1
+ package http
2
+
3
+ import "github.com/gin-gonic/gin"
4
+
5
+ func NewRouter() *gin.Engine {
6
+ r := gin.New() // no default middleware
7
+ r.GET("/health", HealthHandler)
8
+ return r
9
+ }
@@ -0,0 +1,4 @@
1
+ package application
2
+
3
+ // Application orchestration lives here.
4
+ // No domain assumptions yet.
@@ -0,0 +1,11 @@
1
+ package di
2
+
3
+ import (
4
+ api "<%= name %>/internal/api/http"
5
+
6
+ "github.com/gin-gonic/gin"
7
+ )
8
+
9
+ func BuildHTTPRouter() *gin.Engine {
10
+ return api.NewRouter()
11
+ }
@@ -0,0 +1,4 @@
1
+ package domain
2
+
3
+ // Domain contracts live here.
4
+ // Intentionally empty.
@@ -0,0 +1,3 @@
1
+ package infrastructure
2
+
3
+ // Infrastructure implementations live here.
@@ -0,0 +1,16 @@
1
+ package main
2
+
3
+ import (
4
+ "log"
5
+
6
+ "<%= name %>/internal/di"
7
+ )
8
+
9
+ func main() {
10
+ router := di.BuildHTTPRouter()
11
+
12
+ log.Println("service started on :8080")
13
+ if err := router.Run(":8080"); err != nil {
14
+ log.Fatal(err)
15
+ }
16
+ }
File without changes
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "<%= name %>",
3
+ "targets": {
4
+ "build": {
5
+ "executor": "nx:run-commands",
6
+ "options": {
7
+ "cwd": "<%= projectRoot %>",
8
+ "command": "go build -o dist/<%= name %>"
9
+ },
10
+ "outputs": ["{workspaceRoot}/<%= projectRoot %>/dist"]
11
+ },
12
+
13
+ "serve": {
14
+ "executor": "nx:run-commands",
15
+ "options": {
16
+ "cwd": "<%= projectRoot %>",
17
+ "command": "go run main.go"
18
+ }
19
+ }
20
+ }
21
+ }