From 0fda739c38dca187c42029ff1c5a8ce306e394f8 Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Tue, 5 Aug 2014 17:41:07 +0300 Subject: [PATCH] Static config --- lib/bootstrap.ts | 1 + lib/common | 2 +- lib/config.ts | 16 ++++++++++++++++ lib/declarations.ts | 4 +++- lib/nativescript-cli.ts | 8 ++------ lib/services/project-service.ts | 8 ++++---- 6 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 lib/config.ts diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts index e7084481c1..b5ebbff4b2 100644 --- a/lib/bootstrap.ts +++ b/lib/bootstrap.ts @@ -21,3 +21,4 @@ $injector.requireCommand("build", "./commands/build"); $injector.require("npm", "./node-package-manager"); $injector.require("propertiesParser", "./properties-parser"); +$injector.require("config", "./config"); diff --git a/lib/common b/lib/common index aaba8d5acb..2af7b7d96a 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit aaba8d5acb0657b3f0a9d5cf4772393d66733180 +Subproject commit 2af7b7d96a1765d19609e6002b5ad5faedf8f7a1 diff --git a/lib/config.ts b/lib/config.ts new file mode 100644 index 0000000000..8aeb2179a2 --- /dev/null +++ b/lib/config.ts @@ -0,0 +1,16 @@ +/// + +import path = require("path"); + +export class StaticConfig implements IStaticConfig { + public PROJECT_FILE_NAME = ".tnsproject"; + public CLIENT_NAME = "tns"; + public ANALYTICS_API_KEY = ""; + + public version = require("../package.json").version; + + public get helpTextPath() { + return path.join(__dirname, "../resources/help.txt"); + } +} +$injector.register("staticConfig", StaticConfig); \ No newline at end of file diff --git a/lib/declarations.ts b/lib/declarations.ts index 55adf5b3db..02b3c54241 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -6,4 +6,6 @@ interface INodePackageManager { interface IPropertiesParser { createEditor(filePath: string): IFuture; -} \ No newline at end of file +} + +interface IStaticConfig extends Config.IStaticConfig { } \ No newline at end of file diff --git a/lib/nativescript-cli.ts b/lib/nativescript-cli.ts index bebe99e180..f314055c4b 100644 --- a/lib/nativescript-cli.ts +++ b/lib/nativescript-cli.ts @@ -11,12 +11,8 @@ import errors = require("./common/errors"); errors.installUncaughtExceptionListener(); $injector.register("config", { - CI_LOGGER1: false, - PROJECT_FILE_NAME: ".tnsproject", - DEBUG: process.env.NATIVESCRIPT_DEBUG, - version: require("../package.json").version, - helpTextPath: path.join(__dirname, "../resources/help.txt"), - client: "tns" + CI_LOGGER: false, + DEBUG: process.env.NATIVESCRIPT_DEBUG }); var dispatcher = $injector.resolve("dispatcher"); diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index 9c4302ff6d..b5a7baf909 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -18,7 +18,7 @@ class ProjectData implements IProjectData { constructor(private $fs: IFileSystem, private $errors: IErrors, private $projectHelper: IProjectHelper, - private $config: IConfig) { + private $staticConfig: IStaticConfig) { this.initializeProjectData().wait(); } @@ -30,7 +30,7 @@ class ProjectData implements IProjectData { this.projectDir = projectDir; this.projectName = path.basename(projectDir); this.platformsDir = path.join(projectDir, "platforms"); - this.projectFilePath = path.join(projectDir, this.$config.PROJECT_FILE_NAME); + this.projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME); if (this.$fs.exists(this.projectFilePath).wait()) { var fileContent = this.$fs.readJson(this.projectFilePath).wait(); @@ -50,7 +50,7 @@ export class ProjectService implements IProjectService { private $fs: IFileSystem, private $projectTemplatesService: IProjectTemplatesService, private $projectHelper: IProjectHelper, - private $config) { } + private $staticConfig: IStaticConfig) { } public createProject(projectName: string, projectId: string): IFuture { return(() => { @@ -128,7 +128,7 @@ export class ProjectService implements IProjectService { this.$fs.createDirectory(path.join(projectDir, "hooks")).wait(); var projectData = { id: projectId }; - this.$fs.writeFile(path.join(projectDir, this.$config.PROJECT_FILE_NAME), JSON.stringify(projectData)).wait(); + this.$fs.writeFile(path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME), JSON.stringify(projectData)).wait(); }).future()(); }