Skip to content

Commit f1267ff

Browse files
Add standalone flag to ts module of new view
1 parent 9db5d71 commit f1267ff

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

packages/devextreme-schematics/src/add-view/index.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,50 @@ function getModuleName(addRoute: boolean, moduleName: string) {
120120
return moduleName;
121121
}
122122

123-
function addContentToView(options: any) {
123+
function overwriteModuleContent(options: any, path: string, content: string) {
124124
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`;
125+
const componentPath = `/${await getApplicationPath(host, options.project)}${path}`;
129126
if (host.exists(componentPath)) {
130-
host.overwrite(
131-
componentPath,
132-
`<h2>${title}</h2>
133-
<div class="content-block">
134-
<div class="dx-card responsive-paddings">Put your content here</div>
135-
</div>
136-
`);
127+
host.overwrite(componentPath, content);
137128
}
138129
return host;
139130
};
140131
}
141132

133+
function addContentToView(options: any) {
134+
const name = strings.dasherize(basename(normalize(options.name)));
135+
const path = `${dirname(options.name)}/${name}`;
136+
const title = humanize(name);
137+
const componentPath = `${path}/${name}.component.html`;
138+
const content = `<h2>${title}</h2>
139+
<div class="content-block">
140+
<div class="dx-card responsive-paddings">Put your content here</div>
141+
</div>
142+
`;
143+
144+
return overwriteModuleContent(options, componentPath, content);
145+
}
146+
147+
async function addContentToTS(options: any) {
148+
const name = strings.dasherize(basename(normalize(options.name)));
149+
const path = `${dirname(options.name)}/${name}`;
150+
const componentPath = `${path}/${name}.component.ts`;
151+
const content = `import { Component } from '@angular/core';
152+
153+
@Component({
154+
selector: 'app-new-page',
155+
templateUrl: './new-page.component.html',
156+
styleUrl: './new-page.component.css',
157+
standalone: false
158+
})
159+
export class NewPageComponent {
160+
161+
}
162+
`;
163+
164+
return overwriteModuleContent(options, componentPath, content);
165+
}
166+
142167
export default function(options: any): Rule {
143168
return async (host: Tree) => {
144169
const addRoute = options.addRoute;
@@ -155,7 +180,8 @@ export default function(options: any): Rule {
155180
prefix: options.prefix,
156181
standalone: false
157182
}),
158-
addContentToView({ name, project }) as any
183+
addContentToView({ name, project }) as any,
184+
addContentToTS({ name, project }) as any
159185
];
160186

161187
if (addRoute) {

packages/devextreme-schematics/src/add-view/index_spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ describe('view', () => {
5151
expect(tree.files).toContain('/src/app/pages/test/test.component.ts');
5252
expect(tree.files).toContain('/src/app/pages/test/test.component.html');
5353

54-
const content = tree.readContent('/src/app/pages/test/test.component.html');
54+
const contentHTML = tree.readContent('/src/app/pages/test/test.component.html');
55+
const contentTS = tree.readContent('/src/app/pages/test/test.component.ts');
5556

56-
expect(content).toMatch(/<h2>Test<\/h2>/);
57+
expect(contentHTML).toMatch(/<h2>Test<\/h2>/);
58+
expect(contentTS).toContain('standalone: false');
5759
});
5860

5961
it('should add view to default routing module', async () => {

0 commit comments

Comments
 (0)