diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..75c9eb4 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,68 @@ +{ + "root": true, + "extends": [ + "eslint:recommended" + ], + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module", + "ecmaFeatures": { + "globalReturn": true, + "impliedStrict": true + } + }, + "env": { + "es6": true, + "node": true + }, + "rules": { + "no-trailing-spaces": [2], + "no-multiple-empty-lines": [2, {"max": 2, "maxEOF": 0}], + "eol-last": [2], + "indent": [0], + "indent-legacy": [2, 4, {"SwitchCase": 1}], + "max-len": [0, 80], + "brace-style": [0, "stroustrup", {"allowSingleLine": true}], + "curly": [2, "multi-line"], + "camelcase": [0, {"properties": "never"}], + "comma-spacing": [2, {"before": false, "after": true}], + "comma-style": [2, "last"], + "semi": [2], + "semi-spacing": [2, {"before": false, "after": true}], + "key-spacing": [2, {"beforeColon": false, "afterColon": true}], + "keyword-spacing": [2, {"overrides": { + "if": {"after": true}, + "for": {"after": true}, + "while": {"after": true}, + "switch": {"after": false}, + "catch": {"after": false} + }}], + "no-spaced-func": [2], + "space-in-parens": [2, "never"], + "space-before-function-paren": [2, "never"], + "space-before-blocks": [2], + "spaced-comment": [2, "always"], + "no-tabs": [2], + "no-multi-spaces": [2, {"ignoreEOLComments": true}], + "no-whitespace-before-property": [2], + "no-unexpected-multiline": [2], + "no-floating-decimal": [2], + "space-infix-ops": [2, {"int32Hint": true}], + "quotes": [2, "single"], + "dot-notation": [2], + "dot-location": [2, "property"], + "operator-linebreak": [2, "after"], + "eqeqeq": [2], + "new-cap": [2, { "capIsNewExceptionPattern": "^MathJax\\.." }], + "no-redeclare": [2, {"builtinGlobals": true}], + "no-shadow": [0, {"builtinGlobals": true}], + "block-scoped-var": [2], + "no-unused-vars": [2], + "no-undef-init": [2], + "no-use-before-define": [2, "nofunc"], + "no-loop-func": [2], + "no-console": [0], + "no-unused-labels": [2], + "no-useless-escape": [0] + } +} diff --git a/.travis.yml b/.travis.yml index b1aa99b..7ced4f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ node_js: - 6 - 7 - 8 + - 10 before_install: # Get installer script. @@ -12,7 +13,8 @@ before_install: install: - npm install --only=dev - - node nodegame-installer.js @dev --install-dir node_modules --no-spinner --branch v4 --yes + # --branch v4 + - node nodegame-installer.js @dev --install-dir node_modules --no-spinner --yes script: # Add module tests here. diff --git a/CHANGELOG b/CHANGELOG index c95d645..dd7e645 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,53 @@ # CHANGELOG -## 4.0.0 (current) +## 7.0.1 ## current +- Fixed bugs and typos for export. + +## 7.0.0 +- Export functions added for logs and data. + +## 6.0.2 +- Games directories are always set by update-conf. +- Updated to newer version of commander. + +## 6.0.1 +- Minor text. + +## 6.0.0 +- Single-player game. + +## 5.1.0 +- The private directory is created. + +## 5.0.1 +- Game names cannot start with a dot. + +## 5.0.0 +- Relative links for games enabled. + +## 4.2.1 +- CSS file copied +- .gitignore is correctly handled also in non-dev version. + +## 4.2.0 +- Auto generate secret and credentials files. +- Eslinted nodegame. +- Added README and LICENSE. +- Description included. + +## 4.1.1 +- Improved parameter checking, display of help. +- Fixed bug update-conf not loading the latest author and email parameters. +- File .gitignore is added by default. + +## 4.1.0 +- Auto-detect nodeGame installation folder +- Enable games created in games/. +- Small fixes. + +## 4.0.0 - show-conf command. - Replace default nodeGame copyright string. -- TODO: multiple templates. ## 1.1.2 - Minor fix for autoplay template. diff --git a/LICENSE b/LICENSE index 26c0955..054092c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ (The MIT License) -Copyright (c) 2015 Stefano Balietti +Copyright (c) 2018 Stefano Balietti Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 8af16ab..358522c 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ This generator can also be further configured with the following command line fl ## Kudos -Based on a fork of [Express Generator](https://github.com/expressjs/generator). +Originally based on a fork of [Express Generator](https://github.com/expressjs/generator). ## License diff --git a/bin/nodegame b/bin/nodegame index 3c6ce43..2e7101c 100755 --- a/bin/nodegame +++ b/bin/nodegame @@ -1,33 +1,108 @@ -#!/usr/bin/env node +#!/usrng/bin/env node -var program = require('commander'); -var mkdirp = require('mkdirp'); -var os = require('os'); -var fs = require('fs-extra'); -var path = require('path'); -var readline = require('readline'); -var sortedObject = require('sorted-object'); +const program = require('commander'); +const mkdirp = require('mkdirp'); +const fs = require('fs-extra'); +const path = require('path'); +const readline = require('readline'); -var J = require('JSUS').JSUS; -var ngt = require('nodegame-game-template'); +const J = require('JSUS').JSUS; +const ngt = require('nodegame-game-template'); -var _exit = process.exit; -var eol = os.EOL; -var pkg = require('../package.json'); +const pkg = require('../package.json'); +const version = pkg.version; -var version = pkg.version; +const isWin = /^win/.test(process.platform); -var root = path.resolve(__dirname, '..'); -var confFile = root + '/conf/generator.conf.json'; +// This file is "copied" and not linked in Windows, +// therefore we need to be agnostic while loading the root path. +const root = J.resolveModuleDir('nodegame-generator'); +const confFile = path.resolve(root, 'conf', 'generator.conf.json'); -// Re-assign process.exit because of commander -process.exit = exit +const exp = require(path.resolve(root, 'lib', 'export.js')); -// Mock configuration. Will be overwritten. +const NODEGAME_MODULE = 'nodegame'; +// const NODEGAME_MODULE = 'nodegame-test'; + +// Setup readline. +let rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + terminal: true +}); +rl.on('SIGINT', function() { + rl.close(); + console.log(); + console.log(); + console.log('canceled'); +}); + +var stdoutConf = { + willBeMuted: false, + muted: false, + lastPrompt: '', + origPrompt: '' +}; +unmute(); + +function muteNext() { + if (stdoutConf.muted) unmute(); + stdoutConf.willBeMuted = true; +} + +function unmute() { + stdoutConf.willBeMuted = false; + stdoutConf.muted = false; + stdoutConf.lastPrompt = ''; + stdoutConf.origPrompt = ''; +} + +function mute() { + stdoutConf.willBeMuted = false; + stdoutConf.muted = true; +} + +rl._writeToOutput = function _writeToOutput(str) { + // console.log('INPUT ', str, str.length); + if (stdoutConf.muted) { + if (str.length > 2) { + // console.log('LEN : ', str.length); + // console.log('1'); + let len = stdoutConf.lastPrompt.length; + let lenOrig = stdoutConf.origPrompt.length; + str = stdoutConf.lastPrompt.substr(0, Math.max(lenOrig, len - 1)); + stdoutConf.lastPrompt = str; + rl.output.write(str); + } + else if (str.length === 2) { + rl.output.write(str); + } + else { + // console.log('2'); + rl.output.write('*'); + stdoutConf.lastPrompt += '*'; + } + } + else { + // console.log('3'); + rl.output.write(str); + } + if (stdoutConf.willBeMuted) { + stdoutConf.lastPrompt = stdoutConf.origPrompt = str; + mute(); + } +}; + +// Game-creation configuration. + +// Will be overwritten. var conf = { author: 'author', email: 'email', - gamesFolder: undefined + ngDir: undefined, + ngVersion: undefined, + ngGamesAvailDir: undefined, + ngGamesEnabledDir: undefined, }; // Available templates. @@ -36,25 +111,11 @@ var templates = { }; // TODO: make templates actually loading from games_available. -var templatesDir = 'TO_BE_DEFINED'; +// var templatesDir = 'TO_BE_DEFINED'; // Chosen template. Default dictator. const DEFAULT_TEMPLATE = 'dictator'; - -// Full copyright string. Will be overwritten. -var fullCopyright; - -// Flag if a command is passed at all. -var cmdValue; - -// CLI - -before(program, 'outputHelp', function () { - this.allowUnknownOption(); -}); - - // program // .command('list-templates') // .description('List all available game templates') @@ -65,40 +126,61 @@ before(program, 'outputHelp', function () { // if (templates.hasOwnProperty(t)) { // str = ' - ' + t; // if (t === DEFAULT_TEMPLATE) str += ' **default**'; -// console.log(str); +// console.log(str); // } // } // console.log(); // }); +program.version(version); program - .version(version) .command('update-conf') .description('Updates stored configuration (author, games dir, etc.)') - .action(function(env, options){ - createConfFile(options); + .allowUnknownOption() + .action(function(options) { + + loadConfFile(function() { + // Nothing. + rl.close(); + }, true); }); program - .version(version) .command('show-conf') .description('Shows current configuration') - .action(function(env, options){ + .allowUnknownOption() + .action(function(options) { + loadConfFile(function() { showConf(); + rl.close(); }); }); program .command('create-game [game_name] [author] [author_email]') .description('Creates a new game in the games directory') - .option(' --git', 'add .gitignore') - // .option('-t, --template