mkctx 1.0.2 → 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/bin/darwin/arm64/mkctx +0 -0
- package/bin/darwin/x64/mkctx +0 -0
- package/bin/linux/arm64/mkctx +0 -0
- package/bin/linux/x64/mkctx +0 -0
- package/bin/win32/arm64/mkctx.exe +0 -0
- package/bin/win32/x64/mkctx.exe +0 -0
- package/build.ps1 +74 -0
- package/build.sh +41 -0
- package/install.js +34 -53
- package/package.json +14 -18
- package/cleanup.js +0 -28
- package/main.go +0 -210
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/build.ps1
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# build.ps1 - Build script for Windows PowerShell
|
|
2
|
+
|
|
3
|
+
Write-Host "Building mkctx for all platforms..." -ForegroundColor Green
|
|
4
|
+
|
|
5
|
+
# Create directory structure
|
|
6
|
+
$platforms = @("win32", "darwin", "linux")
|
|
7
|
+
$archs = @("x64", "arm64")
|
|
8
|
+
|
|
9
|
+
foreach ($platform in $platforms) {
|
|
10
|
+
foreach ($arch in $archs) {
|
|
11
|
+
$dir = "bin/$platform/$arch"
|
|
12
|
+
Write-Host "Creating directory: $dir"
|
|
13
|
+
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Build for each platform
|
|
18
|
+
Write-Host "Building for Windows x64..." -ForegroundColor Yellow
|
|
19
|
+
$env:GOOS = "windows"
|
|
20
|
+
$env:GOARCH = "amd64"
|
|
21
|
+
go build -o bin/win32/x64/mkctx.exe main.go
|
|
22
|
+
if ($LASTEXITCODE -ne 0) {
|
|
23
|
+
Write-Host "Failed to build for Windows x64" -ForegroundColor Red
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Write-Host "Building for Windows ARM64..." -ForegroundColor Yellow
|
|
27
|
+
$env:GOOS = "windows"
|
|
28
|
+
$env:GOARCH = "arm64"
|
|
29
|
+
go build -o bin/win32/arm64/mkctx.exe main.go
|
|
30
|
+
if ($LASTEXITCODE -ne 0) {
|
|
31
|
+
Write-Host "Failed to build for Windows ARM64" -ForegroundColor Red
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Write-Host "Building for macOS x64..." -ForegroundColor Yellow
|
|
35
|
+
$env:GOOS = "darwin"
|
|
36
|
+
$env:GOARCH = "amd64"
|
|
37
|
+
go build -o bin/darwin/x64/mkctx main.go
|
|
38
|
+
if ($LASTEXITCODE -ne 0) {
|
|
39
|
+
Write-Host "Failed to build for macOS x64" -ForegroundColor Red
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Write-Host "Building for macOS ARM64..." -ForegroundColor Yellow
|
|
43
|
+
$env:GOOS = "darwin"
|
|
44
|
+
$env:GOARCH = "arm64"
|
|
45
|
+
go build -o bin/darwin/arm64/mkctx main.go
|
|
46
|
+
if ($LASTEXITCODE -ne 0) {
|
|
47
|
+
Write-Host "Failed to build for macOS ARM64" -ForegroundColor Red
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Write-Host "Building for Linux x64..." -ForegroundColor Yellow
|
|
51
|
+
$env:GOOS = "linux"
|
|
52
|
+
$env:GOARCH = "amd64"
|
|
53
|
+
go build -o bin/linux/x64/mkctx main.go
|
|
54
|
+
if ($LASTEXITCODE -ne 0) {
|
|
55
|
+
Write-Host "Failed to build for Linux x64" -ForegroundColor Red
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Write-Host "Building for Linux ARM64..." -ForegroundColor Yellow
|
|
59
|
+
$env:GOOS = "linux"
|
|
60
|
+
$env:GOARCH = "arm64"
|
|
61
|
+
go build -o bin/linux/arm64/mkctx main.go
|
|
62
|
+
if ($LASTEXITCODE -ne 0) {
|
|
63
|
+
Write-Host "Failed to build for Linux ARM64" -ForegroundColor Red
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Write-Host "Build completed!" -ForegroundColor Green
|
|
67
|
+
|
|
68
|
+
# Verify created files
|
|
69
|
+
Write-Host "Files created:" -ForegroundColor Cyan
|
|
70
|
+
if (Test-Path "bin") {
|
|
71
|
+
Get-ChildItem -Recurse "bin" | ForEach-Object { Write-Host " - $($_.FullName)" }
|
|
72
|
+
} else {
|
|
73
|
+
Write-Host " No bin directory found" -ForegroundColor Red
|
|
74
|
+
}
|
package/build.sh
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# build.sh - Script de compilación para Linux/macOS
|
|
3
|
+
|
|
4
|
+
echo "🔨 Building mkctx for all platforms..."
|
|
5
|
+
|
|
6
|
+
# Crear estructura de directorios
|
|
7
|
+
platforms=("win32" "darwin" "linux")
|
|
8
|
+
archs=("x64" "arm64")
|
|
9
|
+
|
|
10
|
+
for platform in "${platforms[@]}"; do
|
|
11
|
+
for arch in "${archs[@]}"; do
|
|
12
|
+
mkdir -p "bin/$platform/$arch"
|
|
13
|
+
done
|
|
14
|
+
done
|
|
15
|
+
|
|
16
|
+
# Compilar para cada plataforma
|
|
17
|
+
echo "Building for Windows x64..."
|
|
18
|
+
GOOS=windows GOARCH=amd64 go build -o bin/win32/x64/mkctx.exe main.go
|
|
19
|
+
|
|
20
|
+
echo "Building for Windows ARM64..."
|
|
21
|
+
GOOS=windows GOARCH=arm64 go build -o bin/win32/arm64/mkctx.exe main.go
|
|
22
|
+
|
|
23
|
+
echo "Building for macOS x64..."
|
|
24
|
+
GOOS=darwin GOARCH=amd64 go build -o bin/darwin/x64/mkctx main.go
|
|
25
|
+
|
|
26
|
+
echo "Building for macOS ARM64..."
|
|
27
|
+
GOOS=darwin GOARCH=arm64 go build -o bin/darwin/arm64/mkctx main.go
|
|
28
|
+
|
|
29
|
+
echo "Building for Linux x64..."
|
|
30
|
+
GOOS=linux GOARCH=amd64 go build -o bin/linux/x64/mkctx main.go
|
|
31
|
+
|
|
32
|
+
echo "Building for Linux ARM64..."
|
|
33
|
+
GOOS=linux GOARCH=arm64 go build -o bin/linux/arm64/mkctx main.go
|
|
34
|
+
|
|
35
|
+
echo "✅ Build completed!"
|
|
36
|
+
|
|
37
|
+
# Verificar archivos creados
|
|
38
|
+
echo "📁 Files created:"
|
|
39
|
+
find bin/ -type f | while read file; do
|
|
40
|
+
echo " - $file"
|
|
41
|
+
done
|
package/install.js
CHANGED
|
@@ -3,32 +3,39 @@ const path = require("path");
|
|
|
3
3
|
const { execSync } = require("child_process");
|
|
4
4
|
|
|
5
5
|
function install() {
|
|
6
|
-
const
|
|
6
|
+
const platform = process.platform;
|
|
7
|
+
const arch = process.arch;
|
|
8
|
+
const isWindows = platform === "win32";
|
|
9
|
+
|
|
7
10
|
const binaryName = isWindows ? "mkctx.exe" : "mkctx";
|
|
8
|
-
const sourceBinary = isWindows ? "mkctx.exe" : "mkctx";
|
|
9
|
-
const sourcePath = path.join(__dirname, sourceBinary);
|
|
10
11
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// Determinar la ruta del binario precompilado
|
|
13
|
+
let binaryPath;
|
|
14
|
+
|
|
15
|
+
if (platform === "win32") {
|
|
16
|
+
binaryPath = path.join(__dirname, "bin", "win32", arch, "mkctx.exe");
|
|
17
|
+
} else if (platform === "darwin") {
|
|
18
|
+
binaryPath = path.join(__dirname, "bin", "darwin", arch, "mkctx");
|
|
19
|
+
} else if (platform === "linux") {
|
|
20
|
+
binaryPath = path.join(__dirname, "bin", "linux", arch, "mkctx");
|
|
21
|
+
} else {
|
|
22
|
+
console.log("❌ Unsupported platform:", platform);
|
|
23
|
+
return;
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
//
|
|
18
|
-
if (!fs.existsSync(
|
|
19
|
-
console.log(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
console.log(" Could not read directory");
|
|
26
|
-
}
|
|
26
|
+
// Verificar que el binario precompilado existe
|
|
27
|
+
if (!fs.existsSync(binaryPath)) {
|
|
28
|
+
console.log(
|
|
29
|
+
"❌ Precompiled binary not found for your platform:",
|
|
30
|
+
binaryPath
|
|
31
|
+
);
|
|
32
|
+
console.log("📋 Available platforms: win32, darwin, linux");
|
|
33
|
+
console.log("📋 Available architectures: x64, arm64");
|
|
27
34
|
return;
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
try {
|
|
31
|
-
//
|
|
38
|
+
// Método 1: Usar npm para obtener el directorio global de bins
|
|
32
39
|
let npmGlobalBin;
|
|
33
40
|
try {
|
|
34
41
|
npmGlobalBin = execSync("npm bin -g").toString().trim();
|
|
@@ -47,19 +54,19 @@ function install() {
|
|
|
47
54
|
fs.mkdirSync(npmGlobalBin, { recursive: true });
|
|
48
55
|
}
|
|
49
56
|
|
|
50
|
-
// Copy the binary
|
|
51
|
-
fs.copyFileSync(
|
|
57
|
+
// Copy the precompiled binary
|
|
58
|
+
fs.copyFileSync(binaryPath, installPath);
|
|
52
59
|
|
|
53
60
|
// Set execution permissions (Unix only)
|
|
54
61
|
if (!isWindows) {
|
|
55
62
|
fs.chmodSync(installPath, 0o755);
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
console.log("✅ mkctx installed successfully
|
|
65
|
+
console.log("✅ mkctx installed successfully");
|
|
59
66
|
|
|
60
67
|
// Create a .cmd wrapper for Windows
|
|
61
68
|
if (isWindows) {
|
|
62
|
-
createWindowsWrapper(npmGlobalBin);
|
|
69
|
+
createWindowsWrapper(npmGlobalBin, installPath);
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
return;
|
|
@@ -79,7 +86,7 @@ function install() {
|
|
|
79
86
|
const altInstallPath = path.join(altPath, binaryName);
|
|
80
87
|
console.log(`🔄 Trying to install at: ${altInstallPath}`);
|
|
81
88
|
|
|
82
|
-
fs.copyFileSync(
|
|
89
|
+
fs.copyFileSync(binaryPath, altInstallPath);
|
|
83
90
|
|
|
84
91
|
// Set execution permissions (Unix only)
|
|
85
92
|
if (!isWindows) {
|
|
@@ -88,7 +95,7 @@ function install() {
|
|
|
88
95
|
|
|
89
96
|
// Create Windows wrapper if needed
|
|
90
97
|
if (isWindows) {
|
|
91
|
-
createWindowsWrapper(altPath);
|
|
98
|
+
createWindowsWrapper(altPath, altInstallPath);
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
console.log(`✅ mkctx installed at: ${altInstallPath}`);
|
|
@@ -99,24 +106,15 @@ function install() {
|
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
// If we get here, all methods failed
|
|
103
109
|
console.log("❌ Could not install automatically");
|
|
104
110
|
console.log("📋 Manual installation required:");
|
|
105
|
-
console.log(` 1. Copy the file '${
|
|
106
|
-
console.log(` 2. Make sure the file has execution permissions`);
|
|
107
|
-
|
|
108
|
-
// Show current PATH to help the user
|
|
109
|
-
console.log("\n📁 Your PATH includes these folders:");
|
|
110
|
-
const pathDirs = process.env.PATH
|
|
111
|
-
? process.env.PATH.split(path.delimiter)
|
|
112
|
-
: [];
|
|
113
|
-
pathDirs.forEach((dir) => console.log(" -", dir));
|
|
111
|
+
console.log(` 1. Copy the file '${binaryPath}' to a folder in your PATH`);
|
|
114
112
|
}
|
|
115
113
|
|
|
116
|
-
function createWindowsWrapper(installDir) {
|
|
114
|
+
function createWindowsWrapper(installDir, binaryPath) {
|
|
117
115
|
const wrapperPath = path.join(installDir, "mkctx.cmd");
|
|
118
116
|
const wrapperContent = `@echo off
|
|
119
|
-
"${
|
|
117
|
+
"${binaryPath}" %*
|
|
120
118
|
`;
|
|
121
119
|
fs.writeFileSync(wrapperPath, wrapperContent);
|
|
122
120
|
console.log(`✅ Created Windows wrapper: ${wrapperPath}`);
|
|
@@ -127,7 +125,6 @@ function getAlternativePaths() {
|
|
|
127
125
|
const isWindows = process.platform === "win32";
|
|
128
126
|
|
|
129
127
|
if (isWindows) {
|
|
130
|
-
// Windows paths
|
|
131
128
|
if (process.env.APPDATA) {
|
|
132
129
|
paths.push(path.join(process.env.APPDATA, "npm"));
|
|
133
130
|
}
|
|
@@ -139,29 +136,24 @@ function getAlternativePaths() {
|
|
|
139
136
|
if (process.env.ProgramFiles) {
|
|
140
137
|
paths.push(path.join(process.env.ProgramFiles, "nodejs"));
|
|
141
138
|
}
|
|
142
|
-
// Common Node.js installation paths
|
|
143
139
|
paths.push("C:\\Program Files\\nodejs");
|
|
144
140
|
paths.push("C:\\Program Files (x86)\\nodejs");
|
|
145
141
|
|
|
146
|
-
// User's local bin
|
|
147
142
|
if (process.env.USERPROFILE) {
|
|
148
143
|
paths.push(
|
|
149
144
|
path.join(process.env.USERPROFILE, "AppData", "Roaming", "npm")
|
|
150
145
|
);
|
|
151
146
|
}
|
|
152
147
|
} else {
|
|
153
|
-
// Unix/Linux/macOS paths
|
|
154
148
|
paths.push("/usr/local/bin");
|
|
155
149
|
paths.push("/usr/bin");
|
|
156
150
|
paths.push("/opt/local/bin");
|
|
157
151
|
|
|
158
|
-
// User bin directory
|
|
159
152
|
if (process.env.HOME) {
|
|
160
153
|
paths.push(path.join(process.env.HOME, "bin"));
|
|
161
154
|
paths.push(path.join(process.env.HOME, ".local", "bin"));
|
|
162
155
|
}
|
|
163
156
|
|
|
164
|
-
// Common directories on macOS
|
|
165
157
|
if (process.platform === "darwin") {
|
|
166
158
|
paths.push("/opt/homebrew/bin");
|
|
167
159
|
paths.push("/usr/local/opt/bin");
|
|
@@ -171,15 +163,4 @@ function getAlternativePaths() {
|
|
|
171
163
|
return paths.filter((p) => p !== null && p !== undefined);
|
|
172
164
|
}
|
|
173
165
|
|
|
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
|
-
|
|
185
166
|
install();
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mkctx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Tool to generate project context in markdown for AI assistants",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
7
|
+
"build": "node -e \"console.log('Use build.ps1 on Windows or build.sh on Unix')\"",
|
|
8
|
+
"build:windows": "powershell -ExecutionPolicy Bypass -File build.ps1",
|
|
9
|
+
"build:unix": "chmod +x build.sh && ./build.sh",
|
|
10
|
+
"prepublishOnly": "npm run build:windows || npm run build:unix || echo 'Build failed - manual build required'",
|
|
11
|
+
"install": "node install.js"
|
|
10
12
|
},
|
|
11
13
|
"keywords": [
|
|
12
14
|
"context",
|
|
@@ -14,20 +16,18 @@
|
|
|
14
16
|
"documentation",
|
|
15
17
|
"ai",
|
|
16
18
|
"prompt",
|
|
17
|
-
"code-context"
|
|
18
|
-
"development",
|
|
19
|
-
"tool"
|
|
19
|
+
"code-context"
|
|
20
20
|
],
|
|
21
|
-
"author": "Your Name
|
|
21
|
+
"author": "Your Name",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"bin": {
|
|
24
|
-
"mkctx": "./mkctx.exe"
|
|
24
|
+
"mkctx": "./bin/mkctx.exe"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"
|
|
28
|
-
"package.json",
|
|
27
|
+
"bin/",
|
|
29
28
|
"install.js",
|
|
30
|
-
"
|
|
29
|
+
"build.ps1",
|
|
30
|
+
"build.sh",
|
|
31
31
|
"README.md"
|
|
32
32
|
],
|
|
33
33
|
"engines": {
|
|
@@ -41,9 +41,5 @@
|
|
|
41
41
|
"cpu": [
|
|
42
42
|
"x64",
|
|
43
43
|
"arm64"
|
|
44
|
-
]
|
|
45
|
-
"repository": {
|
|
46
|
-
"type": "git",
|
|
47
|
-
"url": "https://github.com/your-username/mkctx.git"
|
|
48
|
-
}
|
|
44
|
+
]
|
|
49
45
|
}
|
package/cleanup.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
function cleanup() {
|
|
5
|
-
const filesToRemove = ["mkctx", "mkctx.exe", "mkctx.cmd"];
|
|
6
|
-
let removedCount = 0;
|
|
7
|
-
|
|
8
|
-
filesToRemove.forEach((file) => {
|
|
9
|
-
const filePath = path.join(__dirname, file);
|
|
10
|
-
try {
|
|
11
|
-
if (fs.existsSync(filePath)) {
|
|
12
|
-
fs.unlinkSync(filePath);
|
|
13
|
-
console.log(`🧹 Cleaning up: ${file}`);
|
|
14
|
-
removedCount++;
|
|
15
|
-
}
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.log(`⚠️ Could not delete ${file}: ${error.message}`);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
if (removedCount > 0) {
|
|
22
|
-
console.log(`✅ Cleaned up ${removedCount} temporary files`);
|
|
23
|
-
} else {
|
|
24
|
-
console.log(`ℹ️ No temporary files found to clean up`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
cleanup();
|
package/main.go
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
package main
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"encoding/json"
|
|
5
|
-
"fmt"
|
|
6
|
-
"os"
|
|
7
|
-
"path/filepath"
|
|
8
|
-
"strings"
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
type Config struct {
|
|
12
|
-
Src string `json:"src"`
|
|
13
|
-
Ignore string `json:"ignore"`
|
|
14
|
-
Output string `json:"output"`
|
|
15
|
-
FirstComment string `json:"first_comment"`
|
|
16
|
-
LastComment string `json:"last_comment"`
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
func main() {
|
|
20
|
-
if len(os.Args) > 1 && os.Args[1] == "config" {
|
|
21
|
-
createConfig()
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
generateContext()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
func createConfig() {
|
|
28
|
-
config := Config{
|
|
29
|
-
Src: "./src",
|
|
30
|
-
Ignore: "*.log, temp/, node_modules/, .git/",
|
|
31
|
-
Output: "./mkctx",
|
|
32
|
-
FirstComment: "/* Project Context */",
|
|
33
|
-
LastComment: "/* End of Context */",
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
configJSON, _ := json.MarshalIndent(config, "", " ")
|
|
37
|
-
|
|
38
|
-
// Create mkctx directory if it doesn't exist
|
|
39
|
-
_ = os.MkdirAll("mkctx", 0755)
|
|
40
|
-
|
|
41
|
-
// Write configuration file
|
|
42
|
-
_ = os.WriteFile("mkctx.config.json", configJSON, 0644)
|
|
43
|
-
|
|
44
|
-
// Update .gitignore
|
|
45
|
-
updateGitignore()
|
|
46
|
-
|
|
47
|
-
fmt.Println("✅ Configuration created:")
|
|
48
|
-
fmt.Println(" - mkctx.config.json")
|
|
49
|
-
fmt.Println(" - mkctx/ folder")
|
|
50
|
-
fmt.Println(" - Entry in .gitignore")
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
func updateGitignore() {
|
|
54
|
-
gitignorePath := ".gitignore"
|
|
55
|
-
content, err := os.ReadFile(gitignorePath)
|
|
56
|
-
gitignoreExists := err == nil
|
|
57
|
-
|
|
58
|
-
var newContent string
|
|
59
|
-
if gitignoreExists {
|
|
60
|
-
newContent = string(content)
|
|
61
|
-
if !strings.Contains(newContent, "mkctx/") {
|
|
62
|
-
newContent += "\n# mkctx - generated context\nmkctx/\n"
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
newContent = "# mkctx - generated context\nmkctx/\n"
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
_ = os.WriteFile(gitignorePath, []byte(newContent), 0644)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
func generateContext() {
|
|
72
|
-
config := loadConfig()
|
|
73
|
-
files := getFiles(config)
|
|
74
|
-
content := buildContent(files, config)
|
|
75
|
-
|
|
76
|
-
outputPath := config.Output
|
|
77
|
-
if outputPath == "" {
|
|
78
|
-
outputPath = "."
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Ensure output directory exists
|
|
82
|
-
_ = os.MkdirAll(outputPath, 0755)
|
|
83
|
-
|
|
84
|
-
outputFile := filepath.Join(outputPath, "context.md")
|
|
85
|
-
err := os.WriteFile(outputFile, []byte(content), 0644)
|
|
86
|
-
if err != nil {
|
|
87
|
-
fmt.Printf("❌ Error creating file: %v\n", err)
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
fmt.Printf("✅ Context generated at: %s\n", outputFile)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
func loadConfig() Config {
|
|
94
|
-
var config Config
|
|
95
|
-
file, err := os.ReadFile("mkctx.config.json")
|
|
96
|
-
if err != nil {
|
|
97
|
-
return getDefaultConfig()
|
|
98
|
-
}
|
|
99
|
-
json.Unmarshal(file, &config)
|
|
100
|
-
|
|
101
|
-
// Validate and complete configuration
|
|
102
|
-
if config.Src == "" {
|
|
103
|
-
config.Src = "."
|
|
104
|
-
}
|
|
105
|
-
if config.Output == "" {
|
|
106
|
-
config.Output = "."
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return config
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
func getDefaultConfig() Config {
|
|
113
|
-
return Config{
|
|
114
|
-
Src: ".",
|
|
115
|
-
Output: ".",
|
|
116
|
-
FirstComment: "/* Project Context */",
|
|
117
|
-
LastComment: "/* End of Context */",
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
func getFiles(config Config) []string {
|
|
122
|
-
var files []string
|
|
123
|
-
|
|
124
|
-
srcPath := config.Src
|
|
125
|
-
if srcPath == "" {
|
|
126
|
-
srcPath = "."
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
filepath.Walk(srcPath, func(path string, info os.FileInfo, err error) error {
|
|
130
|
-
if err != nil || shouldIgnore(path, config) || info.IsDir() {
|
|
131
|
-
return nil
|
|
132
|
-
}
|
|
133
|
-
files = append(files, path)
|
|
134
|
-
return nil
|
|
135
|
-
})
|
|
136
|
-
return files
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
func shouldIgnore(path string, config Config) bool {
|
|
140
|
-
// Ignore system files
|
|
141
|
-
if strings.Contains(path, ".git") ||
|
|
142
|
-
strings.Contains(path, ".DS_Store") ||
|
|
143
|
-
strings.Contains(path, "Thumbs.db") {
|
|
144
|
-
return true
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Ignore based on configuration
|
|
148
|
-
if config.Ignore != "" {
|
|
149
|
-
ignorePatterns := strings.Split(config.Ignore, ",")
|
|
150
|
-
for _, pattern := range ignorePatterns {
|
|
151
|
-
pattern = strings.TrimSpace(pattern)
|
|
152
|
-
if pattern == "" {
|
|
153
|
-
continue
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Simple pattern with wildcard
|
|
157
|
-
if strings.Contains(pattern, "*") {
|
|
158
|
-
if matched, _ := filepath.Match(pattern, filepath.Base(path)); matched {
|
|
159
|
-
return true
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Entire directory
|
|
164
|
-
if strings.HasSuffix(pattern, "/") {
|
|
165
|
-
dir := strings.TrimSuffix(pattern, "/")
|
|
166
|
-
if strings.Contains(path, dir) {
|
|
167
|
-
return true
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Exact match
|
|
172
|
-
if strings.Contains(path, pattern) {
|
|
173
|
-
return true
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return false
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
func buildContent(files []string, config Config) string {
|
|
182
|
-
var content strings.Builder
|
|
183
|
-
|
|
184
|
-
if config.FirstComment != "" {
|
|
185
|
-
content.WriteString(config.FirstComment + "\n\n")
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
for _, file := range files {
|
|
189
|
-
fileContent, err := os.ReadFile(file)
|
|
190
|
-
if err != nil {
|
|
191
|
-
continue
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
ext := filepath.Ext(file)
|
|
195
|
-
lang := "text"
|
|
196
|
-
if ext != "" {
|
|
197
|
-
lang = ext[1:] // Remove the dot
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
content.WriteString("```" + lang + "\n")
|
|
201
|
-
content.WriteString("// " + file + "\n")
|
|
202
|
-
content.WriteString(string(fileContent))
|
|
203
|
-
content.WriteString("\n```\n\n")
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if config.LastComment != "" {
|
|
207
|
-
content.WriteString(config.LastComment)
|
|
208
|
-
}
|
|
209
|
-
return content.String()
|
|
210
|
-
}
|