Skip to content

Commit

Permalink
build: linux binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarnadas committed Jan 25, 2019
1 parent 0efc6f8 commit d92410d
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 119 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
src/proto/*
src/declarations/*
src/declarations/*
compile/uws*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

/node_modules/
/dist/
/compile/index.js
/compile/*.js
/compile/net64plus-server*
/.idea/
/coverage/
*.exe
Expand Down
69 changes: 41 additions & 28 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
const nexe = require('nexe')
const fs = require('fs')
const path = require('path')

fs.writeFileSync(
'./compile/index.js',
String(fs.readFileSync('./compile/index.js')).replace('./uws_win32_57.node', 'require("./uws_win32_57.node")')
)
fs.writeFileSync(
'./compile/index.js',
String(fs.readFileSync('./compile/index.js'))
.replace(
'./build/Release/farmhash',
'module.exports = require("./farmhash.node");'
)
)
const supportedPlatforms = [
[ 'win32', 'windows', 'x64' ],
[ 'linux', 'linux', 'x64' ]
]

nexe.compile({
input: './compile/index.js',
output: 'net64plus-server',
target: 'windows-x64-8.9.4',
native: {
uws: {
additionalFiles: [
'./compile/uws_win32_57.node'
]
},
farmhash: {
additionalFiles: [
'./compile/farmhash.node'
]
for (const [ platform, platformName, arch ] of supportedPlatforms) {
build(platform, platformName, arch)
}

function build (platform, platformName, arch) {
const buildPath = `./compile/index_${platform}-${arch}.js`

fs.writeFileSync(
buildPath,
String(fs.readFileSync('./compile/index.js'))
.replace(/ \.\/uws_/g, ` require("./uws_`)
.replace(/\.node;/g, `.node");`)
.replace(/\.node /g, `.node") `)
.replace(
`./build/Release/farmhash`,
`module.exports = require("./farmhash.node_${platform}_57");`
)
)

nexe.compile({
input: buildPath,
output: path.join('compile', `net64plus-server_${platform}-${arch}`),
target: `${platformName}-${arch}-8.15.0`,
native: {
uws: {
additionalFiles: [
`./compile/uws_${platform}_57.node`
]
},
farmhash: {
additionalFiles: [
'./compile/farmhash.node'
]
}
}
}
})
})
}
Binary file removed compile/farmhash/build/Release/farmhash.node
Binary file not shown.
82 changes: 0 additions & 82 deletions compile/farmhash/index.js

This file was deleted.

Binary file added compile/farmhash_linux_57.node
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion compile/uws.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const native = require('./uws_win32_57.node')
const native = require(`./uws_${process.platform}_57.node`);
const http = require('http');
const EventEmitter = require('events');
const EE_ERROR = 'Registering more than one listener to a WebSocket is not supported.';
Expand Down
Binary file added compile/uws_linux_57.node
Binary file not shown.
4 changes: 2 additions & 2 deletions src/WebSocketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from './proto/ServerClientMessage'

let WSServer: typeof WebSocket.Server
if (process.env.TARGET_ENV === 'win32') {
if (process.env.IS_EXECUTABLE) {
WSServer = require('../compile/uws').Server
} else {
WSServer = require('uws').Server
Expand Down Expand Up @@ -83,7 +83,7 @@ export class WebSocketServer {
if (passwordRequired) {
console.info('Password protection enabled')
}
if (process.env.TARGET_ENV === 'win32') {
if (process.env.IS_EXECUTABLE) {
console.info('Connect locally via direct connect 127.0.0.1\nTo accept external connections, your Port must be forwarded.\nTo join via LAN, others must use your LAN IP address: win + "cmd" > ipconfig > IPv4 Address or via Hamachi network and IP')
console.info('\nThis is a precompiled version of the Net64+ server. It has the limitation, that it cannot be displayed on the public server list. It is only meant to be used for user servers!\n')
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const UPDATE_INTERVAL = 32
const URL_IP_API = 'http://ip-api.com/json'

let settings = DEFAULT_SETTINGS
if (process.env.TARGET_ENV !== 'win32') {
if (!process.env.IS_EXECUTABLE) {
try {
settings = JSON.parse(fs.readFileSync(path.join(__dirname, '../settings.json'), {
encoding: 'utf8'
Expand Down
6 changes: 3 additions & 3 deletions webpack.compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = [
NODE_ENV: 'production',
VERSION: process.env.npm_package_version,
COMPAT_VERSION: process.env.npm_package_compatVersion,
TARGET_ENV: 'win32',
IS_EXECUTABLE: true,
MAJOR: major,
MINOR: minor
}),
Expand All @@ -31,7 +31,7 @@ module.exports = [
resolve: {
extensions: [ '.js', '.ts', '.json' ]
},
externals: /^.*(uws_win32|Release\/farmhash).*$/,
externals: /^.*(uws_|Release\/farmhash).*$/,
module: {
loaders: [
{
Expand All @@ -45,7 +45,7 @@ module.exports = [
presets: [
['env', {
targets: {
node: 'current'
node: '8.15.0'
}
}]
]
Expand Down

0 comments on commit d92410d

Please sign in to comment.