strong-deploy
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -0,1 +1,13 @@ | ||
2014-08-21, Version 0.1.3 | ||
========================= | ||
* usage: clarify pack and branch meaning (Sam Roberts) | ||
* Remove --redeploy and make git always force push (Krishna Raman) | ||
* Add ability to deploy npm package (tarball) (Krishna Raman) | ||
* Add usage enhancements (Krishna Raman) | ||
2014-08-05, Version 0.1.2 | ||
@@ -2,0 +14,0 @@ ========================= |
103
index.js
@@ -1,11 +0,10 @@ | ||
var assert = require('assert'); | ||
var debug = require('debug')('strong-deploy'); | ||
var Parser = require('posix-getopt').BasicParser; | ||
var path = require('path'); | ||
var shell = require('shelljs'); | ||
var util = require('util'); | ||
var url = require('url'); | ||
var performGitDeployment = require('./lib/git').performGitDeployment; | ||
var performHttpPutDeployment = require('./lib/put-file').performHttpPutDeployment; | ||
function printHelp($0, prn) { | ||
prn('usage: %s [options] URL', $0); | ||
prn('usage: %s [options] URL [PACK|BRANCH]', $0); | ||
prn(''); | ||
@@ -15,43 +14,15 @@ prn('Deploy a node application to a StrongLoop process manager'); | ||
prn('Options:'); | ||
prn(' -h,--help Print this message and exit.'); | ||
prn(' -v,--version Print version and exit.'); | ||
prn(' -h,--help Print this message and exit.'); | ||
prn(' -v,--version Print version and exit.'); | ||
prn(' -c,--config CFG Deploy a specified configuration (default is "default").'); | ||
prn(''); | ||
prn('Git specific options:'); | ||
prn(' --branch BRANCH Deploy a specified branch.'); | ||
prn(' (default: current branch)'); | ||
prn('Arguments:'); | ||
prn(' URL The URL of the StrongLoop process manager'); | ||
prn(' eg: http://127.0.0.1:7777'); | ||
prn(' PACK Deploy an NPM package/tarball.'); | ||
prn(' BRANCH Deploy a git branch.'); | ||
prn(''); | ||
prn('Arguments:'); | ||
prn(' URL The URL of the StrongLoop process manager'); | ||
prn('Default behaviour is to deploy the git branch "deploy".'); | ||
} | ||
function getCurrentBranch() { | ||
var output = shell.exec('git symbolic-ref --short HEAD', {silent: true}); | ||
if (output.code !== 0) { | ||
return Error('This directory does not contain a valid git repository'); | ||
} | ||
return output.output.trim(); | ||
} | ||
function isValidBranch(branchName) { | ||
var output = shell.exec( | ||
util.format('git rev-parse --abbrev-ref %s', branchName), | ||
{silent: true}); | ||
return output.code === 0; | ||
} | ||
function isValidGitURL(url) { | ||
var output = shell.exec( | ||
util.format('git ls-remote %s', url), | ||
{silent: true}); | ||
return output.code === 0; | ||
} | ||
function doGitPush(gitURL, branch, callback) { | ||
shell.exec( | ||
util.format('git push %s %s:%s', gitURL, branch, branch), | ||
callback); | ||
} | ||
// for unit tests | ||
exports._getCurrentBranch = getCurrentBranch; | ||
exports.deploy = function deploy(argv, callback) { | ||
@@ -64,8 +35,8 @@ var $0 = process.env.SLC_COMMAND ? | ||
'h(help)', | ||
'b:(branch)' | ||
'c:(config)', | ||
].join(''), | ||
argv); | ||
var option; | ||
var error; | ||
var branch; | ||
var config = 'default'; | ||
var branchOrPack; | ||
@@ -80,5 +51,8 @@ while ((option = parser.getopt()) !== undefined) { | ||
return callback(); | ||
case 'b': | ||
branch = option.optarg; | ||
case 'c': | ||
config = option.optarg; | ||
break; | ||
case 'p': | ||
npmPkg = option.optarg; | ||
break; | ||
default: | ||
@@ -91,3 +65,4 @@ console.error('Invalid usage (near option \'%s\'), try `%s --help`.', | ||
if (argv.length - parser.optind() != 1) { | ||
var numArgs = argv.length - parser.optind(); | ||
if (numArgs < 1 || numArgs > 2) { | ||
console.error('Invalid usage, try `%s --help`.', $0); | ||
@@ -97,28 +72,24 @@ return callback(Error('usage')); | ||
branch = branch || getCurrentBranch(); | ||
if (branch instanceof Error) { | ||
console.error(branch.message); | ||
callback(branch); | ||
} | ||
config = config || 'default'; | ||
if (!isValidBranch(branch)) { | ||
console.error('Branch `%s` is not available in this repository', branch); | ||
return callback(Error('invalid branch')); | ||
var baseURL = argv[parser.optind()]; | ||
if (numArgs === 2) { | ||
branchOrPack = argv[parser.optind() + 1]; | ||
} | ||
branchOrPack = branchOrPack || 'deploy'; | ||
var deployURL = argv[parser.optind()]; | ||
if (!isValidGitURL(deployURL)) { | ||
console.error('URL `%s` is not valid', deployURL); | ||
return callback(Error('invalid url')); | ||
} | ||
doGitPush(deployURL, branch, function(er, p) { | ||
function cb(er) { | ||
if (er) { | ||
console.error('Deployment unsuccessful'); | ||
callback(Error('Deployment unsuccessful')); | ||
} else { | ||
console.log('Deployed branch `%s` to `%s`', branch, deployURL); | ||
console.log('Deployed `%s` to `%s`', branchOrPack, baseURL); | ||
callback(); | ||
} | ||
}); | ||
} | ||
if (shell.test('-f', path.resolve(branchOrPack))) { | ||
performHttpPutDeployment(baseURL, config, branchOrPack, cb); | ||
} else { | ||
performGitDeployment(baseURL, config, branchOrPack, cb); | ||
} | ||
}; |
{ | ||
"name": "strong-deploy", | ||
"description": "Deploy a node application to a StrongLoop process manager", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -8,3 +8,3 @@ # strong-deploy | ||
``` | ||
usage: sl-deploy [options] URL | ||
usage: sl-deploy [options] URL [PACK|BRANCH] | ||
@@ -14,11 +14,13 @@ Deploy a node application to a StrongLoop process manager | ||
Options: | ||
-h,--help Print this message and exit. | ||
-v,--version Print version and exit. | ||
-h,--help Print this message and exit. | ||
-v,--version Print version and exit. | ||
-c,--config CFG Deploy a specified configuration (default is "default"). | ||
Git specific options: | ||
--branch BRANCH Deploy a specified branch. | ||
(default: current branch) | ||
Arguments: | ||
URL The URL of the StrongLoop process manager | ||
eg: http://127.0.0.1:7777 | ||
PACK Deploy an NPM package/tarball. | ||
BRANCH Deploy a git branch. | ||
Arguments: | ||
URL The URL of the StrongLoop process manager | ||
Default behaviour is to deploy the git branch "deploy". | ||
``` |
var http = require('http'); | ||
var cicada = require('cicada'); | ||
var shell = require('shelljs'); | ||
var child_process = require('child_process'); | ||
var childProcess = require('child_process'); | ||
var assert = require('assert'); | ||
var getCurrentBranch = require('../index.js')._getCurrentBranch; | ||
var getCurrentBranch = require('../lib/git.js')._getCurrentBranch; | ||
@@ -28,5 +28,5 @@ shell.rm('-rf', '.test_artifacts'); | ||
server.once('listening', function() { | ||
var deploy = child_process.fork( | ||
childProcess.fork( | ||
require.resolve('../bin/sl-deploy'), | ||
['--branch', pushBranch, 'http://localhost:5255/repo2'] | ||
['--config', 'repo2', 'http://localhost:5255', pushBranch] | ||
); | ||
@@ -33,0 +33,0 @@ }); |
var assert = require('assert'); | ||
var async = require('async'); | ||
var debug = require('debug')('strong-deploy:test'); | ||
var path = require('path'); | ||
@@ -22,5 +21,4 @@ require('shelljs/global'); | ||
return null; | ||
} else { | ||
return Error('expected error'); | ||
} | ||
return Error('expected error'); | ||
} | ||
@@ -42,5 +40,7 @@ | ||
function(callback) { | ||
deploy(['', '', '--branch', 'no-such-branch', 'http://some-invalid-repo'], function(er) { | ||
return callback(expectError(er)); | ||
}); | ||
deploy(['', '', 'http://some-invalid-repo', 'no-such-branch'], | ||
function(er) { | ||
return callback(expectError(er)); | ||
} | ||
); | ||
}, | ||
@@ -47,0 +47,0 @@ function(callback) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
19846
14
296
25
3
9