UNPKG

3.08 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var ts = require("typescript");
4var fs = require("fs");
5var path = require("path");
6function createDefaultFormatCodeSettings() {
7 return {
8 baseIndentSize: 0,
9 indentSize: 4,
10 tabSize: 4,
11 indentStyle: ts.IndentStyle.Smart,
12 newLineCharacter: "\r\n",
13 convertTabsToSpaces: true,
14 insertSpaceAfterCommaDelimiter: true,
15 insertSpaceAfterSemicolonInForStatements: true,
16 insertSpaceBeforeAndAfterBinaryOperators: true,
17 insertSpaceAfterConstructor: false,
18 insertSpaceAfterKeywordsInControlFlowStatements: true,
19 insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
20 insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
21 insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
22 insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
23 insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
24 insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
25 insertSpaceAfterTypeAssertion: false,
26 insertSpaceBeforeFunctionParenthesis: false,
27 placeOpenBraceOnNewLineForFunctions: false,
28 placeOpenBraceOnNewLineForControlBlocks: false,
29 };
30}
31exports.createDefaultFormatCodeSettings = createDefaultFormatCodeSettings;
32function getConfigFileName(baseDir, configFileName) {
33 var configFilePath = path.resolve(baseDir, configFileName);
34 if (fs.existsSync(configFilePath)) {
35 return configFilePath;
36 }
37 if (baseDir.length === path.dirname(baseDir).length) {
38 return null;
39 }
40 return getConfigFileName(path.resolve(baseDir, "../"), configFileName);
41}
42exports.getConfigFileName = getConfigFileName;
43function readFilesFromTsconfig(configPath) {
44 return readTsconfig(configPath).fileNames;
45}
46exports.readFilesFromTsconfig = readFilesFromTsconfig;
47function readTsconfig(configPath) {
48 // for `extends` support. It supported from TypeScript 2.1.1.
49 // `& { readFile(path: string): string; }` is backword compat for TypeScript compiler 2.0.3 support.
50 var host = {
51 useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
52 readDirectory: ts.sys.readDirectory,
53 fileExists: function (path) { return fs.existsSync(path); },
54 readFile: function (path) { return fs.readFileSync(path, "utf-8"); },
55 };
56 var rootConfig = parseJSON(fs.readFileSync(configPath, "utf-8"));
57 var parsed = ts.parseJsonConfigFileContent(rootConfig, host, path.dirname(configPath));
58 if (parsed.errors && parsed.errors.length !== 0) {
59 throw new Error(parsed.errors.map(function (e) { return e.messageText; }).join("\n"));
60 }
61 return parsed;
62}
63exports.readTsconfig = readTsconfig;
64function parseJSON(jsonText) {
65 var result = ts.parseConfigFileTextToJson("tmp.json", jsonText);
66 if (result.error) {
67 throw new Error("JSON parse error");
68 }
69 return result.config;
70}
71exports.parseJSON = parseJSON;
72//# sourceMappingURL=utils.js.map
\No newline at end of file