opencode-add-dir 1.0.0 → 1.0.1
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/package.json +3 -2
- package/scripts/install.js +58 -0
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-add-dir",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "OpenCode plugin to add external directories to session context",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
|
-
"command"
|
|
10
|
+
"command",
|
|
11
|
+
"scripts"
|
|
11
12
|
],
|
|
12
13
|
"scripts": {
|
|
13
14
|
"build": "tsc",
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
const COMMAND_SOURCE = path.join(__dirname, '..', 'command', 'add-dir.md');
|
|
10
|
+
|
|
11
|
+
function findOpencodeConfigDir(startDir = process.cwd()) {
|
|
12
|
+
const configFiles = ['opencode.jsonc', 'opencode.json'];
|
|
13
|
+
let currentDir = startDir;
|
|
14
|
+
|
|
15
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
16
|
+
for (const configFile of configFiles) {
|
|
17
|
+
const configPath = path.join(currentDir, configFile);
|
|
18
|
+
if (fs.existsSync(configPath)) {
|
|
19
|
+
return currentDir;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
currentDir = path.dirname(currentDir);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const defaultConfigDir = path.join(os.homedir(), '.config', 'opencode');
|
|
26
|
+
if (fs.existsSync(defaultConfigDir)) {
|
|
27
|
+
return defaultConfigDir;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const opencodeDir = findOpencodeConfigDir();
|
|
35
|
+
|
|
36
|
+
if (!opencodeDir) {
|
|
37
|
+
console.log('ℹ opencode-add-dir: Could not find opencode config directory, skipping command file installation');
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const commandDir = path.join(opencodeDir, 'command');
|
|
42
|
+
const commandDest = path.join(commandDir, 'add-dir.md');
|
|
43
|
+
|
|
44
|
+
if (!fs.existsSync(commandDir)) {
|
|
45
|
+
fs.mkdirSync(commandDir, { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (fs.existsSync(COMMAND_SOURCE)) {
|
|
49
|
+
fs.copyFileSync(COMMAND_SOURCE, commandDest);
|
|
50
|
+
console.log('✓ opencode-add-dir: Command file installed to', commandDest);
|
|
51
|
+
} else {
|
|
52
|
+
console.error('✗ opencode-add-dir: Command source file not found at', COMMAND_SOURCE);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error('✗ opencode-add-dir: Failed to install command file:', error.message);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|