/
gemfile.ts
43 lines (38 loc) · 1.32 KB
/
gemfile.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
import * as path from 'path';
import { tryGetSpec } from './try-get-spec';
import { Spec } from './index';
/* Supported example patterns:
* Gemfile
* Gemfile.lock
* rails.2.4.5.gemfile
* rails.2.4.5.gemfile.lock
* gemfiles/Gemfile.rails-2.4.5.lock
* gemfiles/Gemfile.lock.rails-2.4.5
*/
const gemfileOrLockfilePattern = /.*[gG]emfile.*(\.lock)?.*$/;
const gemfileLockPattern = /.*[gG]emfile.*(\.lock).*$/;
export function canHandle(file: string): boolean {
return !!file && gemfileOrLockfilePattern.test(path.basename(file));
}
export async function gatherSpecs(root: string, target: string): Promise<Spec> {
const { dir, name } = path.parse(target);
const isGemfileLock = gemfileLockPattern.test(target);
// if the target is a Gemfile we treat is as the lockfile
const gemfileLock = await tryGetSpec(
root,
isGemfileLock ? target : path.join(target + '.lock'),
);
if (gemfileLock) {
return {
packageName: path.basename(root),
targetFile: path.join(dir, name),
files: { gemfileLock },
};
} else {
throw new Error(
`Could not read ${target || 'Gemfile.lock'} lockfile: can't test ` +
'without dependencies.\nPlease run `bundle install` first or' +
' if this is a custom file name re-run with --file=path/to/custom.gemfile.lock --package-manager=rubygems',
);
}
}