Skip to content

Commit f8846ee

Browse files
committed
refactor: define a interface for workspace config
1 parent ab9f2f5 commit f8846ee

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

src/commands/login/oauth2/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import * as vscode from "vscode";
66
import { isUserConnected } from "../../../credentials";
77
import { base64UrlSafeEncode } from "../../utils";
88
import { clientId, createCredentials } from "../createCredentials";
9-
import {
10-
getAvailablePort,
11-
startLocalServerForCallback,
12-
} from "./callbackServer";
9+
import { getAvailablePort, startLocalServerForCallback } from "./callbackServer";
1310

1411
function authorizeUrl(clientId: string, redirectUri: URL, state: string): URL {
1512
const baseUrl = new URL("/oauth2/authorize", GlobalArgs.aqoraUrl());

src/credentials.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { DateTime } from "luxon";
55
import { credentialsPath, isAccessible } from "./dirs";
66
import { GlobalArgs } from "./globalArgs";
77
import { gql } from "./graphql";
8-
import {
9-
Refresh_TokenMutation,
10-
Refresh_TokenMutationVariables,
11-
} from "./graphql/graphql";
8+
import { Refresh_TokenMutation, Refresh_TokenMutationVariables } from "./graphql/graphql";
129
import { CamelToSnakeCaseNested } from "./utils";
1310

1411
const EXPIRATION_PADDING_SEC = 60;

src/dirs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SystemError extends Error {
2121
}
2222

2323
export async function configDir(): Promise<string> {
24-
console.log("READDDDDDD")
24+
console.log("READDDDDDD");
2525
const paths = xdgAppPaths({ name: PATH_SUFFIX });
2626

2727
if (await isAccessible(paths.data())) {
@@ -39,7 +39,6 @@ export async function configDir(): Promise<string> {
3939
}
4040
}
4141

42-
4342
export async function isAccessible(path: string): Promise<boolean> {
4443
try {
4544
await fs.access(path, fs.constants.R_OK);

src/globalArgs.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import { configDir } from "./dirs";
66

77
export type AqoraProjectType = "submission" | "use_case";
88

9+
interface AqoraWorkspaceConfig {
10+
url?: URL;
11+
noPrompt?: boolean;
12+
configHome?: string;
13+
}
14+
915
export interface AqoraProject {
1016
readonly project: {
1117
readonly name: string;
@@ -36,10 +42,11 @@ export interface GlobalArgsProps {
3642
}
3743

3844
export const GlobalArgs: GlobalArgsProps = (() => {
39-
const config = workspace.getConfiguration();
40-
console.log("AQORA CONFIG", config.get("aqora"));
41-
const url = new URL(config.get<string>("aqora.url") || "https://aqora.io");
42-
const noPrompt = config.get<boolean>("aqora.noPrompt") ?? true;
45+
const config = workspace
46+
.getConfiguration()
47+
.get<AqoraWorkspaceConfig>("aqora");
48+
const url = config?.url || new URL("https://aqora.io");
49+
const noPrompt = config?.noPrompt ?? true;
4350

4451
let extensionPath: string | undefined;
4552

@@ -85,8 +92,8 @@ export const GlobalArgs: GlobalArgsProps = (() => {
8592
const isAqoraProject = async (customPath?: string): Promise<boolean> => {
8693
const project = await getAqoraProject(customPath);
8794
return (
88-
project?.tool.aqora.type === "use_case" ||
89-
project?.tool.aqora.type === "submission"
95+
project?.tool.aqora.type === "use_case"
96+
|| project?.tool.aqora.type === "submission"
9097
);
9198
};
9299

@@ -97,8 +104,7 @@ export const GlobalArgs: GlobalArgsProps = (() => {
97104
get noPrompt() {
98105
return noPrompt;
99106
},
100-
getConfigHome: async () =>
101-
config.get<string>("aqora.configHome") || (await configDir()),
107+
getConfigHome: async () => config.get<string>("aqora.configHome") || (await configDir()),
102108
aqoraUrl: () => new URL(url),
103109
graphqlUrl: () => new URL("/graphql", url),
104110
isAqoraProject,

0 commit comments

Comments
 (0)