diff --git a/.travis.yml b/.travis.yml index 7deb728f..66aa5aa1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ cache: directories: - node_modules - sysconfcpus + - $HOME/.npm install: - | diff --git a/README.md b/README.md index e9e64673..80ec31be 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,16 @@ Add the `-s` option for server mode. This will allow you to view results in your | `--version` or `-v` | Print version of software. | | `--format` | Output format for CLI. Defaults to "human". Valid values are either "human" or "json". | +### CLI Arguments + +Run `elm-analyse` with any number of extra source files to check following any flags. + +Example: + +``` shell +$ elm-analyse --serve directory/not/in/source-directories/Main.elm other/Main.elm +``` + --- ## Supported Checks diff --git a/ts/bin/index.ts b/ts/bin/index.ts index 724d3d70..e74f7eb2 100755 --- a/ts/bin/index.ts +++ b/ts/bin/index.ts @@ -29,7 +29,8 @@ var args = minimist(process.argv.slice(2), { port: args.port || 3000, elmFormatPath: elmFormatPath, format: validFormats.indexOf(args.format) != -1 ? args.format : 'human', - open: args.open || false + open: args.open || false, + extraSourcePaths: args._ }; const info = { version: elmAnalyseVersion, @@ -39,9 +40,9 @@ var args = minimist(process.argv.slice(2), { if (args.help) { console.log('Usages:'); - console.log(' $ elm-analyse'); + console.log(' $ elm-analyse [PATHS ...]'); console.log(' # Analyse the project and log messages to the console\n'); - console.log(' $ elm-analyse -s'); + console.log(' $ elm-analyse -s [PATHS ...]'); console.log( ' # Analyse the project and start a server. Allows inspection of messages through a browser (Default: http://localhost:3000).\n' ); @@ -52,6 +53,8 @@ var args = minimist(process.argv.slice(2), { console.log(' --open, -o Open default browser when server goes live.'); console.log(' --elm-format-path Path to elm-format. Defaults to `elm-format`.'); console.log(' --format Output format for CLI. Defaults to "human". Options "human"|"json"'); + console.log('Arguments: '); + console.log(' PATHS Optional extra source paths. Example: Main.elm'); process.exit(1); } diff --git a/ts/domain.ts b/ts/domain.ts index 3c673cca..5528f1c9 100644 --- a/ts/domain.ts +++ b/ts/domain.ts @@ -6,6 +6,7 @@ interface Config { open: boolean; port: number; elmFormatPath: string; + extraSourcePaths: string[]; } export interface DependencyPointer { diff --git a/ts/file-loading-ports.ts b/ts/file-loading-ports.ts index 782d1101..61d3cf32 100644 --- a/ts/file-loading-ports.ts +++ b/ts/file-loading-ports.ts @@ -16,5 +16,5 @@ export function setup(app: ElmApp, config: Config, directory: string): void { RawDependencies.setup(app); DependencyFiles.setup(app, directory, fileReader); FileLoader.setup(app, config, directory, localCache, fileReader); - Context.setup(app, directory); + Context.setup(config, app, directory); } diff --git a/ts/ports/context.ts b/ts/ports/context.ts index e170d405..6fc8e2b2 100644 --- a/ts/ports/context.ts +++ b/ts/ports/context.ts @@ -1,10 +1,10 @@ import * as fs from 'fs'; import * as fileGatherer from '../util/file-gatherer'; -import { ElmApp, Context } from '../domain'; +import { Config, ElmApp, Context } from '../domain'; -function setup(app: ElmApp, directory: string) { +function setup(config: Config, app: ElmApp, directory: string) { app.ports.loadContext.subscribe(() => { - const input = fileGatherer.gather(directory); + const input = fileGatherer.gather(config, directory); var configuration; try { configuration = fs.readFileSync('./elm-analyse.json').toString(); diff --git a/ts/server/app.ts b/ts/server/app.ts index bce99389..5a80db7e 100644 --- a/ts/server/app.ts +++ b/ts/server/app.ts @@ -39,7 +39,7 @@ function start(config: Config, info: Info, project: {}) { app.get('/api/tree', function(_req, res) { const directory = process.cwd(); - const x = fileGatherer.gather(directory); + const x = fileGatherer.gather(config, directory); res.send(x.sourceFiles); }); diff --git a/ts/util/file-gatherer.ts b/ts/util/file-gatherer.ts index cccf806e..091f3501 100644 --- a/ts/util/file-gatherer.ts +++ b/ts/util/file-gatherer.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import _ from 'lodash'; import * as find from 'find'; import * as _path from 'path'; -import { DependencyPointer } from '../domain'; +import { Config, DependencyPointer } from '../domain'; function isRealElmPaths(sourceDir: string, filePath: String): boolean { const modulePath = filePath.replace(_path.normalize(sourceDir + '/'), ''); @@ -76,12 +76,13 @@ function getDependencyFiles(directory: string, dep: DependencyPointer) { }); } -function gather(directory: string): { interfaceFiles: Array; sourceFiles: string[] } { +function gather(config: Config, directory: string): { interfaceFiles: Array; sourceFiles: string[] } { const packageFile = require(directory + '/elm.json'); const input = { interfaceFiles: [], sourceFiles: targetFilesForPathAndPackage(directory, directory, packageFile) + .concat(_.uniq(config.extraSourcePaths)) }; return input; }