| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- const fs = require('fs');
- const os = require('os');
- const path = require('path');
- const pkg = require('./package.json');
- const config = require('./ssb_config');
- const updater = require('../backend/updater.js');
- let printed = false;
- let checkedForUpdate = false;
- function getModules() {
- const nodeModulesPath = path.resolve(__dirname, 'node_modules');
- try {
- return fs.readdirSync(nodeModulesPath)
- .filter(m => fs.existsSync(path.join(nodeModulesPath, m, 'package.json')));
- } catch {
- return [];
- }
- }
- const colors = {
- blue: '\x1b[38;5;33m',
- yellow: '\x1b[38;5;226m',
- orange: '\x1b[38;5;214m',
- cyan: '\x1b[36m',
- reset: '\x1b[0m'
- };
- async function checkForUpdate() {
- if (checkedForUpdate) return;
- checkedForUpdate = true;
- const updateFlagPath = path.join(__dirname, '../server/.update_required');
- if (fs.existsSync(updateFlagPath)) {
- fs.unlinkSync(updateFlagPath);
- }
- await updater.getRemoteVersion();
- }
- async function printMetadata(mode, modeColor = colors.cyan) {
- if (printed) return;
- printed = true;
- const modules = getModules();
- const version = pkg.version;
- const name = pkg.name;
- const logLevel = config.logging?.level || 'info';
- const publicKey = config.keys?.public || '';
- console.log("=========================");
- console.log(`Running mode: ${modeColor}${mode}${colors.reset}`);
- console.log("=========================");
- console.log(`- Package: ${colors.blue}${name} ${colors.yellow}[Version: ${version}]${colors.reset}`);
- console.log("- Logging Level:", logLevel);
- console.log(`- Oasis ID: [ ${colors.orange}@${publicKey}${colors.reset} ]`);
- const ifaces = os.networkInterfaces();
- const isOnline = Object.values(ifaces).some(list =>
- list && list.some(i => !i.internal && i.family === 'IPv4')
- );
- console.log(`- Mode: ${isOnline ? 'online' : 'offline'}`);
- console.log("");
- console.log("=========================");
- console.log("Modules loaded: [", modules.length, "]");
- console.log("=========================");
- // Check for updates
- await checkForUpdate();
- console.log("=========================");
- }
- module.exports = {
- printMetadata,
- colors
- };
|