kawkab-frontend
Version:
Kawkab frontend is a frontend library for the Kawkab framework
85 lines (84 loc) • 3.69 kB
JavaScript
import { networkInterfaces } from 'os';
function getNetworkIP() {
if (typeof window !== 'undefined') {
return '0.0.0.0';
}
const interfaces = networkInterfaces();
for (const name of Object.keys(interfaces)) {
const iface = interfaces[name];
if (iface) {
for (const alias of iface) {
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
return alias.address;
}
}
}
}
return '0.0.0.0';
}
export const customMessages = {
startup: {
title: (name = 'Kawkab') => `🚀 ${name} - Development System`,
subtitle: (env = 'Development Environment') => `👋 Welcome to the ${env}`,
local: (port = 3000) => `📍 Local Address: http://localhost:${port}/`,
network: (port = 3000) => `🌐 Network Address: http://${getNetworkIP()}:${port}/`,
ready: () => '⚡ Ready for Development!'
},
nodemon: {
start: (server = 'Server') => `🚀 Starting ${server}...`,
restart: (server = 'Server') => `🔄 Restarting ${server}...`,
crash: (error = 'Error') => `💥 ${error} Occurred!`,
exit: (server = 'Server') => `👋 Shutting Down ${server}`,
watching: (files = 'File Changes') => `👁️ Watching for ${files}...`
},
vite: {
configLoaded: (config = 'Vite Configuration') => `🎯 ${config} Loaded Successfully!`,
buildStart: (process = 'Build Process') => `🔨 Starting ${process}...`,
buildEnd: (result = 'Build') => `✅ ${result} Completed Successfully!`,
serverReady: (server = 'Development Server') => `🌟 ${server} Started Successfully!`,
hmr: (type = 'Hot Module Replacement') => `🔄 ${type}...`
},
errors: {
buildFailed: (reason = 'Build Failed') => `❌ ${reason}`,
serverError: (error = 'Server Error') => `💥 ${error}`,
fileNotFound: (file = 'File Not Found') => `📁 ${file}`
},
success: {
buildComplete: (result = 'Build') => `🎉 ${result} Completed Successfully!`,
serverRunning: (server = 'Server') => `✅ ${server} Running Normally`,
filesGenerated: (count = 'Files') => `📝 ${count} Generated Successfully`
}
};
export function printWelcomeMessage(projectName = 'Kawkab', port) {
const actualPort = port || parseInt(process.env.KAWKAB_APP_PORT || '8080');
console.log('\n' + '='.repeat(50));
console.log(customMessages.startup.title(projectName));
console.log(customMessages.startup.subtitle());
console.log(customMessages.startup.local(actualPort));
console.log(customMessages.startup.network(actualPort));
console.log(customMessages.startup.ready());
console.log('='.repeat(50) + '\n');
}
export function printStatusMessage(type, message, timestamp = null) {
const time = timestamp || new Date().toLocaleTimeString('en-US');
console.log(`[${time}] ${message}`);
}
export function getSystemInfo() {
return {
platform: process.platform,
nodeVersion: process.version,
workingDir: process.cwd(),
memory: process.memoryUsage(),
uptime: process.uptime()
};
}
export function printSystemInfo() {
const info = getSystemInfo();
console.log('📊 System Information:');
console.log(` Operating System: ${info.platform}`);
console.log(` Node.js Version: ${info.nodeVersion}`);
console.log(` Working Directory: ${info.workingDir}`);
console.log(` Memory Usage: ${Math.round(info.memory.heapUsed / 1024 / 1024)}MB`);
console.log(` Uptime: ${Math.round(info.uptime)}s`);
console.log('');
}