dscaffold
Version:
A TypeScript framework for scaffolding modular Discord bot projects with dynamic command and event loading
89 lines • 2.9 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
exports.capitalize = capitalize;
exports.toCamelCase = toCamelCase;
exports.toPascalCase = toPascalCase;
exports.toKebabCase = toKebabCase;
exports.ensureDir = ensureDir;
exports.copyTemplate = copyTemplate;
exports.writeFile = writeFile;
exports.readFile = readFile;
exports.pathExists = pathExists;
exports.validateProjectName = validateProjectName;
exports.getTemplatesDir = getTemplatesDir;
exports.getCurrentWorkingDir = getCurrentWorkingDir;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
class Logger {
static info(message) {
console.log(chalk_1.default.blue('ℹ'), message);
}
static success(message) {
console.log(chalk_1.default.green('✓'), message);
}
static warning(message) {
console.log(chalk_1.default.yellow('⚠'), message);
}
static error(message) {
console.log(chalk_1.default.red('✗'), message);
}
static spinner(text) {
return (0, ora_1.default)({
text,
spinner: 'dots',
});
}
}
exports.Logger = Logger;
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function toCamelCase(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, '');
}
function toPascalCase(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => {
return word.toUpperCase();
}).replace(/\s+/g, '');
}
function toKebabCase(str) {
return str
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/\s+/g, '-')
.toLowerCase();
}
async function ensureDir(dirPath) {
await fs_extra_1.default.ensureDir(dirPath);
}
async function copyTemplate(templatePath, targetPath) {
await fs_extra_1.default.copy(templatePath, targetPath);
}
async function writeFile(filePath, content) {
await ensureDir(path_1.default.dirname(filePath));
await fs_extra_1.default.writeFile(filePath, content, 'utf8');
}
async function readFile(filePath) {
return fs_extra_1.default.readFile(filePath, 'utf8');
}
async function pathExists(path) {
return fs_extra_1.default.pathExists(path);
}
function validateProjectName(name) {
const regex = /^[a-zA-Z0-9-_]+$/;
return regex.test(name) && name.length > 0 && name.length <= 50;
}
function getTemplatesDir() {
return path_1.default.join(__dirname, '../../templates');
}
function getCurrentWorkingDir() {
return process.cwd();
}
//# sourceMappingURL=index.js.map