MXS-1300: Un-modularize the core

Making the core a module proved to bring more problems than it solved. For
the sake of simplicity in installation and code coverage reporting, the
core is now completely contained in the `lib/` directory.

Also added preliminary coverage reporting with nyc.
This commit is contained in:
Markus Mäkelä 2017-07-19 08:03:44 +03:00
parent 0f1a427458
commit cf8028a5ce
25 changed files with 77 additions and 86 deletions

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'alter <command>'
exports.desc = 'Alter objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'call <command>'
exports.desc = 'Call module commands'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'clear <command>'
exports.desc = 'Clear object state'

View File

@ -63,21 +63,21 @@ program
type: 'boolean'
})
.command(require('./lib/list.js'))
.command(require('./lib/show.js'))
.command(require('./lib/set.js'))
.command(require('./lib/clear.js'))
.command(require('./lib/enable.js'))
.command(require('./lib/disable.js'))
.command(require('./lib/create.js'))
.command(require('./lib/destroy.js'))
.command(require('./lib/link.js'))
.command(require('./lib/unlink.js'))
.command(require('./lib/start.js'))
.command(require('./lib/stop.js'))
.command(require('./lib/alter.js'))
.command(require('./lib/rotate.js'))
.command(require('./lib/call.js'))
.command(require('./list.js'))
.command(require('./show.js'))
.command(require('./set.js'))
.command(require('./clear.js'))
.command(require('./enable.js'))
.command(require('./disable.js'))
.command(require('./create.js'))
.command(require('./destroy.js'))
.command(require('./link.js'))
.command(require('./unlink.js'))
.command(require('./start.js'))
.command(require('./stop.js'))
.command(require('./alter.js'))
.command(require('./rotate.js'))
.command(require('./call.js'))
.help()
.demandCommand(1, 'At least one command is required')
.command('*', 'the default command', {}, () => {

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'create <command>'
exports.desc = 'Create objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'destroy <command>'
exports.desc = 'Destroy objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
const log_levels = [
'debug',

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
const log_levels = [
'debug',

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
function addServer(argv, path, targets) {
maxctrl(argv, function(host){

View File

@ -11,7 +11,7 @@
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'list <command>'
exports.desc = 'List objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'rotate <command>'
exports.desc = 'Rotate log files'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'set <command>'
exports.desc = 'Set object state'

View File

@ -11,7 +11,7 @@
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'show <command>'
exports.desc = 'Show objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'start <command>'
exports.desc = 'Start objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
exports.command = 'stop <command>'
exports.desc = 'Stop objects'

View File

@ -10,7 +10,7 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
require('../common.js')()
require('./common.js')()
function removeServer(argv, path, targets) {
maxctrl(argv, function(host) {

View File

@ -13,7 +13,7 @@
'use strict';
var maxctrl = require('maxctrl-core')
var maxctrl = require('./lib/core.js')
// Mangle the arguments if we are being called from the command line
if (process.argv[0] == process.execPath) {

View File

@ -1,20 +0,0 @@
{
"name": "maxctrl-core",
"version": "1.0.0",
"description": "MaxScale Administrative Client Core Library",
"repository": "https://github.com/mariadb-corporation/MaxScale",
"main": "core.js",
"keywords": [
"maxscale"
],
"author": "MariaDB Corporation Ab",
"license": "SEE LICENSE IN ../../LICENSE.TXT",
"dependencies": {
"cli-table": "^0.3.1",
"lodash": "^4.17.4",
"lodash-getpath": "^0.2.4",
"request": "^2.81.0",
"request-promise-native": "^1.0.3",
"yargs": "^8.0.2"
}
}

View File

@ -5,7 +5,7 @@
"repository": "https://github.com/mariadb-corporation/MaxScale",
"main": "maxctrl.js",
"scripts": {
"test": "mocha --timeout 15000 --slow 10000"
"test": "nyc mocha --timeout 15000 --slow 10000"
},
"keywords": [
"maxscale"
@ -14,13 +14,24 @@
"maxctrl": "./maxctrl.js"
},
"author": "MariaDB Corporation Ab",
"license": "SEE LICENSE IN ../../LICENSE.TXT",
"license": "SEE LICENSE IN ../LICENSE.TXT",
"dependencies": {
"maxscale-core": "file:./maxctrl_core"
"cli-table": "^0.3.1",
"lodash": "^4.17.4",
"lodash-getpath": "^0.2.4",
"request": "^2.81.0",
"request-promise-native": "^1.0.3",
"yargs": "^8.0.2"
},
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"mocha": "^3.3.0"
"mocha": "^3.3.0",
"nyc": "^11.0.3"
},
"nyc": {
"include": [
"lib/*.js"
]
}
}

View File

@ -1,27 +1,27 @@
require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var tests = [
'list servers',
'list services',
'list monitors',
'list sessions',
'list filters',
'list modules',
'list users',
'list commands',
'show server server1',
'show service RW-Split-Router',
'show monitor MySQL-Monitor',
'show session 5',
'show filter Hint',
'show module readwritesplit',
'show maxscale',
]
describe("Diagnostic commands", function() {
before(startMaxScale)
var ctrl = require('maxctrl-core')
var tests = [
'list servers',
'list services',
'list monitors',
'list sessions',
'list filters',
'list modules',
'list users',
'list commands',
'show server server1',
'show service RW-Split-Router',
'show monitor MySQL-Monitor',
'show session 5',
'show filter Hint',
'show module readwritesplit',
'show maxscale',
]
tests.forEach(function(i) {
it(i, function() {
return ctrl.execute(i.split(' '), {

View File

@ -1,11 +1,11 @@
require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Monitor Commands", function() {
before(startMaxScale)
var ctrl = require('maxctrl-core')
var opts = { extra_args: [ '--quiet'] }
it('create monitor', function() {
return ctrl.execute('create monitor my-monitor mysqlmon'.split(' '), opts)
.then(function() {

View File

@ -1,11 +1,11 @@
require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Server Commands", function() {
before(startMaxScale)
var ctrl = require('maxctrl-core')
var opts = { extra_args: [ '--quiet'] }
it('create server', function() {
return ctrl.execute('create server server5 127.0.0.1 3003'.split(' '), opts)
.then(function() {

View File

@ -1,11 +1,11 @@
require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Service Commands", function() {
before(startMaxScale)
var ctrl = require('maxctrl-core')
var opts = { extra_args: [ '--quiet'] }
it('link servers to a service', function() {
return ctrl.execute('link service Read-Connection-Router server1 server2 server3 server4'.split(' '), opts)
.then(function() {

View File

@ -1,5 +1,8 @@
require('../test_utils.js')()
var ctrl = require('../lib/core.js')
var opts = { extra_args: [ '--quiet'] }
describe("Server states", function() {
before(function() {
return startMaxScale()
@ -8,9 +11,6 @@ describe("Server states", function() {
})
})
var ctrl = require('maxctrl-core')
var opts = { extra_args: [ '--quiet'] }
it('set correct state', function() {
return ctrl.execute('set server server2 master'.split(' '), opts)
.then(function() {