create-nx-workspace 17.0.3 → 17.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +8 -3
- package/bin/create-nx-workspace.d.ts +6 -1
- package/bin/create-nx-workspace.js +205 -76
- package/package.json +3 -3
- package/src/create-preset.js +1 -1
- package/src/create-workspace-options.d.ts +2 -7
- package/src/create-workspace.js +8 -8
- package/src/internal-utils/prompts.d.ts +3 -7
- package/src/internal-utils/prompts.js +23 -58
- package/src/internal-utils/yargs-options.d.ts +1 -4
- package/src/internal-utils/yargs-options.js +6 -13
- package/src/utils/nx/ab-testing.d.ts +59 -9
- package/src/utils/nx/ab-testing.js +43 -11
- package/src/utils/nx/nx-cloud.d.ts +2 -1
- package/src/utils/nx/nx-cloud.js +22 -10
- package/src/utils/nx/show-nx-warning.js +4 -2
- package/src/utils/output.d.ts +0 -1
- package/src/utils/output.js +6 -7
- package/src/utils/package-manager.d.ts +1 -0
- package/src/utils/package-manager.js +3 -0
- package/src/utils/preset/point-to-tutorial-and-course.js +1 -1
- package/src/utils/preset/preset-options.js +4 -0
- package/src/utils/preset/preset.d.ts +7 -2
- package/src/utils/preset/preset.js +5 -0
- package/src/utils/ci/ci-list.d.ts +0 -2
- package/src/utils/ci/ci-list.js +0 -10
package/src/create-workspace.js
CHANGED
|
@@ -11,26 +11,26 @@ const git_1 = require("./utils/git/git");
|
|
|
11
11
|
const get_third_party_preset_1 = require("./utils/preset/get-third-party-preset");
|
|
12
12
|
const error_utils_1 = require("./utils/error-utils");
|
|
13
13
|
async function createWorkspace(preset, options) {
|
|
14
|
-
const { packageManager, name, nxCloud,
|
|
14
|
+
const { packageManager, name, nxCloud, skipGit = false, defaultBase = 'main', commit, cliName, } = options;
|
|
15
15
|
if (cliName) {
|
|
16
16
|
output_1.output.setCliName(cliName ?? 'NX');
|
|
17
17
|
}
|
|
18
18
|
const tmpDir = await (0, create_sandbox_1.createSandbox)(packageManager);
|
|
19
|
-
// nx new requires preset currently. We should probably make it optional.
|
|
19
|
+
// nx new requires a preset currently. We should probably make it optional.
|
|
20
20
|
const directory = await (0, create_empty_workspace_1.createEmptyWorkspace)(tmpDir, name, packageManager, { ...options, preset });
|
|
21
21
|
// If the preset is a third-party preset, we need to call createPreset to install it
|
|
22
|
-
// For first-party presets, it will created by createEmptyWorkspace instead.
|
|
22
|
+
// For first-party presets, it will be created by createEmptyWorkspace instead.
|
|
23
23
|
// In createEmptyWorkspace, it will call `nx new` -> `@nx/workspace newGenerator` -> `@nx/workspace generatePreset`.
|
|
24
24
|
const thirdPartyPreset = await (0, get_third_party_preset_1.getThirdPartyPreset)(preset);
|
|
25
25
|
if (thirdPartyPreset) {
|
|
26
26
|
await (0, create_preset_1.createPreset)(thirdPartyPreset, options, packageManager, directory);
|
|
27
27
|
}
|
|
28
28
|
let nxCloudInstallRes;
|
|
29
|
-
if (nxCloud) {
|
|
30
|
-
nxCloudInstallRes = await (0, nx_cloud_1.setupNxCloud)(directory, packageManager);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
if (nxCloud !== 'skip') {
|
|
30
|
+
nxCloudInstallRes = await (0, nx_cloud_1.setupNxCloud)(directory, packageManager, nxCloud);
|
|
31
|
+
if (nxCloud !== 'yes') {
|
|
32
|
+
await (0, setup_ci_1.setupCI)(directory, nxCloud, packageManager, nxCloudInstallRes?.code === 0);
|
|
33
|
+
}
|
|
34
34
|
}
|
|
35
35
|
if (!skipGit && commit) {
|
|
36
36
|
try {
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import * as yargs from 'yargs';
|
|
2
|
-
import { CI } from '../utils/ci/ci-list';
|
|
3
2
|
import { PackageManager } from '../utils/package-manager';
|
|
3
|
+
import { NxCloud } from '../utils/nx/nx-cloud';
|
|
4
4
|
export declare function determineNxCloud(parsedArgs: yargs.Arguments<{
|
|
5
|
-
nxCloud:
|
|
6
|
-
}>): Promise<
|
|
7
|
-
export declare function determineCI(parsedArgs: yargs.Arguments<{
|
|
8
|
-
ci?: CI;
|
|
9
|
-
allPrompts?: boolean;
|
|
10
|
-
}>, nxCloud: boolean): Promise<string>;
|
|
5
|
+
nxCloud: NxCloud;
|
|
6
|
+
}>): Promise<NxCloud>;
|
|
11
7
|
export declare function determineDefaultBase(parsedArgs: yargs.Arguments<{
|
|
12
8
|
defaultBase?: string;
|
|
13
9
|
}>): Promise<string>;
|
|
@@ -1,79 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.determinePackageManager = exports.determineDefaultBase = exports.
|
|
3
|
+
exports.determinePackageManager = exports.determineDefaultBase = exports.determineNxCloud = void 0;
|
|
4
4
|
const ab_testing_1 = require("../utils/nx/ab-testing");
|
|
5
5
|
const output_1 = require("../utils/output");
|
|
6
6
|
const default_base_1 = require("../utils/git/default-base");
|
|
7
7
|
const package_manager_1 = require("../utils/package-manager");
|
|
8
8
|
const string_utils_1 = require("../utils/string-utils");
|
|
9
9
|
const enquirer = require("enquirer");
|
|
10
|
+
const chalk = require("chalk");
|
|
10
11
|
async function determineNxCloud(parsedArgs) {
|
|
11
12
|
if (parsedArgs.nxCloud === undefined) {
|
|
12
|
-
return
|
|
13
|
-
.prompt([
|
|
14
|
-
{
|
|
15
|
-
name: 'NxCloud',
|
|
16
|
-
message: ab_testing_1.messages.getPromptMessage('nxCloudCreation'),
|
|
17
|
-
type: 'autocomplete',
|
|
18
|
-
choices: [
|
|
19
|
-
{
|
|
20
|
-
name: 'Yes',
|
|
21
|
-
hint: 'I want faster builds',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: 'No',
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
initial: 'Yes',
|
|
28
|
-
},
|
|
29
|
-
])
|
|
30
|
-
.then((a) => a.NxCloud === 'Yes');
|
|
13
|
+
return nxCloudPrompt('setupCI');
|
|
31
14
|
}
|
|
32
15
|
else {
|
|
33
16
|
return parsedArgs.nxCloud;
|
|
34
17
|
}
|
|
35
18
|
}
|
|
36
19
|
exports.determineNxCloud = determineNxCloud;
|
|
37
|
-
async function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return '';
|
|
20
|
+
async function nxCloudPrompt(key) {
|
|
21
|
+
const { message, choices, initial, fallback, footer, hint } = ab_testing_1.messages.getPrompt(key);
|
|
22
|
+
const promptConfig = {
|
|
23
|
+
name: 'NxCloud',
|
|
24
|
+
message,
|
|
25
|
+
type: 'autocomplete',
|
|
26
|
+
choices,
|
|
27
|
+
initial,
|
|
28
|
+
}; // meeroslav: types in enquirer are not up to date
|
|
29
|
+
if (footer) {
|
|
30
|
+
promptConfig.footer = () => chalk.dim(footer);
|
|
49
31
|
}
|
|
50
|
-
if (
|
|
51
|
-
|
|
32
|
+
if (hint) {
|
|
33
|
+
promptConfig.hint = () => chalk.dim(hint);
|
|
52
34
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
type: 'autocomplete',
|
|
60
|
-
initial: '',
|
|
61
|
-
choices: [
|
|
62
|
-
{ message: 'none', name: '' },
|
|
63
|
-
{ message: 'GitHub Actions', name: 'github' },
|
|
64
|
-
{ message: 'Circle CI', name: 'circleci' },
|
|
65
|
-
{ message: 'Azure DevOps', name: 'azure' },
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
])
|
|
69
|
-
// enquirer ignores name and value if they are falsy and takes
|
|
70
|
-
// first field that has a truthy value, so wee need to explicitly
|
|
71
|
-
// check for none
|
|
72
|
-
.then((a) => (a.CI !== 'none' ? a.CI : '')));
|
|
73
|
-
}
|
|
74
|
-
return '';
|
|
35
|
+
return enquirer.prompt([promptConfig]).then((a) => {
|
|
36
|
+
if (fallback && a.NxCloud === fallback.value) {
|
|
37
|
+
return nxCloudPrompt(fallback.key);
|
|
38
|
+
}
|
|
39
|
+
return a.NxCloud;
|
|
40
|
+
});
|
|
75
41
|
}
|
|
76
|
-
exports.determineCI = determineCI;
|
|
77
42
|
async function determineDefaultBase(parsedArgs) {
|
|
78
43
|
if (parsedArgs.defaultBase) {
|
|
79
44
|
return Promise.resolve(parsedArgs.defaultBase);
|
|
@@ -124,7 +89,7 @@ async function determinePackageManager(parsedArgs) {
|
|
|
124
89
|
{
|
|
125
90
|
name: 'packageManager',
|
|
126
91
|
message: `Which package manager to use`,
|
|
127
|
-
initial:
|
|
92
|
+
initial: 0,
|
|
128
93
|
type: 'autocomplete',
|
|
129
94
|
choices: [
|
|
130
95
|
{ name: 'npm', message: 'NPM' },
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import yargs = require('yargs');
|
|
2
2
|
export declare function withNxCloud<T = unknown>(argv: yargs.Argv<T>): yargs.Argv<T & {
|
|
3
|
-
nxCloud:
|
|
4
|
-
}>;
|
|
5
|
-
export declare function withCI<T = unknown>(argv: yargs.Argv<T>): yargs.Argv<T & {
|
|
6
|
-
ci: string | undefined;
|
|
3
|
+
nxCloud: string | undefined;
|
|
7
4
|
}>;
|
|
8
5
|
export declare function withAllPrompts<T = unknown>(argv: yargs.Argv<T>): yargs.Argv<T & {
|
|
9
6
|
allPrompts: boolean;
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withOptions = exports.withGitOptions = exports.withPackageManager = exports.withAllPrompts = exports.
|
|
3
|
+
exports.withOptions = exports.withGitOptions = exports.withPackageManager = exports.withAllPrompts = exports.withNxCloud = void 0;
|
|
4
4
|
const chalk = require("chalk");
|
|
5
|
-
const ci_list_1 = require("../utils/ci/ci-list");
|
|
6
5
|
const ab_testing_1 = require("../utils/nx/ab-testing");
|
|
7
6
|
const package_manager_1 = require("../utils/package-manager");
|
|
8
7
|
function withNxCloud(argv) {
|
|
8
|
+
const { message } = ab_testing_1.messages.getPrompt('setupCI');
|
|
9
9
|
const result = argv.option('nxCloud', {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
alias: 'ci',
|
|
11
|
+
describe: chalk.dim(message),
|
|
12
|
+
choices: ab_testing_1.NxCloudChoices,
|
|
13
|
+
type: 'string',
|
|
12
14
|
});
|
|
13
15
|
return result;
|
|
14
16
|
}
|
|
15
17
|
exports.withNxCloud = withNxCloud;
|
|
16
|
-
function withCI(argv) {
|
|
17
|
-
return argv.option('ci', {
|
|
18
|
-
describe: chalk.dim `Generate a CI workflow file`,
|
|
19
|
-
choices: ci_list_1.ciList,
|
|
20
|
-
defaultDescription: '',
|
|
21
|
-
type: 'string',
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
exports.withCI = withCI;
|
|
25
18
|
function withAllPrompts(argv) {
|
|
26
19
|
return argv.option('allPrompts', {
|
|
27
20
|
alias: 'a',
|
|
@@ -1,17 +1,67 @@
|
|
|
1
|
+
export declare const NxCloudChoices: string[];
|
|
1
2
|
declare const messageOptions: {
|
|
2
|
-
readonly
|
|
3
|
-
readonly code: "
|
|
4
|
-
readonly message: "
|
|
3
|
+
readonly setupCI: readonly [{
|
|
4
|
+
readonly code: "enable-nx-cloud";
|
|
5
|
+
readonly message: "Do you want Nx Cloud to make your CI fast?";
|
|
6
|
+
readonly initial: 1;
|
|
7
|
+
readonly choices: readonly [{
|
|
8
|
+
readonly value: "yes";
|
|
9
|
+
readonly name: "Yes, enable Nx Cloud";
|
|
10
|
+
}, {
|
|
11
|
+
readonly value: "github";
|
|
12
|
+
readonly name: "Yes, configure Nx Cloud for GitHub Actions";
|
|
13
|
+
}, {
|
|
14
|
+
readonly value: "circleci";
|
|
15
|
+
readonly name: "Yes, configure Nx Cloud for Circle CI";
|
|
16
|
+
}, {
|
|
17
|
+
readonly value: "skip";
|
|
18
|
+
readonly name: "Skip for now";
|
|
19
|
+
}];
|
|
20
|
+
readonly footer: "\nRead more about remote cache at https://nx.dev/ci/features/remote-cache";
|
|
21
|
+
readonly hint: "\n(it's free and can be disabled any time)";
|
|
22
|
+
readonly fallback: undefined;
|
|
23
|
+
}, {
|
|
24
|
+
readonly code: "set-up-ci";
|
|
25
|
+
readonly message: "Set up CI with caching, distribution and test deflaking";
|
|
26
|
+
readonly initial: 0;
|
|
27
|
+
readonly choices: readonly [{
|
|
28
|
+
readonly value: "github";
|
|
29
|
+
readonly name: "Yes, for GitHub Actions with Nx Cloud";
|
|
30
|
+
}, {
|
|
31
|
+
readonly value: "circleci";
|
|
32
|
+
readonly name: "Yes, for CircleCI with Nx Cloud";
|
|
33
|
+
}, {
|
|
34
|
+
readonly value: "skip";
|
|
35
|
+
readonly name: "Skip for now";
|
|
36
|
+
}];
|
|
37
|
+
readonly footer: "\nRead more about CI benefits with Nx at https://nx.dev/ci/intro/ci-with-nx";
|
|
38
|
+
readonly hint: "\n(it's free and can be disabled any time)";
|
|
39
|
+
readonly fallback: {
|
|
40
|
+
readonly value: "skip";
|
|
41
|
+
readonly key: "setupNxCloud";
|
|
42
|
+
};
|
|
5
43
|
}];
|
|
6
|
-
readonly
|
|
7
|
-
readonly code: "
|
|
8
|
-
readonly message: "
|
|
44
|
+
readonly setupNxCloud: readonly [{
|
|
45
|
+
readonly code: "enable-caching";
|
|
46
|
+
readonly message: "Would you like remote caching to make your build faster?";
|
|
47
|
+
readonly initial: 0;
|
|
48
|
+
readonly choices: readonly [{
|
|
49
|
+
readonly value: "yes";
|
|
50
|
+
readonly name: "Yes";
|
|
51
|
+
}, {
|
|
52
|
+
readonly value: "skip";
|
|
53
|
+
readonly name: "Skip for now";
|
|
54
|
+
}];
|
|
55
|
+
readonly footer: "\nRead more about remote caching at https://nx.dev/ci/features/remote-cache";
|
|
56
|
+
readonly hint: "\n(it's free and can be disabled any time)";
|
|
57
|
+
readonly fallback: undefined;
|
|
9
58
|
}];
|
|
10
59
|
};
|
|
11
|
-
type MessageKey = keyof typeof messageOptions;
|
|
60
|
+
export type MessageKey = keyof typeof messageOptions;
|
|
61
|
+
type MessageData = typeof messageOptions[MessageKey][number];
|
|
12
62
|
export declare class PromptMessages {
|
|
13
63
|
private selectedMessages;
|
|
14
|
-
|
|
64
|
+
getPrompt(key: MessageKey): MessageData;
|
|
15
65
|
codeOfSelectedPromptMessage(key: MessageKey): string;
|
|
16
66
|
}
|
|
17
67
|
export declare const messages: PromptMessages;
|
|
@@ -23,6 +73,6 @@ export declare function recordStat(opts: {
|
|
|
23
73
|
command: string;
|
|
24
74
|
nxVersion: string;
|
|
25
75
|
useCloud: boolean;
|
|
26
|
-
meta: string;
|
|
76
|
+
meta: string[];
|
|
27
77
|
}): Promise<void>;
|
|
28
78
|
export {};
|
|
@@ -1,18 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recordStat = exports.messages = exports.PromptMessages = void 0;
|
|
3
|
+
exports.recordStat = exports.messages = exports.PromptMessages = exports.NxCloudChoices = void 0;
|
|
4
4
|
const is_ci_1 = require("../ci/is-ci");
|
|
5
|
+
exports.NxCloudChoices = ['yes', 'github', 'circleci', 'skip'];
|
|
5
6
|
const messageOptions = {
|
|
6
|
-
|
|
7
|
+
setupCI: [
|
|
7
8
|
{
|
|
8
|
-
code: '
|
|
9
|
-
message: `
|
|
9
|
+
code: 'enable-nx-cloud',
|
|
10
|
+
message: `Do you want Nx Cloud to make your CI fast?`,
|
|
11
|
+
initial: 1,
|
|
12
|
+
choices: [
|
|
13
|
+
{ value: 'yes', name: 'Yes, enable Nx Cloud' },
|
|
14
|
+
{ value: 'github', name: 'Yes, configure Nx Cloud for GitHub Actions' },
|
|
15
|
+
{ value: 'circleci', name: 'Yes, configure Nx Cloud for Circle CI' },
|
|
16
|
+
{ value: 'skip', name: 'Skip for now' },
|
|
17
|
+
],
|
|
18
|
+
footer: '\nRead more about remote cache at https://nx.dev/ci/features/remote-cache',
|
|
19
|
+
hint: `\n(it's free and can be disabled any time)`,
|
|
20
|
+
fallback: undefined,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
code: 'set-up-ci',
|
|
24
|
+
message: `Set up CI with caching, distribution and test deflaking`,
|
|
25
|
+
initial: 0,
|
|
26
|
+
choices: [
|
|
27
|
+
{ value: 'github', name: 'Yes, for GitHub Actions with Nx Cloud' },
|
|
28
|
+
{ value: 'circleci', name: 'Yes, for CircleCI with Nx Cloud' },
|
|
29
|
+
{ value: 'skip', name: 'Skip for now' },
|
|
30
|
+
],
|
|
31
|
+
footer: '\nRead more about CI benefits with Nx at https://nx.dev/ci/intro/ci-with-nx',
|
|
32
|
+
hint: `\n(it's free and can be disabled any time)`,
|
|
33
|
+
fallback: { value: 'skip', key: 'setupNxCloud' },
|
|
10
34
|
},
|
|
11
35
|
],
|
|
12
|
-
|
|
36
|
+
setupNxCloud: [
|
|
13
37
|
{
|
|
14
|
-
code: '
|
|
15
|
-
message: `
|
|
38
|
+
code: 'enable-caching',
|
|
39
|
+
message: `Would you like remote caching to make your build faster?`,
|
|
40
|
+
initial: 0,
|
|
41
|
+
choices: [
|
|
42
|
+
{ value: 'yes', name: 'Yes' },
|
|
43
|
+
{ value: 'skip', name: 'Skip for now' },
|
|
44
|
+
],
|
|
45
|
+
footer: '\nRead more about remote caching at https://nx.dev/ci/features/remote-cache',
|
|
46
|
+
hint: `\n(it's free and can be disabled any time)`,
|
|
47
|
+
fallback: undefined,
|
|
16
48
|
},
|
|
17
49
|
],
|
|
18
50
|
};
|
|
@@ -20,7 +52,7 @@ class PromptMessages {
|
|
|
20
52
|
constructor() {
|
|
21
53
|
this.selectedMessages = {};
|
|
22
54
|
}
|
|
23
|
-
|
|
55
|
+
getPrompt(key) {
|
|
24
56
|
if (this.selectedMessages[key] === undefined) {
|
|
25
57
|
if (process.env.NX_GENERATE_DOCS_PROCESS === 'true') {
|
|
26
58
|
this.selectedMessages[key] = 0;
|
|
@@ -29,12 +61,12 @@ class PromptMessages {
|
|
|
29
61
|
this.selectedMessages[key] = Math.floor(Math.random() * messageOptions[key].length);
|
|
30
62
|
}
|
|
31
63
|
}
|
|
32
|
-
return messageOptions[key][this.selectedMessages[key]]
|
|
64
|
+
return messageOptions[key][this.selectedMessages[key]];
|
|
33
65
|
}
|
|
34
66
|
codeOfSelectedPromptMessage(key) {
|
|
35
67
|
const selected = this.selectedMessages[key];
|
|
36
68
|
if (selected === undefined) {
|
|
37
|
-
return
|
|
69
|
+
return '';
|
|
38
70
|
}
|
|
39
71
|
else {
|
|
40
72
|
return messageOptions[key][selected].code;
|
|
@@ -65,7 +97,7 @@ async function recordStat(opts) {
|
|
|
65
97
|
command: opts.command,
|
|
66
98
|
isCI: (0, is_ci_1.isCI)(),
|
|
67
99
|
useCloud: opts.useCloud,
|
|
68
|
-
meta: opts.meta,
|
|
100
|
+
meta: opts.meta.filter((v) => !!v).join(','),
|
|
69
101
|
});
|
|
70
102
|
}
|
|
71
103
|
catch (e) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PackageManager } from '../package-manager';
|
|
2
|
-
export
|
|
2
|
+
export type NxCloud = 'yes' | 'github' | 'circleci' | 'skip';
|
|
3
|
+
export declare function setupNxCloud(directory: string, packageManager: PackageManager, nxCloud: NxCloud): Promise<{
|
|
3
4
|
code: number;
|
|
4
5
|
stdout: string;
|
|
5
6
|
}>;
|
package/src/utils/nx/nx-cloud.js
CHANGED
|
@@ -6,19 +6,24 @@ const child_process_utils_1 = require("../child-process-utils");
|
|
|
6
6
|
const output_1 = require("../output");
|
|
7
7
|
const package_manager_1 = require("../package-manager");
|
|
8
8
|
const error_utils_1 = require("../error-utils");
|
|
9
|
-
async function setupNxCloud(directory, packageManager) {
|
|
10
|
-
const nxCloudSpinner = ora(`Setting up
|
|
9
|
+
async function setupNxCloud(directory, packageManager, nxCloud) {
|
|
10
|
+
const nxCloudSpinner = ora(`Setting up Nx Cloud`).start();
|
|
11
11
|
try {
|
|
12
12
|
const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
|
|
13
13
|
const res = await (0, child_process_utils_1.execAndWait)(`${pmc.exec} nx g nx:connect-to-nx-cloud --no-interactive --quiet`, directory);
|
|
14
|
-
|
|
14
|
+
if (nxCloud !== 'yes') {
|
|
15
|
+
nxCloudSpinner.succeed('CI workflow with Nx Cloud has been generated successfully');
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
nxCloudSpinner.succeed('Nx Cloud has been set up successfully');
|
|
19
|
+
}
|
|
15
20
|
return res;
|
|
16
21
|
}
|
|
17
22
|
catch (e) {
|
|
18
23
|
nxCloudSpinner.fail();
|
|
19
24
|
if (e instanceof Error) {
|
|
20
25
|
output_1.output.error({
|
|
21
|
-
title: `Failed to setup
|
|
26
|
+
title: `Failed to setup Nx Cloud`,
|
|
22
27
|
bodyLines: (0, error_utils_1.mapErrorToBodyLines)(e),
|
|
23
28
|
});
|
|
24
29
|
}
|
|
@@ -33,12 +38,19 @@ async function setupNxCloud(directory, packageManager) {
|
|
|
33
38
|
}
|
|
34
39
|
exports.setupNxCloud = setupNxCloud;
|
|
35
40
|
function printNxCloudSuccessMessage(nxCloudOut) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
// remove leading Nx carret and any new lines
|
|
42
|
+
const logContent = nxCloudOut.split('NX ')[1];
|
|
43
|
+
const indexOfTitleEnd = logContent.indexOf('\n');
|
|
44
|
+
const title = logContent.slice(0, logContent.indexOf('\n')).trim();
|
|
45
|
+
const bodyLines = logContent
|
|
46
|
+
.slice(indexOfTitleEnd)
|
|
47
|
+
.replace(/^\n*/, '') // remove leading new lines
|
|
48
|
+
.replace(/\n*$/, '') // remove trailing new lines
|
|
49
|
+
.split('\n')
|
|
50
|
+
.map((r) => r.trim());
|
|
51
|
+
output_1.output.warn({
|
|
52
|
+
title,
|
|
53
|
+
bodyLines,
|
|
42
54
|
});
|
|
43
55
|
}
|
|
44
56
|
exports.printNxCloudSuccessMessage = printNxCloudSuccessMessage;
|
|
@@ -4,6 +4,7 @@ exports.showNxWarning = void 0;
|
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const output_1 = require("../output");
|
|
7
|
+
const package_manager_1 = require("../package-manager");
|
|
7
8
|
function showNxWarning(workspaceName) {
|
|
8
9
|
try {
|
|
9
10
|
const pathToRunNxCommand = (0, path_1.resolve)(process.cwd(), workspaceName);
|
|
@@ -14,12 +15,13 @@ function showNxWarning(workspaceName) {
|
|
|
14
15
|
}
|
|
15
16
|
catch (e) {
|
|
16
17
|
// no nx found
|
|
18
|
+
const { exec, globalAdd } = (0, package_manager_1.getPackageManagerCommand)();
|
|
17
19
|
output_1.output.addVerticalSeparator();
|
|
18
20
|
output_1.output.note({
|
|
19
21
|
title: `Nx CLI is not installed globally.`,
|
|
20
22
|
bodyLines: [
|
|
21
|
-
`This means that you
|
|
22
|
-
`Run "
|
|
23
|
+
`This means that you will have to use "${exec} nx" to execute commands in the workspace.`,
|
|
24
|
+
`Run "${globalAdd} nx" to be able to execute command directly.`,
|
|
23
25
|
],
|
|
24
26
|
});
|
|
25
27
|
}
|
package/src/utils/output.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export interface CLISuccessMessageConfig {
|
|
|
16
16
|
bodyLines?: string[];
|
|
17
17
|
}
|
|
18
18
|
declare class CLIOutput {
|
|
19
|
-
readonly X_PADDING = " ";
|
|
20
19
|
/**
|
|
21
20
|
* Longer dash character which forms more of a continuous line when place side to side
|
|
22
21
|
* with itself, unlike the standard dash character
|
package/src/utils/output.js
CHANGED
|
@@ -16,7 +16,6 @@ if ((0, is_ci_1.isCI)()) {
|
|
|
16
16
|
}
|
|
17
17
|
class CLIOutput {
|
|
18
18
|
constructor() {
|
|
19
|
-
this.X_PADDING = ' ';
|
|
20
19
|
/**
|
|
21
20
|
* Expose some color and other utility functions so that other parts of the codebase that need
|
|
22
21
|
* more fine-grained control of message bodies are still using a centralized
|
|
@@ -40,7 +39,7 @@ class CLIOutput {
|
|
|
40
39
|
*/
|
|
41
40
|
get VERTICAL_SEPARATOR() {
|
|
42
41
|
let divider = '';
|
|
43
|
-
for (let i = 0; i < process.stdout.columns -
|
|
42
|
+
for (let i = 0; i < process.stdout.columns - 1; i++) {
|
|
44
43
|
divider += '\u2014';
|
|
45
44
|
}
|
|
46
45
|
return divider;
|
|
@@ -49,14 +48,14 @@ class CLIOutput {
|
|
|
49
48
|
process.stdout.write(str);
|
|
50
49
|
}
|
|
51
50
|
writeOutputTitle({ color, title, }) {
|
|
52
|
-
this.writeToStdOut(
|
|
51
|
+
this.writeToStdOut(`${this.applyCLIPrefix(color, title)}${os_1.EOL}`);
|
|
53
52
|
}
|
|
54
53
|
writeOptionalOutputBody(bodyLines) {
|
|
55
54
|
if (!bodyLines) {
|
|
56
55
|
return;
|
|
57
56
|
}
|
|
58
57
|
this.addNewline();
|
|
59
|
-
bodyLines.forEach((bodyLine) => this.writeToStdOut(
|
|
58
|
+
bodyLines.forEach((bodyLine) => this.writeToStdOut(`${bodyLine}${os_1.EOL}`));
|
|
60
59
|
}
|
|
61
60
|
setCliName(name) {
|
|
62
61
|
this.cliName = name;
|
|
@@ -64,10 +63,10 @@ class CLIOutput {
|
|
|
64
63
|
applyCLIPrefix(color = 'cyan', text) {
|
|
65
64
|
let cliPrefix = '';
|
|
66
65
|
if (chalk[color]) {
|
|
67
|
-
cliPrefix =
|
|
66
|
+
cliPrefix = chalk.reset.inverse.bold[color](` ${this.cliName} `);
|
|
68
67
|
}
|
|
69
68
|
else {
|
|
70
|
-
cliPrefix =
|
|
69
|
+
cliPrefix = chalk.reset.inverse.bold.keyword(color)(` ${this.cliName} `);
|
|
71
70
|
}
|
|
72
71
|
return `${cliPrefix} ${text}`;
|
|
73
72
|
}
|
|
@@ -80,7 +79,7 @@ class CLIOutput {
|
|
|
80
79
|
this.addNewline();
|
|
81
80
|
}
|
|
82
81
|
addVerticalSeparatorWithoutNewLines(color = 'gray') {
|
|
83
|
-
this.writeToStdOut(`${
|
|
82
|
+
this.writeToStdOut(`${chalk.dim[color](this.VERTICAL_SEPARATOR)}${os_1.EOL}`);
|
|
84
83
|
}
|
|
85
84
|
error({ title, bodyLines }) {
|
|
86
85
|
this.addNewline();
|
|
@@ -17,6 +17,7 @@ export declare function getPackageManagerCommand(packageManager?: PackageManager
|
|
|
17
17
|
install: string;
|
|
18
18
|
exec: string;
|
|
19
19
|
preInstall?: string;
|
|
20
|
+
globalAdd: string;
|
|
20
21
|
};
|
|
21
22
|
export declare function generatePackageManagerFiles(root: string, packageManager?: PackageManager): void;
|
|
22
23
|
export declare function getPackageManagerVersion(packageManager: PackageManager, cwd?: string): string;
|
|
@@ -43,6 +43,7 @@ function getPackageManagerCommand(packageManager = detectPackageManager()) {
|
|
|
43
43
|
: `${installCommand} --ignore-scripts`,
|
|
44
44
|
// using npx is necessary to avoid yarn classic manipulating the version detection when using berry
|
|
45
45
|
exec: useBerry ? 'npx' : 'yarn',
|
|
46
|
+
globalAdd: 'yarn global add',
|
|
46
47
|
};
|
|
47
48
|
case 'pnpm':
|
|
48
49
|
let useExec = false;
|
|
@@ -52,11 +53,13 @@ function getPackageManagerCommand(packageManager = detectPackageManager()) {
|
|
|
52
53
|
return {
|
|
53
54
|
install: 'pnpm install --no-frozen-lockfile --silent --ignore-scripts',
|
|
54
55
|
exec: useExec ? 'pnpm exec' : 'pnpx',
|
|
56
|
+
globalAdd: 'pnpm add -g',
|
|
55
57
|
};
|
|
56
58
|
case 'npm':
|
|
57
59
|
return {
|
|
58
60
|
install: 'npm install --silent --ignore-scripts',
|
|
59
61
|
exec: 'npx',
|
|
62
|
+
globalAdd: 'npm i -g',
|
|
60
63
|
};
|
|
61
64
|
}
|
|
62
65
|
}
|
|
@@ -12,7 +12,7 @@ function pointToTutorialAndCourse(preset) {
|
|
|
12
12
|
output_1.output.note({
|
|
13
13
|
title,
|
|
14
14
|
bodyLines: [
|
|
15
|
-
`https://nx.dev/getting-started/tutorials/
|
|
15
|
+
`https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial`,
|
|
16
16
|
],
|
|
17
17
|
});
|
|
18
18
|
break;
|
|
@@ -23,6 +23,10 @@ exports.presetOptions = [
|
|
|
23
23
|
name: preset_1.Preset.VueMonorepo,
|
|
24
24
|
message: 'vue [a monorepo with a single Vue application]',
|
|
25
25
|
},
|
|
26
|
+
{
|
|
27
|
+
name: preset_1.Preset.Nuxt,
|
|
28
|
+
message: 'nuxt [a monorepo with a single Nuxt application]',
|
|
29
|
+
},
|
|
26
30
|
{
|
|
27
31
|
name: preset_1.Preset.NextJs,
|
|
28
32
|
message: 'next.js [a monorepo with a single Next.js application]',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare enum Preset {
|
|
2
2
|
Apps = "apps",
|
|
3
|
-
Empty = "empty",
|
|
4
|
-
Core = "core",
|
|
3
|
+
Empty = "empty",// same as apps, deprecated
|
|
4
|
+
Core = "core",// same as npm, deprecated
|
|
5
5
|
NPM = "npm",
|
|
6
6
|
TS = "ts",
|
|
7
7
|
WebComponents = "web-components",
|
|
@@ -11,13 +11,18 @@ export declare enum Preset {
|
|
|
11
11
|
ReactStandalone = "react-standalone",
|
|
12
12
|
VueMonorepo = "vue-monorepo",
|
|
13
13
|
VueStandalone = "vue-standalone",
|
|
14
|
+
Nuxt = "nuxt",
|
|
15
|
+
NuxtStandalone = "nuxt-standalone",
|
|
14
16
|
NextJs = "next",
|
|
15
17
|
NextJsStandalone = "nextjs-standalone",
|
|
18
|
+
RemixMonorepo = "remix-monorepo",
|
|
19
|
+
RemixStandalone = "remix-standalone",
|
|
16
20
|
ReactNative = "react-native",
|
|
17
21
|
Expo = "expo",
|
|
18
22
|
Nest = "nest",
|
|
19
23
|
Express = "express",
|
|
20
24
|
React = "react",
|
|
25
|
+
Vue = "vue",
|
|
21
26
|
Angular = "angular",
|
|
22
27
|
NodeStandalone = "node-standalone",
|
|
23
28
|
NodeMonorepo = "node-monorepo",
|
|
@@ -15,13 +15,18 @@ var Preset;
|
|
|
15
15
|
Preset["ReactStandalone"] = "react-standalone";
|
|
16
16
|
Preset["VueMonorepo"] = "vue-monorepo";
|
|
17
17
|
Preset["VueStandalone"] = "vue-standalone";
|
|
18
|
+
Preset["Nuxt"] = "nuxt";
|
|
19
|
+
Preset["NuxtStandalone"] = "nuxt-standalone";
|
|
18
20
|
Preset["NextJs"] = "next";
|
|
19
21
|
Preset["NextJsStandalone"] = "nextjs-standalone";
|
|
22
|
+
Preset["RemixMonorepo"] = "remix-monorepo";
|
|
23
|
+
Preset["RemixStandalone"] = "remix-standalone";
|
|
20
24
|
Preset["ReactNative"] = "react-native";
|
|
21
25
|
Preset["Expo"] = "expo";
|
|
22
26
|
Preset["Nest"] = "nest";
|
|
23
27
|
Preset["Express"] = "express";
|
|
24
28
|
Preset["React"] = "react";
|
|
29
|
+
Preset["Vue"] = "vue";
|
|
25
30
|
Preset["Angular"] = "angular";
|
|
26
31
|
Preset["NodeStandalone"] = "node-standalone";
|
|
27
32
|
Preset["NodeMonorepo"] = "node-monorepo";
|