microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
637e599d4b707fa92106bcd3fbfc075bf8e4625c

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/tsdHelper.ts

56lines · modecode

1// 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 path from 'path';
5import * as Q from 'q';
6import {FileSystem} from './node/fileSystem';
7
8export class TsdHelper {
9 private static REACT_TYPINGS_FOLDERNAME = "ReactTypings";
10 private static REACT_TYPINGS_PATH = path.resolve(__dirname, "..", "..", TsdHelper.REACT_TYPINGS_FOLDERNAME);
11
12 private static installTypeDefinitionFile(src: string, dest: string): Q.Promise<void> {
13 var fileSystem:FileSystem = new FileSystem();
14 if (fileSystem.existsSync(dest)) {
15 return Q.resolve<void>(void 0);
16 }
17
18 // Ensure that the parent folder exits; if not, create the hierarchy of directories
19 let parentFolder = path.resolve(dest, "..");
20 if (!fileSystem.existsSync(parentFolder)) {
21 fileSystem.makeDirectoryRecursiveSync(parentFolder);
22 }
23
24 return fileSystem.copyFile(src, dest);
25 }
26
27 /**
28 * Helper function to get the target path for the type definition files (to be used for intellisense).
29 * Creates the target path if it does not exist already.
30 */
31 public static getOrCreateTypingsTargetPath(projectRoot: string): string {
32 let targetPath = path.resolve(projectRoot, ".vscode", "typings");
33 let fileSystem:FileSystem = new FileSystem();
34
35 if (!fileSystem.existsSync(targetPath)) {
36 fileSystem.makeDirectoryRecursiveSync(targetPath);
37 }
38
39 return targetPath;
40 }
41
42 /**
43 * Helper to install type defintion files for React Native.
44 * {typingsFolderPath} - the parent folder where the type definitions need to be installed
45 * {typeDefsPath} - the relative paths of all type definitions that need to be
46 * installed (relative to <project_root>\.vscode\typings)
47 */
48 public static installTypings(typingsFolderPath: string, typeDefsPath: string[]): Q.Promise<any> {
49 return Q.all(typeDefsPath.map((relativePath: string): Q.Promise<void> => {
50 let src = path.resolve(TsdHelper.REACT_TYPINGS_PATH, relativePath);
51 let dest = path.resolve(typingsFolderPath, relativePath);
52
53 return TsdHelper.installTypeDefinitionFile(src, dest);
54 }));
55 }
56}