mkctx 1.0.1 → 1.0.2

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 (3) hide show
  1. package/cleanup.js +1 -1
  2. package/install.js +67 -16
  3. package/package.json +5 -10
package/cleanup.js CHANGED
@@ -2,7 +2,7 @@ const fs = require("fs");
2
2
  const path = require("path");
3
3
 
4
4
  function cleanup() {
5
- const filesToRemove = ["mkctx", "mkctx.exe"];
5
+ const filesToRemove = ["mkctx", "mkctx.exe", "mkctx.cmd"];
6
6
  let removedCount = 0;
7
7
 
8
8
  filesToRemove.forEach((file) => {
package/install.js CHANGED
@@ -3,16 +3,13 @@ const path = require("path");
3
3
  const { execSync } = require("child_process");
4
4
 
5
5
  function install() {
6
- const binaryName = process.platform === "win32" ? "mkctx.exe" : "mkctx";
7
- const sourceBinary = process.platform === "win32" ? "mkctx.exe" : "mkctx";
6
+ const isWindows = process.platform === "win32";
7
+ const binaryName = isWindows ? "mkctx.exe" : "mkctx";
8
+ const sourceBinary = isWindows ? "mkctx.exe" : "mkctx";
8
9
  const sourcePath = path.join(__dirname, sourceBinary);
9
10
 
10
11
  // Rename the binary if necessary (from mkctx to mkctx.exe on Windows)
11
- if (
12
- process.platform === "win32" &&
13
- fs.existsSync("mkctx") &&
14
- !fs.existsSync("mkctx.exe")
15
- ) {
12
+ if (isWindows && fs.existsSync("mkctx") && !fs.existsSync("mkctx.exe")) {
16
13
  fs.renameSync("mkctx", "mkctx.exe");
17
14
  console.log("✅ Binary renamed for Windows: mkctx -> mkctx.exe");
18
15
  }
@@ -32,23 +29,45 @@ function install() {
32
29
 
33
30
  try {
34
31
  // Method 1: Use npm to get the global bin directory
35
- const npmGlobalBin = execSync("npm bin -g").toString().trim();
32
+ let npmGlobalBin;
33
+ try {
34
+ npmGlobalBin = execSync("npm bin -g").toString().trim();
35
+ } catch (error) {
36
+ // Alternative method to get global bin directory
37
+ npmGlobalBin = execSync("npm root -g").toString().trim();
38
+ npmGlobalBin = path.join(npmGlobalBin, ".bin");
39
+ }
40
+
36
41
  const installPath = path.join(npmGlobalBin, binaryName);
37
42
 
38
43
  console.log(`📦 Installing mkctx at: ${installPath}`);
39
44
 
45
+ // Ensure the directory exists
46
+ if (!fs.existsSync(npmGlobalBin)) {
47
+ fs.mkdirSync(npmGlobalBin, { recursive: true });
48
+ }
49
+
40
50
  // Copy the binary
41
51
  fs.copyFileSync(sourcePath, installPath);
42
52
 
43
53
  // Set execution permissions (Unix only)
44
- if (process.platform !== "win32") {
54
+ if (!isWindows) {
45
55
  fs.chmodSync(installPath, 0o755);
46
56
  }
47
57
 
48
58
  console.log("✅ mkctx installed successfully via npm");
59
+
60
+ // Create a .cmd wrapper for Windows
61
+ if (isWindows) {
62
+ createWindowsWrapper(npmGlobalBin);
63
+ }
64
+
49
65
  return;
50
66
  } catch (error) {
51
- console.log("⚠️ npm method failed, trying alternative method...");
67
+ console.log(
68
+ "⚠️ npm method failed, trying alternative method...",
69
+ error.message
70
+ );
52
71
  }
53
72
 
54
73
  // Alternative method: Search common PATH directories
@@ -63,16 +82,20 @@ function install() {
63
82
  fs.copyFileSync(sourcePath, altInstallPath);
64
83
 
65
84
  // Set execution permissions (Unix only)
66
- if (process.platform !== "win32") {
85
+ if (!isWindows) {
67
86
  fs.chmodSync(altInstallPath, 0o755);
68
87
  }
69
88
 
89
+ // Create Windows wrapper if needed
90
+ if (isWindows) {
91
+ createWindowsWrapper(altPath);
92
+ }
93
+
70
94
  console.log(`✅ mkctx installed at: ${altInstallPath}`);
71
95
  return;
72
96
  }
73
97
  } catch (e) {
74
98
  console.log(` ❌ Installation failed at ${altPath}: ${e.message}`);
75
- // Continue to next path
76
99
  }
77
100
  }
78
101
 
@@ -90,11 +113,21 @@ function install() {
90
113
  pathDirs.forEach((dir) => console.log(" -", dir));
91
114
  }
92
115
 
116
+ function createWindowsWrapper(installDir) {
117
+ const wrapperPath = path.join(installDir, "mkctx.cmd");
118
+ const wrapperContent = `@echo off
119
+ "${path.join(installDir, "mkctx.exe")}" %*
120
+ `;
121
+ fs.writeFileSync(wrapperPath, wrapperContent);
122
+ console.log(`✅ Created Windows wrapper: ${wrapperPath}`);
123
+ }
124
+
93
125
  function getAlternativePaths() {
94
126
  const paths = [];
127
+ const isWindows = process.platform === "win32";
95
128
 
96
- if (process.platform === "win32") {
97
- // Windows
129
+ if (isWindows) {
130
+ // Windows paths
98
131
  if (process.env.APPDATA) {
99
132
  paths.push(path.join(process.env.APPDATA, "npm"));
100
133
  }
@@ -106,11 +139,18 @@ function getAlternativePaths() {
106
139
  if (process.env.ProgramFiles) {
107
140
  paths.push(path.join(process.env.ProgramFiles, "nodejs"));
108
141
  }
109
- // Add common Windows PATH directories
142
+ // Common Node.js installation paths
110
143
  paths.push("C:\\Program Files\\nodejs");
111
144
  paths.push("C:\\Program Files (x86)\\nodejs");
145
+
146
+ // User's local bin
147
+ if (process.env.USERPROFILE) {
148
+ paths.push(
149
+ path.join(process.env.USERPROFILE, "AppData", "Roaming", "npm")
150
+ );
151
+ }
112
152
  } else {
113
- // Unix/Linux/macOS
153
+ // Unix/Linux/macOS paths
114
154
  paths.push("/usr/local/bin");
115
155
  paths.push("/usr/bin");
116
156
  paths.push("/opt/local/bin");
@@ -131,4 +171,15 @@ function getAlternativePaths() {
131
171
  return paths.filter((p) => p !== null && p !== undefined);
132
172
  }
133
173
 
174
+ // Handle uncaught errors
175
+ process.on("uncaughtException", (error) => {
176
+ console.log("❌ Installation failed:", error.message);
177
+ process.exit(1);
178
+ });
179
+
180
+ process.on("unhandledRejection", (reason, promise) => {
181
+ console.log("❌ Unhandled rejection at:", promise, "reason:", reason);
182
+ process.exit(1);
183
+ });
184
+
134
185
  install();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mkctx",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Tool to generate project context in markdown for AI assistants",
5
5
  "main": "main.go",
6
6
  "scripts": {
@@ -18,10 +18,10 @@
18
18
  "development",
19
19
  "tool"
20
20
  ],
21
- "author": "Tu Nombre <tu.email@example.com>",
21
+ "author": "Your Name <your.email@example.com>",
22
22
  "license": "MIT",
23
23
  "bin": {
24
- "mkctx": "./mkctx"
24
+ "mkctx": "./mkctx.exe"
25
25
  },
26
26
  "files": [
27
27
  "main.go",
@@ -31,8 +31,7 @@
31
31
  "README.md"
32
32
  ],
33
33
  "engines": {
34
- "node": ">=14.0.0",
35
- "go": ">=1.16"
34
+ "node": ">=14.0.0"
36
35
  },
37
36
  "os": [
38
37
  "darwin",
@@ -45,10 +44,6 @@
45
44
  ],
46
45
  "repository": {
47
46
  "type": "git",
48
- "url": "https://github.com/David200197/mkctx.git"
49
- },
50
- "homepage": "https://github.com/David200197/mkctx#readme",
51
- "bugs": {
52
- "url": "https://github.com/David200197/mkctx/issues"
47
+ "url": "https://github.com/your-username/mkctx.git"
53
48
  }
54
49
  }