/
relay-compiler.js
executable file
·56 lines (47 loc) · 1.74 KB
/
relay-compiler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
// @flow
// TODO: DRY monorepo-utils/bin/monorepo-babel-node-runner.js and fetch-schema
// This is here to make this `bin` available directly from our monorepo without transpiling it.
require('@babel/register')({
ignore: [/node_modules\/(?!@adeira)/],
rootMode: 'upward-optional',
});
const program = require('commander');
const { invariant } = require('@adeira/js');
const Logger = require('@adeira/logger').default;
const RelayConfig = require('relay-config');
const compiler = require('../src/compiler').default;
program
// Please note: try not to extend this CLI if possible. Always prefer "relay.config.js" file.
.option('--src <src>')
.option('--schema <schema>')
.option('--persist-mode <fs|remote>')
.option('--validate', 'Activates validate only mode', false)
.option(
'--watch',
'This option currently REQUIRES Watchman (https://facebook.github.io/watchman/) to be installed.',
false,
)
.parse(process.argv);
const config = {
src: program.src, // required
schema: program.schema, // required
persistMode: program.persistMode,
validate: program.validate,
watch: program.watch,
...RelayConfig.loadConfig(),
};
invariant(config.src, 'Option --src is required.');
invariant(config.schema, 'Option --schema is required.');
invariant(
config.persistMode === undefined || config.persistMode === 'fs',
'Only filesystem persist mode is currently supported.',
);
// TODO: try to download the schema automatically?
// But please note: some projects are using in-memory server for example and therefore it's not
// possible to "fetch" the schema since there is no URL. Such projects has to sign their
// snapshot manually.
compiler(config).catch(error => {
Logger.error(error);
process.exit(1);
});