Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 59a72be

Browse files
Update dependencies (#99)
* Update dependencies * Change @types/node version * Check ng version * fix lint * refactoring
1 parent e310617 commit 59a72be

File tree

9 files changed

+277
-1819
lines changed

9 files changed

+277
-1819
lines changed

package-lock.json

Lines changed: 128 additions & 1711 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "devextreme-schematics",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "DevExtreme schematics",
55
"scripts": {
66
"build": "tsc -p tsconfig.json",
@@ -21,16 +21,16 @@
2121
],
2222
"schematics": "./src/collection.json",
2323
"dependencies": {
24-
"@angular-devkit/core": "^7.1.4",
25-
"@angular-devkit/schematics": "^7.1.4",
26-
"@schematics/angular": "^7.1.4",
27-
"rxjs": "^6.3.3"
24+
"@angular-devkit/core": "^8.0.0",
25+
"@angular-devkit/schematics": "^8.0.0",
26+
"@schematics/angular": "^8.0.0",
27+
"rxjs": "~6.4.0",
28+
"typescript": "3.4.5"
2829
},
2930
"devDependencies": {
30-
"@types/jasmine": "^2.8.14",
31+
"@types/jasmine": "^3.3.8",
3132
"@types/node": "^8.10.39",
3233
"jasmine": "^2.8.0",
33-
"tslint": "^5.12.0",
34-
"typescript": "3.1.3"
34+
"tslint": "^5.15.0"
3535
}
3636
}

