@monodog/utils 1.0.1 → 1.0.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/helpers.js CHANGED
@@ -5,93 +5,90 @@ import path from 'path';
5
5
  * Scans the monorepo and returns information about all packages
6
6
  */
7
7
  function scanMonorepo(rootDir) {
8
- const packages = [];
9
- console.log('rootDir', rootDir);
10
- // Scan packages directory
11
- const packagesDir = path.join(rootDir, 'packages');
12
- if (fs.existsSync(packagesDir)) {
13
- const packageDirs = fs
14
- .readdirSync(packagesDir, { withFileTypes: true })
15
- .filter(dirent => dirent.isDirectory())
16
- .map(dirent => dirent.name);
17
- for (const packageName of packageDirs) {
18
- const packagePath = path.join(packagesDir, packageName);
19
- const packageInfo = parsePackageInfo(packagePath, packageName);
20
- if (packageInfo) {
21
- packages.push(packageInfo);
22
- }
23
- }
8
+ const packages = [];
9
+ console.log('rootDir', rootDir);
10
+ // Scan packages directory
11
+ const packagesDir = path.join(rootDir, 'packages');
12
+ if (fs.existsSync(packagesDir)) {
13
+ const packageDirs = fs
14
+ .readdirSync(packagesDir, { withFileTypes: true })
15
+ .filter(dirent => dirent.isDirectory())
16
+ .map(dirent => dirent.name);
17
+ for (const packageName of packageDirs) {
18
+ const packagePath = path.join(packagesDir, packageName);
19
+ const packageInfo = parsePackageInfo(packagePath, packageName);
20
+ if (packageInfo) {
21
+ packages.push(packageInfo);
22
+ }
24
23
  }
25
- // Scan apps directory
26
- const appsDir = path.join(rootDir, 'apps');
27
- if (fs.existsSync(appsDir)) {
28
- const appDirs = fs
29
- .readdirSync(appsDir, { withFileTypes: true })
30
- .filter(dirent => dirent.isDirectory())
31
- .map(dirent => dirent.name);
32
- for (const appName of appDirs) {
33
- const appPath = path.join(appsDir, appName);
34
- const appInfo = parsePackageInfo(appPath, appName, 'app');
35
- if (appInfo) {
36
- packages.push(appInfo);
37
- }
38
- }
24
+ }
25
+ // Scan apps directory
26
+ const appsDir = path.join(rootDir, 'apps');
27
+ if (fs.existsSync(appsDir)) {
28
+ const appDirs = fs
29
+ .readdirSync(appsDir, { withFileTypes: true })
30
+ .filter(dirent => dirent.isDirectory())
31
+ .map(dirent => dirent.name);
32
+ for (const appName of appDirs) {
33
+ const appPath = path.join(appsDir, appName);
34
+ const appInfo = parsePackageInfo(appPath, appName, 'app');
35
+ if (appInfo) {
36
+ packages.push(appInfo);
37
+ }
39
38
  }
40
- // Scan libs directory
41
- const libsDir = path.join(rootDir, 'libs');
42
- if (fs.existsSync(libsDir)) {
43
- const libDirs = fs
44
- .readdirSync(libsDir, { withFileTypes: true })
45
- .filter(dirent => dirent.isDirectory())
46
- .map(dirent => dirent.name);
47
- for (const libName of libDirs) {
48
- const libPath = path.join(libsDir, libName);
49
- const libInfo = parsePackageInfo(libPath, libName, 'lib');
50
- if (libInfo) {
51
- packages.push(libInfo);
52
- }
53
- }
39
+ }
40
+ // Scan libs directory
41
+ const libsDir = path.join(rootDir, 'libs');
42
+ if (fs.existsSync(libsDir)) {
43
+ const libDirs = fs
44
+ .readdirSync(libsDir, { withFileTypes: true })
45
+ .filter(dirent => dirent.isDirectory())
46
+ .map(dirent => dirent.name);
47
+ for (const libName of libDirs) {
48
+ const libPath = path.join(libsDir, libName);
49
+ const libInfo = parsePackageInfo(libPath, libName, 'lib');
50
+ if (libInfo) {
51
+ packages.push(libInfo);
52
+ }
54
53
  }
55
- return packages;
54
+ }
55
+ return packages;
56
56
  }
57
57
  /*** Parses package.json and determines package type */
58
58
  function parsePackageInfo(packagePath, packageName, forcedType) {
59
- const packageJsonPath = path.join(packagePath, 'package.json');
60
- if (!fs.existsSync(packageJsonPath)) {
61
- return null;
62
- }
63
- try {
64
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
65
- // Determine package type
66
- let packageType = 'lib';
67
- if (forcedType) {
68
- packageType = forcedType;
69
- }
70
- else if (packageJson.scripts && packageJson.scripts.start) {
71
- packageType = 'app';
72
- }
73
- else if (packageJson.keywords && packageJson.keywords.includes('tool')) {
74
- packageType = 'tool';
75
- }
76
- return {
77
- name: packageJson.name || packageName,
78
- version: packageJson.version || '0.0.0',
79
- type: packageType,
80
- path: packagePath,
81
- dependencies: packageJson.dependencies || {},
82
- devDependencies: packageJson.devDependencies || {},
83
- peerDependencies: packageJson.peerDependencies || {},
84
- scripts: packageJson.scripts || {},
85
- maintainers: packageJson.maintainers || [],
86
- description: packageJson.description,
87
- license: packageJson.license,
88
- repository: packageJson.repository || {},
89
- };
90
- }
91
- catch (error) {
92
- console.error(`Error parsing package.json for ${packageName}:`, error);
93
- return null;
59
+ const packageJsonPath = path.join(packagePath, 'package.json');
60
+ if (!fs.existsSync(packageJsonPath)) {
61
+ return null;
62
+ }
63
+ try {
64
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
65
+ // Determine package type
66
+ let packageType = 'lib';
67
+ if (forcedType) {
68
+ packageType = forcedType;
69
+ } else if (packageJson.scripts && packageJson.scripts.start) {
70
+ packageType = 'app';
71
+ } else if (packageJson.keywords && packageJson.keywords.includes('tool')) {
72
+ packageType = 'tool';
94
73
  }
74
+ return {
75
+ name: packageJson.name || packageName,
76
+ version: packageJson.version || '0.0.0',
77
+ type: packageType,
78
+ path: packagePath,
79
+ dependencies: packageJson.dependencies || {},
80
+ devDependencies: packageJson.devDependencies || {},
81
+ peerDependencies: packageJson.peerDependencies || {},
82
+ scripts: packageJson.scripts || {},
83
+ maintainers: packageJson.maintainers || [],
84
+ description: packageJson.description,
85
+ license: packageJson.license,
86
+ repository: packageJson.repository || {},
87
+ };
88
+ } catch (error) {
89
+ console.error(`Error parsing package.json for ${packageName}:`, error);
90
+ return null;
91
+ }
95
92
  }
96
93
  /**
97
94
  * Analyzes dependencies and determines their status
@@ -110,161 +107,166 @@ function parsePackageInfo(packagePath, packageName, forcedType) {
110
107
  /**
111
108
  * Calculates package health score based on various metrics
112
109
  */
113
- function calculatePackageHealth(buildStatus, testCoverage, lintStatus, securityAudit) {
114
- let score = 0;
115
- // Build status (30 points)
116
- switch (buildStatus) {
117
- case 'success':
118
- score += 30;
119
- break;
120
- case 'running':
121
- score += 15;
122
- break;
123
- case 'failed':
124
- score += 0;
125
- break;
126
- default:
127
- score += 10;
128
- }
129
- // Test coverage (25 points)
130
- score += Math.min(25, (testCoverage / 100) * 25);
131
- // Lint status (25 points)
132
- switch (lintStatus) {
133
- case 'pass':
134
- score += 25;
135
- break;
136
- case 'fail':
137
- score += 0;
138
- break;
139
- default:
140
- score += 10;
141
- }
142
- // Security audit (20 points)
143
- switch (securityAudit) {
144
- case 'pass':
145
- score += 20;
146
- break;
147
- case 'fail':
148
- score += 0;
149
- break;
150
- default:
151
- score += 10;
152
- }
153
- return {
154
- buildStatus,
155
- testCoverage,
156
- lintStatus,
157
- securityAudit,
158
- overallScore: Math.round(score),
159
- };
110
+ function calculatePackageHealth(
111
+ buildStatus,
112
+ testCoverage,
113
+ lintStatus,
114
+ securityAudit
115
+ ) {
116
+ let score = 0;
117
+ // Build status (30 points)
118
+ switch (buildStatus) {
119
+ case 'success':
120
+ score += 30;
121
+ break;
122
+ case 'running':
123
+ score += 15;
124
+ break;
125
+ case 'failed':
126
+ score += 0;
127
+ break;
128
+ default:
129
+ score += 10;
130
+ }
131
+ // Test coverage (25 points)
132
+ score += Math.min(25, (testCoverage / 100) * 25);
133
+ // Lint status (25 points)
134
+ switch (lintStatus) {
135
+ case 'pass':
136
+ score += 25;
137
+ break;
138
+ case 'fail':
139
+ score += 0;
140
+ break;
141
+ default:
142
+ score += 10;
143
+ }
144
+ // Security audit (20 points)
145
+ switch (securityAudit) {
146
+ case 'pass':
147
+ score += 20;
148
+ break;
149
+ case 'fail':
150
+ score += 0;
151
+ break;
152
+ default:
153
+ score += 10;
154
+ }
155
+ return {
156
+ buildStatus,
157
+ testCoverage,
158
+ lintStatus,
159
+ securityAudit,
160
+ overallScore: Math.round(score),
161
+ };
160
162
  }
161
163
  /**
162
164
  * Generates comprehensive monorepo statistics
163
165
  */
164
166
  function generateMonorepoStats(packages) {
165
- const stats = {
166
- totalPackages: packages.length,
167
- apps: packages.filter(p => p.type === 'app').length,
168
- libraries: packages.filter(p => p.type === 'lib').length,
169
- tools: packages.filter(p => p.type === 'tool').length,
170
- healthyPackages: 0,
171
- warningPackages: 0,
172
- errorPackages: 0,
173
- outdatedDependencies: 0,
174
- totalDependencies: 0,
175
- };
176
- // Calculate dependency counts
177
- packages.forEach(pkg => {
178
- stats.totalDependencies += Object.keys(pkg.dependencies).length;
179
- stats.totalDependencies += Object.keys(pkg.devDependencies).length;
180
- stats.totalDependencies += Object.keys(pkg.peerDependencies ?? {}).length;
181
- });
182
- return stats;
167
+ const stats = {
168
+ totalPackages: packages.length,
169
+ apps: packages.filter(p => p.type === 'app').length,
170
+ libraries: packages.filter(p => p.type === 'lib').length,
171
+ tools: packages.filter(p => p.type === 'tool').length,
172
+ healthyPackages: 0,
173
+ warningPackages: 0,
174
+ errorPackages: 0,
175
+ outdatedDependencies: 0,
176
+ totalDependencies: 0,
177
+ };
178
+ // Calculate dependency counts
179
+ packages.forEach(pkg => {
180
+ stats.totalDependencies += Object.keys(pkg.dependencies).length;
181
+ stats.totalDependencies += Object.keys(pkg.devDependencies).length;
182
+ stats.totalDependencies += Object.keys(pkg.peerDependencies ?? {}).length;
183
+ });
184
+ return stats;
183
185
  }
184
186
  /**
185
187
  * Finds circular dependencies in the monorepo
186
188
  */
187
189
  function findCircularDependencies(packages) {
188
- const graph = new Map();
189
- const visited = new Set();
190
- const recursionStack = new Set();
191
- const circularDeps = [];
192
- // Build dependency graph
193
- packages.forEach(pkg => {
194
- graph.set(pkg.name, Object.keys(pkg.dependencies));
195
- });
196
- function dfs(node, path) {
197
- if (recursionStack.has(node)) {
198
- const cycleStart = path.indexOf(node);
199
- circularDeps.push(path.slice(cycleStart));
200
- return;
201
- }
202
- if (visited.has(node)) {
203
- return;
204
- }
205
- visited.add(node);
206
- recursionStack.add(node);
207
- path.push(node);
208
- const dependencies = graph.get(node) || [];
209
- for (const dep of dependencies) {
210
- if (graph.has(dep)) {
211
- dfs(dep, [...path]);
212
- }
213
- }
214
- recursionStack.delete(node);
190
+ const graph = new Map();
191
+ const visited = new Set();
192
+ const recursionStack = new Set();
193
+ const circularDeps = [];
194
+ // Build dependency graph
195
+ packages.forEach(pkg => {
196
+ graph.set(pkg.name, Object.keys(pkg.dependencies));
197
+ });
198
+ function dfs(node, path) {
199
+ if (recursionStack.has(node)) {
200
+ const cycleStart = path.indexOf(node);
201
+ circularDeps.push(path.slice(cycleStart));
202
+ return;
215
203
  }
216
- for (const node of graph.keys()) {
217
- if (!visited.has(node)) {
218
- dfs(node, []);
219
- }
204
+ if (visited.has(node)) {
205
+ return;
206
+ }
207
+ visited.add(node);
208
+ recursionStack.add(node);
209
+ path.push(node);
210
+ const dependencies = graph.get(node) || [];
211
+ for (const dep of dependencies) {
212
+ if (graph.has(dep)) {
213
+ dfs(dep, [...path]);
214
+ }
220
215
  }
221
- return circularDeps;
216
+ recursionStack.delete(node);
217
+ }
218
+ for (const node of graph.keys()) {
219
+ if (!visited.has(node)) {
220
+ dfs(node, []);
221
+ }
222
+ }
223
+ return circularDeps;
222
224
  }
223
225
  /**
224
226
  * Generates a dependency graph for visualization
225
227
  */
226
228
  function generateDependencyGraph(packages) {
227
- const nodes = packages.map(pkg => ({
228
- // id: pkg.name,
229
- label: pkg.name,
230
- type: pkg.type,
231
- version: pkg.version,
232
- dependencies: Object.keys(pkg.dependencies).length,
233
- }));
234
- const edges = [];
235
- packages.forEach(pkg => {
236
- Object.keys(pkg.dependencies).forEach(depName => {
237
- // Only include internal dependencies
238
- if (packages.some(p => p.name === depName)) {
239
- edges.push({
240
- from: pkg.name,
241
- to: depName,
242
- type: 'internal',
243
- });
244
- }
229
+ const nodes = packages.map(pkg => ({
230
+ // id: pkg.name,
231
+ label: pkg.name,
232
+ type: pkg.type,
233
+ version: pkg.version,
234
+ dependencies: Object.keys(pkg.dependencies).length,
235
+ }));
236
+ const edges = [];
237
+ packages.forEach(pkg => {
238
+ Object.keys(pkg.dependencies).forEach(depName => {
239
+ // Only include internal dependencies
240
+ if (packages.some(p => p.name === depName)) {
241
+ edges.push({
242
+ from: pkg.name,
243
+ to: depName,
244
+ type: 'internal',
245
245
  });
246
+ }
246
247
  });
247
- return { nodes, edges };
248
+ });
249
+ return { nodes, edges };
248
250
  }
249
251
  /**
250
252
  * Checks if a package has outdated dependencies
251
253
  */
252
254
  function checkOutdatedDependencies(packageInfo) {
253
- const outdated = [];
254
- // This would typically involve checking against npm registry
255
- // For now, we'll simulate with some basic checks
256
- Object.entries(packageInfo.dependencies).forEach(([name, version]) => {
257
- if (version.startsWith('^') || version.startsWith('~')) {
258
- // Could be outdated, would need registry check
259
- outdated.push({
260
- name,
261
- version: version,
262
- status: 'unknown',
263
- type: 'dependency',
264
- });
265
- }
266
- });
267
- return outdated;
255
+ const outdated = [];
256
+ // This would typically involve checking against npm registry
257
+ // For now, we'll simulate with some basic checks
258
+ Object.entries(packageInfo.dependencies).forEach(([name, version]) => {
259
+ if (version.startsWith('^') || version.startsWith('~')) {
260
+ // Could be outdated, would need registry check
261
+ outdated.push({
262
+ name,
263
+ version: version,
264
+ status: 'unknown',
265
+ type: 'dependency',
266
+ });
267
+ }
268
+ });
269
+ return outdated;
268
270
  }
269
271
  /**
270
272
  * Formats version numbers for comparison
@@ -293,41 +295,45 @@ function checkOutdatedDependencies(packageInfo) {
293
295
  * Gets package size information
294
296
  */
295
297
  function getPackageSize(packagePath) {
296
- try {
297
- let totalSize = 0;
298
- let fileCount = 0;
299
- const calculateSize = (dirPath) => {
300
- const items = fs.readdirSync(dirPath, { withFileTypes: true });
301
- for (const item of items) {
302
- const fullPath = path.join(dirPath, item.name);
303
- if (item.isDirectory()) {
304
- // Skip node_modules and other build artifacts
305
- if (!['node_modules', 'dist', 'build', '.git'].includes(item.name)) {
306
- calculateSize(fullPath);
307
- }
308
- }
309
- else {
310
- try {
311
- const stats = fs.statSync(fullPath);
312
- totalSize += stats.size;
313
- fileCount++;
314
- }
315
- catch (error) {
316
- // Skip files we can't read
317
- }
318
- }
319
- }
320
- };
321
- calculateSize(packagePath);
322
- return {
323
- size: totalSize,
324
- files: fileCount,
325
- };
326
- }
327
- catch (error) {
328
- return { size: 0, files: 0 };
329
- }
298
+ try {
299
+ let totalSize = 0;
300
+ let fileCount = 0;
301
+ const calculateSize = dirPath => {
302
+ const items = fs.readdirSync(dirPath, { withFileTypes: true });
303
+ for (const item of items) {
304
+ const fullPath = path.join(dirPath, item.name);
305
+ if (item.isDirectory()) {
306
+ // Skip node_modules and other build artifacts
307
+ if (!['node_modules', 'dist', 'build', '.git'].includes(item.name)) {
308
+ calculateSize(fullPath);
309
+ }
310
+ } else {
311
+ try {
312
+ const stats = fs.statSync(fullPath);
313
+ totalSize += stats.size;
314
+ fileCount++;
315
+ } catch (error) {
316
+ // Skip files we can't read
317
+ }
318
+ }
319
+ }
320
+ };
321
+ calculateSize(packagePath);
322
+ return {
323
+ size: totalSize,
324
+ files: fileCount,
325
+ };
326
+ } catch (error) {
327
+ return { size: 0, files: 0 };
328
+ }
330
329
  }
331
- export { scanMonorepo, generateMonorepoStats, findCircularDependencies, generateDependencyGraph, checkOutdatedDependencies, getPackageSize,
332
- // analyzeDependencies,
333
- calculatePackageHealth, };
330
+ export {
331
+ scanMonorepo,
332
+ generateMonorepoStats,
333
+ findCircularDependencies,
334
+ generateDependencyGraph,
335
+ checkOutdatedDependencies,
336
+ getPackageSize,
337
+ // analyzeDependencies,
338
+ calculatePackageHealth,
339
+ };
package/helpers.ts CHANGED
@@ -420,7 +420,7 @@ function getPackageSize(packagePath: string): {
420
420
  }
421
421
  }
422
422
  }
423
- }
423
+ };
424
424
 
425
425
  calculateSize(packagePath);
426
426
 
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@monodog/utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Shared utility functions for monodog monorepo dashboard",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
8
- "scripts": {
9
- "build": "tsc --build",
10
- "test": "jest",
11
- "clean": "rm -rf dist node_modules/.cache"
12
- },
13
8
  "devDependencies": {
14
9
  "@types/node": "^20.10.0",
15
10
  "typescript": "^5.2.2"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc --build",
14
+ "clean": "rm -rf dist node_modules/.cache"
16
15
  }
17
- }
16
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  // Extends the shared Node configuration for server/utility environments
3
- "extends": "@lakinmindfire/tsconfig/node.json",
3
+ // "extends": "@manojk/tsconfig/node.json",
4
4
 
5
5
  "compilerOptions": {
6
6
  // Output compilation results to the 'dist' directory
@@ -11,7 +11,7 @@
11
11
  "module": "CommonJS",
12
12
  "moduleResolution": "node",
13
13
  "verbatimModuleSyntax": false,
14
- "downlevelIteration": true,
14
+ "downlevelIteration": true
15
15
  },
16
16
 
17
17
  // Include all TypeScript files in the 'src' folder