UNPKG

1.18 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5const { resolve } = require('path');
6
7const program = require('commander');
8
9const { forIn, readYaml } = require('./utils');
10
11// -- Constants --------------- --- -- -
12
13const TEST_COMPOSE_FILE = 'dc.test.yml';
14
15// -- getTestVolumeNames --------------- --- -- -
16
17/**
18 * Returns the names of the test volumes.
19 * @returns {Promise.<string[]>}
20 */
21const getTestVolumeNames = async () => {
22 const composeFile = await readYaml(resolve(TEST_COMPOSE_FILE));
23 const services = composeFile.services;
24 let names = [];
25
26 // e.g.: ${DX_VOLUMES}/test-store-panel:...
27 const regexp = /\$\{DX_VOLUMES\}\/(.*)\:/;
28 forIn(services, (serviceSpec, serviceName) => {
29 const volumes = serviceSpec.volumes;
30 if (volumes) {
31 volumes.forEach((volume) => {
32 const matches = regexp.exec(volume);
33 if (matches) {
34 names.push(matches[1])
35 }
36 });
37 }
38 });
39
40 return names;
41};
42
43// -- CLI --------------- --- -- -
44
45program
46 .version('0.1.0')
47 .parse(process.argv);
48
49getTestVolumeNames(program)
50 .then((names) => console.log(names.join(' ')))
51 .catch((error) => {
52 console.error(error);
53 process.exit(1);
54 });