UNPKG

@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
'use strict'; 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;