@monodog/backend 1.3.5 → 1.3.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.
package/dist/cli.js CHANGED
@@ -117,12 +117,11 @@ if (serve) {
117
117
  }
118
118
  else {
119
119
  console.log(`\nInitializing Configurations...`);
120
- createConfigFileIfMissing(rootPath ?? process.cwd());
121
120
  copyPackageToWorkspace(rootPath);
122
121
  console.log(`Monodog CLI: No operation specified. Use --serve to start the API or -h for help. Ex: pnpm monodog-cli @monodog/dashboard --serve --root .`);
123
122
  }
124
123
  /**
125
- * Copies an installed NPM package from node_modules into the local packages/ workspace directory.
124
+ * Copies an installed NPM package from node_modules into the local install_path workspace directory.
126
125
  */
127
126
  function copyPackageToWorkspace(rootDir) {
128
127
  // 1. Get package name from arguments
@@ -141,10 +140,10 @@ function copyPackageToWorkspace(rootDir) {
141
140
  // Convert package name to a valid folder name (e.g., @scope/name -> scope-name)
142
141
  // This is optional but makes file paths cleaner.
143
142
  const folderName = packageName.replace('@', '').replace('/', '-');
144
- const destinationPath = path.join(rootDir, 'packages', folderName);
143
+ const destinationPath = path.join(rootDir, appConfig.workspace.install_path, folderName);
145
144
  console.log(`\n--- Monorepo Workspace Conversion ---`);
146
145
  console.log(`Target Package: ${packageName}`);
147
- console.log(`New Workspace: packages/${folderName}`);
146
+ console.log(`New Workspace: ${appConfig.workspace.install_path}/${folderName}`);
148
147
  console.log(`-----------------------------------`);
149
148
  // 2. Validate Source existence
150
149
  if (!fs.existsSync(sourcePath)) {
@@ -158,11 +157,11 @@ function copyPackageToWorkspace(rootDir) {
158
157
  console.error("Please manually remove it or rename it before running the script.");
159
158
  process.exit(1);
160
159
  }
161
- // Ensure the 'packages' directory exists
162
- const packagesDir = path.join(rootDir, 'packages');
160
+ // Ensure the 'install_path' directory exists
161
+ const packagesDir = path.join(rootDir, appConfig.workspace.install_path);
163
162
  if (!fs.existsSync(packagesDir)) {
164
163
  fs.mkdirSync(packagesDir, { recursive: true });
165
- console.log(`Created packages directory: ${packagesDir}`);
164
+ console.log(`Created ${appConfig.workspace.install_path} directory: ${packagesDir}`);
166
165
  }
167
166
  // 4. Perform the copy operation
168
167
  try {
@@ -190,40 +189,3 @@ function copyPackageToWorkspace(rootDir) {
190
189
  process.exit(1);
191
190
  }
192
191
  }
193
- function createConfigFileIfMissing(rootPath) {
194
- // --- CONFIGURATION ---
195
- const configFileName = 'monodog-conf.json';
196
- const configFilePath = path.resolve(rootPath, configFileName);
197
- // The default content for the configuration file
198
- const defaultContent = {
199
- "workspace": {
200
- "root_dir": "./packages/backend"
201
- },
202
- "database": {
203
- "path": "./monodog.db"
204
- },
205
- "server": {
206
- "host": "0.0.0.0",
207
- "port": 4000
208
- }
209
- };
210
- const contentString = JSON.stringify(defaultContent, null, 2);
211
- // ---------------------
212
- console.log(`\n[monodog] Checking for ${configFileName}...`);
213
- if (fs.existsSync(configFilePath)) {
214
- console.log(`[monodog] ${configFileName} already exists. Skipping creation.`);
215
- }
216
- else {
217
- try {
218
- // Write the default content to the file
219
- fs.writeFileSync(configFilePath, contentString, 'utf-8');
220
- console.log(`[monodog] Successfully generated default ${configFileName} in the workspace root.`);
221
- console.log('[monodog] Please review and update settings like "host" and "port".');
222
- }
223
- catch (err) {
224
- const message = err instanceof Error ? err.message : String(err);
225
- console.error(`[monodog Error] Failed to generate ${configFileName}:`, message);
226
- process.exit(1);
227
- }
228
- }
229
- }
@@ -52,12 +52,13 @@ function loadConfig() {
52
52
  // or that we can navigate up to the root from the current file's location.
53
53
  let rootPath = path.resolve(process.cwd()); // Adjust based on your workspace folder depth from root if needed
54
54
  let configPath = path.resolve(rootPath, 'monodog-conf.json');
55
+ createConfigFileIfMissing(rootPath);
55
56
  if (!fs.existsSync(configPath)) {
56
57
  // console.error(`ERRORu: Configuration file not found at ${configPath}`);
57
- rootPath = path.resolve('../../'); //get root config, Adjust based on your workspace folder depth from root if needed
58
- configPath = path.resolve(rootPath, 'monodog-conf.json');
58
+ configPath = path.resolve(path.resolve('../../'), 'monodog-conf.json'); //get root config, Adjust based on your workspace folder depth from root if needed
59
59
  if (!fs.existsSync(configPath)) {
60
60
  console.error(`ERRORp: Configuration file not found at ${configPath}`);
61
+ configPath = path.resolve(rootPath, 'monodog-conf.json');
61
62
  process.exit(1);
62
63
  }
63
64
  }
@@ -77,6 +78,44 @@ function loadConfig() {
77
78
  process.exit(1);
78
79
  }
79
80
  }
81
+ function createConfigFileIfMissing(rootPath) {
82
+ // --- CONFIGURATION ---
83
+ const configFileName = 'monodog-conf.json';
84
+ const configFilePath = path.resolve(rootPath, configFileName);
85
+ // The default content for the configuration file
86
+ const defaultContent = {
87
+ "workspace": {
88
+ "root_dir": "./", // Relative to where the config file is located
89
+ "install_path": "packages" // Where to install monodog packages
90
+ },
91
+ "database": {
92
+ "path": "file:./monodog.db" // SQLite database file path, relative to prisma schema location
93
+ },
94
+ "server": {
95
+ "host": "0.0.0.0", // Default host for the API server
96
+ "port": 4000 // Default port for the API server
97
+ }
98
+ };
99
+ const contentString = JSON.stringify(defaultContent, null, 2);
100
+ // ---------------------
101
+ console.log(`\n[monodog] Checking for ${configFileName}...`);
102
+ if (fs.existsSync(configFilePath)) {
103
+ console.log(`[monodog] ${configFileName} already exists. Skipping creation.`);
104
+ }
105
+ else {
106
+ try {
107
+ // Write the default content to the file
108
+ fs.writeFileSync(configFilePath, contentString, 'utf-8');
109
+ console.log(`[monodog] Successfully generated default ${configFileName} in the workspace root.`);
110
+ console.log('[monodog] Please review and update settings like "host" and "port".');
111
+ }
112
+ catch (err) {
113
+ const message = err instanceof Error ? err.message : String(err);
114
+ console.error(`[monodog Error] Failed to generate ${configFileName}:`, message);
115
+ process.exit(1);
116
+ }
117
+ }
118
+ }
80
119
  // --- Example Usage ---
81
120
  // In your main application file (e.g., packages/backend/src/index.ts):
82
121
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monodog/backend",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "Backend API server for monodog monorepo dashboard",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
package/src/cli.ts CHANGED
@@ -89,15 +89,13 @@ if (serve) {
89
89
  startServer(rootPath, port, host);
90
90
  } else {
91
91
  console.log(`\nInitializing Configurations...`);
92
-
93
- createConfigFileIfMissing(rootPath ?? process.cwd());
94
92
  copyPackageToWorkspace(rootPath);
95
93
 
96
94
  console.log(`Monodog CLI: No operation specified. Use --serve to start the API or -h for help. Ex: pnpm monodog-cli @monodog/dashboard --serve --root .`);
97
95
  }
98
96
 
99
97
  /**
100
- * Copies an installed NPM package from node_modules into the local packages/ workspace directory.
98
+ * Copies an installed NPM package from node_modules into the local install_path workspace directory.
101
99
  */
102
100
  function copyPackageToWorkspace(rootDir: string): void {
103
101
  // 1. Get package name from arguments
@@ -119,11 +117,11 @@ function copyPackageToWorkspace(rootDir: string): void {
119
117
  // Convert package name to a valid folder name (e.g., @scope/name -> scope-name)
120
118
  // This is optional but makes file paths cleaner.
121
119
  const folderName = packageName.replace('@', '').replace('/', '-');
122
- const destinationPath = path.join(rootDir, 'packages', folderName);
120
+ const destinationPath = path.join(rootDir, appConfig.workspace.install_path, folderName);
123
121
 
124
122
  console.log(`\n--- Monorepo Workspace Conversion ---`);
125
123
  console.log(`Target Package: ${packageName}`);
126
- console.log(`New Workspace: packages/${folderName}`);
124
+ console.log(`New Workspace: ${appConfig.workspace.install_path}/${folderName}`);
127
125
  console.log(`-----------------------------------`);
128
126
 
129
127
 
@@ -141,11 +139,11 @@ function copyPackageToWorkspace(rootDir: string): void {
141
139
  process.exit(1);
142
140
  }
143
141
 
144
- // Ensure the 'packages' directory exists
145
- const packagesDir = path.join(rootDir, 'packages');
142
+ // Ensure the 'install_path' directory exists
143
+ const packagesDir = path.join(rootDir, appConfig.workspace.install_path);
146
144
  if (!fs.existsSync(packagesDir)) {
147
145
  fs.mkdirSync(packagesDir, { recursive: true });
148
- console.log(`Created packages directory: ${packagesDir}`);
146
+ console.log(`Created ${appConfig.workspace.install_path} directory: ${packagesDir}`);
149
147
  }
150
148
 
151
149
  // 4. Perform the copy operation
@@ -178,43 +176,4 @@ function copyPackageToWorkspace(rootDir: string): void {
178
176
  }
179
177
  }
180
178
 
181
- function createConfigFileIfMissing(rootPath: string): void {
182
- // --- CONFIGURATION ---
183
- const configFileName = 'monodog-conf.json';
184
- const configFilePath = path.resolve(rootPath, configFileName);
185
-
186
- // The default content for the configuration file
187
- const defaultContent = {
188
- "workspace": {
189
- "root_dir": "./packages/backend"
190
- },
191
- "database": {
192
- "path": "./monodog.db"
193
- },
194
- "server": {
195
- "host": "0.0.0.0",
196
- "port": 4000
197
- }
198
- };
199
-
200
- const contentString = JSON.stringify(defaultContent, null, 2);
201
- // ---------------------
202
-
203
- console.log(`\n[monodog] Checking for ${configFileName}...`);
204
-
205
- if (fs.existsSync(configFilePath)) {
206
- console.log(`[monodog] ${configFileName} already exists. Skipping creation.`);
207
- } else {
208
- try {
209
- // Write the default content to the file
210
- fs.writeFileSync(configFilePath, contentString, 'utf-8');
211
- console.log(`[monodog] Successfully generated default ${configFileName} in the workspace root.`);
212
- console.log('[monodog] Please review and update settings like "host" and "port".');
213
- } catch (err: unknown) {
214
- const message = err instanceof Error ? err.message : String(err);
215
- console.error(`[monodog Error] Failed to generate ${configFileName}:`, message);
216
- process.exit(1);
217
- }
218
- }
219
- }
220
179
 
@@ -5,6 +5,7 @@ import * as path from 'path';
5
5
  interface MonodogConfig {
6
6
  workspace: {
7
7
  root_dir: string;
8
+ install_path: string;
8
9
  };
9
10
  database: {
10
11
  type: 'postgres' | 'mysql' | 'sqlite';
@@ -37,17 +38,17 @@ export function loadConfig(): MonodogConfig {
37
38
  // or that we can navigate up to the root from the current file's location.
38
39
  let rootPath = path.resolve(process.cwd()); // Adjust based on your workspace folder depth from root if needed
39
40
  let configPath = path.resolve(rootPath, 'monodog-conf.json');
41
+ createConfigFileIfMissing(rootPath);
40
42
 
41
- if (!fs.existsSync(configPath)) {
43
+ if (!fs.existsSync(configPath)) {
42
44
  // console.error(`ERRORu: Configuration file not found at ${configPath}`);
43
- rootPath = path.resolve('../../'); //get root config, Adjust based on your workspace folder depth from root if needed
44
- configPath = path.resolve(rootPath, 'monodog-conf.json');
45
-
45
+ configPath = path.resolve(path.resolve('../../'), 'monodog-conf.json'); //get root config, Adjust based on your workspace folder depth from root if needed
46
46
  if (!fs.existsSync(configPath)) {
47
- console.error(`ERRORp: Configuration file not found at ${configPath}`);
48
- process.exit(1);
49
- }
50
- }
47
+ console.error(`ERRORp: Configuration file not found at ${configPath}`);
48
+ configPath = path.resolve(rootPath, 'monodog-conf.json');
49
+ process.exit(1);
50
+ }
51
+ }
51
52
 
52
53
  try {
53
54
  // 2. Read and parse the JSON file
@@ -68,6 +69,48 @@ export function loadConfig(): MonodogConfig {
68
69
  }
69
70
  }
70
71
 
72
+
73
+ function createConfigFileIfMissing(rootPath: string): void {
74
+ // --- CONFIGURATION ---
75
+ const configFileName = 'monodog-conf.json';
76
+ const configFilePath = path.resolve(rootPath, configFileName);
77
+
78
+ // The default content for the configuration file
79
+ const defaultContent = {
80
+ "workspace": {
81
+ "root_dir": "./", // Relative to where the config file is located
82
+ "install_path":"packages" // Where to install monodog packages
83
+ },
84
+ "database": {
85
+ "path": "file:./monodog.db" // SQLite database file path, relative to prisma schema location
86
+ },
87
+ "server": {
88
+ "host": "0.0.0.0", // Default host for the API server
89
+ "port": 4000 // Default port for the API server
90
+ }
91
+ };
92
+
93
+ const contentString = JSON.stringify(defaultContent, null, 2);
94
+ // ---------------------
95
+
96
+ console.log(`\n[monodog] Checking for ${configFileName}...`);
97
+
98
+ if (fs.existsSync(configFilePath)) {
99
+ console.log(`[monodog] ${configFileName} already exists. Skipping creation.`);
100
+ } else {
101
+ try {
102
+ // Write the default content to the file
103
+ fs.writeFileSync(configFilePath, contentString, 'utf-8');
104
+ console.log(`[monodog] Successfully generated default ${configFileName} in the workspace root.`);
105
+ console.log('[monodog] Please review and update settings like "host" and "port".');
106
+ } catch (err: unknown) {
107
+ const message = err instanceof Error ? err.message : String(err);
108
+ console.error(`[monodog Error] Failed to generate ${configFileName}:`, message);
109
+ process.exit(1);
110
+ }
111
+ }
112
+ }
113
+
71
114
  // --- Example Usage ---
72
115
 
73
116
  // In your main application file (e.g., packages/backend/src/index.ts):