Skip to content

Commit

Permalink
feat: support context file location in repository
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Jun 16, 2023
1 parent 7083aab commit 639d864
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sonar.sources = src/
sonar.tests = test/
3 changes: 1 addition & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
sonar.exclusions=test/minimaltemplate/**/*
sonar.exclusions=test/**/*
sonar.exclusions=test/minimaltemplate/**/*
12 changes: 6 additions & 6 deletions src/models/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const DEFAULT_CONTEXT_FILENAME = '.asyncapi-cli';
const DEFAULT_CONTEXT_FILE_LOCATION = os.homedir();
export const DEFAULT_CONTEXT_FILE_PATH = path.resolve(DEFAULT_CONTEXT_FILE_LOCATION, DEFAULT_CONTEXT_FILENAME);

const CONTEXT_FILENAME = process.env.CUSTOM_CONTEXT_FILENAME || DEFAULT_CONTEXT_FILENAME;
const CONTEXT_FILE_LOCATION = process.env.CUSTOM_CONTEXT_FILE_LOCATION || DEFAULT_CONTEXT_FILE_LOCATION;
const CONTEXT_FILENAME = process.env.CUSTOM_CONTEXT_FILENAME ?? DEFAULT_CONTEXT_FILENAME;
const CONTEXT_FILE_LOCATION = process.env.CUSTOM_CONTEXT_FILE_LOCATION ?? DEFAULT_CONTEXT_FILE_LOCATION;

// Usage of promises for assignment of their resolved values to constants is
// known to be troublesome:
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface ICurrentContext {
}

export async function loadContext(contextName?: string): Promise<string> {
const fileContent = await loadContextFile();
const fileContent: IContextFile = await loadContextFile();
if (contextName) {
const context = fileContent.store[String(contextName)];
if (!context) {throw new ContextNotFound(contextName);}
Expand Down Expand Up @@ -101,7 +101,7 @@ export async function addContext(contextName: string, pathToFile: string) {
}

export async function removeContext(contextName: string) {
const fileContent = await loadContextFile();
const fileContent: IContextFile = await loadContextFile();
if (!fileContent.store[String(contextName)]) {
throw new ContextNotFound(contextName);
}
Expand All @@ -113,7 +113,7 @@ export async function removeContext(contextName: string) {
}

export async function getCurrentContext(): Promise<ICurrentContext> {
const fileContent = await loadContextFile();
const fileContent: IContextFile = await loadContextFile();
const context = await loadContext();
return {
current: fileContent.current as string,
Expand All @@ -122,7 +122,7 @@ export async function getCurrentContext(): Promise<ICurrentContext> {
}

export async function setCurrentContext(contextName: string) {
const fileContent = await loadContextFile();
const fileContent: IContextFile = await loadContextFile();
if (!fileContent.store[String(contextName)]) {
throw new ContextNotFound(contextName);
}
Expand Down
1 change: 1 addition & 0 deletions test/commands/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-duplicate-string */
import path from 'path';
import { test } from '@oclif/test';

Expand Down

0 comments on commit 639d864

Please sign in to comment.