/
extract.ts
45 lines (37 loc) · 1.16 KB
/
extract.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { newlineRegex, regEx } from '../../../util/regex';
import { AzureBicepResourceDatasource } from '../../datasource/azure-bicep-resource';
import type {
ExtractConfig,
PackageDependency,
PackageFileContent,
} from '../types';
const RESOURCE_REGEX = regEx(
/resource\s+[A-Za-z0-9_]+\s+(?<replaceString>'(?<depName>.+\..+\/.+)@(?<currentValue>.+?)')/
);
export function extractPackageFile(
content: string,
_packageFile: string,
_config: ExtractConfig
): Promise<PackageFileContent | null> {
const deps: PackageDependency[] = [];
for (const line of content.split(newlineRegex)) {
const trimmedLine = line?.trim();
if (!trimmedLine || trimmedLine.startsWith('//')) {
continue;
}
const match = RESOURCE_REGEX.exec(trimmedLine);
if (!match?.groups) {
continue;
}
const { depName, currentValue, replaceString } = match.groups;
deps.push({
datasource: AzureBicepResourceDatasource.id,
versioning: 'azure-rest-api',
depName,
currentValue,
autoReplaceStringTemplate: "'{{depName}}@{{newValue}}'",
replaceString,
});
}
return Promise.resolve(deps.length ? { deps } : null);
}