<commit_before>///<reference path=".d.ts"/>
"use strict";

import os = require("os");
import path = require("path");
import util = require("util");

import commonHelpers = require("./common/helpers");
import Future = require("fibers/future");
import helpers = require("./helpers");
import options = require("./common/options");
import projectPropertiesServiceLib = require("./services/project-properties-service");

export class Project implements Project.IProject {
	private static JSON_PROJECT_FILE_NAME_REGEX = "[.]abproject";
	private static CHUNK_UPLOAD_MIN_FILE_SIZE = 1024 * 1024 * 50;
	private static CONFIGURATION_FILE_SEARCH_PATTERN: RegExp = new RegExp(".*.abproject$", "i");
	private static VALID_CONFIGURATION_CHARACTERS_REGEX = "[-_A-Za-z0-9]";
	private static CONFIGURATION_FROM_FILE_NAME_REGEX = new RegExp("^[.](" + Project.VALID_CONFIGURATION_CHARACTERS_REGEX + "+?)" + Project.JSON_PROJECT_FILE_NAME_REGEX + "$", "i");
	private static INDENTATION = "     ";
	private static EXPERIMENTAL_TAG = "Experimental";

	private _hasBuildConfigurations: boolean = false;
	private _projectSchema: any;
	private cachedProjectDir: string = "";

	private frameworkProject: Project.IFrameworkProject;
	public projectData: IProjectData;
	public configurationSpecificData: IDictionary<IDictionary<any>>;

	constructor(private $config: IConfiguration,
		private $cordovaMigrationService: ICordovaMigrationService,
		private $errors: IErrors,
		private $frameworkProjectResolver: Project.IFrameworkProjectResolver,
		private $fs: IFileSystem,
		private $jsonSchemaValidator: IJsonSchemaValidator,
		private $loginManager: ILoginManager,
		private $logger: ILogger,
		private $multipartUploadService: IMultipartUploadService,
		private $progressIndicator: IProgressIndicator,
		private $projectConstants: Project.IProjectConstants,
		private $projectFilesManager: Project.IProjectFilesManager,
		private $projectPropertiesService: IProjectPropertiesService,
		private $resources: IResourceLoader,
		private $server: Server.IServer,
		private $staticConfig: IStaticConfig,
		private $templatesService: ITemplatesService,
		private $prompter: IPrompter,
		private $mobileHelper: Mobile.IMobileHelper) {

		this.configurationSpecificData = Object.create(null);
		this.readProjectData().wait();

		if(this.projectData && this.projectData["TemplateAppName"]) {
			this.$errors.failWithoutHelp("This hybrid project targets Apache Cordova 2.x. " +
					"The AppBuilder CLI lets you target only Apache Cordova 3.0.0 or later. " +
					"To develop your projects with Apache Cordova 2.x, run the AppBuilder Windows client or the in-browser client.");
		}
	}

	public get capabilities(): IProjectCapabilities {
		return this.frameworkProject.capabilities;
	}

	public getLiveSyncUrl(): string {
		return this.frameworkProject.liveSyncUrl;
	}

	public get projectConfigFiles(): Project.IConfigurationFile[] {
		return this.frameworkProject.configFiles;
	}

	public get startPackageActivity(): string {
		return this.frameworkProject.startPackageActivity;
	}

	public getProjectTargets(): IFuture<string[]> {
		return (() => {
			var projectDir = this.getProjectDir().wait();
			var projectTargets = this.frameworkProject.getProjectTargets(projectDir).wait();
			return projectTargets;
		}).future<string[]>()();
	}

	public getConfigFileContent(template: string): IFuture<any> {
		return (() => {
			var configFile = _.find(this.projectConfigFiles, configFile => configFile.template === template);
			if(configFile) {
				try {
					var configFileContent = this.$fs.readText(configFile.filepath).wait();
					return configFileContent;
				} catch(e) {
					return null;
				}
			}

			return null;
		}).future<any>()();
	}

	public configurationFilesString(): string {
		if(!this.frameworkProject) {
			var result: string[] = [];

			_.each(_.values(this.$projectConstants.TARGET_FRAMEWORK_IDENTIFIERS), (framework: string) => {
				var frameworkProject = this.$frameworkProjectResolver.resolve(framework);
				var configFiles = frameworkProject.configFiles;
				var title = util.format("Configuration files for %s projects:", framework);
				result.push(title);
				result.push(this.configurationFilesStringCore(configFiles));
			});

			return result.join("\n")
		}

		return this.configurationFilesStringCore(this.frameworkProject.configFiles);
	}

	private configurationFilesStringCore(configFiles: Project.IConfigurationFile[]) {
		return _.map(configFiles, (file) => {
			return util.format("        %s - %s", file.template, file.helpText);
		}).join("\n");
	}

