mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 07:07:33 +00:00
Upgrade syntax of everything to more modern javascript
This commit is contained in:
parent
f8d903b982
commit
69288baebc
43 changed files with 1499 additions and 1521 deletions
|
|
@ -1,40 +1,51 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var argv = require('minimist')(process.argv.slice(2));
|
||||
const argv = require('minimist')(process.argv.slice(2)),
|
||||
Gamedig = require('..');
|
||||
|
||||
var debug = argv.debug;
|
||||
const debug = argv.debug;
|
||||
delete argv.debug;
|
||||
var outputFormat = argv.output;
|
||||
const outputFormat = argv.output;
|
||||
delete argv.output;
|
||||
|
||||
var options = {};
|
||||
for(var key in argv) {
|
||||
var value = argv[key];
|
||||
const options = {};
|
||||
for(const key of Object.keys(argv)) {
|
||||
const value = argv[key];
|
||||
if(
|
||||
key == '_'
|
||||
|| key.charAt(0) == '$'
|
||||
|| (typeof value != 'string' && typeof value != 'number')
|
||||
key === '_'
|
||||
|| key.charAt(0) === '$'
|
||||
|| (typeof value !== 'string' && typeof value !== 'number')
|
||||
)
|
||||
continue;
|
||||
options[key] = value;
|
||||
}
|
||||
|
||||
var Gamedig = require('../lib/index');
|
||||
if(debug) Gamedig.debug = true;
|
||||
Gamedig.isCommandLine = true;
|
||||
|
||||
Gamedig.query(options)
|
||||
.then((state) => {
|
||||
if(outputFormat == 'pretty') {
|
||||
if(outputFormat === 'pretty') {
|
||||
console.log(JSON.stringify(state,null,' '));
|
||||
} else {
|
||||
console.log(JSON.stringify(state));
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if(outputFormat == 'pretty') {
|
||||
console.log(JSON.stringify({error:error},null,' '));
|
||||
} else {
|
||||
console.log(JSON.stringify({error:error}));
|
||||
}
|
||||
if (debug) {
|
||||
if (error instanceof Error) {
|
||||
console.log(error.stack);
|
||||
} else {
|
||||
console.log(error);
|
||||
}
|
||||
} else {
|
||||
if (error instanceof Error) {
|
||||
error = error.message;
|
||||
}
|
||||
if (outputFormat === 'pretty') {
|
||||
console.log(JSON.stringify({error: error}, null, ' '));
|
||||
} else {
|
||||
console.log(JSON.stringify({error: error}));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs');
|
||||
const fs = require('fs'),
|
||||
TypeResolver = require('../lib/typeresolver');
|
||||
|
||||
var TypeResolver = require('../lib/typeresolver');
|
||||
var generated = TypeResolver.printReadme();
|
||||
const generated = TypeResolver.printReadme();
|
||||
|
||||
var readmeFilename = __dirname+'/../README.md';
|
||||
var readme = fs.readFileSync(readmeFilename, {encoding:'utf8'});
|
||||
const readmeFilename = __dirname+'/../README.md';
|
||||
const readme = fs.readFileSync(readmeFilename, {encoding:'utf8'});
|
||||
|
||||
var marker_top = '<!--- BEGIN GENERATED GAMES -->';
|
||||
var marker_bottom = '<!--- END GENERATED GAMES -->';
|
||||
const marker_top = '<!--- BEGIN GENERATED GAMES -->';
|
||||
const marker_bottom = '<!--- END GENERATED GAMES -->';
|
||||
|
||||
var start = readme.indexOf(marker_top);
|
||||
let start = readme.indexOf(marker_top);
|
||||
start += marker_top.length;
|
||||
var end = readme.indexOf(marker_bottom);
|
||||
const end = readme.indexOf(marker_bottom);
|
||||
|
||||
var updated = readme.substr(0,start)+"\n\n"+generated+"\n"+readme.substr(end);
|
||||
const updated = readme.substr(0,start)+"\n\n"+generated+"\n"+readme.substr(end);
|
||||
fs.writeFileSync(readmeFilename, updated);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue