import { DockerfileParser } from 'dockerfile-ast';
import * as _ from 'lodash-es';
const { camelCase } = _;
export function getDockerfileContainers(dockerfileContent) {
    const dockerfile = DockerfileParser.parse(dockerfileContent);
    const containers = {};
    let imageWithTag;
    let image;
    let tag;
    for (const instruction of dockerfile.getInstructions()) {
        let alias;
        if (instruction.getKeyword() === 'FROM') {
            imageWithTag = instruction.getArgumentsContent();
            const split = instruction.getArgumentsContent().split(':');
            image = split[0];
            tag = split[1];
            containers[image] = imageWithTag;
            if (/^[a-zA-Z0-9-]*$/.test(image)) {
                alias = camelCase(image);
            }
        }
        else if (instruction.getKeyword() === 'LABEL') {
            const split = instruction.getArgumentsContent().split('=');
            if (split[0].toUpperCase() === 'ALIAS') {
                alias = camelCase(split[1]);
            }
        }
        if (alias) {
            containers[alias] = imageWithTag;
            containers[`${alias}Tag`] = tag;
            containers[`${alias}Image`] = image;
        }
    }
    return containers;
}
export const dockerPlaceholderGenerator = value => `${_.kebabCase(value)}-placeholder`;
