@tsbb/typescript
Version:
TSBB is a zero-config CLI that helps you develop, test, and publish modern TypeScript project.
36 lines (35 loc) • 1.01 kB
JavaScript
import ts from 'typescript';
import fs from 'fs-extra';
import path from 'node:path';
export class Log {
data = [];
iconStr = '';
constructor() { }
/** show project name */
name() {
const dir = ts.sys.getCurrentDirectory();
const pkgPath = path.resolve(dir, 'package.json');
if (fs.existsSync(pkgPath)) {
const pkg = fs.readJSONSync(pkgPath);
if (pkg.name) {
this.data.unshift(`\x1b[35m${pkg.name}\x1b[0m`);
}
}
else {
this.data.unshift(`\x1b[35m${path.basename(dir)}\x1b[0m`);
}
return this;
}
icon(str) {
this.iconStr = str;
return this;
}
error(message, ...optionalParams) {
console.error(...[this.iconStr, ...this.data, message, ...optionalParams]);
return this;
}
success(message, ...optionalParams) {
console.info(...[this.iconStr, ...this.data, message, ...optionalParams]);
return this;
}
}