Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
make it strict mode compliant & dont demand string type for url path …
Browse files Browse the repository at this point in the history
…parameter values
  • Loading branch information
fogine committed Jun 25, 2018
1 parent 7990a29 commit efb6936
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## FUTURE

* [FIXED] - reserved words should not be used as variable names
* [FIXED] - do not demand url path parameter values to be of string type

## 1.2.2

* [FIXED] - a SDK constructor name should incorporate an application name the sdk is built for (fixes #3)
Expand Down
39 changes: 20 additions & 19 deletions bin/bi-service-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const builder = {
tmp.setGracefulCleanup();
}
const self = this;
const package = require(argv.s + '/package.json');
const npmPackage = require(argv.s + '/package.json');
let specs;

if ((argv.specs instanceof url.Url)) {
Expand All @@ -48,7 +48,7 @@ const builder = {
//for each app - build sdk npm package with API versions bundled in
//separate files
Object.keys(specs).forEach(function(appName) {
let pkg = this.build(appName, specs[appName], package, tmpDir);
let pkg = this.build(appName, specs[appName], npmPackage, tmpDir);
pkg && packages.push(pkg);
}, this);

Expand All @@ -66,29 +66,29 @@ const builder = {
const self = this;
// verify integrity of SDKs (tests) and bundle each created npm package
// in separate zip file -> export to cwd
return Promise.each(packages, function(package) {
return Promise.each(packages, function(pkg) {
if (!argv.tests) {
return;
}

return self.runNpmInstall(package.dir, argv.v).then(function() {
return self.runPackageTests(package.dir, argv.v);
return self.runNpmInstall(pkg.dir, argv.v).then(function() {
return self.runPackageTests(pkg.dir, argv.v);
});
}).map(function(package) {
}).map(function(pkg) {

if (argv.dry) {
return;
}

var zipFilePath = process.cwd() + '/' + package.filename;
var zipFilePath = process.cwd() + '/' + pkg.filename;
var output = fs.createWriteStream(zipFilePath, {
flags: 'wx' //dont overwrite
});

if (argv.v >= 1) {
console.info(`Exporting ${zipFilePath}`);
}
return self.zipFiles(package.files, output);
return self.zipFiles(pkg.files, output);
}).then(function() {
if (argv.cleanup) {
tmpDir.removeCallback();
Expand Down Expand Up @@ -121,18 +121,18 @@ const builder = {
/**
* @param {String} appName
* @param {Object} specs
* @param {Object} package
* @param {Object} pkg
* @param {Object} tmpDir
* @return {Object} package bundle
* @return {Object} pkg bundle
*/
build: function build(appName, specs, package, tmpDir) {
build: function build(appName, specs, pkg, tmpDir) {
const self = this;
var files = [];
var tmplType = self.getTemplateType(specs);
var subdir = `${tmpDir.name}/${package.name}-${appName}-${package.version}`;
var subdir = `${tmpDir.name}/${pkg.name}-${appName}-${pkg.version}`;
var buildedPackage = {
dir: subdir,
filename: `${package.name}-${appName}-${package.version}.zip`,
filename: `${pkg.name}-${appName}-${pkg.version}.zip`,
files: files,
};

Expand All @@ -150,8 +150,8 @@ const builder = {
var sdkPackage = self.renderTemplate(`${tmplType}/package`,
_.merge(
{appName: appName},
package,
{version: self.getSDKPackageVersion(SDK_VERSION, package.version)}
pkg,
{version: self.getSDKPackageVersion(SDK_VERSION, pkg.version)}
));

self.lintSource(sdkIndex);
Expand All @@ -172,7 +172,7 @@ const builder = {
Object.keys(specs).forEach(function(version) {

var spec = specs[version];
var context = self.getTemplateContext(spec, package);
var context = self.getTemplateContext(spec, pkg);
context.context = JSON.stringify(context);

var sdkModule = self.renderTemplate(`${tmplType}/module`, context);
Expand Down Expand Up @@ -321,6 +321,7 @@ const builder = {

var JSHINT_OPTIONS = {
node : 'node',
sub : true,
undef : true,
strict : true,
trailing : true,
Expand All @@ -339,14 +340,14 @@ const builder = {
* @public
*
* @param {Object} spec - swagger 2.0 definition
* @param {Object} package - service's package.json
* @param {Object} pkg - service's package.json
*
* @return {Object}
*/
getTemplateContext: function getTemplateContext(spec, package) {
getTemplateContext: function getTemplateContext(spec, pkg) {
var self = this;
var out = {
moduleName : this.getConstructorName(package.name, spec.info),
moduleName : this.getConstructorName(pkg.name, spec.info),
openbrace : '{',
closebrace : '}',
version : spec.info.version,
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function registerShellCommands(yargs) {
tmp.setGracefulCleanup();
}
let packagePath = config.get('root') + '/package.json';
const package = {
const npmPackage = {
name : config.getOrFail('npmName'),
version : config.get('version') || require(packagePath).version,
};
Expand All @@ -90,7 +90,7 @@ function registerShellCommands(yargs) {
//for each app - build sdk npm package with API versions bundled in
//separate files
Object.keys(specs).forEach(function(appName) {
let pkg = bin.build(appName, specs[appName], package, tmpDir);
let pkg = bin.build(appName, specs[appName], npmPackage, tmpDir);
pkg && packages.push(pkg);
});

Expand Down
5 changes: 1 addition & 4 deletions lib/templates/http/module.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ function {{{moduleName}}}(options) {
}

if (typeof {{name}} === 'undefined') {
{{name}} = options && options.path && options.path.{{name}};
}
if (typeof {{name}} !== 'string') {
return Promise.reject(new Error('"{{name}}" path segment parameter must be a string.'));
{{name}} = options && options.path && options.path['{{name}}'];
}
{{/pathParams}}

Expand Down

0 comments on commit efb6936

Please sign in to comment.