# runtime/entrypoints/invocation.entrypoint.ts

> 52 lines of code and 11 definitions.

Tree: GovLab Quality
Language: typescript
Layer: runtime
Canonical: https://banes-lab.com/anatomy/quality#file-quality-runtime-entrypoints-invocation-entrypoint-ts
Source text: https://banes-lab.com/source/quality/runtime/entrypoints/invocation.entrypoint.ts.txt

Listed in [runtime/entrypoints](https://banes-lab.com/api/source/quality/runtime/entrypoints.md), after [runtime/entrypoints/dependency.entrypoint.ts](https://banes-lab.com/source/quality/runtime/entrypoints/dependency.entrypoint.ts.md) and before [runtime/entrypoints/manifest.entrypoint.ts](https://banes-lab.com/source/quality/runtime/entrypoints/manifest.entrypoint.ts.md).

## Definitions

- `runInstallVerb` (lexical_declaration, line 24)
- `main` (lexical_declaration, line 34)
- `ARGV_START` (lexical_declaration, line 13)
- `CONFIG_FOLDER` (lexical_declaration, line 14)
- `rootFromConfig` (lexical_declaration, line 16)
- `dir` (lexical_declaration, line 20)
- `request` (lexical_declaration, line 25)
- `detected` (lexical_declaration, line 26)
- `plan` (lexical_declaration, line 27)
- `args` (lexical_declaration, line 35)
- `root` (lexical_declaration, line 36)

## Contained in

- [runtime/entrypoints](https://banes-lab.com/anatomy/quality/folder-quality-runtime-entrypoints.md)

## Uses

- [core/adapters/dependency.adapter.ts](https://banes-lab.com/source/quality/core/adapters/dependency.adapter.ts.md)
- [core/coordinators/concern.coordinator.ts](https://banes-lab.com/source/quality/core/coordinators/concern.coordinator.ts.md)
- [core/formatters/dependency.formatter.ts](https://banes-lab.com/source/quality/core/formatters/dependency.formatter.ts.md)
- [core/resolvers/scope.resolver.ts](https://banes-lab.com/source/quality/core/resolvers/scope.resolver.ts.md)

## Linked from

- [core/adapters](https://banes-lab.com/anatomy/quality/folder-quality-core-adapters.md)
- [core/coordinators](https://banes-lab.com/anatomy/quality/folder-quality-core-coordinators.md)
- [core/formatters](https://banes-lab.com/anatomy/quality/folder-quality-core-formatters.md)
- [core/resolvers](https://banes-lab.com/anatomy/quality/folder-quality-core-resolvers.md)
- [runtime/entrypoints](https://banes-lab.com/anatomy/quality/folder-quality-runtime-entrypoints.md)

## Source

```typescript
#!/usr/bin/env node
import { printPlan, printReport } from "#core/formatters/dependency.formatter";
import { FAILURE_EXIT } from "#configuration/constants/invocation.constants";
import { computePlan } from "#core/factories/dependency.factory";
import { detectEcosystems } from "#core/resolvers/scope.resolver";
import { parseCliArgs } from "#core/parsers/invocation.parser";
import path from "node:path";
import process from "node:process";
import { runInstall } from "#core/adapters/dependency.adapter";
import { runLint } from "#core/coordinators/concern.coordinator";
import { validateInstallRequest } from "#core/validators/dependency.validator";

const ARGV_START = 2;
const CONFIG_FOLDER = "config";

const rootFromConfig = function rootFromConfig(configPath: string | null): string {
    if (configPath === null || configPath === "") {
        return process.cwd();
    }
    const dir = path.dirname(path.resolve(configPath));
    return path.basename(dir) === CONFIG_FOLDER ? path.dirname(dir) : dir;
};

const runInstallVerb = function runInstallVerb(args: ReturnType<typeof parseCliArgs>, root: string): void {
    const request = validateInstallRequest({ auto: args.auto, dryRun: args.dryRun, ecosystems: args.ecosystems });
    const detected = request.auto ? detectEcosystems(root).map((entry) => entry.ecosystem) : [];
    const plan = computePlan([...new Set([...request.ecosystems, ...detected])]);
    process.stdout.write(printPlan(plan));
    if (!request.dryRun) {
        process.stdout.write(printReport(runInstall(plan, { dryRun: request.dryRun, root })));
    }
};

const main = async function main(): Promise<number> {
    const args = parseCliArgs(process.argv.slice(ARGV_START));
    const root = rootFromConfig(args.config);
    if (args.concern === "list") {
        process.stdout.write(
            `${detectEcosystems(root)
                .map((entry) => entry.ecosystem)
                .join("\n")}\n`,
        );
        return 0;
    }
    if (args.concern === "install") {
        runInstallVerb(args, root);
        return 0;
    }
    return runLint(args, { env: process.env, root });
};

try {
    process.exitCode = await main();
} catch (error: unknown) {
    process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
    process.exitCode = FAILURE_EXIT;
}
```
