diff --git a/CHANGELOG b/CHANGELOG index a9588b7..c0f9549 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,21 @@ # nodeGame Changelog +# 7.1.0 +- New release, updated installer. + +# 7.0.4 +- Updated installer. +- Minor fixes. + +# 7.0.3 +- Minor, installation fixes. + +# 7.0.0 +- Dropped --phantoms option in launcher. +- More robust paths in launcher. +- Added nodeGameRoot path in launcher. +- Installer adapted to support alpha releases. + # 6.3.0 - Fixed installer getting stuck on versions and help. - Added installer option --no-games to skip installing default games. @@ -143,7 +159,7 @@ treatment for the game. # 2.0.2 - Fixed install.stable script. -- Fixing launcher options. +- Fixing launcher options. # 2.0.0 (current) - Added -s option to launcher. Starts the server in SSL mode. Can be empty (loads nodegame-server/ssl/), or a path to a SSL directory. diff --git a/bin/nodegame-installer.js b/bin/nodegame-installer.js index ddd51d9..91c0cfb 100755 --- a/bin/nodegame-installer.js +++ b/bin/nodegame-installer.js @@ -1,7 +1,7 @@ #!/usr/local/bin/node /** * # nodeGame Installer - * Copyright(c) 2011-2020 Stefano Balietti + * Copyright(c) 2011-2023 Stefano Balietti * MIT Licensed * * http://www.nodegame.org @@ -33,7 +33,7 @@ const warn = txt => { }; // const MAIN_MODULE = 'nodegame'; -const MAIN_MODULE = 'nodegame'; +let MAIN_MODULE = 'nodegame'; // All stable versions. // Versions below < 3 are not available. @@ -41,13 +41,15 @@ const STABLE_VERSIONS = { v3: '3.5.3', v4: '4.3.3', v5: '5.11.2', - v6: '6.3.0' + v6: '6.3.0', + v7: '7.1.0' + // v8: '8.0.0' }; const AVAILABLE_VERSIONS = Object.keys(STABLE_VERSIONS).concat(['dev']); // Installer default version. -const INSTALLER_VERSION = 'v6'; +const INSTALLER_VERSION = 'v7'; // If node_modules folders are detected, their paths (without node_modules) // is stored in here. @@ -81,6 +83,7 @@ var rl = readline.createInterface({ output: process.stdout }); +var alpha = false; var verbose = false; var nodeModulesExisting = false; var isDev = false; @@ -109,6 +112,17 @@ for (let i = 0; i < process.argv.length; i++) { isDev = true; requestedVersion = '@' + version; + // For testing alpha versions. + // MAIN_MODULE = 'nodegame-test'; + // version = '7.0.4'; + // requestedVersion = '@' + version; + // alpha = true; + } + else if (requestedVersion === 'alpha') { + // For testing alpha versions. + MAIN_MODULE = 'nodegame-test'; + requestedVersion = '@latest'; + alpha = true; } else { version = STABLE_VERSIONS[requestedVersion]; @@ -158,7 +172,7 @@ if ((doSSH || branch) && !isDev) { // nodeGame version. const VERSION = isDev ? "v" + version + '-dev' : "v" + version; -const NODEGAME_AND_VERSION = 'nodegame-' + VERSION; +const NODEGAME_AND_VERSION = 'nodegame-' + VERSION + (alpha ? '-alpha' : ''); const ROOT_DIR = process.cwd() const NODE_MODULES_DIR = path.resolve(ROOT_DIR, 'node_modules'); @@ -220,8 +234,8 @@ printInstallInfo(); // Check node version is. var nodeVersion = process.versions.node.split('.'); -if (parseInt(nodeVersion[0], 10) < 4) { - err('node version >= 4.x is required.\n' + +if (parseInt(nodeVersion[0], 10) < 10) { + err('node version >= 10.x is required.\n' + 'Please upgrade your Node.Js installation, ' + 'visit: http://nodejs.org'); installationAborted(); @@ -273,7 +287,7 @@ else checkParentNodeModules(); // Helper functions. /////////////////////////////////////////////////////////////////////////////// -function checkParentNodeModules(cb) { +function checkParentNodeModules() { parentNodeModules = getParentNodeModules(); // Check if a node_modules folder exists in any folder from the one above. @@ -423,10 +437,18 @@ function checkGitExists(cb) { function printNodeGameInfo() { log(); - log('*********************************************** '); - log('** WELCOME TO NODEGAME INSTALLER v' + version + - ' ** '); - log('*********************************************** '); + if (alpha) { + log('***************************************************** '); + log('** WELCOME TO NODEGAME INSTALLER v' + version + + (alpha ? '-alpha' : '') + ' ** '); + log('***************************************************** '); + } + else { + log('*********************************************** '); + log('** WELCOME TO NODEGAME INSTALLER v' + version + ' ** '); + log('*********************************************** '); + } + log(); log('nodeGame: fast, scalable JavaScript for online, large-scale,'); log('multiplayer, real-time games and experiments in the browser.'); @@ -443,13 +465,12 @@ function printNodeGameInfo() { } function printInstallInfo() { - let str; log(); log('----------------------------------------------'); log(); log('node version: ' + process.version); - str = 'nodeGame version: ' + VERSION; + let str = 'nodeGame version: ' + VERSION; if (branch) str += ' (' + branch + ')'; log(str); str = 'install directory: ' + INSTALL_DIR; @@ -518,18 +539,27 @@ function someMagic(cb) { if (!fs.existsSync(path.resolve(mainNgDir, 'private'))) { fs.mkdirSync(path.resolve(mainNgDir, 'private')); } + if (!fs.existsSync(path.resolve(mainNgDir, 'export'))) { + fs.mkdirSync(path.resolve(mainNgDir, 'export')); + } if (!doNotMoveInstall) { // Move nodegame folder outside node_modules. fs.renameSync(mainNgDir, INSTALL_DIR); - // Old npms put already all modules under nodegame. - if (!fs.existsSync(INSTALL_DIR_MODULES)) { - fs.renameSync(NODE_MODULES_DIR, - INSTALL_DIR_MODULES); + try { + // Old npms put already all modules under nodegame. + if (!fs.existsSync(INSTALL_DIR_MODULES)) { + fs.renameSync(NODE_MODULES_DIR, + INSTALL_DIR_MODULES); + } + else if (!nodeModulesExisting) { + fs.rmdirSync(NODE_MODULES_DIR); + } } - else if (!nodeModulesExisting) { - fs.rmdirSync(NODE_MODULES_DIR); + catch(e) { + let keep = nodeModulesExisting; + moveFolderSync(NODE_MODULES_DIR, INSTALL_DIR_MODULES, keep); } } @@ -630,9 +660,9 @@ function getAllGitModules(cb) { fs.renameSync(nodeModulesCopy, nodeModulesPath); } // Copy pre-commit hook. - copyFileSync(gitPrecommitHook, - path.resolve(modulePath, '.git', 'hooks', - 'pre-commit')); + fs.copyFileSync(gitPrecommitHook, + path.resolve(modulePath, '.git', 'hooks', + 'pre-commit')); counter--; if (counter == 0 && cb) cb(); }); @@ -935,74 +965,23 @@ function inArray(needle, haystack) { return false; } +function moveFolderSync(from, to, copy) { + if (!fs.existsSync(to)) fs.mkdirSync(to); + fs.readdirSync(from).forEach(element => { + let fileFrom = path.join(from, element); + let fileTo = path.join(to, element); -// Kudos. Adapted from: -// https://github.com/coderaiser/ -// fs-copy-file-sync/blob/master/lib/fs-copy-file-sync.js -function _copyFileSync(src, dest, flag) { - const SIZE = 65536; - - const COPYFILE_EXCL = 1; - const COPYFILE_FICLONE = 2; - const COPYFILE_FICLONE_FORCE = 4; - - const constants = { - COPYFILE_EXCL, - COPYFILE_FICLONE, - COPYFILE_FICLONE_FORCE, - }; - - const or = (a, b) => a | b; - const getValue = (obj) => (key) => obj[key]; - - const getMaxMask = (obj) => Object - .keys(obj) - .map(getValue(obj)) - .reduce(or); - - const MAX_MASK = getMaxMask(constants); - const isExcl = (flags) => flags & COPYFILE_EXCL; - - - const writeFlag = isExcl(flag) ? 'wx' : 'w'; - - const { - size, - mode, - } = fs.statSync(src); - - const fdSrc = fs.openSync(src, 'r'); - const fdDest = fs.openSync(dest, writeFlag, mode); - - const length = size < SIZE ? size : SIZE; - - let pos = 0; - const peaceSize = size < SIZE ? 0 : size % SIZE; - const offset = 0; - - let buffer = Buffer.allocUnsafe(length); - for (let i = 0; length + pos + peaceSize <= size; i++, pos = length * i) { - fs.readSync(fdSrc, buffer, offset, length, pos); - fs.writeSync(fdDest, buffer, offset, length, pos); - } - - if (peaceSize) { - const length = peaceSize; - buffer = Buffer.allocUnsafe(length); - fs.readSync(fdSrc, buffer, offset, length, pos); - fs.writeSync(fdDest, buffer, offset, length, pos); - } - - fs.closeSync(fdSrc); - fs.closeSync(fdDest); -} + let stats = fs.lstatSync(fileFrom); + if (stats.isFile() || stats.isSymbolicLink()) { + if (copy) fs.copyFileSync(fileFrom, fileTo); + else fs.renameSync(fileFrom, fileTo); + } + else { + moveFolderSync(fileFrom, fileTo); + } + }); + // ALl files moved, removed dir. + if (!copy) fs.rmdirSync(from); -function copyFileSync(from, to) { - if ('function' === typeof fs.copyFileSync) { - fs.copyFileSync(from, to); - } - else { - _copyFileSync(from, to); - } } diff --git a/launcher.js b/launcher.js index 783ff51..6251ed8 100644 --- a/launcher.js +++ b/launcher.js @@ -33,9 +33,6 @@ var sn; // ServerNode options. var options; -// Conf file for all variables. -var confFile; - // Other local options. var confDir, logDir, gamesDir, debug, infoQuery, runTests; var nClients, clientType, killServer, auth, wait, port; @@ -59,8 +56,6 @@ ignoredOptions = []; // Defaults. -confFile = null; - confDir = path.resolve(__dirname, 'conf'); logDir = path.resolve(__dirname, 'log'); gamesDir = path.resolve(__dirname, 'games'); @@ -110,21 +105,21 @@ program // Connect phantoms. .option('-p, --phantoms ', - 'Connect phantoms to the specified channel') - .option('-n, --nClients ', - 'Sets the number of clients phantoms to connect (default: 4)') - .option('-t, --clientType ', - 'Sets the client type of connecting phantoms (default: autoplay)') - .option('-T, --runTests', - 'Run tests after all phantoms are game-over ' + - '(overwrites settings.js in test/)') - .option('-k, --killServer', - 'Kill server after all phantoms are game-over') - .option('-a --auth [option]', - 'Phantoms auth options. Values: new(default)|createNew|' + - 'nextAvailable|next|code|id:code&pwd:password|file:path/to/file.') - .option('-w --wait [milliseconds]', - 'Waits before connecting the next phantom. Default: 1000') + 'Connect phantoms to the specified channel **DISCONTINUED**') + // .option('-n, --nClients ', + // 'Sets the number of clients phantoms to connect (default: 4)') + // .option('-t, --clientType ', + // 'Sets the client type of connecting phantoms (default: autoplay)') + // .option('-T, --runTests', + // 'Run tests after all phantoms are game-over ' + + // '(overwrites settings.js in test/)') + // .option('-k, --killServer', + // 'Kill server after all phantoms are game-over') + // .option('-a --auth [option]', + // 'Phantoms auth options. Values: new(default)|createNew|' + + // 'nextAvailable|next|code|id:code&pwd:password|file:path/to/file.') + // .option('-w --wait [milliseconds]', + // 'Waits before connecting the next phantom. Default: 1000') .parse(process.argv); @@ -132,6 +127,12 @@ program // User options (Commander >= 7). let opts = program.opts(); +if (opts.phantoms) { + console.log('***Err: option --phantoms no longer supported. ' + + 'PhantomJS support discontinued.'); + return false; +} + if (opts.confFile) { if (!fs.existsSync(opts.confFile)) { return printErr('--confFile ' + opts.confFile + ' not found.'); diff --git a/package.json b/package.json index f917fab..a912f1f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nodegame", "description": "Fast, scalable JavaScript for large-scale, online, multiplayer, real-time games and experiments.", - "version": "6.3.0", + "version": "7.1.0", "homepage": "http://nodegame.org", "author": "Stefano Balietti ", "contributors": [ @@ -15,21 +15,21 @@ "url": "https://github.com/nodeGame/nodegame.git" }, "engines": { - "node": ">= 6.0.0" + "node": ">= 10.0.0" }, "dependencies": { - "nodegame-server": "^6.0.0", - "nodegame-client": "^6.0.0", - "nodegame-window": "^6.0.0", - "nodegame-widgets": "^6.0.0", - "nodegame-requirements": "^6.0.0", - "nodegame-game-template": "^6.0.0", - "nodegame-monitor": "^6.0.0", - "nodegame-generator": "^6.0.0", - "ultimatum-game": "^6.0.0", - "nodegame-mturk": "^6.0.0", - "JSUS": "^1.1.0", - "NDDB": "^2.0.0", + "nodegame-client": ">=7.1.0", + "nodegame-server": ">=7.0.3", + "nodegame-window": ">=7.0.0", + "nodegame-widgets": ">=7.0.2", + "nodegame-requirements": ">=7.0.0", + "nodegame-game-template": ">=7.0.0", + "nodegame-monitor": ">=7.0.0", + "nodegame-generator": ">=7.0.0", + "ultimatum-game": ">=7.0.0", + "nodegame-mturk": ">=7.0.0", + "JSUS": ">=1.1.0", + "NDDB": ">=3.0.2", "nodegame-db": "*", "nodegame-mongodb": "*", "commander": "^7.0.0",