diff --git a/docs/generated/packages/angular/generators/application.json b/docs/generated/packages/angular/generators/application.json index 8159f28174..63896891c6 100644 --- a/docs/generated/packages/angular/generators/application.json +++ b/docs/generated/packages/angular/generators/application.json @@ -156,6 +156,11 @@ "default": false, "hidden": true, "x-priority": "internal" + }, + "minimal": { + "description": "Generate a Angular app with a minimal setup.", + "type": "boolean", + "default": false } }, "additionalProperties": false, diff --git a/docs/generated/packages/react/generators/host.json b/docs/generated/packages/react/generators/host.json index 641c84ca1f..802c15f41a 100644 --- a/docs/generated/packages/react/generators/host.json +++ b/docs/generated/packages/react/generators/host.json @@ -156,6 +156,11 @@ "description": "Whether to configure SSR for the host application", "type": "boolean", "default": false + }, + "minimal": { + "description": "Generate a React app with a minimal setup. No nx starter template.", + "type": "boolean", + "default": false } }, "required": ["name"], diff --git a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap index 427df656c4..98ac6c5cf4 100644 --- a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap @@ -1,5 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`app --minimal should skip Nx specific \`nx-welcome.component.ts\` file creation 1`] = ` +"import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +import { AppComponent } from './app.component'; + +@NgModule({ + declarations: [ + AppComponent + ], + imports: [ + BrowserModule + ], + providers: [], + bootstrap: [AppComponent] +}) +export class AppModule { } +" +`; + exports[`app --standalone should generate a standalone app correctly with routing 1`] = ` "import { bootstrapApplication } from '@angular/platform-browser'; import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router'; diff --git a/packages/angular/src/generators/application/angular-v14/application.ts b/packages/angular/src/generators/application/angular-v14/application.ts index 34f7450778..ba704e002f 100644 --- a/packages/angular/src/generators/application/angular-v14/application.ts +++ b/packages/angular/src/generators/application/angular-v14/application.ts @@ -67,24 +67,26 @@ export async function applicationGenerator( updateConfigFiles(host, options); updateAppComponentTemplate(host, options); - // Create the NxWelcomeComponent - const angularComponentSchematic = wrapAngularDevkitSchematic( - '@schematics/angular', - 'component' - ); - await angularComponentSchematic(host, { - name: 'NxWelcome', - inlineTemplate: true, - inlineStyle: true, - prefix: options.prefix, - skipTests: true, - style: options.style, - flat: true, - viewEncapsulation: 'None', - project: options.name, - standalone: options.standalone, - }); - updateNxComponentTemplate(host, options); + if (!options.minimal) { + // Create the NxWelcomeComponent + const angularComponentSchematic = wrapAngularDevkitSchematic( + '@schematics/angular', + 'component' + ); + await angularComponentSchematic(host, { + name: 'NxWelcome', + inlineTemplate: true, + inlineStyle: true, + prefix: options.prefix, + skipTests: true, + style: options.style, + flat: true, + viewEncapsulation: 'None', + project: options.name, + standalone: options.standalone, + }); + updateNxComponentTemplate(host, options); + } if (options.addTailwind) { await setupTailwindGenerator(host, { diff --git a/packages/angular/src/generators/application/angular-v14/schema.d.ts b/packages/angular/src/generators/application/angular-v14/schema.d.ts index 80178effbc..c60a3c085f 100644 --- a/packages/angular/src/generators/application/angular-v14/schema.d.ts +++ b/packages/angular/src/generators/application/angular-v14/schema.d.ts @@ -26,4 +26,5 @@ export interface Schema { skipPackageJson?: boolean; standalone?: boolean; rootProject?: boolean; + minimal?: boolean; } diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index 0ea6fe35af..393690e650 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -862,6 +862,19 @@ describe('app', () => { .toThrow(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using 14.0.0. You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); }); + + describe('--minimal', () => { + it('should skip Nx specific `nx-welcome.component.ts` file creation', async () => { + await generateApp(appTree, 'plain', { minimal: true }); + + expect( + appTree.read('apps/plain/src/app/app.module.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.exists('apps/plain/src/app/nx-welcome.component.ts') + ).toBeFalsy(); + }); + }); }); async function generateApp( diff --git a/packages/angular/src/generators/application/application.ts b/packages/angular/src/generators/application/application.ts index 414ce5d913..ed21599326 100644 --- a/packages/angular/src/generators/application/application.ts +++ b/packages/angular/src/generators/application/application.ts @@ -92,24 +92,26 @@ export async function applicationGenerator( updateConfigFiles(tree, options); updateAppComponentTemplate(tree, options); - // Create the NxWelcomeComponent - const angularComponentSchematic = wrapAngularDevkitSchematic( - '@schematics/angular', - 'component' - ); - await angularComponentSchematic(tree, { - name: 'NxWelcome', - inlineTemplate: true, - inlineStyle: true, - prefix: options.prefix, - skipTests: true, - style: options.style, - flat: true, - viewEncapsulation: 'None', - project: options.name, - standalone: options.standalone, - }); - updateNxComponentTemplate(tree, options); + if (!options.minimal) { + // Create the NxWelcomeComponent + const angularComponentSchematic = wrapAngularDevkitSchematic( + '@schematics/angular', + 'component' + ); + await angularComponentSchematic(tree, { + name: 'NxWelcome', + inlineTemplate: true, + inlineStyle: true, + prefix: options.prefix, + skipTests: true, + style: options.style, + flat: true, + viewEncapsulation: 'None', + project: options.name, + standalone: options.standalone, + }); + updateNxComponentTemplate(tree, options); + } if (options.addTailwind) { await setupTailwindGenerator(tree, { diff --git a/packages/angular/src/generators/application/schema.d.ts b/packages/angular/src/generators/application/schema.d.ts index 80178effbc..c60a3c085f 100644 --- a/packages/angular/src/generators/application/schema.d.ts +++ b/packages/angular/src/generators/application/schema.d.ts @@ -26,4 +26,5 @@ export interface Schema { skipPackageJson?: boolean; standalone?: boolean; rootProject?: boolean; + minimal?: boolean; } diff --git a/packages/angular/src/generators/application/schema.json b/packages/angular/src/generators/application/schema.json index f9b1e0ba07..26bf421988 100644 --- a/packages/angular/src/generators/application/schema.json +++ b/packages/angular/src/generators/application/schema.json @@ -159,6 +159,11 @@ "default": false, "hidden": true, "x-priority": "internal" + }, + "minimal": { + "description": "Generate a Angular app with a minimal setup.", + "type": "boolean", + "default": false } }, "additionalProperties": false, diff --git a/packages/react/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/react/src/generators/application/__snapshots__/application.spec.ts.snap new file mode 100644 index 0000000000..5a2618d399 --- /dev/null +++ b/packages/react/src/generators/application/__snapshots__/application.spec.ts.snap @@ -0,0 +1,107 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`app --minimal should create default application without Nx welcome component 1`] = ` +" +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import styles from './app.module.css'; + + + +export function App() { + + return ( + <> + +

