forked from renovatebot/renovate
/
extract.ts
44 lines (38 loc) · 1.18 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
import { newlineRegex } from '../../../util/regex';
import { GitTagsDatasource } from '../../datasource/git-tags';
import type { PackageDependency, PackageFileContent } from '../types';
export function extractPackageFile(content: string): PackageFileContent | null {
const deps: PackageDependency[] = [];
for (const line of content.split(newlineRegex).map((s) => s.trim())) {
if (line === '') {
continue;
}
// commented out line
if (line.startsWith('#')) {
continue;
}
// commented out line after package name
if (line.includes('#')) {
const [uncommentLine] = line.split('#');
deps.push(handleDepInMintfile(uncommentLine));
continue;
}
deps.push(handleDepInMintfile(line));
}
return deps.length ? { deps } : null;
}
function handleDepInMintfile(line: string): PackageDependency {
if (!line.includes('@')) {
return {
depName: line,
skipReason: 'unspecified-version',
};
}
const [depName, currentVersion] = line.split('@').map((s) => s.trim());
return {
depName,
currentValue: currentVersion,
datasource: GitTagsDatasource.id,
packageName: `https://github.com/${depName}.git`,
};
}