-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackageManagers.ts
More file actions
30 lines (22 loc) · 914 Bytes
/
packageManagers.ts
File metadata and controls
30 lines (22 loc) · 914 Bytes
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
import { fileExists, readFile } from "./filesystem";
import type { Config } from "../types/config";
import type { LockFile } from "../types/lockFile";
export const hasComposer = (config: Config): boolean =>
fileExists(config, "composer.json");
export const hasNpm = (config: Config): boolean =>
fileExists(config, "package.json");
export const hasYarn = (config: Config): boolean =>
fileExists(config, "yarn.lock");
export const getComposer = (config: Config): LockFile =>
<LockFile>JSON.parse(readFile(config, "composer.json"));
export const getNpm = (config: Config): LockFile =>
<LockFile>JSON.parse(readFile(config, "package.json"));
export const getPackageManager = (config: Config): LockFile => {
if (hasComposer(config)) {
return getComposer(config);
}
if (hasNpm(config) || hasYarn(config)) {
return getNpm(config);
}
return <LockFile>{};
};