+ Hello there, + Welcome plain 👋 +

+ +
+ ); + +} + + +export default App; + + +if (import.meta.vitest) { + // add tests related to your file here + // For more information please visit the Vitest docs site here: https://vitest.dev/guide/in-source.html + + const { it, expect, beforeEach } = import.meta.vitest; + let render: any; + + beforeEach(async () => { + render = (await import('@testing-library/react')).render; + }); + + +it('should render successfully', () => { + const { baseElement } = render(); + expect(baseElement).toBeTruthy(); +}); + +it('should have a greeting as the title', () => { + const { getByText } = render(); + expect(getByText(/Welcome plain/gi)).toBeTruthy(); +}); + +} + " +`; + +exports[`app not nested should generate files 1`] = ` +" +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import styles from './app.module.css'; + +import NxWelcome from \\"./nx-welcome\\"; + + + +export function App() { + + return ( + <> + + + +
+ ); + +} + + +export default App; + +" +`; + +exports[`app should create Nx specific template 1`] = ` +" +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import styles from './app.module.css'; + +import NxWelcome from \\"./nx-welcome\\"; + + + +export function App() { + + return ( + <> + + + +
+ ); + +} + + +export default App; + +" +`; diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index 10c596f293..026bf74a1a 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -76,6 +76,9 @@ describe('app', () => { expect(appTree.exists('apps/my-app/.babelrc')).toBeTruthy(); expect(appTree.exists('apps/my-app/src/main.tsx')).toBeTruthy(); expect(appTree.exists('apps/my-app/src/app/app.tsx')).toBeTruthy(); + expect( + appTree.read('apps/my-app/src/app/app.tsx', 'utf-8') + ).toMatchSnapshot(); expect(appTree.exists('apps/my-app/src/app/app.spec.tsx')).toBeTruthy(); expect(appTree.exists('apps/my-app/src/app/app.module.css')).toBeTruthy(); @@ -235,8 +238,8 @@ describe('app', () => { await applicationGenerator(appTree, { ...schema, directory: 'myDir' }); expect( - appTree.read('apps/my-dir/my-app/src/app/app.tsx').toString() - ).toContain(``); + appTree.read('apps/my-dir/my-app/src/app/app.tsx', 'utf-8') + ).toMatchSnapshot(); expect( appTree.read('apps/my-dir/my-app/src/app/nx-welcome.tsx').toString() ).toContain('Hello there'); @@ -835,6 +838,20 @@ describe('app', () => { }); }); + describe('--minimal', () => { + it('should create default application without Nx welcome component', async () => { + await applicationGenerator(appTree, { + ...schema, + name: 'plain', + minimal: true, + }); + expect(appTree.exists('apps/plain/src/app/nx-welcome.tsx')).toBeFalsy(); + expect( + appTree.read('apps/plain/src/app/app.tsx', 'utf-8') + ).toMatchSnapshot(); + }); + }); + describe('--js', () => { it('generates JS files', async () => { await applicationGenerator(appTree, { diff --git a/packages/react/src/generators/application/files/base-webpack/src/app/nx-welcome.tsx b/packages/react/src/generators/application/files/base-webpack/src/app/nx-welcome.tsx deleted file mode 100644 index 761a47a0e2..0000000000 --- a/packages/react/src/generators/application/files/base-webpack/src/app/nx-welcome.tsx +++ /dev/null @@ -1,820 +0,0 @@ -/* - * * * * * * * * * * * * * * * * * * * * * * * * * * * * - This is a starter component and can be deleted. - * * * * * * * * * * * * * * * * * * * * * * * * * * * * - Delete this file and get started with your project! - * * * * * * * * * * * * * * * * * * * * * * * * * * * * - */ -export function NxWelcome({ title }: { title: string }) { - return ( - <> - - ); diff --git a/packages/react/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ b/packages/react/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ index 11244a4959..d1ed0bf98d 100644 --- a/packages/react/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ +++ b/packages/react/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ @@ -2,7 +2,9 @@ import { Component } from 'react'; <% } %> import styled from '<%= styledModule %>'; +<% if (!minimal) { %> import NxWelcome from "./nx-welcome"; +<% } %> const StyledApp = styled.div` // Your style here @@ -16,7 +18,14 @@ export function App() { <% } %> return ( + <% if (!minimal) { %> + <% } else { %> +

