@kodus/cli 0.0.7 → 0.0.9

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/index.js CHANGED
@@ -6,7 +6,7 @@ import { dirname, join } from 'path';
6
6
  import { setupEnvironment } from './src/commands/install.js';
7
7
 
8
8
  // CLI version
9
- program.version("0.0.5");
9
+ program.version("0.0.9");
10
10
 
11
11
  // Install command
12
12
  program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kodus/cli",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "CLI tool for Kodus installation and management",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -15,7 +15,8 @@
15
15
  "files": [
16
16
  "index.js",
17
17
  "src/**/*.js",
18
- "templates/**/*"
18
+ "templates/**/*",
19
+ "scripts/**/*.sh"
19
20
  ],
20
21
  "scripts": {
21
22
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,77 @@
1
+ #!/bin/bash
2
+ # scripts/setup-db.sh
3
+
4
+ echo "Setting up database..."
5
+
6
+ # Criar arquivo de configuração dentro do container
7
+ docker-compose exec -T kodus-orchestrator bash -c 'cat > /usr/src/app/datasource.js << EOL
8
+ const MainSeeder = require("./dist/config/database/typeorm/seed/main.seeder").default;
9
+ const { DataSource } = require("typeorm");
10
+ module.exports = new DataSource({
11
+ type: "postgres",
12
+ host: process.env.API_PG_DB_HOST,
13
+ port: 5432,
14
+ username: process.env.API_PG_DB_USERNAME,
15
+ password: process.env.API_PG_DB_PASSWORD,
16
+ database: process.env.API_PG_DB_DATABASE,
17
+ ssl: false,
18
+ entities: ["./dist/core/infrastructure/adapters/repositories/typeorm/schema/*.model.js",],
19
+ migrations: ["./dist/config/database/typeorm/migrations/*.js"],
20
+ seeds: [MainSeeder]
21
+ });
22
+ EOL'
23
+
24
+ # Criar arquivo de configuração temporário para o seed
25
+ docker-compose exec -T kodus-orchestrator bash -c 'cat > /usr/src/app/seed-datasource.js << EOL
26
+ const MainSeeder = require("./dist/config/database/typeorm/seed/main.seeder").default;
27
+ const { DataSource } = require("typeorm");
28
+ const dataSourceInstance = new DataSource({
29
+ type: "postgres",
30
+ host: process.env.API_PG_DB_HOST,
31
+ port: 5432,
32
+ username: process.env.API_PG_DB_USERNAME,
33
+ password: process.env.API_PG_DB_PASSWORD,
34
+ database: process.env.API_PG_DB_DATABASE,
35
+ ssl: false,
36
+ entities: ["./dist/core/infrastructure/adapters/repositories/typeorm/schema/*.model.js",],
37
+ seeds: [MainSeeder]
38
+ });
39
+ module.exports = { dataSourceInstance };
40
+ EOL'
41
+
42
+ # Criar extensão vector no banco de dados
43
+ echo "Creating vector extension..."
44
+ docker-compose exec -T kodus-orchestrator bash -c 'cd /usr/src/app && yarn typeorm query "CREATE EXTENSION IF NOT EXISTS vector;" -d datasource.js'
45
+
46
+ # Verificar se a extensão foi criada com sucesso
47
+ echo "Verifying vector extension..."
48
+ docker-compose exec -T kodus-orchestrator bash -c 'cd /usr/src/app && yarn typeorm query "SELECT extname, extversion FROM pg_extension WHERE extname = '\''vector'\'';" -d datasource.js'
49
+
50
+ # Rodar migrations dentro do container
51
+ echo "Running migrations..."
52
+ docker-compose exec -T kodus-orchestrator bash -c 'cd /usr/src/app && yarn typeorm migration:run -d datasource.js'
53
+
54
+ # Rodar seeds dentro do container com o novo arquivo de configuração
55
+ echo "Running seeds..."
56
+ docker-compose exec -T kodus-orchestrator bash -c '
57
+ cd /usr/src/app &&
58
+ export NODE_PATH=/usr/src/app/dist &&
59
+ node -e "
60
+ const { runSeeders } = require('\''typeorm-extension'\'');
61
+ const { dataSourceInstance } = require('\''./seed-datasource.js'\'');
62
+
63
+ async function runSeeds() {
64
+ try {
65
+ await dataSourceInstance.initialize();
66
+ await runSeeders(dataSourceInstance);
67
+ process.exit(0);
68
+ } catch (error) {
69
+ console.error('\''Error running seeds:'\'', error);
70
+ process.exit(1);
71
+ }
72
+ }
73
+
74
+ runSeeds();
75
+ "'
76
+
77
+ echo "Database setup completed!"
@@ -11,6 +11,11 @@ import {
11
11
  copyTemplates,
12
12
  createDockerNetworks,
13
13
  } from "../utils/helpers.js";
14
+ import { fileURLToPath } from 'url';
15
+ import { dirname } from 'path';
16
+
17
+ const __filename = fileURLToPath(import.meta.url);
18
+ const __dirname = dirname(__filename);
14
19
 
15
20
  const maxAttempts = 30; // 5 minutes with 10 second intervals
16
21
 
@@ -260,7 +265,16 @@ export const setupEnvironment = async () => {
260
265
  // Setup database
261
266
  const dbSpinner = ora("Setting up database").start();
262
267
  try {
263
- execSync("./scripts/setup-db.sh", { stdio: "pipe" });
268
+ const moduleRoot = dirname(dirname(__dirname)); // Sobe 2 níveis: commands -> src -> root
269
+ const scriptPath = path.join(moduleRoot, 'scripts', 'setup-db.sh');
270
+
271
+ if (!fs.existsSync(scriptPath)) {
272
+ dbSpinner.fail('setup-db.sh script not found!');
273
+ console.error(chalk.red(`\nScript expected at: ${scriptPath}`));
274
+ process.exit(1);
275
+ }
276
+
277
+ execSync(`sh ${scriptPath}`, { stdio: "pipe" });
264
278
  dbSpinner.succeed("Database setup completed");
265
279
  } catch (error) {
266
280
  dbSpinner.fail("Failed to setup database");
@@ -34,22 +34,6 @@ services:
34
34
  env_file:
35
35
  - .env
36
36
 
37
- rabbitmq:
38
- image: localhost:5000/rabbitmq:prod
39
- container_name: rabbitmq-prod
40
- hostname: rabbitmq
41
- ports:
42
- - "5672:5672"
43
- - "15672:15672"
44
- networks:
45
- - monitoring-network
46
- - shared-network
47
- environment:
48
- - RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbit heartbeat 60
49
- restart: unless-stopped
50
- env_file:
51
- - .env
52
-
53
37
  db_kodus_postgres:
54
38
  image: postgres:latest
55
39
  container_name: db_kodus_postgres