@monodog/backend 1.2.1 → 1.2.3
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/dist/cli.js +0 -0
- package/dist/index.js +138 -1
- package/package.json +3 -3
- package/src/index.ts +157 -2
- package/prisma/monolite.db-journal +0 -0
package/dist/cli.js
CHANGED
|
File without changes
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,6 @@ const express_1 = __importDefault(require("express"));
|
|
|
8
8
|
const cors_1 = __importDefault(require("cors"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
// import { glob } from 'glob';
|
|
12
11
|
const body_parser_1 = require("body-parser");
|
|
13
12
|
const monorepo_scanner_1 = require("@monodog/monorepo-scanner");
|
|
14
13
|
const ci_status_1 = require("@monodog/ci-status");
|
|
@@ -1080,6 +1079,144 @@ function startServer(rootPath) {
|
|
|
1080
1079
|
});
|
|
1081
1080
|
}
|
|
1082
1081
|
});
|
|
1082
|
+
// Update package configuration with path from frontend - preserving all fields, no backups
|
|
1083
|
+
app.put('/api/packages/update', async (req, res) => {
|
|
1084
|
+
try {
|
|
1085
|
+
const { packageName, config, packagePath } = req.body;
|
|
1086
|
+
if (!packageName || !config || !packagePath) {
|
|
1087
|
+
return res.status(400).json({
|
|
1088
|
+
success: false,
|
|
1089
|
+
error: 'Package name, configuration, and package path are required',
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
console.log('💾 Updating package configuration for:', packageName);
|
|
1093
|
+
console.log('📁 Package path:', packagePath);
|
|
1094
|
+
// Validate JSON syntax with better error handling
|
|
1095
|
+
let newConfig;
|
|
1096
|
+
try {
|
|
1097
|
+
newConfig = JSON.parse(config);
|
|
1098
|
+
}
|
|
1099
|
+
catch (error) {
|
|
1100
|
+
console.error('JSON parsing error:', error);
|
|
1101
|
+
return res.status(400).json({
|
|
1102
|
+
success: false,
|
|
1103
|
+
error: 'Invalid JSON configuration',
|
|
1104
|
+
message: `JSON parsing error: ${error instanceof Error ? error.message : 'Invalid format'}`,
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
const packageJsonPath = path_1.default.join(packagePath, 'package.json');
|
|
1108
|
+
// Security check: ensure the path is valid
|
|
1109
|
+
if (!fs_1.default.existsSync(packagePath)) {
|
|
1110
|
+
return res.status(404).json({
|
|
1111
|
+
success: false,
|
|
1112
|
+
error: 'Package directory not found',
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
// Check if package.json exists
|
|
1116
|
+
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
1117
|
+
return res.status(404).json({
|
|
1118
|
+
success: false,
|
|
1119
|
+
error: 'package.json not found in the specified directory',
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
// Read the existing package.json to preserve all fields
|
|
1123
|
+
const existingContent = await fs_1.default.promises.readFile(packageJsonPath, 'utf8');
|
|
1124
|
+
let existingConfig;
|
|
1125
|
+
try {
|
|
1126
|
+
existingConfig = JSON.parse(existingContent);
|
|
1127
|
+
}
|
|
1128
|
+
catch (error) {
|
|
1129
|
+
return res.status(500).json({
|
|
1130
|
+
success: false,
|
|
1131
|
+
error: 'Existing package.json contains invalid JSON',
|
|
1132
|
+
message: `Error parsing existing package.json: ${error instanceof Error ? error.message : 'Invalid JSON'}`,
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
// Merge the new configuration with existing configuration
|
|
1136
|
+
const mergedConfig = {
|
|
1137
|
+
...existingConfig,
|
|
1138
|
+
name: newConfig.name || existingConfig.name,
|
|
1139
|
+
version: newConfig.version || existingConfig.version,
|
|
1140
|
+
description: newConfig.description !== undefined
|
|
1141
|
+
? newConfig.description
|
|
1142
|
+
: existingConfig.description,
|
|
1143
|
+
license: newConfig.license !== undefined
|
|
1144
|
+
? newConfig.license
|
|
1145
|
+
: existingConfig.license,
|
|
1146
|
+
repository: newConfig.repository || existingConfig.repository,
|
|
1147
|
+
scripts: newConfig.scripts || existingConfig.scripts,
|
|
1148
|
+
dependencies: newConfig.dependencies || existingConfig.dependencies,
|
|
1149
|
+
devDependencies: newConfig.devDependencies || existingConfig.devDependencies,
|
|
1150
|
+
peerDependencies: newConfig.peerDependencies || existingConfig.peerDependencies,
|
|
1151
|
+
};
|
|
1152
|
+
// Write the merged configuration back
|
|
1153
|
+
const formattedConfig = JSON.stringify(mergedConfig, null, 2);
|
|
1154
|
+
await fs_1.default.promises.writeFile(packageJsonPath, formattedConfig, 'utf8');
|
|
1155
|
+
// Update the package in the database - use correct field names based on your Prisma schema
|
|
1156
|
+
const updateData = {
|
|
1157
|
+
// Use 'lastUpdated' instead of 'updatedAt' based on the error message
|
|
1158
|
+
lastUpdated: new Date(),
|
|
1159
|
+
};
|
|
1160
|
+
// Only update fields that exist in your Prisma schema
|
|
1161
|
+
if (newConfig.version)
|
|
1162
|
+
updateData.version = newConfig.version;
|
|
1163
|
+
if (newConfig.description !== undefined)
|
|
1164
|
+
updateData.description = newConfig.description || '';
|
|
1165
|
+
if (newConfig.license !== undefined)
|
|
1166
|
+
updateData.license = newConfig.license || '';
|
|
1167
|
+
if (newConfig.scripts)
|
|
1168
|
+
updateData.scripts = JSON.stringify(newConfig.scripts);
|
|
1169
|
+
if (newConfig.repository)
|
|
1170
|
+
updateData.repository = JSON.stringify(newConfig.repository);
|
|
1171
|
+
if (newConfig.dependencies)
|
|
1172
|
+
updateData.dependencies = JSON.stringify(newConfig.dependencies);
|
|
1173
|
+
if (newConfig.devDependencies)
|
|
1174
|
+
updateData.devDependencies = JSON.stringify(newConfig.devDependencies);
|
|
1175
|
+
if (newConfig.peerDependencies)
|
|
1176
|
+
updateData.peerDependencies = JSON.stringify(newConfig.peerDependencies);
|
|
1177
|
+
console.log('📝 Updating database with:', updateData);
|
|
1178
|
+
const updatedPackage = await prisma.package.update({
|
|
1179
|
+
where: { name: packageName },
|
|
1180
|
+
data: updateData,
|
|
1181
|
+
});
|
|
1182
|
+
// Transform the response
|
|
1183
|
+
const transformedPackage = {
|
|
1184
|
+
...updatedPackage,
|
|
1185
|
+
maintainers: updatedPackage.maintainers
|
|
1186
|
+
? JSON.parse(updatedPackage.maintainers)
|
|
1187
|
+
: [],
|
|
1188
|
+
scripts: updatedPackage.scripts ? JSON.parse(updatedPackage.scripts) : {},
|
|
1189
|
+
repository: updatedPackage.repository
|
|
1190
|
+
? JSON.parse(updatedPackage.repository)
|
|
1191
|
+
: {},
|
|
1192
|
+
dependencies: updatedPackage.dependencies
|
|
1193
|
+
? JSON.parse(updatedPackage.dependencies)
|
|
1194
|
+
: {},
|
|
1195
|
+
devDependencies: updatedPackage.devDependencies
|
|
1196
|
+
? JSON.parse(updatedPackage.devDependencies)
|
|
1197
|
+
: {},
|
|
1198
|
+
peerDependencies: updatedPackage.peerDependencies
|
|
1199
|
+
? JSON.parse(updatedPackage.peerDependencies)
|
|
1200
|
+
: {},
|
|
1201
|
+
};
|
|
1202
|
+
// Return success response
|
|
1203
|
+
return res.json({
|
|
1204
|
+
success: true,
|
|
1205
|
+
message: 'Package configuration updated successfully',
|
|
1206
|
+
package: transformedPackage,
|
|
1207
|
+
preservedFields: true,
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
catch (error) {
|
|
1211
|
+
console.error('Error updating package configuration:', error);
|
|
1212
|
+
// Ensure we always return JSON, even for errors
|
|
1213
|
+
return res.status(500).json({
|
|
1214
|
+
success: false,
|
|
1215
|
+
error: 'Failed to update package configuration',
|
|
1216
|
+
message: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1083
1220
|
// Error handling middleware
|
|
1084
1221
|
app.use((error, _req, res, _next) => {
|
|
1085
1222
|
console.error('Error:', error);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monodog/backend",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Backend API server for monodog monorepo dashboard",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
8
|
-
"monodog-cli": "
|
|
8
|
+
"monodog-cli": "dist/cli.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@monodog/ci-status": "1.1.1",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"start": "tsx index.ts",
|
|
33
33
|
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
34
34
|
"prestart": "npm run build",
|
|
35
|
-
"
|
|
35
|
+
"cli": "pnpm run build && node dist/cli.js",
|
|
36
36
|
"test": "jest --coverage",
|
|
37
37
|
"clean": "rm -rf dist node_modules/.cache",
|
|
38
38
|
"test:coverage": "jest --coverage",
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import express, { type Request, type Response, type NextFunction } from 'express';
|
|
2
2
|
import cors from 'cors';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import
|
|
5
|
-
// import { glob } from 'glob';
|
|
4
|
+
import fs from 'fs';
|
|
6
5
|
import { json } from 'body-parser';
|
|
7
6
|
import {
|
|
8
7
|
scanner,
|
|
@@ -1244,6 +1243,162 @@ app.put('/api/config/files/:id', async (_req, res) => {
|
|
|
1244
1243
|
}
|
|
1245
1244
|
});
|
|
1246
1245
|
|
|
1246
|
+
// Update package configuration with path from frontend - preserving all fields, no backups
|
|
1247
|
+
app.put('/api/packages/update', async (req, res) => {
|
|
1248
|
+
try {
|
|
1249
|
+
const { packageName, config, packagePath } = req.body;
|
|
1250
|
+
|
|
1251
|
+
if (!packageName || !config || !packagePath) {
|
|
1252
|
+
return res.status(400).json({
|
|
1253
|
+
success: false,
|
|
1254
|
+
error: 'Package name, configuration, and package path are required',
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
console.log('💾 Updating package configuration for:', packageName);
|
|
1259
|
+
console.log('📁 Package path:', packagePath);
|
|
1260
|
+
|
|
1261
|
+
// Validate JSON syntax with better error handling
|
|
1262
|
+
let newConfig;
|
|
1263
|
+
try {
|
|
1264
|
+
newConfig = JSON.parse(config);
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
console.error('JSON parsing error:', error);
|
|
1267
|
+
return res.status(400).json({
|
|
1268
|
+
success: false,
|
|
1269
|
+
error: 'Invalid JSON configuration',
|
|
1270
|
+
message: `JSON parsing error: ${error instanceof Error ? error.message : 'Invalid format'}`,
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
const packageJsonPath = path.join(packagePath, 'package.json');
|
|
1275
|
+
|
|
1276
|
+
// Security check: ensure the path is valid
|
|
1277
|
+
if (!fs.existsSync(packagePath)) {
|
|
1278
|
+
return res.status(404).json({
|
|
1279
|
+
success: false,
|
|
1280
|
+
error: 'Package directory not found',
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// Check if package.json exists
|
|
1285
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
1286
|
+
return res.status(404).json({
|
|
1287
|
+
success: false,
|
|
1288
|
+
error: 'package.json not found in the specified directory',
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// Read the existing package.json to preserve all fields
|
|
1293
|
+
const existingContent = await fs.promises.readFile(packageJsonPath, 'utf8');
|
|
1294
|
+
let existingConfig;
|
|
1295
|
+
try {
|
|
1296
|
+
existingConfig = JSON.parse(existingContent);
|
|
1297
|
+
} catch (error) {
|
|
1298
|
+
return res.status(500).json({
|
|
1299
|
+
success: false,
|
|
1300
|
+
error: 'Existing package.json contains invalid JSON',
|
|
1301
|
+
message: `Error parsing existing package.json: ${error instanceof Error ? error.message : 'Invalid JSON'}`,
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// Merge the new configuration with existing configuration
|
|
1306
|
+
const mergedConfig = {
|
|
1307
|
+
...existingConfig,
|
|
1308
|
+
name: newConfig.name || existingConfig.name,
|
|
1309
|
+
version: newConfig.version || existingConfig.version,
|
|
1310
|
+
description:
|
|
1311
|
+
newConfig.description !== undefined
|
|
1312
|
+
? newConfig.description
|
|
1313
|
+
: existingConfig.description,
|
|
1314
|
+
license:
|
|
1315
|
+
newConfig.license !== undefined
|
|
1316
|
+
? newConfig.license
|
|
1317
|
+
: existingConfig.license,
|
|
1318
|
+
repository: newConfig.repository || existingConfig.repository,
|
|
1319
|
+
scripts: newConfig.scripts || existingConfig.scripts,
|
|
1320
|
+
dependencies: newConfig.dependencies || existingConfig.dependencies,
|
|
1321
|
+
devDependencies:
|
|
1322
|
+
newConfig.devDependencies || existingConfig.devDependencies,
|
|
1323
|
+
peerDependencies:
|
|
1324
|
+
newConfig.peerDependencies || existingConfig.peerDependencies,
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
// Write the merged configuration back
|
|
1328
|
+
const formattedConfig = JSON.stringify(mergedConfig, null, 2);
|
|
1329
|
+
await fs.promises.writeFile(packageJsonPath, formattedConfig, 'utf8');
|
|
1330
|
+
|
|
1331
|
+
// Update the package in the database - use correct field names based on your Prisma schema
|
|
1332
|
+
const updateData: any = {
|
|
1333
|
+
// Use 'lastUpdated' instead of 'updatedAt' based on the error message
|
|
1334
|
+
lastUpdated: new Date(),
|
|
1335
|
+
};
|
|
1336
|
+
|
|
1337
|
+
// Only update fields that exist in your Prisma schema
|
|
1338
|
+
if (newConfig.version) updateData.version = newConfig.version;
|
|
1339
|
+
if (newConfig.description !== undefined)
|
|
1340
|
+
updateData.description = newConfig.description || '';
|
|
1341
|
+
if (newConfig.license !== undefined)
|
|
1342
|
+
updateData.license = newConfig.license || '';
|
|
1343
|
+
if (newConfig.scripts)
|
|
1344
|
+
updateData.scripts = JSON.stringify(newConfig.scripts);
|
|
1345
|
+
if (newConfig.repository)
|
|
1346
|
+
updateData.repository = JSON.stringify(newConfig.repository);
|
|
1347
|
+
if (newConfig.dependencies)
|
|
1348
|
+
updateData.dependencies = JSON.stringify(newConfig.dependencies);
|
|
1349
|
+
if (newConfig.devDependencies)
|
|
1350
|
+
updateData.devDependencies = JSON.stringify(newConfig.devDependencies);
|
|
1351
|
+
if (newConfig.peerDependencies)
|
|
1352
|
+
updateData.peerDependencies = JSON.stringify(newConfig.peerDependencies);
|
|
1353
|
+
|
|
1354
|
+
console.log('📝 Updating database with:', updateData);
|
|
1355
|
+
|
|
1356
|
+
const updatedPackage = await prisma.package.update({
|
|
1357
|
+
where: { name: packageName },
|
|
1358
|
+
data: updateData,
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
// Transform the response
|
|
1362
|
+
const transformedPackage = {
|
|
1363
|
+
...updatedPackage,
|
|
1364
|
+
maintainers: updatedPackage.maintainers
|
|
1365
|
+
? JSON.parse(updatedPackage.maintainers)
|
|
1366
|
+
: [],
|
|
1367
|
+
scripts: updatedPackage.scripts ? JSON.parse(updatedPackage.scripts) : {},
|
|
1368
|
+
repository: updatedPackage.repository
|
|
1369
|
+
? JSON.parse(updatedPackage.repository)
|
|
1370
|
+
: {},
|
|
1371
|
+
dependencies: updatedPackage.dependencies
|
|
1372
|
+
? JSON.parse(updatedPackage.dependencies)
|
|
1373
|
+
: {},
|
|
1374
|
+
devDependencies: updatedPackage.devDependencies
|
|
1375
|
+
? JSON.parse(updatedPackage.devDependencies)
|
|
1376
|
+
: {},
|
|
1377
|
+
peerDependencies: updatedPackage.peerDependencies
|
|
1378
|
+
? JSON.parse(updatedPackage.peerDependencies)
|
|
1379
|
+
: {},
|
|
1380
|
+
};
|
|
1381
|
+
|
|
1382
|
+
// Return success response
|
|
1383
|
+
return res.json({
|
|
1384
|
+
success: true,
|
|
1385
|
+
message: 'Package configuration updated successfully',
|
|
1386
|
+
package: transformedPackage,
|
|
1387
|
+
preservedFields: true,
|
|
1388
|
+
});
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
console.error('Error updating package configuration:', error);
|
|
1391
|
+
|
|
1392
|
+
// Ensure we always return JSON, even for errors
|
|
1393
|
+
return res.status(500).json({
|
|
1394
|
+
success: false,
|
|
1395
|
+
error: 'Failed to update package configuration',
|
|
1396
|
+
message:
|
|
1397
|
+
error instanceof Error ? error.message : 'Unknown error occurred',
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
});
|
|
1401
|
+
|
|
1247
1402
|
// Error handling middleware
|
|
1248
1403
|
app.use(
|
|
1249
1404
|
(
|
|
Binary file
|