reusable-serverless-template
Advanced tools
Comparing version 1.0.6 to 1.0.8
@@ -61,6 +61,6 @@ /** | ||
* @param params sls variable name -> value map. E.g. Map { '(foo' => 'bar', 'stage' => 'test)' } | ||
* @param print print the resolved template before converting to Yaml object | ||
* @param debug print the resolved template before converting to Yaml object | ||
* @return yaml object | ||
*/ | ||
export declare const load: (filePath: string, params?: Map<string, string>, print?: boolean) => string; | ||
export declare const load: (filePath: string, params?: Map<string, string>, debug?: boolean) => string; | ||
/** | ||
@@ -67,0 +67,0 @@ * Dump yaml object |
@@ -85,3 +85,3 @@ "use strict"; | ||
if (paramValue) { | ||
console.log(`Resolving ${variable} => ${paramValue}`); | ||
console.log(`\t ${variable} => ${paramValue}`); | ||
value = value.replace(variable, paramValue); | ||
@@ -149,3 +149,3 @@ } | ||
loadFile(filePath, params = new Map(), indentation = '') { | ||
console.log(`Loading ${path_1.basename(filePath)}, indentation '${indentation}', params ${YamlTemplate.mapToString(params)}`); | ||
console.log(`Loading ${path_1.basename(filePath)}(${YamlTemplate.mapToString(params)}), indented ${indentation.length}x' ', `); | ||
let fileContent = fs_1.readFileSync(filePath, 'utf8'); | ||
@@ -171,9 +171,13 @@ fileContent = fileContent.split('\n') | ||
* @param params sls variable name -> value map. E.g. Map { '(foo' => 'bar', 'stage' => 'test)' } | ||
* @param print print the resolved template before converting to Yaml object | ||
* @param debug print the resolved template before converting to Yaml object | ||
* @return yaml object | ||
*/ | ||
exports.load = function (filePath, params, print = true) { | ||
exports.load = function (filePath, params, debug = true) { | ||
const resolvedTemplate = new YamlTemplate().loadFile(filePath, params); | ||
if (print) { | ||
console.log(resolvedTemplate); | ||
if (debug) { | ||
const spaceCount = (lines) => lines.length.toString().length + 1; | ||
console.log(resolvedTemplate | ||
.split('\n') | ||
.map((line, index, lines) => `${(index + 1).toString().padStart(spaceCount(lines))}:${line}`) //add line numbers so we can easily find a serverless exception source | ||
.join('\n')); | ||
} | ||
@@ -180,0 +184,0 @@ return js_yaml_1.load(resolvedTemplate); |
{ | ||
"name": "reusable-serverless-template", | ||
"version": "1.0.6", | ||
"version": "1.0.8", | ||
"main": "dist/src/index.js", | ||
@@ -23,3 +23,3 @@ "scripts": { | ||
"ts-jest": "^23.10.4", | ||
"typescript": "^2.9.2" | ||
"typescript": "^3.3.1" | ||
}, | ||
@@ -26,0 +26,0 @@ "repository": { |
@@ -47,3 +47,3 @@ # Reusable serverless template | ||
* nested file without parameters ``${tfile:iamRoleStatements/dynamoDbFull.yml}`` | ||
* with parameters ``${tfile:iamRoleStatements/dynamoDbFull.yml:tableName=webhook}`` | ||
* with parameters ``${tfile:iamRoleStatements/dynamoDbFull.yml:tableName=entity}`` | ||
@@ -81,6 +81,4 @@ ## opt and custom | ||
let serverlessYaml = template.load(path.join(__dirname, 'serverless/serverless.core.yml', new Map([['version', '1.0.0']]))); | ||
const serverlessYaml = template.load(path.join(__dirname, 'serverless/serverless.core.yml', new Map([['version', '1.0.0']]))); | ||
console.log(template.dump(serverlessYaml)); | ||
module.exports = serverlessYaml; | ||
@@ -91,3 +89,3 @@ ``` | ||
``` | ||
service: webhookService | ||
service: entityService | ||
@@ -135,5 +133,5 @@ provider: | ||
## Changelog | ||
* 1.0.5 support comments - # at the beginning of a line (with optional lead white spaces) will skip the line | ||
* _1.0.5_ supports comments - # at the beginning of a line (with optional lead white spaces) will skip the line | ||
from processing | ||
* 1.0.1 added support to match and resolve nested variables like | ||
* _1.0.1_ added support to match and resolve nested variables like | ||
``${self:custom.tableName${opt:env}}`` |
21121
367
133