Repository navigation
Expand file tree
/
Copy pathnx-cloud.ts
More file actions
64 lines (56 loc) · 1.9 KB
/
Copy pathnx-cloud.ts
File metadata and controls
64 lines (56 loc) · 1.9 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
import { getCloudOptions } from '../src/nx-cloud/utilities/get-cloud-options';
import {
NxCloudClientUnavailableError,
NxCloudEnterpriseOutdatedError,
} from '../src/nx-cloud/update-manager';
import type { CloudTaskRunnerOptions } from '../src/nx-cloud/nx-cloud-tasks-runner-shell';
import { output } from '../src/utils/output';
import {
UnknownCommandError,
getCloudClient,
} from '../src/nx-cloud/utilities/client';
const command = process.argv[2];
const options = getCloudOptions();
Promise.resolve().then(async () => invokeCommandWithNxCloudClient(options));
export async function invokeCommandWithNxCloudClient(
options: CloudTaskRunnerOptions
) {
try {
const client = await getCloudClient(options);
client.invoke(command);
} catch (e: any) {
if (e instanceof UnknownCommandError) {
output.error({
title: `Unknown Command "${e.command}"`,
});
output.log({
title: 'Available Commands:',
bodyLines: e.availableCommands.map((c) => `- ${c}`),
});
process.exit(1);
}
const body = ['Cannot run commands from the `nx-cloud` CLI.'];
if (e instanceof NxCloudEnterpriseOutdatedError) {
try {
// TODO: Remove this when all enterprise customers have updated.
// Try requiring the bin from the `nx-cloud` package.
return require('nx-cloud/bin/nx-cloud');
} catch {}
body.push(
'If you are an Nx Enterprise customer, please reach out to your assigned Developer Productivity Engineer.',
'If you are NOT an Nx Enterprise customer but are seeing this message, please reach out to cloud-support@nrwl.io.'
);
}
if (e instanceof NxCloudClientUnavailableError) {
body.unshift(
'You may be offline. Please try again when you are back online.'
);
}
output.error({
title: e.message,
bodyLines: body,
});
process.exit(1);
}
}