fix(angular): set default project if not set when creating an application (#10789)
This commit is contained in:
parent
b215362bdb
commit
ca92b7aa0b
@ -5,6 +5,7 @@ import {
|
|||||||
parseJson,
|
parseJson,
|
||||||
readJson,
|
readJson,
|
||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
|
readWorkspaceConfiguration,
|
||||||
updateJson,
|
updateJson,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||||
@ -204,6 +205,29 @@ describe('app', () => {
|
|||||||
const appTsConfig = readJson(appTree, 'apps/app/tsconfig.json');
|
const appTsConfig = readJson(appTree, 'apps/app/tsconfig.json');
|
||||||
expect(appTsConfig.extends).toBe('../../tsconfig.json');
|
expect(appTsConfig.extends).toBe('../../tsconfig.json');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set default project', async () => {
|
||||||
|
// ACT
|
||||||
|
await generateApp(appTree);
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
const { defaultProject } = readWorkspaceConfiguration(appTree);
|
||||||
|
expect(defaultProject).toBe('my-app');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not overwrite default project if already set', async () => {
|
||||||
|
// ARRANGE
|
||||||
|
const workspace = readWorkspaceConfiguration(appTree);
|
||||||
|
workspace.defaultProject = 'some-awesome-project';
|
||||||
|
devkit.updateWorkspaceConfiguration(appTree, workspace);
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
await generateApp(appTree);
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
const { defaultProject } = readWorkspaceConfiguration(appTree);
|
||||||
|
expect(defaultProject).toBe('some-awesome-project');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('nested', () => {
|
describe('nested', () => {
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {
|
|||||||
enableStrictTypeChecking,
|
enableStrictTypeChecking,
|
||||||
normalizeOptions,
|
normalizeOptions,
|
||||||
setApplicationStrictDefault,
|
setApplicationStrictDefault,
|
||||||
|
setDefaultProject,
|
||||||
updateAppComponentTemplate,
|
updateAppComponentTemplate,
|
||||||
updateComponentSpec,
|
updateComponentSpec,
|
||||||
updateConfigFiles,
|
updateConfigFiles,
|
||||||
@ -106,6 +107,7 @@ export async function applicationGenerator(
|
|||||||
await addUnitTestRunner(host, options);
|
await addUnitTestRunner(host, options);
|
||||||
await addE2e(host, options);
|
await addE2e(host, options);
|
||||||
updateEditorTsConfig(host, options);
|
updateEditorTsConfig(host, options);
|
||||||
|
setDefaultProject(host, options);
|
||||||
|
|
||||||
if (options.backendProject) {
|
if (options.backendProject) {
|
||||||
addProxyConfig(host, options);
|
addProxyConfig(host, options);
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export * from './nrwl-home-tpl';
|
|||||||
export * from './remove-scaffolded-e2e';
|
export * from './remove-scaffolded-e2e';
|
||||||
export * from './root-router-config';
|
export * from './root-router-config';
|
||||||
export * from './set-app-strict-default';
|
export * from './set-app-strict-default';
|
||||||
|
export * from './set-default-project';
|
||||||
export * from './update-component-spec';
|
export * from './update-component-spec';
|
||||||
export * from './update-app-component-template';
|
export * from './update-app-component-template';
|
||||||
export * from './update-nx-component-template';
|
export * from './update-nx-component-template';
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
import type { Tree } from '@nrwl/devkit';
|
||||||
|
import {
|
||||||
|
readWorkspaceConfiguration,
|
||||||
|
updateWorkspaceConfiguration,
|
||||||
|
} from '@nrwl/devkit';
|
||||||
|
import type { NormalizedSchema } from './normalized-schema';
|
||||||
|
|
||||||
|
export function setDefaultProject(tree: Tree, options: NormalizedSchema): void {
|
||||||
|
const workspace = readWorkspaceConfiguration(tree);
|
||||||
|
|
||||||
|
if (!workspace.defaultProject) {
|
||||||
|
workspace.defaultProject = options.name;
|
||||||
|
updateWorkspaceConfiguration(tree, workspace);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user