diff --git a/package.json b/package.json index d7b9f4ee9..c05dc57b8 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "semver": "^5.1.0", "tslint": "^3.10.2", "tslint-config-standard": "^1.0.0", - "typescript": "1.8.7", + "typescript": "^1.8.10", "typings": "^1.0.4" }, "dependencies": { diff --git a/src/index.ts b/src/index.ts index dfb7e926f..5072fb629 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { relative, basename, extname, resolve, dirname, sep, join } from 'path' -import { writeFileSync, readFileSync, statSync } from 'fs' +import { readdirSync, writeFileSync, readFileSync, statSync } from 'fs' import { EOL, tmpdir } from 'os' import sourceMapSupport = require('source-map-support') import extend = require('xtend') @@ -208,6 +208,8 @@ export function register (opts?: Options): () => Register { return ts.ScriptSnapshot.fromString(options.getFile(fileName)) }, + getDirectories: getDirectories, + directoryExists: directoryExists, getNewLine: () => EOL, getCurrentDirectory: () => cwd, getCompilationSettings: () => config.options, @@ -505,6 +507,24 @@ export function fileExists (fileName: string): boolean { } } +/** + * Get directories within a directory. + */ +export function getDirectories (path: string): string[] { + return readdirSync(path).filter(name => directoryExists(join(path, name))) +} + +/** + * Check if a directory exists. + */ +export function directoryExists (path: string): boolean { + try { + return statSync(path).isDirectory() + } catch (err) { + return false + } +} + /** * Get the file from the file system. */