Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): fix ng update #1714

Merged
merged 9 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/theme/src/provide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
} from '@angular/core';

import type { IconDefinition } from '@ant-design/icons-angular';
import { BellOutline, DeleteOutline, InboxOutline, PlusOutline } from '@ant-design/icons-angular/icons';
import {
BellOutline,
DeleteOutline,
InboxOutline,
PlusOutline,
MenuFoldOutline,
MenuUnfoldOutline
} from '@ant-design/icons-angular/icons';

import { ALAIN_CONFIG, AlainConfig } from '@delon/util/config';
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
Expand Down Expand Up @@ -67,7 +74,15 @@
provides.push({ provide: ALAIN_I18N_TOKEN, useClass: i18nCls, multi: false });
}

const icons: IconDefinition[] = [BellOutline, DeleteOutline, PlusOutline, InboxOutline, ...(options.icons ?? [])];
const icons: IconDefinition[] = [

Check warning on line 77 in packages/theme/src/provide.ts

View check run for this annotation

Codecov / codecov/patch

packages/theme/src/provide.ts#L77

Added line #L77 was not covered by tests
BellOutline,
DeleteOutline,
PlusOutline,
InboxOutline,
MenuFoldOutline,
MenuUnfoldOutline,
...(options.icons ?? [])
];
provides.push({
provide: ENVIRONMENT_INITIALIZER,
multi: true,
Expand Down
64 changes: 64 additions & 0 deletions schematics/application/files/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { default as ngLang } from '@angular/common/locales/zh';
import { ApplicationConfig, EnvironmentProviders, Provider } from '@angular/core';
import { provideAnimations } from '@angular/platform-browser/animations';
import { provideRouter, withComponentInputBinding, withInMemoryScrolling, withHashLocation, RouterFeatures } from '@angular/router';
import { <% if (i18n) { %>I18NService, <% } %>defaultInterceptor, provideStartup } from '@core';
import { provideCellWidgets } from '@delon/abc/cell';
import { provideSTWidgets } from '@delon/abc/st';
import { authSimpleInterceptor, provideAuth } from '@delon/auth';<% if (form) { %>
import { provideSFConfig } from '@delon/form';<% } %>
import { AlainProvideLang, provideAlain, zh_CN as delonLang } from '@delon/theme';
import { AlainConfig } from '@delon/util/config';
import { environment } from '@env/environment';
import { CELL_WIDGETS, ST_WIDGETS<% if (form) { %>, SF_WIDGETS<% } %> } from '@shared';
import { zhCN as dateLang } from 'date-fns/locale';
import { NzConfig, provideNzConfig } from 'ng-zorro-antd/core/config';
import { zh_CN as zorroLang } from 'ng-zorro-antd/i18n';

import { provideBindAuthRefresh } from './core/net';
import { routes } from './routes/routes';
import { ICONS } from '../style-icons';
import { ICONS_AUTO } from '../style-icons-auto';

const defaultLang: AlainProvideLang = {
abbr: 'zh-CN',
ng: ngLang,
zorro: zorroLang,
date: dateLang,
delon: delonLang
};

const alainConfig: AlainConfig = {
auth: { login_url: '/passport/login' }
};

const ngZorroConfig: NzConfig = {};

const routerFeatures: RouterFeatures[] = [withComponentInputBinding(), withInMemoryScrolling({ scrollPositionRestoration: 'top' })];
if (environment.useHash) routerFeatures.push(withHashLocation());

const providers: Array<Provider | EnvironmentProviders> = [
provideHttpClient(withInterceptors([...(environment.interceptorFns ?? []), authSimpleInterceptor, defaultInterceptor])),
provideAnimations(),
provideRouter(routes, ...routerFeatures),
provideAlain({ config: alainConfig, defaultLang<% if (i18n) { %>, i18nClass: I18NService<% } %>, icons: [...ICONS_AUTO, ...ICONS] }),
provideNzConfig(ngZorroConfig),
provideAuth(),
provideCellWidgets(...CELL_WIDGETS),
provideSTWidgets(...ST_WIDGETS),<% if (form) { %>
provideSFConfig({
widgets: [...SF_WIDGETS]
}),<% } %>
provideStartup(),
...(environment.providers || [])
];

// If you use `@delon/auth` to refresh the token, additional registration `provideBindAuthRefresh` is required
if (environment.api?.refreshTokenEnabled && environment.api.refreshTokenType === 'auth-refresh') {
providers.push(provideBindAuthRefresh());
}

export const appConfig: ApplicationConfig = {
providers: providers
};
114 changes: 0 additions & 114 deletions schematics/application/files/src/app/app.module.ts

This file was deleted.

15 changes: 0 additions & 15 deletions schematics/application/files/src/app/core/core.module.ts

This file was deleted.

5 changes: 2 additions & 3 deletions schematics/application/files/src/app/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<% if (i18n) { %>export * from './i18n/i18n.service';<% } %>
export * from './module-import-guard';
export * from './net/default.interceptor';
export * from './startup/startup.service';
export * from './start-page.guard';
export * from './start-page.guard';<% if (i18n) { %>
export * from './i18n/i18n.service';<% } %>
122 changes: 56 additions & 66 deletions schematics/application/files/src/app/core/startup/startup.service.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,78 @@
import { Injectable, Inject } from '@angular/core';
import { APP_INITIALIZER, Injectable, Provider, inject } from '@angular/core';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { DA_SERVICE_TOKEN } from '@delon/auth';
import { ALAIN_I18N_TOKEN, MenuService, SettingsService, TitleService } from '@delon/theme';
import { ACLService } from '@delon/acl';<% if (i18n) { %>
import { I18NService } from '../i18n/i18n.service';<% } %>
import { Observable, zip, of, catchError, map } from 'rxjs';
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzIconService } from 'ng-zorro-antd/icon';

import { ICONS } from '../../../style-icons';
import { ICONS_AUTO } from '../../../style-icons-auto';

/**
* Used for application startup
* Generally used to get the basic data of the application, like: Menu Data, User Data, etc.
*/
export function provideStartup(): Provider[] {
return [
StartupService,
{
provide: APP_INITIALIZER,
useFactory: (startupService: StartupService) => () => startupService.load(),
deps: [StartupService],
multi: true
}
];
}

@Injectable()
export class StartupService {
constructor(
iconSrv: NzIconService,
private menuService: MenuService,<% if (i18n) { %>
@Inject(ALAIN_I18N_TOKEN) private i18n: I18NService,<% } %>
private settingService: SettingsService,
private aclService: ACLService,
private titleService: TitleService,
@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
private httpClient: HttpClient,
private router: Router
) {
iconSrv.addIcon(...ICONS_AUTO, ...ICONS);
private menuService = inject(MenuService);
private settingService = inject(SettingsService);
private tokenService = inject(DA_SERVICE_TOKEN);
private aclService = inject(ACLService);
private titleService = inject(TitleService);
private httpClient = inject(HttpClient);
private router = inject(Router);<% if (i18n) { %>
private i18n = inject<I18NService>(ALAIN_I18N_TOKEN);<% } %>
// If http request allows anonymous access, you need to add `ALLOW_ANONYMOUS`:
// this.httpClient.get('assets/tmp/app-data.json', { context: new HttpContext().set(ALLOW_ANONYMOUS, true) })
private appData$ = this.httpClient.get('assets/tmp/app-data.json').pipe(
catchError((res: NzSafeAny) => {
console.warn(`StartupService.load: Network request failed`, res);
setTimeout(() => this.router.navigateByUrl(`/exception/500`));
return of({});
})
);

private handleAppData(res: NzSafeAny): void {
// Application information: including site name, description, year
this.settingService.setApp(res.app);
// User information: including name, avatar, email address
this.settingService.setUser(res.user);
// ACL: Set the permissions to full, https://ng-alain.com/acl/getting-started
this.aclService.setFull(true);
// Menu data, https://ng-alain.com/theme/menu
this.menuService.add(res.menu);
// Can be set page suffix title, https://ng-alain.com/theme/title
this.titleService.suffix = res.app.name;
}

<% if (i18n) { %>
private viaHttp(): Observable<void> {
const defaultLang = this.i18n.defaultLang;
return zip(this.i18n.loadLangData(defaultLang), this.httpClient.get('assets/tmp/app-data.json')).pipe(
catchError((res: NzSafeAny) => {
console.warn(`StartupService.load: Network request failed`, res);
setTimeout(() => this.router.navigateByUrl(`/exception/500`));
return [];
}),
map(([langData, appData]: [Record<string, string>, NzSafeAny]) => {
// setting language data
this.i18n.use(defaultLang, langData);
private viaHttp(): Observable<void> {
const defaultLang = this.i18n.defaultLang;
return zip(this.i18n.loadLangData(defaultLang), this.appData$).pipe(
map(([langData, appData]: [Record<string, string>, NzSafeAny]) => {
// setting language data
this.i18n.use(defaultLang, langData);

// Application data
// Application information: including site name, description, year
this.settingService.setApp(appData.app);
// User information: including name, avatar, email address
this.settingService.setUser(appData.user);
// ACL: Set the permissions to full, https://ng-alain.com/acl/getting-started
this.aclService.setFull(true);
// Menu data, https://ng-alain.com/theme/menu
this.menuService.add(appData.menu);
// Can be set page suffix title, https://ng-alain.com/theme/title
this.titleService.suffix = appData.app.name;
})
);
}
this.handleAppData(appData);
})
);
}
<% } else { %>
private viaHttp(): Observable<void> {
// If http request allows anonymous access, you need to add `ALLOW_ANONYMOUS`:
// this.httpClient.get('assets/tmp/app-data.json', { context: new HttpContext().set(ALLOW_ANONYMOUS, true) })
return this.httpClient.get('assets/tmp/app-data.json').pipe(
catchError((res: NzSafeAny) => {
console.warn(`StartupService.load: Network request failed`, res);
setTimeout(() => this.router.navigateByUrl(`/exception/500`));
return of({});
}),
map((res: NzSafeAny) => {
// Application information: including site name, description, year
this.settingService.setApp(res.app);
// User information: including name, avatar, email address
this.settingService.setUser(res.user);
// ACL: Set the permissions to full, https://ng-alain.com/acl/getting-started
this.aclService.setFull(true);
// Menu data, https://ng-alain.com/theme/menu
this.menuService.add(res.menu);
// Can be set page suffix title, https://ng-alain.com/theme/title
this.titleService.suffix = res.app.name;
})
);
}
private viaHttp(): Observable<void> {
return this.appData$.pipe(map((res: NzSafeAny) => this.handleAppData(res)));
}
<% } %>

<% if (i18n) { %>
Expand Down
Loading