<commit_before>'use strict';

const _camelCase = require('camelcase');
const LambdaTemplates = require('wysknd-aws-cf-generator').LambdaTemplates;
const FunctionTemplate = LambdaTemplates.FunctionTemplate;
const _lambdaConfig = require('../../../src/lambda-config');

module.exports = (dirInfo) => {
    return _lambdaConfig.lambdas.map((lambda) => {
        const roleName = '<%= projectPrefix %>.default_lambda_role';
        const key = _camelCase(lambda.functionName);
        const roleKey = dirInfo.getRootToken(roleName);

        const template = new FunctionTemplate(key, lambda.functionName, lambda.handlerName)
            .setRole(`$REGION.${roleName}`)
            .addDependency(roleKey);

        if (typeof lambda.description === 'string' &&
            lambda.description.length > 0) {
            template.setDescription(lambda.description);
        }

        if (typeof lambda.memory === 'number') {
            template.setMemorySize(lambda.memory);
        }

        if (typeof lambda.timeout === 'number') {
            template.setTimeout(lambda.timeout);
        }

        return template;
    });
};<commit_msg>Include alias generation in lambda function template<commit_after>'use strict';

const LambdaTemplates = require('wysknd-aws-cf-generator').LambdaTemplates;
const FunctionTemplate = LambdaTemplates.FunctionTemplate;
const AliasTemplate = LambdaTemplates.AliasTemplate;

const _lambdaConfig = require('../../../src/lambda-config');

module.exports = (dirInfo) => {
    return _lambdaConfig.lambdas.map((lambda) => {
        const roleName = '<%= projectPrefix %>.default_lambda_role';
        const roleKey = dirInfo.getNamespacedToken('iam_role', roleName);

        const functionName = lambda.functionName;
        const functionKey = dirInfo.getNamespacedToken('lambda_function', functionName);

        const functionTemplate = new FunctionTemplate(functionKey, functionName, lambda.handlerName)
            .setRole(`$REGION.${roleName}`)
            .addDependency(roleKey);

        if (typeof lambda.description === 'string' &&
            lambda.description.length > 0) {
            functionTemplate.setDescription(lambda.description);
        }

        if (typeof lambda.memory === 'number') {
            functionTemplate.setMemorySize(lambda.memory);
        }

        if (typeof lambda.timeout === 'number') {
            functionTemplate.setTimeout(lambda.timeout);
        }

        const aliasTemplates = [<%- projectTargetEnvironments.map(item => `'${item}'`).join(',') %>].map((envName) => {
            const aliasKey = dirInfo.getNamespacedToken('lambda_alias', `${functionName}_${envName}`);
            return new AliasTemplate(aliasKey, envName, functionName)
                .addDependency(functionKey);
        });

        return [functionTemplate].concat(aliasTemplates);
    }).reduce((result, item) => {
        return result.concat(item);
    }, []);
};
{'fraction_non_alphanumeric': 0.13499658236500342, 'fraction_numerical': 0.000683526999316473, 'mean_word_length': 3.070931849791377, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1889564', 'n_tokens_mistral': 786, 'n_tokens_neox': 767, 'n_words': 140}