	public get configurations(): string[] {
		var configurations: string[] = [];
		if(options.debug || options.d) {
			configurations.push(this.$projectConstants.DEBUG_CONFIGURATION_NAME);
		}

		if(options.release || options.r) {
			configurations.push(this.$projectConstants.RELEASE_CONFIGURATION_NAME);
		}

		if(configurations.length === 0) {
			configurations.push(this.$projectConstants.DEBUG_CONFIGURATION_NAME);
			configurations.push(this.$projectConstants.RELEASE_CONFIGURATION_NAME);<commit_msg>Fix dynamic help for edit-configuration command.<commit_after>///<reference path=".d.ts"/>
"use strict";

import os = require("os");
import path = require("path");
import util = require("util");

import commonHelpers = require("./common/helpers");
import Future = require("fibers/future");
import helpers = require("./helpers");
import options = require("./common/options");
import projectPropertiesServiceLib = require("./services/project-properties-service");

export class Project implements Project.IProject {
	private static JSON_PROJECT_FILE_NAME_REGEX = "[.]abproject";
	private static CHUNK_UPLOAD_MIN_FILE_SIZE = 1024 * 1024 * 50;
	private static CONFIGURATION_FILE_SEARCH_PATTERN: RegExp = new RegExp(".*.abproject$", "i");
	private static VALID_CONFIGURATION_CHARACTERS_REGEX = "[-_A-Za-z0-9]";
	private static CONFIGURATION_FROM_FILE_NAME_REGEX = new RegExp("^[.](" + Project.VALID_CONFIGURATION_CHARACTERS_REGEX + "+?)" + Project.JSON_PROJECT_FILE_NAME_REGEX + "$", "i");
	private static INDENTATION = "     ";
	private static EXPERIMENTAL_TAG = "Experimental";

	private _hasBuildConfigurations: boolean = false;
	private _projectSchema: any;
	private cachedProjectDir: string = "";

	private frameworkProject: Project.IFrameworkProject;
	public projectData: IProjectData;
	public configurationSpecificData: IDictionary<IDictionary<any>>;

	constructor(private $config: IConfiguration,
		private $cordovaMigrationService: ICordovaMigrationService,
		private $errors: IErrors,
		private $frameworkProjectResolver: Project.IFrameworkProjectResolver,
		private $fs: IFileSystem,
		private $jsonSchemaValidator: IJsonSchemaValidator,
		private $loginManager: ILoginManager,
		private $logger: ILogger,
		private $multipartUploadService: IMultipartUploadService,
		private $progressIndicator: IProgressIndicator,
		private $projectConstants: Project.IProjectConstants,
		private $projectFilesManager: Project.IProjectFilesManager,
		private $projectPropertiesService: IProjectPropertiesService,
		private $resources: IResourceLoader,
		private $server: Server.IServer,
		private $staticConfig: IStaticConfig,
		private $templatesService: ITemplatesService,
		private $prompter: IPrompter,
		private $mobileHelper: Mobile.IMobileHelper) {

		this.configurationSpecificData = Object.create(null);
		this.readProjectData().wait();

		if(this.projectData && this.projectData["TemplateAppName"]) {
			this.$errors.failWithoutHelp("This hybrid project targets Apache Cordova 2.x. " +
					"The AppBuilder CLI lets you target only Apache Cordova 3.0.0 or later. " +
					"To develop your projects with Apache Cordova 2.x, run the AppBuilder Windows client or the in-browser client.");
		}
	}

	public get capabilities(): IProjectCapabilities {
		return this.frameworkProject.capabilities;
	}

	public getLiveSyncUrl(): string {
		return this.frameworkProject.liveSyncUrl;
	}

	public get projectConfigFiles(): Project.IConfigurationFile[] {
		return this.frameworkProject.configFiles;
	}

	public get startPackageActivity(): string {
		return this.frameworkProject.startPackageActivity;
	}

	public getProjectTargets(): IFuture<string[]> {
		return (() => {
			var projectDir = this.getProjectDir().wait();
			var projectTargets = this.frameworkProject.getProjectTargets(projectDir).wait();
			return projectTargets;
		}).future<string[]>()();
	}

	public getConfigFileContent(template: string): IFuture<any> {
		return (() => {
			var configFile = _.find(this.projectConfigFiles, configFile => configFile.template === template);
			if(configFile) {
				try {
					var configFileContent = this.$fs.readText(configFile.filepath).wait();
					return configFileContent;
				} catch(e) {
					return null;
				}
			}

			return null;
		}).future<any>()();
	}

	public configurationFilesString(): string {
		if(!this.frameworkProject) {
			var result: string[] = [];

			_.each(_.values(this.$projectConstants.TARGET_FRAMEWORK_IDENTIFIERS), (framework: string) => {
				var frameworkProject = this.$frameworkProjectResolver.resolve(framework);
				var configFiles = frameworkProject.configFiles;
				if(configFiles && configFiles.length > 0) {
					var title = util.format("Configuration files for %s projects:", framework);
					result.push(title);
					result.push(this.configurationFilesStringCore(configFiles));
				}
			});

			return result.join("\n")
		}

		return this.configurationFilesStringCore(this.frameworkProject.configFiles);
	}

	private configurationFilesStringCore(configFiles: Project.IConfigurationFile[]) {
		return _.map(configFiles, (file) => {
			return util.format("        %s - %s", file.template, file.helpText);
		}).join("\n");
	}

	public get configurations(): string[] {
		var configurations: string[] = [];
		if(options.debug || options.d) {
			configurations.push(this.$projectConstants.DEBUG_CONFIGURATION_NAME);
		}

		if(options.release || options.r) {
			configurations.push(this.$projectConstants.RELEASE_CONFIGURATION_NAME);
		}

		if(configurations.length === 0) {
			configurations.push(this.$projectConstants.DEBUG_CONFIGURATION_NAME);
			configurations.push(this.$projectConstants.RELEASE_CONFIGURATION_NAME);
{'fraction_non_alphanumeric': 0.12010188087774294, 'fraction_numerical': 0.0036246081504702193, 'mean_word_length': 5.465484483850538, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '567289', 'n_tokens_mistral': 3200, 'n_tokens_neox': 2889, 'n_words': 619}