tsconfig-generator
Advanced tools
Comparing version 0.0.4 to 0.0.5
21
index.js
#!/usr/bin/env node | ||
const _ = require('lodash'); | ||
const fs = require('fs'); | ||
@@ -12,3 +13,3 @@ const path = require('path'); | ||
program | ||
.version('0.0.4') | ||
.version('0.0.5') | ||
.option('-i, --input [inputFile]', 'Specifies the path of the input JSON file') | ||
@@ -23,4 +24,8 @@ .option('-o, --output [outputFile]', 'Specifies the path of the output JSON file') | ||
let config = JSON.parse(fs.readFileSync(inputFilePath, 'utf8')); | ||
replaceConfigKeyIfExists(config, 'compilerOptions.baseUrl', path.dirname(outputFilePath)); | ||
replaceConfigKeyIfExists(config, 'extends', path.dirname(outputFilePath)); | ||
const absoluteBaseUrlPath = replaceAllMatches(environmentVariableRegex, config.compilerOptions.baseUrl); | ||
config.compilerOptions.baseUrl = getRelativePathTo(path.dirname(outputFilePath), absoluteBaseUrlPath); | ||
walkTheObjectAndReplaceEnvironmentVariables(config, absoluteBaseUrlPath); | ||
@@ -77,2 +82,14 @@ fs.writeFileSync(outputFilePath ? outputFilePath : DEFAULT_TS_CONFIG_FILE_PATH, JSON.stringify(config, null, | ||
}); | ||
} | ||
function replaceConfigKeyIfExists(config, keyPathToReplace, targetPath) | ||
{ | ||
if(!_.has(config, keyPathToReplace)) | ||
{ | ||
return; | ||
} | ||
const valueToReplace = _.get(config, keyPathToReplace); | ||
const pathFromEnvVar = replaceAllMatches(environmentVariableRegex, valueToReplace); | ||
_.set(config, keyPathToReplace, path.isAbsolute(pathFromEnvVar) ? getRelativePathTo(targetPath, pathFromEnvVar) : pathFromEnvVar); | ||
} |
@@ -8,3 +8,4 @@ { | ||
"dependencies": { | ||
"commander": "^2.15.1" | ||
"commander": "^2.15.1", | ||
"lodash": "4.17.10" | ||
}, | ||
@@ -34,3 +35,3 @@ "description": "Creates a tsconfig.json by using the paths defined with environment variables", | ||
}, | ||
"version": "0.0.4" | ||
"version": "0.0.5" | ||
} |
{ | ||
"extends": "../../test/git/root/tsconfig.json", | ||
"compilerOptions": { | ||
"alwaysStrict": true, | ||
"baseUrl": "../../../test/git", | ||
"baseUrl": "../../test/git/root", | ||
"declaration": true, | ||
@@ -33,2 +34,2 @@ "experimentalDecorators": true, | ||
} | ||
} | ||
} |
{ | ||
"extends": "${TEST_GIT_ROOT}/tsconfig.json", | ||
"compilerOptions": { | ||
@@ -3,0 +4,0 @@ "alwaysStrict": true, |
20396
212
2
+ Addedlodash@4.17.10
+ Addedlodash@4.17.10(transitive)