@monodog/backend 1.2.6 → 1.2.7

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.
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCommits = getCommits;
7
+ exports.storePackage = storePackage;
8
+ exports.storeCommits = storeCommits;
9
+ exports.getPackageDependenciesInfo = getPackageDependenciesInfo;
10
+ exports.storeDependencies = storeDependencies;
11
+ const dotenv_1 = __importDefault(require("dotenv"));
12
+ const path_1 = __importDefault(require("path"));
13
+ dotenv_1.default.config({ path: path_1.default.resolve(__dirname, '../.env') });
14
+ const client_1 = require("@prisma/client");
15
+ const config_loader_1 = require("../config-loader");
16
+ const appConfig = (0, config_loader_1.loadConfig)();
17
+ // Default settings
18
+ const DEFAULT_PORT = 4000;
19
+ const port = appConfig.server.port ?? DEFAULT_PORT; //Default port
20
+ const host = appConfig.server.host ?? 'localhost'; //Default host
21
+ const prisma = new client_1.PrismaClient();
22
+ const API_BASE = `http://${host}:${port}/api`;
23
+ async function getCommits(path) {
24
+ const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));
25
+ if (!res.ok)
26
+ throw new Error('Failed to fetch commits');
27
+ return await res.json();
28
+ }
29
+ async function storeCommits(packageName, commits) {
30
+ console.log('💾 Storing commits for:' + packageName);
31
+ // Create or update dependencies
32
+ for (const commit of commits) {
33
+ try {
34
+ await prisma.commit.upsert({
35
+ where: {
36
+ hash: commit.hash,
37
+ },
38
+ update: {
39
+ message: commit.message,
40
+ author: commit.author,
41
+ date: commit.date,
42
+ type: commit.type,
43
+ },
44
+ create: {
45
+ hash: commit.hash,
46
+ message: commit.message,
47
+ author: commit.author,
48
+ date: commit.date,
49
+ type: commit.type,
50
+ packageName: packageName,
51
+ },
52
+ });
53
+ }
54
+ catch (e) {
55
+ if (e instanceof client_1.Prisma.PrismaClientKnownRequestError &&
56
+ e.code === 'P2002') {
57
+ // Handle unique constraint violation (e.g., commit already exists)
58
+ console.warn(`Skipping commit: ${commit.hash} (Depenndency already exists)`);
59
+ }
60
+ else {
61
+ // Handle any other unexpected errors
62
+ console.error(`Failed to store commit: ${commit.hash}`, e);
63
+ }
64
+ }
65
+ }
66
+ }
67
+ /**
68
+ * Store packages in database
69
+ */
70
+ async function storePackage(pkg) {
71
+ try {
72
+ // Create or update package
73
+ await prisma.package.upsert({
74
+ where: { name: pkg.name },
75
+ update: {
76
+ version: pkg.version,
77
+ type: pkg.type,
78
+ path: pkg.path,
79
+ description: pkg.description,
80
+ license: pkg.license,
81
+ repository: JSON.stringify(pkg.repository),
82
+ scripts: JSON.stringify(pkg.scripts),
83
+ lastUpdated: new Date(),
84
+ },
85
+ create: {
86
+ // Timestamps
87
+ createdAt: new Date(),
88
+ lastUpdated: new Date(),
89
+ // Key Metrics and Relationships
90
+ dependencies: JSON.stringify(pkg.dependencies), // The total number of direct dependencies (12 in your example)
91
+ // Manual Serialization Required: Stores a JSON array string of maintainers, e.g., '["team-frontend"]'
92
+ maintainers: pkg.maintainers.join(','),
93
+ // Manual Serialization Required: Stores a JSON array string of tags, e.g., '["core", "ui"]'
94
+ // Manual Serialization Required: Stores the scripts object as a JSON string
95
+ // Example: '{"dev": "vite", "build": "tsc && vite build"}'
96
+ scripts: JSON.stringify(pkg.scripts),
97
+ // Dependency Lists (Manual Serialization Required)
98
+ // Stores a JSON array string of dependencies.
99
+ // dependenciesList: JSON.stringify(pkg.dependenciesList),
100
+ devDependencies: JSON.stringify(pkg.devDependencies),
101
+ peerDependencies: JSON.stringify(pkg.peerDependencies),
102
+ name: pkg.name,
103
+ version: pkg.version,
104
+ type: pkg.type,
105
+ path: pkg.path,
106
+ description: pkg.description ?? '',
107
+ license: pkg.license ?? '',
108
+ repository: JSON.stringify(pkg.repository),
109
+ status: '',
110
+ },
111
+ });
112
+ const commits = await getCommits(pkg.path ?? '');
113
+ if (commits.length) {
114
+ await storeCommits(pkg.name, commits);
115
+ }
116
+ const dependenciesInfo = getPackageDependenciesInfo(pkg);
117
+ if (dependenciesInfo.length) {
118
+ await storeDependencies(pkg.name, dependenciesInfo);
119
+ }
120
+ }
121
+ catch (error) {
122
+ console.warn(`⚠️ Failed to store report for ${pkg.name}:`, error);
123
+ }
124
+ }
125
+ /**
126
+ * Get package dependencies
127
+ */
128
+ function getPackageDependenciesInfo(pkg) {
129
+ const allDeps = [];
130
+ Object.keys(pkg.dependencies || {}).forEach(depName => {
131
+ allDeps.push({
132
+ name: depName,
133
+ version: pkg.dependencies[depName],
134
+ type: 'dependency',
135
+ latest: '',
136
+ outdated: false,
137
+ });
138
+ });
139
+ Object.keys(pkg.devDependencies || {}).forEach(depName => {
140
+ allDeps.push({
141
+ name: depName,
142
+ version: pkg.devDependencies[depName],
143
+ type: 'devDependency',
144
+ latest: '',
145
+ outdated: false,
146
+ });
147
+ });
148
+ Object.keys(pkg.peerDependencies || {}).forEach(depName => {
149
+ allDeps.push({
150
+ name: depName,
151
+ version: pkg.peerDependencies[depName],
152
+ type: 'peerDependency',
153
+ latest: '',
154
+ outdated: false,
155
+ });
156
+ });
157
+ return allDeps;
158
+ }
159
+ /**
160
+ * Store dependencies in database
161
+ */
162
+ async function storeDependencies(packageName, dependencies) {
163
+ console.log('💾 Storing Dependencies for:' + packageName);
164
+ // Create or update dependencies
165
+ for (const dep of dependencies) {
166
+ try {
167
+ await prisma.dependencyInfo.upsert({
168
+ where: {
169
+ name_packageName: {
170
+ // This refers to the composite unique constraint
171
+ name: dep.name,
172
+ packageName,
173
+ },
174
+ },
175
+ update: {
176
+ version: dep.version,
177
+ type: dep.type,
178
+ latest: dep.latest,
179
+ outdated: dep.outdated,
180
+ },
181
+ create: {
182
+ name: dep.name,
183
+ version: dep.version,
184
+ type: dep.type,
185
+ latest: dep.latest,
186
+ outdated: dep.outdated,
187
+ packageName: packageName,
188
+ },
189
+ });
190
+ console.log('💾 Dependencies stored in database:' + dep.name);
191
+ }
192
+ catch (e) {
193
+ if (e instanceof client_1.Prisma.PrismaClientKnownRequestError &&
194
+ e.code === 'P2002') {
195
+ // Handle unique constraint violation (e.g., depedency already exists)
196
+ console.warn(`Skipping dependency: ${dep.name} (Depenndency already exists)`);
197
+ }
198
+ else {
199
+ // Handle any other unexpected errors
200
+ console.error(`Failed to store dependency: ${dep.name}`, e);
201
+ }
202
+ }
203
+ }
204
+ }
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@monodog/backend",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "Backend API server for monodog monorepo dashboard",
5
+ "main": "dist/index.js",
5
6
  "license": "MIT",
