Skip to content

Commit

Permalink
Update old dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-essent committed Oct 29, 2019
1 parent 674f50c commit 1b313a2
Show file tree
Hide file tree
Showing 6 changed files with 717 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
features
node_modules
*.tgz
57 changes: 29 additions & 28 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
#!/usr/bin/env node
'use strict'
var BehavePro = require('../lib/behavepro');
var args = require('minimist')(process.argv.slice(2));
var packageJson = require('../package.json');
var chalk = require('chalk');
"use strict";
var BehavePro = require("../lib/behavepro");
var args = require("minimist")(process.argv.slice(2));
var packageJson = require("../package.json");
var chalk = require("chalk");

if (args.help) {
console.log(
chalk.cyan('Behave Pro NodeJS client v' + packageJson.version) + '\n\n' +
'$ behavepro [--id PROJECT ID] [--userId USER] [--apiKey KEY]\n\n' +
' [--host HOST] Behave Pro host - default: \'http://behave.pro\'\n' +
' [--id PROJECT ID] JIRA project id\n' +
' [--userId USER] Behave Pro user id\n' +
' [--apiKey KEY] Behave Pro api key\n' +
' [--output DIRECTORY] Output directory - default: \'features\'\n' +
' [--manual] Include scenarios marked as manual\n' +
' [--config CONFIG] JSON config file - relative to current directory\n\n' +
'Further docs at http://docs.behave.pro'
);
return;
console.log(
chalk.cyan("Behave Pro NodeJS client v" + packageJson.version) +
"\n\n" +
"$ behavepro [--id PROJECT ID] [--userId USER] [--apiKey KEY]\n\n" +
" [--host HOST] Behave Pro host - default: 'http://behave.pro'\n" +
" [--id PROJECT ID] JIRA project id\n" +
" [--userId USER] Behave Pro user id\n" +
" [--apiKey KEY] Behave Pro api key\n" +
" [--output DIRECTORY] Output directory - default: 'features'\n" +
" [--manual] Include scenarios marked as manual\n" +
" [--config CONFIG] JSON config file - relative to current directory\n\n" +
"Further docs at http://docs.behave.pro"
);
return;
}

var settings = {
host: args.host || 'https://behave.pro',
id: args.key || args.project || args.id,
userId: args.user || args.userId,
apiKey: args.api || args.apiKey || args.password,
output: args.output || args.dir || args.directory || 'features',
manual: args.manual || args.m || false,
config: args.config || 'config.json'
host: args.host || "https://behave.pro",
id: args.key || args.project || args.id,
userId: args.user || args.userId,
apiKey: args.api || args.apiKey || args.password,
output: args.output || args.dir || args.directory || "features",
manual: args.manual || args.m || false,
config: args.config || "config.json"
};

if (settings.id && settings.userId && settings.apiKey) {
BehavePro.fetchFeatures(settings);
BehavePro.fetchFeatures(settings);
} else {
BehavePro.fetchFeaturesFromConfig(settings);
}
BehavePro.fetchFeaturesFromConfig(settings);
}
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env node
'use strict'
var BehavePro = require('./lib/behavepro');
var _ = require('underscore');
"use strict";
var BehavePro = require("./lib/behavepro");
var _ = require("lodash");

var defaultSettings = {
host: 'https://behave.pro',
output: 'features',
manual: false,
config: 'config.json'
host: "https://behave.pro",
output: "features",
manual: false,
config: "config.json"
};

module.exports = function(settings, callback) {
_.defaults(settings, defaultSettings);
BehavePro.fetchFeatures(settings, function() {
if (callback) callback();
});
}
_.defaults(settings, defaultSettings);
BehavePro.fetchFeatures(settings, function() {
if (callback) callback();
});
};
55 changes: 23 additions & 32 deletions lib/behavepro.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
#!/usr/bin/env node
"use strict";
var request = require("request");
var unzipper = require("unzipper");
var fs = require("fs");
var mkdir = require("mkdirp");
var _ = require("underscore");
var chalk = require("chalk");
var red = chalk.red;
const request = require("request");
const unzipper = require("unzipper");
const fs = require("fs");
const mkdir = require("mkdirp");
const _ = require("lodash");
const chalk = require("chalk");
const red = chalk.red;

var fetchFeaturesFromConfig = function(settings, callback) {
const fetchFeaturesFromConfig = function(settings, callback) {
fs.exists(process.cwd() + "/" + settings.config, function findConfig(exists) {
if (exists) {
var configuration = require(process.cwd() + "/" + settings.config);
const configuration = require(process.cwd() + "/" + settings.config);
configuration.forEach(function(config) {
_.extend(settings, config);
fetchFeatures(settings, callback);
});
} else {
var err = new Error(
const err = new Error(
red("Could not find config at " + process.cwd() + "/" + settings.config)
);
throw err;
}
});
};

var fetchFeatures = function(settings, callback) {
var projectId = settings.id;
var userId = settings.userId;
var apiKey = settings.apiKey;
const fetchFeatures = function(settings, callback) {
const projectId = settings.id;
const userId = settings.userId;
const apiKey = settings.apiKey;

ensureSettingsExist(projectId, userId, apiKey, function() {
console.log(
chalk.cyan("Downloading features from JIRA project " + projectId + "...")
);
var url = [
const url = [
settings.host,
"/rest/cucumber/1.0/project/",
projectId,
Expand All @@ -47,50 +47,41 @@ var fetchFeatures = function(settings, callback) {
url: url,
headers: {
Authorization:
"Basic " + new Buffer(userId + ":" + apiKey).toString("base64")
"Basic " + Buffer.from(userId + ":" + apiKey).toString("base64")
},
encoding: null
},
function(error, response, body) {
if (error) throw error;
var err = null;
let err = null;
switch (response.statusCode) {
case 500:
err = new Error(red("Server error: check your host url"));
throw err;
return;
case 401:
err = new Error(
red("Unauthorized: ensure userId and apiKey are both valid")
);
throw err;
return;
case 200:
break;
default:
err = new Error(
red(response.statusCode + " http error when downloading")
);
throw err;
return;
}

var path = settings.output + "/" + projectId;
const path = settings.output + "/" + projectId;
mkdir(path, function(err) {
if (err) throw err;
writeFeatures(body, path, function() {
countFeatures(path, function(files) {
console.log(
chalk.green(
"Saved " +
files.length +
" " +
(files.length > 1 ? "features" : "feature") +
" to " +
process.cwd() +
"/" +
path +
"/"
`Saved ${files.length} ${
files.length > 1 ? "features" : "feature"
} to ${process.cwd()}/${path}/`
)
);
});
Expand All @@ -110,7 +101,7 @@ module.exports = {
function writeFeatures(body, path, callback) {
fs.writeFile(path + ".zip", body, function(err) {
if (err) throw err;
var stream = fs.createReadStream(path + ".zip").pipe(
const stream = fs.createReadStream(path + ".zip").pipe(
unzipper.Extract({
path: path
})
Expand All @@ -124,7 +115,7 @@ function writeFeatures(body, path, callback) {
}

function ensureSettingsExist(projectId, userId, apiKey, callback) {
var err = null;
let err = null;

if (!projectId) {
err = new Error(red("projectId is missing"));
Expand Down
Loading

0 comments on commit 1b313a2

Please sign in to comment.