First commit
This commit is contained in:
149
start.js
Normal file
149
start.js
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2020, 2023, The Unified Company.
|
||||
|
||||
This code is part of Unify.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the ESA Software Community License - Strong Copyleft,
|
||||
|
||||
https://unifyjs.org
|
||||
|
||||
*/
|
||||
|
||||
import child_process from'child_process';
|
||||
|
||||
import { execSync } from'child_process';
|
||||
|
||||
import binaryName from "./framework/node_modules/esbuild/getBinaryName.js"
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import path from 'path';
|
||||
|
||||
import consoleColors from './framework/unify/consoleColors.js';
|
||||
|
||||
import colors from './framework/unify/consoleColors.js';
|
||||
|
||||
import cluster from 'cluster';
|
||||
|
||||
|
||||
const originalEmit = process.emit;
|
||||
process.emit = function (name, data, ...args) {
|
||||
if (
|
||||
name === `warning` &&
|
||||
typeof data === `object` &&
|
||||
data.name === `ExperimentalWarning`
|
||||
//if you want to only stop certain messages, test for the message here:
|
||||
//&& data.message.includes(`Fetch API`)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return originalEmit.apply(process, arguments);
|
||||
};
|
||||
|
||||
|
||||
class boatLoader{
|
||||
|
||||
async cmd( command ) {
|
||||
|
||||
var imported = await import( command );
|
||||
|
||||
return imported;
|
||||
|
||||
}
|
||||
|
||||
async esBuild() {
|
||||
|
||||
var options = new Object();
|
||||
|
||||
options.stdio = 'pipe';
|
||||
|
||||
var args = new Array();
|
||||
|
||||
|
||||
args.push("--bundle")
|
||||
|
||||
args.push('framework/client/index.js')
|
||||
|
||||
args.push("--outfile=assets/bundle.js")
|
||||
|
||||
args.push("--keep-names")
|
||||
|
||||
//args.push('--external:fs, better-sqlite3, process')
|
||||
|
||||
args.push('--format=esm')
|
||||
|
||||
//console.log(binaryName, args.join(" "))
|
||||
|
||||
console.log("\n\n Bundling application, This can take a while, Please wait...\n\n");
|
||||
|
||||
var child = child_process.spawnSync( binaryName, args, options );
|
||||
|
||||
if( child.error ) {
|
||||
|
||||
if( child.error.code == "EACCES" ) {
|
||||
|
||||
console.log( "\n\n" )
|
||||
console.log( " EsBuild binary cannot be accessed." );
|
||||
console.log( " Please perform an: \n\n" );
|
||||
|
||||
console.log( consoleColors.green( " sudo chmod 755 " + binaryName), "\n\n\n\n" );
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
async startServer() {
|
||||
|
||||
var proceed = true;
|
||||
|
||||
if( cluster.isMaster ) {
|
||||
|
||||
var cacheManager = await import( './framework/server/scripts/cacheManager.js' );
|
||||
|
||||
var cache = new cacheManager.default();
|
||||
|
||||
await cache.start();
|
||||
|
||||
|
||||
var config = await import("./framework/configs/config.js")
|
||||
|
||||
|
||||
|
||||
if( config.default.mode == "production" ) {
|
||||
|
||||
proceed = await this.esBuild();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( proceed ) {
|
||||
|
||||
import( './framework/server/index.js' );
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//console.log(colors.green( "start.js" ));
|
||||
|
||||
var instance = new boatLoader();
|
||||
|
||||
await instance.startServer();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user