go-duck-cli 1.1.29 → 1.1.31
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/generators/devops.js +6 -1
- package/generators/graphql.js +4 -1
- package/generators/kratos.js +3 -1
- package/generators/router.js +4 -1
- package/index.js +11 -7
- package/package.json +1 -1
package/generators/devops.js
CHANGED
|
@@ -96,6 +96,7 @@ services:
|
|
|
96
96
|
- "${dbPort}:5432"
|
|
97
97
|
volumes:
|
|
98
98
|
- postgres_data:/var/lib/postgresql/data
|
|
99
|
+
- ./postgres-init:/docker-entrypoint-initdb.d
|
|
99
100
|
healthcheck:
|
|
100
101
|
test: ["CMD-SHELL", "pg_isready -U ${config.datasource?.username || 'postgres'} -d ${config.datasource?.database || 'go_duck_master'}"]
|
|
101
102
|
interval: 5s
|
|
@@ -167,7 +168,7 @@ services:
|
|
|
167
168
|
KEYCLOAK_ADMIN: admin
|
|
168
169
|
KEYCLOAK_ADMIN_PASSWORD: admin
|
|
169
170
|
KC_DB: postgres
|
|
170
|
-
KC_DB_URL: jdbc:postgresql://postgres:5432
|
|
171
|
+
KC_DB_URL: jdbc:postgresql://postgres:5432/keycloak
|
|
171
172
|
KC_DB_USERNAME: ${config.datasource?.username || 'postgres'}
|
|
172
173
|
KC_DB_PASSWORD: ${config.datasource?.password || 'password'}
|
|
173
174
|
depends_on:
|
|
@@ -392,6 +393,10 @@ jobs:
|
|
|
392
393
|
await fs.ensureDir(realmConfigDir);
|
|
393
394
|
await fs.writeFile(path.join(realmConfigDir, `${realmName}-realm.json`), realmJson);
|
|
394
395
|
|
|
396
|
+
const postgresInitDir = path.join(devopsDir, 'postgres-init');
|
|
397
|
+
await fs.ensureDir(postgresInitDir);
|
|
398
|
+
await fs.writeFile(path.join(postgresInitDir, 'init.sql'), 'CREATE DATABASE keycloak;\n');
|
|
399
|
+
|
|
395
400
|
await fs.writeFile(path.join(devopsDir, 'Dockerfile'), dockerfile);
|
|
396
401
|
await fs.writeFile(path.join(devopsDir, 'services.yml'), servicesYaml);
|
|
397
402
|
await fs.writeFile(path.join(devopsDir, 'app.yml'), appYaml);
|
package/generators/graphql.js
CHANGED
|
@@ -2,12 +2,15 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import Handlebars from 'handlebars';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
5
6
|
|
|
6
7
|
export const generateGraphQLCode = async (config, entities, relationships, outputDir, enums = []) => {
|
|
7
8
|
const graphDir = path.join(outputDir, 'graph');
|
|
8
9
|
await fs.ensureDir(graphDir);
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
const templatesDir = path.resolve(__dirname, '../templates/graphql');
|
|
11
14
|
|
|
12
15
|
// 1. Generate schema.graphqls
|
|
13
16
|
const schemaTemplatePath = path.join(templatesDir, 'schema.graphql.hbs');
|
package/generators/kratos.js
CHANGED
|
@@ -2,6 +2,7 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import Handlebars from 'handlebars';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
5
6
|
|
|
6
7
|
export const generateKratosCode = async (entities, projectRootDir, projectName, enums = []) => {
|
|
7
8
|
console.log(chalk.cyan('Generating Kratos gRPC Services...'));
|
|
@@ -14,7 +15,8 @@ export const generateKratosCode = async (entities, projectRootDir, projectName,
|
|
|
14
15
|
await fs.ensureDir(serviceDir);
|
|
15
16
|
await fs.ensureDir(serverDir);
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = path.dirname(__filename);
|
|
18
20
|
const templateBase = path.resolve(__dirname, '..', 'templates');
|
|
19
21
|
|
|
20
22
|
const protoTemplateSource = await fs.readFile(path.join(templateBase, 'proto', 'entity.proto.hbs'), 'utf8');
|
package/generators/router.js
CHANGED
|
@@ -2,12 +2,15 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import Handlebars from 'handlebars';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
5
6
|
|
|
6
7
|
export const generateRouterCode = async (outputDir, config, entities, openEntities) => {
|
|
7
8
|
const routerDir = path.join(outputDir, 'router');
|
|
8
9
|
await fs.ensureDir(routerDir);
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
const templatePath = path.resolve(__dirname, '../templates/go/router.go.hbs');
|
|
11
14
|
if (!await fs.pathExists(templatePath)) {
|
|
12
15
|
console.error(chalk.red(`❌ Router template not found: ${templatePath}`));
|
|
13
16
|
return;
|
package/index.js
CHANGED
|
@@ -14,10 +14,14 @@ import chalk from 'chalk';
|
|
|
14
14
|
import { execSync } from 'child_process';
|
|
15
15
|
import express from 'express';
|
|
16
16
|
import open from 'open';
|
|
17
|
+
import { fileURLToPath } from 'url';
|
|
17
18
|
import { parseGDL } from './parser/gdl.js';
|
|
18
19
|
import { generateMultitenancy } from './generators/multitenancy.js';
|
|
19
20
|
import { generateLiquibaseChangelogs } from './generators/migrations.js';
|
|
20
21
|
import { generateMeteringCode } from './generators/metering.js';
|
|
22
|
+
|
|
23
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
24
|
+
const __dirname = path.dirname(__filename);
|
|
21
25
|
import { generateGraphQLCode } from './generators/graphql.js';
|
|
22
26
|
import { generatePostgRESTCode } from './generators/postgrest.js';
|
|
23
27
|
import { generateSwaggerDocs } from './generators/swagger.js';
|
|
@@ -288,7 +292,7 @@ Handlebars.registerPartial('renderFields', `
|
|
|
288
292
|
{{/each}}
|
|
289
293
|
`);
|
|
290
294
|
|
|
291
|
-
const pkgPath = path.resolve(
|
|
295
|
+
const pkgPath = path.resolve(__dirname, 'package.json');
|
|
292
296
|
const pkg = fs.readJsonSync(pkgPath);
|
|
293
297
|
|
|
294
298
|
program
|
|
@@ -399,15 +403,15 @@ const generateEntities = async (gdlPath, outputDir, config) => {
|
|
|
399
403
|
return fromEntityCreated || toEntityCreated;
|
|
400
404
|
});
|
|
401
405
|
|
|
402
|
-
const entityTemplatePath = path.resolve(
|
|
406
|
+
const entityTemplatePath = path.resolve(__dirname, 'templates/go/entity.go.hbs');
|
|
403
407
|
const entityTemplateSource = await fs.readFile(entityTemplatePath, 'utf8');
|
|
404
408
|
const entityTemplate = Handlebars.compile(entityTemplateSource);
|
|
405
409
|
|
|
406
|
-
const controllerTemplatePath = path.resolve(
|
|
410
|
+
const controllerTemplatePath = path.resolve(__dirname, 'templates/go/controller.go.hbs');
|
|
407
411
|
const controllerTemplateSource = await fs.readFile(controllerTemplatePath, 'utf8');
|
|
408
412
|
const controllerTemplate = Handlebars.compile(controllerTemplateSource);
|
|
409
413
|
|
|
410
|
-
const enumTemplatePath = path.resolve(
|
|
414
|
+
const enumTemplatePath = path.resolve(__dirname, 'templates/go/enum.go.hbs');
|
|
411
415
|
const enumTemplateSource = await fs.readFile(enumTemplatePath, 'utf8');
|
|
412
416
|
const enumTemplate = Handlebars.compile(enumTemplateSource);
|
|
413
417
|
|
|
@@ -512,7 +516,7 @@ program
|
|
|
512
516
|
await generateRepositoryCode(absoluteOutputDir);
|
|
513
517
|
|
|
514
518
|
{
|
|
515
|
-
const migratorTemplatePath = path.resolve(
|
|
519
|
+
const migratorTemplatePath = path.resolve(__dirname, 'templates/go/migrator.go.hbs');
|
|
516
520
|
if (await fs.pathExists(migratorTemplatePath)) {
|
|
517
521
|
const migratorTemplate = Handlebars.compile(await fs.readFile(migratorTemplatePath, 'utf8'));
|
|
518
522
|
await fs.writeFile(path.join(absoluteOutputDir, 'migrations/migrations.go'), migratorTemplate({ app_name: config.name }));
|
|
@@ -550,7 +554,7 @@ program
|
|
|
550
554
|
console.log(chalk.green('🤖 System-level AI Blueprint Documentation generated!'));
|
|
551
555
|
|
|
552
556
|
// 9. Generate main.go
|
|
553
|
-
const mainTemplatePath = path.resolve(
|
|
557
|
+
const mainTemplatePath = path.resolve(__dirname, 'templates/go/main.go.hbs');
|
|
554
558
|
if (await fs.pathExists(mainTemplatePath)) {
|
|
555
559
|
const mainTemplateSource = await fs.readFile(mainTemplatePath, 'utf8');
|
|
556
560
|
const mainTemplate = Handlebars.compile(mainTemplateSource);
|
|
@@ -675,7 +679,7 @@ program
|
|
|
675
679
|
|
|
676
680
|
// Regenerate main.go to include new routes if any (or just entities)
|
|
677
681
|
const timestamp = new Date().toISOString().replace(/[-:T]/g, '').split('.')[0];
|
|
678
|
-
const mainTemplatePath = path.resolve(
|
|
682
|
+
const mainTemplatePath = path.resolve(__dirname, 'templates/go/main.go.hbs');
|
|
679
683
|
if (await fs.pathExists(mainTemplatePath)) {
|
|
680
684
|
const mainTemplate = Handlebars.compile(await fs.readFile(mainTemplatePath, 'utf8'));
|
|
681
685
|
await fs.writeFile(path.join(absoluteOutputDir, 'main.go'), mainTemplate({ app_name: config.name, entities, openEntities, timestamp }));
|