Skip to content

Commit

Permalink
WIP logo/terminal stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArcaneBrony committed Oct 27, 2024
1 parent fc38480 commit 4e12fbd
Show file tree
Hide file tree
Showing 19 changed files with 1,690 additions and 48 deletions.
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 36 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachSystem flake-utils.lib.allSystems (system:
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachSystem flake-utils.lib.allSystems (
system:
let
pkgs = import nixpkgs {
inherit system;
};
hashesFile = builtins.fromJSON (builtins.readFile ./hashes.json);
lib = pkgs.lib;
in rec {
in
rec {
packages.default = pkgs.buildNpmPackage {
pname = "spacebar-server-ts";
name = "spacebar-server-ts";
Expand All @@ -41,27 +48,35 @@
npm prune --omit dev --no-save $npmInstallFlags "''${npmInstallFlagsArray[@]}" $npmFlags "''${npmFlagsArray[@]}"
find node_modules -maxdepth 1 -type d -empty -delete
mkdir -p $out/node_modules/
cp -r node_modules/* $out/node_modules/
cp -r dist/ $out/node_modules/@spacebar
#mkdir -p $out/node_modules/
#cp -r node_modules/* $out/node_modules/
#cp -r dist/ $out/node_modules/@spacebar
#for i in dist/**/start.js
#do
# makeWrapper ${pkgs.nodejs-slim}/bin/node $out/bin/start-`dirname ''${i/dist\//}` --prefix NODE_PATH : $out/node_modules --add-flags $out/node_modules/@spacebar`dirname ''${i/dist/}`/start.js
#done
#set +x
#substituteInPlace package.json --replace 'dist/' 'node_modules/@spacebar/'
#find $out/node_modules/@spacebar/ -type f -name "*.js" | while read srcFile; do
# echo Patching imports in ''${srcFile/$out\/node_modules\/@spacebar//}...
# substituteInPlace $srcFile --replace 'require("./' 'require(__dirname + "/'
# substituteInPlace $srcFile --replace 'require("../' 'require(__dirname + "/../'
# substituteInPlace $srcFile --replace ', "assets"' ', "..", "assets"'
# #substituteInPlace $srcFile --replace 'require("@spacebar/' 'require("
#done
#set -x
#cp -r assets/ $out/
#cp package.json $out/
#rm -v $out/assets/openapi.json
##rm -v $out/assets/schemas.json
mkdir -p $out
cp -r assets dist node_modules package.json $out/
for i in dist/**/start.js
do
makeWrapper ${pkgs.nodejs-slim}/bin/node $out/bin/start-`dirname ''${i/dist\//}` --prefix NODE_PATH : $out/node_modules --add-flags $out/node_modules/@spacebar`dirname ''${i/dist/}`/start.js
makeWrapper ${pkgs.nodejs-slim}/bin/node $out/bin/start-`dirname ''${i/dist\//}` --prefix NODE_PATH : $out/node_modules --add-flags $out/$i
done
set +x
substituteInPlace package.json --replace 'dist/' 'node_modules/@spacebar/'
find $out/node_modules/@spacebar/ -type f -name "*.js" | while read srcFile; do
echo Patching imports in ''${srcFile/$out\/node_modules\/@spacebar//}...
substituteInPlace $srcFile --replace 'require("./' 'require(__dirname + "/'
substituteInPlace $srcFile --replace 'require("../' 'require(__dirname + "/../'
substituteInPlace $srcFile --replace ', "assets"' ', "..", "assets"'
#substituteInPlace $srcFile --replace 'require("@spacebar/' 'require("
done
set -x
cp -r assets/ $out/
cp package.json $out/
rm -v $out/assets/openapi.json
#rm -v $out/assets/schemas.json
#debug utils:
#cp $out/node_modules/@spacebar/ $out/build_output -r
Expand Down
2 changes: 1 addition & 1 deletion hashes.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"npmDepsHash": "sha256-KuKvhybhYGxC6oiVUxyjdEQD4xalXZ3OxT4KJ49ROAw="
"npmDepsHash": "sha256-zs6ViAc3w1g4/VTsrNajKL65gKFHbzvBUIxlDbEO690="
}
96 changes: 96 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,19 @@
"@spacebar/util": "dist/util"
},
"optionalDependencies": {
"@types/ref": "^0.0.32",
"@types/ref-struct": "^0.0.33",
"@yukikaze-bot/erlpack": "^1.0.1",
"erlpack": "^0.1.4",
"ioctl": "^2.0.2",
"jimp": "^0.22.12",
"mysql": "^2.18.1",
"node-ioctl": "*",
"nodemailer-mailgun-transport": "^2.1.5",
"nodemailer-mailjet-transport": "github:n0script22/nodemailer-mailjet-transport",
"nodemailer-sendgrid-transport": "github:Maria-Golomb/nodemailer-sendgrid-transport",
"pg": "^8.11.3",
"ref-struct": "^1.1.0",
"sqlite3": "^5.1.6"
}
}
4 changes: 2 additions & 2 deletions src/api/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ try {
}

if (cluster.isPrimary && process.env.NODE_ENV == "production") {
console.log(`Primary ${process.pid} is running`);
console.log(`Primary PID: ${process.pid}`);

// Fork workers.
for (let i = 0; i < cores; i++) {
cluster.fork();
}

cluster.on("exit", (worker) => {
console.log(`worker ${worker.process.pid} died, restart worker`);
console.log(`Worker ${worker.process.pid} died, restarting worker`);
cluster.fork();
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function main() {

Sentry.errorHandler(app);

console.log(`[Server] ${green(`listening on port ${bold(port)}`)}`);
console.log(`[Server] ${green(`Listening on port ${bold(port)}`)}`);
}

main().catch(console.error);
35 changes: 17 additions & 18 deletions src/bundle/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// process.env.MONGOMS_DEBUG = "true";
import moduleAlias from "module-alias";

moduleAlias(__dirname + "../../../package.json");

import "reflect-metadata";
Expand All @@ -26,8 +27,10 @@ import os from "os";
import { red, bold, yellow, cyan } from "picocolors";
import { initStats } from "./stats";
import { config } from "dotenv";

config();
import { execSync } from "child_process";
import { centerString, Logo } from "@spacebar/util";

const cores = process.env.THREADS ? parseInt(process.env.THREADS) : 1;

Expand All @@ -41,23 +44,19 @@ function getCommitOrFail() {

if (cluster.isPrimary) {
const commit = getCommitOrFail();

Logo.printLogo();
console.log(
bold(`
███████╗██████╗ █████╗ ██████╗███████╗██████╗ █████╗ ██████╗
██╔════╝██╔══██╗██╔══██╗██╔════╝██╔════╝██╔══██╗██╔══██╗██╔══██╗
███████╗██████╔╝███████║██║ █████╗ ██████╔╝███████║██████╔╝
╚════██║██╔═══╝ ██╔══██║██║ ██╔══╝ ██╔══██╗██╔══██║██╔══██╗
███████║██║ ██║ ██║╚██████╗███████╗██████╔╝██║ ██║██║ ██║
╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
spacebar-server | ${yellow(
`Pre-release (${
commit !== null
? commit.slice(0, 7)
: "Unknown (Git cannot be found)"
})`,
)}
${centerString(
`spacebar-server | ${yellow(
`Pre-release (${
commit !== null
? commit.slice(0, 7)
: "Unknown (Git cannot be found)"
})`,
)}`,
64,
)}
Commit Hash: ${
commit !== null
Expand All @@ -74,7 +73,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)

initStats();

console.log(`[Process] starting with ${cores} threads`);
console.log(`[Process] Starting with ${cores} threads`);

if (cores === 1) {
require("./Server");
Expand All @@ -87,7 +86,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
const delay = process.env.DATABASE?.includes("://") ? 0 : i * 1000;
setTimeout(() => {
cluster.fork();
console.log(`[Process] worker ${cyan(i)} started.`);
console.log(`[Process] Worker ${cyan(i)} started.`);
}, delay);
}

Expand All @@ -102,7 +101,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
cluster.on("exit", (worker) => {
console.log(
`[Worker] ${red(
`died with PID: ${worker.process.pid} , restarting ...`,
`PID ${worker.process.pid} died, restarting ...`,
)}`,
);
cluster.fork();
Expand Down
Loading

0 comments on commit 4e12fbd

Please sign in to comment.