Skip to content

Commit

Permalink
fix: don't fail to load config if cli not run in a project
Browse files Browse the repository at this point in the history
  • Loading branch information
laurci committed Sep 2, 2021
1 parent c14209a commit 36be43e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/cli/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import config from "./config";
import {generateCommand} from "./commands/generate";
import {runCommand} from "./commands/run";

const commands = [generateCommand, ...Object.keys(config.scripts ?? {}).map((name) => runCommand(name))];
const commands = config.root == "not_found" ? [] : [generateCommand, ...Object.keys(config.scripts ?? {}).map((name) => runCommand(name))];

const args = commands.reduce((arg, command) => command(arg), yargs);

Expand Down
15 changes: 5 additions & 10 deletions src/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@ export interface Config {
}

const configLoader = cosmiconfigSync("kubernate").search();
if (!configLoader || !configLoader.config) {
log.fatal("Could not load config file!");
process.exit(1);
}

if (configLoader.isEmpty) {
log.fatal("Config file is empty");
process.exit(1);
}

const config = {root: path.dirname(configLoader.filepath), filePath: configLoader.filepath, ...configLoader.config} as Config & {
const config = {
root: !!configLoader?.filepath ? path.dirname(configLoader?.filepath ?? "") : "not_found",
filePath: configLoader?.filepath,
...(configLoader?.config ?? {}),
} as Config & {
filePath: string;
root: string;
};
Expand Down

0 comments on commit 36be43e

Please sign in to comment.