1
0
mirror of https://github.com/c9fe/22120.git synced 2024-07-14 23:32:22 +02:00
22120/global-run.cjs
2023-07-23 10:16:35 +08:00

25 lines
732 B
JavaScript
Executable File

#!/usr/bin/env node
const os = require('os');
const { spawn } = require('child_process');
// Checking if node_modules directory exists
const fs = require('fs');
const path = require('path');
if (!fs.existsSync(path.join(process.cwd(), 'node_modules'))) {
spawn('npm', ['i'], { stdio: 'inherit' });
}
// Getting the total system memory
const totalMemory = os.totalmem();
// Allocating 90% of the total memory
const memoryAllocation = Math.floor((totalMemory / (1024 * 1024)) * 0.8); // Converted bytes to MB and took 90% of it
console.log(`Index can use up to: ${memoryAllocation}MB RAM`);
// Running the application
spawn('node', [`--max-old-space-size=${memoryAllocation}`, 'build/diskernet.mjs'], { stdio: 'inherit' });