mkctx 1.0.1 → 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 +80 -48
- package/package.json +15 -24
- 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,52 +3,78 @@ const path = require("path");
|
|
|
3
3
|
const { execSync } = require("child_process");
|
|
4
4
|
|
|
5
5
|
function install() {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
) {
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const platform = process.platform;
|
|
7
|
+
const arch = process.arch;
|
|
8
|
+
const isWindows = platform === "win32";
|
|
9
|
+
|
|
10
|
+
const binaryName = isWindows ? "mkctx.exe" : "mkctx";
|
|
11
|
+
|
|
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;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
//
|
|
21
|
-
if (!fs.existsSync(
|
|
22
|
-
console.log(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
console.log(" Could not read directory");
|
|
29
|
-
}
|
|
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");
|
|
30
34
|
return;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
try {
|
|
34
|
-
//
|
|
35
|
-
|
|
38
|
+
// Método 1: Usar npm para obtener el directorio global de bins
|
|
39
|
+
let npmGlobalBin;
|
|
40
|
+
try {
|
|
41
|
+
npmGlobalBin = execSync("npm bin -g").toString().trim();
|
|
42
|
+
} catch (error) {
|
|
43
|
+
// Alternative method to get global bin directory
|
|
44
|
+
npmGlobalBin = execSync("npm root -g").toString().trim();
|
|
45
|
+
npmGlobalBin = path.join(npmGlobalBin, ".bin");
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
const installPath = path.join(npmGlobalBin, binaryName);
|
|
37
49
|
|
|
38
50
|
console.log(`📦 Installing mkctx at: ${installPath}`);
|
|
39
51
|
|
|
40
|
-
//
|
|
41
|
-
fs.
|
|
52
|
+
// Ensure the directory exists
|
|
53
|
+
if (!fs.existsSync(npmGlobalBin)) {
|
|
54
|
+
fs.mkdirSync(npmGlobalBin, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Copy the precompiled binary
|
|
58
|
+
fs.copyFileSync(binaryPath, installPath);
|
|
42
59
|
|
|
43
60
|
// Set execution permissions (Unix only)
|
|
44
|
-
if (
|
|
61
|
+
if (!isWindows) {
|
|
45
62
|
fs.chmodSync(installPath, 0o755);
|
|
46
63
|
}
|
|
47
64
|
|
|
48
|
-
console.log("✅ mkctx installed successfully
|
|
65
|
+
console.log("✅ mkctx installed successfully");
|
|
66
|
+
|
|
67
|
+
// Create a .cmd wrapper for Windows
|
|
68
|
+
if (isWindows) {
|
|
69
|
+
createWindowsWrapper(npmGlobalBin, installPath);
|
|
70
|
+
}
|
|
71
|
+
|
|
49
72
|
return;
|
|
50
73
|
} catch (error) {
|
|
51
|
-
console.log(
|
|
74
|
+
console.log(
|
|
75
|
+
"⚠️ npm method failed, trying alternative method...",
|
|
76
|
+
error.message
|
|
77
|
+
);
|
|
52
78
|
}
|
|
53
79
|
|
|
54
80
|
// Alternative method: Search common PATH directories
|
|
@@ -60,41 +86,45 @@ function install() {
|
|
|
60
86
|
const altInstallPath = path.join(altPath, binaryName);
|
|
61
87
|
console.log(`🔄 Trying to install at: ${altInstallPath}`);
|
|
62
88
|
|
|
63
|
-
fs.copyFileSync(
|
|
89
|
+
fs.copyFileSync(binaryPath, altInstallPath);
|
|
64
90
|
|
|
65
91
|
// Set execution permissions (Unix only)
|
|
66
|
-
if (
|
|
92
|
+
if (!isWindows) {
|
|
67
93
|
fs.chmodSync(altInstallPath, 0o755);
|
|
68
94
|
}
|
|
69
95
|
|
|
96
|
+
// Create Windows wrapper if needed
|
|
97
|
+
if (isWindows) {
|
|
98
|
+
createWindowsWrapper(altPath, altInstallPath);
|
|
99
|
+
}
|
|
100
|
+
|
|
70
101
|
console.log(`✅ mkctx installed at: ${altInstallPath}`);
|
|
71
102
|
return;
|
|
72
103
|
}
|
|
73
104
|
} catch (e) {
|
|
74
105
|
console.log(` ❌ Installation failed at ${altPath}: ${e.message}`);
|
|
75
|
-
// Continue to next path
|
|
76
106
|
}
|
|
77
107
|
}
|
|
78
108
|
|
|
79
|
-
// If we get here, all methods failed
|
|
80
109
|
console.log("❌ Could not install automatically");
|
|
81
110
|
console.log("📋 Manual installation required:");
|
|
82
|
-
console.log(` 1. Copy the file '${
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
111
|
+
console.log(` 1. Copy the file '${binaryPath}' to a folder in your PATH`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function createWindowsWrapper(installDir, binaryPath) {
|
|
115
|
+
const wrapperPath = path.join(installDir, "mkctx.cmd");
|
|
116
|
+
const wrapperContent = `@echo off
|
|
117
|
+
"${binaryPath}" %*
|
|
118
|
+
`;
|
|
119
|
+
fs.writeFileSync(wrapperPath, wrapperContent);
|
|
120
|
+
console.log(`✅ Created Windows wrapper: ${wrapperPath}`);
|
|
91
121
|
}
|
|
92
122
|
|
|
93
123
|
function getAlternativePaths() {
|
|
94
124
|
const paths = [];
|
|
125
|
+
const isWindows = process.platform === "win32";
|
|
95
126
|
|
|
96
|
-
if (
|
|
97
|
-
// Windows
|
|
127
|
+
if (isWindows) {
|
|
98
128
|
if (process.env.APPDATA) {
|
|
99
129
|
paths.push(path.join(process.env.APPDATA, "npm"));
|
|
100
130
|
}
|
|
@@ -106,22 +136,24 @@ function getAlternativePaths() {
|
|
|
106
136
|
if (process.env.ProgramFiles) {
|
|
107
137
|
paths.push(path.join(process.env.ProgramFiles, "nodejs"));
|
|
108
138
|
}
|
|
109
|
-
// Add common Windows PATH directories
|
|
110
139
|
paths.push("C:\\Program Files\\nodejs");
|
|
111
140
|
paths.push("C:\\Program Files (x86)\\nodejs");
|
|
141
|
+
|
|
142
|
+
if (process.env.USERPROFILE) {
|
|
143
|
+
paths.push(
|
|
144
|
+
path.join(process.env.USERPROFILE, "AppData", "Roaming", "npm")
|
|
145
|
+
);
|
|
146
|
+
}
|
|
112
147
|
} else {
|
|
113
|
-
// Unix/Linux/macOS
|
|
114
148
|
paths.push("/usr/local/bin");
|
|
115
149
|
paths.push("/usr/bin");
|
|
116
150
|
paths.push("/opt/local/bin");
|
|
117
151
|
|
|
118
|
-
// User bin directory
|
|
119
152
|
if (process.env.HOME) {
|
|
120
153
|
paths.push(path.join(process.env.HOME, "bin"));
|
|
121
154
|
paths.push(path.join(process.env.HOME, ".local", "bin"));
|
|
122
155
|
}
|
|
123
156
|
|
|
124
|
-
// Common directories on macOS
|
|
125
157
|
if (process.platform === "darwin") {
|
|
126
158
|
paths.push("/opt/homebrew/bin");
|
|
127
159
|
paths.push("/usr/local/opt/bin");
|
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,25 +16,22 @@
|
|
|
14
16
|
"documentation",
|
|
15
17
|
"ai",
|
|
16
18
|
"prompt",
|
|
17
|
-
"code-context"
|
|
18
|
-
"development",
|
|
19
|
-
"tool"
|
|
19
|
+
"code-context"
|
|
20
20
|
],
|
|
21
|
-
"author": "
|
|
21
|
+
"author": "Your Name",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"bin": {
|
|
24
|
-
"mkctx": "./mkctx"
|
|
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": {
|
|
34
|
-
"node": ">=14.0.0"
|
|
35
|
-
"go": ">=1.16"
|
|
34
|
+
"node": ">=14.0.0"
|
|
36
35
|
},
|
|
37
36
|
"os": [
|
|
38
37
|
"darwin",
|
|
@@ -42,13 +41,5 @@
|
|
|
42
41
|
"cpu": [
|
|
43
42
|
"x64",
|
|
44
43
|
"arm64"
|
|
45
|
-
]
|
|
46
|
-
"repository": {
|
|
47
|
-
"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"
|
|
53
|
-
}
|
|
44
|
+
]
|
|
54
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"];
|
|
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
|
-
}
|