(configPath: string, secretsPath: string)
| 19 | ]; |
| 20 | |
| 21 | export const validateConfiguration = (configPath: string, secretsPath: string) => { |
| 22 | const goRawConfig = goSync(() => readFileSync(path.resolve(configPath), 'utf-8')); |
| 23 | if (!goRawConfig.success) |
| 24 | return fail(`Unable to read config file at "${configPath}". Reason: ${goRawConfig.error.message}`); |
| 25 | |
| 26 | const goConfig = goSync(() => JSON.parse(goRawConfig.data)); |
| 27 | if (!goConfig.success) return fail(`The configuration is not a valid JSON.`); |
| 28 | |
| 29 | const goRawSecrets = goSync(() => readFileSync(path.resolve(secretsPath), 'utf-8')); |
| 30 | if (!goRawSecrets.success) { |
| 31 | return fail(`Unable to read secrets file at "${secretsPath}". Reason: ${goRawSecrets.error.message}`); |
| 32 | } |
| 33 | |
| 34 | const goSecrets = goSync(() => dotenv.parse(goRawSecrets.data)); |
| 35 | if (!goSecrets.success) return fail(`The secrets have incorrect format.`); |
| 36 | |
| 37 | const parseResult = parseConfigWithSecrets(goConfig.data, goSecrets.data); |
| 38 | if (!parseResult.success) return fail(`The configuration is not valid. Reason: ${parseResult.error.message}`); |
| 39 | |
| 40 | return succeed('The configuration is valid'); |
| 41 | }; |
| 42 | |
| 43 | export const cli = () => { |
| 44 | const cliArguments = yargs(hideBin(process.argv)) |
no test coverage detected