separate lean server from socket server

cleanup_stuff
Jon Eugster 1 year ago
parent b239a5d3dc
commit 527f58e3a4

1
.gitignore vendored

@ -1,5 +1,4 @@
node_modules node_modules
games/
client/dist client/dist
games/ games/
server/.lake server/.lake

@ -297,8 +297,9 @@ cd lean4game
npm install npm install
``` ```
TODO: This is outdated!
If you are developing a game other than `Robo` or `NNG4`, adapt the If you are developing a game other than `Robo` or `NNG4`, adapt the
code at the beginning of `lean4game/server/index.mjs`: code at the beginning of `lean4game/relay/index.mjs`:
```typescript ```typescript
const games = { const games = {
"g/hhu-adam/robo": { "g/hhu-adam/robo": {

@ -2,7 +2,7 @@
module.exports = { module.exports = {
apps : [{ apps : [{
name : "lean4game", name : "lean4game",
script : "server/index.mjs", script : "relay/index.mjs",
env: { env: {
LEAN4GAME_GITHUB_USER: "", LEAN4GAME_GITHUB_USER: "",
LEAN4GAME_GITHUB_TOKEN: "", LEAN4GAME_GITHUB_TOKEN: "",

@ -63,13 +63,13 @@
}, },
"scripts": { "scripts": {
"start": "concurrently -n server,client -c blue,green \"npm run start_server\" \"npm run start_client\"", "start": "concurrently -n server,client -c blue,green \"npm run start_server\" \"npm run start_client\"",
"start_server": "cd server && lake build && cross-env NODE_ENV=development nodemon -e mjs --exec \"node ./index.mjs\"", "start_server": "(cd server && lake build) && (cd relay && cross-env NODE_ENV=development nodemon -e mjs --exec \"node ./index.mjs\")",
"start_client": "cross-env NODE_ENV=development vite --host", "start_client": "cross-env NODE_ENV=development vite --host",
"build": "npm run build_server && npm run build_client", "build": "npm run build_server && npm run build_client",
"preview": "vite preview", "preview": "vite preview",
"build_server": "cd server && lake build", "build_server": "cd server && lake build",
"build_client": "cross-env NODE_ENV=production vite build", "build_client": "cross-env NODE_ENV=production vite build",
"production": "cross-env NODE_ENV=production node server/index.mjs" "production": "cross-env NODE_ENV=production node relay/index.mjs"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [

@ -79,17 +79,17 @@ async function doImport (owner, repo, id) {
artifactId = artifact.id artifactId = artifact.id
const url = artifact.archive_download_url const url = artifact.archive_download_url
// Make sure the download folder exists // Make sure the download folder exists
if (!fs.existsSync(`${__dirname}/../games`)){ if (!fs.existsSync(path.join(__dirname, "..", "games"))){
fs.mkdirSync(`${__dirname}/../games`); fs.mkdirSync(path.join(__dirname, "..", "games"));
} }
if (!fs.existsSync(`${__dirname}/../games/tmp`)){ if (!fs.existsSync(path.join(__dirname, "..", "games", "tmp"))){
fs.mkdirSync(`${__dirname}/../games/tmp`); fs.mkdirSync(path.join(__dirname, "..", "games", "tmp"));
} }
progress[id].output += `Download from ${url}\n` progress[id].output += `Download from ${url}\n`
await download(id, url, `${__dirname}/../games/tmp/${owner.toLowerCase()}_${repo.toLowerCase()}_${artifactId}.zip`) await download(id, url, path.join(__dirname, "..", "games", "tmp", `${owner.toLowerCase()}_${repo.toLowerCase()}_${artifactId}.zip`))
progress[id].output += `Download finished.\n` progress[id].output += `Download finished.\n`
await runProcess(id, "/bin/bash", [`${__dirname}/unpack.sh`, artifactId, owner.toLowerCase(), repo.toLowerCase()], `${__dirname}/..`) await runProcess(id, "/bin/bash", [path.join(__dirname, "unpack.sh"), artifactId, owner.toLowerCase(), repo.toLowerCase()], path.join(__dirname, ".."))
// let manifest = fs.readFileSync(`tmp/artifact_${artifactId}_inner/manifest.json`); // let manifest = fs.readFileSync(`tmp/artifact_${artifactId}_inner/manifest.json`);
@ -110,8 +110,8 @@ async function doImport (owner, repo, id) {
} finally { } finally {
// clean-up temp. files // clean-up temp. files
if (artifactId) { if (artifactId) {
fs.rmSync(`${__dirname}/../games/tmp/${owner}_${repo}_${artifactId}.zip`, {force: true, recursive: false}); fs.rmSync(path.join(__dirname, "..", "games", "tmp", `${owner}_${repo}_${artifactId}.zip`), {force: true, recursive: false});
fs.rmSync(`${__dirname}/../games/tmp/${owner}_${repo}_${artifactId}`, {force: true, recursive: true}); fs.rmSync(path.join(__dirname, "..", "games", "tmp", `${owner}_${repo}_${artifactId}`), {force: true, recursive: true});
} }
progress[id].done = true progress[id].done = true
} }

@ -35,7 +35,7 @@ router.get('/import/status/:owner/:repo', importStatus)
router.get('/import/trigger/:owner/:repo', importTrigger) router.get('/import/trigger/:owner/:repo', importTrigger)
const server = app const server = app
.use(express.static(path.join(__dirname, '../client/dist/'))) // TODO: add a dist folder from inside the game .use(express.static(path.join(__dirname, '..', 'client', 'dist'))) // TODO: add a dist folder from inside the game
.use('/data/g/:owner/:repo/*', (req, res, next) => { .use('/data/g/:owner/:repo/*', (req, res, next) => {
const owner = req.params.owner; const owner = req.params.owner;
const repo = req.params.repo const repo = req.params.repo
@ -103,7 +103,7 @@ function startServerProcess(owner, repo) {
} else { } else {
// If the game is built with `-Klean4game.local` there is no copy in the lake packages. // If the game is built with `-Klean4game.local` there is no copy in the lake packages.
serverProcess = cp.spawn("./gameserver", args, serverProcess = cp.spawn("./gameserver", args,
{ cwd: path.join(__dirname, ".lake", "build", "bin") }) { cwd: path.join(__dirname, "..", "server", ".lake", "build", "bin") })
} }
} else { } else {
serverProcess = cp.spawn("./bubblewrap.sh", serverProcess = cp.spawn("./bubblewrap.sh",
@ -111,7 +111,6 @@ function startServerProcess(owner, repo) {
{ cwd: __dirname }) { cwd: __dirname })
} }
serverProcess.on('error', error => serverProcess.on('error', error =>
console.error(`Launching Lean Server failed: ${error}`) console.error(`Launching Lean Server failed: ${error}`)
) )

@ -6,7 +6,7 @@ REPO=$3
# mkdir -p games # mkdir -p games
cd games cd games
pwd
# mkdir -p tmp # mkdir -p tmp
mkdir -p ${OWNER} mkdir -p ${OWNER}

3
server/.gitignore vendored

@ -1,3 +0,0 @@
build/
games/
.lake

@ -12,5 +12,5 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
}, },
"exclude": ["server"] "exclude": ["server", "relay"]
} }

@ -8,7 +8,7 @@ export default defineConfig({
//root: 'client/src', //root: 'client/src',
build: { build: {
// Relative to the root // Relative to the root
// Note: This has to match the path in `server/index.mjs` // Note: This has to match the path in `relay/index.mjs`
outDir: 'client/dist', outDir: 'client/dist',
}, },
plugins: [ plugins: [

Loading…
Cancel
Save