+ Hello there, + Welcome <%= projectName %> 👋 +

+ <% } %>
); <% if (classComponent) { %> diff --git a/packages/react/src/generators/application/lib/create-application-files.ts b/packages/react/src/generators/application/lib/create-application-files.ts index db25f808c6..cea05f609c 100644 --- a/packages/react/src/generators/application/lib/create-application-files.ts +++ b/packages/react/src/generators/application/lib/create-application-files.ts @@ -54,6 +54,16 @@ export function createApplicationFiles(host: Tree, options: NormalizedSchema) { `${options.appProjectRoot}/src/app/${options.fileName}.spec.tsx` ); } + + if (!options.minimal) { + generateFiles( + host, + join(__dirname, '../files/nx-welcome'), + options.appProjectRoot, + templateVariables + ); + } + generateFiles( host, join(__dirname, styleSolutionSpecificAppFiles), diff --git a/packages/react/src/generators/application/lib/normalize-options.ts b/packages/react/src/generators/application/lib/normalize-options.ts index 6a821f0549..900d7fc263 100644 --- a/packages/react/src/generators/application/lib/normalize-options.ts +++ b/packages/react/src/generators/application/lib/normalize-options.ts @@ -75,6 +75,7 @@ export function normalizeOptions( normalized.e2eTestRunner = normalized.e2eTestRunner ?? 'cypress'; normalized.inSourceTests = normalized.minimal || normalized.inSourceTests; normalized.devServerPort ??= findFreePort(host); + normalized.minimal = normalized.minimal ?? false; return normalized; } diff --git a/packages/react/src/generators/host/files/common/src/app/__fileName__.tsx__tmpl__ b/packages/react/src/generators/host/files/common/src/app/__fileName__.tsx__tmpl__ index 2bda4c58b3..00edc49cc2 100644 --- a/packages/react/src/generators/host/files/common/src/app/__fileName__.tsx__tmpl__ +++ b/packages/react/src/generators/host/files/common/src/app/__fileName__.tsx__tmpl__ @@ -1,5 +1,7 @@ import * as React from 'react'; +<% if (!minimal) { %> import NxWelcome from "./nx-welcome"; +<% } %> import { Link, Route, Routes } from 'react-router-dom'; <% if (remotes.length > 0) { %> @@ -17,7 +19,9 @@ export function App() { <% }); %> + <% if (!minimal) { %> } /> + <% } %> <% remotes.forEach(function(r) { %> />} /> <% }); %> diff --git a/packages/react/src/generators/host/schema.d.ts b/packages/react/src/generators/host/schema.d.ts index 7b1e41554c..c43a7f9418 100644 --- a/packages/react/src/generators/host/schema.d.ts +++ b/packages/react/src/generators/host/schema.d.ts @@ -22,6 +22,7 @@ export interface Schema { style: SupportedStyles; tags?: string; unitTestRunner: 'jest' | 'vitest' | 'none'; + minimal?: boolean; } export interface NormalizedSchema extends Schema { diff --git a/packages/react/src/generators/host/schema.json b/packages/react/src/generators/host/schema.json index cdd62f72ed..ba6adf0f57 100644 --- a/packages/react/src/generators/host/schema.json +++ b/packages/react/src/generators/host/schema.json @@ -162,6 +162,11 @@ "description": "Whether to configure SSR for the host application", "type": "boolean", "default": false + }, + "minimal": { + "description": "Generate a React app with a minimal setup. No nx starter template.", + "type": "boolean", + "default": false } }, "required": ["name"],