know-thy-build 0.1.0 → 0.2.0

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.
Files changed (2) hide show
  1. package/bin/cli.js +24 -18
  2. package/package.json +2 -2
package/bin/cli.js CHANGED
@@ -10,11 +10,10 @@ import {
10
10
  import { dirname, join } from "path";
11
11
  import { fileURLToPath } from "url";
12
12
  import { createInterface } from "readline";
13
+ import { homedir } from "os";
13
14
 
14
15
  const __dirname = dirname(fileURLToPath(import.meta.url));
15
16
  const templatesDir = join(__dirname, "..", "templates");
16
- const targetDir = process.cwd();
17
- const COMMANDS_DIR = join(targetDir, ".claude", "commands");
18
17
 
19
18
  const LANG_OPTIONS = [
20
19
  { key: "en", label: "English" },
@@ -59,7 +58,6 @@ async function askLanguage() {
59
58
  return custom || LANG_OPTIONS[0].label;
60
59
  }
61
60
 
62
- // Try matching by key or label
63
61
  const lower = answer.toLowerCase();
64
62
  const match = LANG_OPTIONS.find(
65
63
  (o) => o.key === lower || o.label.toLowerCase().startsWith(lower)
@@ -67,9 +65,13 @@ async function askLanguage() {
67
65
  return match ? match.label : answer;
68
66
  }
69
67
 
70
- function install(lang) {
71
- if (!existsSync(COMMANDS_DIR)) {
72
- mkdirSync(COMMANDS_DIR, { recursive: true });
68
+ function install(lang, global) {
69
+ const commandsDir = global
70
+ ? join(homedir(), ".claude", "commands")
71
+ : join(process.cwd(), ".claude", "commands");
72
+
73
+ if (!existsSync(commandsDir)) {
74
+ mkdirSync(commandsDir, { recursive: true });
73
75
  }
74
76
 
75
77
  const templates = readdirSync(templatesDir).filter((f) => f.endsWith(".md"));
@@ -78,14 +80,15 @@ function install(lang) {
78
80
  const src = join(templatesDir, file);
79
81
  let content = readFileSync(src, "utf-8");
80
82
  content = content.replaceAll("{{LANG}}", lang);
81
- const dest = join(COMMANDS_DIR, file);
83
+ const dest = join(commandsDir, file);
82
84
  writeFileSync(dest, content, "utf-8");
83
85
  }
84
86
 
87
+ const scope = global ? "globally (~/.claude/commands/)" : "in this project";
85
88
  console.log(`
86
- Done! (${lang})
89
+ Done! Installed ${scope} (${lang})
87
90
 
88
- Open Claude Code in this project and run:
91
+ Open Claude Code and run:
89
92
 
90
93
  /know-thy-build
91
94
  `);
@@ -94,22 +97,24 @@ function install(lang) {
94
97
  // --- Main ---
95
98
 
96
99
  const args = process.argv.slice(2);
97
- const command = args[0];
98
100
 
99
- if (command === "--help" || command === "-h") {
101
+ if (args.includes("--help") || args.includes("-h")) {
100
102
  console.log(`
101
- know-thy-build - Socratic project project definition tool
103
+ know-thy-build - Socratic project definition tool
102
104
 
103
105
  Usage:
104
- npx know-thy-build Interactive setup
106
+ npx know-thy-build Install in current project
107
+ npx know-thy-build --global Install globally (~/.claude/commands/)
105
108
  npx know-thy-build --lang ko Skip language prompt
106
109
 
107
- Language shortcuts: ko, en, ja, zh, es, fr, de, pt
110
+ Options:
111
+ --global, -g Install to ~/.claude/commands/ (available in all projects)
112
+ --lang, -l Language shortcut: ko, en, ja, zh, es, fr, de, pt
108
113
  `);
109
114
  process.exit(0);
110
115
  }
111
116
 
112
- if (command === "--version" || command === "-v") {
117
+ if (args.includes("--version") || args.includes("-v")) {
113
118
  const pkg = JSON.parse(
114
119
  readFileSync(join(__dirname, "..", "package.json"), "utf-8")
115
120
  );
@@ -117,7 +122,8 @@ if (command === "--version" || command === "-v") {
117
122
  process.exit(0);
118
123
  }
119
124
 
120
- // If --lang provided, skip prompt
125
+ const global = args.includes("--global") || args.includes("-g");
126
+
121
127
  let lang = null;
122
128
  for (let i = 0; i < args.length; i++) {
123
129
  if (args[i] === "--lang" || args[i] === "-l") {
@@ -133,7 +139,7 @@ for (let i = 0; i < args.length; i++) {
133
139
  if (lang) {
134
140
  const lower = lang.toLowerCase();
135
141
  const match = LANG_OPTIONS.find((o) => o.key === lower);
136
- install(match ? match.label : lang);
142
+ install(match ? match.label : lang, global);
137
143
  } else {
138
- askLanguage().then((chosen) => install(chosen));
144
+ askLanguage().then((chosen) => install(chosen, global));
139
145
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "know-thy-build",
3
- "version": "0.1.0",
4
- "description": "Socratic project constitution generator for Claude Code",
3
+ "version": "0.2.0",
4
+ "description": "Socratic project definition tool for Claude Code",
5
5
  "bin": {
6
6
  "know-thy-build": "./bin/cli.js"
7
7
  },