-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from christopheranderson/dev
Merge Dev for 0.2.0-alpha update
- Loading branch information
Showing
10 changed files
with
310 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
var demeteorizer = require('demeteorizer'), | ||
_ = require('underscore'), | ||
path = require('path'), | ||
promise = require('bluebird'), | ||
logger = require('./logger'); | ||
_ = require('underscore'), | ||
path = require('path'), | ||
promise = require('bluebird'), | ||
logger = require('./logger'); | ||
|
||
demeteorizer = promise.promisify(demeteorizer); | ||
|
||
module.exports = { | ||
run: function(options){ | ||
run: function (options) { | ||
// Fill in options with defaults | ||
options = _.defaults(options || {}, { | ||
var meteorOptions = _.defaults(options.meteor || {}, { | ||
debug: false, | ||
input: process.cwd(), | ||
directory: path.join(process.cwd(), '.demeteorized'), | ||
json: {}, | ||
architecture: null | ||
}); | ||
logger.info('run-demeteorizer','Starting Demeteorizer'); | ||
logger.verbose('run-demeteorizer','Options: ' + JSON.stringify(options)); | ||
|
||
logger.info('run-demeteorizer', 'Starting Demeteorizer'); | ||
logger.verbose('run-demeteorizer', 'Options: ' + JSON.stringify(meteorOptions)); | ||
|
||
// Run demeteorizer, which disassembles our meteor app into a node app. | ||
return demeteorizer(options) | ||
.then(function() { | ||
return demeteorizer(meteorOptions) | ||
.then(function () { | ||
logger.info('run-demeteorizer', 'Demeteorization Finished'); | ||
}).catch(function(err){ | ||
}).catch(function (err) { | ||
logger.error('run-demeteorizer', 'Demeteorizer encountered an error'); | ||
return promise.reject(err); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,99 @@ | ||
var fs = require('fs'), | ||
_ = require('underscore'), | ||
path = require('path'), | ||
Promise = require('bluebird'), | ||
logger = require('./logger'), | ||
spawn = require('child_process').spawn; | ||
|
||
_ = require('underscore'), | ||
path = require('path'), | ||
Promise = require('bluebird'), | ||
logger = require('./logger'), | ||
spawn = require('child_process').spawn, | ||
assert = require('assert'); | ||
|
||
var stat = Promise.promisify(fs.stat); | ||
|
||
var pathToServer = './.demeteorized/bundle/programs/server'; | ||
|
||
module.exports = { | ||
run: function() { | ||
logger.info('run-install','Starting Installation'); | ||
return new Promise(function(resolve, reject) { | ||
run: function (options) { | ||
logger.info('run-install', 'Starting Installation'); | ||
return new Promise(function (resolve, reject) { | ||
// Check that the file path exists | ||
stat(pathToServer) | ||
.catch(reject) | ||
.then(function() { | ||
logger.verbose('run-install','Changing directory to ', pathToServer); | ||
process.chdir(pathToServer); | ||
}) | ||
// Installs npm packages required by demeteorized app | ||
.then(install) | ||
.catch(reject) | ||
// Copy the program.json file to the bundle directory (because meteor expects our Node app to start in the server folder...) | ||
.then(copyProgramsJson) | ||
.catch(reject) | ||
.then(function(){ | ||
// Jump down to bundle | ||
// TODO: this is pretty hacky | ||
logger.verbose('run-install','Changing directory to ', path.join(pathToServer, '../..')); | ||
process.chdir('../..'); | ||
}) | ||
// Copy the Web.config file into the root directory so IIS Node will use "main.js" | ||
.then(copyWebConfig) | ||
.catch(reject) | ||
.then(function() { | ||
// Return to where we started | ||
// TODO: this is pretty hacky too | ||
logger.verbose('run-install','Changing directory to ', path.join(pathToServer, '../../../..')) | ||
process.chdir('../..'); | ||
resolve(); | ||
}); | ||
.catch(reject) | ||
.then(function () { | ||
logger.verbose('run-install', 'Changing directory to ', pathToServer); | ||
process.chdir(pathToServer); | ||
}) | ||
// Installs npm packages required by demeteorized app | ||
.then(install) | ||
.catch(reject) | ||
// Copy the program.json file to the bundle directory (because meteor expects our Node app to start in the server folder...) | ||
.then(copyProgramsJson) | ||
.catch(reject) | ||
.then(function () { | ||
// Jump down to bundle | ||
// TODO: this is pretty hacky | ||
logger.verbose('run-install', 'Changing directory to ', path.join(pathToServer, '../..')); | ||
process.chdir('../..'); | ||
return options.pathToWebConfig; | ||
}) | ||
// Copy the Web.config file into the root directory so IIS Node will use "main.js" | ||
.then(copyWebConfig) | ||
.catch(reject) | ||
.then(function () { | ||
// Return to where we started | ||
// TODO: this is pretty hacky too | ||
logger.verbose('run-install', 'Changing directory to ', path.join(pathToServer, '../../../..')) | ||
process.chdir('../..'); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
var install = function() { | ||
return new Promise(function(resolve, reject) { | ||
var install = function () { | ||
return new Promise(function (resolve, reject) { | ||
// Run npm install | ||
logger.verbose('run-install','Installing packages for server'); | ||
logger.verbose('run-install', 'Installing packages for server'); | ||
var isWin = /^win/.test(process.platform); | ||
var child = spawn(isWin ? 'cmd' : 'sh', [isWin?'/c':'-c', 'npm', 'install']); | ||
var child = spawn(isWin ? 'cmd' : 'sh', [isWin ? '/c' : '-c', 'npm', 'install']); | ||
child.stdout.pipe(process.stdout); | ||
child.stderr.pipe(process.stderr); | ||
child.on('error', function(err) { | ||
child.on('error', function (err) { | ||
logger.error('run-install', err); | ||
reject(err); | ||
}); | ||
child.on('exit', function(code) { | ||
if(code != 0) return reject(new Error('npm install failed, see npm-debug.log for more details')); | ||
child.on('exit', function (code) { | ||
if (code != 0) return reject(new Error('npm install failed, see npm-debug.log for more details')); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
var copyFile = function(source, target) { | ||
var copyFile = function (source, target) { | ||
logger.verbose('run-install','Copying: ' + source + ' to: ' + target); | ||
// Took some ideas from: http://stackoverflow.com/a/14387791/3662111 | ||
return new Promise(function(resolve, reject) { | ||
return new Promise(function (resolve, reject) { | ||
var rd = fs.createReadStream(source); | ||
rd.on("error", function(err) { | ||
rd.on("error", function (err) { | ||
reject(err); | ||
}); | ||
var wr = fs.createWriteStream(target); | ||
wr.on("error", function(err) { | ||
wr.on("error", function (err) { | ||
reject(err); | ||
}); | ||
wr.on("close", function(ex) { | ||
wr.on("close", function (ex) { | ||
resolve(); | ||
}); | ||
var status = logger.newStream('Moving file - ' + path.basename(source), fs.statSync(source).size); | ||
rd.pipe(status).pipe(wr); | ||
}) | ||
} | ||
|
||
var copyWebConfig = function() { | ||
return copyFile(path.join(__dirname, '../resources/web.config'), path.join(process.cwd(), 'web.config')); | ||
var copyWebConfig = function (pathToWebConfig) { | ||
if(pathToWebConfig) logger.verbose('run-install','Custom Web.config! Relative path to Web.config: ' + pathToWebConfig); | ||
var _pathToWebConfig = pathToWebConfig || path.join(__dirname, '../resources/web.config'); | ||
assert(fs.existsSync(_pathToWebConfig), 'Error: The specified web.config does not exist: ' + _pathToWebConfig); | ||
return copyFile(_pathToWebConfig, path.join(process.cwd(), 'web.config')); | ||
} | ||
|
||
var copyProgramsJson = function() { | ||
var copyProgramsJson = function () { | ||
return copyFile(path.join(process.cwd(), 'program.json'), path.join(process.cwd(), '../../program.json')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
var Promise = require('bluebird'), | ||
logger = require('./logger'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
semver = require('semver'); | ||
|
||
var exec = Promise.promisify(require('child_process').exec); | ||
|
||
var versionChecks = [{ | ||
name: 'node', | ||
cmd: 'node -v', | ||
versions: '0.10.40' | ||
}, | ||
{ | ||
name: 'python', | ||
cmd: 'python ' + path.join(__dirname, '../version.py'), // for some reason, python --version doesn't return on stdout | ||
versions: '2.7.x' | ||
}, | ||
{ | ||
name: 'meteor', | ||
cmd: 'meteor --version', | ||
versions: '>0.8.1 || 1.x' | ||
}] | ||
|
||
module.exports = { | ||
run: function(options){ | ||
logger.level = 'silly'; | ||
return new Promise(function(resolve, reject){ | ||
Promise.all(versionChecks.map(function(check){ | ||
return validateVersion(check.name, check.cmd, check.versions); | ||
})) | ||
.catch(reject) | ||
.then(checkForVCR) | ||
.catch(reject) | ||
.then(resolve); | ||
}); | ||
} | ||
} | ||
|
||
var validateVersion = function(name, cmd, versions) { | ||
return new Promise(function(resolve, reject) { | ||
exec(cmd) | ||
.catch(reject) | ||
.then(function(result){ | ||
logger.silly(cmd + ' -> stdout: ' + result); | ||
var matches = result.match(/(\d+\.\d+\.\d+)/g); | ||
var curr = matches ? matches[0] : null; | ||
if(curr && semver.satisfies(curr, versions)){ | ||
logger.verbose('run-precheck', name + ' has a valid version. Current version: ' + curr + ' Valid version(s): ' + versions); | ||
resolve(); | ||
} else { | ||
reject(name + ' has an invalid version. Current version: ' + curr + ' Valid version(s): ' + versions); | ||
} | ||
}) | ||
.then(resolve, reject); | ||
}) | ||
} | ||
|
||
var checkForVCR = function() { | ||
return new Promise(function(resolve, reject) { | ||
if(!process.env.windir) return resolve('Could not find windows directory'); | ||
fs.readdir(path.resolve(process.env.windir, 'System32'), function(err, dirs){ | ||
if(err) reject(err); | ||
dirs = dirs.filter(function(i) { | ||
if(i.indexOf('msvcr') > -1) { | ||
return i; | ||
} | ||
}); | ||
if(dirs.length > 0) { | ||
logger.verbose('run-precheck', 'Has a version of MSVCR installed'); | ||
return resolve(); | ||
} else { | ||
return reject('You need to install a Microsoft Visual C++ Redistributable. Consult node-gyp for more information. Installation will likely fail.'); | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.