serverless-fragments
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -46,2 +46,3 @@ export declare type Token = { | ||
static replaceTFile(dir: string, value: string, startIndex: number, endIndex: number, indentation: string, params: Map<string, string>): string; | ||
private static chopLastColon; | ||
static extractTFile(value: string, startIndex: number, endIndex: number): TFile; | ||
@@ -48,0 +49,0 @@ static canReplace(value: string, startIndex: number, endIndex: number, params: Map<string, string>): boolean; |
@@ -86,4 +86,8 @@ "use strict"; | ||
.join('\n'); | ||
return value.replace(tFile.placeholder, this.resolveTokensRecursive(dir, fileContent, mergedParams)); | ||
const replaced = value.replace(tFile.placeholder, this.resolveTokensRecursive(dir, fileContent, mergedParams)); | ||
return this.chopLastColon(replaced); | ||
} | ||
static chopLastColon(value) { | ||
return value.endsWith(':') ? value.substring(0, value.length - 1) : value; | ||
} | ||
static extractTFile(value, startIndex, endIndex) { | ||
@@ -112,3 +116,3 @@ const tfilePlaceholder = value.substr(startIndex, endIndex - startIndex + 1); | ||
} | ||
return value; | ||
return this.chopLastColon(value); | ||
} | ||
@@ -115,0 +119,0 @@ static extractVariable(value, startIndex, endIndex) { |
@@ -60,2 +60,9 @@ "use strict"; | ||
})); | ||
it("optional colon after token", () => __awaiter(this, void 0, void 0, function* () { | ||
const content = `\${opt:stage}:`; | ||
const params = new Map([['stage', 'test']]); | ||
const resolved = src_1.FragmentsProcessor.replaceVariable(content, 0, content.length, params); | ||
const expectedContent = `test`; | ||
expect(resolved).toBe(expectedContent); | ||
})); | ||
}); | ||
@@ -62,0 +69,0 @@ describe("FragmentsProcessor resolveTokensRecursive", () => { |
{ | ||
"name": "serverless-fragments", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -80,3 +80,5 @@ # Serverless fragments | ||
* nested variables ``${self:${opt:env}.tableName}`` | ||
* a variables with a default ```` | ||
* a variables with a default ``${opt:stage, 'test'}`` | ||
*Note: tfile, opt and custom token support an optional colon after the declaration which is removed once there are resolved by the engine. The reason for it is to avoid validation error by yaml formatter in VSCode which otherwise reports the lines with tokens only as invalid mapping entry. This is a valid syntax too ``${tfile:config/${opt:stage}.json}:``* | ||
@@ -90,3 +92,3 @@ ### Comments | ||
* add comments to the fragments``# full entity table and all it's indexes access for the lambda`` | ||
## Examples | ||
@@ -93,0 +95,0 @@ |
36606
588
176