cartotree 0.2.0 → 0.2.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/.claude-plugin/marketplace.json +11 -11
- package/.claude-plugin/plugin.json +12 -12
- package/LICENSE +20 -20
- package/README.md +270 -246
- package/bin/cartotree.js +162 -162
- package/hooks/hooks.json +14 -14
- package/package.json +45 -45
- package/skills/cartotree/SKILL.md +32 -32
- package/src/ai.js +112 -112
- package/src/atlas/cache.js +46 -46
- package/src/atlas/files.js +56 -56
- package/src/atlas/git.js +65 -65
- package/src/atlas/init.js +114 -114
- package/src/atlas/links.js +87 -87
- package/src/atlas/locate.js +218 -218
- package/src/atlas/mcp.js +106 -106
- package/src/atlas/peek.js +24 -24
- package/src/atlas/symbols.js +41 -41
- package/src/clipboard.js +10 -10
- package/src/config.js +25 -25
- package/src/exports.js +73 -73
- package/src/ignore.js +30 -30
- package/src/sync.js +29 -29
- package/src/tree.js +96 -96
package/src/tree.js
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const chalk = require('chalk');
|
|
4
|
-
const { shouldIgnore } = require('./ignore');
|
|
5
|
-
const { parseExports, formatExports } = require('./exports');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function getFolderDescription(dirPath) {
|
|
9
|
-
const folderMd = path.join(dirPath, '.folder.md');
|
|
10
|
-
const readmeMd = path.join(dirPath, 'README.md');
|
|
11
|
-
|
|
12
|
-
if (fs.existsSync(folderMd)) {
|
|
13
|
-
const content = fs.readFileSync(folderMd, 'utf-8').trim();
|
|
14
|
-
return content.split('\n')[0].replace(/^#\s*/, '');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (fs.existsSync(readmeMd)) {
|
|
18
|
-
const content = fs.readFileSync(readmeMd, 'utf-8').trim();
|
|
19
|
-
const firstLine = content.split('\n')[0].replace(/^#\s*/, '');
|
|
20
|
-
if (firstLine.length < 80) return firstLine;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function buildTree(dirPath, opts, prefix = '', currentDepth = 0) {
|
|
27
|
-
if (currentDepth > opts.depth) return '';
|
|
28
|
-
|
|
29
|
-
let entries;
|
|
30
|
-
try {
|
|
31
|
-
entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
32
|
-
} catch (err) {
|
|
33
|
-
if (err.code === 'EACCES') {
|
|
34
|
-
return `${prefix}${chalk.red('[permission denied]')}\n`;
|
|
35
|
-
}
|
|
36
|
-
return `${prefix}${chalk.red(`[error: ${err.code}]`)}\n`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const filtered = entries
|
|
40
|
-
.filter(e => !shouldIgnore(e.name, opts.exclude))
|
|
41
|
-
.sort((a, b) => {
|
|
42
|
-
if (a.isDirectory() && !b.isDirectory()) return -1;
|
|
43
|
-
if (!a.isDirectory() && b.isDirectory()) return 1;
|
|
44
|
-
return a.name.localeCompare(b.name);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (filtered.length === 0) {
|
|
48
|
-
return `${prefix}${chalk.gray('(empty)')}\n`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let output = '';
|
|
52
|
-
|
|
53
|
-
filtered.forEach((entry, index) => {
|
|
54
|
-
const isLast = index === filtered.length - 1;
|
|
55
|
-
const connector = isLast ? '└── ' : '├── ';
|
|
56
|
-
const childPrefix = isLast ? ' ' : '│ ';
|
|
57
|
-
const fullPath = path.join(dirPath, entry.name);
|
|
58
|
-
|
|
59
|
-
if (entry.isSymbolicLink()) {
|
|
60
|
-
try {
|
|
61
|
-
const target = fs.readlinkSync(fullPath);
|
|
62
|
-
output += `${prefix}${connector}${chalk.magenta(entry.name)}${chalk.gray(` -> ${target}`)}\n`;
|
|
63
|
-
} catch {
|
|
64
|
-
output += `${prefix}${connector}${chalk.magenta(entry.name)}${chalk.red(' -> [broken link]')}\n`;
|
|
65
|
-
}
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (entry.isDirectory()) {
|
|
70
|
-
const desc = getFolderDescription(fullPath);
|
|
71
|
-
const annotation = desc ? chalk.gray(` # ${desc}`) : '';
|
|
72
|
-
output += `${prefix}${connector}${chalk.cyan(entry.name)}/${annotation}\n`;
|
|
73
|
-
if (currentDepth < opts.depth) {
|
|
74
|
-
output += buildTree(fullPath, opts, prefix + childPrefix, currentDepth + 1);
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
const exports = opts.showExports ? parseExports(fullPath) : null;
|
|
78
|
-
const exportTag = exports ? chalk.yellow(` ${formatExports(exports)}`) : '';
|
|
79
|
-
output += `${prefix}${connector}${entry.name}${exportTag}\n`;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return output;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function generateTree(rootPath, opts) {
|
|
87
|
-
const rootName = path.basename(rootPath);
|
|
88
|
-
const desc = getFolderDescription(rootPath);
|
|
89
|
-
const annotation = desc ? chalk.gray(` # ${desc}`) : '';
|
|
90
|
-
|
|
91
|
-
let output = `${chalk.bold.cyan(rootName)}/${annotation}\n`;
|
|
92
|
-
output += buildTree(rootPath, opts);
|
|
93
|
-
|
|
94
|
-
return output;
|
|
95
|
-
}
|
|
96
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const { shouldIgnore } = require('./ignore');
|
|
5
|
+
const { parseExports, formatExports } = require('./exports');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function getFolderDescription(dirPath) {
|
|
9
|
+
const folderMd = path.join(dirPath, '.folder.md');
|
|
10
|
+
const readmeMd = path.join(dirPath, 'README.md');
|
|
11
|
+
|
|
12
|
+
if (fs.existsSync(folderMd)) {
|
|
13
|
+
const content = fs.readFileSync(folderMd, 'utf-8').trim();
|
|
14
|
+
return content.split('\n')[0].replace(/^#\s*/, '');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (fs.existsSync(readmeMd)) {
|
|
18
|
+
const content = fs.readFileSync(readmeMd, 'utf-8').trim();
|
|
19
|
+
const firstLine = content.split('\n')[0].replace(/^#\s*/, '');
|
|
20
|
+
if (firstLine.length < 80) return firstLine;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function buildTree(dirPath, opts, prefix = '', currentDepth = 0) {
|
|
27
|
+
if (currentDepth > opts.depth) return '';
|
|
28
|
+
|
|
29
|
+
let entries;
|
|
30
|
+
try {
|
|
31
|
+
entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if (err.code === 'EACCES') {
|
|
34
|
+
return `${prefix}${chalk.red('[permission denied]')}\n`;
|
|
35
|
+
}
|
|
36
|
+
return `${prefix}${chalk.red(`[error: ${err.code}]`)}\n`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const filtered = entries
|
|
40
|
+
.filter(e => !shouldIgnore(e.name, opts.exclude))
|
|
41
|
+
.sort((a, b) => {
|
|
42
|
+
if (a.isDirectory() && !b.isDirectory()) return -1;
|
|
43
|
+
if (!a.isDirectory() && b.isDirectory()) return 1;
|
|
44
|
+
return a.name.localeCompare(b.name);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (filtered.length === 0) {
|
|
48
|
+
return `${prefix}${chalk.gray('(empty)')}\n`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let output = '';
|
|
52
|
+
|
|
53
|
+
filtered.forEach((entry, index) => {
|
|
54
|
+
const isLast = index === filtered.length - 1;
|
|
55
|
+
const connector = isLast ? '└── ' : '├── ';
|
|
56
|
+
const childPrefix = isLast ? ' ' : '│ ';
|
|
57
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
58
|
+
|
|
59
|
+
if (entry.isSymbolicLink()) {
|
|
60
|
+
try {
|
|
61
|
+
const target = fs.readlinkSync(fullPath);
|
|
62
|
+
output += `${prefix}${connector}${chalk.magenta(entry.name)}${chalk.gray(` -> ${target}`)}\n`;
|
|
63
|
+
} catch {
|
|
64
|
+
output += `${prefix}${connector}${chalk.magenta(entry.name)}${chalk.red(' -> [broken link]')}\n`;
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (entry.isDirectory()) {
|
|
70
|
+
const desc = getFolderDescription(fullPath);
|
|
71
|
+
const annotation = desc ? chalk.gray(` # ${desc}`) : '';
|
|
72
|
+
output += `${prefix}${connector}${chalk.cyan(entry.name)}/${annotation}\n`;
|
|
73
|
+
if (currentDepth < opts.depth) {
|
|
74
|
+
output += buildTree(fullPath, opts, prefix + childPrefix, currentDepth + 1);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
const exports = opts.showExports ? parseExports(fullPath) : null;
|
|
78
|
+
const exportTag = exports ? chalk.yellow(` ${formatExports(exports)}`) : '';
|
|
79
|
+
output += `${prefix}${connector}${entry.name}${exportTag}\n`;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return output;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function generateTree(rootPath, opts) {
|
|
87
|
+
const rootName = path.basename(rootPath);
|
|
88
|
+
const desc = getFolderDescription(rootPath);
|
|
89
|
+
const annotation = desc ? chalk.gray(` # ${desc}`) : '';
|
|
90
|
+
|
|
91
|
+
let output = `${chalk.bold.cyan(rootName)}/${annotation}\n`;
|
|
92
|
+
output += buildTree(rootPath, opts);
|
|
93
|
+
|
|
94
|
+
return output;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
97
|
module.exports = { generateTree };
|