Skip to content

Commit

Permalink
feat(core): extend nxCloud prompt to include basic CI workflow options (
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Jan 18, 2024
1 parent f98a16f commit d45a13e
Show file tree
Hide file tree
Showing 41 changed files with 276 additions and 324 deletions.
14 changes: 4 additions & 10 deletions docs/generated/cli/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ Type: `string`

Bundler to be used to build the app

### ci

Type: `string`

Choices: [github, circleci, azure, bitbucket-pipelines, gitlab]

Generate a CI workflow file

### commit.email

Type: `string`
Expand Down Expand Up @@ -127,9 +119,11 @@ Generate a 'src/' directory for Next.js

### nxCloud

Type: `boolean`
Type: `string`

Choices: [yes, github, circleci, skip]

Enable remote caching to make your CI faster
Do you want Nx Cloud to make your CI fast?

### packageManager

Expand Down
14 changes: 4 additions & 10 deletions docs/generated/packages/nx/documents/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ Type: `string`

Bundler to be used to build the app

### ci

Type: `string`

Choices: [github, circleci, azure, bitbucket-pipelines, gitlab]

Generate a CI workflow file

### commit.email

Type: `string`
Expand Down Expand Up @@ -127,9 +119,11 @@ Generate a 'src/' directory for Next.js

### nxCloud

Type: `boolean`
Type: `string`

Choices: [yes, github, circleci, skip]

Enable remote caching to make your CI faster
Do you want Nx Cloud to make your CI fast?

### packageManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Run the command `npx create-nx-workspace@latest` and when prompted, provide the
✔ Default stylesheet format · css
✔ Would you like to use Standalone Components in your application? · No
✔ Would you like to add routing? · Yes
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
```

{% card title="Opting into Nx Cloud" description="You will also be prompted whether to add Nx Cloud to your workspace. We won't address this in this tutorial, but you can see the introduction to Nx Cloud for more details." url="/ci/intro/ci-with-nx" /%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Create a new Angular application with the following command:
✔ Default stylesheet format · css
✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? · No
✔ Test runner to use for end to end (E2E) tests · cypress
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
```

You get asked a few questions that help Nx preconfigure your new Angular application. These include
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/angular-tutorial/angular-monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Create a new Angular monorepo with the following command:
✔ Default stylesheet format · css
✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? · No
✔ Test runner to use for end to end (E2E) tests · cypress
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
```

Let's name the initial application `angular-store`. In this tutorial we're going to use `cypress` for e2e tests and `css` for styling. The above command generates the following structure:
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/guides/remix.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ In this recipe, we'll show you how to create a [Remix](https://remix.run) applic
```{% command="npx create-nx-workspace acme --preset=apps" path="~/" %}
> NX Let's create a new workspace [https://nx.dev/getting-started/intro]
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
> NX Creating your v16.3.2 workspace.
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/node-server-tutorial/1-code-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Run the command `npx create-nx-workspace@latest` and when prompted, provide the
✔ What framework should be used? · express
✔ Standalone project or integrated monorepo? · standalone
✔ Would you like to generate a Dockerfile? [https://docs.docker.com/] · Yes
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
```

{% card title="Opting into Nx Cloud" description="You will also be prompted whether to add Nx Cloud to your workspace. We won't address this in this tutorial, but you can see the introduction to Nx Cloud for more details." url="/ci/intro/ci-with-nx" /%}
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/react-standalone-tutorial/react-standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Create a new standalone React application with the following command:
✔ Which bundler would you like to use? · vite
✔ Test runner to use for end to end (E2E) tests · cypress
✔ Default stylesheet format · css
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
```

You can choose any bundler you like. In this tutorial we're going to use Vite. The above command generates the following structure:
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/react-tutorial/react-monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Create a new React monorepo with the following command:
✔ Which bundler would you like to use? · vite
✔ Test runner to use for end to end (E2E) tests · cypress
✔ Default stylesheet format · css
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
```

Let's name the initial application `react-store`. In this tutorial we're going to use `vite` as a bundler, `cypress` for e2e tests and `css` for styling. The above command generates the following structure:
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/recipes/add-stack/add-astro.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ We can leverage [`nx init`](/recipes/adopting-nx/adding-to-existing-project#inst
✔ Which of the following scripts are cacheable? (Produce the same output given the same input, e.g. build, test and lint usually are, serve and start are not). You can use spacebar to select one or more scripts. · build
✔ Does the "build" script create any outputs? If not, leave blank, otherwise provide a path (e.g. dist, lib, build, coverage) · dist
Enable remote caching to make your CI faster · No
Would you like remote caching to make your build faster? · Yes
> NX 📦 Installing dependencies
Expand Down
6 changes: 3 additions & 3 deletions docs/shared/recipes/add-stack/add-svelte.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ Because we are not using a Nx plugin for Svelte, there are a few items we'll hav
{%tab label="npm"%}

```shell
npx create-nx-workspace@latest acme --preset=ts-standalone --nx-cloud=true
npx create-nx-workspace@latest acme --preset=ts-standalone --nx-cloud=yes
```

{% /tab %}
{%tab label="yarn"%}

```shell
npx create-nx-workspace@latest acme --preset=ts-standalone --nx-cloud=true --pm yarn
npx create-nx-workspace@latest acme --preset=ts-standalone --nx-cloud=yes --pm yarn
```

{% /tab %}
{%tab label="pnpm"%}

```shell
npx create-nx-workspace@latest acme --preset=ts-standalone --nx-cloud=true --pm pnpm
npx create-nx-workspace@latest acme --preset=ts-standalone --nx-cloud=yes --pm pnpm
```

{% /tab %}
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/recipes/module-federation-with-ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Run the following command with the options listed to create an empty workspace.
✔ Where would you like to create your workspace? · myorg
✔ Which stack do you want to use? · none
✔ Package-based or integrated? · integrated
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
```

{% card title="Opting into Nx Cloud" description="You will also be prompted whether to add Nx Cloud to your workspace. We won't address this in this recipe, but you can see the introduction to Nx Cloud for more details." url="/ci/intro/ci-with-nx" /%}
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/vue-standalone-tutorial/vue-standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Create a new Vue application with the following command:
✔ Test runner to use for end to end (E2E) tests · cypress
✔ Default stylesheet format · css
Enable remote caching to make your CI faster · Yes
Do you want Nx Cloud to make your CI fast? · Yes
> NX Creating your v17.0.0 workspace.
Expand Down
10 changes: 5 additions & 5 deletions e2e/nx-init/src/nx-init-react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('nx init (for React)', () => {
const craToNxOutput = runCommand(
`${
pmc.runUninstalledPackage
} nx@${getPublishedVersion()} init --nxCloud=false --integrated --vite=false`
} nx@${getPublishedVersion()} init --nxCloud=skip --integrated --vite=false`
);

expect(craToNxOutput).toContain('🎉 Done!');
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('nx init (for React)', () => {
const craToNxOutput = runCommand(
`${
pmc.runUninstalledPackage
} nx@${getPublishedVersion()} init --nxCloud=false --integrated`
} nx@${getPublishedVersion()} init --nxCloud=skip --integrated`
);

expect(craToNxOutput).toContain('🎉 Done!');
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('nx init (for React)', () => {
runCommand(
`${
pmc.runUninstalledPackage
} nx@${getPublishedVersion()} init --nxCloud=false --force --integrated`
} nx@${getPublishedVersion()} init --nxCloud=skip --force --integrated`
);

const viteConfig = readFile(`apps/${appName}/vite.config.js`);
Expand All @@ -115,7 +115,7 @@ describe('nx init (for React)', () => {
const craToNxOutput = runCommand(
`${
pmc.runUninstalledPackage
} nx@${getPublishedVersion()} init --nxCloud=false --vite=false`
} nx@${getPublishedVersion()} init --nxCloud=skip --vite=false`
);

expect(craToNxOutput).toContain('🎉 Done!');
Expand All @@ -137,7 +137,7 @@ describe('nx init (for React)', () => {
const craToNxOutput = runCommand(
`${
pmc.runUninstalledPackage
} nx@${getPublishedVersion()} init --nxCloud=false --vite`
} nx@${getPublishedVersion()} init --nxCloud=skip --vite`
);

expect(craToNxOutput).toContain('🎉 Done!');
Expand Down
9 changes: 2 additions & 7 deletions e2e/utils/create-project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export function runCreateWorkspace(
base,
packageManager,
extraArgs,
ci,
useDetectedPm = false,
cwd = e2eCwd,
bundler,
Expand All @@ -240,7 +239,6 @@ export function runCreateWorkspace(
base?: string;
packageManager?: 'npm' | 'yarn' | 'pnpm';
extraArgs?: string;
ci?: 'azure' | 'github' | 'circleci';
useDetectedPm?: boolean;
cwd?: string;
bundler?: 'webpack' | 'vite';
Expand All @@ -258,16 +256,13 @@ export function runCreateWorkspace(

const pm = getPackageManagerCommand({ packageManager });

let command = `${pm.createWorkspace} ${name} --preset=${preset} --no-nxCloud --no-interactive`;
let command = `${pm.createWorkspace} ${name} --preset=${preset} --nxCloud=skip --no-interactive`;
if (appName) {
command += ` --appName=${appName}`;
}
if (style) {
command += ` --style=${style}`;
}
if (ci) {
command += ` --ci=${ci}`;
}

if (bundler) {
command += ` --bundler=${bundler}`;
Expand Down Expand Up @@ -366,7 +361,7 @@ export function runCreatePlugin(

let command = `${
pm.runUninstalledPackage
} create-nx-plugin@${getPublishedVersion()} ${name} --no-nxCloud`;
} create-nx-plugin@${getPublishedVersion()} ${name} --nxCloud=skip`;

if (packageManager && !useDetectedPm) {
command += ` --package-manager=${packageManager}`;
Expand Down
11 changes: 0 additions & 11 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,6 @@ describe('create-nx-workspace', () => {
process.env.SELECTED_PM = packageManager;
});

it('should return error when ci workflow is selected but no cloud is set up', () => {
const wsName = uniq('github');
runCreateWorkspace(wsName, {
preset: 'apps',
packageManager,
ci: 'circleci',
});
checkFilesExist('package.json');
checkFilesDoNotExist('.circleci/config.yml');
});

describe('Use detected package manager', () => {
function setupProject(envPm: 'npm' | 'yarn' | 'pnpm') {
process.env.SELECTED_PM = envPm;
Expand Down
17 changes: 7 additions & 10 deletions packages/create-nx-plugin/bin/create-nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import enquirer = require('enquirer');
import yargs = require('yargs');

import {
determineCI,
determineDefaultBase,
determineNxCloud,
determinePackageManager,
} from 'create-nx-workspace/src/internal-utils/prompts';
import {
withAllPrompts,
withCI,
withGitOptions,
withNxCloud,
withOptions,
withPackageManager,
} from 'create-nx-workspace/src/internal-utils/yargs-options';
import { createWorkspace, CreateWorkspaceOptions } from 'create-nx-workspace';
import { output } from 'create-nx-workspace/src/utils/output';
import { CI } from 'create-nx-workspace/src/utils/ci/ci-list';
import { NxCloud } from 'create-nx-workspace/src/utils/nx/nx-cloud';
import type { PackageManager } from 'create-nx-workspace/src/utils/package-manager';
import { showNxWarning } from 'create-nx-workspace/src/utils/nx/show-nx-warning';
import { printNxCloudSuccessMessage } from 'create-nx-workspace/src/utils/nx/nx-cloud';
Expand Down Expand Up @@ -82,9 +80,8 @@ interface CreateNxPluginArguments {
pluginName: string;
createPackageName?: string;
packageManager: PackageManager;
ci: CI;
allPrompts: boolean;
nxCloud: boolean;
nxCloud: NxCloud;
}

export const commandsObject: yargs.Argv<CreateNxPluginArguments> = yargs
Expand All @@ -110,7 +107,6 @@ export const commandsObject: yargs.Argv<CreateNxPluginArguments> = yargs
type: 'string',
}),
withNxCloud,
withCI,
withAllPrompts,
withPackageManager,
withGitOptions
Expand Down Expand Up @@ -160,8 +156,11 @@ async function main(parsedArgs: yargs.Arguments<CreateNxPluginArguments>) {
await recordStat({
nxVersion,
command: 'create-nx-workspace',
useCloud: parsedArgs.nxCloud,
meta: messages.codeOfSelectedPromptMessage('nxCloudCreation'),
useCloud: parsedArgs.nxCloud !== 'skip',
meta: [
messages.codeOfSelectedPromptMessage('setupCI'),
messages.codeOfSelectedPromptMessage('setupNxCloud'),
],
});

if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) {
Expand All @@ -184,15 +183,13 @@ async function normalizeArgsMiddleware(
const packageManager = await determinePackageManager(argv);
const defaultBase = await determineDefaultBase(argv);
const nxCloud = await determineNxCloud(argv);
const ci = await determineCI(argv, nxCloud);

Object.assign(argv, {
pluginName,
createPackageName,
nxCloud,
packageManager,
defaultBase,
ci,
} as Partial<CreateNxPluginArguments>);
} catch (e) {
console.error(e);
Expand Down
Loading

1 comment on commit d45a13e

@vercel
Copy link

@vercel vercel bot commented on d45a13e Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.