@investravis.com/hexo-goose-builder
Version:
An exploratory plugin that aims to introduce a theme builder for Hexo, which supports modular development in the theme building process and supports popular ESM scripts and TailwindCSS, etc.
136 lines (115 loc) โข 4.81 kB
JavaScript
;
const chalk = require('chalk');
const path = require('path');
const fs = require('fs');
class Banner {
constructor() {
this.version = this.getVersion();
this.author = 'Travis Tang';
this.title = '๐ฆข Hexo Goose Builder';
}
/**
* ่ทๅๆไปถ็ๆฌๅท
* ไผๅ
ไปpackage.json่ฏปๅ๏ผๅฆๆๅคฑ่ดฅๅไฝฟ็จ้ป่ฎคๅผ
*/
getVersion() {
try {
const packagePath = path.join(__dirname, '..', 'package.json');
if (fs.existsSync(packagePath)) {
const packageContent = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
return packageContent.version || '1.0.0';
}
} catch (error) {
// ๅฆๆ่ฏปๅๅคฑ่ดฅ๏ผ่ฟๅ้ป่ฎค็ๆฌ
}
return '1.0.0';
}
/**
* ๆ นๆฎๆง่กๆจกๅผ่ทๅๆจกๅผๆ่ฟฐๆๆฌ
* @param {string} mode - ๆง่กๆจกๅผ
* @returns {string} - ๆจกๅผๆ่ฟฐๆๆฌ
*/
getModeText(mode) {
const modeMap = {
'deploy': '้จ็ฝฒๆจกๅผ',
'generate': '็ๆๆจกๅผ',
'server': 'ๅผๅๆจกๅผ',
's': 'ๅผๅๆจกๅผ',
'g': '็ๆๆจกๅผ',
'd': '้จ็ฝฒๆจกๅผ'
};
return modeMap[mode] || `${mode}ๆจกๅผ`;
}
/**
* ๆพ็คบๆฌข่ฟbanner
* @param {string} mode - ๅฝๅๆง่กๆจกๅผ
* @param {Object} options - ๅฏ้ๅๆฐ
* @param {boolean} options.showModeOnly - ๆฏๅฆๅชๆพ็คบๆจกๅผไฟกๆฏ
* @param {string} options.customMessage - ่ชๅฎไนๆถๆฏ
*/
show(mode, options = {}) {
const { showModeOnly = false, customMessage } = options;
const modeText = this.getModeText(mode);
if (showModeOnly) {
console.log(chalk.blue(`[Theme Builder] ๅฝๅๆจกๅผ: ${modeText}`));
return;
}
const message = customMessage || `ๆญฃๅจๆๅปบๆจ็ไธป้ข็ปไปถ... (${modeText})`;
console.log(chalk.cyan(`
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
${this.title.padEnd(36)}
Version: ${this.version.padEnd(31)}
Author: ${this.author.padEnd(32)}
${message.padEnd(36)}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
`));
}
/**
* ๆพ็คบๅฎๆbanner
* @param {string} mode - ๅฝๅๆง่กๆจกๅผ
* @param {string} action - ๅฎๆ็ๅจไฝ๏ผๅฆ'็ผ่ฏ'ใ'้จ็ฝฒ'็ญ
*/
showComplete(mode, action = 'ๆๅปบ') {
const modeText = this.getModeText(mode);
console.log(chalk.green(`
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ${action}ๅฎๆ! (${modeText})
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
`));
}
/**
* ๆพ็คบ้่ฏฏbanner
* @param {string} mode - ๅฝๅๆง่กๆจกๅผ
* @param {string} error - ้่ฏฏไฟกๆฏ
*/
showError(mode, error) {
const modeText = this.getModeText(mode);
console.log(chalk.red(`
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๆๅปบๅคฑ่ดฅ! (${modeText})
${error.substring(0, 36).padEnd(36)}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
`));
}
/**
* ๆพ็คบ็ฎๆด็็ถๆไฟกๆฏ
* @param {string} mode - ๅฝๅๆง่กๆจกๅผ
* @param {string} status - ็ถๆไฟกๆฏ
* @param {string} type - ๆถๆฏ็ฑปๅ: 'info', 'success', 'warning', 'error'
*/
showStatus(mode, status, type = 'info') {
const modeText = this.getModeText(mode);
const colorMap = {
'info': chalk.blue,
'success': chalk.green,
'warning': chalk.yellow,
'error': chalk.red
};
const color = colorMap[type] || chalk.blue;
const icon = type === 'success' ? 'โ' :
type === 'warning' ? 'โ ' :
type === 'error' ? 'โ' : 'โน';
console.log(color(`[Theme Builder] ${icon} ${status} (${modeText})`));
}
}
module.exports = Banner;