create-nx-workspace 20.2.0-beta.2 → 20.2.0-beta.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.
@@ -21,6 +21,9 @@ interface ReactArguments extends BaseArguments {
21
21
  nextAppDir: boolean;
22
22
  nextSrcDir: boolean;
23
23
  e2eTestRunner: 'none' | 'cypress' | 'playwright';
24
+ linter?: 'none' | 'eslint';
25
+ formatter?: 'none' | 'prettier';
26
+ workspaces?: boolean;
24
27
  }
25
28
  interface AngularArguments extends BaseArguments {
26
29
  stack: 'angular';
@@ -8,7 +8,6 @@ const create_workspace_1 = require("../src/create-workspace");
8
8
  const preset_1 = require("../src/utils/preset/preset");
9
9
  const output_1 = require("../src/utils/output");
10
10
  const nx_version_1 = require("../src/utils/nx/nx-version");
11
- const point_to_tutorial_and_course_1 = require("../src/utils/preset/point-to-tutorial-and-course");
12
11
  const decorator_1 = require("./decorator");
13
12
  const get_third_party_preset_1 = require("../src/utils/preset/get-third-party-preset");
14
13
  const prompts_1 = require("../src/internal-utils/prompts");
@@ -17,6 +16,7 @@ const ab_testing_1 = require("../src/utils/nx/ab-testing");
17
16
  const error_utils_1 = require("../src/utils/error-utils");
18
17
  const fs_1 = require("fs");
19
18
  const is_ci_1 = require("../src/utils/ci/is-ci");
19
+ const social_information_1 = require("../src/utils/social-information");
20
20
  exports.commandsObject = yargs
21
21
  .wrap(yargs.terminalWidth())
22
22
  .parserConfiguration({
@@ -69,6 +69,15 @@ exports.commandsObject = yargs
69
69
  .option('bundler', {
70
70
  describe: chalk.dim `Bundler to be used to build the app.`,
71
71
  type: 'string',
72
+ })
73
+ .option('workspaces', {
74
+ describe: chalk.dim `Use package manager workspaces.`,
75
+ type: 'boolean',
76
+ default: false,
77
+ })
78
+ .option('formatter', {
79
+ describe: chalk.dim `Code formatter to use.`,
80
+ type: 'string',
72
81
  })
73
82
  .option('framework', {
74
83
  describe: chalk.dim `Framework option to be used with certain stacks.`,
@@ -126,10 +135,10 @@ async function main(parsedArgs) {
126
135
  ],
127
136
  });
128
137
  if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) {
129
- console.log(workspaceInfo.nxCloudInfo);
138
+ process.stdout.write(workspaceInfo.nxCloudInfo);
130
139
  }
131
140
  if ((0, preset_1.isKnownPreset)(parsedArgs.preset)) {
132
- (0, point_to_tutorial_and_course_1.pointToTutorialAndCourse)(parsedArgs.preset);
141
+ (0, social_information_1.printSocialInformation)();
133
142
  }
134
143
  else {
135
144
  output_1.output.log({
@@ -307,30 +316,55 @@ async function determinePresetOptions(parsedArgs) {
307
316
  return parsedArgs;
308
317
  }
309
318
  }
319
+ async function determineFormatterOptions(args) {
320
+ if (args.formatter)
321
+ return args.formatter;
322
+ const reply = await enquirer.prompt([
323
+ {
324
+ name: 'prettier',
325
+ message: `Would you like to use Prettier for code formatting?`,
326
+ type: 'autocomplete',
327
+ choices: [
328
+ {
329
+ name: 'Yes',
330
+ },
331
+ {
332
+ name: 'No',
333
+ },
334
+ ],
335
+ initial: 1,
336
+ skip: !args.interactive || (0, is_ci_1.isCI)(),
337
+ },
338
+ ]);
339
+ return reply.prettier === 'Yes' ? 'prettier' : 'none';
340
+ }
341
+ async function determineLinterOptions(args) {
342
+ const reply = await enquirer.prompt([
343
+ {
344
+ name: 'eslint',
345
+ message: `Would you like to use ESLint?`,
346
+ type: 'autocomplete',
347
+ choices: [
348
+ {
349
+ name: 'Yes',
350
+ },
351
+ {
352
+ name: 'No',
353
+ },
354
+ ],
355
+ initial: 1,
356
+ skip: !args.interactive || (0, is_ci_1.isCI)(),
357
+ },
358
+ ]);
359
+ return reply.eslint === 'Yes' ? 'eslint' : 'none';
360
+ }
310
361
  async function determineNoneOptions(parsedArgs) {
311
362
  if ((!parsedArgs.preset || parsedArgs.preset === preset_1.Preset.TS) &&
312
363
  process.env.NX_ADD_PLUGINS !== 'false' &&
313
364
  process.env.NX_ADD_TS_PLUGIN !== 'false') {
314
- const reply = await enquirer.prompt([
315
- {
316
- name: 'prettier',
317
- message: `Would you like to use Prettier for code formatting?`,
318
- type: 'autocomplete',
319
- choices: [
320
- {
321
- name: 'Yes',
322
- },
323
- {
324
- name: 'No',
325
- },
326
- ],
327
- initial: 1,
328
- skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
329
- },
330
- ]);
331
365
  return {
332
366
  preset: preset_1.Preset.TS,
333
- formatter: reply.prettier === 'Yes' ? 'prettier' : 'none',
367
+ formatter: await determineFormatterOptions(parsedArgs),
334
368
  };
335
369
  }
336
370
  else {
@@ -392,6 +426,9 @@ async function determineReactOptions(parsedArgs) {
392
426
  let e2eTestRunner = undefined;
393
427
  let nextAppDir = false;
394
428
  let nextSrcDir = false;
429
+ let linter;
430
+ let formatter;
431
+ const workspaces = parsedArgs.workspaces ?? false;
395
432
  if (parsedArgs.preset && parsedArgs.preset !== preset_1.Preset.React) {
396
433
  preset = parsedArgs.preset;
397
434
  if (preset === preset_1.Preset.ReactStandalone ||
@@ -405,19 +442,17 @@ async function determineReactOptions(parsedArgs) {
405
442
  }
406
443
  else {
407
444
  const framework = await determineReactFramework(parsedArgs);
408
- // React Native and Expo only support integrated monorepos for now.
409
- // TODO(jack): Add standalone support for React Native and Expo.
410
- const workspaceType = framework === 'react-native' || framework === 'expo'
411
- ? 'integrated'
412
- : await determineStandaloneOrMonorepo();
413
- if (workspaceType === 'standalone') {
445
+ const isStandalone = workspaces || framework === 'react-native' || framework === 'expo'
446
+ ? false
447
+ : (await determineStandaloneOrMonorepo()) === 'standalone';
448
+ if (isStandalone) {
414
449
  appName = parsedArgs.name;
415
450
  }
416
451
  else {
417
452
  appName = await determineAppName(parsedArgs);
418
453
  }
419
454
  if (framework === 'nextjs') {
420
- if (workspaceType === 'standalone') {
455
+ if (isStandalone) {
421
456
  preset = preset_1.Preset.NextJsStandalone;
422
457
  }
423
458
  else {
@@ -425,7 +460,7 @@ async function determineReactOptions(parsedArgs) {
425
460
  }
426
461
  }
427
462
  else if (framework === 'remix') {
428
- if (workspaceType === 'standalone') {
463
+ if (isStandalone) {
429
464
  preset = preset_1.Preset.RemixStandalone;
430
465
  }
431
466
  else {
@@ -439,7 +474,7 @@ async function determineReactOptions(parsedArgs) {
439
474
  preset = preset_1.Preset.Expo;
440
475
  }
441
476
  else {
442
- if (workspaceType === 'standalone') {
477
+ if (isStandalone) {
443
478
  preset = preset_1.Preset.ReactStandalone;
444
479
  }
445
480
  else {
@@ -510,6 +545,14 @@ async function determineReactOptions(parsedArgs) {
510
545
  ]);
511
546
  style = reply.style;
512
547
  }
548
+ if (workspaces) {
549
+ linter = await determineLinterOptions(parsedArgs);
550
+ formatter = await determineFormatterOptions(parsedArgs);
551
+ }
552
+ else {
553
+ linter = 'eslint';
554
+ formatter = 'prettier';
555
+ }
513
556
  return {
514
557
  preset,
515
558
  style,
@@ -518,6 +561,9 @@ async function determineReactOptions(parsedArgs) {
518
561
  nextAppDir,
519
562
  nextSrcDir,
520
563
  e2eTestRunner,
564
+ linter,
565
+ formatter,
566
+ workspaces,
521
567
  };
522
568
  }
523
569
  async function determineVueOptions(parsedArgs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nx-workspace",
3
- "version": "20.2.0-beta.2",
3
+ "version": "20.2.0-beta.4",
4
4
  "private": false,
5
5
  "description": "Smart Monorepos · Fast CI",
6
6
  "repository": {
@@ -11,14 +11,16 @@ const setup_ci_1 = require("./utils/ci/setup-ci");
11
11
  const git_1 = require("./utils/git/git");
12
12
  const get_third_party_preset_1 = require("./utils/preset/get-third-party-preset");
13
13
  const error_utils_1 = require("./utils/error-utils");
14
+ const preset_1 = require("./utils/preset/preset");
14
15
  async function createWorkspace(preset, options) {
15
16
  const { packageManager, name, nxCloud, skipGit = false, defaultBase = 'main', commit, cliName, useGitHub, } = options;
16
17
  if (cliName) {
17
18
  output_1.output.setCliName(cliName ?? 'NX');
18
19
  }
19
20
  const tmpDir = await (0, create_sandbox_1.createSandbox)(packageManager);
21
+ const workspaceGlobs = getWorkspaceGlobsFromPreset(preset);
20
22
  // nx new requires a preset currently. We should probably make it optional.
21
- const directory = await (0, create_empty_workspace_1.createEmptyWorkspace)(tmpDir, name, packageManager, { ...options, preset });
23
+ const directory = await (0, create_empty_workspace_1.createEmptyWorkspace)(tmpDir, name, packageManager, { ...options, preset, workspaceGlobs });
22
24
  // If the preset is a third-party preset, we need to call createPreset to install it
23
25
  // For first-party presets, it will be created by createEmptyWorkspace instead.
24
26
  // In createEmptyWorkspace, it will call `nx new` -> `@nx/workspace newGenerator` -> `@nx/workspace generatePreset`.
@@ -63,3 +65,23 @@ function extractConnectUrl(text) {
63
65
  const match = text.match(urlPattern);
64
66
  return match ? match[0] : null;
65
67
  }
68
+ function getWorkspaceGlobsFromPreset(preset) {
69
+ // Should match how apps are created in `packages/workspace/src/generators/preset/preset.ts`.
70
+ switch (preset) {
71
+ case preset_1.Preset.AngularMonorepo:
72
+ case preset_1.Preset.Expo:
73
+ case preset_1.Preset.Express:
74
+ case preset_1.Preset.Nest:
75
+ case preset_1.Preset.NextJs:
76
+ case preset_1.Preset.NodeMonorepo:
77
+ case preset_1.Preset.Nuxt:
78
+ case preset_1.Preset.ReactNative:
79
+ case preset_1.Preset.ReactMonorepo:
80
+ case preset_1.Preset.RemixMonorepo:
81
+ case preset_1.Preset.VueMonorepo:
82
+ case preset_1.Preset.WebComponents:
83
+ return ['apps/**', 'packages/**'];
84
+ default:
85
+ return ['packages/**'];
86
+ }
87
+ }
@@ -1,4 +1,4 @@
1
- export type NxCloud = 'yes' | 'github' | 'circleci' | 'skip';
1
+ export type NxCloud = 'yes' | 'github' | 'gitlab' | 'azure' | 'bitbucket-pipelines' | 'circleci' | 'skip';
2
2
  export declare function readNxCloudToken(directory: string): string | undefined;
3
3
  export declare function getOnboardingInfo(nxCloud: NxCloud, token: string, directory: string, useGithub?: boolean): Promise<{
4
4
  output: string;
@@ -117,7 +117,6 @@ class CLIOutput {
117
117
  title: chalk.green(title),
118
118
  });
119
119
  this.writeOptionalOutputBody(bodyLines);
120
- this.addNewline();
121
120
  }
122
121
  logSingleLine(message) {
123
122
  this.addNewline();
@@ -0,0 +1 @@
1
+ export declare function printSocialInformation(): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printSocialInformation = printSocialInformation;
4
+ const output_1 = require("./output");
5
+ function printSocialInformation() {
6
+ output_1.output.success({
7
+ title: 'Welcome to the Nx community! 👋',
8
+ bodyLines: [
9
+ '🌟 Star Nx on GitHub: https://github.com/nrwl/nx',
10
+ '📢 Stay up to date on X: https://x.com/nxdevtools',
11
+ '💬 Discuss Nx on Discord: https://go.nx.dev/community',
12
+ ],
13
+ });
14
+ }
@@ -1,2 +0,0 @@
1
- import { Preset } from './preset';
2
- export declare function pointToTutorialAndCourse(preset: Preset): void;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pointToTutorialAndCourse = pointToTutorialAndCourse;
4
- const output_1 = require("../output");
5
- const preset_1 = require("./preset");
6
- function pointToTutorialAndCourse(preset) {
7
- const title = `First time using Nx? Check out this interactive Nx tutorial.`;
8
- switch (preset) {
9
- case preset_1.Preset.NPM:
10
- case preset_1.Preset.Apps:
11
- output_1.output.addVerticalSeparator();
12
- output_1.output.note({
13
- title,
14
- bodyLines: [
15
- `https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial`,
16
- ],
17
- });
18
- break;
19
- case preset_1.Preset.TS:
20
- output_1.output.addVerticalSeparator();
21
- output_1.output.note({
22
- title,
23
- bodyLines: [
24
- `https://nx.dev/getting-started/tutorials/integrated-repo-tutorial`,
25
- ],
26
- });
27
- break;
28
- case preset_1.Preset.ReactStandalone:
29
- output_1.output.addVerticalSeparator();
30
- output_1.output.note({
31
- title,
32
- bodyLines: [
33
- `https://nx.dev/getting-started/tutorials/react-standalone-tutorial`,
34
- ],
35
- });
36
- break;
37
- case preset_1.Preset.ReactMonorepo:
38
- case preset_1.Preset.NextJs:
39
- case preset_1.Preset.NextJsStandalone:
40
- output_1.output.addVerticalSeparator();
41
- output_1.output.note({
42
- title,
43
- bodyLines: [`https://nx.dev/react-tutorial/1-code-generation`],
44
- });
45
- break;
46
- case preset_1.Preset.AngularStandalone:
47
- output_1.output.addVerticalSeparator();
48
- output_1.output.note({
49
- title,
50
- bodyLines: [
51
- `https://nx.dev/getting-started/tutorials/angular-standalone-tutorial`,
52
- ],
53
- });
54
- break;
55
- case preset_1.Preset.AngularMonorepo:
56
- output_1.output.addVerticalSeparator();
57
- output_1.output.note({
58
- title,
59
- bodyLines: [`https://nx.dev/angular-tutorial/1-code-generation`],
60
- });
61
- break;
62
- case preset_1.Preset.Express:
63
- case preset_1.Preset.NodeStandalone:
64
- output_1.output.addVerticalSeparator();
65
- output_1.output.note({
66
- title,
67
- bodyLines: [
68
- `https://nx.dev/getting-started/tutorials/node-server-tutorial`,
69
- ],
70
- });
71
- break;
72
- }
73
- }
@@ -1,5 +0,0 @@
1
- import { Preset } from './preset';
2
- export declare const presetOptions: {
3
- name: Preset;
4
- message: string;
5
- }[];
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.presetOptions = void 0;
4
- const preset_1 = require("./preset");
5
- exports.presetOptions = [
6
- {
7
- name: preset_1.Preset.Apps,
8
- message: 'apps [an empty monorepo with no plugins with a layout that works best for building apps]',
9
- },
10
- {
11
- name: preset_1.Preset.TS,
12
- message: 'ts [an empty monorepo with the JS/TS plugin preinstalled]',
13
- },
14
- {
15
- name: preset_1.Preset.ReactMonorepo,
16
- message: 'react [a monorepo with a single React application]',
17
- },
18
- {
19
- name: preset_1.Preset.AngularMonorepo,
20
- message: 'angular [a monorepo with a single Angular application]',
21
- },
22
- {
23
- name: preset_1.Preset.VueMonorepo,
24
- message: 'vue [a monorepo with a single Vue application]',
25
- },
26
- {
27
- name: preset_1.Preset.Nuxt,
28
- message: 'nuxt [a monorepo with a single Nuxt application]',
29
- },
30
- {
31
- name: preset_1.Preset.NextJs,
32
- message: 'next.js [a monorepo with a single Next.js application]',
33
- },
34
- {
35
- name: preset_1.Preset.Nest,
36
- message: 'nest [a monorepo with a single Nest application]',
37
- },
38
- {
39
- name: preset_1.Preset.ReactNative,
40
- message: 'react-native [a monorepo with a single React Native application]',
41
- },
42
- ];