From 5b9a9f2591bbaa1cd0d977ee12e0157ae844963b Mon Sep 17 00:00:00 2001 From: Todor Totev Date: Thu, 7 Aug 2014 17:41:46 +0300 Subject: [PATCH] Share properties-parser npm between NativeScript & Cordova CLIs --- bootstrap.ts | 1 + declarations.d.ts | 7 ++++++- definitions/properties-parser.d.ts | 4 ++++ properties-parser.ts | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 definitions/properties-parser.d.ts create mode 100644 properties-parser.ts diff --git a/bootstrap.ts b/bootstrap.ts index 4eb826ec..064f0eda 100644 --- a/bootstrap.ts +++ b/bootstrap.ts @@ -12,5 +12,6 @@ $injector.require("cancellation", "./common/services/cancellation"); $injector.require("httpClient", "./common/http-client"); $injector.require("childProcess", "./common/child-process"); $injector.require("projectHelper", "./common/project-helper"); +$injector.require("propertiesParser", "./commmon/properties-parser"); $injector.requireCommand(["help", "/?"], "./common/commands/help"); diff --git a/declarations.d.ts b/declarations.d.ts index 0ea36c73..a84b3e8d 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -124,4 +124,9 @@ interface IChildProcess { interface IProjectHelper { projectDir: string; generateDefaultAppId(appName: string): string; -} \ No newline at end of file +} + +interface IPropertiesParser { + parse(text: string): any; + createEditor(filePath: string): IFuture; +} diff --git a/definitions/properties-parser.d.ts b/definitions/properties-parser.d.ts new file mode 100644 index 00000000..a9f554e0 --- /dev/null +++ b/definitions/properties-parser.d.ts @@ -0,0 +1,4 @@ +declare module "properties-parser" { + function parse(text: string): any; + function createEditor(path: string, callback: (err: IErrors, data: any) => void); +} \ No newline at end of file diff --git a/properties-parser.ts b/properties-parser.ts new file mode 100644 index 00000000..e3191362 --- /dev/null +++ b/properties-parser.ts @@ -0,0 +1,24 @@ +/// + +import propertiesParser = require("properties-parser"); +import Future = require("fibers/future"); + +export class PropertiesParser implements IPropertiesParser { + public parse(text: string): any { + return propertiesParser.parse(text); + } + + public createEditor(filePath: string) { + var future = new Future(); + propertiesParser.createEditor(filePath, (err, data) => { + if(err) { + future.throw(err); + } else { + future.return(data); + } + }); + + return future; + } +} +$injector.register("propertiesParser", PropertiesParser); \ No newline at end of file