Skip to content

Commit

Permalink
Merge branch 'release/2.2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
hypery2k committed Apr 1, 2016
2 parents 41d4035 + 9702dd7 commit ec45195
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -4,7 +4,10 @@ after_success: npm run coverage && cat ./coverage/lcov.info | coveralls
node_js:
- "0.12"
- "4.0"
- "4.3"
- "4"
- "5.0"
- "5"
env:
- NPM_VERSION=3
- NPM_VERSION=2
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Expand Up @@ -9,7 +9,10 @@ environment:
- NPM_VERSION: "3"
# node.js
- NODE_VERSION: "0.12"
- NODE_VERSION: "4.0"
- NODE_VERSION: "4.3"
- NODE_VERSION: "4"
- NODE_VERSION: "5.0"
- NODE_VERSION: "5"

platform:
Expand Down
14 changes: 8 additions & 6 deletions cli/install.js
Expand Up @@ -83,7 +83,7 @@ whichDeferred.promise
npmconf.load(npmconfDeferred.makeNodeResolver());
npmconfDeferred.promise.then(function () {
var downloadUrl = process.env.SAFARIDRIVER_CDNURL ||
'http://selenium-release.storage.googleapis.com/2.48/SafariDriver.safariextz';
'http://selenium-release.storage.googleapis.com/2.48/SafariDriver.safariextz';
var fileName = downloadUrl.split('/').pop();
var downloadedFile = path.join(tmpPath, fileName);
if (!fs.existsSync(downloadedFile)) {
Expand All @@ -96,8 +96,10 @@ whichDeferred.promise
}).then(function (downloadedFile) {
// request to open safari extension installation
var spawn = require('child_process').spawn;
console.log('Opening file ', downloadedFile);
spawn('open', [downloadedFile]);
console.log('Opening file ', downloadedFile);
spawn('open', [downloadedFile], {
detached: true
});
exit(0);
}).fail(function (err) {
console.error('Safari Driver installation failed', err, err.stack);
Expand Down Expand Up @@ -150,16 +152,16 @@ function findSuitableTempDirectory(npmConf) {


function requestBinary(url, dest) {
var deferred = kew.defer();
var deferred = kew.defer();
console.log('Receiving...');

httpreq.get(url,{binary: true}, function (err, res){
httpreq.get(url, {binary: true}, function (err, res) {
if (err) {
deferred.reject(err);
console.error('Error making request.');
} else {
fs.writeFile(dest, res.body, function (err) {
if(err) {
if (err) {
deferred.reject(err);
console.log('Error writing file');
} else {
Expand Down
6 changes: 3 additions & 3 deletions cli/package.json
@@ -1,6 +1,6 @@
{
"name": "galenframework-cli",
"version": "2.2.3",
"version": "2.3.0",
"description": "Just the node wrapper for the Galen Framework.",
"homepage": "https://github.com/hypery2k/galenframework-cli",
"bugs": {
Expand All @@ -22,7 +22,7 @@
"install": "node install.js",
"postinstall": "node postinstall.js",
"test": "nodeunit --reporter=minimal test/tests.js",
"pretest": "jshint -c ../.jshintrc lib/*.js && jshint -c ../.jshintrc *.js",
"pretest": "jshint -c ../.jshintrc --filename *.js && jshint -c ../.jshintrc --filename lib/*.js && jshint -c ../.jshintrc --filename test/*.js",
"coverage": "istanbul -- cover nodeunit test/tests.js && istanbul-coveralls --no-rm"
},
"bin": {
Expand All @@ -32,7 +32,7 @@
"dependencies": {
"chromedriver": "*",
"fs-extra": "0.26.2",
"galenframework": "2.2.3",
"galenframework": "2.2.4",
"httpreq": "0.4.13",
"kew": "0.7.0",
"npmconf": "2.1.2",
Expand Down
105 changes: 85 additions & 20 deletions core/install.js
Expand Up @@ -7,6 +7,7 @@
'use strict';

var requestProgress = require('request-progress');
var replace = require('replace-in-file');
var Progress = require('progress');
var AdmZip = require('adm-zip');
var cp = require('child_process');
Expand Down Expand Up @@ -112,11 +113,14 @@ whichDeferred.promise
return requestBinary(getRequestOptions(conf), downloadedFile);
} else {
console.log('Download already available at', downloadedFile);
return downloadedFile;
return {
requestOptions: getRequestOptions(conf),
downloadedFile: downloadedFile
};
}
})
.then(function (downloadedFile) {
return extractDownload(downloadedFile);
.then(function (response) {
return extractDownload(response.downloadedFile, response.requestOptions, false);
})
.then(function (extractedPath) {
return copyIntoPlace(extractedPath, pkgPath);
Expand All @@ -128,16 +132,32 @@ whichDeferred.promise
console.log('Done. galen binary available at ', location);
// Ensure executable is executable by all users
fs.chmodSync(location, '755');
fs.chmodSync(libPath + '/galen/galen', '755');
fs.chmodSync(libPath + '/galen/galen.bat', '755');
exit(0);
fs.chmodSync(location + '/galen/galen', '755');
fs.chmodSync(location + '/galen/galen.bat', '755');
replace({
files: location + '/galen/galen.bat',
replace: 'com.galenframework.GalenMain %*',
with: 'com.galenframework.GalenMain %* -Djna.nosys=true'
},
function (error, changedFiles) {
//Catch errors
if (error) {
console.error('Error occurred:', error);
}
//List changed files
console.log('Modified files:', changedFiles.join(', '));
exit(0);
});
})
.fail(function (err) {
console.error('Galen installation failed', err, err.stack);
exit(1);
});


/**
* Save the destination directory back
* @param {string} location - path of the directory
*/
function writeLocationFile(location) {
console.log('Writing location.js file');
if (process.platform === 'win32') {
Expand All @@ -147,19 +167,29 @@ function writeLocationFile(location) {
'module.exports.location = \'' + location + '\';');
}

/**
* Exit helper function
* @param {int} code - exit code
* @function
*/
function exit(code) {
validExit = true;
process.env.PATH = originalPath;
process.exit(code || 0);
}


/**
* Function to find an writable temp directory
* @param {object} npmConf - current NPM configuration
* @returns {string} representing suitable temp directory
* @function
*/
function findSuitableTempDirectory(npmConf) {
var now = Date.now();
var candidateTmpDirs = [
process.env.TMPDIR || process.env.TEMP || npmConf.get('tmp'),
'/tmp',
path.join(process.cwd(), 'tmp')
path.join(process.cwd(), 'tmp',
'/tmp')
];

for (var i = 0; i < candidateTmpDirs.length; i++) {
Expand All @@ -183,7 +213,12 @@ function findSuitableTempDirectory(npmConf) {
exit(1);
}


/**
* Create request opions object
* @param {object} conf - current NPM config
* @returns {{uri: string, encoding: null, followRedirect: boolean, headers: {}, strictSSL: *}}
* @function
*/
function getRequestOptions(conf) {
var strictSSL = conf.get('strict-ssl');
if (process.version == 'v0.10.34') {
Expand Down Expand Up @@ -228,7 +263,13 @@ function getRequestOptions(conf) {
return options;
}


/**
* Downloads binary file
* @param {object} requestOptions - to use for HTTP call
* @param {string} filePath - download URL
* @returns {*}
* @function
*/
function requestBinary(requestOptions, filePath) {
var deferred = kew.defer();
var writePath = filePath + '-download-' + Date.now();
Expand All @@ -241,7 +282,10 @@ function requestBinary(requestOptions, filePath) {
fs.writeFileSync(writePath, body);
console.log('Received ' + Math.floor(body.length / 1024) + 'K total.');
fs.renameSync(writePath, filePath);
deferred.resolve(filePath);
deferred.resolve({
requestOptions: requestOptions,
downloadedFile: filePath
});

} else if (response) {
console.error('Error requesting archive.\n' +
Expand All @@ -255,11 +299,11 @@ function requestBinary(requestOptions, filePath) {
exit(1);
} else if (error) {
console.error('Error making request.\n' + error.stack + '\n\n' +
'Please report this full log at https://github.com/hypery2k/galenframework/issues');
'Please report this full log at https://github.com/hypery2k/galenframework-cli/issues');
exit(1);
} else {
console.error('Something unexpected happened, please report this full ' +
'log at https://github.com/hypery2k/galenframework/issues');
'log at https://github.com/hypery2k/galenframework-cli/issues');
exit(1);
}
})).on('progress', function (state) {
Expand All @@ -273,8 +317,15 @@ function requestBinary(requestOptions, filePath) {
return deferred.promise;
}


function extractDownload(filePath) {
/**
* Extracts the given Archive
* @param {string} filePath - path of the ZIP archive to extract
* @param {object} requestOptions - request options for retry attempt
* @param {boolean} retry - set to true if it's already an retry attempt
* @returns {*} - path of the extracted archive content
* @function
*/
function extractDownload(filePath, requestOptions, retry) {
var deferred = kew.defer();
// extract to a unique directory in case multiple processes are
// installing and extracting at once
Expand Down Expand Up @@ -302,8 +353,16 @@ function extractDownload(filePath) {
console.log('Extracting tar contents (via spawned process)');
cp.execFile('tar', ['jxf', filePath], options, function (err) {
if (err) {
console.error('Error extracting archive');
deferred.reject(err);
if (!retry) {
console.log('Error during extracting. Trying to download again.');
fs.unlinkSync(filePath);
return requestBinary(requestOptions, filePath).then(function (downloadedFile) {
return extractDownload(downloadedFile, requestOptions, true);
});
} else {
deferred.reject(err);
console.error('Error extracting archive');
}
} else {
deferred.resolve(extractedPath);
}
Expand All @@ -312,7 +371,13 @@ function extractDownload(filePath) {
return deferred.promise;
}


/**
* Helper function to move folder contents to target directory
* @param {string} extractedPath - source directory path
* @param {string} targetPath - target directory path
* @returns {string} {!Promise.<RESULT>} promise for chaing
* @function
*/
function copyIntoPlace(extractedPath, targetPath) {
console.log('Removing', targetPath);
return kew.nfcall(fs.remove, targetPath).then(function () {
Expand Down
7 changes: 4 additions & 3 deletions core/package.json
@@ -1,6 +1,6 @@
{
"name": "galenframework",
"version": "2.2.3",
"version": "2.2.4",
"description": "The command line tool to use the Galen Framework. This includes the wrapper above and webdriver downloads for different browsers",
"homepage": "https://github.com/hypery2k/galenframework-cli",
"bugs": {
Expand All @@ -21,7 +21,7 @@
"scripts": {
"install": "node install.js",
"test": "nodeunit --reporter=minimal test/tests.js",
"pretest": "jshint -c ../.jshintrc lib/*.js && jshint -c ../.jshintrc *.js",
"pretest": "jshint -c ../.jshintrc --filename *.js && jshint -c ../.jshintrc --filename lib/*.js && jshint -c ../.jshintrc --filename test/*.js",
"coverage": "istanbul -- cover nodeunit test/tests.js && istanbul-coveralls --no-rm"
},
"bin": {
Expand All @@ -33,6 +33,7 @@
"kew": "0.6.0",
"npmconf": "2.1.2",
"progress": "1.1.8",
"replace-in-file": "1.0.2",
"request": "2.60.0",
"request-progress": "0.3.1",
"which": "^1.1.1",
Expand All @@ -51,7 +52,7 @@
"url": "git+https://github.com/hypery2k/galenframework-cli.git"
},
"license": "MIT",
"_galenVersion": "2.2.3",
"_galenVersion": "2.2.4",
"_npmVersion": "2.6.0",
"_nodeVersion": "1.4.1"
}

0 comments on commit ec45195

Please sign in to comment.