@monodog/backend 1.1.16 → 1.1.18

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @monodog/backend@1.1.16 build /home/manoj/Documents/MonoDog/packages/backend
2
+ > @monodog/backend@1.1.17 build /home/manoj/Documents/MonoDog/packages/backend
3
3
  > rm -rf dist && tsc -p tsconfig.json
4
4
 
package/dist/cli.js CHANGED
@@ -1,13 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- /**
4
- * CLI Entry Point for the Monorepo Analysis Engine.
5
- * * This script is executed when a user runs the `monodog-cli` 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. Run a one-off analysis command. (Future functionality)
10
- */
11
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
4
  if (k2 === undefined) k2 = k;
13
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -42,8 +34,16 @@ var __importStar = (this && this.__importStar) || (function () {
42
34
  };
43
35
  })();
44
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
+ /**
38
+ * CLI Entry Point for the Monorepo Analysis Engine.
39
+ * * This script is executed when a user runs the `monodog-cli` command
40
+ * in their project. It handles command-line arguments to determine
41
+ * whether to:
42
+ * 1. Start the API server for the dashboard.
43
+ * 2. Run a one-off analysis command. (Future functionality)
44
+ */
45
+ const fs = __importStar(require("fs"));
45
46
  const path = __importStar(require("path"));
46
- const index_1 = require("./index"); // Assume index.ts exports this function
47
47
  // --- Argument Parsing ---
48
48
  // 1. Get arguments excluding the node executable and script name
49
49
  const args = process.argv.slice(2);
@@ -90,9 +90,79 @@ if (serve) {
90
90
  console.log(`Starting Monodog API server...`);
91
91
  console.log(`Analyzing monorepo at root: ${rootPath}`);
92
92
  // Start the Express server and begin analysis
93
- (0, index_1.startServer)(rootPath);
93
+ // startServer(rootPath);
94
+ copyPackageToWorkspace(rootPath);
94
95
  }
95
96
  else {
96
97
  // Default mode: print usage or run a default report if no command is specified
97
98
  console.log(`Monodog CLI: No operation specified. Use --serve to start the API or -h for help.`);
98
99
  }
100
+ /**
101
+ * Copies an installed NPM package from node_modules into the local packages/ workspace directory.
102
+ */
103
+ function copyPackageToWorkspace(rootDir) {
104
+ // 1. Get package name from arguments
105
+ // The package name is expected as the first command-line argument (process.argv[2])
106
+ const packageName = process.argv[2];
107
+ if (!packageName) {
108
+ console.error("Error: Please provide the package name as an argument.");
109
+ console.log("Usage: node copy-to-workspace.js <package-name>");
110
+ console.log("Example: node copy-to-workspace.js @monodog/dashboard");
111
+ process.exit(1);
112
+ }
113
+ // const rootDir = process.cwd();
114
+ const sourcePath = path.join(rootDir, 'node_modules', packageName);
115
+ // Convert package name to a valid folder name (e.g., @scope/name -> scope-name)
116
+ // This is optional but makes file paths cleaner.
117
+ const folderName = packageName.replace('@', '').replace('/', '-');
118
+ const destinationPath = path.join(rootDir, 'packages', folderName);
119
+ console.log(`\n--- Monorepo Workspace Conversion ---`);
120
+ console.log(`Target Package: ${packageName}`);
121
+ console.log(`New Workspace: packages/${folderName}`);
122
+ console.log(`-----------------------------------`);
123
+ // 2. Validate Source existence
124
+ if (!fs.existsSync(sourcePath)) {
125
+ console.error(`\n❌ Error: Source package not found at ${sourcePath}.`);
126
+ console.error("Please ensure the package is installed via 'pnpm install <package-name>' first.");
127
+ process.exit(1);
128
+ }
129
+ // 3. Validate Destination existence (prevent accidental overwrite)
130
+ if (fs.existsSync(destinationPath)) {
131
+ console.error(`\n❌ Error: Destination directory already exists at ${destinationPath}.`);
132
+ console.error("Please manually remove it or rename it before running the script.");
133
+ process.exit(1);
134
+ }
135
+ // Ensure the 'packages' directory exists
136
+ const packagesDir = path.join(rootDir, 'packages');
137
+ if (!fs.existsSync(packagesDir)) {
138
+ fs.mkdirSync(packagesDir, { recursive: true });
139
+ console.log(`Created packages directory: ${packagesDir}`);
140
+ }
141
+ // 4. Perform the copy operation
142
+ try {
143
+ console.log(`\nCopying files from ${sourcePath} to ${destinationPath}...`);
144
+ // fs.cpSync provides cross-platform recursive copying (Node 16.7+)
145
+ fs.cpSync(sourcePath, destinationPath, {
146
+ recursive: true,
147
+ dereference: true,
148
+ // Filter out node_modules inside the package itself to avoid deep recursion
149
+ filter: (src) => !src.includes('node_modules')
150
+ });
151
+ console.log(`\n✅ Success! Contents of '${packageName}' copied to '${destinationPath}'`);
152
+ // Post-copy instructions
153
+ console.log("\n*** IMPORTANT NEXT STEPS (MANDATORY) ***");
154
+ console.log("1. Add the new workspace path to your root 'package.json':");
155
+ console.log(` - Add "packages/${folderName}" to the 'workspaces' array.`);
156
+ console.log("2. Force pnpm to use the local workspace via 'overrides':");
157
+ console.log(" - Add the following to your root package.json:");
158
+ console.log(` "pnpm": { "overrides": { "${packageName}": "file:./packages/${folderName}" } }`);
159
+ console.log("3. Run 'pnpm install' in the root to link the new workspace.");
160
+ console.log("\n--- DEVELOPMENT WARNING ---");
161
+ console.log("Remember: This copy contains the **compiled output**, not usually the full source code (e.g., missing original TypeScript/Sass/tests). To properly develop this workspace, you may need to replace the contents with the package's original source repository.");
162
+ }
163
+ catch (err) {
164
+ const message = err instanceof Error ? err.message : String(err);
165
+ console.error(`\n❌ Failed to copy files: ${message}`);
166
+ process.exit(1);
167
+ }
168
+ }
package/dist/index.js CHANGED
@@ -1126,6 +1126,16 @@ function startServer(rootPath) {
1126
1126
  process.exit(1);
1127
1127
  }
