Skip to content

Commit

Permalink
Merge pull request #28 from smollweide/develop
Browse files Browse the repository at this point in the history
v0.12.1
  • Loading branch information
smollweide authored Apr 12, 2017
2 parents af4a57c + 5e8feec commit ec62431
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var replacePathsStr = '/v2/{baseSiteId}';
var responseFuncPath = __dirname + '/func-imported';

// http://petstore.swagger.io/v2/swagger.json
// http://localhost:3001/src/swagger/swagger-demo-docs.json

mockServer({
restPath: dest,
Expand Down
5 changes: 3 additions & 2 deletions lib/ValidatorResponses.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ValidatorResponses.prototype = extend(ValidatorResponses.prototype, {
*/
_getValidationResponses: function (path) {
var out = [];
var rootDirArray = this.readDir(path, ['.DS_Store', '_DTO']);
var rootDirArray = this.readDir(path, ['.DS_Store', '_DTO', '.validation.json', 'preferences.json']);

this.for(rootDirArray, function (rootItem) {

Expand All @@ -140,8 +140,9 @@ ValidatorResponses.prototype = extend(ValidatorResponses.prototype, {

var isErrorFile = (mockItem.file.search(/error/g) >= 0);
var isStoreFile = (mockItem.file.search(/^\./g) >= 0);
var isHeaderFile = (mockItem.file.search(/\.headers\.json$/) >= 0);

if (!isErrorFile && !isStoreFile) {
if (!isErrorFile && !isStoreFile && !isHeaderFile) {
out.push({
path: pathItemPath,
method: method,
Expand Down
54 changes: 54 additions & 0 deletions lib/commands/create-defined-directories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

var log = require('chip')();
var Utils = require('../Utils');
var utils = new Utils();

function checkAndCreateDirectory(path) {
if (!utils.isFilledString(path)) {
return false;
}

if (utils.existDir(path)) {
return true;
}

utils.writeDir(path);
log('wrote directory ' + path);
return true;
}

function checkAndCreateFile(path, contentJson) {
if (!utils.isFilledString(path)) {
return false;
}

if (utils.existFile(path)) {
return true;
}

utils.writeFile(path, JSON.stringify(contentJson));
log('wrote file ' + path);
return true;
}

function createDefinedDirectories(options) {

checkAndCreateDirectory(options.restPath);
checkAndCreateFile(options.restPath + '/.validation.json', {});
checkAndCreateFile(options.restPath + '/preferences.json', {});

if (options.funcPath instanceof Array) {
options.funcPath.forEach(function (funcPathItem) {
checkAndCreateDirectory(funcPathItem);
});
} else {
checkAndCreateDirectory(options.funcPath);
}

if (options.swaggerImport) {
checkAndCreateDirectory(options.swaggerImport.responseFuncPath);
}

}

module.exports = createDefinedDirectories;
4 changes: 4 additions & 0 deletions mock-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var versionCli = require('./lib/cli/version-cli');
var helpCli = require('./lib/cli/help-cli');
var swaggerImportCli = require('./lib/cli/swagger-import-cli');
var validateCli = require('./lib/cli/validate-cli');
var createDefinedDirectories = require('./lib/commands/create-defined-directories');

var processVersionIndex = process.argv.indexOf('--version');
var processHelpIndex = process.argv.indexOf('--help');
var processSwaggerImportIndex = process.argv.indexOf('swagger-import');
Expand All @@ -16,6 +18,8 @@ function runServer(options) {

var appController = AppControllerSingleton.getInstance(options);

createDefinedDirectories(appController.options);

var UiController = require('./lib/controller/UiController');
var SchemaController = require('./lib/controller/SchemaController');
var SwaggerImportController = require('./lib/controller/SwaggerImportController');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-mock-server",
"version": "0.12.0",
"version": "0.12.1",
"description": "File based Node REST API mock server",
"email": "[email protected]",
"author": "Simon Mollweide <[email protected]>",
Expand Down
3 changes: 2 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var mockServer = require('../mock-server.js'),

process.env.NODE_ENV = 'test';

utils.writeDir('./test/tmp');

serverOptions = {
urlBase: 'http://localhost:8888',
urlPath: '/rest/v1',
Expand Down Expand Up @@ -50,7 +52,6 @@ function _getFile(path) {
_startMockServer();

var swaggerImporter = new SwaggerImport(serverOptions.swaggerImport);
utils.writeDir('./test/tmp');

new ValidatorResponses({
restPath: serverOptions.restPath
Expand Down

0 comments on commit ec62431

Please sign in to comment.