6
-
7
+ "bin": {
8
+ "monodog-cli": "dist/cli.js"
9
+ },
7
10
  "scripts": {
8
11
  "dev": "tsx watch src/index.ts",
9
12
  "start": "tsx index.ts",
@@ -11,15 +14,13 @@
11
14
  "build": "rm -rf dist && tsc -p tsconfig.json",
12
15
  "prestart": "npm run build",
13
16
  "cli": "pnpm run build && node dist/cli.js",
14
- "test": "jest --coverage",
15
17
  "clean": "rm -rf dist node_modules/.cache",
16
- "test:coverage": "jest --coverage",
17
18
  "lint": "eslint .",
18
19
  "lint:fix": "eslint . --fix",
19
- "db:url": "npx ts-node get-db-url.ts",
20
- "migrate": "DATABASE_URL=$(npm run db:url --silent 2>/dev/null | tr -d '\\n') npx prisma migrate dev",
21
- "serve": "DATABASE_URL=$(npm run db:url --silent 2>/dev/null | tr -d '\\n') ts-node dist/cli.js --serve "
22
- },
20
+ "db:url": "ts-node src/get-db-url.ts",
21
+ "generate": "DATABASE_URL=$(npm run db:url --silent 2>/dev/null | tr -d '\\n') prisma generate",
22
+ "migrate": "DATABASE_URL=$(npm run db:url --silent 2>/dev/null | tr -d '\\n') prisma migrate dev",
23
+ "serve": "DATABASE_URL=$(npm run db:url --silent 2>/dev/null | tr -d '\\n') node dist/cli.js --serve" },
23
24
  "dependencies": {
24
25
  "@monodog/ci-status": "1.1.1",
25
26
  "@monodog/monorepo-scanner": "1.0.7",
package/src/cli.ts CHANGED
@@ -24,10 +24,12 @@ const args = process.argv.slice(2);
24
24
 
25
25
  // Default settings
26
26
  const DEFAULT_PORT = 4000;
27
- let serve = false;
28
27
  let rootPath = path.resolve(appConfig.workspace.root_dir ?? process.cwd()); // Default to the current working directory
29
28
  let port = appConfig.server.port ?? DEFAULT_PORT; //Default port
30
- let host = appConfig.server.host ?? 'localhost'; //Default port
29
+ const host = appConfig.server.host ?? 'localhost'; //Default host
30
+
31
+ let serve = false;
32
+
31
33
 
32
34
  // Simple argument parsing loop
33
35
  for (let i = 0; i < args.length; i++) {
@@ -8,8 +8,17 @@ import dotenv from 'dotenv';
8
8
  import path from 'path';
9
9
  dotenv.config({ path: path.resolve(__dirname, '../.env') });
10
10
  import { PrismaClient, Prisma, Commit } from '@prisma/client';
11
+ import { loadConfig } from '../config-loader';
12
+
13
+ const appConfig = loadConfig();
14
+
15
+ // Default settings
16
+ const DEFAULT_PORT = 4000;
17
+ const port = appConfig.server.port ?? DEFAULT_PORT; //Default port
18
+ const host = appConfig.server.host ?? 'localhost'; //Default host
19
+
11
20
  const prisma = new PrismaClient();
12
- const API_BASE = `http://localhost:4000/api`;
21
+ const API_BASE = `http://${host}:${port}/api`;
13
22
 
14
23
  async function getCommits(path: string): Promise<Commit[]> {
15
24
  const res = await fetch(API_BASE + `/commits/` + encodeURIComponent(path));