1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var ts = require("typescript");
|
4 | var fs = require("fs");
|
5 | var path = require("path");
|
6 | function 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 | }
|
31 | exports.createDefaultFormatCodeSettings = createDefaultFormatCodeSettings;
|
32 | function 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 | }
|
42 | exports.getConfigFileName = getConfigFileName;
|
43 | function readFilesFromTsconfig(configPath) {
|
44 | return readTsconfig(configPath).fileNames;
|
45 | }
|
46 | exports.readFilesFromTsconfig = readFilesFromTsconfig;
|
47 | function readTsconfig(configPath) {
|
48 |
|
49 |
|
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 | }
|
63 | exports.readTsconfig = readTsconfig;
|
64 | function 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 | }
|
71 | exports.parseJSON = parseJSON;
|
72 |
|
\ | No newline at end of file |