UNPKG

@bowtie/sls

Version:

Serverless helpers & utilities

41 lines (32 loc) 1.13 kB
const defaults = require('./defaults') const { parseServiceConfig } = require('../utils') const mapAlias = (subject) => { const results = {} const { mappings = {} } = parseServiceConfig() Object.keys(mappings).forEach(scope => { const matches = mappings[scope] Object.keys(matches).forEach(match => { const compare = new RegExp(matches[match]) if (compare.test(subject)) { console.log('DEBUG: Subject matches!', { subject, compare, match }) if (results[scope]) { console.warn(`WARN: Duplicate mapping in '${scope}'! Overwriting: '${results[scope]}' -> '${match}' ...`) } results[scope] = match } }) }) console.log('DEBUG: mapAlias()', { results }) return results } const mapAliasScope = (scope, subject) => mapAlias(subject)[scope] const envGetAlias = (name) => (mapAliasScope('env', name) || defaults.envAlias) const envHasAlias = (name, alias) => (alias === envGetAlias(name)) const tagIsRelease = (tag) => tag && envHasAlias(tag, 'release') module.exports = { mapAlias, mapAliasScope, envGetAlias, envHasAlias, tagIsRelease }