feat(angular): add preserveAngularCLILayout option to ng-add
This commit is contained in:
parent
690be207be
commit
48d953e4d7
@ -293,22 +293,6 @@ forEachCli('angular', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO(FrozenPandaz): reenable after angular 9
|
|
||||||
xit('should convert a project with common libraries in the ecosystem', () => {
|
|
||||||
// create a new AngularCLI app
|
|
||||||
runNew();
|
|
||||||
|
|
||||||
// Add some Angular libraries
|
|
||||||
runNgAdd('add @angular/elements');
|
|
||||||
runNgAdd('add @angular/material');
|
|
||||||
runNgAdd('add @angular/pwa');
|
|
||||||
runNgAdd('add @ngrx/store');
|
|
||||||
runNgAdd('add @ngrx/effects');
|
|
||||||
|
|
||||||
// Add Nx
|
|
||||||
runNgAdd('add @nrwl/workspace --skip-install');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle different types of errors', () => {
|
it('should handle different types of errors', () => {
|
||||||
// create a new AngularCLI app
|
// create a new AngularCLI app
|
||||||
runNew();
|
runNew();
|
||||||
@ -353,6 +337,18 @@ forEachCli('angular', () => {
|
|||||||
// Put src back
|
// Put src back
|
||||||
runCommand('mv src-bak src');
|
runCommand('mv src-bak src');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support preserveAngularCLILayout', () => {
|
||||||
|
runNew('', false, false);
|
||||||
|
runNgAdd('add @nrwl/workspace --preserveAngularCLILayout');
|
||||||
|
|
||||||
|
const updatedAngularCLIJson = readJson('angular.json');
|
||||||
|
expect(updatedAngularCLIJson.projects.proj.root).toEqual('');
|
||||||
|
expect(updatedAngularCLIJson.projects.proj.sourceRoot).toEqual('src');
|
||||||
|
|
||||||
|
const output = runCLI('build');
|
||||||
|
expect(output).toContain(`> ng run proj:build`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ describe('workspace', () => {
|
|||||||
appTree = new UnitTestTree(Tree.empty());
|
appTree = new UnitTestTree(Tree.empty());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('move to nx layout', () => {
|
||||||
it('should error if no package.json is present', async () => {
|
it('should error if no package.json is present', async () => {
|
||||||
try {
|
try {
|
||||||
await runSchematic('ng-add', { name: 'myApp' }, appTree);
|
await runSchematic('ng-add', { name: 'myApp' }, appTree);
|
||||||
@ -228,3 +229,38 @@ describe('workspace', () => {
|
|||||||
expect(tree.exists('/karma.conf.js')).toBe(true);
|
expect(tree.exists('/karma.conf.js')).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('preserve angular cli layout', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
appTree.create('/package.json', JSON.stringify({ devDependencies: {} }));
|
||||||
|
appTree.create(
|
||||||
|
'/angular.json',
|
||||||
|
JSON.stringify({ projects: { myproj: {} } })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update package.json', async () => {
|
||||||
|
const tree = await runSchematic(
|
||||||
|
'ng-add',
|
||||||
|
{ preserveAngularCLILayout: true },
|
||||||
|
appTree
|
||||||
|
);
|
||||||
|
|
||||||
|
const d = JSON.parse(tree.readContent('/package.json')).devDependencies;
|
||||||
|
expect(d['@nrwl/workspace']).toBeDefined();
|
||||||
|
expect(d['@nrwl/angular']).not.toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create nx.json', async () => {
|
||||||
|
const tree = await runSchematic(
|
||||||
|
'ng-add',
|
||||||
|
{ preserveAngularCLILayout: true },
|
||||||
|
appTree
|
||||||
|
);
|
||||||
|
|
||||||
|
const nxJson = JSON.parse(tree.readContent('/nx.json'));
|
||||||
|
expect(nxJson.projects).toEqual({ myproj: { tags: [] } });
|
||||||
|
expect(nxJson.npmScope).toEqual('myproj');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import {
|
|||||||
renameSyncInTree,
|
renameSyncInTree,
|
||||||
renameDirSyncInTree,
|
renameDirSyncInTree,
|
||||||
addInstallTask,
|
addInstallTask,
|
||||||
|
addDepsToPackageJson,
|
||||||
} from '@nrwl/workspace';
|
} from '@nrwl/workspace';
|
||||||
import { DEFAULT_NRWL_PRETTIER_CONFIG } from '../workspace/workspace';
|
import { DEFAULT_NRWL_PRETTIER_CONFIG } from '../workspace/workspace';
|
||||||
import { JsonArray } from '@angular-devkit/core';
|
import { JsonArray } from '@angular-devkit/core';
|
||||||
@ -557,7 +558,49 @@ function checkCanConvertToWorkspace(options: Schema) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createNxJson = (host: Tree) => {
|
||||||
|
const json = JSON.parse(host.read('angular.json').toString());
|
||||||
|
if (Object.keys(json.projects || {}).length !== 1) {
|
||||||
|
throw new Error(
|
||||||
|
`The schematic can only be used with Angular CLI workspaces with a single project.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const name = Object.keys(json.projects)[0];
|
||||||
|
host.create(
|
||||||
|
'nx.json',
|
||||||
|
serializeJson({
|
||||||
|
npmScope: name,
|
||||||
|
implicitDependencies: {
|
||||||
|
'angular.json': '*',
|
||||||
|
'package.json': '*',
|
||||||
|
'tsconfig.json': '*',
|
||||||
|
'tslint.json': '*',
|
||||||
|
'nx.json': '*',
|
||||||
|
},
|
||||||
|
projects: {
|
||||||
|
[name]: {
|
||||||
|
tags: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tasksRunnerOptions: {
|
||||||
|
default: {
|
||||||
|
runner: '@nrwl/workspace/tasks-runners/default',
|
||||||
|
options: {
|
||||||
|
cacheableOperations: ['build', 'lint', 'test', 'e2e'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default function (schema: Schema): Rule {
|
export default function (schema: Schema): Rule {
|
||||||
|
if (schema.preserveAngularCLILayout) {
|
||||||
|
return chain([
|
||||||
|
addDepsToPackageJson({}, { '@nrwl/workspace': nxVersion }),
|
||||||
|
createNxJson,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
const options = {
|
const options = {
|
||||||
...schema,
|
...schema,
|
||||||
npmScope: toFileName(schema.npmScope || schema.name),
|
npmScope: toFileName(schema.npmScope || schema.name),
|
||||||
@ -581,3 +624,4 @@ export default function (schema: Schema): Rule {
|
|||||||
addInstallTask(options),
|
addInstallTask(options),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -2,4 +2,5 @@ export interface Schema {
|
|||||||
name: string;
|
name: string;
|
||||||
skipInstall: boolean;
|
skipInstall: boolean;
|
||||||
npmScope?: string;
|
npmScope?: string;
|
||||||
|
preserveAngularCLILayout: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,11 @@
|
|||||||
"description": "Skip installing after adding @nrwl/workspace",
|
"description": "Skip installing after adding @nrwl/workspace",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
"preserveAngularCLILayout": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Preserve the Angular CLI layout instead of moving the app into apps.",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Project name.",
|
"description": "Project name.",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user