import * as fs from 'fs';
import * as fileGatherer from '../util/file-gatherer';
import { ElmApp, Context } from '../domain';

function setup(app: ElmApp, directory: string) {
    app.ports.loadContext.subscribe(() => {
        const input = fileGatherer.gather(directory);
        var configuration;
        try {
            configuration = fs.readFileSync('./elm-analyse.json').toString();
        } catch (e) {
            configuration = '';
        }
        const data: Context = {
            sourceFiles: input.sourceFiles,
            interfaceFiles: input.interfaceFiles,
            configuration: configuration
        };

        setTimeout(function() {
            app.ports.onLoadedContext.send(data);
        }, 5);
    });
}

export { setup };

import * as fs from 'fs';
import * as fileGatherer from '../util/file-gatherer';
import { ElmApp, Context } from '../domain';
import * as path from 'path';

function setup(app: ElmApp, directory: string) {
    app.ports.loadContext.subscribe(() => {
        const input = fileGatherer.gather(directory);
        var configuration;
        try {
            configuration = fs.readFileSync(path.join(directory, 'elm-analyse.json')).toString();
        } catch (e) {
            configuration = '';
        }
        const data: Context = {
            sourceFiles: input.sourceFiles,
            interfaceFiles: input.interfaceFiles,
            configuration: configuration
        };

        setTimeout(function() {
            app.ports.onLoadedContext.send(data);
        }, 5);
    });
}

export { setup };

Read elm-analyse configuration from the directory where the elm.json is rather than the current working directory of the process. This helps with running in a multi-project structure where you may open "/project/" in an editor and have an elm project under "/project/web/".
Read elm-analyse configuration from the directory where the elm.json is rather than the current working directory of the process.  This helps with running in a multi-project structure where you may open "/project/" in an editor and have an elm project under "/project/web/".
