tooltwist
Version:
Tooltwist Command Line Interface
668 lines (537 loc) • 23.6 kB
JavaScript
var fs = require('fs'),
path = require('path'),
parseString = require('xml2js').parseString,
Log = require('./log'),
Config = require('./config'),
glob = require("glob");
exports.Controller = function(){
Log.debug('controller.Controller()')
Log.info();
Log.info('Loading details from Controller config files...')
// Get the launchpad name
var config = Config.getConfig();
if (config['deploy'].launchpad) {
// Use launchpad from the config file
Log.debug();
Log.debug('Using launchpad from config file.');
exports.LAUNCHPAD_NAME = config['deploy'].launchpad;
} else {
// Get launchpad from directory name
Log.debug();
Log.debug('Use directory name as launchpad.');
exports.LAUNCHPAD_NAME = path.basename(Config.PROJECT_ROOT);
}
Log.info();
Log.info(" LAUNCHPAD=" + exports.LAUNCHPAD_NAME)
loadGlobals_fromController();
loadLaunchpadDetails_fromController();
loadGeneratorSlotDetails();
loadServerSlotDetails();
loadPayloadDetails();
}
exports.init_fromConfig = function(){
Log.debug('*************** Controller.init()')
// Log.error('\n\n\n\n\ncontroller.js init')
exports.LAUNCHPAD_NAME = 'deploy';
// loadGlobals();
//exports.TTC_HOST = 'localhost',
//exports.TTC_PORT = (Config.HTTP_PORT ? Config.HTTP_PORT : 5000);
//ZZZZ This should not be used, because there may be multiple servers
exports.PRODUCTION_SERVER = Config.getConfig().deploy.servers[0].host;
exports.PRODUCTION_SERVER_HOME = Config.getConfig().deploy.servers[0].serverHome;
exports.IMAGE_DIR = Config.HIDDEN_DIR + "/image"
/*
export PAYLOAD_HOME=${TTC_DEPLOY}/payloads
export VERSIONS_HOME=${TTC_DEPLOY}/versions
export LAUNCHPAD_HOME=${TTC_DEPLOY}/launchpads
export CUSTCONF_HOME=${TTC_DEPLOY}/custom-config-files
*/
// exports.GENCONF_HOME = exports.TTC_DEPLOY + '/generated-config-files';
// exports.CUSTCONF_HOME = exports.TTC_DEPLOY + '/custom-config-files';
// exports.JENKINS_HOME = exports.TTC_DEPLOY + '/jenkins';
// exports.JENKINS_PORT = Config.controller.jenkinsPort;
// exports.OS = Config.controller.os,
// exports.JAVAC_MEMORY = Config.controller.javacMemory,
// exports.JAVAC_DEBUG = Config.controller.javacDebug,
// exports.THIS_SCRIPT = File.basename(__FILE__)
// exports.BIN_DIR = File.expand_path(File.dirname(__FILE__))
// var RESOURCES_DIR = __dirname + '/..';
// Set other values
// exports.CONTROLLER_HOME = exports.TTC_DEPLOY;
// exports.LAUNCHPAD_HOME = exports.TTC_DEPLOY + "/launchpads" //ZZZZZ Is this really used anywhere?
// exports.LAUNCHPAD_DIR = exports.TTC_DEPLOY + "/launchpads/" + exports.LAUNCHPAD_NAME
// exports.IMAGE_DIR = Config.HIDDEN_DIR + "/image"
// exports.BUILD_FILE = exports.LAUNCHPAD_DIR + "/build.xml"
// exports.SUMMARY_FILE = exports.LAUNCHPAD_DIR + "/CONFIG_SUMMARY"
// //loadLaunchpadDetails();
// //loadGeneratorSlotDetails();
// loadServerSlotDetails();
// loadPayloadDetails();
}
/*
* Get environment variables
*/
function loadGlobals(){
console.log('loadGlobals() - I DONT THINK THIS IS CALLED')
process.exit(1);
//
//
//
// NOTE: Used for Deploy, not Controller
//
//
//
//ZZZZ Check which of these are actually needed
// TTC_CONFIG, something like ${TTC_HOME}/devel/ttc/config
exports.TTC_CONFIG = Config.controller.configDir;
if (exports.TTC_CONFIG == null || exports.TTC_CONFIG == "") {
softbomb("Value config.controller.configDir not defined in tooltwist.js")
}
var stat = fs.statSync(exports.TTC_CONFIG);
if ( !stat.isDirectory(exports.TTC_CONFIG)) {
softbomb("Value config.controller.configDir in tooltwist.js refers to an invalid directory: " + exports.TTC_CONFIG)
}
// TTC_DEPLOY, something like /ControllerV8
exports.TTC_DEPLOY = Config.controller.deployDir
if (exports.TTC_DEPLOY == null || exports.TTC_DEPLOY == "") {
bomb("Value config.controller.deployDir not defined in tooltwist.js")
}
var stat = fs.statSync(exports.TTC_DEPLOY);
if ( !stat.isDirectory(exports.TTC_DEPLOY)) {
bomb("Value config.controller.deployDir in tooltwist.js refers to an invalid directory: " + exports.TTC_DEPLOY)
}
//exports.TTC_HOST = 'localhost',
// exports.TTC_PORT = Config['designer'].port,
/*
export PAYLOAD_HOME=${TTC_DEPLOY}/payloads
export VERSIONS_HOME=${TTC_DEPLOY}/versions
export LAUNCHPAD_HOME=${TTC_DEPLOY}/launchpads
export CUSTCONF_HOME=${TTC_DEPLOY}/custom-config-files
*/
exports.GENCONF_HOME = exports.TTC_DEPLOY + '/generated-config-files';
exports.CUSTCONF_HOME = exports.TTC_DEPLOY + '/custom-config-files';
exports.JENKINS_HOME = exports.TTC_DEPLOY + '/jenkins';
exports.JENKINS_PORT = Config.controller.jenkinsPort;
exports.OS = Config.controller.os,
exports.JAVAC_MEMORY = Config.controller.javacMemory,
exports.JAVAC_DEBUG = Config.controller.javacDebug,
// exports.THIS_SCRIPT = File.basename(__FILE__)
// exports.BIN_DIR = File.expand_path(File.dirname(__FILE__))
// var RESOURCES_DIR = __dirname + '/..';
// Set other values
exports.CONTROLLER_HOME = exports.TTC_DEPLOY;
exports.LAUNCHPAD_HOME = exports.TTC_DEPLOY + "/launchpads" //ZZZZZ Is this really used anywhere?
exports.LAUNCHPAD_DIR = exports.TTC_DEPLOY + "/launchpads/" + exports.LAUNCHPAD_NAME
exports.IMAGE_DIR = Config.HIDDEN_DIR + "/image"
exports.BUILD_FILE = exports.LAUNCHPAD_DIR + "/build.xml"
exports.SUMMARY_FILE = exports.LAUNCHPAD_DIR + "/CONFIG_SUMMARY"
console.log("IMAGE_DIR=", IMAGE_DIR)
process.exit(1);
// From launchpad definition
exports.LAUNCHPAD_TYPE = Config.controller.launchpadType;
}
/*
* Get properties from environment variables
*/
function loadGlobals_fromController(){
// TTC_CONFIG, something like ${TTC_HOME}/devel/ttc/config
exports.TTC_CONFIG = process.env['TTC_CONFIG']
if (exports.TTC_CONFIG == null || exports.TTC_CONFIG == "") {
softbomb("Environment variable TTC_CONFIG is not defined")
}
var stat = fs.statSync(exports.TTC_CONFIG);
if ( !stat.isDirectory(exports.TTC_CONFIG)) {
softbomb("Environment variable TTC_CONFIG refers to an invalid directory: " + exports.TTC_CONFIG)
}
// TTC_DEPLOY, something like /ControllerV8
exports.TTC_DEPLOY = process.env['TTC_DEPLOY']
if (exports.TTC_DEPLOY == null || exports.TTC_DEPLOY == "") {
bomb("Environment variable TTC_DEPLOY is not defined")
}
var stat = fs.statSync(exports.TTC_DEPLOY);
if ( !stat.isDirectory(exports.TTC_DEPLOY)) {
bomb("Environment variable TTC_DEPLOY refers to an invalid directory: " + exports.TTC_DEPLOY)
}
//exports.TTC_HOST = process.env['TTC_HOST']
//exports.TTC_PORT = process.env['TTC_PORT']
exports.GENCONF_HOME = process.env['GENCONF_HOME']
exports.CUSTCONF_HOME = process.env['CUSTCONF_HOME']
exports.JENKINS_HOME = process.env['JENKINS_HOME']
exports.JENKINS_PORT = process.env['JENKINS_PORT']
exports.OS = process.env['OS']
exports.JAVAC_MEMORY = process.env['JAVAC_MEMORY']
exports.JAVAC_DEBUG = process.env['JAVAC_DEBUG']
// exports.THIS_SCRIPT = File.basename(__FILE__)
// exports.BIN_DIR = File.expand_path(File.dirname(__FILE__))
// var RESOURCES_DIR = __dirname + '/..';
// Set other values
exports.CONTROLLER_HOME = "/ControllerV8"
exports.LAUNCHPAD_HOME = exports.TTC_DEPLOY + "/launchpads" //ZZZZZ Is this really used anywhere?
exports.LAUNCHPAD_DIR = exports.TTC_DEPLOY + "/launchpads/" + exports.LAUNCHPAD_NAME
exports.IMAGE_DIR = exports.TTC_DEPLOY + "/launchpads/" + exports.LAUNCHPAD_NAME + "/image"
exports.BUILD_FILE = exports.LAUNCHPAD_DIR + "/build.xml"
exports.SUMMARY_FILE = exports.LAUNCHPAD_DIR + "/CONFIG_SUMMARY"
}
/**
* Load the launchpad configuration
*/
function loadLaunchpadDetails_fromController(){
Log.debug("\nloadLaunchpadDetails_fromController()")
var launchpadFile = exports.TTC_DEPLOY + "/config-files/launchpad." + exports.LAUNCHPAD_NAME + ".xml"
if ( !fs.existsSync(launchpadFile)) {
bomb("Unknown launchpad " + exports.LAUNCHPAD_NAME)
}
Log.debug(' launchpad config: ' + launchpadFile);
var xml = fs.readFileSync(launchpadFile, { encoding: 'UTF-8' });
parseString(xml, { async: false }, function (err, result) {
//console.dir(result);
//description = result.config.description[0]
exports.LAUNCHPAD_TYPE = result.config.type[0]
//latestStatus = result.config.latestStatus[0]
//disable = result.config.disable[0]
Log.info(' LAUNCHPAD_TYPE=' + exports.LAUNCHPAD_TYPE);
});
}
/*
* Load the generator slot configuration into global variables
*/
function loadGeneratorSlotDetails(){
//print "\nloadGeneratorSlotDetails(#{exports.LAUNCHPAD_NAME})\n"
// Find all generator slot config files.
var found = false;
var list = glob.sync(exports.TTC_DEPLOY + "/config-files/generatorSlot.*.xml")
list.forEach(function (file, index) {
// Load the XML config file
var xml = fs.readFileSync(file, { encoding: 'UTF-8' });
parseString(xml, { async: false }, function (err, result) {
// See if this is for the right launchpad
if (result.generatorSlot.launchpadUsingThisSlot != exports.LAUNCHPAD_NAME)
return;
Log.info();
Log.info(' generatorSlot config: ' + file);
// Get the name of this slot
var slot = file.substring(0, file.length - 4) // Strip off .xml
var pos = slot.lastIndexOf('/generatorSlot.')
if (pos >= 0)
slot = slot.substring(pos + '/generatorSlot.'.length)
exports.GENERATOR_SLOT_NAME = slot
// Get other details
exports.GENERATOR_DESCRIPTION = result.generatorSlot.description[0];
// exports.GENERATOR_HTTP_PORT = result.generatorSlot.httpPort[0];
// exports.GENERATOR_HTTPS_PORT = result.generatorSlot.httpsPort[0];
// exports.GENERATOR_SERVER_PORT = result.generatorSlot.serverPort[0];
// exports.GENERATOR_AJP_PORT = result.generatorSlot.ajpPort[0];
exports.GENERATOR_HTTP_PORT = Config.HTTP_PORT;
// exports.GENERATOR_HTTPS_PORT = Config.HTTPS_PORT;
// exports.GENERATOR_SERVER_PORT = result.generatorSlot.serverPort[0];
exports.GENERATOR_AJP_PORT = Config.AJP_PORT;
exports.GENERATOR_DISABLE = result.generatorSlot.disable[0]; //ZZZZZZZZZZ Check this
exports.GENERATOR_INSTALL_TOMCAT = result.generatorSlot.installTomcat[0];
exports.GENERATOR_IMAGEMAGICK_HOME = result.generatorSlot.imagemagickHome[0];
// Nice debug message
Log.info(' GENERATOR_DESCRIPTION=' + exports.GENERATOR_DESCRIPTION);
Log.info(' GENERATOR_HTTP_PORT=' + exports.GENERATOR_HTTP_PORT);
// Log.info(' GENERATOR_HTTPS_PORT=' + exports.GENERATOR_HTTPS_PORT);
Log.info(' GENERATOR_SERVER_PORT=' + exports.STOP_PORT);
Log.info(' GENERATOR_AJP_PORT=' + exports.GENERATOR_AJP_PORT);
Log.info(' GENERATOR_DISABLE=' + exports.GENERATOR_DISABLE);
// Log.info(' GENERATOR_INSTALL_TOMCAT=' + exports.GENERATOR_INSTALL_TOMCAT);
// Log.info(' GENERATOR_IMAGEMAGICK_HOME=' + exports.GENERATOR_IMAGEMAGICK_HOME);
found = true;
});
});
// Check a generator slot was found
if ( !found) {
bomb('\nError: No generator slot found for launchpad \'' + exports.LAUNCHPAD_NAME + '\'.\n');
}
}
//
// Load the server slot configuration into global variables
//
function loadServerSlotDetails(){
Log.debug('\nloadServerSlotDetails()')
// Find all server slot config files.
var server_def = null;
var required_group = null; // Set if the server is a group
var list = glob.sync(exports.TTC_DEPLOY + "/config-files/serverSlot.*.xml")
list.forEach(function (file, index) {
// Load the XML config file
var xml = fs.readFileSync(file, { encoding: 'UTF-8' });
parseString(xml, { async: false }, function (err, result) {
// See if this is for the right launchpad
if (result.serverSlot.launchpadUsingThisSlot != exports.LAUNCHPAD_NAME)
return;
Log.info();
Log.info(' serverSlot config: ' + file);
// Get the name of this slot
var slot = file.substring(0, file.length - 4) // Strip off .xml
var pos = slot.lastIndexOf('/serverSlot.')
if (pos >= 0)
slot = slot.substring(pos + '/serverSlot.'.length)
exports.PRODUCTION_SLOT_NAME = slot
// See if this server slot represents a group of server slots
var isGroup = result.serverSlot.isGroup;
if (isGroup == "Y") {
required_group = exports.PRODUCTION_SLOT_NAME
}
server_file = file
server_def = result;
});
});
// Check a server slot was found
if ( !server_def) {
bomb('\nError: No server slot found for launchpad \'' + exports.LAUNCHPAD_NAME + '\'.\n');
}
/*
* If this server slot is a group, get the details from the first server slot in the group.
*/
if (required_group){
//ZZZZZ Need to test this.
Log.info("Launchpad uses group " + required_group + "\n")
// This is a group, so find the first server in the group -> server_xml
server_def = null
var list = glob.sync(exports.TTC_DEPLOY + "/config-files/serverSlot.*.xml")
list.forEach(function (file, index) {
if (server_def) return; // Already found first slot.
// Load the XML config file
var xml = fs.readFileSync(file, { encoding: 'UTF-8' });
parseString(xml, { async: false }, function (err, result) {
// See if this is for the right launchpad
if (result.serverSlot.group != required_group)
return;
Log.info(' group config: ' + file);
// This is the correct group. Use it's XML defintion
var slot = file.substring(0, file.length - 4) // Strip off .xml
var pos = slot.lastIndexOf('/serverSlot.')
if (pos >= 0)
slot = slot.substring(pos + '/serverSlot.'.length)
exports.PRODUCTION_SLOT_NAME = slot
Log.debug("Server " + exports.PRODUCTION_SLOT_NAME + " is the first in the group.\n")
server_file = file;
server_def = result;
});
});
// Check that the group had at least one server slot
if (server_def == nil){
bomb('\nError: No server slot found for server group \'' + required_group + '\'.\n');
}
}
// Get details from the server's XML
Log.debug("Using config from server '" + exports.PRODUCTION_SLOT_NAME + "' for all servers in this group.\n")
Log.debug("server_file: " + server_file)
exports.PRODUCTION_DESCRIPTION = server_def.serverSlot.description[0];
exports.PRODUCTION_IS_GROUP = server_def.serverSlot.isGroup[0];
exports.PRODUCTION_SERVER_HOME = server_def.serverSlot.serverHome[0];
exports.PRODUCTION_WEBAPP_NAME = server_def.serverSlot.webappName[0];
exports.PRODUCTION_HTTP_PORT = server_def.serverSlot.httpPort[0];
exports.PRODUCTION_HTTPS_PORT = server_def.serverSlot.httpsPort[0];
exports.PRODUCTION_SERVER_PORT = server_def.serverSlot.serverPort[0];
exports.PRODUCTION_AJP_PORT = server_def.serverSlot.ajpPort[0];
exports.PRODUCTION_WEBAPPS_DIR = server_def.serverSlot.webappsDir[0];
exports.PRODUCTION_TOMCAT_HOME = server_def.serverSlot.tomcatHome[0];
exports.PRODUCTION_INSTALL_CMD = server_def.serverSlot.installCmd[0];
exports.PRODUCTION_INSTALL_METHOD = server_def.serverSlot.installMethod[0];
exports.PRODUCTION_SERVER = server_def.serverSlot.server[0];
exports.PRODUCTION_USERNAME = server_def.serverSlot.username[0];
exports.PRODUCTION_PASSWORD = server_def.serverSlot.password[0];
exports.PRODUCTION_INSTALL_TOMCAT = server_def.serverSlot.installTomcat[0];
exports.PRODUCTION_IMAGEMAGICK_HOME = server_def.serverSlot.imagemagickHome[0];
exports.PRODUCTION_SSH_PORT = server_def.serverSlot.sshPort[0];
exports.PRODUCTION_FIP_PORT = server_def.serverSlot.fipPort[0];
// Display a nice debug message
Log.info(' PRODUCTION_DESCRIPTION=' + exports.PRODUCTION_DESCRIPTION);
Log.info(' PRODUCTION_IS_GROUP=' + exports.PRODUCTION_IS_GROUP);
Log.info(' PRODUCTION_SERVER_HOME=' + exports.PRODUCTION_SERVER_HOME);
Log.info(' PRODUCTION_WEBAPP_NAME=' + exports.PRODUCTION_WEBAPP_NAME);
Log.info(' PRODUCTION_HTTP_PORT=' + exports.PRODUCTION_HTTP_PORT);
Log.info(' PRODUCTION_HTTPS_PORT=' + exports.PRODUCTION_HTTPS_PORT);
Log.info(' PRODUCTION_SERVER_PORT=' + exports.PRODUCTION_SERVER_PORT);
Log.info(' PRODUCTION_AJP_PORT=' + exports.PRODUCTION_AJP_PORT);
Log.info(' PRODUCTION_WEBAPPS_DIR=' + exports.PRODUCTION_WEBAPPS_DIR);
Log.info(' PRODUCTION_TOMCAT_HOME=' + exports.PRODUCTION_TOMCAT_HOME);
Log.info(' PRODUCTION_INSTALL_CMD=' + exports.PRODUCTION_INSTALL_CMD);
Log.info(' PRODUCTION_INSTALL_METHOD=' + exports.PRODUCTION_INSTALL_METHOD);
Log.info(' PRODUCTION_SERVER=' + exports.PRODUCTION_SERVER);
Log.info(' PRODUCTION_USERNAME=' + exports.PRODUCTION_USERNAME);
Log.info(' PRODUCTION_PASSWORD=' + exports.PRODUCTION_PASSWORD);
Log.info(' PRODUCTION_INSTALL_TOMCAT=' + exports.PRODUCTION_INSTALL_TOMCAT);
Log.info(' PRODUCTION_IMAGEMAGICK_HOME=' + exports.PRODUCTION_IMAGEMAGICK_HOME);
Log.info(' PRODUCTION_SSH_PORT=' + exports.PRODUCTION_SSH_PORT);
Log.info(' PRODUCTION_FIP_PORT=' + exports.PRODUCTION_FIP_PORT);
}
/*
def self.deploymentConfigFile(exports.LAUNCHPAD_NAME)
config_file = "#{$TTC_DEPLOY}/config-files/deploymentConfig.#{exports.LAUNCHPAD_NAME}.xml"
return config_file
end
*/
/*
* Load the payload details.
* In this v8.3, this means a single webdesign project.
*/
function loadPayloadDetails(){
Log.debug("loadPayloadDetails()\n")
var config_file = exports.TTC_DEPLOY + "/config-files/deploymentConfig." + exports.LAUNCHPAD_NAME + ".xml";
if ( !fs.existsSync(config_file)) {
bomb("Unknown file " + config_file + "\n")
}
Log.info();
Log.info(' deployment config: ' + config_file);
// Load the XML config file
exports.WEBDESIGN_PAYLOAD = null;
var xml = fs.readFileSync(config_file, { encoding: 'UTF-8' });
parseString(xml, { async: false }, function (err, result) {
// Look for the webdesign project
result.config.payload.forEach(function (payload, index){
if (payload.layer[0] == 'webdesign'){
exports.WEBDESIGN_PAYLOAD = payload.name[0];
exports.WEBDESIGN_VERSION = payload.version[0];
exports.WEBDESIGN_VERSION_TYPE = payload.versionType[0];
Log.debug("payload = ", payload);
Log.info(" WEBDESIGN_PAYLOAD=" + exports.WEBDESIGN_PAYLOAD);
Log.info(" WEBDESIGN_VERSION=" + exports.WEBDESIGN_VERSION);
Config.setProjectName(exports.WEBDESIGN_PAYLOAD)
}
});
});
if (exports.WEBDESIGN_PAYLOAD == null) {
bomb("Launchpad has no webdesign project")
}
// Go to the payload definition to find the Repository URL
// In the future, this might be stored in the launchpad itself.
// Load the XML config file
var payloadConfig = exports.TTC_DEPLOY + "/payloads/webdesign-projects/" + exports.WEBDESIGN_PAYLOAD + "/payload.xml";
Log.info();
Log.info(' web design config: ' + payloadConfig);
var xml = fs.readFileSync(payloadConfig, { encoding: 'UTF-8' });
parseString(xml, { async: false }, function (err, result) {
Log.debug('payload def = ', result)
var versionType = result.version.versionType[0];
var type = result.version.type[0];
var description = result.version.description[0];
var remoteUrl = result.version.remoteUrl[0];
// var gitUser = result.version.gitUser[0];
// var gitPassword = result.version.gitPassword[0];
exports.WEBDESIGN_REMOTEURL = remoteUrl;
Log.info(' WEBDESIGN_REMOTEURL=' + exports.WEBDESIGN_REMOTEURL);
});
}
/*
* A terrible error has occurred - bomb out, removing the summary and build.xml files
*/
function bomb(msg){
// Display the error message
Log.always("\n**\n** Fatal error: " + msg + "\n**\n\n");
/*ZZZZZ
// Remove the build and summary file.
if ($BUILD_FILE != nil and File.exist?($BUILD_FILE)) {
Log.debug("- removing #{$BUILD_FILE}.\n")
FileUtils.rm($BUILD_FILE)
}
if ($SUMMARY_FILE != nil and File.exist?($SUMMARY_FILE)) {
Log.debug("- removing #{$SUMMARY_FILE}.\n")
FileUtils.rm($SUMMARY_FILE)
}
*/
// Display the error message and exit with an error status
process.exit(1)
}
function softbomb(msg){
//Display the error message and exit with an error status
Log.error('\n**\n** Fatal error: ' + msg + '\n**\n\n');
process.exit(1);
}
/*
NOW CALLED FROM GRADLE
exports.runGrunt = function(callback){
// Run npm to update Grunt packages
Log.log();
Log.log('***************************************************************************')
Log.log('*** ***')
Log.log('*** Grunt phase ***')
Log.log('*** ***')
Log.log('***************************************************************************')
Log.log('Checking packages used by Grunt')
var gruntDir = Config.HIDDEN_DIR + "/PHASE2";
Log.info('$ cd ' + gruntDir)
Log.info('$ npm install')
system('npm', [ 'install' ], { cwd: gruntDir }, function(){
// npm has finished, so now run grunt
Log.info('\n$ grunt')
system('grunt', [ ], { cwd: gruntDir }, function(status){
// If an error occurred with Grunt, display a message and bomb out.
if (status !== 0) {
Log.fatalError('Grunt returned error code ' + status);
}
// Carry on to the next step
Log.info('\nGrunt finished.')
return callback();
});
});
/ *
// Run Grunt in this process.
// Provide grunt with command line arguments
// This overrides the real command line passed to the 'tooltwist' command,
// but they have already been parsed so it's okay.
process.argv = [ process.argv[0], 'grunt', '--gruntfile', Config.HIDDEN_DIR + '/PHASE2/Gruntfile.js' ]
//Log.debug('process.argv=', process.argv)
// Now run the default grunt task, taken from gruntfile.js
var g = require('grunt')
g.cli.tasks = ['default'];
g.cli()
Log.info('\nGrunt completed')
return callback();
});
* /
};
*/
/*
MOVED TO GRUNT
exports.transfer = function(callback){
Log.log()
Log.log('***************************************************************************')
Log.log('*** ***')
Log.log('*** Transfer phase ***')
Log.log('*** ***')
Log.log('***************************************************************************')
Log.info('$ cd ' + Config.HIDDEN_DIR + '/do_install')
Log.info('$ gradle')
system('gradle', [ ], { cwd: Config.HIDDEN_DIR + '/do_install' }, function(status){
// If the install failed display a message and bomb out.
if (status !== 0) {
Log.fatalError('InstallerUtil/Gradle returned error code ' + status);
}
// Installed ok, carry on.
Log.info('\ninstall finished.')
return callback();
});
};
*/
/**
* Run a command from the shell
*/
// Is this used?
function system(command, args, options, callback) {
var spawn = require('child_process').spawn;
var child = spawn(command, args, options);
child.on('error', function(e) {
Log.error('\nFatal Error running \'' + command + '\':\n' + e + '\n');
process.exit(1)
});
// Echo the output of the command
process.stdout.write(' ')
child.stdout.on('data', function (data) {
var str = '' + data;
str = str.replace(/\n/g, "\n ")
process.stdout.write(str);
});
child.stderr.on('data', function (data) {
var str = '' + data;
str = str.replace(/\n/g, "\n ")
process.stdout.write(str);
});
// Handle the process completion.
child.on('close', function (code) {
return callback(code);
});
}