Skip to content

Commit

Permalink
feat: load typescript config by default if present
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored and AriPerkkio committed Dec 31, 2021
1 parent 3d8bee0 commit 126033c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ import { CONFIGURATION_FILE_TEMPLATE } from './config-templates';
import { loadConfig } from './load';
import { WorkerData } from '@engine/types';

const DEFAULT_CONFIGURATION_FILE = 'eslint-remote-tester.config.js';
const DEFAULT_CONFIGURATION_FILE_NAME = 'eslint-remote-tester.config';
const DEFAULT_CONFIGURATION_FILE_JS = `${DEFAULT_CONFIGURATION_FILE_NAME}.js`;
const DEFAULT_CONFIGURATION_FILE_TS = `${DEFAULT_CONFIGURATION_FILE_NAME}.ts`;
const CLI_ARGS_CONFIG = ['-c', '--config'];

function determineDefaultConfigFile() {
if (fs.existsSync(DEFAULT_CONFIGURATION_FILE_TS)) {
return DEFAULT_CONFIGURATION_FILE_TS;
}

return DEFAULT_CONFIGURATION_FILE_JS;
}

export function resolveConfigurationLocation(): string {
// Main thread can read config location from args
const configArgumentIndex = process.argv.findIndex(arg =>
Expand All @@ -28,7 +38,7 @@ export function resolveConfigurationLocation(): string {
return (
cliConfigLocation ||
workerDataConfiguration ||
DEFAULT_CONFIGURATION_FILE
determineDefaultConfigFile()
);
}

Expand All @@ -37,7 +47,7 @@ const CONFIGURATION_FILE = resolveConfigurationLocation();
if (!fs.existsSync(CONFIGURATION_FILE)) {
let defaultCreated = false;

if (CONFIGURATION_FILE === DEFAULT_CONFIGURATION_FILE) {
if (CONFIGURATION_FILE === DEFAULT_CONFIGURATION_FILE_JS) {
fs.writeFileSync(
CONFIGURATION_FILE,
CONFIGURATION_FILE_TEMPLATE,
Expand All @@ -50,7 +60,7 @@ if (!fs.existsSync(CONFIGURATION_FILE)) {
if (defaultCreated) {
console.log(
chalk.green(
`Default configuration file created: ${DEFAULT_CONFIGURATION_FILE}`
`Default configuration file created: ${DEFAULT_CONFIGURATION_FILE_JS}`
)
);
}
Expand Down

0 comments on commit 126033c

Please sign in to comment.