Skip to content
Permalink
Browse files

Common functions required for app and documenter (#15)

* Common repo functions for documenter integration

* Added postman-collection in dependencies

* Updated common functions to incorporate pre-package script

* Updated pre-package.js, changed syntax_mode for golang, powershell, ruby and remove require statement from functions

* Included homepage urls for respective codegens and added it to the languages.js pre-package script to be accessible by common functions

* Updated repository test
  • Loading branch information
umeshp7 committed Jun 3, 2019
1 parent a56f974 commit c938558feab89131430661813322cdfc54cd6445
@@ -168,7 +168,7 @@
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"indent": ["error", 4, {
"indent": ["error", 2, {
"VariableDeclarator": { "var": 1, "let": 1, "const": 1 },
"SwitchCase": 1
}],
@@ -0,0 +1,74 @@
### NPM Specific: Disregard recursive project files
### ===============================================
/.editorconfig
/.gitmodules
/test

### Borrowed from .gitignore
### ========================

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Prevent IDE stuff
.idea
.vscode
*.sublime-*

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
.coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

out/
No changes.
@@ -20,7 +20,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/curl",
"dependencies": {},
"devDependencies": {
"async": "2.6.0",
@@ -7,7 +7,7 @@
"type": "code_generator",
"lang": "go",
"variant": "native",
"syntax_mode": "go"
"syntax_mode": "golang"
},
"directories": {
"lib": "lib",
@@ -25,7 +25,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/golang",
"dependencies": {},
"devDependencies": {
"async": "2.6.0",
@@ -24,6 +24,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/js-fetch",
"dependencies": {},
"devDependencies": {
"async": "2.6.0",
@@ -24,7 +24,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/js-jquery",
"dependencies": {},
"devDependencies": {
"async": "2.5.0",
@@ -24,6 +24,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/nodejs-native",
"dependencies": {},
"devDependencies": {
"async": "2.5.0",
@@ -25,7 +25,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/php-curl",
"dependencies": {},
"devDependencies": {
"async": "2.5.0",
@@ -4,9 +4,9 @@
"description": "Converts postman request to powershell rest method",
"com_postman_plugin": {
"type": "code_generator",
"lang": "bash",
"variant": "powershell - rest method",
"syntax_mode": "bash"
"lang": "powershell",
"variant": "restmethod",
"syntax_mode": "powershell"
},
"directories": {
"lib": "lib",
@@ -24,7 +24,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/powershell-restmethod",
"dependencies": {},
"devDependencies": {
"async": "2.6.0",
@@ -25,7 +25,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/python-requests",
"dependencies": {},
"devDependencies": {
"async": "2.5.0",
@@ -5,7 +5,8 @@
"com_postman_plugin": {
"type": "code_generator",
"lang": "Ruby",
"variant": "net/http"
"variant": "net/http",
"syntax_mode": "ruby"
},
"main": "index.js",
"directories": {
@@ -23,7 +24,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/ruby",
"dependencies": {},
"devDependencies": {
"async": "2.5.0",
@@ -25,7 +25,7 @@
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
"homepage": "",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/swift",
"dependencies": {},
"devDependencies": {
"async": "2.6.0",
@@ -1 +1 @@

module.exports = require('./lib');
@@ -0,0 +1,21 @@
{
"bash": "bash",
"curl": "cURL",
"javascript": "JavaScript",
"http": "HTTP",
"python": "Python",
"ruby": "Ruby",
"java": "Java",
"c": "C",
"php": "PHP",
"objective-c": "Objective-C",
"perl": "Perl",
"go": "Go",
"swift": "Swift",
"typescript": "TypeScript",
"powershell": "Powershell",
"csharp": "C#",
"nodejs": "NodeJs",
"ocaml": "OCaml",
"shell": "Shell"
}
@@ -0,0 +1,118 @@
var sdk = require('postman-collection'),
labelList = require('./assets/languageLabels.json'),
languageMap = require('./assets/languages.js');

module.exports = {
/**
* Gets the options specific to a given language.
*
* @param {Object} language - language key provided by getLanguageList function
* @param {Array} variant - variant key provided by getLanguageList function
* @param {Function} callback - callback function with arguments (error, object)
*/
getOptions (language, variant, callback) {
var validCodegen = languageMap.filter((codegen) => {
var lang = codegen.lang.trim(),
currentVariant = codegen.variant.trim();
return language === lang.toLowerCase() && variant.toLowerCase() === currentVariant.toLowerCase();
});

validCodegen.forEach((codegen) => {
main = codegen.main;
if (typeof main.getOptions !== 'function') {
return callback('Codegen~getOptions: getOptions is not a function');
}
if (!main.getOptions) {
return callback('Codegen~convert: Could not find condegen corresponding to provided language, variant pair');
}

return callback(null, main.getOptions());
});
},

/**
* Returns an object of supported languages
*
*/
getLanguageList () {
var langMap = {},
supportedLanguages = [];
languageMap.forEach((codegen) => {
var lang = codegen.lang.trim(),
syntax_mode = codegen.syntax_mode.trim(),
variant = codegen.variant.trim();
lang = lang.toLowerCase();
if (!langMap[lang]) {
langMap[lang] = {
key: lang,
label: labelList[lang] ? labelList[lang] : lang,
syntax_mode: syntax_mode.toLowerCase(),
variants: [
{
key: variant
}
]
};
}
else {
langMap[lang].variants.push({
key: variant
});
}
});

supportedLanguages = Object.keys(langMap).map(function (lang) {
return langMap[lang];
});

return supportedLanguages;
},

/**
* Converts a request to a preferred language snippet
*
* @param {Object} language - language key provided by getLanguageList function
* @param {Array} variant - variant key provided by getLanguageList function
* @param {String} request - valid postman request
* @param {Object} [options] - contains convert level options
* @param {Number} [options.indentType] - indentation based on tab or spaces
* @param {Number} [options.indentCount] - count/frequency of indentType
* @param {Number} [options.requestTimeout] : time in milli-seconds after which request will bail out
* @param {Boolean} [options.requestBodyTrim] : whether to trim request body fields
* @param {Boolean} [options.addCacheHeader] : whether to add cache-control header to postman SDK-request
* @param {Boolean} [options.followRedirect] : whether to allow redirects of a request
* @param {Function} callback - callback function with arguments (error, string)
*/
convert (language, variant, request, options, callback) {
var convert, main;

if (!sdk.Request.isRequest(request)) {
return callback('Codegen~convert: Invalid request');
}

languageMap.forEach((codegen) => {
var lang = codegen.lang.trim(),
currentVariant = codegen.variant.trim();
if (language.toLowerCase() === lang.toLowerCase() && variant.toLowerCase() === currentVariant.toLowerCase()) {
main = codegen.main;
convert = main.convert;

if (typeof convert !== 'function') {
return callback('Codegen~convert: Convert is not a function');
}
}
});
if (!convert) {
return callback('Codegen~convert: Could not find condegen corresponding to provided language, variant pair');
}


convert(request, options, function (err, snippet) {
if (err) {
return callback(err);
}

return callback(null, snippet);
});
}
};
@@ -1,5 +1,10 @@
#!/bin/bash
set -e; # stop on error

echo "Running pre-package script"
node npm/pre-package.js
echo "Run successful languages.js saved in lib/assets"

if [ -n "$1" ];
then
CODEGEN=$1 # Code gen where npm install is desired to run , first input argument

0 comments on commit c938558

Please sign in to comment.
You can’t perform that action at this time.