microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/settingsHelper.ts

83lines · 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
acf08bc2dlebu10 years ago16public static get launchJsonPath(): string {
17return path.join(vscode.workspace.rootPath, ".vscode", "launch.json");
18}
19
3d1881c7Joshua Skelton10 years ago20/**
21* Constructs a JSON object from tsconfig.json. Will create the file if needed.
22*/
23public static readSettingsJson(): Q.Promise<any> {
24let settingsJsonPath: string = SettingsHelper.settingsJsonPath;
25let fileSystem = new FileSystem();
26
27return fileSystem.exists(settingsJsonPath)
acf08bc2dlebu10 years ago28.then(function(exists: boolean): Q.Promise<string> {
29if (!exists) {
30return fileSystem.writeFile(settingsJsonPath, "{}")
31.then(() => { return "{}"; });
32}
cdbc4389Joshua Skelton10 years ago33
acf08bc2dlebu10 years ago34return fileSystem.readFile(settingsJsonPath, "utf-8");
35})
36.then(function(jsonContents: string): Q.Promise<any> {
37return JSON.parse(jsonContents);
38});
3d1881c7Joshua Skelton10 years ago39}
40
41/**
42* Writes out a JSON configuration object to the tsconfig.json file.
43*/
44public static writeSettingsJson(settingsJson: any): Q.Promise<void> {
45let settingsJsonPath: string = SettingsHelper.settingsJsonPath;
46
47return Q.nfcall<void>(fs.writeFile, settingsJsonPath, JSON.stringify(settingsJson, null, 4));
48}
49
50/**
51* Enable javascript intellisense via typescript.
52*/
8a9925eeEric Hamilton10 years ago53public static setTypeScriptTsdk(path: string): Q.Promise<void> {
3d1881c7Joshua Skelton10 years ago54return SettingsHelper.readSettingsJson()
5e53b45aJoshua Skelton10 years ago55.then(function(settingsJson: any): Q.Promise<void> {
56if (settingsJson["typescript.tsdk"] !== path) {
57settingsJson["typescript.tsdk"] = path;
3d1881c7Joshua Skelton10 years ago58
5e53b45aJoshua Skelton10 years ago59return SettingsHelper.writeSettingsJson(settingsJson);
60}
61});
3d1881c7Joshua Skelton10 years ago62}
bed90dbdJoshua Skelton10 years ago63
8a9925eeEric Hamilton10 years ago64/**
65* Removes javascript intellisense via typescript.
66*/
67public static removeTypeScriptTsdk(): Q.Promise<void> {
68return SettingsHelper.readSettingsJson()
69.then(function(settingsJson: any): Q.Promise<void> {
70if (settingsJson["typescript.tsdk"] !== undefined) {
71delete settingsJson["typescript.tsdk"];
72return SettingsHelper.writeSettingsJson(settingsJson);
73}
74});
75}
76
77public static getTypeScriptTsdk(): Q.Promise<string> {
bed90dbdJoshua Skelton10 years ago78return SettingsHelper.readSettingsJson()
79.then(function(settingsJson: any): Q.Promise<string> {
8a9925eeEric Hamilton10 years ago80return settingsJson["typescript.tsdk"] || null;
bed90dbdJoshua Skelton10 years ago81});
82}
3d1881c7Joshua Skelton10 years ago83}