Initial upload: AI Context Generator CLI with TypeScript implementation
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
39
app/ai-context-generator-cli/src/utils/cli.ts
Normal file
39
app/ai-context-generator-cli/src/utils/cli.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import * as path from 'path';
|
||||
|
||||
export class CLIUtils {
|
||||
static resolveDirectory(dir: string): string {
|
||||
if (path.isAbsolute(dir)) {
|
||||
return dir;
|
||||
}
|
||||
return path.resolve(process.cwd(), dir);
|
||||
}
|
||||
|
||||
static resolveOutputPath(
|
||||
output: string,
|
||||
format: 'json' | 'yaml'
|
||||
): string {
|
||||
if (path.isAbsolute(output)) {
|
||||
return output;
|
||||
}
|
||||
|
||||
if (!output.endsWith(`.${format}`)) {
|
||||
return `${output}.${format}`;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
static sanitizePattern(pattern: string): string {
|
||||
return pattern
|
||||
.replace(/\*/g, '.*')
|
||||
.replace(/\?/g, '.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user