claude-code-templates 1.4.1 ā 1.4.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/package.json +1 -1
- package/src/command-stats.js +90 -21
package/package.json
CHANGED
package/src/command-stats.js
CHANGED
|
@@ -106,23 +106,28 @@ async function analyzeCommands(targetDir = process.cwd()) {
|
|
|
106
106
|
*/
|
|
107
107
|
function displayCommandStats(analysis) {
|
|
108
108
|
console.log(chalk.cyan('\nš Claude Code Command Analysis'));
|
|
109
|
-
|
|
109
|
+
|
|
110
|
+
// Calculate header width dynamically
|
|
111
|
+
const headerWidth = analysis.commands.length > 0 ?
|
|
112
|
+
Math.min(Math.max(...analysis.commands.map(cmd => cmd.name.length)), 25) + 60 : 80;
|
|
113
|
+
|
|
114
|
+
console.log(chalk.gray('ā'.repeat(headerWidth)));
|
|
110
115
|
|
|
111
116
|
if (!analysis.exists) {
|
|
112
117
|
console.log(chalk.yellow('ā ļø ' + analysis.message));
|
|
113
118
|
console.log(chalk.blue('\nš” Run the setup first: npx claude-code-templates'));
|
|
114
|
-
return;
|
|
119
|
+
return false; // Indicate no .claude directory
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
if (analysis.error) {
|
|
118
123
|
console.log(chalk.red('ā ' + analysis.error));
|
|
119
|
-
return;
|
|
124
|
+
return false;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
if (analysis.commands.length === 0) {
|
|
123
128
|
console.log(chalk.yellow('ā ļø ' + analysis.message));
|
|
124
129
|
console.log(chalk.blue('\nš” No commands found to analyze'));
|
|
125
|
-
return;
|
|
130
|
+
return false; // Indicate no commands found
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
// Summary
|
|
@@ -131,38 +136,95 @@ function displayCommandStats(analysis) {
|
|
|
131
136
|
console.log(chalk.green(`ā
Found ${analysis.total} command file(s) (${totalSizeKB} KB, ~${totalTokens} tokens total)`));
|
|
132
137
|
console.log('');
|
|
133
138
|
|
|
139
|
+
// Calculate dynamic column widths based on content
|
|
140
|
+
const maxNameLength = Math.max(
|
|
141
|
+
7, // Minimum width for "Command"
|
|
142
|
+
Math.max(...analysis.commands.map(cmd => cmd.name.length))
|
|
143
|
+
);
|
|
144
|
+
const nameWidth = Math.min(maxNameLength, 25); // Cap at 25 characters
|
|
145
|
+
|
|
134
146
|
// Table header
|
|
135
147
|
const header = chalk.bold.blue(
|
|
136
|
-
'Command'.padEnd(
|
|
137
|
-
'Size'.padEnd(
|
|
138
|
-
'Lines'.padEnd(
|
|
139
|
-
'Words'.padEnd(
|
|
140
|
-
'Tokens'.padEnd(
|
|
148
|
+
'Command'.padEnd(nameWidth) + ' ā ' +
|
|
149
|
+
'Size'.padEnd(6) + ' ā ' +
|
|
150
|
+
'Lines'.padEnd(5) + ' ā ' +
|
|
151
|
+
'Words'.padEnd(5) + ' ā ' +
|
|
152
|
+
'Tokens (aprox)'.padEnd(13) + ' ā ' +
|
|
141
153
|
'Last Modified'
|
|
142
154
|
);
|
|
143
155
|
console.log(header);
|
|
144
|
-
|
|
156
|
+
|
|
157
|
+
// Create separator line with proper spacing
|
|
158
|
+
const separatorLength = nameWidth + 6 + 5 + 5 + 13 + 13 + 15; // Calculate total width
|
|
159
|
+
console.log(chalk.gray('ā'.repeat(separatorLength)));
|
|
145
160
|
|
|
146
161
|
// Table rows
|
|
147
162
|
analysis.commands.forEach(cmd => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
163
|
+
// Truncate command name if too long and add ellipsis
|
|
164
|
+
let displayName = cmd.name;
|
|
165
|
+
if (displayName.length > nameWidth) {
|
|
166
|
+
displayName = displayName.substring(0, nameWidth - 3) + '...';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const sizeFormatted = `${(cmd.size / 1024).toFixed(1)}KB`.padEnd(6);
|
|
170
|
+
const linesFormatted = cmd.lines.toString().padEnd(5);
|
|
171
|
+
const wordsFormatted = cmd.wordCount.toString().padEnd(5);
|
|
172
|
+
const tokensFormatted = cmd.tokens.toString().padEnd(13);
|
|
152
173
|
const dateFormatted = cmd.lastModified.toLocaleDateString();
|
|
153
174
|
|
|
154
|
-
const row = chalk.white(
|
|
155
|
-
chalk.cyan(sizeFormatted) +
|
|
156
|
-
chalk.yellow(linesFormatted) +
|
|
157
|
-
chalk.green(wordsFormatted) +
|
|
158
|
-
chalk.magenta(tokensFormatted) +
|
|
175
|
+
const row = chalk.white(displayName.padEnd(nameWidth)) + chalk.gray(' ā ') +
|
|
176
|
+
chalk.cyan(sizeFormatted) + chalk.gray(' ā ') +
|
|
177
|
+
chalk.yellow(linesFormatted) + chalk.gray(' ā ') +
|
|
178
|
+
chalk.green(wordsFormatted) + chalk.gray(' ā ') +
|
|
179
|
+
chalk.magenta(tokensFormatted) + chalk.gray(' ā ') +
|
|
159
180
|
chalk.gray(dateFormatted);
|
|
160
181
|
|
|
161
182
|
console.log(row);
|
|
162
183
|
});
|
|
163
184
|
|
|
164
|
-
console.log(chalk.gray('ā'.repeat(
|
|
185
|
+
console.log(chalk.gray('ā'.repeat(separatorLength)));
|
|
165
186
|
console.log(chalk.bold(`Total: ${analysis.total} commands, ${totalSizeKB} KB, ~${totalTokens} tokens`));
|
|
187
|
+
return true; // Indicate commands were found and displayed
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Prompts user to setup Claude Code Templates when no commands are found
|
|
192
|
+
* @param {string} targetDir - Project directory
|
|
193
|
+
*/
|
|
194
|
+
async function promptSetupWhenNoCommands(targetDir) {
|
|
195
|
+
const inquirer = require('inquirer');
|
|
196
|
+
|
|
197
|
+
console.log(chalk.cyan('\nš Claude Code Templates Setup'));
|
|
198
|
+
console.log(chalk.gray('No Claude Code commands found in this project. You can set up Claude Code Templates to get started.'));
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
const { setupNow } = await inquirer.prompt([{
|
|
202
|
+
type: 'confirm',
|
|
203
|
+
name: 'setupNow',
|
|
204
|
+
message: 'Would you like to start the Claude Code Templates setup now?',
|
|
205
|
+
default: true,
|
|
206
|
+
prefix: chalk.blue('š¤')
|
|
207
|
+
}]);
|
|
208
|
+
|
|
209
|
+
if (!setupNow) {
|
|
210
|
+
console.log(chalk.yellow('āļø Setup skipped. Run "npx claude-code-templates" anytime to set up your project.'));
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
console.log(chalk.blue('\nš Starting Claude Code Templates setup...'));
|
|
215
|
+
console.log(chalk.gray('This will guide you through language and framework selection.\n'));
|
|
216
|
+
|
|
217
|
+
// Import and run the main setup function
|
|
218
|
+
const createClaudeConfig = require('./index');
|
|
219
|
+
await createClaudeConfig({ directory: targetDir });
|
|
220
|
+
|
|
221
|
+
return true;
|
|
222
|
+
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error(chalk.red('Error during setup:'), error.message);
|
|
225
|
+
console.log(chalk.blue('š” You can run setup manually with: npx claude-code-templates'));
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
166
228
|
}
|
|
167
229
|
|
|
168
230
|
/**
|
|
@@ -269,7 +331,13 @@ async function runCommandStats(options = {}) {
|
|
|
269
331
|
const analysis = await analyzeCommands(targetDir);
|
|
270
332
|
|
|
271
333
|
// Display results
|
|
272
|
-
displayCommandStats(analysis);
|
|
334
|
+
const hasCommands = displayCommandStats(analysis);
|
|
335
|
+
|
|
336
|
+
// If no commands found, offer to start setup
|
|
337
|
+
if (!hasCommands) {
|
|
338
|
+
await promptSetupWhenNoCommands(targetDir);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
273
341
|
|
|
274
342
|
// Prompt for optimization
|
|
275
343
|
await promptCommandOptimization(analysis, targetDir);
|
|
@@ -279,5 +347,6 @@ module.exports = {
|
|
|
279
347
|
analyzeCommands,
|
|
280
348
|
displayCommandStats,
|
|
281
349
|
promptCommandOptimization,
|
|
350
|
+
promptSetupWhenNoCommands,
|
|
282
351
|
runCommandStats
|
|
283
352
|
};
|