Skip to content

Commit 301f65e

Browse files
alexeaglekormide
andauthored
feat: fill substitutions in source.json#docs_url (#290)
* chore: fill substitutions in source.json#docs_url See bazelbuild/bazel-central-registry#5593 * squash: add test --------- Co-authored-by: Derek Cormier <[email protected]>
1 parent a965eec commit 301f65e

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

dist/cli/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/domain/source-template.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,33 @@ describe('substitute', () => {
105105
);
106106
expect(jsonContent.strip_prefix).toEqual('bar-1.2.3');
107107
});
108+
109+
test('substitutes docs_url', () => {
110+
mockSourceFile({
111+
content: `\
112+
{
113+
"integrity": "",
114+
"strip_prefix": "{REPO}-{VERSION}",
115+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz",
116+
"docs_url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.docs.tar.gz"
117+
}`,
118+
});
119+
const sourceTemplate = new SourceTemplate('source.template.json');
120+
sourceTemplate.substitute({
121+
OWNER: 'foo',
122+
REPO: 'bar',
123+
TAG: 'v1.2.3',
124+
VERSION: '1.2.3',
125+
});
126+
sourceTemplate.save('source.json');
127+
128+
const jsonContent = JSON.parse(
129+
mocked(fs.writeFileSync).mock.calls[0][1] as string
130+
);
131+
expect(jsonContent.docs_url).toEqual(
132+
'https://github.com/foo/bar/releases/download/v1.2.3/bar-v1.2.3.docs.tar.gz'
133+
);
134+
});
108135
});
109136

110137
describe('validateFullySubstituted', () => {

src/domain/source-template.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class SourceTemplate {
6262
public substitute(
6363
vars: Partial<Record<SubstitutableVar, string>>
6464
): SourceTemplate {
65-
for (const prop of ['url', 'strip_prefix'].filter(
65+
for (const prop of ['docs_url', 'url', 'strip_prefix'].filter(
6666
(prop) => prop in this.sourceJson
6767
)) {
6868
this.sourceJson[prop] = substituteVars(
@@ -76,7 +76,7 @@ export class SourceTemplate {
7676

7777
public validateFullySubstituted(): void {
7878
const unsubstituted = new Set<SubstitutableVar>();
79-
for (const prop of ['url', 'strip_prefix'].filter(
79+
for (const prop of ['docs_url', 'url', 'strip_prefix'].filter(
8080
(prop) => prop in this.sourceJson
8181
)) {
8282
getUnsubstitutedVars(this.sourceJson[prop] as string).forEach((v) =>

0 commit comments

Comments
 (0)