Enhance CommandLine and LoggerFactory for better type safety and clarity
* Further refined `CommandLine` class to ensure consistent use of `CommandLineOptions`. * Improved method organization in command line option setup for better readability. * Updated `LoggerFactory` to utilize `LoggingLevel` directly in logging level management, streamlining the process.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import SupportedBrowser from "./SupportedBrowser";
|
import SupportedBrowser from "./SupportedBrowser";
|
||||||
|
|
||||||
|
// Source: https://github.com/browserstack/api
|
||||||
|
|
||||||
export class BrowserstackApi {
|
export class BrowserstackApi {
|
||||||
private readonly _baseUrl: string = 'https://api.browserstack.com/5';
|
private readonly _baseUrl: string = 'https://api.browserstack.com/5';
|
||||||
private readonly _authorizationHeader: string;
|
private readonly _authorizationHeader: string;
|
||||||
@@ -9,11 +11,16 @@ export class BrowserstackApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getSupportedBrowsers(): Promise<SupportedBrowser[]> {
|
public async getSupportedBrowsers(): Promise<SupportedBrowser[]> {
|
||||||
const response = await fetch(`${this._baseUrl}/browsers?flat=true`, {
|
const endpoint = `${this._baseUrl}/browsers?flat=true`;
|
||||||
headers: {
|
const headers = {
|
||||||
'Authorization': this._authorizationHeader
|
'Authorization': this._authorizationHeader
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
const response = await fetch(endpoint, { headers });
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch BrowserStack supported browsers due to [ ${response.statusText}]`);
|
||||||
|
}
|
||||||
|
|
||||||
return response.json() as Promise<SupportedBrowser[]>;
|
return response.json() as Promise<SupportedBrowser[]>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,62 +34,7 @@ export default class CommandLine {
|
|||||||
|
|
||||||
return CommandLine._program.opts<CommandLineOptions>();
|
return CommandLine._program.opts<CommandLineOptions>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a configuration object to command line arguments array
|
|
||||||
*/
|
|
||||||
public static configToArgs(config: CommandLineOptions): string[] {
|
|
||||||
const args: string[] = [];
|
|
||||||
|
|
||||||
// Required options
|
|
||||||
args.push('--application-id', config.applicationId);
|
|
||||||
args.push('--secret', config.secret);
|
|
||||||
args.push('--pcast-uri', config.pcastUri);
|
|
||||||
args.push('--channel-uri', config.channelUri);
|
|
||||||
|
|
||||||
// Optional URI options
|
|
||||||
if (config.publisherUri) {
|
|
||||||
args.push('--publisher-uri', config.publisherUri);
|
|
||||||
}
|
|
||||||
if (config.ingestUri) {
|
|
||||||
args.push('--ingest-uri', config.ingestUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Browser and OS options (singular option names, multiple values)
|
|
||||||
config.viewers.forEach(viewer => {
|
|
||||||
args.push('--viewer', viewer);
|
|
||||||
});
|
|
||||||
config.publishers.forEach(publisher => {
|
|
||||||
args.push('--publisher', publisher);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test options (singular option name, multiple values)
|
|
||||||
config.tests.forEach(test => {
|
|
||||||
args.push('--test', test);
|
|
||||||
});
|
|
||||||
|
|
||||||
// BrowserStack options
|
|
||||||
if (config.useBrowserstack) {
|
|
||||||
args.push('--use-browserstack');
|
|
||||||
}
|
|
||||||
if (config.useBrowserstackLocal) {
|
|
||||||
args.push('--use-browserstack-local');
|
|
||||||
}
|
|
||||||
if (config.browserstackUser) {
|
|
||||||
args.push('--browserstack-user', config.browserstackUser);
|
|
||||||
}
|
|
||||||
if (config.browserstackKey) {
|
|
||||||
args.push('--browserstack-key', config.browserstackKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logging options
|
|
||||||
if (config.logLevel) {
|
|
||||||
args.push('--log-level', LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(config.logLevel));
|
|
||||||
}
|
|
||||||
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
CommandLine._program.version(PackageJson.version);
|
CommandLine._program.version(PackageJson.version);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user