create-nx-workspace 23.2.0-beta.1 → 23.2.0-beta.10
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/dist/bin/create-nx-workspace.d.ts +13 -4
- package/dist/bin/create-nx-workspace.js +384 -553
- package/dist/internal.d.ts +3 -1
- package/dist/internal.js +7 -1
- package/dist/src/create-workspace.js +75 -4
- package/dist/src/internal-utils/prompt-helpers.d.ts +57 -0
- package/dist/src/internal-utils/prompt-helpers.js +105 -0
- package/dist/src/internal-utils/prompts.d.ts +16 -0
- package/dist/src/internal-utils/prompts.js +145 -117
- package/dist/src/utils/ai/ai-output.js +9 -4
- package/dist/src/utils/error-utils.d.ts +1 -1
- package/dist/src/utils/exit-codes.d.ts +12 -0
- package/dist/src/utils/exit-codes.js +24 -0
- package/dist/src/utils/git/git.js +29 -30
- package/dist/src/utils/nx/ab-testing.d.ts +0 -1
- package/dist/src/utils/nx/ab-testing.js +4 -2
- package/dist/src/utils/template/download-template.js +10 -3
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FORMATTERS = exports.LINTERS = void 0;
|
|
3
4
|
exports.determineNxCloud = determineNxCloud;
|
|
4
5
|
exports.determineNxCloudV2 = determineNxCloudV2;
|
|
5
6
|
exports.determineIfGitHubWillBeUsed = determineIfGitHubWillBeUsed;
|
|
@@ -9,8 +10,9 @@ exports.determineAnalytics = determineAnalytics;
|
|
|
9
10
|
exports.determineDefaultBase = determineDefaultBase;
|
|
10
11
|
exports.confirmThirdPartyPreset = confirmThirdPartyPreset;
|
|
11
12
|
exports.determinePackageManager = determinePackageManager;
|
|
13
|
+
exports.determineLinterOptions = determineLinterOptions;
|
|
14
|
+
exports.determineFormatterOptions = determineFormatterOptions;
|
|
12
15
|
const tslib_1 = require("tslib");
|
|
13
|
-
const enquirer_1 = tslib_1.__importDefault(require("enquirer"));
|
|
14
16
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
15
17
|
const ab_testing_1 = require("../utils/nx/ab-testing");
|
|
16
18
|
const default_base_1 = require("../utils/git/default-base");
|
|
@@ -21,6 +23,7 @@ const create_workspace_options_1 = require("../create-workspace-options");
|
|
|
21
23
|
const ai_output_1 = require("../utils/ai/ai-output");
|
|
22
24
|
const error_utils_1 = require("../utils/error-utils");
|
|
23
25
|
const output_1 = require("../utils/output");
|
|
26
|
+
const prompt_helpers_1 = require("./prompt-helpers");
|
|
24
27
|
async function determineNxCloud(parsedArgs) {
|
|
25
28
|
if (parsedArgs.nxCloud) {
|
|
26
29
|
return parsedArgs.nxCloud;
|
|
@@ -56,40 +59,30 @@ async function determineIfGitHubWillBeUsed(parsedArgs) {
|
|
|
56
59
|
if (parsedArgs.nxCloud === 'yes' || parsedArgs.nxCloud === 'circleci') {
|
|
57
60
|
if (parsedArgs?.useGitHub)
|
|
58
61
|
return true;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
message: 'Will you be using GitHub as your git hosting provider?',
|
|
63
|
-
type: 'autocomplete',
|
|
64
|
-
choices: [{ name: 'Yes' }, { name: 'No' }],
|
|
65
|
-
initial: 0,
|
|
66
|
-
},
|
|
67
|
-
]);
|
|
68
|
-
return reply.github === 'Yes';
|
|
62
|
+
return (0, prompt_helpers_1.confirmationPrompt)({
|
|
63
|
+
message: 'Will you be using GitHub as your git hosting provider?',
|
|
64
|
+
});
|
|
69
65
|
}
|
|
70
66
|
return false;
|
|
71
67
|
}
|
|
72
68
|
async function nxCloudPrompt(key) {
|
|
73
|
-
const { message, choices, initial, fallback, footer
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
69
|
+
const { message, choices, initial, fallback, footer } = ab_testing_1.messages.getPrompt(key);
|
|
70
|
+
// These choices are `{ value, name }` with `name` as the display text — the
|
|
71
|
+
// inverse of enquirer's usual `{ name, message }`. Take `value` so the answer
|
|
72
|
+
// is the key the caller compares against, not the label.
|
|
73
|
+
const options = choices.map((c) => typeof c === 'string'
|
|
74
|
+
? { value: c }
|
|
75
|
+
: { value: c.value ?? c.name, label: c.message ?? c.name ?? c.value });
|
|
76
|
+
const answer = (await (0, prompt_helpers_1.selectPrompt)({
|
|
77
|
+
// No separate footer slot, so it is folded into the message.
|
|
78
|
+
message: `${message}\n${chalk_1.default.dim(footer)}`,
|
|
79
|
+
choices: options,
|
|
80
|
+
initial: options[initial ?? 0]?.value,
|
|
81
|
+
}));
|
|
82
|
+
if (fallback && answer === fallback.value) {
|
|
83
|
+
return nxCloudPrompt(fallback.key);
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
promptConfig.hint = () => chalk_1.default.dim(hint);
|
|
86
|
-
}
|
|
87
|
-
return enquirer_1.default.prompt([promptConfig]).then((a) => {
|
|
88
|
-
if (fallback && a.NxCloud === fallback.value) {
|
|
89
|
-
return nxCloudPrompt(fallback.key);
|
|
90
|
-
}
|
|
91
|
-
return a.NxCloud;
|
|
92
|
-
});
|
|
85
|
+
return answer;
|
|
93
86
|
}
|
|
94
87
|
async function determineTemplate(parsedArgs) {
|
|
95
88
|
if (parsedArgs.template)
|
|
@@ -101,37 +94,32 @@ async function determineTemplate(parsedArgs) {
|
|
|
101
94
|
// Docs generation needs preset flow to document all presets
|
|
102
95
|
if (process.env.NX_GENERATE_DOCS_PROCESS === 'true')
|
|
103
96
|
return 'custom';
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
],
|
|
131
|
-
initial: 0,
|
|
132
|
-
},
|
|
133
|
-
]);
|
|
134
|
-
return template;
|
|
97
|
+
return (0, prompt_helpers_1.selectPrompt)({
|
|
98
|
+
message: 'Which starter do you want to use?',
|
|
99
|
+
choices: [
|
|
100
|
+
{
|
|
101
|
+
value: 'nrwl/empty-template',
|
|
102
|
+
label: 'Minimal (empty monorepo without projects)',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
value: 'nrwl/react-template',
|
|
106
|
+
label: 'React (fullstack monorepo with React and Express)',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
value: 'nrwl/angular-template',
|
|
110
|
+
label: 'Angular (fullstack monorepo with Angular and Express)',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
value: 'nrwl/typescript-template',
|
|
114
|
+
label: 'NPM Packages (monorepo with TypeScript packages ready to publish)',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
value: 'custom',
|
|
118
|
+
label: 'Custom (advanced setup with additional frameworks)',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
initial: 'nrwl/empty-template',
|
|
122
|
+
});
|
|
135
123
|
}
|
|
136
124
|
async function determineAiAgents(parsedArgs) {
|
|
137
125
|
if (parsedArgs.aiAgents) {
|
|
@@ -148,17 +136,14 @@ async function determineAiAgents(parsedArgs) {
|
|
|
148
136
|
return [];
|
|
149
137
|
}
|
|
150
138
|
async function aiAgentsPrompt() {
|
|
151
|
-
|
|
152
|
-
name: 'agents',
|
|
139
|
+
return (0, prompt_helpers_1.multiselectPrompt)({
|
|
153
140
|
message: 'Which AI agents, if any, would you like to set up?',
|
|
154
|
-
type: 'multiselect',
|
|
155
141
|
choices: create_workspace_options_1.supportedAgents.map((a) => ({
|
|
156
|
-
|
|
157
|
-
|
|
142
|
+
value: a,
|
|
143
|
+
label: create_workspace_options_1.agentDisplayMap[a],
|
|
158
144
|
})),
|
|
159
|
-
|
|
160
|
-
};
|
|
161
|
-
return (await enquirer_1.default.prompt([promptConfig])).agents;
|
|
145
|
+
required: false,
|
|
146
|
+
});
|
|
162
147
|
}
|
|
163
148
|
async function determineAnalytics(parsedArgs) {
|
|
164
149
|
if (typeof parsedArgs.analytics === 'boolean') {
|
|
@@ -168,15 +153,14 @@ async function determineAnalytics(parsedArgs) {
|
|
|
168
153
|
// Not asked in non-interactive/CI.
|
|
169
154
|
return 'unset';
|
|
170
155
|
}
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
]);
|
|
156
|
+
const enableAnalytics = await (0, prompt_helpers_1.selectPrompt)({
|
|
157
|
+
message: 'Help improve Nx by sharing your usage data?',
|
|
158
|
+
choices: [
|
|
159
|
+
{ value: 'Yes', label: 'Yes' },
|
|
160
|
+
{ value: 'No', label: 'No' },
|
|
161
|
+
],
|
|
162
|
+
initial: 'Yes',
|
|
163
|
+
});
|
|
180
164
|
return enableAnalytics === 'Yes' ? 'yes' : 'no';
|
|
181
165
|
}
|
|
182
166
|
async function determineDefaultBase(parsedArgs) {
|
|
@@ -184,21 +168,17 @@ async function determineDefaultBase(parsedArgs) {
|
|
|
184
168
|
return parsedArgs.defaultBase;
|
|
185
169
|
}
|
|
186
170
|
else if (parsedArgs.allPrompts) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
type: 'input',
|
|
194
|
-
},
|
|
195
|
-
])
|
|
196
|
-
.then((a) => {
|
|
197
|
-
if (!a.DefaultBase) {
|
|
198
|
-
throw new error_utils_1.CnwError('INVALID_BRANCH_NAME', 'Branch name cannot be empty');
|
|
199
|
-
}
|
|
200
|
-
return a.DefaultBase;
|
|
171
|
+
const defaultBase = await (0, prompt_helpers_1.textPrompt)({
|
|
172
|
+
message: `Main branch name`,
|
|
173
|
+
initialValue: `main`,
|
|
174
|
+
// Reject here so clearing the field re-prompts rather than aborting the
|
|
175
|
+
// run on the throw below.
|
|
176
|
+
validate: (value) => value.trim() ? undefined : 'Branch name cannot be empty',
|
|
201
177
|
});
|
|
178
|
+
if (!defaultBase) {
|
|
179
|
+
throw new error_utils_1.CnwError('INVALID_BRANCH_NAME', 'Branch name cannot be empty');
|
|
180
|
+
}
|
|
181
|
+
return defaultBase;
|
|
202
182
|
}
|
|
203
183
|
return (0, default_base_1.deduceDefaultBase)();
|
|
204
184
|
}
|
|
@@ -230,15 +210,14 @@ async function confirmThirdPartyPreset(packageName, interactive, trusted) {
|
|
|
230
210
|
if (interactive === false || (0, is_ci_1.isCI)() || (0, ai_output_1.isAiAgent)()) {
|
|
231
211
|
return true;
|
|
232
212
|
}
|
|
233
|
-
const
|
|
234
|
-
{
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
]);
|
|
213
|
+
const confirm = await (0, prompt_helpers_1.selectPrompt)({
|
|
214
|
+
message: `Install third-party preset '${packageName}'?`,
|
|
215
|
+
choices: [
|
|
216
|
+
{ value: 'No', label: 'No' },
|
|
217
|
+
{ value: 'Yes', label: 'Yes' },
|
|
218
|
+
],
|
|
219
|
+
initial: 'No',
|
|
220
|
+
});
|
|
242
221
|
return confirm === 'Yes';
|
|
243
222
|
}
|
|
244
223
|
async function determinePackageManager(parsedArgs) {
|
|
@@ -252,22 +231,71 @@ async function determinePackageManager(parsedArgs) {
|
|
|
252
231
|
])}`);
|
|
253
232
|
}
|
|
254
233
|
else if (parsedArgs.allPrompts) {
|
|
255
|
-
return
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
{ name: 'pnpm', message: 'PNPM' },
|
|
266
|
-
{ name: 'bun', message: 'Bun' },
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
])
|
|
270
|
-
.then((a) => a.packageManager);
|
|
234
|
+
return (0, prompt_helpers_1.selectPrompt)({
|
|
235
|
+
message: `Which package manager to use`,
|
|
236
|
+
choices: [
|
|
237
|
+
{ value: 'npm', label: 'NPM' },
|
|
238
|
+
{ value: 'yarn', label: 'Yarn' },
|
|
239
|
+
{ value: 'pnpm', label: 'PNPM' },
|
|
240
|
+
{ value: 'bun', label: 'Bun' },
|
|
241
|
+
],
|
|
242
|
+
initial: 'npm',
|
|
243
|
+
});
|
|
271
244
|
}
|
|
272
245
|
return (0, package_manager_1.detectInvokedPackageManager)();
|
|
273
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Mirrors `LinterType` in `@nx/js`, which this package cannot depend on.
|
|
249
|
+
* One array so the type and the yargs `choices` gate cannot drift apart.
|
|
250
|
+
*/
|
|
251
|
+
exports.LINTERS = ['eslint', 'oxlint', 'none'];
|
|
252
|
+
async function determineLinterOptions(args) {
|
|
253
|
+
if (args.linter)
|
|
254
|
+
return args.linter;
|
|
255
|
+
// ESLint is the non-interactive default; changing it means changing this
|
|
256
|
+
// line, not the option order.
|
|
257
|
+
if (!args.interactive || (0, is_ci_1.isCI)())
|
|
258
|
+
return 'eslint';
|
|
259
|
+
return (0, prompt_helpers_1.selectPrompt)({
|
|
260
|
+
message: `Which linter would you like to use?`,
|
|
261
|
+
// `value` is what's returned; `label` is what the list shows. Oxlint is
|
|
262
|
+
// labelled so it isn't presented as an equal of ESLint while the docs and
|
|
263
|
+
// the package both call it experimental.
|
|
264
|
+
choices: [
|
|
265
|
+
{ value: 'eslint', label: 'eslint' },
|
|
266
|
+
{ value: 'oxlint', label: 'oxlint (experimental)' },
|
|
267
|
+
{ value: 'none', label: 'none' },
|
|
268
|
+
],
|
|
269
|
+
initial: 'eslint',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
// Order here is incidental; the prompt's own choice order sets the default. `satisfies` stops a typo
|
|
273
|
+
// getting in, and the coverage assertion below stops a member being dropped -
|
|
274
|
+
// on its own the array would happily be a subset, and the prompt would then
|
|
275
|
+
// reject a value the generator schemas still accept.
|
|
276
|
+
exports.FORMATTERS = [
|
|
277
|
+
'oxfmt',
|
|
278
|
+
'prettier',
|
|
279
|
+
'none',
|
|
280
|
+
];
|
|
281
|
+
const _formattersAreExhaustive = true;
|
|
282
|
+
async function determineFormatterOptions(args) {
|
|
283
|
+
if (args.formatter)
|
|
284
|
+
return args.formatter;
|
|
285
|
+
// Prettier is the non-interactive default; changing it means changing this
|
|
286
|
+
// line, not the option order.
|
|
287
|
+
if (!args.interactive || (0, is_ci_1.isCI)())
|
|
288
|
+
return 'prettier';
|
|
289
|
+
return (0, prompt_helpers_1.selectPrompt)({
|
|
290
|
+
message: `Which code formatter would you like to use?`,
|
|
291
|
+
// `value` is what's returned; `label` is what the list shows. oxfmt is
|
|
292
|
+
// labelled so it isn't presented as an equal of Prettier while it is
|
|
293
|
+
// pre-1.0.
|
|
294
|
+
choices: [
|
|
295
|
+
{ value: 'prettier', label: 'prettier' },
|
|
296
|
+
{ value: 'oxfmt', label: 'oxfmt (experimental)' },
|
|
297
|
+
{ value: 'none', label: 'none' },
|
|
298
|
+
],
|
|
299
|
+
initial: 'prettier',
|
|
300
|
+
});
|
|
301
|
+
}
|
|
@@ -113,7 +113,7 @@ function buildTemplateRequiredResult(workspaceName) {
|
|
|
113
113
|
stage: 'needs_input',
|
|
114
114
|
success: false,
|
|
115
115
|
title: 'Template Selection Required',
|
|
116
|
-
message: 'Ask the user which workspace type they want, then run again with --template. If the directory exists, append a number (e.g., my-nx-repo-2).',
|
|
116
|
+
message: 'Ask the user which workspace type they want, then run again with --template. If the directory exists, append a number (e.g., my-nx-repo-2). If this environment cannot reach github.com, run with --preset=empty instead of --template to create a minimal workspace without downloading a template.',
|
|
117
117
|
suggestedName: name,
|
|
118
118
|
templates: [
|
|
119
119
|
{
|
|
@@ -227,9 +227,14 @@ function getErrorHints(errorCode) {
|
|
|
227
227
|
];
|
|
228
228
|
case 'NETWORK_ERROR':
|
|
229
229
|
return [
|
|
230
|
-
'
|
|
231
|
-
'
|
|
232
|
-
'
|
|
230
|
+
'Templates download from github.com, which may be blocked or unreachable in this environment',
|
|
231
|
+
'Check your network and sandbox configuration (allow https://github.com) and try again',
|
|
232
|
+
'Or re-run with --preset=empty (instead of --template) to create a minimal workspace without downloading a template, then build on top of it',
|
|
233
|
+
];
|
|
234
|
+
case 'TEMPLATE_CLONE_FAILED':
|
|
235
|
+
return [
|
|
236
|
+
'Check the template name (e.g. nrwl/empty-template)',
|
|
237
|
+
'If github.com is restricted in this environment, re-run with --preset=empty',
|
|
233
238
|
];
|
|
234
239
|
case 'PACKAGE_INSTALL_ERROR':
|
|
235
240
|
return [
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Error codes for CNW errors.
|
|
3
3
|
* These are used for telemetry and error tracking.
|
|
4
4
|
*/
|
|
5
|
-
export type CnwErrorCode = 'DIRECTORY_EXISTS' | 'INVALID_WORKSPACE_NAME' | 'INVALID_FOLDER_NAME' | 'INVALID_BRANCH_NAME' | 'INVALID_PACKAGE_MANAGER' | 'INVALID_PATH' | 'INVALID_PRESET' | 'INVALID_WORKSPACE_TYPE' | 'INVALID_APP_NAME' | 'PRESET_FAILED' | 'SANDBOX_FAILED' | 'TEMPLATE_CLONE_FAILED' | 'CI_WORKFLOW_FAILED' | 'WORKSPACE_CREATION_FAILED' | 'ANGULAR_PREFIX_INVALID' | 'INVALID_BUNDLER' | 'NETWORK_ERROR' | 'PACKAGE_INSTALL_ERROR' | 'UNKNOWN';
|
|
5
|
+
export type CnwErrorCode = 'DIRECTORY_EXISTS' | 'INVALID_WORKSPACE_NAME' | 'INVALID_FOLDER_NAME' | 'INVALID_BRANCH_NAME' | 'INVALID_PACKAGE_MANAGER' | 'INVALID_PATH' | 'INVALID_PRESET' | 'INVALID_WORKSPACE_TYPE' | 'INVALID_APP_NAME' | 'PRESET_FAILED' | 'SANDBOX_FAILED' | 'TEMPLATE_CLONE_FAILED' | 'CI_WORKFLOW_FAILED' | 'WORKSPACE_CREATION_FAILED' | 'ANGULAR_PREFIX_INVALID' | 'INVALID_BUNDLER' | 'NETWORK_ERROR' | 'PACKAGE_INSTALL_ERROR' | 'CANCELLED' | 'UNKNOWN';
|
|
6
6
|
/**
|
|
7
7
|
* Custom error class for CNW errors.
|
|
8
8
|
* Used for structured error reporting and telemetry.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ends the process the way an interrupted process ends: by SIGINT, not by
|
|
3
|
+
* exiting with its conventional code.
|
|
4
|
+
*
|
|
5
|
+
* A shell reports 130 either way, but a parent using waitpid sees
|
|
6
|
+
* `signal: 'SIGINT'` rather than `code: 130`, which is what tools wrapping
|
|
7
|
+
* this CLI check to tell "the user pressed Ctrl+C" from "the command failed".
|
|
8
|
+
*
|
|
9
|
+
* Kept in sync with `packages/nx/src/utils/exit-codes.ts`; this package
|
|
10
|
+
* deliberately does not depend on `nx`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function exitAsInterrupted(): never;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exitAsInterrupted = exitAsInterrupted;
|
|
4
|
+
/**
|
|
5
|
+
* Ends the process the way an interrupted process ends: by SIGINT, not by
|
|
6
|
+
* exiting with its conventional code.
|
|
7
|
+
*
|
|
8
|
+
* A shell reports 130 either way, but a parent using waitpid sees
|
|
9
|
+
* `signal: 'SIGINT'` rather than `code: 130`, which is what tools wrapping
|
|
10
|
+
* this CLI check to tell "the user pressed Ctrl+C" from "the command failed".
|
|
11
|
+
*
|
|
12
|
+
* Kept in sync with `packages/nx/src/utils/exit-codes.ts`; this package
|
|
13
|
+
* deliberately does not depend on `nx`.
|
|
14
|
+
*/
|
|
15
|
+
function exitAsInterrupted() {
|
|
16
|
+
// Windows has no signal disposition to inherit - `process.kill` there
|
|
17
|
+
// terminates with an arbitrary code - so keep the 128+SIGINT convention.
|
|
18
|
+
if (process.platform !== 'win32') {
|
|
19
|
+
// Any listener would swallow this; the default action is what terminates.
|
|
20
|
+
process.removeAllListeners('SIGINT');
|
|
21
|
+
process.kill(process.pid, 'SIGINT');
|
|
22
|
+
}
|
|
23
|
+
process.exit(130);
|
|
24
|
+
}
|
|
@@ -5,12 +5,11 @@ exports.checkGitVersion = checkGitVersion;
|
|
|
5
5
|
exports.isGhCliAvailable = isGhCliAvailable;
|
|
6
6
|
exports.initializeGitRepo = initializeGitRepo;
|
|
7
7
|
exports.pushToGitHub = pushToGitHub;
|
|
8
|
-
const tslib_1 = require("tslib");
|
|
9
8
|
const child_process_1 = require("child_process");
|
|
10
9
|
const default_base_1 = require("./default-base");
|
|
11
10
|
const output_1 = require("../output");
|
|
12
11
|
const child_process_utils_1 = require("../child-process-utils");
|
|
13
|
-
const
|
|
12
|
+
const prompt_helpers_1 = require("../../internal-utils/prompt-helpers");
|
|
14
13
|
var VcsPushStatus;
|
|
15
14
|
(function (VcsPushStatus) {
|
|
16
15
|
VcsPushStatus["PushedToVcs"] = "PushedToVcs";
|
|
@@ -195,41 +194,41 @@ async function pushToGitHub(directory, options) {
|
|
|
195
194
|
// This runs while user is answering prompts, so validation is usually instant
|
|
196
195
|
populateExistingRepos(directory);
|
|
197
196
|
// First prompt: Ask if they want to push to GitHub
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
initial: 0,
|
|
205
|
-
},
|
|
206
|
-
]);
|
|
207
|
-
if (push !== 'Yes') {
|
|
197
|
+
// Cancelling is a decision not to push, not a failure to push.
|
|
198
|
+
const push = await (0, prompt_helpers_1.confirmationPrompt)({
|
|
199
|
+
message: 'Would you like to push this workspace to GitHub?',
|
|
200
|
+
onCancel: () => false,
|
|
201
|
+
});
|
|
202
|
+
if (!push) {
|
|
208
203
|
return VcsPushStatus.OptedOutOfPushingToVcs;
|
|
209
204
|
}
|
|
210
205
|
// Create default repository name using the username we already have
|
|
211
206
|
const defaultRepo = `${username}/${options.name}`;
|
|
212
207
|
const createRepoUrl = `https://github.com/new?name=${encodeURIComponent(options.name)}`;
|
|
213
208
|
// Second prompt: Ask where to create the repository with validation
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
209
|
+
// Validation runs synchronously, so the background fetch is resolved here
|
|
210
|
+
// rather than awaited inside it. It was started before the prompt above, so
|
|
211
|
+
// it has normally settled by now.
|
|
212
|
+
const existingRepos = await existingReposPromise;
|
|
213
|
+
// An empty name cannot come from the prompt - `validate` requires a slash -
|
|
214
|
+
// so it is unambiguous as the cancelled signal.
|
|
215
|
+
const repoName = await (0, prompt_helpers_1.textPrompt)({
|
|
216
|
+
message: 'Repository name (format: username/repo-name):',
|
|
217
|
+
initialValue: defaultRepo,
|
|
218
|
+
validate: (value) => {
|
|
219
|
+
if (!value.includes('/')) {
|
|
220
|
+
return 'Repository name must be in format: username/repo-name';
|
|
221
|
+
}
|
|
222
|
+
if (existingRepos?.has(value)) {
|
|
223
|
+
return `Repository '${value}' already exists. Choose a different name or create manually: ${createRepoUrl}`;
|
|
224
|
+
}
|
|
225
|
+
return undefined;
|
|
231
226
|
},
|
|
232
|
-
|
|
227
|
+
onCancel: () => '',
|
|
228
|
+
});
|
|
229
|
+
if (!repoName) {
|
|
230
|
+
return VcsPushStatus.OptedOutOfPushingToVcs;
|
|
231
|
+
}
|
|
233
232
|
// Create GitHub repository and push using gh CLI.
|
|
234
233
|
// Uses execAndWait (not spawnAndWait) so output is captured rather than
|
|
235
234
|
// streamed to the terminal. This prevents git push output from bleeding
|
|
@@ -174,8 +174,10 @@ const messageOptions = {
|
|
|
174
174
|
{ value: 'gitlab', name: 'Gitlab' },
|
|
175
175
|
{ value: 'azure', name: 'Azure DevOps' },
|
|
176
176
|
{ value: 'bitbucket-pipelines', name: 'BitBucket Pipelines' },
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
// Trailing newline puts a blank line before "Do it later". A leading
|
|
178
|
+
// one would split that choice from its own radio marker.
|
|
179
|
+
{ value: 'circleci', name: 'Circle CI\n' },
|
|
180
|
+
{ value: 'skip', name: 'Do it later' },
|
|
179
181
|
],
|
|
180
182
|
footer: `\nSelf-healing CI, remote caching, and task distribution are provided by Nx Cloud: ${exports.NX_CLOUD_HYPERLINK}`,
|
|
181
183
|
fallback: { value: 'skip', key: 'setupNxCloud' },
|
|
@@ -25,8 +25,9 @@ const DEFAULT_BRANCHES = ['main', 'master'];
|
|
|
25
25
|
async function downloadTemplate(template, directory) {
|
|
26
26
|
let body;
|
|
27
27
|
const attempts = [];
|
|
28
|
-
//
|
|
29
|
-
//
|
|
28
|
+
// 404 means the repo/branch does not exist; any other failure (thrown fetch,
|
|
29
|
+
// 403 from a sandbox proxy, 407/429/5xx) means blocked or failed egress.
|
|
30
|
+
// The distinction picks the error code and its hints.
|
|
30
31
|
let networkError = false;
|
|
31
32
|
for (const branch of DEFAULT_BRANCHES) {
|
|
32
33
|
const url = `https://github.com/${template}/archive/refs/heads/${branch}.tar.gz`;
|
|
@@ -36,6 +37,8 @@ async function downloadTemplate(template, directory) {
|
|
|
36
37
|
body = res.body;
|
|
37
38
|
break;
|
|
38
39
|
}
|
|
40
|
+
if (res.status !== 404)
|
|
41
|
+
networkError = true;
|
|
39
42
|
attempts.push(`${branch}: HTTP ${res.status}`);
|
|
40
43
|
}
|
|
41
44
|
catch (e) {
|
|
@@ -44,7 +47,11 @@ async function downloadTemplate(template, directory) {
|
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
if (!body) {
|
|
47
|
-
|
|
50
|
+
if (networkError) {
|
|
51
|
+
throw new error_utils_1.CnwError('NETWORK_ERROR', `Failed to download template '${template}' (${attempts.join('; ')}).\n` +
|
|
52
|
+
`github.com may be blocked or unreachable in this environment. Check your network and sandbox configuration and try again, or run with --preset=empty (instead of --template) to create a minimal workspace without downloading a template.`);
|
|
53
|
+
}
|
|
54
|
+
throw new error_utils_1.CnwError('TEMPLATE_CLONE_FAILED', `Failed to download template '${template}' (${attempts.join('; ')}). Check that the template name is correct.`);
|
|
48
55
|
}
|
|
49
56
|
// Only remove the directory on failure if we created it - never delete a
|
|
50
57
|
// pre-existing dir (e.g. the user's current directory).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-nx-workspace",
|
|
3
|
-
"version": "23.2.0-beta.
|
|
3
|
+
"version": "23.2.0-beta.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Smart Monorepos · Fast Builds",
|
|
6
6
|
"repository": {
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://nx.dev",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"
|
|
40
|
+
"@clack/prompts": "^1.7.0",
|
|
41
|
+
"axios": "1.18.1",
|
|
41
42
|
"chalk": "^4.1.0",
|
|
42
|
-
"enquirer": "~2.3.6",
|
|
43
43
|
"flat": "^5.0.2",
|
|
44
44
|
"open": "^8.4.0",
|
|
45
45
|
"ora": "^5.3.0",
|