microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/settingsHelper.ts

66lines · modeblame

3d1881c7Joshua Skelton10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as Q from "q";
5import * as vscode from "vscode";
6import fs = require("fs");
7import path = require("path");
8import {FileSystem} from "../common/node/fileSystem";
9
10export class SettingsHelper {
11
12public static get settingsJsonPath(): string {
13return path.join(vscode.workspace.rootPath, ".vscode", "settings.json");
14}
15
16/**
17* Constructs a JSON object from tsconfig.json. Will create the file if needed.
18*/
19public static readSettingsJson(): Q.Promise<any> {
20let settingsJsonPath: string = SettingsHelper.settingsJsonPath;
21let fileSystem = new FileSystem();
22
23return fileSystem.exists(settingsJsonPath)
cdbc4389Joshua Skelton10 years ago24.then(function(exists: boolean): Q.Promise<string> {
3d1881c7Joshua Skelton10 years ago25if (!exists) {
cdbc4389Joshua Skelton10 years ago26return fileSystem.writeFile(settingsJsonPath, "{}")
8c2b3bebJoshua Skelton10 years ago27.then(() => { return "{}"; });
3d1881c7Joshua Skelton10 years ago28}
cdbc4389Joshua Skelton10 years ago29
3d1881c7Joshua Skelton10 years ago30return fileSystem.readFile(settingsJsonPath, "utf-8");
31})
32.then(function(jsonContents: string): Q.Promise<any> {
33return JSON.parse(jsonContents);
34});
35}
36
37/**
38* Writes out a JSON configuration object to the tsconfig.json file.
39*/
40public static writeSettingsJson(settingsJson: any): Q.Promise<void> {
41let settingsJsonPath: string = SettingsHelper.settingsJsonPath;
42
43return Q.nfcall<void>(fs.writeFile, settingsJsonPath, JSON.stringify(settingsJson, null, 4));
44}
45
46/**
47* Enable javascript intellisense via typescript.
48*/
49public static typescriptTsdk(path: string): Q.Promise<void> {
50return SettingsHelper.readSettingsJson()
5e53b45aJoshua Skelton10 years ago51.then(function(settingsJson: any): Q.Promise<void> {
52if (settingsJson["typescript.tsdk"] !== path) {
53settingsJson["typescript.tsdk"] = path;
3d1881c7Joshua Skelton10 years ago54
5e53b45aJoshua Skelton10 years ago55return SettingsHelper.writeSettingsJson(settingsJson);
56}
57});
3d1881c7Joshua Skelton10 years ago58}
bed90dbdJoshua Skelton10 years ago59
60public static getTypescriptTsdk(): Q.Promise<string> {
61return SettingsHelper.readSettingsJson()
62.then(function(settingsJson: any): Q.Promise<string> {
63return settingsJson["typescript.tsdk"] || "";
64});
65}
3d1881c7Joshua Skelton10 years ago66}