export function readConfig()

in packages/just-task/src/config.ts [22:56]


export function readConfig(): { [key: string]: TaskFunction } | void {
  // uses a separate instance of yargs to first parse the config (without the --help in the way) so we can parse the configFile first regardless
  const configFile = resolveConfigFile(argv());

  if (configFile && fs.existsSync(configFile)) {
    const ext = path.extname(configFile);
    if (ext === '.ts' || ext === '.tsx') {
      // TODO: add option to do typechecking as well
      enableTypeScript({ transpileOnly: true });
    }

    try {
      const configModule = require(configFile);

      mark('registry:configModule');

      if (typeof configModule === 'function') {
        configModule();
      }

      logger.perf('registry:configModule');

      return configModule;
    } catch (e) {
      logger.error(`Invalid configuration file: ${configFile}`);
      logger.error(`Error: ${e.stack || e.message || e}`);
      process.exit(1);
    }
  } else {
    logger.error(
      `Cannot find config file "${configFile}".`,
      `Please create a file called "just.config.js" in the root of the project next to "package.json".`,
    );
  }
}