-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
plain.ts
31 lines (24 loc) · 969 Bytes
/
plain.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { readLocalFile } from '../../../../util/fs';
import type { Http } from '../../../../util/http';
import { newlineRegex } from '../../../../util/regex';
import type { ReleaseResult } from '../../types';
import type { CustomDatasourceFetcher } from './types';
function convertLinesToVersions(content: string): ReleaseResult {
const lines = content.split(newlineRegex).map((line) => line.trim());
const versions = lines.map((value) => {
return { version: value };
});
return {
releases: versions,
};
}
export class PlainFetcher implements CustomDatasourceFetcher {
async fetch(http: Http, registryURL: string): Promise<unknown> {
const response = await http.getPlain(registryURL);
return convertLinesToVersions(response.body);
}
async readFile(registryURL: string): Promise<unknown> {
const fileContent = await readLocalFile(registryURL, 'utf8');
return fileContent ? convertLinesToVersions(fileContent) : null;
}
}