microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/utils/node/package.ts
40lines · modeblame
a31b007cunknown10 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
3fb37ad5unknown10 years ago | 4 | import {Node} from "../node/node"; |
| 5 | import * as pathModule from "path"; | |
| 6 | | |
| 7 | export interface IPackageInformation { | |
| 8 | name: string; | |
eb2a5b33dlebu10 years ago | 9 | dependencies: { [name: string]: string }; |
3fb37ad5unknown10 years ago | 10 | } |
| 11 | | |
| 12 | export class Package { | |
| 13 | private _path: string; | |
| 14 | private INFORMATION_PACKAGE_FILENAME = "package.json"; | |
| 15 | | |
| 16 | constructor(path: string) { | |
| 17 | this._path = path; | |
| 18 | } | |
| 19 | | |
| 20 | private informationJsonFilePath(): string { | |
| 21 | return pathModule.resolve(this._path, this.INFORMATION_PACKAGE_FILENAME); | |
| 22 | } | |
| 23 | | |
e639e7a4Daniel10 years ago | 24 | public parsePackageInformation(): Q.Promise<IPackageInformation> { |
3fb37ad5unknown10 years ago | 25 | return new Node.FileSystem().readFile(this.informationJsonFilePath(), "utf8") |
| 26 | .then(data => | |
| 27 | <IPackageInformation>JSON.parse(data)); | |
| 28 | } | |
| 29 | | |
| 30 | public name(): Q.Promise<string> { | |
e639e7a4Daniel10 years ago | 31 | return this.parsePackageInformation() |
| 32 | .then(packageInformation => | |
| 33 | packageInformation.name); | |
3fb37ad5unknown10 years ago | 34 | } |
| 35 | | |
eb2a5b33dlebu10 years ago | 36 | public dependencies(): Q.Promise<{ [name: string]: string }> { |
e639e7a4Daniel10 years ago | 37 | return this.parsePackageInformation() |
eb2a5b33dlebu10 years ago | 38 | .then(packageInformation => packageInformation.dependencies); |
3fb37ad5unknown10 years ago | 39 | } |
3d97c2a3Meena Kunnathur Balakrishnan10 years ago | 40 | } |