micro-mockers
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -14,5 +14,6 @@ #!/usr/bin/env node | ||
const config = new Config(lib.command.context); | ||
const child = spawn('docker-compose', ['-f', config.compose, 'down']); | ||
child.stdout.pipe(process.stdout); | ||
child.stderr.pipe(process.stderr); | ||
config.load().then(() => { | ||
const child = spawn('docker-compose', ['-f', config.compose, 'down']); | ||
child.stdout.pipe(process.stdout); | ||
child.stderr.pipe(process.stderr); | ||
}); |
@@ -8,2 +8,5 @@ #!/usr/bin/env node | ||
const pEvent = require('p-event'); | ||
const Promise = require('bluebird'); | ||
const lib = require('../lib'); | ||
@@ -17,24 +20,22 @@ const Config = lib.classes.Config; | ||
const config = new Config(lib.command.context); | ||
const host = config.adminApi; | ||
const status = new adminApi.Status(host); | ||
const plugins = new adminApi.Plugins(host); | ||
const apis = new adminApi.Apis(host); | ||
config.load().then(() => { | ||
const host = config.adminApi; | ||
const status = new adminApi.Status(host); | ||
const plugins = new adminApi.Plugins(host); | ||
const apis = new adminApi.Apis(host); | ||
debug('running docker-compose up'); | ||
const child = spawn('docker-compose', ['-f', config.compose, 'up', '-d', '--build']); | ||
child.stdout.pipe(process.stdout); | ||
child.stderr.pipe(process.stderr); | ||
debug('running docker-compose up'); | ||
const child = spawn('docker-compose', ['-f', config.compose, 'up', '-d', '--build']); | ||
child.stdout.pipe(process.stdout); | ||
child.stderr.pipe(process.stderr); | ||
child.on('close', (code) => { | ||
// TODO: error handling when code > 0. | ||
debug('docker-compose up finished with code %s', code); | ||
status.ping().then(syncPlugins).then(syncApis).catch(debug); | ||
return Promise.resolve(pEvent(child, 'close')).then(Promise.coroutine(function*(code) { | ||
debug('docker-compose up finished with code %s', code); | ||
if (code > 0) { | ||
throw new Error('docker-compose up failed'); | ||
} | ||
yield status.ping(); | ||
yield plugins.syncAll(config.plugins || []); | ||
yield apis.syncAll(config.apis || []); | ||
})); | ||
}); | ||
function syncPlugins() { | ||
return plugins.syncAll(config.plugins || []); | ||
} | ||
function syncApis() { | ||
return apis.syncAll(config.apis || []); | ||
} |
0.5.0 / 2018-05-08 | ||
================== | ||
* Dropped Node 6. | ||
* Use eslint. | ||
* Upgrade to Kong 0.12 | ||
* Removed example - there's already the test/fixture. | ||
* Upgrade to loopback-boot v3 and use Yarn. | ||
0.4.1 / 2017-08-10 | ||
@@ -3,0 +12,0 @@ ================== |
@@ -18,3 +18,2 @@ 'use strict'; | ||
module.exports = class Builder { | ||
constructor(options) { | ||
@@ -26,9 +25,11 @@ this.config = new Config(options); | ||
// Prepare the docker compose file. | ||
const composeDoc = this.config.readTemplate().bind(this) | ||
return this.config.readTemplate().bind(this) | ||
.then(yaml.safeLoad) | ||
.then(this.prepareRelativePaths) | ||
.then(this.prepareServices) | ||
.then(yaml.safeDump); | ||
// Write to file. | ||
return Promise.join(this.config.compose, composeDoc, 'utf8', fs.writeFileAsync); | ||
.then(yaml.safeDump) | ||
.then((composeDoc) => { | ||
// Write to file. | ||
return fs.writeFileAsync(this.config.compose, composeDoc, 'utf8'); | ||
}); | ||
} | ||
@@ -43,10 +44,9 @@ | ||
for (let conf in service) { | ||
// https://docs.docker.com/compose/compose-file/#/build | ||
// TODO: context + dockerfile. | ||
if (typeof service[conf] === 'string') { | ||
// https://docs.docker.com/compose/compose-file/#/build | ||
doc.services[key][conf] = service[conf].split(':').map(this.config.relativeToCompose).join(':'); | ||
} | ||
// https://docs.docker.com/compose/compose-file/#/envfile | ||
// https://docs.docker.com/compose/compose-file/#/volumes-volumedriver | ||
else if (Array.isArray(service[conf])) { | ||
} else if (Array.isArray(service[conf])) { | ||
// https://docs.docker.com/compose/compose-file/#/envfile | ||
// https://docs.docker.com/compose/compose-file/#/volumes-volumedriver | ||
doc.services[key][conf] = service[conf].map((item) => { | ||
@@ -91,7 +91,2 @@ if (typeof item === 'string') { | ||
} | ||
cleanup() { | ||
return fs.unlinkAsync(this.config.compose); | ||
} | ||
}; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
const merge = require('mixable-object').merge; | ||
const ConfigLoader = require('loopback-boot').ConfigLoader; | ||
const Bootstrapper = require('loopback-boot').Bootstrapper; | ||
@@ -46,3 +46,2 @@ const Promise = require('bluebird'); | ||
module.exports = class Config { | ||
constructor(options) { | ||
@@ -56,3 +55,12 @@ if (options == null) { | ||
this.env = options.env || process.env.NODE_ENV || 'development'; | ||
this.settings = options.config || ConfigLoader.loadAppConfig(this.root, this.env); | ||
this._bootstrapper = new Bootstrapper({ | ||
// app: this.env, | ||
appRootDir: this.root, | ||
phases: ['load'], | ||
plugins: ['application'] | ||
}); | ||
this._context = { | ||
// app: this.env, | ||
}; | ||
this._load = null; | ||
@@ -87,3 +95,7 @@ /** | ||
}; | ||
} | ||
setup() { | ||
this.settings = this._context.configurations.application; | ||
// This is how the config should look like. | ||
@@ -131,2 +143,12 @@ const schema = { | ||
load(done) { | ||
// Cached with a promise. | ||
if (this._load != null) { | ||
return this._load.asCallback(done); | ||
} | ||
this._load = Promise.resolve(this._bootstrapper.run(this._context)) | ||
.bind(this).then(this.setup).return(this); | ||
return this._load.asCallback(done); | ||
} | ||
get(key) { | ||
@@ -149,3 +171,5 @@ const schema = Joi.reach(this.schema, key); | ||
readTemplate() { | ||
return fs.readFileAsync(this.get('template'), 'utf8'); | ||
return this.load().then(() => { | ||
return fs.readFileAsync(this.get('template'), 'utf8'); | ||
}); | ||
} | ||
@@ -196,3 +220,2 @@ | ||
} | ||
}; |
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
'use strict'; | ||
@@ -11,3 +11,2 @@ // const debug = require('debug')('mm:kong:apis'); | ||
class Apis extends Base { | ||
get rootPath() { | ||
@@ -26,3 +25,2 @@ return 'apis'; | ||
} | ||
} | ||
@@ -29,0 +27,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
'use strict'; | ||
@@ -11,3 +11,2 @@ const debug = require('debug')('mm:kong:base'); | ||
class Base extends Rest { | ||
/** | ||
@@ -38,3 +37,2 @@ * The attributes that should be passed to a sub-endpoint. | ||
} | ||
} | ||
@@ -41,0 +39,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
'use strict'; | ||
@@ -11,7 +11,5 @@ const debug = require('debug')('mm:kong:consumers'); | ||
class Consumers extends Base { | ||
get rootPath() { | ||
return 'consumers'; | ||
} | ||
} | ||
@@ -18,0 +16,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
'use strict'; | ||
@@ -9,3 +9,2 @@ // const debug = require('debug')('mm:kong:plugins'); | ||
class Plugins extends Base { | ||
constructor(options) { | ||
@@ -38,5 +37,4 @@ super(options); | ||
} | ||
} | ||
module.exports = Plugins; |
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
'use strict'; | ||
@@ -8,3 +8,2 @@ const debug = require('debug')('mm:kong:status'); | ||
module.exports = class Status extends Rest { | ||
get rootPath() { | ||
@@ -35,3 +34,2 @@ return 'status'; | ||
} | ||
}; |
{ | ||
"name": "micro-mockers", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"main": "index.js", | ||
@@ -30,22 +30,27 @@ "bin": { | ||
"homepage": "https://github.com/Wiredcraft/micro-mockers", | ||
"engines": { | ||
"node": ">=8.9.0" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.5.0", | ||
"commander": "^2.11.0", | ||
"debug": "^2.6.8", | ||
"bluebird": "^3.5.1", | ||
"commander": "^2.15.1", | ||
"debug": "^3.1.0", | ||
"dot": "^1.1.2", | ||
"dot-prop": "^4.1.1", | ||
"dot-prop": "^4.2.0", | ||
"file-register": "^0.1.0", | ||
"joi": "^10.6.0", | ||
"js-yaml": "^3.9.0", | ||
"joi": "^13.1.2", | ||
"js-yaml": "^3.11.0", | ||
"lib-rest": "^0.1.4", | ||
"loopback-boot": "^2.25.0", | ||
"loopback-boot": "^3.1.0", | ||
"mixable-object": "^0.1.1", | ||
"request": "^2.79.0" | ||
"p-event": "^1.3.0", | ||
"request": "^2.85.0" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.13.1", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^4.19.1", | ||
"eslint-config-wcl-backend": "^0.2.1", | ||
"istanbul": "^0.4.4", | ||
"jscs": "^3.0.7", | ||
"mocha": "^3.4.2", | ||
"should": "^11.1.2" | ||
"mocha": "^5.0.5", | ||
"should": "^13.2.1" | ||
}, | ||
@@ -52,0 +57,0 @@ "license": "MIT", |
@@ -12,3 +12,3 @@ # Micro Mockers | ||
- `npm install -g micro-mockers` | ||
- `cd` to your work directory (see `example` as an example) | ||
- `cd` to your work directory (see `test/fixture` as an example) | ||
- `mm build` | ||
@@ -15,0 +15,0 @@ - `mm up` |
@@ -9,2 +9,4 @@ 'use strict'; | ||
describe('The Config', () => { | ||
let config; | ||
it('should be there', () => { | ||
@@ -14,10 +16,10 @@ Config.should.be.Function(); | ||
let config; | ||
it('can construct', () => { | ||
config = new Config(path.resolve(__dirname, '../example')); | ||
config.should.have.property('compose'); | ||
config.should.have.property('composeRoot'); | ||
config = new Config(path.resolve(__dirname, 'fixture')); | ||
}); | ||
it('can load', () => { | ||
return config.load(); | ||
}); | ||
it('should have a schema', () => { | ||
@@ -24,0 +26,0 @@ config.should.have.property('schema'); |
@@ -19,3 +19,3 @@ 'use strict'; | ||
it('can construct', () => { | ||
builder = new Builder(path.resolve(__dirname, '../example')); | ||
builder = new Builder(path.resolve(__dirname, 'fixture')); | ||
builder.should.have.property('config'); | ||
@@ -31,12 +31,2 @@ }); | ||
it('TODO: check the file content'); | ||
it('can cleanup', () => { | ||
return builder.cleanup().then(() => { | ||
return fs.accessAsync(builder.config.compose).then(() => { | ||
throw new Error('expected an error'); | ||
}, (err) => { | ||
err.should.be.Error(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -20,2 +20,3 @@ 'use strict'; | ||
config = new Config(path.resolve(__dirname, 'fixture')); | ||
return config.load(); | ||
}); | ||
@@ -22,0 +23,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
'use strict'; | ||
@@ -6,3 +6,2 @@ const Rest = require('lib-rest').Rest; | ||
module.exports = class Apis extends Rest { | ||
get rootPath() { | ||
@@ -18,3 +17,2 @@ return 'api/lorems'; | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
42182
13
6
35
1074
+ Addedp-event@^1.3.0
+ Addedasync@2.6.4(transitive)
+ Addedhoek@5.0.46.1.3(transitive)
+ Addedisemail@3.2.0(transitive)
+ Addedjoi@13.7.0(transitive)
+ Addedloopback-boot@3.3.1(transitive)
+ Addedp-event@1.3.0(transitive)
+ Addedp-timeout@1.2.1(transitive)
+ Addedtopo@3.0.3(transitive)
- Removedasync@0.9.2(transitive)
- Removedhoek@4.3.1(transitive)
- Removedisemail@2.2.1(transitive)
- Removeditems@2.2.1(transitive)
- Removedjoi@10.6.0(transitive)
- Removedloopback-boot@2.28.0(transitive)
- Removedtopo@2.1.1(transitive)
Updatedbluebird@^3.5.1
Updatedcommander@^2.15.1
Updateddebug@^3.1.0
Updateddot-prop@^4.2.0
Updatedjoi@^13.1.2
Updatedjs-yaml@^3.11.0
Updatedloopback-boot@^3.1.0
Updatedrequest@^2.85.0