{"size": 3494, "ext": "js", "max_stars_repo_path": "node_modules/titanium-sdk/lib/builder.js", "max_stars_repo_name": "trabian/titanium_mobile", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/titanium-sdk/lib/builder.js", "max_issues_repo_name": "trabian/titanium_mobile", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/titanium-sdk/lib/builder.js", "max_forks_repo_name": "trabian/titanium_mobile", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.406504065, "max_line_length": 85, "alphanum_fraction": 0.6923297081}
/**
 * @overview
 * The base class for platform specific build commands. This ensures some
 * commonality between build commands so that hooks can consistently
 * access build properties.
 *
 * @copyright
 * Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
 *
 * @license
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */

var appc = require('node-appc'),
	fs = require('fs'),
	path = require('path');

/**
 * The base class for platform specific build commands. This ensures some
 * commonality between build commands so that hooks can consistently
 * access build properties.
 *
 * General usage is to extend the Builder class and override the config(),
 * validate(), and run() methods:
 *
 * var Builder = require('titanium-sdk/lib/builder');
 * var util = require('util');
 *
 * function AndroidBuilder() {
 *     Builder.apply(this, arguments);
 * }
 *
 * util.inherits(AndroidBuilder, Builder);
 *
 * AndroidBuilder.prototype.config = function config(logger, config, cli) {
 *     Builder.prototype.config.apply(this, arguments);
 *     // TODO
 * };
 *
 * AndroidBuilder.prototype.validate = function validate() {
 *     // TODO
 * };
 *
 * AndroidBuilder.prototype.run = function run(logger, config, cli, finished) {
 *     Builder.prototype.run.apply(this, arguments);
 *     // TODO
 *     finished();
 * };
 *
 * @module lib/builder
 */

module.exports = Builder;

/**
 * Constructs the build state. This needs to be explicitly called from the
 * derived builder's constructor.
 * @class
 * @classdesc Base class for all build states.
 * @constructor
 * @param {Module} The "module" variable from the build command file
 */
function Builder(buildModule) {
	this.titaniumSdkPath = (function scan(dir) {
		var file = path.join(dir, 'manifest.json');
		if (fs.existsSync(file)) {
			return dir;
		}
		dir = path.dirname(dir);
		return dir != '/' && scan(dir);
	}(__dirname));

	this.titaniumSdkVersion = path.basename(this.titaniumSdkPath);

	this.platformPath = (function scan(dir) {
		var file = path.join(dir, 'package.json');
		if (fs.existsSync(file)) {
			return dir;
		}
		dir = path.dirname(dir);
		return dir != '/' && scan(dir);
	}(path.dirname(buildModule.filename)));

	this.platformName = path.basename(this.platformPath);

	this.globalModulesPath = path.join(this.titaniumSdkPath, '..', '..', 'modules');

	this.packageJson = require(path.join(this.platformPath, 'package.json'));

	this.conf = {};
}

/**
 * Defines common variables prior to running the build's config(). This super
 * function should be called prior to the platform-specific build command's config().
 * @param {Object} logger - The logger instance
 * @param {Object} config - The CLI config
 * @param {Object} cli - The CLI instance
 */
Builder.prototype.config = function config(logger, config, cli) {
	this.logger = logger;
	this.config = config;
	this.cli = cli;
};

/**
 * Validation stub function. Meant to be overwritten.
 */
Builder.prototype.validate = function validate() {
};

/**
 * Defines common variables prior to running the build. This super function
 * should be called prior to the platform-specific build command's run().
 */
Builder.prototype.run = function run(logger, config, cli, finished) {
	this.tiapp = cli.tiapp;
	this.projectDir = cli.argv['project-dir'];
	this.buildDir = path.join(this.projectDir, 'build', this.platformName);

	// QUESTION: should we call finished()?
};