devextreme-schematics 1.3.0-beta.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +10 -8
- package/src/add-app-template/index.js +2 -1
- package/src/add-app-template/index.js.map +1 -1
- package/src/add-app-template/index.ts +30 -0
- package/src/add-app-template/index_spec.js +6 -5
- package/src/add-app-template/index_spec.js.map +1 -1
- package/src/add-app-template/index_spec.ts +73 -0
- package/src/add-app-template/schema.json +7 -3
- package/src/add-layout/files/devextreme.json +1 -1
- package/src/add-layout/files/src/app/__name__.component.html +3 -3
- package/src/add-layout/files/src/app/__name__.component.ts +1 -1
- package/src/add-layout/files/src/app/app-routing.module.ts +1 -1
- package/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.ts +13 -11
- package/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.ts +10 -9
- package/src/add-layout/files/src/app/layouts/single-card/single-card.component.ts +4 -4
- package/src/add-layout/files/src/app/not-authorized-container.ts +2 -0
- package/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.html +8 -6
- package/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.ts +6 -15
- package/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.html +9 -7
- package/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.ts +4 -13
- package/src/add-layout/files/src/app/shared/components/header/header.component.ts +11 -6
- package/src/add-layout/files/src/app/shared/components/login-form/login-form.component.html +8 -6
- package/src/add-layout/files/src/app/shared/components/login-form/login-form.component.ts +2 -12
- package/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.html +8 -6
- package/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.ts +2 -12
- package/src/add-layout/files/src/app/shared/components/side-navigation-menu/side-navigation-menu.component.ts +8 -7
- package/src/add-layout/files/src/app/shared/components/user-panel/user-panel.component.html +5 -2
- package/src/add-layout/files/src/app/shared/components/user-panel/user-panel.component.ts +3 -2
- package/src/add-layout/files/src/app/shared/services/auth.service.ts +11 -5
- package/src/add-layout/files/src/app/shared/services/screen.service.ts +2 -2
- package/src/add-layout/files/src/app/unauthenticated-content.ts +53 -0
- package/src/add-layout/files/src/dx-styles.scss +4 -0
- package/src/add-layout/index.js +45 -31
- package/src/add-layout/index.js.map +1 -1
- package/src/add-layout/index.ts +384 -0
- package/src/add-layout/index_spec.js +42 -28
- package/src/add-layout/index_spec.js.map +1 -1
- package/src/add-layout/index_spec.ts +340 -0
- package/src/add-layout/schema.json +6 -2
- package/src/add-sample-views/files/pages/home/home.component.html +5 -5
- package/src/add-sample-views/files/pages/profile/profile.component.ts +1 -1
- package/src/add-sample-views/files/pages/tasks/tasks.component.html +1 -0
- package/src/add-sample-views/index.js +13 -4
- package/src/add-sample-views/index.js.map +1 -1
- package/src/add-sample-views/index.ts +141 -0
- package/src/add-sample-views/index_spec.js +5 -4
- package/src/add-sample-views/index_spec.js.map +1 -1
- package/src/add-sample-views/index_spec.ts +74 -0
- package/src/add-sample-views/schema.json +1 -1
- package/src/add-view/index.d.ts +2 -2
- package/src/add-view/index.js +33 -22
- package/src/add-view/index.js.map +1 -1
- package/src/add-view/index.ts +166 -0
- package/src/add-view/index_spec.js +12 -12
- package/src/add-view/index_spec.js.map +1 -1
- package/src/add-view/index_spec.ts +155 -0
- package/src/add-view/schema.json +4 -4
- package/src/collection.json +2 -1
- package/src/install/index.js +16 -3
- package/src/install/index.js.map +1 -1
- package/src/install/index.ts +88 -0
- package/src/install/index_spec.js +10 -9
- package/src/install/index_spec.js.map +1 -1
- package/src/install/index_spec.ts +106 -0
- package/src/install/schema.json +2 -2
- package/src/utility/array.js +1 -0
- package/src/utility/array.js.map +1 -1
- package/src/utility/array.ts +3 -0
- package/src/utility/change.js +1 -0
- package/src/utility/change.js.map +1 -1
- package/src/utility/change.ts +66 -0
- package/src/utility/latest-versions.d.ts +1 -1
- package/src/utility/latest-versions.js +3 -2
- package/src/utility/latest-versions.js.map +1 -1
- package/src/utility/latest-versions.ts +6 -0
- package/src/utility/modify-json-file.d.ts +1 -0
- package/src/utility/modify-json-file.js +7 -3
- package/src/utility/modify-json-file.js.map +1 -1
- package/src/utility/modify-json-file.ts +16 -0
- package/src/utility/project.d.ts +4 -4
- package/src/utility/project.js +35 -12
- package/src/utility/project.js.map +1 -1
- package/src/utility/project.ts +30 -0
- package/src/utility/routing.js +1 -0
- package/src/utility/routing.js.map +1 -1
- package/src/utility/routing.ts +44 -0
- package/src/utility/source.js +1 -0
- package/src/utility/source.js.map +1 -1
- package/src/utility/source.ts +16 -0
- package/src/utility/string.js +1 -0
- package/src/utility/string.js.map +1 -1
- package/src/utility/string.ts +5 -0
- package/src/utility/styles.d.ts +1 -2
- package/src/utility/styles.js +3 -4
- package/src/utility/styles.js.map +1 -1
- package/src/utility/styles.ts +30 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
|
2
|
+
import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema';
|
3
|
+
import * as path from 'path';
|
4
|
+
|
5
|
+
const collectionPath = path.join(__dirname, '../collection.json');
|
6
|
+
|
7
|
+
describe('sample views', () => {
|
8
|
+
const appOptions: any = {
|
9
|
+
name: 'testApp',
|
10
|
+
projectRoot: '',
|
11
|
+
inlineStyle: false,
|
12
|
+
inlineTemplate: false,
|
13
|
+
routing: true,
|
14
|
+
style: 'css',
|
15
|
+
skipTests: false,
|
16
|
+
skipPackageJson: false
|
17
|
+
};
|
18
|
+
|
19
|
+
const workspaceOptions: WorkspaceOptions = {
|
20
|
+
name: 'workspace',
|
21
|
+
version: '6.0.0'
|
22
|
+
};
|
23
|
+
|
24
|
+
const sampleViewsOptions: any = {
|
25
|
+
project: 'testApp'
|
26
|
+
};
|
27
|
+
|
28
|
+
const angularSchematicsCollection = require.resolve('../../node_modules/@schematics/angular/collection.json');
|
29
|
+
const schematicRunner = new SchematicTestRunner('@schematics/angular', angularSchematicsCollection);
|
30
|
+
let appTree: UnitTestTree;
|
31
|
+
|
32
|
+
beforeEach(async () => {
|
33
|
+
appTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
|
34
|
+
appTree = await schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
|
35
|
+
});
|
36
|
+
|
37
|
+
it('should add sample views', async () => {
|
38
|
+
const runner = new SchematicTestRunner('schematics', collectionPath);
|
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();
|
41
|
+
|
42
|
+
const moduleContent = tree.readContent('/src/app/app-routing.module.ts');
|
43
|
+
|
44
|
+
expect(moduleContent).toMatch(/component: HomeComponent/);
|
45
|
+
expect(moduleContent).toMatch(/path: 'home'/);
|
46
|
+
|
47
|
+
expect(moduleContent).toMatch(/import { HomeComponent } from /);
|
48
|
+
expect(moduleContent).toMatch(/declarations:\s\[\n*\s*HomeComponent/);
|
49
|
+
|
50
|
+
const navigationContent = tree.readContent('/src/app/app-navigation.ts');
|
51
|
+
expect(navigationContent).toMatch(/text: 'Home'/);
|
52
|
+
expect(navigationContent).toContain(`export const navigation = [
|
53
|
+
{
|
54
|
+
text: 'Home',
|
55
|
+
path: '/home',
|
56
|
+
icon: 'home'
|
57
|
+
},
|
58
|
+
{
|
59
|
+
text: 'Examples',
|
60
|
+
icon: 'folder',
|
61
|
+
items: [
|
62
|
+
{
|
63
|
+
text: 'Profile',
|
64
|
+
path: '/profile'
|
65
|
+
},
|
66
|
+
{
|
67
|
+
text: 'Tasks',
|
68
|
+
path: '/tasks'
|
69
|
+
}
|
70
|
+
]
|
71
|
+
}
|
72
|
+
];`);
|
73
|
+
});
|
74
|
+
});
|
package/src/add-view/index.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { Rule } from '@angular-devkit/schematics';
|
2
|
-
export declare function addViewToRouting(options: any): (host:
|
1
|
+
import { Rule, Tree } from '@angular-devkit/schematics';
|
2
|
+
export declare function addViewToRouting(options: any): (host: Tree) => Promise<import("@angular-devkit/schematics/src/tree/interface").Tree>;
|
3
3
|
export default function (options: any): Rule;
|
package/src/add-view/index.js
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.addViewToRouting = void 0;
|
3
13
|
const schematics_1 = require("@angular-devkit/schematics");
|
4
14
|
const find_module_1 = require("@schematics/angular/utility/find-module");
|
5
15
|
const change_1 = require("../utility/change");
|
@@ -9,18 +19,20 @@ const core_1 = require("@angular-devkit/core");
|
|
9
19
|
const project_1 = require("../utility/project");
|
10
20
|
const string_1 = require("../utility/string");
|
11
21
|
function getPathToFile(host, projectName, moduleName) {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
23
|
+
const rootPath = yield project_1.getApplicationPath(host, projectName);
|
24
|
+
try {
|
25
|
+
return find_module_1.findModuleFromOptions(host, { name: moduleName, path: rootPath, module: moduleName });
|
26
|
+
}
|
27
|
+
catch (error) {
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
});
|
19
31
|
}
|
20
32
|
function addViewToNavigation(options) {
|
21
|
-
return (host) => {
|
33
|
+
return (host) => __awaiter(this, void 0, void 0, function* () {
|
22
34
|
const navigationName = 'app-navigation';
|
23
|
-
const navigationFilePath = getPathToFile(host, options.project, navigationName);
|
35
|
+
const navigationFilePath = yield getPathToFile(host, options.project, navigationName);
|
24
36
|
if (!navigationFilePath) {
|
25
37
|
return;
|
26
38
|
}
|
@@ -35,7 +47,7 @@ function addViewToNavigation(options) {
|
|
35
47
|
}`;
|
36
48
|
change_1.insertItemToArray(host, navigationFilePath, source, navigationItem, { location: 'end' });
|
37
49
|
return host;
|
38
|
-
};
|
50
|
+
});
|
39
51
|
}
|
40
52
|
function addRedirectRoute(host, routingModulePath, page) {
|
41
53
|
const source = source_1.getSourceFile(host, routingModulePath);
|
@@ -46,14 +58,13 @@ function addRedirectRoute(host, routingModulePath, page) {
|
|
46
58
|
const routes = routing_1.findRoutesInSource(source);
|
47
59
|
const redirectRoute = ` {
|
48
60
|
path: '**',
|
49
|
-
redirectTo: '${core_1.strings.dasherize(page)}'
|
50
|
-
canActivate: [ AuthGuardService ]
|
61
|
+
redirectTo: '${core_1.strings.dasherize(page)}'
|
51
62
|
}`;
|
52
63
|
change_1.insertItemToArray(host, routingModulePath, routes, redirectRoute, { location: 'end' });
|
53
64
|
}
|
54
65
|
function addViewToRouting(options) {
|
55
|
-
return (host) => {
|
56
|
-
const routingModulePath = getPathToFile(host, options.project, options.module);
|
66
|
+
return (host) => __awaiter(this, void 0, void 0, function* () {
|
67
|
+
const routingModulePath = yield getPathToFile(host, options.project, options.module);
|
57
68
|
if (!routingModulePath) {
|
58
69
|
throw new schematics_1.SchematicsException('Specified module does not exist.');
|
59
70
|
}
|
@@ -68,7 +79,7 @@ function addViewToRouting(options) {
|
|
68
79
|
change_1.insertItemToArray(host, routingModulePath, routes, route);
|
69
80
|
}
|
70
81
|
return host;
|
71
|
-
};
|
82
|
+
});
|
72
83
|
}
|
73
84
|
exports.addViewToRouting = addViewToRouting;
|
74
85
|
function getPathForView(name) {
|
@@ -84,11 +95,11 @@ function getModuleName(addRoute, moduleName) {
|
|
84
95
|
return moduleName;
|
85
96
|
}
|
86
97
|
function addContentToView(options) {
|
87
|
-
return (host) => {
|
98
|
+
return (host) => __awaiter(this, void 0, void 0, function* () {
|
88
99
|
const name = core_1.strings.dasherize(core_1.basename(core_1.normalize(options.name)));
|
89
100
|
const path = `${core_1.dirname(options.name)}/${name}`;
|
90
101
|
const title = string_1.humanize(name);
|
91
|
-
const componentPath = `/${project_1.getApplicationPath(host, options.project)}${path}/${name}.component.html`;
|
102
|
+
const componentPath = `/${yield project_1.getApplicationPath(host, options.project)}${path}/${name}.component.html`;
|
92
103
|
if (host.exists(componentPath)) {
|
93
104
|
host.overwrite(componentPath, `<h2 class="content-block">${title}</h2>
|
94
105
|
<div class="content-block">
|
@@ -97,19 +108,19 @@ function addContentToView(options) {
|
|
97
108
|
`);
|
98
109
|
}
|
99
110
|
return host;
|
100
|
-
};
|
111
|
+
});
|
101
112
|
}
|
102
113
|
function default_1(options) {
|
103
|
-
return (host) => {
|
114
|
+
return (host) => __awaiter(this, void 0, void 0, function* () {
|
104
115
|
const addRoute = options.addRoute;
|
105
|
-
const project = project_1.getProjectName(host, options);
|
116
|
+
const project = yield project_1.getProjectName(host, options);
|
106
117
|
const module = getModuleName(addRoute, options.module);
|
107
118
|
const name = getPathForView(options.name);
|
108
119
|
const rules = [schematics_1.externalSchematic('@schematics/angular', 'component', {
|
109
120
|
name,
|
110
121
|
project,
|
111
122
|
module,
|
112
|
-
|
123
|
+
skipTests: options.skipTests,
|
113
124
|
inlineStyle: options.inlineStyle,
|
114
125
|
prefix: options.prefix
|
115
126
|
}),
|
@@ -120,7 +131,7 @@ function default_1(options) {
|
|
120
131
|
rules.push(addViewToNavigation({ name, icon: options.icon, project }));
|
121
132
|
}
|
122
133
|
return schematics_1.chain(rules);
|
123
|
-
};
|
134
|
+
});
|
124
135
|
}
|
125
136
|
exports.default = default_1;
|
126
137
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAMoC;AAEpC,yEAEiD;AAEjD,8CAE2B;AAE3B,gDAI4B;AAE5B,8CAAkD;AAElD,+CAA6E;AAE7E,gDAG4B;AAC5B,8CAA6C;AAE7C,SAAe,aAAa,CAAC,IAAU,EAAE,WAAmB,EAAE,UAAkB;;QAC9E,MAAM,QAAQ,GAAG,MAAM,4BAAkB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAE7D,IAAI;YACF,OAAO,mCAAqB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;SAC9F;QAAC,OAAO,KAAK,EAAE;YACd,OAAO;SACR;IACH,CAAC;CAAA;AAED,SAAS,mBAAmB,CAAC,OAAY;IACvC,OAAO,CAAO,IAAU,EAAE,EAAE;QAC1B,MAAM,cAAc,GAAG,gBAAgB,CAAC;QACxC,MAAM,kBAAkB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAEtF,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO;SACR;QAED,MAAM,MAAM,GAAG,sBAAa,CAAC,IAAI,EAAE,kBAAkB,CAAE,CAAC;QACxD,MAAM,QAAQ,GAAG,cAAO,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,cAAO,CAAC,SAAS,CAAC,eAAQ,CAAC,gBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,iBAAQ,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,cAAc,GAAG;aACd,KAAK;cACJ,QAA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'@angular-devkit/schematics';
|
8
|
+
|
9
|
+
import {
|
10
|
+
findModuleFromOptions
|
11
|
+
} from '@schematics/angular/utility/find-module';
|
12
|
+
|
13
|
+
import {
|
14
|
+
insertItemToArray
|
15
|
+
} from '../utility/change';
|
16
|
+
|
17
|
+
import {
|
18
|
+
hasComponentInRoutes,
|
19
|
+
getRoute,
|
20
|
+
findRoutesInSource
|
21
|
+
} from '../utility/routing';
|
22
|
+
|
23
|
+
import { getSourceFile } from '../utility/source';
|
24
|
+
|
25
|
+
import { strings, basename, normalize, dirname } from '@angular-devkit/core';
|
26
|
+
|
27
|
+
import {
|
28
|
+
getProjectName,
|
29
|
+
getApplicationPath
|
30
|
+
} from '../utility/project';
|
31
|
+
import { humanize } from '../utility/string';
|
32
|
+
|
33
|
+
async function getPathToFile(host: Tree, projectName: string, moduleName: string) {
|
34
|
+
const rootPath = await getApplicationPath(host, projectName);
|
35
|
+
|
36
|
+
try {
|
37
|
+
return findModuleFromOptions(host, { name: moduleName, path: rootPath, module: moduleName });
|
38
|
+
} catch (error) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
function addViewToNavigation(options: any) {
|
44
|
+
return async (host: Tree) => {
|
45
|
+
const navigationName = 'app-navigation';
|
46
|
+
const navigationFilePath = await getPathToFile(host, options.project, navigationName);
|
47
|
+
|
48
|
+
if (!navigationFilePath) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
const source = getSourceFile(host, navigationFilePath)!;
|
53
|
+
const pagePath = strings.dasherize(options.name);
|
54
|
+
const name = strings.dasherize(basename(normalize(options.name)));
|
55
|
+
const title = humanize(name);
|
56
|
+
const navigationItem = ` {
|
57
|
+
text: '${title}',
|
58
|
+
path: '/${pagePath}',
|
59
|
+
icon: '${options.icon}'
|
60
|
+
}`;
|
61
|
+
|
62
|
+
insertItemToArray(host, navigationFilePath, source, navigationItem, { location: 'end' });
|
63
|
+
|
64
|
+
return host;
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
function addRedirectRoute(host: Tree, routingModulePath: string, page: string) {
|
69
|
+
const source = getSourceFile(host, routingModulePath)!;
|
70
|
+
const content = source.getText();
|
71
|
+
if (content.match(/path:\s*'\*\*'/g)) {
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
|
75
|
+
const routes = findRoutesInSource(source)!;
|
76
|
+
const redirectRoute = ` {
|
77
|
+
path: '**',
|
78
|
+
redirectTo: '${strings.dasherize(page)}'
|
79
|
+
}`;
|
80
|
+
|
81
|
+
insertItemToArray(host, routingModulePath, routes, redirectRoute, { location: 'end' });
|
82
|
+
}
|
83
|
+
|
84
|
+
export function addViewToRouting(options: any) {
|
85
|
+
return async (host: Tree) => {
|
86
|
+
const routingModulePath = await getPathToFile(host, options.project, options.module);
|
87
|
+
|
88
|
+
if (!routingModulePath) {
|
89
|
+
throw new SchematicsException('Specified module does not exist.');
|
90
|
+
}
|
91
|
+
|
92
|
+
addRedirectRoute(host, routingModulePath, options.name);
|
93
|
+
|
94
|
+
const source = getSourceFile(host, routingModulePath)!;
|
95
|
+
const routes = findRoutesInSource(source);
|
96
|
+
|
97
|
+
if (!routes) {
|
98
|
+
throw new SchematicsException('No routes found.');
|
99
|
+
}
|
100
|
+
|
101
|
+
if (!hasComponentInRoutes(routes, options.name)) {
|
102
|
+
const route = getRoute(options.name);
|
103
|
+
insertItemToArray(host, routingModulePath, routes, route);
|
104
|
+
}
|
105
|
+
return host;
|
106
|
+
};
|
107
|
+
}
|
108
|
+
|
109
|
+
function getPathForView(name: string) {
|
110
|
+
if (name.includes('/')) {
|
111
|
+
return name;
|
112
|
+
}
|
113
|
+
return 'pages/' + name;
|
114
|
+
}
|
115
|
+
|
116
|
+
function getModuleName(addRoute: boolean, moduleName: string) {
|
117
|
+
if (!moduleName && addRoute) {
|
118
|
+
return 'app-routing';
|
119
|
+
}
|
120
|
+
return moduleName;
|
121
|
+
}
|
122
|
+
|
123
|
+
function addContentToView(options: any) {
|
124
|
+
return async (host: Tree) => {
|
125
|
+
const name = strings.dasherize(basename(normalize(options.name)));
|
126
|
+
const path = `${dirname(options.name)}/${name}`;
|
127
|
+
const title = humanize(name);
|
128
|
+
const componentPath = `/${await getApplicationPath(host, options.project)}${path}/${name}.component.html`;
|
129
|
+
if (host.exists(componentPath)) {
|
130
|
+
host.overwrite(
|
131
|
+
componentPath,
|
132
|
+
`<h2 class="content-block">${title}</h2>
|
133
|
+
<div class="content-block">
|
134
|
+
<div class="dx-card responsive-paddings">Put your content here</div>
|
135
|
+
</div>
|
136
|
+
`);
|
137
|
+
}
|
138
|
+
return host;
|
139
|
+
};
|
140
|
+
}
|
141
|
+
|
142
|
+
export default function(options: any): Rule {
|
143
|
+
return async (host: Tree) => {
|
144
|
+
const addRoute = options.addRoute;
|
145
|
+
const project = await getProjectName(host, options);
|
146
|
+
const module = getModuleName(addRoute, options.module);
|
147
|
+
const name = getPathForView(options.name);
|
148
|
+
|
149
|
+
const rules = [externalSchematic('@schematics/angular', 'component', {
|
150
|
+
name,
|
151
|
+
project,
|
152
|
+
module,
|
153
|
+
skipTests: options.skipTests,
|
154
|
+
inlineStyle: options.inlineStyle,
|
155
|
+
prefix: options.prefix
|
156
|
+
}),
|
157
|
+
addContentToView({ name, project }) as any
|
158
|
+
];
|
159
|
+
|
160
|
+
if (addRoute) {
|
161
|
+
rules.push(addViewToRouting({ name, project, module }) as any);
|
162
|
+
rules.push(addViewToNavigation({ name, icon: options.icon, project }) as any);
|
163
|
+
}
|
164
|
+
return chain(rules);
|
165
|
+
};
|
166
|
+
}
|
@@ -1,9 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
4
5
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
6
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) :
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
9
|
});
|
9
10
|
};
|
@@ -40,11 +41,11 @@ describe('view', () => {
|
|
40
41
|
const angularSchematicsCollection = require.resolve('../../node_modules/@schematics/angular/collection.json');
|
41
42
|
const schematicRunner = new testing_1.SchematicTestRunner('@schematics/angular', angularSchematicsCollection);
|
42
43
|
let appTree;
|
43
|
-
beforeEach(() => __awaiter(
|
44
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
44
45
|
appTree = yield schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
|
45
46
|
appTree = yield schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
|
46
47
|
}));
|
47
|
-
it('should create new view', () => __awaiter(
|
48
|
+
it('should create new view', () => __awaiter(void 0, void 0, void 0, function* () {
|
48
49
|
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
49
50
|
let tree = yield runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
|
50
51
|
tree = yield runner.runSchematicAsync('add-view', componentOptions, appTree).toPromise();
|
@@ -53,12 +54,12 @@ describe('view', () => {
|
|
53
54
|
const content = tree.readContent('/src/app/pages/test/test.component.html');
|
54
55
|
expect(content).toMatch(/<h2 class="content-block">Test<\/h2>/);
|
55
56
|
}));
|
56
|
-
it('should add view to default routing module', () => __awaiter(
|
57
|
-
const options = Object.assign({}, componentOptions, { addRoute: true });
|
57
|
+
it('should add view to default routing module', () => __awaiter(void 0, void 0, void 0, function* () {
|
58
|
+
const options = Object.assign(Object.assign({}, componentOptions), { addRoute: true });
|
58
59
|
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
59
60
|
let tree = yield runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
|
60
61
|
tree = yield runner.runSchematicAsync('add-view', options, tree).toPromise();
|
61
|
-
tree = yield runner.runSchematicAsync('add-view', Object.assign({}, options, { name: 'test2' }), tree).toPromise();
|
62
|
+
tree = yield runner.runSchematicAsync('add-view', Object.assign(Object.assign({}, options), { name: 'test2' }), tree).toPromise();
|
62
63
|
const moduleContent = tree.readContent('/src/app/app-routing.module.ts');
|
63
64
|
expect(moduleContent).toContain(`const routes: Routes = [
|
64
65
|
{
|
@@ -78,13 +79,12 @@ describe('view', () => {
|
|
78
79
|
},
|
79
80
|
{
|
80
81
|
path: '**',
|
81
|
-
redirectTo: 'pages/test'
|
82
|
-
canActivate: [ AuthGuardService ]
|
82
|
+
redirectTo: 'pages/test'
|
83
83
|
}
|
84
84
|
];`);
|
85
85
|
}));
|
86
|
-
it('should add view to other routing module', () => __awaiter(
|
87
|
-
const options = Object.assign({}, componentOptions, { addRoute: true, module: 'test/test-routing' });
|
86
|
+
it('should add view to other routing module', () => __awaiter(void 0, void 0, void 0, function* () {
|
87
|
+
const options = Object.assign(Object.assign({}, componentOptions), { addRoute: true, module: 'test/test-routing' });
|
88
88
|
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
89
89
|
let tree = yield runner.runExternalSchematicAsync('@schematics/angular', 'module', {
|
90
90
|
name: 'test',
|
@@ -102,7 +102,7 @@ describe('view', () => {
|
|
102
102
|
expect(moduleContent).toMatch(/path: 'pages\/test'/);
|
103
103
|
expect(moduleContent).toContain('canActivate: [ AuthGuardService ]');
|
104
104
|
}));
|
105
|
-
it('should add view to navigation', () => __awaiter(
|
105
|
+
it('should add view to navigation', () => __awaiter(void 0, void 0, void 0, function* () {
|
106
106
|
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
107
107
|
let tree = yield runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
|
108
108
|
tree = yield runner.runSchematicAsync('add-view', componentOptions, tree).toPromise();
|
@@ -129,7 +129,7 @@ describe('view', () => {
|
|
129
129
|
const pageContent = tree.readContent('/src/app/pages/some-test/some-test.component.html');
|
130
130
|
expect(pageContent).toMatch(/<h2 class="content-block">Some Test<\/h2>/);
|
131
131
|
}));
|
132
|
-
it('should create new view with path', () => __awaiter(
|
132
|
+
it('should create new view with path', () => __awaiter(void 0, void 0, void 0, function* () {
|
133
133
|
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
134
134
|
componentOptions.name = 'folder/test';
|
135
135
|
let tree = yield runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index_spec.js","sourceRoot":"","sources":["index_spec.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index_spec.js","sourceRoot":"","sources":["index_spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,gEAAuF;AAEvF,6BAA6B;AAE7B,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAElE,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,MAAM,UAAU,GAAQ;QACtB,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,EAAE;QACf,WAAW,EAAE,KAAK;QAClB,cAAc,EAAE,KAAK;QACrB,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,KAAK;QAChB,eAAe,EAAE,KAAK;KACvB,CAAC;IAEF,MAAM,gBAAgB,GAAqB;QACzC,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,OAAO;KACjB,CAAC;IAEF,MAAM,gBAAgB,GAAQ;QAC5B,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,KAAK;QAClB,cAAc,EAAE,KAAK;QACrB,eAAe,EAAE,SAAS;QAC1B,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,SAAS;QACj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from '@schematics/angular/workspace/schema';
|
3
|
+
import * as path from 'path';
|
4
|
+
|
5
|
+
const collectionPath = path.join(__dirname, '../collection.json');
|
6
|
+
|
7
|
+
describe('view', () => {
|
8
|
+
const appOptions: any = {
|
9
|
+
name: 'testApp',
|
10
|
+
projectRoot: '',
|
11
|
+
inlineStyle: false,
|
12
|
+
inlineTemplate: false,
|
13
|
+
routing: true,
|
14
|
+
style: 'css',
|
15
|
+
skipTests: false,
|
16
|
+
skipPackageJson: false
|
17
|
+
};
|
18
|
+
|
19
|
+
const workspaceOptions: WorkspaceOptions = {
|
20
|
+
name: 'workspace',
|
21
|
+
version: '6.0.0'
|
22
|
+
};
|
23
|
+
|
24
|
+
const componentOptions: any = {
|
25
|
+
name: 'test',
|
26
|
+
inlineStyle: false,
|
27
|
+
inlineTemplate: false,
|
28
|
+
changeDetection: 'Default',
|
29
|
+
styleext: 'css',
|
30
|
+
skipImport: true,
|
31
|
+
module: undefined,
|
32
|
+
export: false,
|
33
|
+
project: 'testApp'
|
34
|
+
};
|
35
|
+
|
36
|
+
const angularSchematicsCollection = require.resolve('../../node_modules/@schematics/angular/collection.json');
|
37
|
+
const schematicRunner = new SchematicTestRunner('@schematics/angular', angularSchematicsCollection);
|
38
|
+
let appTree: UnitTestTree;
|
39
|
+
|
40
|
+
beforeEach(async () => {
|
41
|
+
appTree = await schematicRunner.runSchematicAsync('workspace', workspaceOptions).toPromise();
|
42
|
+
appTree = await schematicRunner.runSchematicAsync('application', appOptions, appTree).toPromise();
|
43
|
+
});
|
44
|
+
|
45
|
+
it('should create new view', async () => {
|
46
|
+
const runner = new SchematicTestRunner('schematics', collectionPath);
|
47
|
+
let tree = await runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
|
48
|
+
tree = await runner.runSchematicAsync('add-view', componentOptions, appTree).toPromise();
|
49
|
+
|
50
|
+
expect(tree.files).toContain('/src/app/pages/test/test.component.ts');
|
51
|
+
expect(tree.files).toContain('/src/app/pages/test/test.component.html');
|
52
|
+
|
53
|
+
const content = tree.readContent('/src/app/pages/test/test.component.html');
|
54
|
+
|
55
|
+
expect(content).toMatch(/<h2 class="content-block">Test<\/h2>/);
|
56
|
+
});
|
57
|
+
|
58
|
+
it('should add view to default routing module', async () => {
|
59
|
+
const options = { ...componentOptions, addRoute: true };
|
60
|
+
|
61
|
+
const runner = new SchematicTestRunner('schematics', collectionPath);
|
62
|
+
let tree = await runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
|
63
|
+
tree = await runner.runSchematicAsync('add-view', options, tree).toPromise();
|
64
|
+
tree = await runner.runSchematicAsync('add-view', { ...options, name: 'test2' }, tree).toPromise();
|
65
|
+
const moduleContent = tree.readContent('/src/app/app-routing.module.ts');
|
66
|
+
|
67
|
+
expect(moduleContent).toContain(`const routes: Routes = [
|
68
|
+
{
|
69
|
+
path: 'pages/test2',
|
70
|
+
component: Test2Component,
|
71
|
+
canActivate: [ AuthGuardService ]
|
72
|
+
},
|
73
|
+
{
|
74
|
+
path: 'pages/test',
|
75
|
+
component: TestComponent,
|
76
|
+
canActivate: [ AuthGuardService ]
|
77
|
+
},
|
78
|
+
{
|
79
|
+
path: 'login-form',
|
80
|
+
component: LoginFormComponent,
|
81
|
+
canActivate: [ AuthGuardService ]
|
82
|
+
},
|
83
|
+
{
|
84
|
+
path: '**',
|
85
|
+
redirectTo: 'pages/test'
|
86
|
+
}
|
87
|
+
];`);
|
88
|
+
});
|
89
|
+
|
90
|
+
it('should add view to other routing module', async () => {
|
91
|
+
const options = { ...componentOptions, addRoute: true, module: 'test/test-routing' };
|
92
|
+
|
93
|
+
const runner = new SchematicTestRunner('schematics', collectionPath);
|
94
|
+
let tree = await runner.runExternalSchematicAsync('@schematics/angular', 'module', {
|
95
|
+
name: 'test',
|
96
|
+
routing: true,
|
97
|
+
project: 'testApp'
|
98
|
+
}, appTree).toPromise();
|
99
|
+
|
100
|
+
tree = await runner.runSchematicAsync('add-layout', {
|
101
|
+
layout: 'side-nav-outer-toolbar',
|
102
|
+
project: 'testApp',
|
103
|
+
name: 'test'
|
104
|
+
}, tree).toPromise();
|
105
|
+
tree = await runner.runSchematicAsync('add-view', options, tree).toPromise();
|
106
|
+
|
107
|
+
const moduleContent = tree.readContent('/src/app/test/test-routing.module.ts');
|
108
|
+
|
109
|
+
expect(moduleContent).toMatch(/component: TestComponent/);
|
110
|
+
expect(moduleContent).toMatch(/path: 'pages\/test'/);
|
111
|
+
expect(moduleContent).toContain('canActivate: [ AuthGuardService ]');
|
112
|
+
});
|
113
|
+
|
114
|
+
it('should add view to navigation', async () => {
|
115
|
+
const runner = new SchematicTestRunner('schematics', collectionPath);
|
116
|
+
let tree = await runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
|
117
|
+
tree = await runner.runSchematicAsync('add-view', componentOptions, tree).toPromise();
|
118
|
+
|
119
|
+
componentOptions.name = 'some test';
|
120
|
+
componentOptions.icon = 'home';
|
121
|
+
tree = await runner.runSchematicAsync('add-view', componentOptions, tree).toPromise();
|
122
|
+
|
123
|
+
const moduleContent = tree.readContent('/src/app/app-navigation.ts');
|
124
|
+
|
125
|
+
expect(moduleContent).toMatch(/text: 'Some Test'/);
|
126
|
+
expect(moduleContent).toMatch(/icon: 'home'/);
|
127
|
+
expect(moduleContent).toMatch(/text: 'Test'/);
|
128
|
+
expect(moduleContent).toMatch(/icon: 'folder'/);
|
129
|
+
|
130
|
+
expect(moduleContent).toContain(`navigation = [
|
131
|
+
{
|
132
|
+
text: 'Test',
|
133
|
+
path: '/pages/test',
|
134
|
+
icon: 'folder'
|
135
|
+
},
|
136
|
+
{
|
137
|
+
text: 'Some Test',
|
138
|
+
path: '/pages/some-test',
|
139
|
+
icon: 'home'
|
140
|
+
}
|
141
|
+
];`);
|
142
|
+
const pageContent = tree.readContent('/src/app/pages/some-test/some-test.component.html');
|
143
|
+
expect(pageContent).toMatch(/<h2 class="content-block">Some Test<\/h2>/);
|
144
|
+
});
|
145
|
+
|
146
|
+
it('should create new view with path', async () => {
|
147
|
+
const runner = new SchematicTestRunner('schematics', collectionPath);
|
148
|
+
componentOptions.name = 'folder/test';
|
149
|
+
let tree = await runner.runSchematicAsync('add-layout', { layout: 'side-nav-outer-toolbar' }, appTree).toPromise();
|
150
|
+
tree = await runner.runSchematicAsync('add-view', componentOptions, appTree).toPromise();
|
151
|
+
|
152
|
+
expect(tree.files).toContain('/src/app/folder/test/test.component.ts');
|
153
|
+
expect(tree.files).toContain('/src/app/folder/test/test.component.html');
|
154
|
+
});
|
155
|
+
});
|