Skip to content

Commit

Permalink
Specify extra source paths on command line.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Soo committed Jul 22, 2020
1 parent 10dcdf8 commit 19d3b94
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
9 changes: 6 additions & 3 deletions ts/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
);
Expand All @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions ts/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface Config {
open: boolean;
port: number;
elmFormatPath: string;
extraSourcePaths: string[];
}

export interface DependencyPointer {
Expand Down
2 changes: 1 addition & 1 deletion ts/file-loading-ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 3 additions & 3 deletions ts/ports/context.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion ts/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
5 changes: 3 additions & 2 deletions ts/util/file-gatherer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '/'), '');
Expand Down Expand Up @@ -76,12 +76,13 @@ function getDependencyFiles(directory: string, dep: DependencyPointer) {
});
}

function gather(directory: string): { interfaceFiles: Array<string[]>; sourceFiles: string[] } {
function gather(config: Config, directory: string): { interfaceFiles: Array<string[]>; sourceFiles: string[] } {
const packageFile = require(directory + '/elm.json');

const input = {
interfaceFiles: [],
sourceFiles: targetFilesForPathAndPackage(directory, directory, packageFile)
.concat(_.uniq(config.extraSourcePaths))
};
return input;
}
Expand Down

0 comments on commit 19d3b94

Please sign in to comment.