-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
82 lines (75 loc) · 2.05 KB
/
mod.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {
isUnix,
NpmWrapper,
createRestoreCommand,
createScriptCommand,
createGenericCommand,
NpmCommand,
} from "./_utils.ts";
import {
createWindowsWrapper,
} from "./_windows.ts";
import {
createLinuxWrapper,
} from "./_unix.ts";
function createWrapper(): NpmWrapper {
return isUnix() ? createLinuxWrapper() : createWindowsWrapper();
}
export {
NpmCommand,
RestorePackagesCommand,
RunScriptCommand,
} from "./_utils.ts";
/**
* Checks if NPM is installed and available. This requires the --allow-run permission.
*/
export function isNpmInstalled(): Promise<boolean> {
const wrapper = createWrapper();
return wrapper.isInstalled();
}
/**
* Restore packages for a given Directory. This requires the --allow-run permission.
* @param dir Directory containing packages.json
*/
export function restoreNpmPackages(dir?: string): Promise<boolean> {
dir = dir ?? Deno.cwd();
const wrapper = createWrapper();
const command = createRestoreCommand(dir);
return wrapper.run(command);
}
/**
* Runs a NPM Script via "npm run <script>". This requires the --allow-run permission.
* @param scriptName Script to be executed
* @param dir Directory containing packages.json
*/
export function runNpmScript(
scriptName: string,
dir?: string,
): Promise<boolean> {
dir = dir ?? Deno.cwd();
const wrapper = createWrapper();
const command = createScriptCommand(dir, scriptName);
return wrapper.run(command);
}
/**
* Runs a NPM command. This requires the --allow-run permission.
* @param commandArgs Command to be run, e.g. fund
* @param dir Directory for context
*/
export function runNpmCommand(
commandArgs: string[],
dir?: string,
): Promise<boolean> {
dir = dir ?? Deno.cwd();
const wrapper = createWrapper();
const command = createGenericCommand(commandArgs, dir);
return wrapper.run(command);
}
/**
* Runs a NPM command. This requires the --allow-run permission.
* @param npmCommand Command to be run
*/
export function runGenericNpmCommand(npmCommand: NpmCommand) {
const wrapper = createWrapper();
return wrapper.run(npmCommand);
}