Skip to content

Commit

Permalink
feat(core): new nx starter (nrwl#7912)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcabanes authored Dec 3, 2021
1 parent 125d3a6 commit 66e4e85
Show file tree
Hide file tree
Showing 47 changed files with 5,405 additions and 2,042 deletions.
1 change: 0 additions & 1 deletion .verdaccio/htpasswd
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test:$6FrCaT/v0dwE:autocreated 2020-03-25T19:10:50.254Z
dddd:ZpRSQxtFPtZog:autocreated 2021-08-21T07:57:21.687Z
3 changes: 2 additions & 1 deletion e2e/angular-core/src/angular-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ describe('Angular Package', () => {
names(mylib).className
}Module } from '@${proj}/my-dir/${mylib}';
import { AppComponent } from './app.component';
import { NxWelcomeComponent } from './nx-welcome.component';
@NgModule({
imports: [BrowserModule, MyDir${names(mylib).className}Module],
declarations: [AppComponent],
declarations: [AppComponent, NxWelcomeComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
Expand Down
3 changes: 2 additions & 1 deletion e2e/angular-extensions/src/angular-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ describe('Angular Package', () => {
}Module} from '@${proj}/${buildableLib}';
import { AppComponent } from './app.component';
import { NxWelcomeComponent } from './nx-welcome.component';
@NgModule({
declarations: [AppComponent],
declarations: [AppComponent, NxWelcomeComponent],
imports: [BrowserModule, ${names(buildableLib).className}Module],
providers: [],
bootstrap: [AppComponent],
Expand Down
1 change: 0 additions & 1 deletion e2e/next/src/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ async function checkApp(
const buildResult = runCLI(`build ${appName} --withDeps`);
expect(buildResult).toContain(`Compiled successfully`);
checkFilesExist(`dist/apps/${appName}/.next/build-manifest.json`);
checkFilesExist(`dist/apps/${appName}/public/star.svg`);

const packageJson = readJson(`dist/apps/${appName}/package.json`);
expect(packageJson.dependencies.react).toBeDefined();
Expand Down
24 changes: 17 additions & 7 deletions packages/angular/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('app', () => {
const myAppPrefix = workspaceJson.projects['my-app'].prefix;

expect(myAppPrefix).toEqual('proj');
expect(appE2eSpec).toContain('Welcome to my-app!');
expect(appE2eSpec).toContain('Welcome my-app');
});

it('should set a new prefix and use it', async () => {
Expand All @@ -151,7 +151,7 @@ describe('app', () => {
const myAppPrefix = workspaceJson.projects['my-app-with-prefix'].prefix;

expect(myAppPrefix).toEqual('custom');
expect(appE2eSpec).toContain('Welcome to my-app-with-prefix!');
expect(appE2eSpec).toContain('Welcome my-app-with-prefix');
});

// TODO: this should work
Expand Down Expand Up @@ -289,7 +289,7 @@ describe('app', () => {
await generateApp(appTree, 'myApp', { directory: 'myDir' });
expect(
appTree.read('apps/my-dir/my-app/src/app/app.component.html', 'utf-8')
).toContain('Thank you for using and showing some ♥ for Nx.');
).toContain('<proj-nx-welcome></proj-nx-welcome>');
});

it("should update `template`'s property of AppComponent with Nx content", async () => {
Expand All @@ -299,7 +299,17 @@ describe('app', () => {
});
expect(
appTree.read('apps/my-dir/my-app/src/app/app.component.ts', 'utf-8')
).toContain('Thank you for using and showing some ♥ for Nx.');
).toContain('<proj-nx-welcome></proj-nx-welcome>');
});

it('should create Nx specific `nx-welcome.component.ts` file', async () => {
await generateApp(appTree, 'myApp', { directory: 'myDir' });
expect(
appTree.read(
'apps/my-dir/my-app/src/app/nx-welcome.component.ts',
'utf-8'
)
).toContain('Hello there');
});

it('should update the AppComponent spec to target Nx content', async () => {
Expand All @@ -313,7 +323,7 @@ describe('app', () => {
);

expect(testFileContent).toContain(`querySelector('h1')`);
expect(testFileContent).toContain('Welcome to my-dir-my-app!');
expect(testFileContent).toContain('Welcome my-dir-my-app');
});
});

Expand Down Expand Up @@ -633,7 +643,7 @@ describe('app', () => {

expect(
appTree.read('apps/my-app-e2e/src/app.e2e-spec.ts', 'utf-8')
).toContain(`'Welcome to my-app!'`);
).toContain(`'Welcome my-app'`);
expect(
appTree.read('apps/my-app-e2e/src/app.po.ts', 'utf-8')
).toContain(`'proj-root header h1'`);
Expand All @@ -650,7 +660,7 @@ describe('app', () => {
'apps/my-directory/my-app-e2e/src/app.e2e-spec.ts',
'utf-8'
)
).toContain(`'Welcome to my-directory-my-app!'`);
).toContain(`'Welcome my-directory-my-app'`);
expect(
appTree.read('apps/my-directory/my-app-e2e/src/app.po.ts', 'utf-8')
).toContain(`'proj-root header h1'`);
Expand Down
24 changes: 20 additions & 4 deletions packages/angular/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import init from '../init/init';
import {
createFiles,
normalizeOptions,
updateComponentStyles,
updateComponentTemplate,
updateAppComponentTemplate,
updateNxComponentTemplate,
updateConfigFiles,
addE2e,
updateComponentSpec,
Expand Down Expand Up @@ -78,8 +78,24 @@ export async function applicationGenerator(

moveFilesToNewDirectory(host, appProjectRoot, options.appProjectRoot);
updateConfigFiles(host, options);
updateComponentTemplate(host, options);
updateComponentStyles(host, options);
updateAppComponentTemplate(host, options);

// Create the NxWelcomeComponent
const angularComponentSchematic = wrapAngularDevkitSchematic(
'@schematics/angular',
'component'
);
await angularComponentSchematic(host, {
name: 'NxWelcome',
inlineTemplate: true,
prefix: options.prefix,
skipTests: true,
style: 'none',
flat: true,
viewEncapsulation: 'None',
project: options.name,
});
updateNxComponentTemplate(host, options);

if (options.unitTestRunner !== UnitTestRunner.None) {
updateComponentSpec(host, options);
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/generators/application/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export * from './remove-scaffolded-e2e';
export * from './root-router-config';
export * from './set-app-strict-default';
export * from './update-component-spec';
export * from './update-component-styles';
export * from './update-component-template';
export * from './update-app-component-template';
export * from './update-nx-component-template';
export * from './update-config-files';
export * from './update-e2e-project';
export * from './update-editor-tsconfig';
Loading

0 comments on commit 66e4e85

Please sign in to comment.