@manojkmfsi/monodog 1.0.1

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.
Files changed (61) hide show
  1. package/.eslintrc.cjs +15 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/CHANGELOG.md +79 -0
  4. package/LICENCE +21 -0
  5. package/README.md +55 -0
  6. package/dist/config-loader.js +116 -0
  7. package/dist/get-db-url.js +10 -0
  8. package/dist/gitService.js +242 -0
  9. package/dist/index.js +1370 -0
  10. package/dist/serve.js +103 -0
  11. package/dist/setup.js +155 -0
  12. package/dist/utils/ci-status.js +446 -0
  13. package/dist/utils/helpers.js +237 -0
  14. package/dist/utils/monorepo-scanner.js +486 -0
  15. package/dist/utils/utilities.js +414 -0
  16. package/monodog-conf.example.json +16 -0
  17. package/monodog-conf.json +16 -0
  18. package/monodog-dashboard/README.md +58 -0
  19. package/monodog-dashboard/dist/assets/index-2d967652.js +71 -0
  20. package/monodog-dashboard/dist/assets/index-504dc418.css +1 -0
  21. package/monodog-dashboard/dist/index.html +15 -0
  22. package/package.json +50 -0
  23. package/prisma/migrations/20251017041048_init/migration.sql +19 -0
  24. package/prisma/migrations/20251017083007_add_package/migration.sql +21 -0
  25. package/prisma/migrations/20251021083705_alter_package/migration.sql +37 -0
  26. package/prisma/migrations/20251022085155_test/migration.sql +2 -0
  27. package/prisma/migrations/20251022160841_/migration.sql +35 -0
  28. package/prisma/migrations/20251023130158_rename_column_name/migration.sql +34 -0
  29. package/prisma/migrations/20251023174837_/migration.sql +34 -0
  30. package/prisma/migrations/20251023175830_uodate_schema/migration.sql +32 -0
  31. package/prisma/migrations/20251024103700_add_dependency_info/migration.sql +13 -0
  32. package/prisma/migrations/20251025192150_add_dependency_info/migration.sql +19 -0
  33. package/prisma/migrations/20251025192342_add_dependency_info/migration.sql +40 -0
  34. package/prisma/migrations/20251025204613_add_dependency_info/migration.sql +8 -0
  35. package/prisma/migrations/20251026071336_add_dependency_info/migration.sql +25 -0
  36. package/prisma/migrations/20251027062626_add_commit/migration.sql +10 -0
  37. package/prisma/migrations/20251027062748_add_commit/migration.sql +23 -0
  38. package/prisma/migrations/20251027092741_add_commit/migration.sql +17 -0
  39. package/prisma/migrations/20251027112736_add_health_status/migration.sql +16 -0
  40. package/prisma/migrations/20251027140546_init_packages/migration.sql +16 -0
  41. package/prisma/migrations/20251029073436_added_package_heath_key/migration.sql +34 -0
  42. package/prisma/migrations/20251029073830_added_package_health_key/migration.sql +49 -0
  43. package/prisma/migrations/20251111091920_/migration.sql +16 -0
  44. package/prisma/migrations/20251211155036_cascade_on_auto_delete/migration.sql +48 -0
  45. package/prisma/migrations/migration_lock.toml +3 -0
  46. package/prisma/schema.prisma +114 -0
  47. package/release.config.js +41 -0
  48. package/src/config-loader.ts +119 -0
  49. package/src/get-db-url.ts +11 -0
  50. package/src/gitService.ts +277 -0
  51. package/src/index.ts +1554 -0
  52. package/src/serve.ts +87 -0
  53. package/src/setup.ts +164 -0
  54. package/src/types/monorepo-scanner.d.ts +32 -0
  55. package/src/utils/ci-status.ts +639 -0
  56. package/src/utils/helpers.js +203 -0
  57. package/src/utils/helpers.js.map +1 -0
  58. package/src/utils/helpers.ts +238 -0
  59. package/src/utils/monorepo-scanner.ts +599 -0
  60. package/src/utils/utilities.ts +483 -0
  61. package/tsconfig.json +16 -0
