Comparing version 0.4.1 to 0.4.2
@@ -8,2 +8,36 @@ "use strict"; | ||
var processExecDebugOn = false; | ||
var processExec = function() { | ||
var logging = []; | ||
var done = null; | ||
var storeDone = function( args, i ) { | ||
done = args[ i ]; | ||
args[ i ] = function() { | ||
if ( processExecDebugOn ) { | ||
console.error( 'result', arguments ); | ||
} | ||
done.apply( {}, arguments ); | ||
}; | ||
}; | ||
for ( var i = 0; i < arguments.length; i++ ) { | ||
if ( done === null && typeof arguments[ i ] === 'function' ) { | ||
storeDone( arguments, i ); | ||
break; | ||
} else { | ||
logging.push( arguments[ i ] ); | ||
} | ||
} | ||
if ( processExecDebugOn ) { | ||
console.error( 'executing', logging ); | ||
} | ||
childProcess.exec.apply( childProcess, arguments ); | ||
}; | ||
var Deploid = function( config ) { | ||
@@ -13,2 +47,4 @@ | ||
processExecDebugOn = this._config.debug; | ||
if ( !config.hasOwnProperty( 'user' ) ) { | ||
@@ -97,4 +133,11 @@ config.user = config.name; | ||
if ( this._tmpDir ) { | ||
// leave tmp files in place for debugging | ||
if ( this._tmpDir && !processExecDebugOn ) { | ||
this._rmdir( this._tmpDir, done ); | ||
} else { | ||
if ( processExecDebugOn ) { | ||
console.error( 'Temporary directory not deleted for debugging: ', this._tmpDir ); | ||
} | ||
done(); | ||
@@ -118,2 +161,6 @@ } | ||
var nodeBinaryDirOffset = null; | ||
var packageJson = {}; | ||
async.series( [ | ||
@@ -131,10 +178,11 @@ function( done ) { | ||
console.error( 'Cloning source dir.' ); | ||
childProcess.exec( 'rsync -azr ' + self._config.srcDir.replace( /\/$/, '' ) + '/ ' + tmpSrcDir, done ); | ||
processExec( 'rsync -azr ' + self._config.srcDir.replace( /\/$/, '' ) + '/ ' + tmpSrcDir, done ); | ||
}, | ||
function( done ) { | ||
console.error( 'Checking out ' + self._config.version + '.' ); | ||
childProcess.exec( 'git checkout ' + self._config.branch, { cwd: tmpSrcDir }, done ); | ||
processExec( 'git checkout ' + self._config.branch, { cwd: tmpSrcDir }, done ); | ||
}, | ||
function( done ) { | ||
getNodeVersion( tmpSrcDir + '/package.json', function( err, nodeVersion ) { | ||
getPackageFile( tmpSrcDir + '/package.json', function( err, contents ) { | ||
if ( err ) { | ||
@@ -145,2 +193,15 @@ done( err ); | ||
packageJson = contents; | ||
done(); | ||
} ); | ||
}, | ||
function( done ) { | ||
getNodeVersion( packageJson, function( err, nodeVersion ) { | ||
if ( err ) { | ||
done( err ); | ||
return; | ||
} | ||
self._config.nodeVersion = nodeVersion; | ||
@@ -156,16 +217,8 @@ | ||
function( done ) { | ||
console.error( 'Performing npm installation.' ); | ||
childProcess.exec( 'npm install --production', { cwd: tmpSrcDir }, done ); | ||
}, | ||
function( done ) { | ||
console.error( 'Performing npm build.' ); | ||
childProcess.exec( 'npm run-script build', { cwd: tmpSrcDir }, done ); | ||
}, | ||
function( done ) { | ||
console.error( 'Copying NVM src.' ); | ||
childProcess.exec( 'rsync -azr /tmp/nvm.tmp/ ' + tmpNvmDir, done ); | ||
processExec( 'rsync -azr /tmp/nvm.tmp/ ' + tmpNvmDir, done ); | ||
}, | ||
function( done ) { | ||
console.error( 'Installing node version ' + self._config.nodeVersion + ' in NVM.' ); | ||
childProcess.exec( __dirname + '/nvmSetup.sh ' + tmpNvmDir + ' ' + self._config.nodeVersion, function( err ) { | ||
processExec( __dirname + '/nvmSetup.sh ' + tmpNvmDir + ' ' + self._config.nodeVersion, function( err, data ) { | ||
@@ -177,2 +230,3 @@ if ( err ) { | ||
console.error( 'NVM data' ); | ||
done(); | ||
@@ -182,23 +236,67 @@ } ); | ||
function( done ) { | ||
fs.readdir( tmpNvmDir, function( err, files ) { | ||
if ( err ) { | ||
done( err ); | ||
return; | ||
} | ||
var newNodeVersion = null; | ||
for ( var i = 0; i < files.length && newNodeVersion === null; i++ ) { | ||
var match = files[i].match( /^v([0-9]+\.[0-9]+\.[0-9]+)$/ ); | ||
if ( match ) { | ||
newNodeVersion = match[1]; | ||
} | ||
self._config.nodeVersion = null; | ||
async.parallel( [ | ||
function( done ) { | ||
fs.readdir( tmpNvmDir, function( err, files ) { | ||
if ( err ) { | ||
done(); | ||
return; | ||
} | ||
var newNodeVersion = null; | ||
for ( var i = 0; i < files.length && newNodeVersion === null; i++ ) { | ||
var match = files[ i ].match( /^v([0-9]+\.[0-9]+\.[0-9]+)$/ ); | ||
if ( match ) { | ||
newNodeVersion = match[ 1 ]; | ||
} | ||
} | ||
if ( newNodeVersion === null ) { | ||
done(); | ||
return; | ||
} | ||
self._config.nodeVersion = newNodeVersion; | ||
nodeBinaryDirOffset = ''; | ||
done(); | ||
} ); | ||
}, | ||
function( done ) { | ||
fs.readdir( tmpNvmDir + '/versions/node', function( err, files ) { | ||
if ( err ) { | ||
done(); | ||
return; | ||
} | ||
var newNodeVersion = null; | ||
for ( var i = 0; i < files.length && newNodeVersion === null; i++ ) { | ||
var match = files[ i ].match( /^v([0-9]+\.[0-9]+\.[0-9]+)$/ ); | ||
if ( match ) { | ||
newNodeVersion = match[ 1 ]; | ||
} | ||
} | ||
if ( newNodeVersion === null ) { | ||
done(); | ||
return; | ||
} | ||
self._config.nodeVersion = newNodeVersion; | ||
nodeBinaryDirOffset = 'versions/node/'; | ||
done(); | ||
} ); | ||
} | ||
if ( newNodeVersion === null ) { | ||
done( 'failed to find node installation in NVM' ); | ||
], function() { | ||
if ( self._config.nodeVersion === null ) { | ||
done( new Error( 'could not find node installation' ) ); | ||
return; | ||
} | ||
self._config.nodeVersion = newNodeVersion; | ||
done(); | ||
@@ -208,8 +306,21 @@ } ); | ||
function( done ) { | ||
console.error( 'Linking to current node version.' ); | ||
childProcess.exec( 'ln -s v' + self._config.nodeVersion + ' vCurrent', { cwd: tmpNvmDir }, done ); | ||
console.error( 'Linking to current node version: ' + nodeBinaryDirOffset + 'v' + self._config.nodeVersion ); | ||
processExec( 'ln -s ' + nodeBinaryDirOffset + 'v' + self._config.nodeVersion + ' vCurrent', { cwd: tmpNvmDir }, done ); | ||
}, | ||
function( done ) { | ||
console.error( 'Performing npm installation.' ); | ||
processExec( tmpNvmDir + '/vCurrent/bin/npm install --production', { cwd: tmpSrcDir }, done ); | ||
}, | ||
function( done ) { | ||
if ( packageJson && packageJson.scripts && packageJson.scripts.build ) { | ||
console.error( 'Performing npm build.' ); | ||
processExec( tmpNvmDir + '/vCurrent/bin/npm run-script build', { cwd: tmpSrcDir }, done ); | ||
} else { | ||
console.error( 'No npm build script.' ); | ||
done(); | ||
} | ||
}, | ||
function( done ) { | ||
console.error( 'Boxing up package.' ); | ||
childProcess.exec( 'tar -cz ' + self._config.version + ' >| ' + self._config.version + '.tar.gz', { cwd: self._tmpDir }, done ); | ||
processExec( 'tar -cz ' + self._config.version + ' >| ' + self._config.version + '.tar.gz', { cwd: self._tmpDir }, done ); | ||
}, | ||
@@ -220,3 +331,3 @@ function( done ) { | ||
} | ||
], function( err ) { | ||
], function( err, results ) { | ||
@@ -276,3 +387,3 @@ if ( err ) { | ||
var regEx = new RegExp( '\\{\\{' + field + '\\}\\}', 'g' ); | ||
data = data.replace( regEx, self._config[field] ); | ||
data = data.replace( regEx, self._config[ field ] ); | ||
} | ||
@@ -330,3 +441,2 @@ } | ||
self._runSshCmd( node, 'sudo service ' + self._config.daemon + ' start', function( err ) { | ||
@@ -528,7 +638,7 @@ | ||
if ( self._config.debug ) { | ||
console.error( 'DEBUG', scpCmd ); | ||
} | ||
//if ( self._config.debug ) { | ||
// console.error( 'DEBUG', scpCmd ); | ||
//} | ||
childProcess.exec( scpCmd, done ); | ||
processExec( scpCmd, done ); | ||
@@ -565,17 +675,4 @@ }; | ||
childProcess.exec( sshCmd, { maxBuffer: maxBuffer }, function( err, stdout, stderr ) { | ||
processExec( sshCmd, { maxBuffer: maxBuffer }, done ); | ||
if ( self._config.debug ) { | ||
console.error( 'DEBUG', sshCmd ); | ||
if ( stdout ) { | ||
console.error( "\nSTDOUT:\n", stdout ); | ||
} | ||
if ( stderr ) { | ||
console.error( "\nSTDERR:\n", stderr ); | ||
} | ||
} | ||
done( err, stdout, stderr ); | ||
} ); | ||
}; | ||
@@ -601,3 +698,3 @@ | ||
function( done ) { | ||
childProcess.exec( 'git clone https://github.com/creationix/nvm.git /tmp/nvm.tmp', function( err, stdOut, stdErr ) { | ||
processExec( 'git clone https://github.com/creationix/nvm.git /tmp/nvm.tmp', function( err, stdOut, stdErr ) { | ||
@@ -614,3 +711,3 @@ if ( err && !stdErr.match( /already exists and is not an empty directory/ ) ) { | ||
function( done ) { | ||
childProcess.exec( 'git pull', { cwd: '/tmp/nvm.tmp' }, done ); | ||
processExec( 'git pull', { cwd: '/tmp/nvm.tmp' }, done ); | ||
} | ||
@@ -652,6 +749,6 @@ ], function( err ) { | ||
function( done ) { | ||
childProcess.exec( 'rm -rf ' + self._config.srcDir, done ); | ||
processExec( 'rm -rf ' + self._config.srcDir, done ); | ||
}, | ||
function( done ) { | ||
childProcess.exec( 'mkdir ' + self._config.srcDir, done ); | ||
processExec( 'mkdir ' + self._config.srcDir, done ); | ||
} | ||
@@ -680,3 +777,3 @@ ], done ); | ||
childProcess.exec( 'git status', { cwd: self._config.srcDir }, function( err ) { | ||
processExec( 'git status', { cwd: self._config.srcDir }, function( err ) { | ||
@@ -701,3 +798,3 @@ if ( err ) { | ||
childProcess.exec( 'git config --get remote.origin.url', { cwd: self._config.srcDir }, function( err, stdout ) { | ||
processExec( 'git config --get remote.origin.url', { cwd: self._config.srcDir }, function( err, stdout ) { | ||
@@ -742,3 +839,3 @@ if ( !stdout && !err ) { | ||
clearSrc( function() { | ||
childProcess.exec( 'git clone ' + self._config.source + ' ' + self._config.srcDir, function( err ) { | ||
processExec( 'git clone ' + self._config.source + ' ' + self._config.srcDir, function( err ) { | ||
if ( err ) { | ||
@@ -758,3 +855,3 @@ done( err ); | ||
childProcess.exec( 'git pull --all', { cwd: self._config.srcDir }, function( err ) { | ||
processExec( 'git pull --all', { cwd: self._config.srcDir }, function( err ) { | ||
if ( err ) { | ||
@@ -798,3 +895,3 @@ done( err ); | ||
if ( realpath.length < 2 ) { | ||
done( 'path is invalid' ); | ||
done( new Error( 'path is invalid' ) ); | ||
return; | ||
@@ -809,3 +906,3 @@ } | ||
function( done ) { | ||
childProcess.exec( 'rm -rf ' + path, done ); | ||
processExec( 'rm -rf ' + path, done ); | ||
} | ||
@@ -816,10 +913,8 @@ ], done ); | ||
function getNodeVersion( packageFile, done ) { | ||
function getPackageFile( packageFile, done ) { | ||
var nodeVersion = null; | ||
fs.readFile( packageFile, { encoding: 'utf8' }, function( err, data ) { | ||
if ( typeof data !== 'string' ) { | ||
err = 'could not get file data'; | ||
err = new Error( 'could not get file data' ); | ||
} | ||
@@ -832,16 +927,13 @@ | ||
data = JSON.parse( data ); | ||
try { | ||
data = JSON.parse( data ); | ||
} catch ( e ) { | ||
done( e ); | ||
return; | ||
} | ||
if ( data && data.engines && data.engines.node ) { | ||
nodeVersion = data.engines.node; | ||
// convert dynamic version numbers to something NVM can understand | ||
if ( nodeVersion.match( />=|~/ ) ) { | ||
nodeVersion = nodeVersion.replace( /^[^0-9]*/, '' ).replace( /\.[^\.]*$/, '' ); | ||
} | ||
nodeVersion = nodeVersion.replace( /\.x$/, '' ); | ||
done( null, nodeVersion ); | ||
if ( data ) { | ||
done( null, data ); | ||
} else { | ||
done( 'package.json missing engines.node field' ); | ||
done( new Error( 'package.json missing data' ) ); | ||
} | ||
@@ -852,3 +944,19 @@ | ||
function getNodeVersion( packageFile, done ) { | ||
if ( packageFile && packageFile.engines && packageFile.engines.node ) { | ||
var nodeVersion = packageFile.engines.node; | ||
// convert dynamic version numbers to something NVM can understand | ||
if ( nodeVersion.match( />=|~/ ) ) { | ||
nodeVersion = nodeVersion.replace( /^[^0-9]*/, '' ).replace( /\.[^\.]*$/, '' ); | ||
} | ||
done( null, nodeVersion.replace( /\.x$/, '' ) ); | ||
} else { | ||
done( new Error( 'package.json missing engines.node field' ) ); | ||
} | ||
} | ||
module.exports = Deploid; |
{ | ||
"name": "daemonix", | ||
"description": "Daemonix is a tool for deploying and managing NodeJS systems as a daemon in Linux/Unix environments.", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"author": "Anthony Hildoer <anthony@bluerival.com>", | ||
@@ -14,12 +14,12 @@ "repository": { | ||
"dependencies": { | ||
"async": "~0.8", | ||
"commander": "~2.2", | ||
"inquirer": "~0.5", | ||
"mkdirp": "~0.5", | ||
"semver": "~2.3", | ||
"sidi": "~0.0", | ||
"temporary": "~0.0" | ||
"async": "1.2.1", | ||
"commander": "2.8.1", | ||
"inquirer": "0.8.5", | ||
"mkdirp": "0.5.1", | ||
"semver": "4.3.6", | ||
"sidi": "0.0.1", | ||
"temporary": "0.0.8" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1" | ||
"mocha": "2.2.5" | ||
}, | ||
@@ -26,0 +26,0 @@ "keywords": [ |
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
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
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
61125
17
1842
1
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasync@1.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcli-width@1.1.1(transitive)
+ Addedcommander@2.8.1(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfigures@1.7.0(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedinquirer@0.8.5(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedmkdirp@0.5.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedrx@2.5.3(transitive)
+ Addedsemver@4.3.6(transitive)
+ Addedsidi@0.0.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
- Removedansi-styles@1.0.0(transitive)
- Removedasync@0.8.0(transitive)
- Removedchalk@0.4.0(transitive)
- Removedcli-color@0.3.3(transitive)
- Removedcommander@2.2.0(transitive)
- Removedd@0.1.11.0.2(transitive)
- Removedes5-ext@0.10.64(transitive)
- Removedes6-iterator@0.1.32.0.3(transitive)
- Removedes6-symbol@2.0.13.1.4(transitive)
- Removedes6-weak-map@0.1.4(transitive)
- Removedesniff@2.0.1(transitive)
- Removedevent-emitter@0.3.5(transitive)
- Removedext@1.7.0(transitive)
- Removedhas-color@0.1.7(transitive)
- Removedinquirer@0.5.1(transitive)
- Removedlodash@2.4.2(transitive)
- Removedlru-queue@0.1.0(transitive)
- Removedmemoizee@0.3.10(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednext-tick@0.2.21.1.0(transitive)
- Removedsemver@2.3.2(transitive)
- Removedsidi@0.0.2(transitive)
- Removedstrip-ansi@0.1.1(transitive)
- Removedtimers-ext@0.1.8(transitive)
- Removedtype@2.7.3(transitive)
Updatedasync@1.2.1
Updatedcommander@2.8.1
Updatedinquirer@0.8.5
Updatedmkdirp@0.5.1
Updatedsemver@4.3.6
Updatedsidi@0.0.1
Updatedtemporary@0.0.8