src/add-app-template/index_spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@ const angularSchematicsCollection = require.resolve('../../node_modules/@schemat
2424
const schematicRunner = new SchematicTestRunner('@schematics/angular', angularSchematicsCollection);
2525
let appTree: UnitTestTree;
2626

27-
beforeEach(() => {
28-
appTree = schematicRunner.runSchematic('workspace', workspaceOptions);
29-
appTree = schematicRunner.runSchematic('application', appOptions, appTree);
27+
beforeEach(async () => {
28+
appTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
29+
appTree = await schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
3030
});
3131

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

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

41-
it('should consider the `project` option', () => {
42-
appTree = schematicRunner.runSchematic('application', {
41+
it('should consider the `project` option', async () => {
42+
appTree = await schematicRunner.runSchematicAsync('application', {
4343
name: 'testApp2',
4444
inlineStyle: false,
4545
inlineTemplate: false,
4646
routing: true,
4747
style: 'scss',
4848
projectRoot: 'projects/testApp2'
49-
}, appTree);
49+
}, appTree).toPromise();
5050

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

5656
expect(tree.files)
5757
.toContain('/devextreme.json');
@@ -61,9 +61,9 @@ describe('add-app-template', () => {
6161
.toContain('/projects/testApp2/src/app/pages/home/home.component.ts');
6262
});
6363

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

6868
const angularContent = JSON.parse(tree.readContent('/angular.json'));
6969
const budgets = angularContent.projects.testApp.architect.build.configurations.production.budgets;

src/add-layout/files/src/app/shared/components/side-navigation-menu/side-navigation-menu.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as events from 'devextreme/events';
99
styleUrls: ['./side-navigation-menu.component.scss']
1010
})
1111
export class SideNavigationMenuComponent implements AfterViewInit, OnDestroy {
12-
@ViewChild(DxTreeViewComponent)
12+
@ViewChild(DxTreeViewComponent<% if(requireStaticFlag) { %>, { static: true }<% } %>)
1313
menu: DxTreeViewComponent;
1414

1515
@Output()

src/add-layout/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import {
1414
template
1515
} from '@angular-devkit/schematics';
1616

17+
import {
18+
getPackageJsonDependency
19+
} from '@schematics/angular/utility/dependencies';
20+
1721
import { of } from 'rxjs';
1822

1923
import {
@@ -73,6 +77,7 @@ import { Change } from '@schematics/angular/utility/change';
7377

7478
const projectFilesSource = './files/src';
7579
const workspaceFilesSource = './files';
80+
const ngRequireStaticFlag = /^(\W*[8-9][0-9]*)/;
7681

7782
function addScriptSafe(scripts: any, name: string, value: string) {
7883
const currentValue = scripts[name];
@@ -328,7 +333,17 @@ export default function(options: any): Rule {
328333
const override = options.resolveConflicts === 'override';
329334
const componentName = override ? 'app' : getComponentName(host, appPath);
330335
const pathToCss = sourcePath.replace(/\/?(\w)+\/?/g, '../');
331-
const templateOptions = { name: componentName, layout, title, strings, path: pathToCss, prefix };
336+
const ngVersion = getPackageJsonDependency(host, '@angular/core')!.version;
337+
const templateOptions = {
338+
name: componentName,
339+
layout,
340+
title,
341+
strings,
342+
path: pathToCss,
343+
prefix,
344+
// https://github.com/angular/angular/blob/master/CHANGELOG.md#800-2019-05-28
345+
requireStaticFlag: ngRequireStaticFlag.test(ngVersion)
346+
};
332347

333348
const modifyContent = (templateContent: string, currentContent: string, filePath: string) => {
334349
if (basename(filePath) === 'styles.scss') {

src/add-layout/index_spec.ts

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
22
import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema';
3+
import {
4+
NodeDependencyType,
5+
addPackageJsonDependency,
6+
removePackageJsonDependency
7+
} from '@schematics/angular/utility/dependencies';
38
import * as path from 'path';
49

510
import { modifyJSONFile } from '../utility/modify-json-file';
@@ -32,14 +37,14 @@ describe('layout', () => {
3237
const schematicRunner = new SchematicTestRunner('@schematics/angular', angularSchematicsCollection);
3338
let appTree: UnitTestTree;
3439

35-
beforeEach(() => {
36-
appTree = schematicRunner.runSchematic('workspace', workspaceOptions);
37-
appTree = schematicRunner.runSchematic('application', appOptions, appTree);
40+
beforeEach(async () => {
41+
appTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
42+
appTree = await schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
3843
});
3944

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

4449
expect(tree.files)
4550
.toContain('/devextreme.json');
@@ -106,17 +111,37 @@ describe('layout', () => {
106111
expect(appContent).toContain('styleUrls: [\'./app.component.scss\']');
107112
expect(appContent).toContain('selector: \'app-root\',');
108113
expect(appContent).toContain(`import { AuthService, ScreenService, AppInfoService } from './shared/services';`);
114+
115+
const navigationMenu = tree.readContent(
116+
'/src/app/shared/components/side-navigation-menu/side-navigation-menu.component.ts');
117+
expect(navigationMenu).toContain('@ViewChild(DxTreeViewComponent, { static: true })');
109118
});
110119

111-
it('should add npm scripts', () => {
120+
it('should add npm scripts', async () => {
112121
const runner = new SchematicTestRunner('schematics', collectionPath);
113-
const tree = runner.runSchematic('add-layout', options, appTree);
122+
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
114123
const packageConfig = JSON.parse(tree.readContent('package.json'));
115124
expect(packageConfig.scripts['build-themes']).toBe('devextreme build');
116125
expect(packageConfig.scripts['postinstall']).toBe('npm run build-themes');
117126
});
118127

119-
it('should add npm scripts safely', () => {
128+
it('should set static flag', async () => {
129+
removePackageJsonDependency(appTree, '@angular/core');
130+
addPackageJsonDependency(appTree, {
131+
type: NodeDependencyType.Default,
132+
name: '@angular/core',
133+
version: '7.0.0'
134+
});
135+
136+
const runner = new SchematicTestRunner('schematics', collectionPath);
137+
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
138+
const navigationMenu = tree.readContent(
139+
'/src/app/shared/components/side-navigation-menu/side-navigation-menu.component.ts');
140+
141+
expect(navigationMenu).toContain('@ViewChild(DxTreeViewComponent)');
142+
});
143+
144+
it('should add npm scripts safely', async () => {
120145
modifyJSONFile(appTree, './package.json', config => {
121146
const scripts = config['scripts'];
122147

@@ -127,28 +152,28 @@ describe('layout', () => {
127152
});
128153

129154
const runner = new SchematicTestRunner('schematics', collectionPath);
130-
const tree = runner.runSchematic('add-layout', options, appTree);
155+
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
131156
const packageConfig = JSON.parse(tree.readContent('package.json'));
132157
expect(packageConfig.scripts['origin-build-themes']).toBe('prev value 1');
133158
expect(packageConfig.scripts['origin-postinstall']).toBe('prev value 2');
134159
expect(packageConfig.scripts['build-themes']).toBe('npm run origin-build-themes && devextreme build');
135160
expect(packageConfig.scripts['postinstall']).toBe('npm run origin-postinstall && npm run build-themes');
136161
});
137162

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

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

146-
it('should update budgets if updateBudgets option is true', () => {
171+
it('should update budgets if updateBudgets option is true', async () => {
147172
const runner = new SchematicTestRunner('schematics', collectionPath);
148-
const tree = runner.runSchematic('add-layout', {
173+
const tree = await runner.runSchematicAsync('add-layout', {
149174
...options,
150175
updateBudgets: true
151-
}, appTree);
176+
}, appTree).toPromise();
152177

153178
const angularContent = JSON.parse(tree.readContent('/angular.json'));
154179
const budgets = angularContent.projects.testApp.architect.build.configurations.production.budgets;
@@ -161,9 +186,9 @@ describe('layout', () => {
161186
});
162187
});
163188

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

168193
const angularContent = JSON.parse(tree.readContent('/angular.json'));
169194
const budgets = angularContent.projects.testApp.architect.build.configurations.production.budgets;
@@ -177,11 +202,11 @@ describe('layout', () => {
177202
expect(budgets[0]).toEqual(defaultBudget);
178203
});
179204

180-
it('should add layout without override', () => {
205+
it('should add layout without override', async () => {
181206
const runner = new SchematicTestRunner('schematics', collectionPath);
182207

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

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

@@ -201,14 +226,15 @@ describe('layout', () => {
201226
expect(appInfo).toContain(`return 'TestApp';`);
202227
});
203228

204-
it('should add routing to layout', () => {
205-
let newAppTree = schematicRunner.runSchematic('workspace', workspaceOptions);
229+
it('should add routing to layout', async () => {
230+
let newAppTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
206231

207232
appOptions.routing = false;
208-
newAppTree = schematicRunner.runSchematic('application', appOptions, newAppTree);
233+
newAppTree = await schematicRunner.runSchematicAsync(
234+
'application', appOptions, newAppTree).toPromise();
209235

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

213239
expect(tree.files).toContain('/src/app/app-routing.module.ts');
214240
const moduleContent = tree.readContent('/src/app/app-routing.module.ts');
@@ -223,49 +249,49 @@ describe('layout', () => {
223249
}`);
224250
});
225251

226-
it('should use selected layout', () => {
252+
it('should use selected layout', async () => {
227253
const runner = new SchematicTestRunner('schematics', collectionPath);
228254
options.layout = 'side-nav-inner-toolbar';
229255
options.resolveConflicts = 'override';
230-
const tree = runner.runSchematic('add-layout', options, appTree);
256+
const tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
231257
const content = tree.readContent('/src/app/app.component.html');
232258

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

236-
it('should consider the `project` option', () => {
237-
appTree = schematicRunner.runSchematic('application', {
262+
it('should consider the `project` option', async () => {
263+
appTree = await schematicRunner.runSchematicAsync('application', {
238264
...appOptions,
239265
name: 'testApp2',
240266
projectRoot: 'projects/testApp2'
241-
}, appTree);
267+
}, appTree).toPromise();
242268

243269
const runner = new SchematicTestRunner('schematics', collectionPath);
244-
const tree = runner.runSchematic('add-layout', {
270+
const tree = await runner.runSchematicAsync('add-layout', {
245271
...options,
246272
project: 'testApp2'
247-
}, appTree);
273+
}, appTree).toPromise();
248274

249275
expect(tree.files)
250276
.toContain('/devextreme.json');
251277
expect(tree.files)
252278
.toContain('/projects/testApp2/src/themes/metadata.base.json');
253279
});
254280

255-
it('should merge build commands in devextreme.json file', () => {
256-
appTree = schematicRunner.runSchematic('application', {
281+
it('should merge build commands in devextreme.json file', async () => {
282+
appTree = await schematicRunner.runSchematicAsync('application', {
257283
...appOptions,
258284
name: 'testApp2',
259285
prefix: 'app2',
260286
projectRoot: 'projects/testApp2'
261-
}, appTree);
287+
}, appTree).toPromise();
262288

263289
const runner = new SchematicTestRunner('schematics', collectionPath);
264-
let tree = runner.runSchematic('add-layout', options, appTree);
265-
tree = runner.runSchematic('add-layout', {
290+
let tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
291+
tree = await runner.runSchematicAsync('add-layout', {
266292
...options,
267293
project: 'testApp2'
268-
}, appTree);
294+
}, appTree).toPromise();
269295

270296
const appContent = tree.readContent('projects/testApp2/src/app/app.component.ts');
271297
expect(appContent).toContain('selector: \'app2-root\',');
@@ -275,19 +301,19 @@ describe('layout', () => {
275301
expect(content).toContain('"inputFile": "projects/testApp2/src/themes/metadata.base.json",');
276302
});
277303

278-
it('should add e2e tests only for default project', () => {
279-
appTree = schematicRunner.runSchematic('application', {
304+
it('should add e2e tests only for default project', async () => {
305+
appTree = await schematicRunner.runSchematicAsync('application', {
280306
...appOptions,
281307
name: 'testApp2',
282308
projectRoot: 'projects/testApp2'
283-
}, appTree);
309+
}, appTree).toPromise();
284310

285311
const runner = new SchematicTestRunner('schematics', collectionPath);
286-
let tree = runner.runSchematic('add-layout', options, appTree);
287-
tree = runner.runSchematic('add-layout', {
312+
let tree = await runner.runSchematicAsync('add-layout', options, appTree).toPromise();
313+
tree = await runner.runSchematicAsync('add-layout', {
288314
...options,
289315
project: 'testApp2'
290-
}, appTree);
316+
}, appTree).toPromise();
291317

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

src/add-sample-views/index_spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ describe('sample views', () => {
2929
const schematicRunner = new SchematicTestRunner('@schematics/angular', angularSchematicsCollection);
3030
let appTree: UnitTestTree;
3131

32-
beforeEach(() => {
33-
appTree = schematicRunner.runSchematic('workspace', workspaceOptions);
34-
appTree = schematicRunner.runSchematic('application', appOptions, appTree);
32+
beforeEach(async () => {
33+
appTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
34+
appTree = await schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
3535
});
3636

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

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

0 commit comments

Comments
 (0)