cleanup(misc): formatter changes

This commit is contained in:
Jeremy Forsythe 2020-08-14 19:42:21 -04:00 committed by Jo Hanna Pearce
parent fb01c409bd
commit a4d0f11e73
2 changed files with 22 additions and 16 deletions

View File

@ -66,9 +66,9 @@ describe('updateWorkspace Rule', () => {
it('should delete the project', async () => {
let workspace = JSON.parse(tree.read('workspace.json').toString());
expect(workspace.projects['ng-app']).toBeDefined();
tree = (await callRule(updateWorkspace(schema), tree)) as UnitTestTree;
workspace = JSON.parse(tree.read('workspace.json').toString());
expect(workspace.projects['ng-app']).toBeUndefined();
});
@ -136,12 +136,12 @@ describe('updateWorkspace Rule', () => {
skipFormat: false,
forceRemove: false,
};
let workspace = JSON.parse(tree.read('workspace.json').toString());
expect(workspace.defaultProject).toBeDefined();
tree = (await callRule(updateWorkspace(schema), tree)) as UnitTestTree;
workspace = JSON.parse(tree.read('workspace.json').toString());
expect(workspace.defaultProject).toBeUndefined();
});
@ -155,12 +155,11 @@ describe('updateWorkspace Rule', () => {
let workspace = JSON.parse(tree.read('workspace.json').toString());
expect(workspace.defaultProject).toBeDefined();
tree = (await callRule(updateWorkspace(schema), tree)) as UnitTestTree;
workspace = JSON.parse(tree.read('workspace.json').toString());
expect(workspace.defaultProject).toBeDefined();
});
});
});

View File

@ -8,13 +8,20 @@ import { updateWorkspaceInTree, getWorkspacePath } from '@nrwl/workspace';
* @param schema The options provided to the schematic
*/
export function updateWorkspace(schema: Schema) {
return updateWorkspaceInTree((workspace, context: SchematicContext, host: Tree) => {
delete workspace.projects[schema.projectName];
if (workspace.defaultProject && workspace.defaultProject === schema.projectName) {
delete workspace.defaultProject;
const workspacePath = getWorkspacePath(host);
context.logger.warn(`Default project was removed in ${workspacePath} because it was "${schema.projectName}". If you want a default project you should define a new one.`);
return updateWorkspaceInTree(
(workspace, context: SchematicContext, host: Tree) => {
delete workspace.projects[schema.projectName];
if (
workspace.defaultProject &&
workspace.defaultProject === schema.projectName
) {
delete workspace.defaultProject;
const workspacePath = getWorkspacePath(host);
context.logger.warn(
`Default project was removed in ${workspacePath} because it was "${schema.projectName}". If you want a default project you should define a new one.`
);
}
return workspace;
}
return workspace;
});
);
}