Skip to content

Commit 8489f87

Browse files
committed
feat: added angular 20 for app
1 parent a745285 commit 8489f87

File tree

13 files changed

+495
-42
lines changed

13 files changed

+495
-42
lines changed

package-lock.json

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

packages/devextreme-cli/package-lock.json

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

packages/devextreme-cli/src/applications/application.angular.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ const bumpAngular = (appPath, versionTag) => {
8282
modifyJson(getPackageJsonPath(appPath), ({ dependencies, devDependencies, ...rest }) => {
8383
const bump = (section) => {
8484
for(const depName in section) {
85-
section[depName] = depName.startsWith('@angular') ? versionTag : section[depName];
85+
if(depName.startsWith('@angular')) {
86+
section[depName] = versionTag;
87+
}
8688
}
89+
return section;
8790
};
8891

8992
return {

packages/devextreme-cli/src/utility/ng-version.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const getPublicNgVersion = () => {
1919
return new semver(version);
2020
};
2121

22+
// here ng version
2223
const getNgCliVersion = () => {
2324
let ngCliVersion = getLocalNgVersion();
2425
if(!ngCliVersion) {

packages/devextreme-cli/src/utility/template-creator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const applyTemplateToFile = (filePath, templateOptions) => {
1515
return fileContent;
1616
};
1717

18+
// here add page to app
1819
const addPageToApp = (pageName, pageDir, templatePagesPath, getCorrectExtension, { getPageFileName = () => pageName } = {}) => {
1920
fs.readdirSync(templatePagesPath).forEach((pageItem) => {
2021
const pagePath = path.join(pageDir, `${getPageFileName(pageName, pageItem)}${getCorrectExtension(extname(pageItem))}`);
@@ -29,6 +30,7 @@ const addPageToApp = (pageName, pageDir, templatePagesPath, getCorrectExtension,
2930
});
3031
};
3132

33+
// here move template files to project
3234
const moveTemplateFilesToProject = (templateFolder, appPath, templateOptions, getCorrectPath, pathToFileRelativelyRoot) => {
3335
const relativePath = pathToFileRelativelyRoot || '';
3436
const pathToFiles = path.join(templateFolder, relativePath);

packages/devextreme-schematics/src/add-layout/files/src/app/__name__.component.html renamed to packages/devextreme-schematics/src/add-layout/files/src/app/__name__.html

File renamed without changes.

packages/devextreme-schematics/src/add-layout/files/src/app/__name__.component.scss renamed to packages/devextreme-schematics/src/add-layout/files/src/app/__name__.scss

File renamed without changes.

packages/devextreme-schematics/src/add-layout/files/src/app/__name__.component.ts renamed to packages/devextreme-schematics/src/add-layout/files/src/app/__name__.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { UnauthenticatedContentComponent } from './unauthenticated-content';
99

1010
@Component({
1111
selector: '<%= prefix %>-root',
12-
templateUrl: './<%= name %>.component.html',
13-
styleUrls: ['./<%= name %>.component.scss'],
12+
templateUrl: './<%= name %>.html',
13+
styleUrls: ['./<%= name %>.scss'],
1414
standalone: true,
1515
imports: [
1616
RouterModule,

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
filter,
1010
forEach,
1111
mergeWith,
12-
callRule,
1312
FileEntry,
14-
template
13+
template,
14+
callRule
1515
} from '@angular-devkit/schematics';
1616

1717
import {
@@ -66,6 +66,7 @@ import { getWorkspace } from '@schematics/angular/utility/workspace';
6666
import { Change } from '@schematics/angular/utility/change';
6767

6868
import { PatchNodePackageInstallTask } from '../utility/patch';
69+
import { isAngularVersionHigherThan } from '../utility/angular-version';
6970

7071
const projectFilesSource = './files/src';
7172
const workspaceFilesSource = './files';
@@ -161,13 +162,13 @@ function modifyFileRule(path: string, callback: (source: SourceFile) => Change[]
161162
}
162163

163164
const changes = callback(source);
164-
165165
return applyChanges(host, changes, path);
166166
};
167167
}
168168

169-
function updateAppComponent(sourcePath: string, templateOptions: any = {}) {
170-
const appMComponentPath = sourcePath + 'app.component.ts';
169+
// need here fix ?
170+
function updateAppComponent(host: Tree, sourcePath: string, templateOptions: any = {}) {
171+
const appMComponentPath = sourcePath + (isAngularVersionHigherThan(host, 20) ? 'app.ts' : 'app.component.ts');
171172

172173
const importSetter = (importName: string, path: string, alias: string) => {
173174
return (source: SourceFile) => {
@@ -188,19 +189,23 @@ function updateAppComponent(sourcePath: string, templateOptions: any = {}) {
188189
return chain(rules);
189190
}
190191

192+
// need here fix ?
191193
function getComponentName(host: Tree, sourcePath: string) {
192194
let name = '';
193195
let index = 0;
194196

195-
if (!host.exists(sourcePath + 'app.component.ts')) {
197+
if (!host.exists(sourcePath + 'app.component.ts') && !host.exists(sourcePath + 'app.ts')) {
196198
name = 'app';
197199
}
198200

199201
while (!name) {
200202
index++;
201203
const componentName = `app${index}`;
202204

203-
if (!host.exists(`${sourcePath}${componentName}.component.ts`)) {
205+
if (
206+
!host.exists(`${sourcePath}${componentName}.component.ts`)
207+
&& !host.exists(`${sourcePath}${componentName}.ts`)
208+
) {
204209
name = componentName;
205210
}
206211
}
@@ -270,10 +275,12 @@ function modifyContentByTemplate(
270275
};
271276
}
272277

273-
function updateDevextremeConfig(sourcePath: string = '') {
278+
function updateDevextremeConfig(host: Tree, sourcePath: string = '') {
274279
const devextremeConfigPath = '/devextreme.json';
280+
const postfix = isAngularVersionHigherThan(host, 20) ? 'test' : 'component';
275281
const templateOptions = {
276-
sourcePath
282+
sourcePath,
283+
postfix
277284
};
278285

279286
const modifyConfig = (templateContent: string, currentContent: string) => {
@@ -302,6 +309,10 @@ const modifyRouting = (host: Tree, routingFilePath: string) => {
302309
}
303310
};
304311

312+
function setPostfix(host: Tree, name: string) {
313+
return name + (isAngularVersionHigherThan(host, 20) ? '' : '.component');
314+
}
315+
305316
export default function(options: any): Rule {
306317
return async (host: Tree) => {
307318
const project = await getProjectName(host, options.project);
@@ -315,13 +326,14 @@ export default function(options: any): Rule {
315326
const override = options.resolveConflicts === 'override';
316327
const componentName = override ? 'app' : getComponentName(host, appPath);
317328
const pathToCss = sourcePath?.replace(/\/?(\w)+\/?/g, '../');
329+
318330
const templateOptions = {
319-
name: componentName,
331+
name: setPostfix(host, componentName),
320332
layout,
321333
title,
322334
strings,
323335
path: pathToCss,
324-
prefix
336+
prefix,
325337
};
326338

327339
const modifyContent = (templateContent: string, currentContent: string, filePath: string) => {
@@ -339,8 +351,8 @@ export default function(options: any): Rule {
339351

340352
const rules = [
341353
modifyContentByTemplate(sourcePath, projectFilesSource, null, templateOptions, modifyContent),
342-
updateDevextremeConfig(sourcePath),
343-
updateAppComponent(appPath, templateOptions),
354+
updateDevextremeConfig(host, sourcePath),
355+
updateAppComponent(host, appPath, templateOptions),
344356
addBuildThemeScript(),
345357
() => addCustomThemeStyles(host, options, sourcePath) as any,
346358
addViewportToBody(sourcePath),

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

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import {
2323
} from '../utility/routing';
2424

2525
import { getSourceFile } from '../utility/source';
26+
import { getAngularVersion, isAngularVersionHigherThan } from '../utility/angular-version';
2627

27-
import { strings, basename, normalize, dirname } from '@angular-devkit/core';
28+
import { strings, basename, normalize, dirname, Path } from '@angular-devkit/core';
2829

2930
import {
3031
getProjectName,
@@ -106,7 +107,8 @@ export function addViewToRouting(options: any) {
106107

107108
const name = options.name.replace(/^pages\//, '');
108109
const componentName = getRouteComponentName(name);
109-
const importChanges = insertImport(source, routingModulePath, componentName, `./pages/${name}/${name}.component`);
110+
const path = isAngularVersionHigherThan(host, 20) ? `./pages/${name}/${name}.ts` : `./pages/${name}/${name}.component.ts`;
111+
const importChanges = insertImport(source, routingModulePath, componentName, path);
110112
applyChanges(host, [importChanges], routingModulePath);
111113
}
112114
return host;
@@ -137,38 +139,57 @@ function overwriteModuleContent(options: any, path: string, content: string) {
137139
};
138140
}
139141

140-
function addContentToView(options: any) {
141-
const name = strings.dasherize(basename(normalize(options.name)));
142-
const path = `${dirname(options.name)}/${name}`;
143-
const title = humanize(name);
144-
const componentPath = `${path}/${name}.component.html`;
142+
function getComponentFileNames(name: string, angularVersion: number) {
143+
const baseName = strings.dasherize(basename(normalize(name)));
144+
const path = `${dirname(name as Path)}/${baseName}`;
145+
146+
if (angularVersion >= 20) {
147+
return {
148+
path,
149+
ts: `${path}/${baseName}.ts` as Path,
150+
html: `${path}/${baseName}.html` as Path,
151+
style: `${path}/${baseName}.scss` as Path
152+
};
153+
}
154+
155+
return {
156+
path,
157+
ts: `${path}/${baseName}.component.ts` as Path,
158+
html: `${path}/${baseName}.component.html` as Path,
159+
style: `${path}/${baseName}.component.scss` as Path
160+
};
161+
}
162+
163+
function addContentToView(options: any, angularVersion: number) {
164+
const { html } = getComponentFileNames(options.name, angularVersion);
165+
const title = humanize(strings.dasherize(basename(normalize(options.name))));
145166
const content = `<h2>${title}</h2>
146167
<div class="content-block">
147168
<div class="dx-card responsive-paddings">Put your content here</div>
148169
</div>
149170
`;
150171

151-
return overwriteModuleContent(options, componentPath, content);
172+
return overwriteModuleContent(options, html, content);
152173
}
153174

154-
async function addContentToTS(options: any) {
175+
async function addContentToTS(options: any, angularVersion: number) {
176+
const { ts, html, style } = getComponentFileNames(options.name, angularVersion);
155177
const name = strings.dasherize(basename(normalize(options.name)));
156-
const path = `${dirname(options.name)}/${name}`;
157-
const componentPath = `${path}/${name}.component.ts`;
178+
const componentName = strings.classify(basename(normalize(name)));
158179
const content = `import { Component } from '@angular/core';
159180
160181
@Component({
161182
selector: 'app-${name}',
162-
templateUrl: './${name}.component.html',
163-
styleUrl: './${name}.component.css',
183+
templateUrl: './${basename(html)}',
184+
styleUrl: './${basename(style)}',
164185
standalone: true
165186
})
166-
export class ${strings.classify(basename(normalize(name)))}Component {
187+
export class ${componentName}Component {
167188
168189
}
169190
`;
170191

171-
return overwriteModuleContent(options, componentPath, content);
192+
return overwriteModuleContent(options, ts, content);
172193
}
173194

174195
export default function(options: any): Rule {
@@ -177,6 +198,7 @@ export default function(options: any): Rule {
177198
const project = await getProjectName(host, options.project);
178199
const module = getModuleName(addRoute, options.module);
179200
const name = getPathForView(options.name);
201+
const angularVersion = getAngularVersion(host);
180202

181203
const rules = [externalSchematic('../node_modules/@schematics/angular', 'component', {
182204
name,
@@ -187,8 +209,8 @@ export default function(options: any): Rule {
187209
prefix: options.prefix,
188210
standalone: true
189211
}),
190-
addContentToView({ name, project }) as any,
191-
addContentToTS({ name, project }) as any
212+
addContentToView({ name, project }, angularVersion) as any,
213+
addContentToTS({ name, project }, angularVersion) as any
192214
];
193215

194216
if (addRoute) {

0 commit comments

Comments
 (0)