package/src/serve.ts ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI Entry Point for serving Monodog.
5
+ * * This script is executed when a user runs the serve command
6
+ * in their project. It handles command-line arguments to determine
7
+ * whether to:
8
+ * 1. Start the API server for the dashboard.
9
+ * 2. Start serving the dashboard frontend.
10
+ */
11
+
12
+ import * as path from 'path';
13
+ import { startServer, serveDashboard } from './index'; // Assume index.ts exports this function
14
+
15
+ import { appConfig } from './config-loader';
16
+ import fs from 'fs';
17
+
18
+ // --- Argument Parsing ---
19
+
20
+ // 1. Get arguments excluding the node executable and script name
21
+ const args = process.argv.slice(2);
22
+
23
+ // Default settings
24
+ const DEFAULT_PORT = 8999;
25
+ const rootPath = findMonorepoRoot();
26
+ const port = appConfig.server.port ?? DEFAULT_PORT; //Default port
27
+ const host = appConfig.server.host ?? 'localhost'; //Default host
28
+
29
+
30
+ // --- Execution Logic ---
31
+
32
+ console.log(`Starting Monodog API server...`);
33
+ console.log(`Analyzing monorepo at root: ${rootPath}`);
34
+ // Start the Express server and begin analysis
35
+ startServer(rootPath, port, host);
36
+ serveDashboard(
37
+ path.join(rootPath),
38
+ appConfig.dashboard.port,
39
+ appConfig.dashboard.host
40
+ );
41
+
42
+ /**
43
+ * Find the monorepo root by looking for package.json with workspaces or pnpm-workspace.yaml
44
+ */
45
+ function findMonorepoRoot(): string {
46
+ let currentDir = __dirname;
47
+
48
+ while (currentDir !== path.parse(currentDir).root) {
49
+ const packageJsonPath = path.join(currentDir, 'package.json');
50
+ const pnpmWorkspacePath = path.join(currentDir, 'pnpm-workspace.yaml');
51
+
52
+ // Check if this directory has package.json with workspaces or pnpm-workspace.yaml
53
+ if (fs.existsSync(packageJsonPath)) {
54
+ try {
55
+ const packageJson = JSON.parse(
56
+ fs.readFileSync(packageJsonPath, 'utf8')
57
+ );
58
+ // If it has workspaces or is the root monorepo package
59
+ if (packageJson.workspaces || fs.existsSync(pnpmWorkspacePath)) {
60
+ console.log('✅ Found monorepo root:', currentDir);
61
+ return currentDir;
62
+ }
63
+ } catch (error) {
64
+ // Continue searching if package.json is invalid
65
+ }
66
+ }
67
+
68
+ // Check if we're at the git root
69
+ const gitPath = path.join(currentDir, '.git');
70
+ if (fs.existsSync(gitPath)) {
71
+ console.log('✅ Found git root (likely monorepo root):', currentDir);
72
+ return currentDir;
73
+ }
74
+
75
+ // Go up one directory
76
+ const parentDir = path.dirname(currentDir);
77
+ if (parentDir === currentDir) break; // Prevent infinite loop
78
+ currentDir = parentDir;
79
+ }
80
+
81
+ // Fallback to process.cwd() if we can't find the root
82
+ console.log(
83
+ '⚠️ Could not find monorepo root, using process.cwd():',
84
+ process.cwd()
85
+ );
86
+ return process.cwd();
87
+ }
package/src/setup.ts ADDED
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI Entry Point for the Setting up workspace.
5
+ * * This script is executed when a user runs the setup command
6
+ * in their project. It handles command-line arguments to determine
7
+ * whether to:
8
+ * 1. Copy monodog to workspace.
9
+ */
10
+ import * as fs from 'fs';
11
+
12
+ import * as path from 'path';
13
+
14
+ import { appConfig } from './config-loader';
15
+
16
+ // --- Argument Parsing ---
17
+
18
+ // 1. Get arguments excluding the node executable and script name
19
+ const args = process.argv.slice(2);
20
+
21
+ // Default settings
22
+ let rootPath = path.resolve(process.cwd()); // Default to the current working directory ?(inside node modules)
23
+ const host = appConfig.server.host ?? 'localhost'; //Default host
24
+
25
+ console.log('rp1', rootPath);
26
+ // Simple argument parsing loop
27
+ for (let i = 0; i < args.length; i++) {
28
+ const arg = args[i];
29
+
30
+ if (arg === '--root') {
31
+ // Look at the next argument for the path
32
+ if (i + 1 < args.length) {
33
+ rootPath = path.resolve(args[i + 1]);
34
+ i++; // Skip the next argument since we've consumed it
35
+ } else {
36
+ console.error('Error: --root requires a path argument.');
37
+ process.exit(1);
38
+ }
39
+ }
40
+ }
41
+ console.log('rp2', rootPath);
42
+
43
+ // --- Execution Logic ---
44
+
45
+ console.log(`\nInitializing Setup...`);
46
+
47
+ copyPackageToWorkspace(rootPath);
48
+ console.log('\n*** Run the server ***');
49
+ console.log('npm --workspace @manojkmfsi/monoapp run serve');
50
+ process.exit(0);
51
+
52
+ /**
53
+ * Copies an installed NPM package from node_modules into the local install_path directory.
54
+ */
55
+ function copyPackageToWorkspace(rootDir: string): void {
56
+ // 1. Get package name from arguments
57
+ // The package name is expected as the first command-line argument (process.argv[2])
58
+ const packageName = process.argv[2];
59
+
60
+ if (!packageName || packageName.startsWith('--')) {
61
+ console.error(
62
+ 'Error: Please provide the package name as an argument if you want to setup dashboard.'
63
+ );
64
+ console.log('Usage: pnpm monodog-cli @monodog/dashboard --serve --root .');
65
+ }
66
+ const sourcePath = path.join(rootDir, 'node_modules', packageName);
67
+
68
+ // Convert package name to a valid folder name (e.g., @scope/name -> scope-name)
69
+ // This is optional but makes file paths cleaner.
70
+ const folderName = packageName.replace('@', '').replace('/', '-');
71
+ const destinationPath = path.join(
72
+ rootDir,
73
+ folderName
74
+ );
75
+
76
+ console.log(`\n--- Monorepo Workspace Conversion ---`);
77
+ console.log(`Target Package: ${packageName}`);
78
+ console.log(
79
+ `Target folder: ${folderName}`
80
+ );
81
+ console.log(`-----------------------------------`);
82
+
83
+ // 2. Validate Source existence
84
+ if (!fs.existsSync(sourcePath)) {
85
+ console.error(`\n❌ Error: Source package not found at ${sourcePath}.`);
86
+ console.error(
87
+ "Please ensure the package is installed via 'pnpm install <package-name>' first."
88
+ );
89
+ process.exit(1);
90
+ }
91
+
92
+ // Check if source path exists and is a directory before copying
93
+ if (!fs.existsSync(sourcePath) || !fs.statSync(sourcePath).isDirectory()) {
94
+ console.error(
95
+ `\n❌ Fatal Error: Source package directory not found or is not a directory.`
96
+ );
97
+ console.error(`Attempted source path: ${sourcePath}`);
98
+ console.error(
99
+ `This likely means the package '${packageName}' was not fully installed or is improperly linked by the package manager.`
100
+ );
101
+ process.exit(1);
102
+ }
103
+
104
+ // 3. Handle Destination existence: Skip if found to acontinue setup
105
+ if (fs.existsSync(destinationPath)) {
106
+ console.log(
107
+ `\n⚠️ Warning: Destination directory already exists at ${destinationPath}.`
108
+ );
109
+ console.log(`\nSkipping Setup.`);
110
+ process.exit(0);
111
+ }
112
+
113
+
114
+
115
+ // 4. Perform the copy operation
116
+ try {
117
+ console.log(`\nCopying files from ${sourcePath} to ${destinationPath}...`);
118
+
119
+ // fs.cpSync provides cross-platform recursive copying (Node 16.7+)
120
+ // Added filter to exclude node_modules, dist, and cache folders from the copy,
121
+ // which prevents recursive errors and corrupted copies.
122
+ // const INCLUDED_ROOT_ITEMS = ['package.json', 'README.md', 'dist', 'monodog-conf.json', 'monodog-dashboard'];
123
+
124
+ fs.cpSync(sourcePath, destinationPath, {
125
+ recursive: true,
126
+ dereference: true,
127
+ // filter: (src: string): boolean => {
128
+ // const relative = path.relative(sourcePath, src);
129
+
130
+ // // 1. Always include the source root itself to initiate the copy
131
+ // if (relative === '') {
132
+ // return true;
133
+ // }
134
+
135
+ // // 2. Get the top-level path segment (e.g., 'dist', 'prisma', 'package.json')
136
+ // // This is the file/directory name immediately under the source path.
137
+ // const topLevelItem = relative.split(path.sep)[0];
138
+
139
+ // // 3. Include if the top-level item is one of the desired items.
140
+ // if (INCLUDED_ROOT_ITEMS.includes(topLevelItem)) {
141
+ // return true;
142
+ // }
143
+
144
+ // // 4. Exclude everything else (like /src, /test, /node_modules, etc.)
145
+ // return false;
146
+ // }
147
+ // filter: (src: string): boolean => {
148
+ // const basename = path.basename(src);
149
+ // return !(['node_modules', '.turbo'].includes(basename));
150
+ // }
151
+
152
+ // Filter out node_modules inside the package itself to avoid deep recursion
153
+ // filter: (src: string): boolean => !src.includes('node_modules'),
154
+ });
155
+
156
+ console.log(
157
+ `\n✅ Success! Contents of '${packageName}' copied to '${destinationPath}'`
158
+ );
159
+ } catch (err: unknown) {
160
+ const message = err instanceof Error ? err.message : String(err);
161
+ console.error(`\n❌ Failed to copy files: ${message}`);
162
+ process.exit(1);
163
+ }
164
+ }
@@ -0,0 +1,32 @@
1
+ // This declaration explicitly tells TypeScript about the specific functions
2
+ // exported by the '@monodog/monorepo-scanner' package, bypassing TS7016 errors.
3
+
4
+ declare module '@monodog/monorepo-scanner' {
5
+ /**
6
+ * Declares the exported function 'funCheckSecurityAudit'.
7
+ * The actual implementation and return type reside in the source package.
8
+ */
9
+ export function funCheckSecurityAudit(options?: any): any;
10
+ export function funCheckTestCoverage(options?: any): any;
11
+ export function funCheckLintStatus(options?: any): any;
12
+ export function funCheckBuildStatus(options?: any): any;
13
+ export function generateReports(options?: any): any;
14
+ export function quickScan(options?: any): any;
15
+
16
+ /**
17
+ * Defines the exported class structure, including the constructor
18
+ * and the methods used in the backend.
19
+ */
20
+ export class MonorepoScanner {
21
+ // Constructor (when called with `new`)
22
+ constructor(options?: any);
23
+
24
+ /** * Resets any internal cache state for the scanner.
25
+ */
26
+ clearCache(): void;
27
+
28
+ /** * Retrieves the processed results from the scan.
29
+ */
30
+ exportResults(result: any, format: 'json' | 'csv' | 'html'): any;
31
+ }
32
+ }