@jameslnewell/buildkite-pipelines
Version:
Generate Buildkite pipelines from code.
381 lines (380 loc) • 13.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "CommandStep", {
enumerable: true,
get: function() {
return CommandStep;
}
});
const _key = require("./helpers/key");
const _label = require("./helpers/label");
const _condition = require("./helpers/condition");
const _branches = require("./helpers/branches");
const _dependencies = require("./helpers/dependencies");
const _skip = require("./helpers/skip");
const _isPluginBuilder = require("./isPluginBuilder");
const _agents = require("./helpers/agents");
const _env = require("./helpers/env");
function _check_private_redeclaration(obj, privateCollection) {
if (privateCollection.has(obj)) {
throw new TypeError("Cannot initialize the same private elements twice on an object");
}
}
function _class_apply_descriptor_get(receiver, descriptor) {
if (descriptor.get) {
return descriptor.get.call(receiver);
}
return descriptor.value;
}
function _class_apply_descriptor_set(receiver, descriptor, value) {
if (descriptor.set) {
descriptor.set.call(receiver, value);
} else {
if (!descriptor.writable) {
throw new TypeError("attempted to set read only private field");
}
descriptor.value = value;
}
}
function _class_extract_field_descriptor(receiver, privateMap, action) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to " + action + " private field on non-instance");
}
return privateMap.get(receiver);
}
function _class_private_field_get(receiver, privateMap) {
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
return _class_apply_descriptor_get(receiver, descriptor);
}
function _class_private_field_init(obj, privateMap, value) {
_check_private_redeclaration(obj, privateMap);
privateMap.set(obj, value);
}
function _class_private_field_set(receiver, privateMap, value) {
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
_class_apply_descriptor_set(receiver, descriptor, value);
return value;
}
var _commands = /*#__PURE__*/ new WeakMap(), _plugins = /*#__PURE__*/ new WeakMap(), _keyHelper = /*#__PURE__*/ new WeakMap(), _labelHelper = /*#__PURE__*/ new WeakMap(), _conditionHelper = /*#__PURE__*/ new WeakMap(), _branchesHelper = /*#__PURE__*/ new WeakMap(), _dependenciesHelper = /*#__PURE__*/ new WeakMap(), _skipHelper = /*#__PURE__*/ new WeakMap(), _agentsHelper = /*#__PURE__*/ new WeakMap(), _envHelper = /*#__PURE__*/ new WeakMap(), _concurrency = /*#__PURE__*/ new WeakMap(), _concurrencyGroup = /*#__PURE__*/ new WeakMap(), _parallelism = /*#__PURE__*/ new WeakMap(), _softFail = /*#__PURE__*/ new WeakMap(), _timeoutInMinutes = /*#__PURE__*/ new WeakMap(), _automaticRetries = /*#__PURE__*/ new WeakMap(), _manualRetry = /*#__PURE__*/ new WeakMap();
class CommandStep {
getCommands() {
var _class_private_field_get1;
return [
...(_class_private_field_get1 = _class_private_field_get(this, _commands)) !== null && _class_private_field_get1 !== void 0 ? _class_private_field_get1 : []
];
}
/**
* @deprecated Use .addCommand() instead
*/ command(command) {
return this.addCommand(command);
}
addCommand(command) {
if (!_class_private_field_get(this, _commands)) {
_class_private_field_set(this, _commands, []);
}
_class_private_field_get(this, _commands).push(command);
return this;
}
getKey() {
return _class_private_field_get(this, _keyHelper).getKey();
}
/**
* @deprecated Use .setKey() instead
*/ key(key) {
return this.setKey(key);
}
setKey(key) {
_class_private_field_get(this, _keyHelper).setKey(key);
return this;
}
getLabel() {
return _class_private_field_get(this, _labelHelper).getLabel();
}
/**
* @deprecated Use .setLabel() instead
*/ label(label) {
return this.setLabel(label);
}
setLabel(label) {
_class_private_field_get(this, _labelHelper).setLabel(label);
return this;
}
getCondition() {
return _class_private_field_get(this, _conditionHelper).getCondition();
}
/**
* @deprecated Use .setCondition() instead
*/ condition(condition) {
return this.setCondition(condition);
}
setCondition(condition) {
_class_private_field_get(this, _conditionHelper).setCondition(condition);
return this;
}
getBranches() {
return _class_private_field_get(this, _branchesHelper).getBranches();
}
/**
* @deprecated Use .addBranch() instead
*/ branch(branch) {
return this.addBranch(branch);
}
addBranch(branch) {
_class_private_field_get(this, _branchesHelper).addBranch(branch);
return this;
}
getDependencies() {
return _class_private_field_get(this, _dependenciesHelper).getDependencies();
}
/**
* @deprecated Use .addDependency() instead
*/ dependOn(dependency) {
return this.addDependency(dependency);
}
addDependency(dependency) {
_class_private_field_get(this, _dependenciesHelper).addDependency(dependency);
return this;
}
/**
* @deprecated Use .addDependency() instead
*/ allowDependencyFailure(allow) {
return this.setAllowDependencyFailure(allow);
}
setAllowDependencyFailure(allow) {
_class_private_field_get(this, _dependenciesHelper).setAllowDependencyFailure(allow);
return this;
}
/**
* @deprecated Use .setSkip() instead
*/ skip(skip) {
return this.setSkip(skip);
}
setSkip(skip) {
_class_private_field_get(this, _skipHelper).setSkip(skip);
return this;
}
getPlugins() {
// 🤔 not sure we want to allow mutation of the plugins yet
return [
..._class_private_field_get(this, _plugins)
];
}
/**
* @deprecated Use .addPlugin() instead
*/ plugin(plugin) {
return this.addPlugin(plugin);
}
addPlugin(plugin) {
_class_private_field_get(this, _plugins).push(plugin);
return this;
}
/**
* @deprecated Use .addPlugins() instead
*/ plugins(plugins) {
return this.addPlugins(plugins);
}
addPlugins(plugins) {
_class_private_field_get(this, _plugins).push(...plugins);
return this;
}
/**
* @deprecated Use .setParallelism() instead
*/ parallelism(parallelism) {
return this.setParallelism(parallelism);
}
setParallelism(parallelism) {
if (parallelism === 0) {
throw new Error('Parallelism of zero will result in step being omitted');
}
_class_private_field_set(this, _parallelism, parallelism);
return this;
}
getEnv() {
return _class_private_field_get(this, _envHelper).getEnv();
}
/**
* @deprecated Use .addEnv() instead
*/ env(name, value) {
return this.addEnv(name, value);
}
addEnv(name, value) {
_class_private_field_get(this, _envHelper).addEnv(name, value);
return this;
}
/**
* @deprecated Use .setConcurrency() instead
*/ concurrency(group, jobs) {
return this.setConcurrency(group, jobs);
}
setConcurrency(group, jobs) {
if (jobs === 0) {
throw new Error('Concurrency of zero will result in step which never starts');
}
_class_private_field_set(this, _concurrency, jobs);
_class_private_field_set(this, _concurrencyGroup, group);
return this;
}
getSoftFail() {
return _class_private_field_get(this, _softFail);
}
/**
* @deprecated Use .setSoftFail() instead
*/ softFail(fail = true) {
return this.setSoftFail(fail);
}
setSoftFail(fail) {
_class_private_field_set(this, _softFail, fail);
return this;
}
getTimeout() {
return _class_private_field_get(this, _timeoutInMinutes);
}
/**
* @deprecated Use .setTimeout() instead
*/ timeout(minutes) {
return this.setTimeout(minutes);
}
setTimeout(minutes) {
_class_private_field_set(this, _timeoutInMinutes, minutes);
return this;
}
getAgents() {
return _class_private_field_get(this, _agentsHelper).getAgents();
}
/**
* @deprecated Use .addAgent() instead
*/ agent(tag, value) {
return this.addAgent(tag, value);
}
addAgent(tag, value) {
_class_private_field_get(this, _agentsHelper).addAgent(tag, value);
return this;
}
setManualRetry(retry) {
_class_private_field_set(this, _manualRetry, retry);
return this;
}
addAutomaticRetry(retry) {
_class_private_field_get(this, _automaticRetries).push(retry);
return this;
}
async build() {
const object = {
...{
commands: _class_private_field_get(this, _commands)
},
..._class_private_field_get(this, _keyHelper).build(),
..._class_private_field_get(this, _labelHelper).build(),
..._class_private_field_get(this, _conditionHelper).build(),
..._class_private_field_get(this, _branchesHelper).build(),
..._class_private_field_get(this, _dependenciesHelper).build(),
..._class_private_field_get(this, _skipHelper).build(),
..._class_private_field_get(this, _parallelism) ? {
parallelism: _class_private_field_get(this, _parallelism)
} : {},
..._class_private_field_get(this, _concurrency) ? {
concurrency: _class_private_field_get(this, _concurrency)
} : {},
..._class_private_field_get(this, _concurrencyGroup) ? {
concurrency_group: _class_private_field_get(this, _concurrencyGroup)
} : {},
..._class_private_field_get(this, _envHelper).build(),
..._class_private_field_get(this, _softFail) ? {
soft_fail: _class_private_field_get(this, _softFail)
} : {},
..._class_private_field_get(this, _timeoutInMinutes) ? {
timeout_in_minutes: _class_private_field_get(this, _timeoutInMinutes)
} : {},
..._class_private_field_get(this, _agentsHelper).build()
};
if (_class_private_field_get(this, _manualRetry) !== undefined) {
object.retry = {
...object.retry,
manual: _class_private_field_get(this, _manualRetry)
};
}
if (_class_private_field_get(this, _automaticRetries).length) {
object.retry = {
...object.retry,
automatic: _class_private_field_get(this, _automaticRetries)
};
}
if (_class_private_field_get(this, _plugins).length > 0) {
object.plugins = await Promise.all(_class_private_field_get(this, _plugins).map(async (plugin)=>(0, _isPluginBuilder.isPluginBuilder)(plugin) ? await plugin.build() : plugin));
}
return object;
}
constructor(){
_class_private_field_init(this, _commands, {
writable: true,
value: void 0
});
_class_private_field_init(this, _plugins, {
writable: true,
value: []
});
_class_private_field_init(this, _keyHelper, {
writable: true,
value: new _key.KeyHelper()
});
_class_private_field_init(this, _labelHelper, {
writable: true,
value: new _label.LabelHelper()
});
_class_private_field_init(this, _conditionHelper, {
writable: true,
value: new _condition.ConditionHelper()
});
_class_private_field_init(this, _branchesHelper, {
writable: true,
value: new _branches.BranchFilterHelper()
});
_class_private_field_init(this, _dependenciesHelper, {
writable: true,
value: new _dependencies.DependenciesHelper()
});
_class_private_field_init(this, _skipHelper, {
writable: true,
value: new _skip.SkipHelper()
});
_class_private_field_init(this, _agentsHelper, {
writable: true,
value: new _agents.AgentsHelper()
});
_class_private_field_init(this, _envHelper, {
writable: true,
value: new _env.EnvironmentHelper()
});
_class_private_field_init(this, _concurrency, {
writable: true,
value: void 0
});
_class_private_field_init(this, _concurrencyGroup, {
writable: true,
value: void 0
});
_class_private_field_init(this, _parallelism, {
writable: true,
value: void 0
});
_class_private_field_init(this, _softFail, {
writable: true,
value: void 0
});
_class_private_field_init(this, _timeoutInMinutes, {
writable: true,
value: void 0
});
_class_private_field_init(this, _automaticRetries, {
writable: true,
value: []
});
_class_private_field_init(this, _manualRetry, {
writable: true,
value: void 0
});
}
}
//# sourceMappingURL=CommandStep.js.map