Skip to content

Commit

Permalink
Update angular schematics to 16.2.10 (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomodasheesh committed May 17, 2024
1 parent 6abc677 commit ee61248
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const latestVersions = require('../utility/latest-versions');
const { extractToolingVersion, toolingVersionOptionName } = require('../utility/extract-tooling-version');
const schematicsVersion = latestVersions['devextreme-schematics'] || 'latest';

const minNgCliVersion = new semver('12.0.0');
const minNgCliVersion = new semver('16.0.0');
const ngCliWithStandalone = new semver('17.0.0');

async function runSchematicCommand(schematicCommand, options, evaluatingOptions) {
Expand Down
584 changes: 354 additions & 230 deletions packages/devextreme-schematics/package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions packages/devextreme-schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
],
"schematics": "./src/collection.json",
"dependencies": {
"@angular-devkit/core": "^12.2.18",
"@angular-devkit/schematics": "^12.2.18",
"@schematics/angular": "^12.2.18"
"@angular-devkit/core": "^16.2.10",
"@angular-devkit/schematics": "^16.2.10",
"@schematics/angular": "^16.2.10"
},
"devDependencies": {
"@types/jasmine": "~3.10.18",
"@types/node": "ts4.3",
"@types/node": "ts4.9",
"@types/semver": "^7.5.7",
"jasmine": "^2.99.0",
"rxjs": "^6.6.7",
"tslint": "^5.20.1",
"typescript": "^4.3.1"
"typescript": "^4.9.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ const schematicRunner = new SchematicTestRunner('@schematics/angular', angularSc
let appTree: UnitTestTree;

beforeEach(async () => {
appTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
appTree = await schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
appTree = await schematicRunner.runSchematic('workspace', workspaceOptions);
appTree = await schematicRunner.runSchematic('application', appOptions, appTree);
});

describe('add-app-template', () => {
it('should add DevExtreme', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-app-template', { }, appTree).toPromise();
const tree = await runner.runSchematic('add-app-template', { }, appTree);
const packageConfig = JSON.parse(tree.readContent('package.json'));

expect('devextreme' in packageConfig.dependencies).toBe(true);
});

it('should consider the `project` option', async () => {
appTree = await schematicRunner.runSchematicAsync('application', {
appTree = await schematicRunner.runSchematic('application', {
name: 'testApp2',
inlineStyle: false,
inlineTemplate: false,
routing: true,
style: 'scss',
projectRoot: 'projects/testApp2'
}, appTree).toPromise();
}, appTree);

const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-app-template', {
const tree = await runner.runSchematic('add-app-template', {
project: 'testApp2'
}, appTree).toPromise();
}, appTree);

expect(tree.files)
.toContain('/devextreme.json');
Expand All @@ -63,7 +63,7 @@ describe('add-app-template', () => {

it('should consider the `updateBudgets` option', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-app-template', { updateBudgets: true }, appTree).toPromise();
const tree = await runner.runSchematic('add-app-template', { updateBudgets: true }, appTree);

const angularContent = JSON.parse(tree.readContent('/angular.json'));
const budgets = angularContent.projects.testApp.architect.build.configurations.production.budgets;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/schema",
"$id": "SchematicsDevextremeAddAppTemplate",
"title": "Add a DevExtreme layout template to an Anular application",
"title": "Add a DevExtreme layout template to an Angular application",
"type": "object",
"properties": {
"layout": {
Expand Down Expand Up @@ -43,7 +43,7 @@
},
"globalNgCliVersion": {
"type":"string",
"default": "^12.0.0"
"default": "^16.2.0"
},
"empty": {
"type": "boolean",
Expand Down
10 changes: 0 additions & 10 deletions packages/devextreme-schematics/src/add-layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {

import {
modifyJSONFile,
parseJson
} from '../utility/modify-json-file';

import {
Expand Down Expand Up @@ -318,8 +317,6 @@ const modifyRoutingModule = (host: Tree, routingModulePath: string) => {

export default function(options: any): Rule {
return async (host: Tree) => {
const ngConfig = host.read('./angular.json')!.toString();
const defaultProjectName = parseJson(ngConfig).defaultProject;
const project = await getProjectName(host, options.project);
const workspace = await getWorkspace(host);
const ngProject = workspace.projects.get(project);
Expand Down Expand Up @@ -373,13 +370,6 @@ export default function(options: any): Rule {
});
}

if (override) {
if (project === defaultProjectName) {
rules.push(modifyContentByTemplate('./', workspaceFilesSource, 'e2e/src/app.e2e-spec.ts', { title }));
rules.push(modifyContentByTemplate('./', workspaceFilesSource, 'e2e/src/app.po.ts'));
}
}

return chain(rules);
};
}
90 changes: 33 additions & 57 deletions packages/devextreme-schematics/src/add-layout/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,30 @@ describe('layout', () => {

const workspaceOptions: WorkspaceOptions = {
name: 'workspace',
version: '6.0.0'
version: '16.0.0'
};

const options: any = {
layout: 'side-nav-outer-toolbar',
resolveConflicts: 'override',
globalNgCliVersion: '^12.2.0'
globalNgCliVersion: '^16.2.0'
};

const angularSchematicsCollection = require.resolve('../../node_modules/@schematics/angular/collection.json');
const schematicRunner = new SchematicTestRunner('@schematics/angular', angularSchematicsCollection);
const schematicRunner = new SchematicTestRunner(
'@schematics/angular',
angularSchematicsCollection,
);
let appTree: UnitTestTree;

beforeEach(async () => {
appTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
appTree = await schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
appTree = await schematicRunner.runSchematic('workspace', workspaceOptions);
appTree = await schematicRunner.runSchematic('application', appOptions, appTree);
});

it('should add layout with override', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);

expect(tree.files)
.toContain('/devextreme.json');
Expand Down Expand Up @@ -108,12 +111,6 @@ describe('layout', () => {
'ChangePasswordFormModule, ' +
'LoginFormModule }');

const testContent = tree.readContent('/e2e/src/app.e2e-spec.ts');
expect(testContent).toMatch(/'Welcome to TestApp!'/);

const testUtilsContent = tree.readContent('/e2e/src/app.po.ts');
expect(testUtilsContent).toMatch(/'app-root .dx-drawer-content .dx-card p:nth-child\(2\)'/);

const appContent = tree.readContent('/src/app/app.component.ts');
expect(appContent).toContain('templateUrl: \'./app.component.html\',');
expect(appContent).toContain('styleUrls: [\'./app.component.scss\']');
Expand All @@ -127,7 +124,7 @@ describe('layout', () => {

it('should add npm scripts', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);
const packageConfig = JSON.parse(tree.readContent('package.json'));
expect(packageConfig.scripts['build-themes']).toBe('devextreme build');
expect(packageConfig.scripts['postinstall']).toBe('npm run build-themes');
Expand All @@ -142,7 +139,7 @@ describe('layout', () => {
});

const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);
const navigationMenu = tree.readContent(
'/src/app/shared/components/side-navigation-menu/side-navigation-menu.component.ts');

Expand All @@ -160,7 +157,7 @@ describe('layout', () => {
});

const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);
const packageConfig = JSON.parse(tree.readContent('package.json'));
expect(packageConfig.scripts['origin-build-themes']).toBe('prev value 1');
expect(packageConfig.scripts['origin-postinstall']).toBe('prev value 2');
Expand All @@ -170,26 +167,26 @@ describe('layout', () => {

it('should add angular/cdk dependency', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);
const packageConfig = JSON.parse(tree.readContent('package.json'));

expect(packageConfig.dependencies['@angular/cdk']).toBeDefined();
});

it('should choose angular/cdk version such as angular/cli', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);
const packageConfig = JSON.parse(tree.readContent('package.json'));

expect(packageConfig.dependencies['@angular/cdk']).toBe('~12.2.0');
expect(packageConfig.dependencies['@angular/cdk']).toBe('~16.2.0');
});

it('should update budgets if updateBudgets option is true', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', {
const tree = await runner.runSchematic('add-layout', {
...options,
updateBudgets: true
}, appTree).toPromise();
}, appTree);

const angularContent = JSON.parse(tree.readContent('/angular.json'));
const budgets = angularContent.projects.testApp.architect.build.configurations.production.budgets;
Expand All @@ -204,7 +201,7 @@ describe('layout', () => {

it('should not update budgets if updateBudgets option is not defined or false', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);

const angularContent = JSON.parse(tree.readContent('/angular.json'));
const budgets = angularContent.projects.testApp.architect.build.configurations.production.budgets;
Expand All @@ -222,7 +219,7 @@ describe('layout', () => {
const runner = new SchematicTestRunner('schematics', collectionPath);

options.resolveConflicts = 'createNew';
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);

expect(tree.files).toContain('/src/app/app1.component.ts');

Expand All @@ -243,14 +240,14 @@ describe('layout', () => {
});

it('should add routing to layout', async () => {
let newAppTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
let newAppTree = await schematicRunner.runSchematic('workspace', workspaceOptions);

appOptions.routing = false;
newAppTree = await schematicRunner.runSchematicAsync(
'application', appOptions, newAppTree).toPromise();
newAppTree = await schematicRunner.runSchematic(
'application', appOptions, newAppTree);

const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);

expect(tree.files).toContain('/src/app/app-routing.module.ts');
const moduleContent = tree.readContent('/src/app/app-routing.module.ts');
Expand All @@ -269,24 +266,24 @@ describe('layout', () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
options.layout = 'side-nav-inner-toolbar';
options.resolveConflicts = 'override';
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
const tree = await runner.runSchematic('add-layout', options, appTree);
const content = tree.readContent('/src/app/app.component.html');

expect(content).toContain('app-side-nav-inner-toolbar title="{{appInfo.title}}"');
});

it('should consider the `project` option', async () => {
appTree = await schematicRunner.runSchematicAsync('application', {
appTree = await schematicRunner.runSchematic('application', {
...appOptions,
name: 'testApp2',
projectRoot: 'projects/testApp2'
}, appTree).toPromise();
}, appTree);

const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('add-layout', {
const tree = await runner.runSchematic('add-layout', {
...options,
project: 'testApp2'
}, appTree).toPromise();
}, appTree);

expect(tree.files)
.toContain('/devextreme.json');
Expand All @@ -295,19 +292,19 @@ describe('layout', () => {
});

it('should merge build commands in devextreme.json file', async () => {
appTree = await schematicRunner.runSchematicAsync('application', {
appTree = await schematicRunner.runSchematic('application', {
...appOptions,
name: 'testApp2',
prefix: 'app2',
projectRoot: 'projects/testApp2'
}, appTree).toPromise();
}, appTree);

const runner = new SchematicTestRunner('schematics', collectionPath);
let tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
tree = await runner.runSchematicAsync('add-layout', {
let tree = await runner.runSchematic('add-layout', options, appTree);
tree = await runner.runSchematic('add-layout', {
...options,
project: 'testApp2'
}, appTree).toPromise();
}, appTree);

const appContent = tree.readContent('projects/testApp2/src/app/app.component.ts');
expect(appContent).toContain('selector: \'app2-root\',');
Expand All @@ -316,25 +313,4 @@ describe('layout', () => {
expect(content).toContain('"inputFile": "src/themes/metadata.base.json",');
expect(content).toContain('"inputFile": "projects/testApp2/src/themes/metadata.base.json",');
});

it('should add e2e tests only for default project', async () => {
appTree = await schematicRunner.runSchematicAsync('application', {
...appOptions,
name: 'testApp2',
projectRoot: 'projects/testApp2'
}, appTree).toPromise();

const runner = new SchematicTestRunner('schematics', collectionPath);
let tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
tree = await runner.runSchematicAsync('add-layout', {
...options,
project: 'testApp2'
}, appTree).toPromise();

const testContent = tree.readContent('/e2e/src/app.e2e-spec.ts');
expect(testContent).toContain('Welcome to TestApp!');

const testUtilsContent = tree.readContent('/e2e/src/app.po.ts');
expect(testUtilsContent).toMatch(/'app-root .dx-drawer-content .dx-card p:nth-child\(2\)'/);
});
});
2 changes: 1 addition & 1 deletion packages/devextreme-schematics/src/add-layout/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"globalNgCliVersion": {
"type":"string",
"default": "12.2.0"
"default": "16.2.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ describe('sample views', () => {
let appTree: UnitTestTree;

beforeEach(async () => {
appTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
appTree = await schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
appTree = await schematicRunner.runSchematic('workspace', workspaceOptions);
appTree = await schematicRunner.runSchematic('application', appOptions, appTree);
});

it('should add sample views', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
let tree = await runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
tree = await runner.runSchematicAsync('add-sample-views', sampleViewsOptions, tree).toPromise();
let tree = await runner.runSchematic('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree);
tree = await runner.runSchematic('add-sample-views', sampleViewsOptions, tree);

const moduleContent = tree.readContent('/src/app/app-routing.module.ts');

Expand Down

0 comments on commit ee61248

Please sign in to comment.