From 68a00fad161c19fe3d1f2ba43aef08d34ed9fa1a Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 13 Mar 2015 14:47:21 +0200 Subject: [PATCH] Enable proxy using for http requests Add config.json file inside new config directory. This file is required in order to allow user specific configurations. Modify nativescript-cli.ts in order to wrap resolving of config and errors inside fiber as the new implementation of config has .wait(). Update common lib, where the following changes are applied: Rename the following config options: - FIDDLER_HOSTNAME to PROXY_HOSTNAME - PROXY_TO_FIDDLER to USE_PROXY Add PROXY_PORT option to config with default value 8888. Add ConfigBase class which should be used as a base for CLI specific configs. Required for https://github.com/NativeScript/nativescript-cli/issues/297 and https://github.com/NativeScript/nativescript-cli/issues/302 --- config/config.json | 8 ++++++++ lib/common | 2 +- lib/config.ts | 19 ++++++++++++++----- lib/nativescript-cli.ts | 9 +++++---- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 config/config.json diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000000..8ba1653ca2 --- /dev/null +++ b/config/config.json @@ -0,0 +1,8 @@ +{ + "DEBUG": false, + "USE_PROXY": false, + "PROXY_PORT": 8888, + "PROXY_HOSTNAME": "127.0.0.1", + "TYPESCRIPT_COMPILER_OPTIONS": {}, + "CI_LOGGER": false +} \ No newline at end of file diff --git a/lib/common b/lib/common index f2bc1309bb..840f96b976 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit f2bc1309bb1ff0e92ba3c045cb90aca0f4a80e97 +Subproject commit 840f96b9761bb083277f7e9e07c15f3b585424f9 diff --git a/lib/config.ts b/lib/config.ts index 3c17d0156c..1c0f1aac02 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -4,12 +4,21 @@ import path = require("path"); import util = require("util"); import staticConfigBaseLibPath = require("./common/static-config-base"); +import configBaseLib = require("./common/config-base"); -$injector.register("config", { - CI_LOGGER: false, - DEBUG: process.env.NATIVESCRIPT_DEBUG, - TYPESCRIPT_COMPILER_OPTIONS: { } -}); +export class Configuration extends configBaseLib.ConfigBase { // User specific config + CI_LOGGER = false; + DEBUG = process.env.NATIVESCRIPT_DEBUG; + TYPESCRIPT_COMPILER_OPTIONS = {}; + USE_PROXY = false; + + /*don't require logger and everything that has logger as dependency in config.js due to cyclic dependency*/ + constructor(protected $fs: IFileSystem) { + super($fs); + _.extend(this, this.loadConfig("config").wait()); + } +} +$injector.register("config", Configuration); export class StaticConfig extends staticConfigBaseLibPath.StaticConfigBase implements IStaticConfig { public PROJECT_FILE_NAME = ".tnsproject"; diff --git a/lib/nativescript-cli.ts b/lib/nativescript-cli.ts index 51bfe6a997..9770da7fdb 100644 --- a/lib/nativescript-cli.ts +++ b/lib/nativescript-cli.ts @@ -8,11 +8,12 @@ import Future = require("fibers/future"); import errors = require("./common/errors"); errors.installUncaughtExceptionListener(); -var config = $injector.resolve("$config"); -($injector.resolve("$errors")).printCallStack = config.DEBUG; - fiber(() => { - var commandDispatcher : ICommandDispatcher = $injector.resolve("commandDispatcher"); + var config = $injector.resolve("$config"); + var err = $injector.resolve("$errors"); + err.printCallStack = config.DEBUG; + + var commandDispatcher: ICommandDispatcher = $injector.resolve("commandDispatcher"); if (process.argv[2] === "completion") { commandDispatcher.completeCommand().wait();