-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·59 lines (47 loc) · 1.57 KB
/
index.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
57
58
59
#!/usr/bin/env node
const ora = require('ora');
const graphqlSchemaDiff = require('graphql-schema-diff');
const cosmiconfig = require('cosmiconfig');
const message = require('./modules/message');
const slack = require('./modules/slack');
const MODULE_NAME = 'schemaDiffBot';
const spinner = ora('getting config file...').start();
(async () => {
const programVariables = await cosmiconfig(MODULE_NAME).search();
if (!programVariables) {
spinner.fail('no config file found.');
return;
}
if (programVariables.isEmpty) {
spinner.fail('config file is empty.');
}
spinner.info('config file found.');
spinner.info('comparing schemas...');
const diffs = await await graphqlSchemaDiff.getDiff(
programVariables.config.leftSchema,
programVariables.config.rightSchema || programVariables.config.leftSchema,
programVariables.config.options || {}
);
if (!diffs) {
spinner.succeed('Schemas are identical, no message to send! 0/').stop();
return;
}
spinner.info('creating message with differences...');
const allChanges = [...diffs.dangerousChanges, ...diffs.breakingChanges];
const mountedMessage = message.mountMessage(
allChanges,
programVariables.config
);
const onMessageSentWithSuccess = () => {
spinner.succeed('Message sent to slack.').stop();
if (programVariables.config.stopProcessIfHasDifferences) {
process.exit(-1);
}
};
slack.sendToSlackChannel(
mountedMessage,
programVariables.config,
onMessageSentWithSuccess,
error => spinner.fail(`Something went wrong\n${error}`).stop()
);
})();