go-duck-cli 1.1.30 → 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.
@@ -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 templatesDir = path.resolve(path.dirname(import.meta.url.replace('file://', '')), '../templates/graphql');
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');
@@ -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 __dirname = path.dirname(import.meta.url.replace('file://', ''));
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');
@@ -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 templatePath = path.resolve(path.dirname(import.meta.url.replace('file://', '')), '../templates/go/router.go.hbs');
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(path.dirname(import.meta.url.replace('file://', '')), 'package.json');
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(path.dirname(import.meta.url.replace('file://', '')), 'templates/go/entity.go.hbs');
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(path.dirname(import.meta.url.replace('file://', '')), 'templates/go/controller.go.hbs');
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(path.dirname(import.meta.url.replace('file://', '')), 'templates/go/enum.go.hbs');
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(path.dirname(import.meta.url.replace('file://', '')), 'templates/go/migrator.go.hbs');
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(path.dirname(import.meta.url.replace('file://', '')), 'templates/go/main.go.hbs');
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(path.dirname(import.meta.url.replace('file://', '')), 'templates/go/main.go.hbs');
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 }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "go-duck-cli",
3
- "version": "1.1.30",
3
+ "version": "1.1.31",
4
4
  "description": "The Ultimate Evolutionary Go Microservice Scaffolder.",
5
5
  "main": "index.js",
6
6
  "type": "module",