fix(angular): ensure apps/libs layout is created when migrating from angular cli to nx monorepo layout (#13577)
This commit is contained in:
parent
63820a9e50
commit
2dd2eeae63
@ -284,19 +284,17 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
|
||||
// Restore e2e directory
|
||||
runCommand('mv e2e-bak e2e');
|
||||
|
||||
// TODO: this functionality is currently broken, this validation doesn't exist
|
||||
// // Remove src
|
||||
// runCommand('mv src src-bak');
|
||||
// expect(() => runNgAdd('@nrwl/angular', '--npm-scope projscope --skip-install')).toThrow(
|
||||
// 'Path: src does not exist'
|
||||
// );
|
||||
// Remove src
|
||||
runCommand('mv src src-bak');
|
||||
expect(() =>
|
||||
runNgAdd('@nrwl/angular', '--npm-scope projscope --skip-install')
|
||||
).toThrow('The project source root "src" could not be found.');
|
||||
|
||||
// // Put src back
|
||||
// runCommand('mv src-bak src');
|
||||
// Put src back
|
||||
runCommand('mv src-bak src');
|
||||
});
|
||||
|
||||
//TODO: reenable
|
||||
xit('should handle a workspace with cypress v9', () => {
|
||||
it('should handle a workspace with cypress v9', () => {
|
||||
addCypress9();
|
||||
|
||||
// Remove cypress.json
|
||||
@ -383,8 +381,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
|
||||
});
|
||||
});
|
||||
|
||||
//TODO: reenable
|
||||
xit('should handle a workspace with cypress v10', () => {
|
||||
it('should handle a workspace with cypress v10', () => {
|
||||
addCypress10();
|
||||
|
||||
// Remove cypress.config.ts
|
||||
|
||||
@ -269,6 +269,101 @@ describe('workspace', () => {
|
||||
expect(prettierIgnore).toBe('# existing ignore rules');
|
||||
});
|
||||
|
||||
it('should generate .gitkeep file in apps directory when there are no applications', async () => {
|
||||
tree.write('projects/lib1/README.md', '');
|
||||
tree.write('projects/lib1/src/public-api.ts', '');
|
||||
writeJson(tree, 'angular.json', {
|
||||
$schema: './node_modules/@angular/cli/lib/config/schema.json',
|
||||
version: 1,
|
||||
defaultProject: 'lib1',
|
||||
newProjectRoot: 'projects',
|
||||
projects: {
|
||||
lib1: {
|
||||
root: 'projects/lib1',
|
||||
sourceRoot: 'projects/lib1/src',
|
||||
projectType: 'library',
|
||||
architect: {
|
||||
build: {
|
||||
builder: '@angular-devkit/build-angular:ng-packagr',
|
||||
options: { tsConfig: 'projects/lib1/tsconfig.lib.json' },
|
||||
},
|
||||
test: {
|
||||
builder: '@angular-devkit/build-angular:karma',
|
||||
options: { tsConfig: 'projects/lib1/tsconfig.spec.json' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await migrateFromAngularCli(tree, {});
|
||||
|
||||
expect(tree.exists('apps/.gitkeep')).toBe(true);
|
||||
});
|
||||
|
||||
it('should not generate .gitkeep file in apps directory when there is at least one application', async () => {
|
||||
await migrateFromAngularCli(tree, {});
|
||||
|
||||
expect(tree.exists('apps/.gitkeep')).toBe(false);
|
||||
});
|
||||
|
||||
it('should generate .gitkeep file in libs directory when there are no libraries', async () => {
|
||||
await migrateFromAngularCli(tree, {});
|
||||
|
||||
expect(tree.exists('libs/.gitkeep')).toBe(true);
|
||||
});
|
||||
|
||||
it('should not generate .gitkeep file in libs directory when there is at least one library', async () => {
|
||||
tree.write('projects/lib1/README.md', '');
|
||||
tree.write('projects/lib1/src/public-api.ts', '');
|
||||
writeJson(tree, 'angular.json', {
|
||||
$schema: './node_modules/@angular/cli/lib/config/schema.json',
|
||||
version: 1,
|
||||
defaultProject: 'app1',
|
||||
newProjectRoot: 'projects',
|
||||
projects: {
|
||||
app1: {
|
||||
root: '',
|
||||
sourceRoot: 'src',
|
||||
projectType: 'application',
|
||||
architect: {
|
||||
build: {
|
||||
builder: '@angular-devkit/build-angular:browser',
|
||||
options: { tsConfig: 'tsconfig.app.json' },
|
||||
},
|
||||
test: {
|
||||
builder: '@angular-devkit/build-angular:karma',
|
||||
options: { tsConfig: 'tsconfig.spec.json' },
|
||||
},
|
||||
e2e: {
|
||||
builder: '@angular-devkit/build-angular:protractor',
|
||||
options: { protractorConfig: 'e2e/protractor.conf.js' },
|
||||
},
|
||||
},
|
||||
},
|
||||
lib1: {
|
||||
root: 'projects/lib1',
|
||||
sourceRoot: 'projects/lib1/src',
|
||||
projectType: 'library',
|
||||
architect: {
|
||||
build: {
|
||||
builder: '@angular-devkit/build-angular:ng-packagr',
|
||||
options: { tsConfig: 'projects/lib1/tsconfig.lib.json' },
|
||||
},
|
||||
test: {
|
||||
builder: '@angular-devkit/build-angular:karma',
|
||||
options: { tsConfig: 'projects/lib1/tsconfig.spec.json' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await migrateFromAngularCli(tree, {});
|
||||
|
||||
expect(tree.exists('libs/.gitkeep')).toBe(false);
|
||||
});
|
||||
|
||||
it('should create a root eslint config', async () => {
|
||||
await migrateFromAngularCli(tree, {});
|
||||
|
||||
|
||||
@ -3,9 +3,7 @@ import {
|
||||
addDependenciesToPackageJson,
|
||||
installPackagesTask,
|
||||
readJson,
|
||||
readWorkspaceConfiguration,
|
||||
updateJson,
|
||||
updateWorkspaceConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { convertToNxProjectGenerator } from '@nrwl/workspace/generators';
|
||||
import { prettierVersion } from '@nrwl/workspace/src/utils/versions';
|
||||
@ -20,6 +18,7 @@ import {
|
||||
createWorkspaceFiles,
|
||||
decorateAngularCli,
|
||||
deleteAngularJson,
|
||||
deleteGitKeepFilesIfNotNeeded,
|
||||
formatFilesTask,
|
||||
getAllProjects,
|
||||
getWorkspaceRootFileTypesInfo,
|
||||
@ -119,6 +118,8 @@ export async function migrateFromAngularCli(
|
||||
updateRootEsLintConfig(tree, eslintConfig, options.unitTestRunner);
|
||||
cleanupEsLintPackages(tree);
|
||||
}
|
||||
|
||||
deleteGitKeepFilesIfNotNeeded(tree);
|
||||
}
|
||||
|
||||
deleteAngularJson(tree);
|
||||
|
||||
@ -400,3 +400,12 @@ export function deleteAngularJson(tree: Tree): void {
|
||||
}
|
||||
tree.delete('angular.json');
|
||||
}
|
||||
|
||||
export function deleteGitKeepFilesIfNotNeeded(tree: Tree): void {
|
||||
if (tree.children('apps').length > 1 && tree.exists('apps/.gitkeep')) {
|
||||
tree.delete('apps/.gitkeep');
|
||||
}
|
||||
if (tree.children('libs').length > 1 && tree.exists('libs/.gitkeep')) {
|
||||
tree.delete('libs/.gitkeep');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user