Skip to content

Commit

Permalink
Support for reading tsconfig files in directories
Browse files Browse the repository at this point in the history
Related to palantir#692
  • Loading branch information
louy committed Dec 6, 2015
1 parent 08d36e6 commit f45e0cb
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import * as fs from "fs";
import * as path from "path";
import * as glob from "glob";
import * as optimist from "optimist";
import * as Linter from "./tslint";
Expand Down Expand Up @@ -178,20 +179,46 @@ const processFile = (file: string) => {
}
};

const GLOB_IGNORE = 'node_modules';
const GLOB_IGNORE: string[] = ['**/node_modules/**', '**/typings/**'];

const fileArgs: string[] = argv._;
const files: string[] = fileArgs.reduce((files: string[], arg: string) => {
return files.concat(glob.sync(arg, {ignore: GLOB_IGNORE}));
}, []);

files.forEach(file => {
files.forEach(arg => {
const stat = fs.lstatSync(arg);

// Check whether argument is actually a directory
const stat = fs.lstatSync(file);
if (stat.isDirectory()) {
let globIgnore = GLOB_IGNORE;

// Try finding a tsconfig file
const configFile = path.join(arg, "/tsconfig.json");
let configStat: fs.Stats;
try {
configStat = fs.lstatSync(configFile);
} catch (e) {}

if (configStat && configStat.isFile()) {
let config: any;
try {
config = JSON.parse(fs.readFileSync(configFile, "utf8"));
} catch (e) {
// Invalid file contents?
console.warn("tsconfig.json file (" + configFile + ") appears not to be valid");
console.error(e);
}
if (config) {
if(config.exclude) {
globIgnore = globIgnore.concat(config.exclude);
}
}
}

// Just read all ts files in the directory
glob.sync(file + "/**/*.ts", {ignore: GLOB_IGNORE}).forEach(processFile);
glob.sync(path.join(arg, "/**/*.ts"), {ignore: globIgnore}).forEach(processFile);
} else {
processFile(file);
processFile(arg);
}
});

0 comments on commit f45e0cb

Please sign in to comment.