eshost-cli
Advanced tools
Comparing version 3.4.0 to 3.5.0
@@ -48,2 +48,5 @@ #!/usr/bin/env node | ||
.alias('showSource', 'i') | ||
.describe('unanimous', 'If all engines agree, exit(0) with no output, otherwise print and exit(1); implies --coalesce') | ||
.boolean('unanimous') | ||
.alias('unanimous', 'u') | ||
.nargs('h', 1) | ||
@@ -57,2 +60,4 @@ .describe('async', 'wait for realm destruction before reporting results') | ||
.nargs('add', 2) | ||
.describe('edit', 'edit a host') | ||
.nargs('edit', 1) | ||
.describe('delete', 'delete a host') | ||
@@ -77,2 +82,3 @@ .nargs('delete', 1) | ||
.example('eshost --tags latest test.js') | ||
.example('eshost --unanimous test.js') | ||
.fail(function (msg, err) { | ||
@@ -89,2 +95,7 @@ if (err) { | ||
// --unanimous implies --coalesce | ||
if (argv.unanimous) { | ||
argv.coalesce = true; | ||
} | ||
let config; | ||
@@ -175,8 +186,6 @@ if (argv.c) { | ||
let reporterOptions = { | ||
coalesce: argv.coalesce, | ||
showSource: argv.showSource, | ||
coalesce: argv.coalesce | ||
unanimous: argv.unanimous | ||
}; | ||
if (argv.showSource) { | ||
reporterOptions.showSource = true; | ||
} | ||
@@ -201,9 +210,17 @@ let reporter; | ||
process.exit(0); | ||
} else { | ||
if (argv.args) { | ||
console.error('Use --args with --add'); | ||
process.exit(1); | ||
} | ||
} | ||
// edit a host | ||
if (argv.edit) { | ||
hostManager.edit(config, argv.edit, argv.args, hostTags); | ||
console.log(`Host '${argv.edit}' edited`); | ||
process.exit(0); | ||
} | ||
if (argv.args) { | ||
// at this point in execution, implies (argv.args && !(argv.add || argv.edit)) | ||
console.error('Use --args with --add or --edit'); | ||
process.exit(1); | ||
} | ||
// delete a host | ||
@@ -210,0 +227,0 @@ if (argv.delete) { |
'use strict'; | ||
const fs = require('fs'); | ||
const Path = require('path'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
class Config { | ||
constructor (path) { | ||
Object.defineProperty(this, 'configPath', { value: path }); | ||
constructor(configPath) { | ||
Object.defineProperty(this, 'configPath', { | ||
value: configPath | ||
}); | ||
this.load(); | ||
@@ -16,8 +18,14 @@ } | ||
if (!fs.existsSync(this.configPath)) return; | ||
if (!fs.existsSync(this.configPath)) { | ||
return; | ||
} | ||
const contents = fs.readFileSync(this.configPath, 'utf8'); | ||
if (!contents) return; | ||
if (!contents) { | ||
return; | ||
} | ||
const config = JSON.parse(contents); | ||
Object.keys(config).forEach(k => this[k] = config[k]); | ||
@@ -28,3 +36,3 @@ | ||
save(cb) { | ||
save() { | ||
fs.writeFileSync(this.configPath, JSON.stringify(this, null, 2), 'utf8'); | ||
@@ -38,4 +46,4 @@ } | ||
Config.defaultConfigPath = Path.join(os.homedir(), '.eshost-config.json'); | ||
Config.defaultConfigPath = path.join(os.homedir(), '.eshost-config.json'); | ||
module.exports = Config; |
@@ -9,29 +9,49 @@ 'use strict'; | ||
const head = [ | ||
'name', | ||
'type', | ||
'path', | ||
'args', | ||
'tags', | ||
]; | ||
const colWidths = head.map(h => h.length + 2); | ||
exports.list = function list(config) { | ||
console.log(chalk.grey('Using config ', config.configPath)); | ||
var table = new Table({ | ||
head: [ | ||
'name', | ||
'type', | ||
'path', | ||
'args', | ||
'tags' | ||
], | ||
const table = new Table({ | ||
colWidths, head | ||
}); | ||
Object.keys(config.hosts).forEach(name => { | ||
const host = config.hosts[name]; | ||
table.push([ | ||
name, | ||
host.type, | ||
host.path || '', | ||
host.args || '', | ||
(host.tags || '') + '', | ||
]); | ||
}) | ||
const names = Object.keys(config.hosts); | ||
let output; | ||
console.log(table.toString()); | ||
} | ||
if (!names.length) { | ||
output = 'No configured hosts'; | ||
} else { | ||
output = names.reduce((accum, name) => { | ||
const { | ||
type, | ||
path = '', | ||
args = '', | ||
tags = '' | ||
} = config.hosts[name]; | ||
const row = [ name, type, path, args, tags ]; | ||
const {colWidths: widths} = accum.options; | ||
// Update the stored colWidths for each cell, saving the largest/longest | ||
accum.options.colWidths = Array.from(widths, (width, index) => { | ||
return Math.max(width, String(row[index]).length + 2); | ||
}); | ||
accum.push(row); | ||
return accum; | ||
}, table).sort().toString(); | ||
} | ||
console.log(output); | ||
}; | ||
exports.add = function add(config, name, type, path, args, tags) { | ||
@@ -62,2 +82,22 @@ console.log(chalk.grey('Using config ', config.configPath)); | ||
exports.edit = function edit(config, name, args, tags) { | ||
console.log(chalk.grey('Using config ', config.configPath)); | ||
if (!config.hosts[name]) { | ||
console.log(chalk.red(`Host '${name}' does not exist`)); | ||
process.exit(1); | ||
return; | ||
} | ||
if (args) { | ||
config.hosts[name].args = args; | ||
} | ||
if (tags) { | ||
config.hosts[name].tags = tags; | ||
} | ||
config.save(); | ||
} | ||
exports.delete = function deleteHost(config, name) { | ||
@@ -64,0 +104,0 @@ console.log(chalk.grey('Using config ', config.configPath)); |
@@ -0,1 +1,3 @@ | ||
const chalk = require('chalk'); | ||
module.exports = class Reporter { | ||
@@ -5,11 +7,27 @@ constructor (options = {}) { | ||
} | ||
start(){} | ||
result(host, result) { } | ||
end(){} | ||
start() {} | ||
result(host, result) {} | ||
end() {} | ||
static coalesceInto(table, host, result, resultsMap /*{result:[...hosts]}*/, sep = "\n") { | ||
get isUnanimous() { | ||
if (this.results.length === 1) { | ||
return true; | ||
} | ||
// Get the result string of the first result entry | ||
let first = this.results[0][1]; | ||
// Compare the first result string to all result strings | ||
for (let [ host, result ] of this.results) { | ||
if (result !== first) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
static coalesceInto(records, host, result, resultsMap /*{result:[...hosts]}*/, sep = "\n") { | ||
let found = false; | ||
for (let row of table) { | ||
if (row[1] === result) { | ||
for (let record of records) { | ||
if (record[1] === result) { | ||
let hosts = resultsMap[result]; | ||
@@ -24,3 +42,3 @@ hosts.push(host); | ||
text = text.trim(); | ||
row[0] = text; | ||
record[0] = text; | ||
@@ -34,3 +52,3 @@ found = true; | ||
resultsMap[result] = [host]; | ||
table.push([ | ||
records.push([ | ||
host.name, result | ||
@@ -40,2 +58,7 @@ ]); | ||
} | ||
static printSource(source) { | ||
console.log(chalk.blue('## Source')); | ||
console.log(`${source}\n`); | ||
} | ||
} |
@@ -5,12 +5,13 @@ const Reporter = require('../Reporter.js'); | ||
module.exports = class DefaultReporter extends Reporter { | ||
constructor (options) { | ||
constructor(options) { | ||
super(options); | ||
this.source = undefined; | ||
this.results = []; | ||
this.resultsMap = {}; | ||
} | ||
start(text) { | ||
start(source) { | ||
this.source = source; | ||
if (this.options.showSource) { | ||
console.log(chalk.blue('## Source')); | ||
console.log(text); | ||
console.log(""); | ||
Reporter.printSource(source); | ||
} | ||
@@ -25,3 +26,9 @@ } | ||
if (this.options.coalesce) { | ||
Reporter.coalesceInto(this.results, host, resultString, this.resultsMap, ", "); | ||
if (this.options.unanimous) { | ||
this.results.push([ | ||
host.name, resultString | ||
]); | ||
} else { | ||
Reporter.coalesceInto(this.results, host, resultString, this.resultsMap, ", "); | ||
} | ||
} else { | ||
@@ -33,5 +40,15 @@ printHostResult(host.name, resultString); | ||
if (this.options.coalesce) { | ||
this.results.forEach(row => { | ||
printHostResult(row[0], row[1]); | ||
}) | ||
if (this.options.unanimous && this.isUnanimous) { | ||
process.exit(0); | ||
// don't print anything | ||
} else { | ||
this.results.forEach(row => { | ||
printHostResult(row[0], row[1]); | ||
}); | ||
if (this.options.unanimous) { | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
@@ -43,4 +60,3 @@ } | ||
console.log(chalk.blue(`#### ${name}`)); | ||
console.log(result); | ||
console.log(""); | ||
console.log(`${result}\n`); | ||
} |
@@ -8,2 +8,3 @@ const Reporter = require('../Reporter.js'); | ||
super(options); | ||
this.source = undefined; | ||
this.results = new Table(); | ||
@@ -13,7 +14,7 @@ this.resultsMap = {}; | ||
start(text) { | ||
start(source) { | ||
this.source = source; | ||
if (this.options.showSource) { | ||
console.log(chalk.blue('## Source')); | ||
console.log(text); | ||
console.log(""); | ||
Reporter.printSource(source); | ||
} | ||
@@ -39,4 +40,17 @@ } | ||
end() { | ||
console.log(this.results.toString()); | ||
if (this.options.unanimous && this.isUnanimous) { | ||
process.exit(0); | ||
// don't print anything | ||
} else { | ||
if (this.options.showSource) { | ||
Reporter.printSource(this.source); | ||
} | ||
console.log(this.results.toString()); | ||
if (this.options.unanimous) { | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "eshost-cli", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"description": "Run scripts in any ECMAScript host", | ||
@@ -17,5 +17,7 @@ "bin": { | ||
}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^3.5.0" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha test/**/*.js" | ||
}, | ||
@@ -22,0 +24,0 @@ "repository": { |
@@ -41,3 +41,3 @@ ## eshost-cli | ||
You can --add, --list, and --delete hosts. Adding a host requires a name, type, and path to the runtime executable. You can optionally pass arguments using --args. The same host can be added multiple times with different --args which makes it easy to compare the output of runtimes given different options (eg. by turning language features on and off). | ||
You can --list, --add, --edit, and --delete hosts. Adding a host requires a name, type, and path to the runtime executable. You can optionally pass arguments using --args. The same host can be added multiple times with different --args which makes it easy to compare the output of runtimes given different options (eg. by turning language features on and off). | ||
@@ -44,0 +44,0 @@ Console hosts are either provided by the browser vendors or, more likely, built from source. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
19393
13
542
0
1