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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | 1x 1x 1x 1x 1x 1x 1x 54x 54x 54x 1x 1x 1x 1x 1x 1x 1x 30x 30x 14x 14x 16x 16x 16x 16x 50x 16x 16x 16x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 4x 8x 8x 4x 14x 12x 20x 20x 12x 12x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 20x 20x 20x 20x 33x 33x 20x 20x 20x 20x 20x 1x 1x 1x 1x 1x 1x 9x 9x 9x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 14x 14x 8x 8x 8x 8x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 15x 8x 14x 14x 14x 2x 2x 14x 14x 14x 8x 8x 8x 8x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 36x 36x 36x 36x 2x 2x 36x 36x 36x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 1x 135x 135x 135x 135x 2x 2x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 135x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x |
/**
* Generate string from the params.
* @param {string} cmdName - Name of the command.
* @param {string} param - Parameter of the command.
* @return {string} The generated string.
*/
function processString(cmdName, param) {
return `${cmdName} ${param}`;
}
/**
* Process Cmd, Run, Entrypoint, Shell commands.
* @param {string} cmdName - Name of the command.
* @param {*} params - Parameters of the command.
* @return {string} - The generated string.
*/
function processCmdAndRunAndEntryPointAndShell(cmdName, params) {
if (typeof params === 'string') {
return `${cmdName} [ "${params}" ]`;
}
if (Array.isArray(params)) {
let paramsList = '';
params.forEach((param) => {
paramsList += `"${param}", `;
});
// remove tailing colon
paramsList = paramsList.replace(/, $/, '');
return `${cmdName} [ ${paramsList} ]`;
}
return null;
}
/**
* Process Label, Env commands.
* @param {*} cmdName - Name of the command.
* @param {*} params - Parameters of the command.
* @return {string} - The generated string.
*/
function processLabelAndEnv(cmdName, params) {
let lines = '';
if (Array.isArray(params)) {
Object.keys(params).forEach((key) => {
lines += `${cmdName} ${key}=${params[key]}`;
lines += '\n';
});
} else if (typeof params === 'object') {
Object.keys(params).forEach((key) => {
lines += `${cmdName} ${key}=${params[key]}`;
lines += '\n';
});
}
lines = lines.substring(0, lines.length - 1);
return lines;
}
/**
* Process Arg, Expose commands.
* @param {string} cmdName - Name of the command.
* @param {*} params - Parameters of the command.
* @return {string} - The generated string.
*/
function processSimpleArrays(cmdName, params) {
let lines = '';
params.forEach((param) => {
lines += `${cmdName} ${param}`;
lines += '\n';
});
lines = lines.substring(0, lines.length - 1);
return lines;
}
/**
* Process CMD command.
* @param {*} params - parameters of the CMD command.
* @return {string} - The generated string.
*/
function processSingleCmd(params) {
return processCmdAndRunAndEntryPointAndShell('CMD', params);
}
/**
* Process RUN command.
* @param {*} params - parameters of the RUN command.
* @return {string} - The generated string.
*/
function processSingleRun(params) {
return processCmdAndRunAndEntryPointAndShell('RUN', params);
}
/**
* Process LABEL command.
* @param {*} params - parameters of the LABEL command.
* @return {string} - The generated string.
*/
function processLabels(params) {
return processLabelAndEnv('LABEL', params);
}
/**
* Process ENV command.
* @param {*} params - parameters of the ENV command.
* @return {string} - The generated string.
*/
function processEnvs(params) {
return processLabelAndEnv('ENV', params);
}
/**
* Process ADD command.
* @param {*} params - parameters of the ADD command.
* @return {string} - The generated string.
*/
function processAdd(params) {
let lines = '';
Object.keys(params).forEach((key) => {
lines += `ADD ${key} ${params[key]}`;
lines += '\n';
});
lines = lines.substring(0, lines.length - 1);
return lines;
}
/**
* Process COPY command.
* @param {*} params - parameters of the COPY command.
* @return {string} - The generated string.
*/
function processCopy(params) {
let lines = '';
Object.keys(params).filter((key) => {
return key !== 'from';
}).forEach((key) => {
let command = 'COPY';
if (params.from) {
command = `COPY --from=${params.from}`;
}
lines += `${command} ${key} ${params[key]}`;
lines += '\n';
});
lines = lines.substring(0, lines.length - 1);
return lines;
}
/**
* Process ENTRYPOINT command.
* @param {*} params - parameters of the ENTRYPOINT command.
* @return {string} - The generated string.
*/
function processEntryPoint(params) {
return processCmdAndRunAndEntryPointAndShell('ENTRYPOINT', params);
}
/**
* Process FROM command.
* @param {*} params - parameters of the FROM command.
* @return {string} - The generated string.
*/
function processFrom(params) {
let response = processString('FROM', params.baseImage);
if (params.alias) {
response = `${response} AS ${params.alias}`;
}
return response;
}
/**
* Process USER command.
* @param {*} params - parameters of the USER command.
* @return {string} - The generated string.
*/
function processUser(params) {
return processString('USER', params);
}
/**
* Process WORKDIR command.
* @param {*} params - parameters of the FROM command.
* @return {string} - The generated string.
*/
function processWorkDir(params) {
return processString('WORKDIR', params);
}
/**
* Process STOPSIGNAL command.
* @param {*} params - parameters of the STOPSIGNAL command.
* @return {string} - The generated string.
*/
function processStopSignal(params) {
return processString('STOPSIGNAL', params);
}
/**
* Process EXPOSE command.
* @param {*} params - parameters of the EXPOSE command.
* @return {string} - The generated string.
*/
function processExposes(params) {
return processSimpleArrays('EXPOSE', params);
}
/**
* Process ARG command.
* @param {*} params - parameters of the ARG command.
* @return {string} - The generated string.
*/
function processArgs(params) {
return processSimpleArrays('ARG', params);
}
/**
* Process VOLUME command.
* @param {*} params - parameters of the VOLUME command.
* @return {string} - The generated string.
*/
function processVolumes(params) {
return processSimpleArrays('VOLUME', params);
}
/**
* Process SHELL command.
* @param {*} params - parameters of the SHELL command.
* @return {string} - The generated string.
*/
function processShell(params) {
return processCmdAndRunAndEntryPointAndShell('SHELL', params);
}
/**
* Process COMMENT symbol.
* @param {*} params - parameters of the COMMENT symbol.
* @return {string} - The generated string.
*/
function processComment(params) {
return `# ${params}`;
}
/**
* Determine the name of the corresponding function.
* @param {string} functionName - Name of the function.
* @return {*} - The callable function.
*/
function determineFunction(functionName) {
let fName = functionName.toLowerCase();
if (functionName.indexOf('-') !== -1) {
fName = functionName.substring(0, functionName.indexOf('-'));
}
const functions = {
from: processFrom,
run: processSingleRun,
cmd: processSingleCmd,
labels: processLabels,
expose: processExposes,
env: processEnvs,
add: processAdd,
copy: processCopy,
entrypoint: processEntryPoint,
volumes: processVolumes,
user: processUser,
working_dir: processWorkDir,
args: processArgs,
stopsignal: processStopSignal,
shell: processShell,
comment: processComment,
};
return functions[fName] || functions.comment;
}
module.exports = {
processFrom,
processRun: processSingleRun,
processCmd: processSingleCmd,
processLabels,
processEnvs,
processExposes,
processAdd,
processCopy,
processEntryPoint,
processUser,
processWorkDir,
processStopSignal,
processArgs,
processVolumes,
processShell,
determineFunction,
processComment,
};
|