Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 52c9bc7

Browse files
vsavkinFrozenPandaz
authored andcommittedSep 11, 2020
feat(core): add a prompt when using --scan without nx-cloud
1 parent ed5f3a6 commit 52c9bc7

File tree

5 files changed

+77
-9
lines changed

5 files changed

+77
-9
lines changed
 

Diff for: ‎packages/create-nx-workspace/bin/create-nx-workspace.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function showHelp() {
135135
136136
interactive Enable interactive mode when using presets (boolean)
137137
138-
nx-cloud Connect to distributed computation cache provided by Nx Cloud (boolean)
138+
nx-cloud Use Nx Cloud (boolean)
139139
140140
[new workspace options] any 'new workspace' options
141141
`);
@@ -465,18 +465,18 @@ async function askAboutNxCloud(parsedArgs: any) {
465465
.prompt([
466466
{
467467
name: 'NxCloud',
468-
message: `Use the free tier of the distributed cache provided by Nx Cloud?`,
468+
message: `Use Nx Cloud? (It's free and doesn't require registration.)`,
469469
type: 'list',
470470
choices: [
471471
{
472472
value: 'yes',
473473
name:
474-
'Yes [Faster command execution, faster CI. Learn more at https://nx.app]',
474+
'Yes [Faster builds, run details, Github integration. Learn more at https://nx.app]',
475475
},
476476

477477
{
478478
value: 'no',
479-
name: 'No [Only use local computation cache]',
479+
name: 'No',
480480
},
481481
],
482482
default: 'no',

Diff for: ‎packages/workspace/src/command-line/affected.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import { calculateFileChanges, readEnvironment } from '../core/file-utils';
1616
import { printAffected } from './print-affected';
1717
import { projectHasTarget } from '../utils/project-graph-utils';
1818
import { DefaultReporter } from '../tasks-runner/default-reporter';
19+
import { promptForNxCloud } from './prompt-for-nx-cloud';
1920

20-
export function affected(
21+
export async function affected(
2122
command: 'apps' | 'libs' | 'dep-graph' | 'print-affected' | 'affected',
2223
parsedArgs: yargs.Arguments & RawNxArgs
23-
): void {
24+
) {
2425
const { nxArgs, overrides } = splitArgsIntoNxArgsAndOverrides(
2526
parsedArgs,
2627
'affected',
@@ -29,6 +30,8 @@ export function affected(
2930
}
3031
);
3132

33+
await promptForNxCloud(nxArgs.scan);
34+
3235
const projectGraph = createProjectGraph();
3336
let affectedGraph = nxArgs.all
3437
? projectGraph
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as inquirer from 'inquirer';
2+
import { readNxJson } from '../core/file-utils';
3+
import { output } from '../utils/output';
4+
import { detectPackageManager } from '../utils/detect-package-manager';
5+
import { execSync } from 'child_process';
6+
7+
export async function promptForNxCloud(scan: boolean) {
8+
if (!scan) return;
9+
10+
const nxJson = readNxJson();
11+
const nxCloudRunnerIsUsed = Object.values(nxJson.tasksRunnerOptions).find(
12+
(r) => r.runner == '@nrwl/nx-cloud'
13+
);
14+
if (nxCloudRunnerIsUsed) return;
15+
16+
const res = await askAboutNxCloud();
17+
if (res) {
18+
const pm = detectPackageManager();
19+
if (pm === 'yarn') {
20+
execSync('yarn add -D @nrwl/nx-cloud@latest');
21+
} else {
22+
execSync('npm install --save-dev @nrwl/nx-cloud@latest');
23+
}
24+
execSync(`npx nx g @nrwl/nx-cloud:init`, {
25+
stdio: [0, 1, 2],
26+
});
27+
} else {
28+
output.log({ title: 'Executing the command without --scan' });
29+
}
30+
}
31+
32+
async function askAboutNxCloud() {
33+
output.log({
34+
title: '--scan requires the workspace to be connected to Nx Cloud.',
35+
});
36+
return inquirer
37+
.prompt([
38+
{
39+
name: 'NxCloud',
40+
message: `Use Nx Cloud? (It's free and doesn't require registration.)`,
41+
type: 'list',
42+
choices: [
43+
{
44+
value: 'yes',
45+
name:
46+
'Yes [Faster builds, run details, Github integration. Learn more at https://nx.app]',
47+
},
48+
49+
{
50+
value: 'no',
51+
name: 'No',
52+
},
53+
],
54+
default: 'no',
55+
},
56+
])
57+
.then((a: { NxCloud: 'yes' | 'no' }) => a.NxCloud === 'yes');
58+
}

Diff for: ‎packages/workspace/src/command-line/run-many.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import { readEnvironment } from '../core/file-utils';
1313
import { DefaultReporter } from '../tasks-runner/default-reporter';
1414
import { projectHasTarget } from '../utils/project-graph-utils';
1515
import { output } from '../utils/output';
16+
import { promptForNxCloud } from './prompt-for-nx-cloud';
1617

17-
export function runMany(parsedArgs: yargs.Arguments): void {
18+
export async function runMany(parsedArgs: yargs.Arguments) {
1819
const { nxArgs, overrides } = splitArgsIntoNxArgsAndOverrides(
1920
parsedArgs,
2021
'run-many'
2122
);
23+
24+
await promptForNxCloud(nxArgs.scan);
25+
2226
const projectGraph = createProjectGraph();
2327
const projects = projectsToRun(nxArgs, projectGraph);
2428
const projectMap: Record<string, ProjectGraphNode> = {};

Diff for: ‎packages/workspace/src/command-line/run-one.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { readEnvironment } from '../core/file-utils';
44
import { EmptyReporter } from '../tasks-runner/empty-reporter';
55
import { splitArgsIntoNxArgsAndOverrides } from './utils';
66
import { projectHasTarget } from '../utils/project-graph-utils';
7+
import { promptForNxCloud } from './prompt-for-nx-cloud';
78

8-
export function runOne(opts: {
9+
export async function runOne(opts: {
910
project: string;
1011
target: string;
1112
configuration: string;
1213
parsedArgs: any;
13-
}): void {
14+
}) {
1415
const { nxArgs, overrides } = splitArgsIntoNxArgsAndOverrides(
1516
{
1617
...opts.parsedArgs,
@@ -20,6 +21,8 @@ export function runOne(opts: {
2021
'run-one'
2122
);
2223

24+
await promptForNxCloud(nxArgs.scan);
25+
2326
const projectGraph = createProjectGraph();
2427
const { projects, projectsMap } = getProjects(
2528
projectGraph,

0 commit comments

Comments
 (0)
Please sign in to comment.