UNPKG

tooltwist

Version:
253 lines (207 loc) 6.75 kB
var fs = require('fs'), path = require('path'), Log = require('./log'), Plugin = require('./plugin'), Templates = require('./templates'); /** * Constants */ exports.HIDDEN_DIRNAME = '.tooltwist'; exports.CONFIG_FILE = 'tooltwist.js'; exports.TEMPLATES_DIRNAME = 'tooltwist.templates'; /** * Calculated constants (pseudo-constants) */ exports.REPO = null; exports.BRANCH = null; exports.PROJECT_NAME = null; exports.PROJECT_ROOT = null; exports.HIDDEN_DIR = null; exports.TOOLTWIST_HOME = null; exports.WEBDESIGN_DIR = null; exports.EXTENSIONS_DIR = null; exports.TEMPLATE_OVERRIDE_DIR = null; exports.IMAGEMAGICK_HOME = null; exports.IS_CONTROLLER = null; exports.NO_PULL = false; exports.RESOURCES_DIR = __dirname + '/..'; exports.LAUNCHPAD = null; // Tomcat ports exports.HTTP_PORT = 5000; exports.STOP_PORT = 5002; exports.AJP_PORT = 5004; // exports.HTTP_PORT = 8080; // exports.STOP_PORT = 8009; // exports.AJP_PORT = 8007; // Fip values exports.FIP_SOURCE_UUID = null; exports.FIP_DESTINATION_UUID = null; exports.FIP_DESTINATION_PASSPHRASE = null; // Plugin for the current mode. exports.MODE = null; exports.plugin = null; exports.USE_PHASE2 = true; // If false, start the server and wait (as in designer mode) /** * Properties set while loading the config. */ var _found = false; var _inCurrentDirectory = false; var _config = null; /** * Look for the config, starting from the current * directory and moving up through parent directores. */ exports.findConfig = function() { Log.debug(); Log.debug('config.findConfig()'); var directory = process.cwd(); _inCurrentDirectory = true; for ( ; ; ) { Log.debug('checking ' + directory); // Look for the config file var file = path.resolve(directory, exports.CONFIG_FILE); if (fs.existsSync(file) && fs.statSync(file).isFile()) { // File found - load the config _found = true; var tmp = null; try { tmp = require(file); } catch (e) { Log.error(e); Log.fatalError('Error while loading ' + exports.CONFIG_FILE + ' (see above)') process.exit(1); } if (tmp.config) { _config = tmp.config; } else { Log.error(); Log.error('\tERROR: Missing \'exports.config\' in ' + file + '\n'); process.exit(1); } // Remember the default mode exports.MODE = _config.mode; // Set constants based on this root directory. Log.debug('config found at ' + directory) setPseudoConstants(directory, _config); return true; } // Not found - move up to the parent directory _inCurrentDirectory = false; var parent = path.resolve(directory, '..'); if (parent === directory) { _found = false; return false; } directory = parent; } } /** * Find the plugin for this operation. */ exports.setOperation = function(operation) { Log.debug('Config.setOperation(' + operation + ')') // Find the plugin for this operation. exports.OPERATION = operation; exports.plugin = Plugin.findPlugin(operation); //console.log('PLUGIN IS ', exports.plugin) } function setPseudoConstants(projectRoot) { // Set pseudo-constants exports.PROJECT_ROOT = projectRoot; exports.HIDDEN_DIR = projectRoot + '/' + exports.HIDDEN_DIRNAME; exports.TOOLTWIST_HOME = projectRoot + '/' + exports.HIDDEN_DIRNAME + '/site-conf'; exports.WEBDESIGN_DIR = projectRoot + '/' + exports.HIDDEN_DIRNAME + '/webdesign-projects'; exports.EXTENSIONS_DIR = projectRoot + '/' + exports.HIDDEN_DIRNAME + '/extension-projects'; exports.TEMPLATE_OVERRIDE_DIR = projectRoot + '/' + exports.TEMPLATES_DIRNAME; exports.BUILD_DIR = projectRoot + '/' + exports.HIDDEN_DIRNAME + '/PHASE1/ttsvr'; Log.info("\nDirectories:") Log.info(" PROJECT_ROOT=" + exports.PROJECT_ROOT) Log.info(" HIDDEN_DIR=" + exports.HIDDEN_DIR) Log.info(" TOOLTWIST_HOME=" + exports.TOOLTWIST_HOME) Log.info(" WEBDESIGN_DIR=" + exports.WEBDESIGN_DIR) Log.info(" EXTENSIONS_DIR=" + exports.EXTENSIONS_DIR) Log.info(" TEMPLATE_OVERRIDE_DIR=" + exports.TEMPLATE_OVERRIDE_DIR) Log.info(" BUILD_DIR=" + exports.BUILD_DIR) Log.info(" RESOURCES_DIR=" + exports.RESOURCES_DIR) // Version of ToolTwist to use exports.TOOLTWIST_VERSION = _config.version ? _config.version : '8.3.3-SNAPSHOT'; Log.info(" TOOLTWIST_VERSION=" + exports.TOOLTWIST_VERSION) // See if this is a Controller-related mode exports.IS_CONTROLLER = false; if (_config.mode === "controller" || _config.mode === "deploy") { exports.IS_CONTROLLER = true; } Log.info(" IS_CONTROLLER=" + exports.IS_CONTROLLER) // PORTS for running tomcat if (_config['designer'].port) { exports.HTTP_PORT = _config['designer'].port; exports.STOP_PORT = _config['designer'].port + 1; exports.AJP_PORT = _config['designer'].port + 2; } // Values for FIP if (exports.IS_CONTROLLER && _config['deploy']){ exports.FIP_SOURCE_UUID = _config['deploy'].sourceUuid; exports.FIP_DESTINATION_UUID = _config['deploy'].destinationUuid; exports.FIP_DESTINATION_PASSPHRASE = _config['deploy'].destinationPassphrase; // Don't make this information public. // Log.info(); // Log.info(" FIP_SOURCE_UUID=" + exports.FIP_SOURCE_UUID); // Log.info(" FIP_DESTINATION_UUID=" + exports.FIP_DESTINATION_UUID); // Log.info(" FIP_DESTINATION_PASSPHRASE=" + exports.FIP_DESTINATION_PASSPHRASE); } /* // Controller-related values if (_config.mode === 'controller') { if (_config.controller && _config['deploy'].launchpad) { // Use launchpad from the config file Log.debug(); Log.debug('Using launchpad from config file.'); exports.LAUNCHPAD = _config['deploy'].launchpad; } else { // Get launchpad from directory name Log.debug(); Log.debug('Use directory name as launchpad.'); exports.LAUNCHPAD = path.basename(exports.PROJECT_ROOT); } Log.info(); Log.info(" LAUNCHPAD=" + exports.LAUNCHPAD) } */ } exports.wasFound = function() { return _found; } exports.isInCurrentDirectory = function() { return _inCurrentDirectory; } exports.getConfigPath = function() { if (_found) { return exports.PROJECT_ROOT + '/' + exports.CONFIG_FILE; } return null; } /** * Return the configuration from tooltwist.js */ exports.getConfig = function() { return _config; } /** * Remember the name of the project. */ exports.setProjectName = function(name) { exports.PROJECT_NAME = name; } /** * If set, this prevents doing a 'git pull' to update an existing webdesign project. */ exports.setNoPull = function(nopull) { exports.NO_PULL = (nopull) ? true : false; } /** * Remember the path to use for $IMAGEMAGICK_HOME environment * variable, when we use 'convert' to manipulate images. */ exports.setImageMagickHome = function(path) { exports.IMAGEMAGICK_HOME = path; }