@mdless/cli 1.0.6 → 1.0.8
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/README.md +2 -0
- package/package.json +1 -1
- package/src/commands/scan.ts +90 -0
- package/src/config.ts +42 -0
- package/src/index.ts +6 -0
- package/src/utils.ts +19 -0
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @mdless/cli
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
**Mind less, ship more.**
|
|
4
6
|
|
|
5
7
|
You know that feeling when you craft the perfect Claude Code skill, and then you need it in another project? Or when your teammate asks "how did you make Claude do that?"
|
package/package.json
CHANGED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readdirSync, statSync, existsSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join, basename } from "node:path";
|
|
4
|
+
import { loadConfig, saveConfig } from "../config.js";
|
|
5
|
+
import { clearLine, formatDuration, truncatePath } from "../utils.js";
|
|
6
|
+
|
|
7
|
+
const EXCLUSIONS = new Set([
|
|
8
|
+
"node_modules",
|
|
9
|
+
"dist",
|
|
10
|
+
"build",
|
|
11
|
+
"Library",
|
|
12
|
+
"Applications",
|
|
13
|
+
"__pycache__",
|
|
14
|
+
"venv",
|
|
15
|
+
"worktrees",
|
|
16
|
+
"workspaces",
|
|
17
|
+
"tmp",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
function* walkDirectories(dir: string): Generator<string> {
|
|
21
|
+
let entries: string[];
|
|
22
|
+
try {
|
|
23
|
+
entries = readdirSync(dir);
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
if (entry.startsWith(".") || EXCLUSIONS.has(entry)) continue;
|
|
30
|
+
|
|
31
|
+
const fullPath = join(dir, entry);
|
|
32
|
+
let stat;
|
|
33
|
+
try {
|
|
34
|
+
stat = statSync(fullPath);
|
|
35
|
+
} catch {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (stat.isDirectory()) {
|
|
40
|
+
yield fullPath;
|
|
41
|
+
yield* walkDirectories(fullPath);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isClaudeWorkspace(dir: string): boolean {
|
|
47
|
+
return existsSync(join(dir, ".claude")) && existsSync(join(dir, ".git"));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function scanCommand(): Promise<void> {
|
|
51
|
+
const startTime = Date.now();
|
|
52
|
+
const home = homedir();
|
|
53
|
+
|
|
54
|
+
console.log(`Scanning from ${home}...`);
|
|
55
|
+
|
|
56
|
+
const found: string[] = [];
|
|
57
|
+
let scanned = 0;
|
|
58
|
+
|
|
59
|
+
for (const dir of walkDirectories(home)) {
|
|
60
|
+
scanned++;
|
|
61
|
+
if (isClaudeWorkspace(dir)) {
|
|
62
|
+
found.push(dir);
|
|
63
|
+
}
|
|
64
|
+
if (scanned % 100 === 0) {
|
|
65
|
+
clearLine();
|
|
66
|
+
process.stdout.write(
|
|
67
|
+
` ${scanned.toLocaleString()} checked, ${found.length} found | ${truncatePath(dir)}`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
clearLine();
|
|
73
|
+
|
|
74
|
+
const config = loadConfig();
|
|
75
|
+
config.workingDirectories = found.map((path) => ({
|
|
76
|
+
path,
|
|
77
|
+
name: basename(path),
|
|
78
|
+
sync: true,
|
|
79
|
+
}));
|
|
80
|
+
saveConfig(config);
|
|
81
|
+
|
|
82
|
+
const duration = formatDuration(Date.now() - startTime);
|
|
83
|
+
console.log(`\n✓ Found ${found.length} workspaces in ${duration}`);
|
|
84
|
+
|
|
85
|
+
for (const dir of found) {
|
|
86
|
+
console.log(` • ${basename(dir)}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log(`\nSaved to ~/.mdless/config.json`);
|
|
90
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
export const MDLESS_DIR = join(homedir(), ".mdless");
|
|
6
|
+
export const CONFIG_PATH = join(MDLESS_DIR, "config.json");
|
|
7
|
+
|
|
8
|
+
export interface WorkingDirectory {
|
|
9
|
+
path: string;
|
|
10
|
+
name: string;
|
|
11
|
+
sync: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface MdlessConfig {
|
|
15
|
+
version: 1;
|
|
16
|
+
workingDirectories: WorkingDirectory[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ensureConfigDir(): void {
|
|
20
|
+
if (!existsSync(MDLESS_DIR)) {
|
|
21
|
+
mkdirSync(MDLESS_DIR, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function loadConfig(): MdlessConfig {
|
|
26
|
+
ensureConfigDir();
|
|
27
|
+
|
|
28
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
29
|
+
return {
|
|
30
|
+
version: 1,
|
|
31
|
+
workingDirectories: [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const content = readFileSync(CONFIG_PATH, "utf-8");
|
|
36
|
+
return JSON.parse(content) as MdlessConfig;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function saveConfig(config: MdlessConfig): void {
|
|
40
|
+
ensureConfigDir();
|
|
41
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n");
|
|
42
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import { select } from "@inquirer/prompts";
|
|
4
4
|
import packageJson from "../package.json" with { type: "json" };
|
|
5
|
+
import { scanCommand } from "./commands/scan.js";
|
|
5
6
|
import { skillsCommand } from "./commands/skills.js";
|
|
6
7
|
import { withExitHandler } from "./utils.js";
|
|
7
8
|
|
|
@@ -20,6 +21,11 @@ const commands = [
|
|
|
20
21
|
description: "Share Claude Code skills across projects and teams",
|
|
21
22
|
action: skillsCommand,
|
|
22
23
|
},
|
|
24
|
+
{
|
|
25
|
+
name: "scan",
|
|
26
|
+
description: "Find Claude workspaces on your computer",
|
|
27
|
+
action: scanCommand,
|
|
28
|
+
},
|
|
23
29
|
] as const;
|
|
24
30
|
|
|
25
31
|
async function interactiveMode(): Promise<void> {
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
|
|
4
5
|
export function exit(): never {
|
|
@@ -18,3 +19,21 @@ export function withExitHandler<T>(promise: Promise<T>): Promise<T> {
|
|
|
18
19
|
throw e;
|
|
19
20
|
});
|
|
20
21
|
}
|
|
22
|
+
|
|
23
|
+
export function truncatePath(path: string, maxLength = 50): string {
|
|
24
|
+
const home = homedir();
|
|
25
|
+
let display = path.startsWith(home) ? path.replace(home, "~") : path;
|
|
26
|
+
if (display.length > maxLength) {
|
|
27
|
+
display = "..." + display.slice(-maxLength + 3);
|
|
28
|
+
}
|
|
29
|
+
return display;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function clearLine(): void {
|
|
33
|
+
process.stdout.write("\r\x1b[K");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function formatDuration(ms: number): string {
|
|
37
|
+
if (ms < 1000) return `${ms}ms`;
|
|
38
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
39
|
+
}
|