Skip to content

Commit

Permalink
[RelayCompilerMain] Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Jun 5, 2019
1 parent 9ad6486 commit 8dd5f9c
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions packages/relay-compiler/bin/RelayCompilerMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ function getLanguagePlugin(
}

async function main(config: Config) {
if (config.verbose && config.quiet) {
throw new Error("I can't be quiet and verbose at the same time");
}

config = getPathBasedConfig(config);
config = await getWatchConfig(config);

const codegenRunner = module.exports.getCodegenRunner(config);

const result = config.watch
? await codegenRunner.watchAll()
: await codegenRunner.compileAll();

if (result === 'ERROR') {
process.exit(100);
}
if (config.validate && result !== 'NO_CHANGES') {
process.exit(101);
}
}

function getPathBasedConfig(config: Config) {
const schema = path.resolve(process.cwd(), config.schema);
if (!fs.existsSync(schema)) {
throw new Error(`--schema path does not exist: ${schema}`);
Expand All @@ -177,29 +199,7 @@ async function main(config: Config) {
}
}

if (config.verbose && config.quiet) {
throw new Error("I can't be quiet and verbose at the same time");
}

config = await getWatchConfig(config);

const codegenRunner = module.exports.getCodegenRunner({
...config,
persistOutput,
schema,
src,
});

const result = config.watch
? await codegenRunner.watchAll()
: await codegenRunner.compileAll();

if (result === 'ERROR') {
process.exit(100);
}
if (config.validate && result !== 'NO_CHANGES') {
process.exit(101);
}
return {...config, schema, src, persistOutput};
}

async function getWatchConfig(config: Config) {
Expand Down

0 comments on commit 8dd5f9c

Please sign in to comment.