tooltwist
Version:
Tooltwist Command Line Interface
164 lines (134 loc) • 4.84 kB
JavaScript
/**
* Plugin to create a Docker container
*/
var fs = null,
Log = null,
Gradle = null,
mkdirp = require('mkdirp'),
Config = null,
Templates = null;
/**
* Set up the plugin
*/
exports.init = function(appDir) {
// console.log('plugins.docker.init()')
// Run requires, based on main app directory (i.e. not relative to the plugin)
Log = require(appDir + '/log');
Config = require(appDir + '/config');
Templates = require(appDir + '/templates');
Gradle = require(appDir + '../../lib/gradle');
fs = require('fs');
//ZZZZZ Check Docker is installed
}
/**
* Create a default config file for the Designer.
*/
exports.commandLineInit = function() {
// console.log('plugins.docker.commandLineInit()')
// Use the template to create the initial config file
var from = __dirname + '/templates/' + "war-tooltwist.js"
Log.debug('from=' + from)
var data = {
MODE: 'war',
// HOST: HOST
};
var creatingExampleTemplate = false;
Templates.copy(from, Config.CONFIG_FILE, creatingExampleTemplate, data);
// Create example templates
Templates.createExampleTemplates({ mode: 'war'});
// Display a nice message.
Log.always();
Log.always('\tSpecification file \'' + Config.CONFIG_FILE + '\' has been created with a default');
Log.always('\tconfiguration to install the demo webdesign project \'ttdemo\' into');
Log.always('\ta war file. Modify this file to suit your needs, then run:');
Log.always();
Log.always('\t $ tooltwist war')
Log.always();
Log.always('\tFor debugging purposes you can also run:')
Log.always();
Log.always('\t $ tooltwist designer')
Log.always();
// All done
process.exit(0)
}
exports.beforePhase1 = function() {
// console.log('plugins.docker.beforePhase1()')
var config = Config.getConfig();
// DESIGNER MODE
Config.REPO = config['designer'].repo;
//ZZZ check is set
Config.BRANCH = config['designer'].branch;
// ZZZ check works if undefined
Config.USE_PHASE2 = true;
}
/**
* This function is called as soon as PHASE1 detects that Tomcat is running.
*/
exports.tomcatRunning = function() {
// console.log('\nplugins.docker.tomcatRunning()')
// Display a nice message for Designer users.
//Log.log();
// Log.log(' (Server can be stopped with Control-C)');
// Log.log();
Log.log();
Log.log();
Log.log('\t\t THE SERVER IS NOW RUNNING.')
Log.log();
Log.log('\t\t http://localhost:' + Config.HTTP_PORT + '/ttsvr/login');
Log.log();
Log.log();
// Log.log();
//Log.log(' Default log file is ' + Config.HIDDEN_DIR + '/tooltwist.log')
}
/**
* This function is called after generating the default build files from
* templates, but before starting Phase 2. Note that phase 2 occurs WITHIN
* phase 1, so afterPhase1() has not been called yet.
*/
exports.beforePhase2 = function() {
// console.log("plugins.docker.beforePhase2");
// Set a few extra variables
var config = Config.getConfig();
config.CONTAINER_HTTP_PORT = 6080;
config.DOCKER_HOST = '192.168.59.103'; // Default for boot2docker (I think)
if ( !config['war']) {
Log.error()
Log.error('Error: ' + Config.CONFIG_FILE + ' does not have config.war section.');
Log.error()
process.exit(1)
}
/*
* Generate files for PHASE2 (Grunt), Docker, and installing.
*/
var templateDir = __dirname + '/templates';
// PHASE2 (generate, build docker, install, etc)
mkdirp.sync(Config.HIDDEN_DIR + '/PHASE2');
Templates.copyTemplate(templateDir, 'war-PHASE2-DOIT', 'PHASE2/DOIT', config)
fs.chmodSync(Config.HIDDEN_DIR+'/PHASE2/DOIT', '744');
Templates.copyTemplate(templateDir, 'war-PHASE2-package.json', 'PHASE2/package.json', config)
Templates.copyTemplate(templateDir, 'war-PHASE2-Gruntfile.js', 'PHASE2/Gruntfile.js', config)
// Create production config files
var outputsDir = Config.HIDDEN_DIR + '/outputs';
var creatingExamples = false;
Templates.copyTemplateDirectory(templateDir, 'production', 'war-production-', creatingExamples, outputsDir, Config.getConfig());
// Ensure that required directories exist
mkdirp.sync(Config.HIDDEN_DIR + '/do_generate/work');
mkdirp.sync(Config.HIDDEN_DIR + '/do_generate/logs');
mkdirp.sync(Config.HIDDEN_DIR + '/image');
mkdirp.sync(Config.HIDDEN_DIR + '/image/webdesign-projects/config');
fs.writeFileSync(Config.HIDDEN_DIR + '/image/webdesign-projects/config/_empty', '')
}
exports.afterPhase2 = function() {
// console.log("plugins.docker.afterPhase2");
// Create Dockerfile
//ZZZZ
}
exports.afterPhase1 = function(code) {
// console.log('\nplugins.docker.afterPhase1()')
}
exports.createExampleTemplates = function() {
// console.log('plugins.war.createExampleTemplates()')
var templateDir = __dirname + '/templates';
Templates.copyExampleTemplate(templateDir, 'PHASE2/'+Config.mode+'-Gruntfile.js');
Templates.copyExampleTemplate(templateDir, 'PHASE2/'+Config.mode+'-package.json');
}