forked from OKEAMAH/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.js
More file actions
41 lines (36 loc) · 1.04 KB
/
exec.js
File metadata and controls
41 lines (36 loc) · 1.04 KB
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
// @flow
import Project from '../../Project';
import * as options from '../../utils/options';
import { BoltError } from '../../utils/errors';
import execCommand from '../../utils/execCommand';
export type WorkspaceExecOptions = {
cwd?: string,
pkgName: string,
command: string,
commandArgs: options.Args
};
export function toWorkspaceExecOptions(
args: options.Args,
flags: options.Flags
): WorkspaceExecOptions {
let [pkgName] = args;
let [command, ...commandArgs] = flags['--'] || [];
return {
cwd: options.string(flags.cwd, 'cwd'),
pkgName,
command,
commandArgs
};
}
export async function workspaceExec(opts: WorkspaceExecOptions) {
let cwd = opts.cwd || process.cwd();
let project = await Project.init(cwd);
let packages = await project.getPackages();
let pkg = await project.getPackageByName(packages, opts.pkgName);
if (!pkg) {
throw new BoltError(
`Could not find a workspace named "${opts.pkgName}" from "${cwd}"`
);
}
await execCommand(project, pkg, opts.command, opts.commandArgs);
}