mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
199 lines
7.3 KiB
JavaScript
199 lines
7.3 KiB
JavaScript
"use strict";
|
|
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
r[k] = a[j];
|
|
return r;
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var child_process_1 = __importDefault(require("child_process"));
|
|
/**
|
|
* Converts supplied yml files to cli arguments
|
|
* https://docs.docker.com/compose/reference/overview/#use--f-to-specify-name-and-path-of-one-or-more-compose-files
|
|
*/
|
|
var configToArgs = function (config) {
|
|
if (typeof config === 'undefined') {
|
|
return [];
|
|
}
|
|
else if (typeof config === 'string') {
|
|
return ['-f', config];
|
|
}
|
|
else if (config instanceof Array) {
|
|
return config.reduce(function (args, item) { return args.concat(['-f', item]); }, []);
|
|
}
|
|
throw new Error("Invalid argument supplied: " + config);
|
|
};
|
|
/**
|
|
* Converts docker-compose commandline options to cli arguments
|
|
*/
|
|
var composeOptionsToArgs = function (composeOptions) {
|
|
var composeArgs = [];
|
|
composeOptions.forEach(function (option) {
|
|
if (option instanceof Array) {
|
|
composeArgs = composeArgs.concat(option);
|
|
}
|
|
if (typeof option === 'string') {
|
|
composeArgs = composeArgs.concat([option]);
|
|
}
|
|
});
|
|
return composeArgs;
|
|
};
|
|
/**
|
|
* Executes docker-compose command with common options
|
|
*/
|
|
var execCompose = function (command, args, options) {
|
|
if (options === void 0) { options = {}; }
|
|
return new Promise(function (resolve, reject) {
|
|
var composeOptions = options.composeOptions || [];
|
|
var commandOptions = options.commandOptions || [];
|
|
var composeArgs = composeOptionsToArgs(composeOptions);
|
|
composeArgs = composeArgs.concat(configToArgs(options.config).concat([command].concat(composeOptionsToArgs(commandOptions), args)));
|
|
var cwd = options.cwd;
|
|
var env = options.env || undefined;
|
|
var childProc = child_process_1.default.spawn('docker-compose', composeArgs, { cwd: cwd, env: env });
|
|
childProc.on('error', function (err) {
|
|
reject(err);
|
|
});
|
|
var result = {
|
|
exitCode: null,
|
|
err: '',
|
|
out: ''
|
|
};
|
|
childProc.stdout.on('data', function (chunk) {
|
|
result.out += chunk.toString();
|
|
});
|
|
childProc.stderr.on('data', function (chunk) {
|
|
result.err += chunk.toString();
|
|
});
|
|
childProc.on('exit', function (exitCode) {
|
|
result.exitCode = exitCode;
|
|
if (exitCode === 0) {
|
|
resolve(result);
|
|
}
|
|
else {
|
|
reject(result);
|
|
}
|
|
});
|
|
if (options.log) {
|
|
childProc.stdout.pipe(process.stdout);
|
|
childProc.stderr.pipe(process.stderr);
|
|
}
|
|
});
|
|
};
|
|
/**
|
|
* Determines whether or not to use the default non-interactive flag -d for up commands
|
|
*/
|
|
var shouldUseDefaultNonInteractiveFlag = function (options) {
|
|
if (options === void 0) { options = {}; }
|
|
var commandOptions = options.commandOptions || [];
|
|
var containsOtherNonInteractiveFlag = commandOptions.reduce(function (memo, item) {
|
|
return memo && !item.includes('--abort-on-container-exit');
|
|
}, true);
|
|
return containsOtherNonInteractiveFlag;
|
|
};
|
|
exports.upAll = function (options) {
|
|
var args = shouldUseDefaultNonInteractiveFlag(options) ? ['-d'] : [];
|
|
return execCompose('up', args, options);
|
|
};
|
|
exports.upMany = function (services, options) {
|
|
var args = shouldUseDefaultNonInteractiveFlag(options) ? ['-d'].concat(services) : services;
|
|
return execCompose('up', args, options);
|
|
};
|
|
exports.upOne = function (service, options) {
|
|
var args = shouldUseDefaultNonInteractiveFlag(options) ? ['-d', service] : [service];
|
|
return execCompose('up', args, options);
|
|
};
|
|
exports.down = function (options) {
|
|
return execCompose('down', [], options);
|
|
};
|
|
exports.stop = function (options) {
|
|
return execCompose('stop', [], options);
|
|
};
|
|
exports.stopOne = function (service, options) {
|
|
return execCompose('stop', [service], options);
|
|
};
|
|
exports.kill = function (options) {
|
|
return execCompose('kill', [], options);
|
|
};
|
|
exports.rm = function (options) {
|
|
var services = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
services[_i - 1] = arguments[_i];
|
|
}
|
|
return execCompose('rm', __spreadArrays(['-f'], services), options);
|
|
};
|
|
exports.exec = function (container, command, options) {
|
|
var args = Array.isArray(command) ? command : command.split(/\s+/);
|
|
return execCompose('exec', ['-T', container].concat(args), options);
|
|
};
|
|
exports.run = function (container, command, options) {
|
|
var args = Array.isArray(command) ? command : command.split(/\s+/);
|
|
return execCompose('run', ['-T', container].concat(args), options);
|
|
};
|
|
exports.buildAll = function (options) {
|
|
if (options === void 0) { options = {}; }
|
|
return execCompose('build', options.parallel ? ['--parallel'] : [], options);
|
|
};
|
|
exports.buildMany = function (services, options) {
|
|
if (options === void 0) { options = {}; }
|
|
return execCompose('build', options.parallel ? ['--parallel'].concat(services) : services, options);
|
|
};
|
|
exports.buildOne = function (service, options) {
|
|
return execCompose('build', [service], options);
|
|
};
|
|
exports.pullAll = function (options) {
|
|
if (options === void 0) { options = {}; }
|
|
return execCompose('pull', [], options);
|
|
};
|
|
exports.pullMany = function (services, options) {
|
|
if (options === void 0) { options = {}; }
|
|
return execCompose('pull', services, options);
|
|
};
|
|
exports.pullOne = function (service, options) {
|
|
return execCompose('pull', [service], options);
|
|
};
|
|
exports.config = function (options) {
|
|
return execCompose('config', [], options);
|
|
};
|
|
exports.configServices = function (options) {
|
|
return execCompose('config', ['--services'], options);
|
|
};
|
|
exports.configVolumes = function (options) {
|
|
return execCompose('config', ['--volumes'], options);
|
|
};
|
|
exports.ps = function (options) {
|
|
return execCompose('ps', [], options);
|
|
};
|
|
exports.push = function (options) {
|
|
if (options === void 0) { options = {}; }
|
|
return execCompose('push', options.ignorePushFailures ? ['--ignore-push-failures'] : [], options);
|
|
};
|
|
exports.restartAll = function (options) {
|
|
return execCompose('restart', [], options);
|
|
};
|
|
exports.restartMany = function (services, options) {
|
|
return execCompose('restart', services, options);
|
|
};
|
|
exports.restartOne = function (service, options) {
|
|
return exports.restartMany([service], options);
|
|
};
|
|
exports.logs = function (services, options) {
|
|
if (options === void 0) { options = {}; }
|
|
var args = Array.isArray(services) ? services : [services];
|
|
if (options.follow) {
|
|
args = __spreadArrays(['--follow'], args);
|
|
}
|
|
return execCompose('logs', args, options);
|
|
};
|
|
exports.port = function (service, containerPort, options) {
|
|
var args = [service, containerPort];
|
|
return execCompose('port', args, options);
|
|
};
|
|
exports.version = function (options) {
|
|
return execCompose('version', ['--short'], options);
|
|
};
|