-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from smollweide/develop
v0.14.0
- Loading branch information
Showing
32 changed files
with
816 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.idea | ||
yarn.lock | ||
node_modules | ||
/preferences.json | ||
/demo/rest/*/*/*/mock/response.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "NUM-12", | ||
"description": "Sticky header - see spec for details", | ||
"selectedResponses": { | ||
"products/#{productCode}/GET": "success", | ||
"products/#search/GET": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
"type": "application/json" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
# Collections | ||
|
||
Collections allow you to store your current selected responses and share it with your team members. | ||
For that you can use the UI or the both [CLI commands](/readme.md#L113). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint no-console: 0 */ | ||
|
||
var log = require('chip')(); | ||
var Utils = require('./../Utils'); | ||
var utils = new Utils(); | ||
var activateCollection = require('../commands/activate-collection'); | ||
var util = require('util'); | ||
var extend = util._extend; | ||
var _defaults = require('../defaults/options-defaults'); | ||
|
||
function activateCollectionCli(options) { | ||
options = extend(_defaults, options || {}); | ||
if (activateCollection(process.argv[3], options)) { | ||
log(`collection "${process.argv[3]}" activated`); | ||
} | ||
} | ||
|
||
function collectionsCli(options) { | ||
|
||
var path = `${options.restPath}/_collections`; | ||
|
||
console.log('AVAILABLE COLLECTIONS:'); | ||
console.log('- reset'); | ||
utils.readDir(path).forEach(function (dirItem) { | ||
console.log(`- ${dirItem.file.replace('.json', '')}`); | ||
}); | ||
} | ||
|
||
var exportFunc; | ||
|
||
if (process.argv.length > 3) { | ||
exportFunc = activateCollectionCli; | ||
} else { | ||
exportFunc = collectionsCli; | ||
} | ||
|
||
module.exports = exportFunc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
var log = require('chip')(); | ||
var Utils = require('../Utils'); | ||
var utils = new Utils(); | ||
var getCollection = require('./get-collection'); | ||
var ignoreInRestRoot = require('../constants/ignore-in-rest-root'); | ||
|
||
function activateCollection(id, options) { | ||
|
||
if (!utils.isFilledString(id)) { | ||
return false; | ||
} | ||
|
||
var collection; | ||
|
||
if (id === 'reset') { | ||
collection = { | ||
selectedResponses: {}, | ||
}; | ||
} else { | ||
collection = getCollection(id, options); | ||
} | ||
|
||
if (!collection || !collection.selectedResponses) { | ||
return true; | ||
} | ||
|
||
var selectedResponses = collection.selectedResponses; | ||
|
||
var path = `${options.restPath}`; | ||
var serviceGroups = utils.readDir(path, ignoreInRestRoot); | ||
|
||
serviceGroups.forEach(function (serviceGroup) { | ||
var endPoints = utils.readDir(serviceGroup.path); | ||
endPoints.forEach(function (endPoint) { | ||
var services = utils.readDir(endPoint.path); | ||
services.forEach(function (service) { | ||
var name = `${serviceGroup.file}/${endPoint.file}/${service.file}`; | ||
var pathSelectedFile = `${service.path}/mock/response.txt`; | ||
|
||
// if nothing is selected remove fiel -> fallback success | ||
if (typeof selectedResponses[name] === 'string') { | ||
utils.writeFile(pathSelectedFile, selectedResponses[name]); | ||
log(`Wrote file "${pathSelectedFile.replace(options.restPath, '')}"`); | ||
} else if (utils.existFile(pathSelectedFile)) { | ||
utils.removeFile(pathSelectedFile); | ||
log(`Removed file "${pathSelectedFile.replace(options.restPath, '')}"`); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
module.exports = activateCollection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
var log = require('chip')(); | ||
var Utils = require('../Utils'); | ||
var utils = new Utils(); | ||
|
||
function deleteCollection(id, options) { | ||
if (!utils.isFilledString(id)) { | ||
return false; | ||
} | ||
|
||
var path = `${options.restPath}/_collections/${id}.json`; | ||
|
||
if (!utils.existFile(path)) { | ||
log.error(`cannot delete collection ${id}: file "${path}" don\'t exist!`); | ||
return false; | ||
} | ||
|
||
utils.removeFile(path); | ||
return true; | ||
} | ||
|
||
module.exports = deleteCollection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
var log = require('chip')(); | ||
var Utils = require('../Utils'); | ||
var utils = new Utils(); | ||
|
||
function getCollection(id, options) { | ||
|
||
if (!utils.isFilledString(id)) { | ||
return false; | ||
} | ||
|
||
var path = `${options.restPath}/_collections/${id}.json`; | ||
|
||
if (!utils.existFile(path)) { | ||
log.error(`cannot read collection ${id}: file "${path}" don\'t exist!`); | ||
return false; | ||
} | ||
|
||
return JSON.parse(utils.readFile(path)); | ||
} | ||
|
||
module.exports = getCollection; |
Oops, something went wrong.