-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
exec.ts
45 lines (38 loc) Β· 1.54 KB
/
exec.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 {BaseCommand} from '@yarnpkg/cli';
import {Configuration, Project} from '@yarnpkg/core';
import {scriptUtils} from '@yarnpkg/core';
import {Command, Option, Usage} from 'clipanion';
// eslint-disable-next-line arca/no-default-export
export default class ExecCommand extends BaseCommand {
static paths = [
[`exec`],
];
static usage: Usage = Command.Usage({
description: `execute a shell script`,
details: `
This command simply executes a shell script within the context of the root directory of the active workspace using the portable shell.
It also makes sure to call it in a way that's compatible with the current project (for example, on PnP projects the environment will be setup in such a way that PnP will be correctly injected into the environment).
`,
examples: [[
`Execute a single shell command`,
`$0 exec echo Hello World`,
], [
`Execute a shell script`,
`$0 exec "tsc & babel src --out-dir lib"`,
]],
});
commandName = Option.String();
args = Option.Proxy();
async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project, locator} = await Project.find(configuration, this.context.cwd);
await project.restoreInstallState();
return await scriptUtils.executePackageShellcode(locator, this.commandName, this.args, {
cwd: this.context.cwd,
stdin: this.context.stdin,
stdout: this.context.stdout,
stderr: this.context.stderr,
project,
});
}
}