1128
1128
  });
1129
+ // const appD = express();
1130
+ // // Serve static files from the 'dist' directory
1131
+ // appD.use(express.static(rootPath + '/apps/dashboard/dist'));
1132
+ // // For any other routes, serve the index.html
1133
+ // appD.get('*', (req, res) => {
1134
+ // res.sendFile(path.join(rootPath, '/apps/dashboard/dist', 'index.html'));
1135
+ // });
1136
+ // appD.listen(3000, () => {
1137
+ // console.log(`dashboard Server listening at http://localhost:${3000}`);
1138
+ // });
1129
1139
  // export default app;
1130
1140
  // const overallScore =
1131
1141
  // healthMetrics.reduce((sum, h) => sum + h.health!.overallScore, 0) /
@@ -1,65 +1,96 @@
1
1
  "use strict";
2
- // This script runs automatically after 'pnpm install' to ensure the necessary
3
- // workspace directories are set up for the customer.
4
- var __importDefault = (this && this.__importDefault) || function (mod) {
5
- return (mod && mod.__esModule) ? mod : { "default": mod };
6
- };
2
+ // src/setup-workspace.ts
3
+ // Converts the original script to TypeScript.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
7
37
  Object.defineProperty(exports, "__esModule", { value: true });
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const packagesToCreate = ['backend', 'frontend'];
11
- /**
12
- * Creates a minimal package.json and index.js for a new workspace.
13
- * @param workspaceName - The name of the workspace (e.g., 'backend').
14
- */
15
- function createMinimalWorkspace(workspaceName) {
16
- const packageDir = path_1.default.join(process.cwd(), 'packages', workspaceName);
17
- const packageJsonPath = path_1.default.join(packageDir, 'package.json');
18
- const indexJsPath = path_1.default.join(packageDir, 'index.js');
19
- // 1. Create the directory structure
20
- if (!fs_1.default.existsSync(packageDir)) {
21
- console.log(`\n✅ Creating essential workspace directory: packages/${workspaceName}`);
22
- fs_1.default.mkdirSync(packageDir, { recursive: true });
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ function copyPackageToWorkspace() {
41
+ const packageName = process.argv[2];
42
+ if (!packageName) {
43
+ console.error('Error: Please provide the package name as an argument.');
44
+ console.log('Usage: ts-node src/setup-workspace.ts <package-name>');
45
+ console.log('Example: ts-node src/setup-workspace.ts @monodog/dashboard');
46
+ process.exit(1);
23
47
  }
24
- else {
25
- // If it exists, we assume the customer has already populated it.
26
- return;
48
+ const rootDir = process.cwd();
49
+ const sourcePath = path.join(rootDir, 'node_modules', packageName);
50
+ const folderName = packageName.replace('@', '').replace('/', '-');
51
+ const destinationPath = path.join(rootDir, 'packages', folderName);
52
+ console.log('\n--- Monorepo Workspace Conversion ---');
53
+ console.log(`Target Package: ${packageName}`);
54
+ console.log(`New Workspace: packages/${folderName}`);
55
+ console.log('-----------------------------------');
56
+ if (!fs.existsSync(sourcePath)) {
57
+ console.error(`\n❌ Error: Source package not found at ${sourcePath}.`);
58
+ console.error("Please ensure the package is installed via 'pnpm install <package-name>' first.");
59
+ process.exit(1);
27
60
  }
28
- // 2. Define package.json content
29
- const packageJsonContent = JSON.stringify({
30
- name: workspaceName,
31
- version: '1.0.0',
32
- description: `Source code for the ${workspaceName} service.`,
33
- scripts: {
34
- // Placeholder scripts for the customer to use
35
- start: `node index.js`,
36
- dev: `echo "Starting ${workspaceName}..." && node index.js`,
37
- },
38
- // We can pre-add common dev dependencies here if necessary
39
- devDependencies: {
40
- // Example:
41
- // typescript: '^5.0.0',
42
- },
43
- }, null, 2);
44
- // 3. Write package.json
45
- console.log(`📝 Writing minimal package.json for ${workspaceName}...`);
46
- fs_1.default.writeFileSync(packageJsonPath, packageJsonContent, { encoding: 'utf8' });
47
- // 4. Write a placeholder file
48
- const indexJsContent = `console.log('Hello from the packages/${workspaceName} workspace!');`;
49
- console.log('📄 Writing placeholder index.js...');
50
- fs_1.default.writeFileSync(indexJsPath, indexJsContent, { encoding: 'utf8' });
51
- }
52
- function setupTemplate() {
53
- console.log('\n--- Template Initializer (Running via postinstall) ---');
54
- // 1. Ensure the packages directory exists
55
- const packagesRoot = path_1.default.join(process.cwd(), 'packages');
56
- if (!fs_1.default.existsSync(packagesRoot)) {
57
- fs_1.default.mkdirSync(packagesRoot, { recursive: true });
61
+ if (fs.existsSync(destinationPath)) {
62
+ console.error(`\n❌ Error: Destination directory already exists at ${destinationPath}.`);
63
+ console.error('Please manually remove it or rename it before running the script.');
64
+ process.exit(1);
65
+ }
66
+ const packagesDir = path.join(rootDir, 'packages');
67
+ if (!fs.existsSync(packagesDir)) {
68
+ fs.mkdirSync(packagesDir, { recursive: true });
69
+ console.log(`Created packages directory: ${packagesDir}`);
70
+ }
71
+ try {
72
+ console.log(`\nCopying files from ${sourcePath} to ${destinationPath}...`);
73
+ fs.cpSync(sourcePath, destinationPath, {
74
+ recursive: true,
75
+ dereference: true,
76
+ // explicit typing for the filter parameter
77
+ filter: (src) => !src.includes('node_modules'),
78
+ });
79
+ console.log(`\n✅ Success! Contents of '${packageName}' copied to '${destinationPath}'`);
80
+ console.log('\n*** IMPORTANT NEXT STEPS (MANDATORY) ***');
81
+ console.log("1. Add the new workspace path to your root 'package.json':");
82
+ console.log(` - Add "packages/${folderName}" to the 'workspaces' array.`);
83
+ console.log("2. Force pnpm to use the local workspace via 'overrides':");
84
+ console.log(' - Add the following to your root package.json:');
85
+ console.log(` "pnpm": { "overrides": { "${packageName}": "file:./packages/${folderName}" } }`);
86
+ console.log("3. Run 'pnpm install' in the root to link the new workspace.");
87
+ console.log('\n--- DEVELOPMENT WARNING ---');
88
+ console.log('Remember: This copy contains the **compiled output**, not usually the full source code (e.g., missing original TypeScript/Sass/tests). To properly develop this workspace, you may need to replace the contents with the package\'s original source repository.');
89
+ }
90
+ catch (err) {
91
+ const message = err instanceof Error ? err.message : String(err);
92
+ console.error(`\n❌ Failed to copy files: ${message}`);
93
+ process.exit(1);
58
94
  }
59
- // 2. Create default workspaces
60
- packagesToCreate.forEach(createMinimalWorkspace);
61
- console.log('\n✨ Initial template setup complete. Packages are ready to be developed.');
62
- // Note: pnpm install has already run when this script executes,
63
- // so no need to run 'pnpm install' again.
64
95
  }
65
- setupTemplate();
96
+ copyPackageToWorkspace();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monodog/backend",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
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
@@ -8,6 +8,7 @@
8
8
  * 1. Start the API server for the dashboard.
9
9
  * 2. Run a one-off analysis command. (Future functionality)
10
10
  */
11
+ import * as fs from 'fs';
11
12
 
12
13
  import * as path from 'path';
13
14
  import { startServer } from './index'; // Assume index.ts exports this function
@@ -61,8 +62,92 @@ if (serve) {
61
62
  console.log(`Starting Monodog API server...`);
62
63
  console.log(`Analyzing monorepo at root: ${rootPath}`);
63
64
  // Start the Express server and begin analysis
64
- startServer(rootPath);
65
+ // startServer(rootPath);
66
+ copyPackageToWorkspace(rootPath);
65
67
  } else {
66
68
  // Default mode: print usage or run a default report if no command is specified
67
69
  console.log(`Monodog CLI: No operation specified. Use --serve to start the API or -h for help.`);
68
70
  }
71
+
72
+ /**
73
+ * Copies an installed NPM package from node_modules into the local packages/ workspace directory.
74
+ */
75
+ function copyPackageToWorkspace(rootDir: string): void {
76
+ // 1. Get package name from arguments
77
+ // The package name is expected as the first command-line argument (process.argv[2])
78
+ const packageName = process.argv[2];
79
+
80
+ if (!packageName) {
81
+ console.error("Error: Please provide the package name as an argument.");
82
+ console.log("Usage: node copy-to-workspace.js <package-name>");
83
+ console.log("Example: node copy-to-workspace.js @monodog/dashboard");
84
+ process.exit(1);
85
+ }
86
+
87
+ // const rootDir = process.cwd();
88
+ const sourcePath = path.join(rootDir, 'node_modules', packageName);
89
+
90
+ // Convert package name to a valid folder name (e.g., @scope/name -> scope-name)
91
+ // This is optional but makes file paths cleaner.
92
+ const folderName = packageName.replace('@', '').replace('/', '-');
93
+ const destinationPath = path.join(rootDir, 'packages', folderName);
94
+
95
+ console.log(`\n--- Monorepo Workspace Conversion ---`);
96
+ console.log(`Target Package: ${packageName}`);
97
+ console.log(`New Workspace: packages/${folderName}`);
98
+ console.log(`-----------------------------------`);
99
+
100
+
101
+ // 2. Validate Source existence
102
+ if (!fs.existsSync(sourcePath)) {
103
+ console.error(`\n❌ Error: Source package not found at ${sourcePath}.`);
104
+ console.error("Please ensure the package is installed via 'pnpm install <package-name>' first.");
105
+ process.exit(1);
106
+ }
107
+
108
+ // 3. Validate Destination existence (prevent accidental overwrite)
109
+ if (fs.existsSync(destinationPath)) {
110
+ console.error(`\n❌ Error: Destination directory already exists at ${destinationPath}.`);
111
+ console.error("Please manually remove it or rename it before running the script.");
112
+ process.exit(1);
113
+ }
114
+
115
+ // Ensure the 'packages' directory exists
116
+ const packagesDir = path.join(rootDir, 'packages');
117
+ if (!fs.existsSync(packagesDir)) {
118
+ fs.mkdirSync(packagesDir, { recursive: true });
119
+ console.log(`Created packages directory: ${packagesDir}`);
120
+ }
121
+
122
+ // 4. Perform the copy operation
123
+ try {
124
+ console.log(`\nCopying files from ${sourcePath} to ${destinationPath}...`);
125
+
126
+ // fs.cpSync provides cross-platform recursive copying (Node 16.7+)
127
+ fs.cpSync(sourcePath, destinationPath, {
128
+ recursive: true,
129
+ dereference: true,
130
+ // Filter out node_modules inside the package itself to avoid deep recursion
131
+ filter: (src) => !src.includes('node_modules')
132
+ });
133
+
134
+ console.log(`\n✅ Success! Contents of '${packageName}' copied to '${destinationPath}'`);
135
+
136
+ // Post-copy instructions
137
+ console.log("\n*** IMPORTANT NEXT STEPS (MANDATORY) ***");
138
+ console.log("1. Add the new workspace path to your root 'package.json':");
139
+ console.log(` - Add "packages/${folderName}" to the 'workspaces' array.`);
140
+ console.log("2. Force pnpm to use the local workspace via 'overrides':");
141
+ console.log(" - Add the following to your root package.json:");
142
+ console.log(` "pnpm": { "overrides": { "${packageName}": "file:./packages/${folderName}" } }`);
143
+ console.log("3. Run 'pnpm install' in the root to link the new workspace.");
144
+ console.log("\n--- DEVELOPMENT WARNING ---");
145
+ console.log("Remember: This copy contains the **compiled output**, not usually the full source code (e.g., missing original TypeScript/Sass/tests). To properly develop this workspace, you may need to replace the contents with the package's original source repository.");
146
+
147
+ } catch (err: unknown) {
148
+ const message = err instanceof Error ? err.message : String(err);
149
+ console.error(`\n❌ Failed to copy files: ${message}`);
150
+ process.exit(1);
151
+ }
152
+ }
153
+
package/src/index.ts CHANGED
@@ -1298,7 +1298,18 @@ app.listen(PORT, () => {
1298
1298
  process.exit(1);
1299
1299
  }
1300
1300
  });
1301
+ // const appD = express();
1302
+ // // Serve static files from the 'dist' directory
1303
+ // appD.use(express.static(rootPath + '/apps/dashboard/dist'));
1301
1304
 
1305
+ // // For any other routes, serve the index.html
1306
+ // appD.get('*', (req, res) => {
1307
+ // res.sendFile(path.join(rootPath, '/apps/dashboard/dist', 'index.html'));
1308
+ // });
1309
+
1310
+ // appD.listen(3000, () => {
1311
+ // console.log(`dashboard Server listening at http://localhost:${3000}`);
1312
+ // });
1302
1313
  // export default app;
1303
1314
 
1304
1315
  // const overallScore =
@@ -1,73 +1,74 @@
1
- // This script runs automatically after 'pnpm install' to ensure the necessary
2
- // workspace directories are set up for the customer.
1
+ // src/setup-workspace.ts
2
+ // Converts the original script to TypeScript.
3
3
 
4
- import fs from 'fs';
5
- import path from 'path';
6
- import { execSync } from 'child_process';
4
+ import * as fs from 'fs';
5
+ import * as path from 'path';
7
6
 
8
- const packagesToCreate: string[] = ['backend', 'frontend'];
7
+ function copyPackageToWorkspace(): void {
8
+ const packageName: string | undefined = process.argv[2];
9
9
 
10
- /**
11
- * Creates a minimal package.json and index.js for a new workspace.
12
- * @param workspaceName - The name of the workspace (e.g., 'backend').
13
- */
14
- function createMinimalWorkspace(workspaceName: string): void {
15
- const packageDir = path.join(process.cwd(), 'packages', workspaceName);
16
- const packageJsonPath = path.join(packageDir, 'package.json');
17
- const indexJsPath = path.join(packageDir, 'index.js');
10
+ if (!packageName) {
11
+ console.error('Error: Please provide the package name as an argument.');
12
+ console.log('Usage: ts-node src/setup-workspace.ts <package-name>');
13
+ console.log('Example: ts-node src/setup-workspace.ts @monodog/dashboard');
14
+ process.exit(1);
15
+ }
18
16
 
19
- // 1. Create the directory structure
20
- if (!fs.existsSync(packageDir)) {
21
- console.log(`\n✅ Creating essential workspace directory: packages/${workspaceName}`);
22
- fs.mkdirSync(packageDir, { recursive: true });
23
- } else {
24
- // If it exists, we assume the customer has already populated it.
25
- return;
26
- }
17
+ const rootDir: string = process.cwd();
18
+ const sourcePath: string = path.join(rootDir, 'node_modules', packageName);
27
19
 
28
- // 2. Define package.json content
29
- const packageJsonContent = JSON.stringify({
30
- name: workspaceName,
31
- version: '1.0.0',
32
- description: `Source code for the ${workspaceName} service.`,
33
- scripts: {
34
- // Placeholder scripts for the customer to use
35
- start: `node index.js`,
36
- dev: `echo "Starting ${workspaceName}..." && node index.js`,
37
- },
38
- // We can pre-add common dev dependencies here if necessary
39
- devDependencies: {
40
- // Example:
41
- // typescript: '^5.0.0',
42
- },
43
- }, null, 2);
20
+ const folderName: string = packageName.replace('@', '').replace('/', '-');
21
+ const destinationPath: string = path.join(rootDir, 'packages', folderName);
44
22
 
45
- // 3. Write package.json
46
- console.log(`📝 Writing minimal package.json for ${workspaceName}...`);
47
- fs.writeFileSync(packageJsonPath, packageJsonContent, { encoding: 'utf8' });
23
+ console.log('\n--- Monorepo Workspace Conversion ---');
24
+ console.log(`Target Package: ${packageName}`);
25
+ console.log(`New Workspace: packages/${folderName}`);
26
+ console.log('-----------------------------------');
48
27
 
49
- // 4. Write a placeholder file
50
- const indexJsContent = `console.log('Hello from the packages/${workspaceName} workspace!');`;
51
- console.log('📄 Writing placeholder index.js...');
52
- fs.writeFileSync(indexJsPath, indexJsContent, { encoding: 'utf8' });
53
- }
28
+ if (!fs.existsSync(sourcePath)) {
29
+ console.error(`\n❌ Error: Source package not found at ${sourcePath}.`);
30
+ console.error("Please ensure the package is installed via 'pnpm install <package-name>' first.");
31
+ process.exit(1);
32
+ }
33
+
34
+ if (fs.existsSync(destinationPath)) {
35
+ console.error(`\n❌ Error: Destination directory already exists at ${destinationPath}.`);
36
+ console.error('Please manually remove it or rename it before running the script.');
37
+ process.exit(1);
38
+ }
54
39
 
55
- function setupTemplate(): void {
56
- console.log('\n--- Template Initializer (Running via postinstall) ---');
40
+ const packagesDir: string = path.join(rootDir, 'packages');
41
+ if (!fs.existsSync(packagesDir)) {
42
+ fs.mkdirSync(packagesDir, { recursive: true });
43
+ console.log(`Created packages directory: ${packagesDir}`);
44
+ }
57
45
 
58
- // 1. Ensure the packages directory exists
59
- const packagesRoot = path.join(process.cwd(), 'packages');
60
- if (!fs.existsSync(packagesRoot)) {
61
- fs.mkdirSync(packagesRoot, { recursive: true });
62
- }
46
+ try {
47
+ console.log(`\nCopying files from ${sourcePath} to ${destinationPath}...`);
63
48
 
64
- // 2. Create default workspaces
65
- packagesToCreate.forEach(createMinimalWorkspace);
49
+ fs.cpSync(sourcePath, destinationPath, {
50
+ recursive: true,
51
+ dereference: true,
52
+ // explicit typing for the filter parameter
53
+ filter: (src: string): boolean => !src.includes('node_modules'),
54
+ });
66
55
 
67
- console.log('\n Initial template setup complete. Packages are ready to be developed.');
56
+ console.log(`\n Success! Contents of '${packageName}' copied to '${destinationPath}'`);
68
57
 
69
- // Note: pnpm install has already run when this script executes,
70
- // so no need to run 'pnpm install' again.
58
+ console.log('\n*** IMPORTANT NEXT STEPS (MANDATORY) ***');
59
+ console.log("1. Add the new workspace path to your root 'package.json':");
60
+ console.log(` - Add "packages/${folderName}" to the 'workspaces' array.`);
61
+ console.log("2. Force pnpm to use the local workspace via 'overrides':");
62
+ console.log(' - Add the following to your root package.json:');
63
+ console.log(` "pnpm": { "overrides": { "${packageName}": "file:./packages/${folderName}" } }`);
64
+ console.log("3. Run 'pnpm install' in the root to link the new workspace.");
65
+ console.log('\n--- DEVELOPMENT WARNING ---');
66
+ console.log('Remember: This copy contains the **compiled output**, not usually the full source code (e.g., missing original TypeScript/Sass/tests). To properly develop this workspace, you may need to replace the contents with the package\'s original source repository.');
67
+ } catch (err: unknown) {
68
+ const message = err instanceof Error ? err.message : String(err);
69
+ console.error(`\n❌ Failed to copy files: ${message}`);
70
+ process.exit(1);
71
+ }
71
72
  }
72
73
 
73
- setupTemplate();
74
+ copyPackageToWorkspace();