Skip to content

Instantly share code, notes, and snippets.

@dannyockilson
Last active March 29, 2018 19:06
Show Gist options
  • Save dannyockilson/a992d569f12b87e938fba72db02a2060 to your computer and use it in GitHub Desktop.
Save dannyockilson/a992d569f12b87e938fba72db02a2060 to your computer and use it in GitHub Desktop.
Quick helper scripts for angular projects
#! /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