Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x | import dedent from 'dedent';
import { Logger } from '../logger.js';
const CONFIG_KEYS = [
{ id: 'name', name: 'name', displayName: 'Name', kind: 'string' },
{ id: 'description', name: 'description', displayName: 'Description', kind: 'string' },
{ id: 'zero-downtime', name: 'homogeneous', displayName: 'Zero-downtime deployment', kind: 'inverted-bool' },
{ id: 'sticky-sessions', name: 'stickySessions', displayName: 'Sticky sessions', kind: 'bool' },
{ id: 'cancel-on-push', name: 'cancelOnPush', displayName: 'Cancel current deployment on push', kind: 'bool' },
{ id: 'force-https', name: 'forceHttps', displayName: 'Force redirection of HTTP to HTTPS', kind: 'force-https' },
{ id: 'task', name: 'instanceLifetime', displayName: 'Deploy an application as a Clever Task', kind: 'task' },
];
export function listAvailableIds(asText = false) {
const ids = CONFIG_KEYS.map((configKey) => configKey.id);
if (asText) {
return new Intl.ListFormat('en', { style: 'short', type: 'disjunction' }).format(ids);
}
return ids;
}
export function getById(id) {
const configKey = CONFIG_KEYS.find((ck) => ck.id === id);
if (configKey != null) {
return configKey;
}
throw new Error(dedent`
Invalid configuration name: ${id}.
Available configuration names: ${listAvailableIds(true)}.
`);
}
export function formatValue(configKey, value) {
switch (configKey.kind) {
case 'bool': {
return value;
}
case 'inverted-bool': {
return !value;
}
case 'force-https': {
return value === 'ENABLED';
}
case 'task': {
return value === 'TASK';
}
default: {
return String(value);
}
}
}
export function parse(configKey, value) {
switch (configKey.kind) {
case 'bool':
case 'inverted-bool':
case 'force-https':
case 'task': {
if (value !== 'true' && value !== 'false') {
throw new Error('Invalid configuration value, it must be a boolean (true or false)');
}
if (configKey.kind === 'bool') {
return value === 'true';
}
if (configKey.kind === 'inverted-bool') {
return value === 'false';
}
if (configKey.kind === 'force-https') {
return value === 'true' ? 'ENABLED' : 'DISABLED';
}
if (configKey.kind === 'task') {
return value === 'false' ? 'REGULAR' : 'TASK';
}
return;
}
default: {
return value;
}
}
}
export function parseOptions(options) {
const newOptions = CONFIG_KEYS.map((configKey) => {
return parseConfigOption(configKey, options);
}).filter((a) => {
return a != null && a[1] != null;
});
return Object.fromEntries(newOptions);
}
function parseConfigOption(configKey, options) {
switch (configKey.kind) {
case 'bool':
case 'inverted-bool':
case 'force-https':
case 'task': {
const enable = options[`enable-${configKey.id}`];
const disable = options[`disable-${configKey.id}`];
if (enable && disable) {
throw new Error(`You cannot use both --enable-${configKey.id} and --disable-${configKey.id} at the same time`);
}
if (enable || disable) {
if (configKey.kind === 'bool') {
return [configKey.name, enable];
}
if (configKey.kind === 'inverted-bool') {
return [configKey.name, disable];
}
if (configKey.kind === 'force-https' || configKey.kind === 'task') {
return [configKey.name, parse(configKey, String(enable))];
}
}
return;
}
default: {
return [configKey.name, options[configKey.id]];
}
}
}
export function printValue(app, id) {
const configKey = getById(id);
Logger.println(formatValue(configKey, app[configKey.name]));
}
export function printAllValues(app) {
console.table(
Object.fromEntries(
CONFIG_KEYS.map((configKey) => {
return [configKey.id, formatValue(configKey, app[configKey.name])];
}),
),
);
}
|