Last active
March 29, 2018 19:06
-
-
Save dannyockilson/a992d569f12b87e938fba72db02a2060 to your computer and use it in GitHub Desktop.
Quick helper scripts for angular projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
const fs = require('fs'); | |
const files = [ | |
'src/tsconfig.app.json', | |
'src/tsconfig.server.json', | |
'src/tsconfig.spec.json' | |
]; | |
const paths = { | |
"@lib/*": [ | |
"libs/*" | |
], | |
"@app/*": [ | |
"app/*" | |
] | |
}; | |
function updateConfig(files) { | |
for (let file of files) { | |
try { | |
fs.readFile(file, (err, contents) => { | |
if (err) console.warn(`Error from readFile ${file}:`, err); | |
let json = JSON.parse(contents); | |
if (json.compilerOptions) { | |
let existingPaths = json.compilerOptions.paths || {}; | |
json.compilerOptions = { | |
...json.compilerOptions, | |
paths: { | |
...existingPaths, | |
...paths | |
} | |
} | |
} | |
let config = JSON.stringify(json, null, 2); | |
fs.writeFile(file, config, (err) => { | |
if (err) console.warn(`Error from writeFile ${file}:`, err); | |
}); | |
}); | |
} catch (e) { | |
console.error(`Error thrown updating ${file}: `, e); | |
} | |
} | |
} | |
updateConfig(files); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment