1 | #!/usr/bin/env node
|
2 |
|
3 | const { resolve } = require('path');
|
4 |
|
5 | const program = require('commander');
|
6 |
|
7 | const { readYaml } = require('./utils');
|
8 |
|
9 |
|
10 |
|
11 | const PROD_COMPOSE_FILE = 'dc.prod.yml';
|
12 | const COMPOSE_FILE = process.env.COMPOSE_FILE || PROD_COMPOSE_FILE;
|
13 | const COMPOSE_PROJECT_NAME = process.env.COMPOSE_PROJECT_NAME;
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | const getNetworkNames = async ({ composefile, prepend }) => {
|
24 | const composeFile = await readYaml(resolve(composefile));
|
25 | const networks = composeFile.networks;
|
26 | let names = Object.keys(networks);
|
27 |
|
28 | names = names.filter((name) => {
|
29 | return networks[name] && !networks[name].external
|
30 | });
|
31 |
|
32 | if (prepend) {
|
33 | names = names.map((name) => `${COMPOSE_PROJECT_NAME}_${name}`);
|
34 | }
|
35 |
|
36 | return names;
|
37 | };
|
38 |
|
39 |
|
40 |
|
41 | program
|
42 | .version('0.1.0')
|
43 | .option('--composefile [path]', `Specify the Compose file to use [${COMPOSE_FILE}].`, COMPOSE_FILE)
|
44 | .option('--prepend', 'Prepend the compose-project-name.')
|
45 | .parse(process.argv);
|
46 |
|
47 | getNetworkNames(program)
|
48 | .then((names) => console.log(names.join(' ')))
|
49 | .catch((error) => {
|
50 | console.error(error);
|
51 | process.exit(1);
|
52 | });
|