DefinitelyTyped/scripts/generate-tsconfigs.ts
Andy ae4fe7b6de Use "lib" in tsconfigs instead of "target". (#13968)
* Use "lib" in tsconfigs instead of "target".

Only add "dom" to libraries that need it. This is determined by a script, so many libraries that have "dom" maybe should not.

* Update new-package and readme

* Add back "target" where necessary
2017-01-18 07:51:51 -08:00

59 lines
1.3 KiB
TypeScript

// Usage: ts-node generate-tsconfigs.ts
/// <reference types="node" />
import * as fs from 'fs';
import * as path from 'path';
function repeat(s: string, count: number) {
return Array(count + 1).join(s);
}
const home = path.join(__dirname, '..');
for (const dirName of fs.readdirSync(home)) {
if (dirName.startsWith(".") || dirName === "node_modules" || dirName === "scripts") {
continue;
}
const dir = path.join(home, dirName);
const stats = fs.lstatSync(dir);
if (stats.isDirectory()) {
fixTsconfig(dir);
// Also do it for old versions
for (const subdir of fs.readdirSync(dir)) {
if (/^v\d+$/.test(subdir)) {
fixTsconfig(path.join(dir, subdir));
}
}
}
}
function fixTsconfig(dir: string): void {
const target = path.join(dir, 'tsconfig.json');
let json = JSON.parse(fs.readFileSync(target, 'utf-8'));
json = fix(json);
fs.writeFileSync(target, JSON.stringify(json, undefined, 4), "utf-8");
}
function fix(config: any): any {
const out: any = {};
for (const key in config) {
let value = config[key];
if (key === "compilerOptions") {
value = fixCompilerOptions(value);
}
out[key] = value;
}
return out;
}
function fixCompilerOptions(config: any): any {
const out: any = {};
for (const key in config) {
out[key] = config[key];
// Do something interesting here
}
return out;
}