Skip to content

Commit

Permalink
chore: merge branch 'master' into feat-provide
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Nov 10, 2023
2 parents 73dcea4 + d1ed91e commit fdd6e58
Show file tree
Hide file tree
Showing 31 changed files with 150 additions and 117 deletions.
6 changes: 2 additions & 4 deletions packages/form/spec/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export function builder(options?: {
} {
options = { detectChanges: true, ...options };
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, AlainThemeModule.forRoot(), DelonFormModule.forRoot()].concat(
options.imports || []
),
imports: [NoopAnimationsModule, AlainThemeModule, DelonFormModule.forRoot()].concat(options.imports || []),
declarations: [TestFormComponent]
});
if (options.template) {
Expand Down Expand Up @@ -80,7 +78,7 @@ export function configureSFTestSuite(options?: { imports?: NzSafeAny[] }): void
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
AlainThemeModule.forRoot(),
AlainThemeModule,
DelonFormModule.forRoot(),
HttpClientTestingModule,
...(options?.imports ?? [])
Expand Down
5 changes: 1 addition & 4 deletions packages/form/spec/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ describe('form: component', () => {

function genModule(options: { acl?: boolean; i18n?: boolean } = {}): void {
options = { acl: false, i18n: false, ...options };
const imports = [NoopAnimationsModule, DelonFormModule.forRoot(), AlainThemeModule.forRoot()];
if (options.i18n) {
imports.push(AlainThemeModule.forRoot());
}
const imports = [NoopAnimationsModule, DelonFormModule.forRoot(), AlainThemeModule];
if (options.acl) {
imports.push(DelonACLModule.forRoot());
}
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/date/date.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Pipe: _date', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AlainThemeModule.forRoot()],
imports: [AlainThemeModule],
declarations: [TestComponent],
providers: [{ provide: NZ_DATE_LOCALE, useValue: dateFnsLang }]
});
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/date/date.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Pipe, PipeTransform } from '@angular/core';
import { formatDate } from '@delon/util/date-time';
import { NzI18nService } from 'ng-zorro-antd/i18n';

@Pipe({ name: '_date' })
@Pipe({ name: '_date', standalone: true })
export class DatePipe implements PipeTransform {
constructor(private nzI18n: NzI18nService) {}

Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/keys/keys.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Pipe: keys', () => {

function genModule(template?: string): void {
TestBed.configureTestingModule({
imports: [AlainThemeModule.forRoot()],
imports: [AlainThemeModule],
declarations: [TestComponent]
});
if (template) TestBed.overrideTemplate(TestComponent, template);
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/keys/keys.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { NzSafeAny } from 'ng-zorro-antd/core/types';
/**
* [Document](https://ng-alain.com/theme/keys)
*/
@Pipe({ name: 'keys' })
@Pipe({ name: 'keys', standalone: true })
export class KeysPipe implements PipeTransform {
transform(value: NzSafeAny, keyIsNumber: boolean = false): NzSafeAny[] {
const ret: NzSafeAny[] = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/safe/html.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Pipe: html', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AlainThemeModule.forRoot()],
imports: [AlainThemeModule],
declarations: [TestComponent]
});
fixture = TestBed.createComponent(TestComponent);
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/safe/html.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Pipe({ name: 'html' })
@Pipe({ name: 'html', standalone: true })
export class HTMLPipe implements PipeTransform {
constructor(private dom: DomSanitizer) {}

Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/safe/url.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Pipe: url', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AlainThemeModule.forRoot()],
imports: [AlainThemeModule],
declarations: [TestComponent]
});
fixture = TestBed.createComponent(TestComponent);
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/safe/url.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';

@Pipe({ name: 'url' })
@Pipe({ name: 'url', standalone: true })
export class URLPipe implements PipeTransform {
constructor(private dom: DomSanitizer) {}

Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/yn/yn.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Pipe: yn', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AlainThemeModule.forRoot()],
imports: [AlainThemeModule],
declarations: [TestComponent]
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/pipes/yn/yn.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function yn(value: boolean, opt?: YNOptions): string {
return html;
}

@Pipe({ name: 'yn' })
@Pipe({ name: 'yn', standalone: true })
export class YNPipe implements PipeTransform {
constructor(private dom: DomSanitizer) {}

Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/services/drawer/drawer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('theme: DrawerHelper', () => {

beforeEach(() => {
@NgModule({
imports: [CommonModule, NoopAnimationsModule, AlainThemeModule.forChild(), NzDrawerModule],
imports: [CommonModule, NoopAnimationsModule, AlainThemeModule, NzDrawerModule],
declarations: [TestDrawerComponent, TestComponent]
})
class TestModule {}
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/services/i18n/i18n.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Inject, Pipe, PipeTransform } from '@angular/core';

import { AlainI18NService, ALAIN_I18N_TOKEN } from './i18n';

@Pipe({ name: 'i18n' })
@Pipe({ name: 'i18n', standalone: true })
export class I18nPipe implements PipeTransform {
constructor(@Inject(ALAIN_I18N_TOKEN) private i18n: AlainI18NService) {}

Expand Down
10 changes: 5 additions & 5 deletions packages/theme/src/services/i18n/i18n.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('theme: i18n', () => {
describe('', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AlainThemeModule.forRoot()],
imports: [AlainThemeModule],
declarations: [TestComponent]
});
fixture = TestBed.createComponent(TestComponent);
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('theme: i18n', () => {

it('#interpolation', () => {
TestBed.configureTestingModule({
imports: [AlainThemeModule.forRoot()],
imports: [AlainThemeModule],
declarations: [TestComponent],
providers: [provideAlainConfig({ themeI18n: { interpolation: ['#', '#'] } })]
});
Expand All @@ -88,7 +88,7 @@ describe('theme: i18n', () => {
it('should be working', fakeAsync(() => {
TestBed.configureTestingModule({
imports: [
AlainThemeModule.forRoot(),
AlainThemeModule,
RouterTestingModule.withRoutes([
{
path: ':i18n',
Expand All @@ -112,7 +112,7 @@ describe('theme: i18n', () => {
it('should be can not work', fakeAsync(() => {
TestBed.configureTestingModule({
imports: [
AlainThemeModule.forRoot(),
AlainThemeModule,
RouterTestingModule.withRoutes([
{ path: ':invalid', component: TestComponent, canActivate: [alainI18nCanActivate] }
])
Expand All @@ -131,7 +131,7 @@ describe('theme: i18n', () => {
it('should be working', fakeAsync(() => {
TestBed.configureTestingModule({
imports: [
AlainThemeModule.forRoot(),
AlainThemeModule,
RouterTestingModule.withRoutes([
{ path: ':lang', component: TestComponent, canActivate: [alainI18nCanActivate] }
])
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/services/modal/modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('theme: ModalHelper', () => {

beforeEach(() => {
@NgModule({
imports: [CommonModule, NoopAnimationsModule, AlainThemeModule.forChild(), NzModalModule],
imports: [CommonModule, NoopAnimationsModule, AlainThemeModule, NzModalModule],
declarations: [TestModalComponent, TestComponent]
})
class TestModule {}
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/services/rtl/rtl.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Service: RTL', () => {

beforeEach(() => {
@NgModule({
imports: [CommonModule, AlainThemeModule.forChild()]
imports: [CommonModule, AlainThemeModule]
})
class TestModule {}
const injector = TestBed.configureTestingModule({ imports: [TestModule] });
Expand Down
23 changes: 2 additions & 21 deletions packages/theme/src/theme.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/* eslint-disable import/order */
import { OverlayModule } from '@angular/cdk/overlay';
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

// #region import

const HELPERS = [ModalHelper, DrawerHelper];

// pipes
import { BellOutline, DeleteOutline, InboxOutline, PlusOutline } from '@ant-design/icons-angular/icons';

Expand All @@ -29,16 +27,13 @@ const PIPES = [DatePipe, KeysPipe, YNPipe, I18nPipe, HTMLPipe, URLPipe];

// - zorro: https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/components/icon/icons.ts

import { DrawerHelper } from './services/drawer/drawer.helper';
import { ModalHelper } from './services/modal/modal.helper';
import { ALAIN_SETTING_KEYS } from './services/settings/settings.service';
const ICONS = [BellOutline, DeleteOutline, PlusOutline, InboxOutline];

// #endregion

@NgModule({
imports: [CommonModule, RouterModule, OverlayModule, NzI18nModule],
declarations: PIPES,
imports: [CommonModule, RouterModule, OverlayModule, NzI18nModule, ...PIPES],
providers: [
{
provide: ALAIN_SETTING_KEYS,
Expand All @@ -55,18 +50,4 @@ export class AlainThemeModule {
constructor(iconSrv: NzIconService) {
iconSrv.addIcon(...ICONS);
}

static forRoot(): ModuleWithProviders<AlainThemeModule> {
return {
ngModule: AlainThemeModule,
providers: HELPERS
};
}

static forChild(): ModuleWithProviders<AlainThemeModule> {
return {
ngModule: AlainThemeModule,
providers: HELPERS
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const PASSPORT = [
CommonModule,
FormsModule,
RouterModule,<% if (i18n) { %>
AlainThemeModule.forChild(),<% } %>
AlainThemeModule,<% } %>
ThemeBtnModule,
SettingDrawerModule,
LayoutDefaultModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const DIRECTIVES: Array<Type<void>> = [];
FormsModule,
RouterModule,
ReactiveFormsModule,
AlainThemeModule.forChild(),
AlainThemeModule,
DelonACLModule,<% if (form) { %>
DelonFormModule,<% } %>
...SHARED_DELON_MODULES,
Expand Down
4 changes: 2 additions & 2 deletions schematics/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"aliases": ["alain-shell"]
},
"ng-update": {
"factory": "./ng-update/index#updateToV13",
"description": "Updates the NG-ALAIN to v13"
"factory": "./ng-update/index#updateToV17",
"description": "Just TEST"
},
"application": {
"factory": "./application",
Expand Down
2 changes: 1 addition & 1 deletion schematics/ng-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function updateToV17(): Rule {
/** Post-update schematic to be called when update is finished. */
export function postUpdate(context: SchematicContext, targetVersion: TargetVersion, hasFailures: boolean): void {
context.logger.info('');
context.logger.info(` ✓ Updated NG-ALAIN to ${targetVersion}`);
context.logger.info(`✓ Updated NG-ALAIN to ${targetVersion}`);
context.logger.info('');

if (hasFailures) {
Expand Down
45 changes: 45 additions & 0 deletions schematics/ng-update/upgrade-rules/v17/autoRegisterFormWidgets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { insertImport, addSymbolToNgModuleMetadata } from '@schematics/angular/utility/ast-utils';
import { Change, InsertChange } from '@schematics/angular/utility/change';

import { DEFAULT_WORKSPACE_PATH, getSourceFile, readJSON, applyChanges, logWarn } from '../../../utils';

export function autoRegisterFormWidgets(): Rule {
return (tree: Tree, context: SchematicContext) => {
const angularJson = readJSON(tree, DEFAULT_WORKSPACE_PATH);
const projectNames = Object.keys(angularJson.projects);
for (const name of projectNames) {
autoRegisterFormWidgetsRun(tree, name, angularJson.projects[name].sourceRoot, context);
}
};
}

function autoRegisterFormWidgetsRun(tree: Tree, name: string, sourceRoot: string, context: SchematicContext): void {
const modulePath = `${sourceRoot}/app/shared/json-schema/json-schema.module.ts`;
if (!tree.exists(modulePath)) return;

const list = [
{ symbolName: 'AutoCompleteWidgetModule', fileName: '@delon/form/widgets/autocomplete' },
{ symbolName: 'CascaderWidgetModule', fileName: '@delon/form/widgets/cascader' },
{ symbolName: 'MentionWidgetModule', fileName: '@delon/form/widgets/mention' },
{ symbolName: 'RateWidgetModule', fileName: '@delon/form/widgets/rate' },
{ symbolName: 'SliderWidgetModule', fileName: '@delon/form/widgets/slider' },
{ symbolName: 'TagWidgetModule', fileName: '@delon/form/widgets/tag' },
{ symbolName: 'TimeWidgetModule', fileName: '@delon/form/widgets/time' },
{ symbolName: 'TransferWidgetModule', fileName: '@delon/form/widgets/transfer' },
{ symbolName: 'TreeSelectWidgetModule', fileName: '@delon/form/widgets/tree-select' },
{ symbolName: 'UploadWidgetModule', fileName: '@delon/form/widgets/upload' }
];
const source = getSourceFile(tree, modulePath);
const changes: Change[] = [];
for (const item of list) {
changes.push(insertImport(source, modulePath, item.symbolName, item.fileName) as InsertChange);
changes.push(...addSymbolToNgModuleMetadata(source, modulePath, 'imports', item.symbolName));
}
applyChanges(tree, modulePath, changes);

logWarn(
context,
`[@delon/form] Register all widgets in ${name} project, you can reduce package size by removing unnecessary parts`
);
}
14 changes: 14 additions & 0 deletions schematics/ng-update/upgrade-rules/v17/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,18 @@ describe('Schematic: ng-update: v17Rule', () => {
expect(content).toContain(`import { UploadWidgetModule } from '@delon/form/widgets/upload';`);
expect(content).toContain(`, UploadWidgetModule`);
});

it('#removeAlainThemeModuleForRoot', async () => {
const globalConfigPath = '/projects/foo/src/app/global-config.module.ts';
tree.create(
globalConfigPath,
`
import { AlainThemeModule } from '@delon/theme';
const alainModules: any[] = [AlainThemeModule.forRoot(), DelonACLModule.forRoot()];
`
);
await runMigration();
const content = tree.readContent(globalConfigPath);
expect(content).not.toContain(`AlainThemeModule.forRoot()`);
});
});
Loading

0 comments on commit fdd6e58

Please sign in to comment.