Repository navigation
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·53 lines (49 loc) · 1.74 KB
/
Copy pathcli.js
File metadata and controls
executable file
·53 lines (49 loc) · 1.74 KB
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
#!/usr/bin/env node
import figlet from 'figlet';
import colors from 'colors';
import config from './lib/config.js';
import { serve } from './commands/serve.js';
import { publish } from './commands/publish.js';
import { publishLocal } from './commands/publish-local.js';
import { merge } from './commands/merge.js';
import { getAppVersion } from './lib/utils.js';
config.config.then((configResolved) => {
// Welcome to openapi dev tool
figlet('OpenAPI Dev Tool', async (err, data) => {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return -1;
}
console.log(colors.cyan(data));
console.log(`v${getAppVersion()}`);
console.log('\nExecuting ' + colors.cyan(config.command) + ' command...\n');
if (config.command === 'serve') {
// Serve
serve(configResolved).catch(() => {
process.exit(1);
});
} else if (config.command === 'publish') {
// Publish
publish(configResolved).then((result) => {
// Check if at least one specs was rejected
const rejected = result.find((item) => item.isRejected());
if (rejected) process.exit(1);
});
} else if (config.command === 'publish-local') {
// Publish local
publishLocal(configResolved).then((result) => {
// Check if at least one specs was rejected
const rejected = result.find((item) => item.isRejected());
if (rejected) process.exit(1);
});
} else if (config.command === 'merge') {
// merge specs into one single file
merge(configResolved).then((result) => {
// Check if at least one specs was rejected
const rejected = result.find((item) => item.isRejected());
if (rejected) process.exit(1);
});
}
});
});