-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(semver): add tag template string support
- Loading branch information
1 parent
4bc45e3
commit 91dec48
Showing
5 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/semver/src/executors/version/utils/tag-template.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { resolveTagTemplate } from './tag-template'; | ||
|
||
describe('resolveTagTemplate', () => { | ||
const testContext = { test1: 'xxx', test2: 'yyy' }; | ||
|
||
it('should do noting to the template string', () => { | ||
expect(resolveTagTemplate('test string that have test1 and ${nothing} in it', testContext)) | ||
.toBe('test string that have test1 and ${nothing} in it'); | ||
}); | ||
|
||
it('should replace all ${test1} placeholders', () => { | ||
expect(resolveTagTemplate('test string with ${test1}, when ${test1} repeat itself', testContext)) | ||
.toBe('test string with xxx, when xxx repeat itself'); | ||
}); | ||
|
||
it('should replace all ${test1} and ${test2} placeholders', () => { | ||
expect(resolveTagTemplate('test string with ${test1} and ${test2}', testContext)) | ||
.toBe('test string with xxx and yyy'); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/semver/src/executors/version/utils/tag-template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface TagTemplateContext { | ||
[key: string]: string; | ||
} | ||
|
||
export function resolveTagTemplate(template: string, resolvingContext: TagTemplateContext): string { | ||
return Object.keys(resolvingContext) | ||
.reduce((accumulator, contextParamKey) => accumulator | ||
.replace(new RegExp(`\\$\\{${contextParamKey}}`, 'g'), | ||
resolvingContext[contextParamKey]), template); | ||
} |