Skip to content

Commit

Permalink
fix: upgrade schematics to non-deprecated module names
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelRoux committed May 28, 2024
1 parent ccdcfac commit 946ef9f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion projects/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h1>

<pre>
// app.module.ts
NgxMatomoTrackerModule.forRoot({{'{'}}
MatomoModule.forRoot({{'{'}}
siteId: 'YOUR_MATOMO_SITE_ID_HERE',
trackerUrl: 'YOUR_MATOMO_URL_HERE',
&#125;)</pre>
Expand Down
10 changes: 3 additions & 7 deletions projects/demo/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import {
MatomoConfiguration,
NgxMatomoRouterModule,
NgxMatomoTrackerModule,
} from 'ngx-matomo-client';
import { MatomoConfiguration, MatomoRouterModule, MatomoModule } from 'ngx-matomo-client';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule,
NgxMatomoTrackerModule.forRoot({
MatomoModule.forRoot({
trackerUrl: '',
siteId: '',
} as MatomoConfiguration),
NgxMatomoRouterModule,
MatomoRouterModule,
],
declarations: [AppComponent],
schemas: [NO_ERRORS_SCHEMA],
Expand Down
6 changes: 3 additions & 3 deletions projects/demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MatInputModule } from '@angular/material/input';
import { MatTabsModule } from '@angular/material/tabs';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxMatomoRouterModule, NgxMatomoTrackerModule } from 'ngx-matomo-client';
import { MatomoRouterModule, MatomoModule } from 'ngx-matomo-client';
import { environment } from '../environments/environment';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand All @@ -31,11 +31,11 @@ import { TrackSimpleClickEventComponent } from './track-simple-click-event/track
BrowserAnimationsModule,
FormsModule,
AppRoutingModule,
NgxMatomoTrackerModule.forRoot({
MatomoModule.forRoot({
siteId: environment.matomoSiteId,
trackerUrl: environment.matomoTrackerUrl,
}),
NgxMatomoRouterModule.forRoot({
MatomoRouterModule.forRoot({
exclude: /without-router$/,
}),
MatTabsModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatomoConfiguration, NgxMatomoTrackerModule } from 'ngx-matomo-client';
import { MatomoConfiguration, MatomoModule } from 'ngx-matomo-client';
import { TrackEventComponentComponent } from './track-event-component.component';

describe('TrackEventComponentComponent', () => {
Expand All @@ -10,7 +10,7 @@ describe('TrackEventComponentComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
NgxMatomoTrackerModule.forRoot({
MatomoModule.forRoot({
trackerUrl: '',
siteId: '',
} as MatomoConfiguration),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatomoConfiguration, NgxMatomoTrackerModule } from 'ngx-matomo-client';
import { MatomoConfiguration, MatomoModule } from 'ngx-matomo-client';
import { TrackEventTemplateComponent } from './track-event-template.component';

describe('TrackEventTemplateComponent', () => {
Expand All @@ -10,7 +10,7 @@ describe('TrackEventTemplateComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
NgxMatomoTrackerModule.forRoot({
MatomoModule.forRoot({
trackerUrl: '',
siteId: '',
} as MatomoConfiguration),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatomoConfiguration, NgxMatomoTrackerModule } from 'ngx-matomo-client';
import { MatomoConfiguration, MatomoModule } from 'ngx-matomo-client';
import { TrackPageViewWithoutRouterComponent } from './track-page-view-without-router.component';

describe('TrackPageViewWithoutRouterComponent', () => {
Expand All @@ -10,7 +10,7 @@ describe('TrackPageViewWithoutRouterComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
NgxMatomoTrackerModule.forRoot({
MatomoModule.forRoot({
trackerUrl: '',
siteId: '',
} as MatomoConfiguration),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatomoConfiguration, NgxMatomoTrackerModule } from 'ngx-matomo-client';
import { MatomoConfiguration, MatomoModule } from 'ngx-matomo-client';
import { TrackSimpleClickEventComponent } from './track-simple-click-event.component';

describe('TrackSimpleClickEventComponent', () => {
Expand All @@ -10,7 +10,7 @@ describe('TrackSimpleClickEventComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
NgxMatomoTrackerModule.forRoot({
MatomoModule.forRoot({
trackerUrl: '',
siteId: '',
} as MatomoConfiguration),
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-matomo-client/core/tracker/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { inject, InjectionToken } from '@angular/core';
import { requireNonNull } from '../utils/coercion';

const CONFIG_NOT_FOUND =
'No Matomo configuration found! Have you included Matomo module using NgxMatomoTrackerModule.forRoot() ?';
'No Matomo configuration found! Have you included Matomo module using MatomoModule.forRoot() or provideMatomo()?';

/** Internal marker token to detect that router has been enabled */
export const MATOMO_ROUTER_ENABLED = new InjectionToken<boolean>('MATOMO_ROUTER_ENABLED', {
Expand Down
12 changes: 7 additions & 5 deletions projects/ngx-matomo-client/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function hasLegacyModuleDeclaration(source: ts.SourceFile): boolean {

return arrLiteral.elements
.filter(el => el.kind === ts.SyntaxKind.CallExpression)
.some(el => (el as ts.Identifier).getText().startsWith('NgxMatomo'));
.some(el => (el as ts.Identifier).getText().startsWith('Matomo'));
}

function getImportEntryPoints(
Expand Down Expand Up @@ -188,8 +188,8 @@ function addImportsToNgModule(options: Options, context: SchematicContext): Rule
// setup to new providers-style setup.

const imports = findRelevantImports(source, isRelevantImportPath);
let mainModuleIdentifier = 'NgxMatomoModule';
let routerModuleIdentifier = 'NgxMatomoRouterModule';
let mainModuleIdentifier = 'MatomoModule';
let routerModuleIdentifier = 'MatomoRouterModule';
let asteriskAlias: string | undefined;
let mainModuleImported = false;
let routerModuleImported = false;
Expand All @@ -209,23 +209,25 @@ function addImportsToNgModule(options: Options, context: SchematicContext): Rule
asteriskAlias = bindings.name.text;

if (!mainModuleImported) {
mainModuleIdentifier = `${asteriskAlias}.NgxMatomoModule`;
mainModuleIdentifier = `${asteriskAlias}.MatomoModule`;
}

if (!routerModuleImported) {
routerModuleIdentifier = `${asteriskAlias}.NgxMatomoRouterModule`;
routerModuleIdentifier = `${asteriskAlias}.MatomoRouterModule`;
}

mainModuleImported = true;
routerModuleImported = true;
} else {
for (const specifier of bindings.elements) {
switch (specifier.name.text) {
case 'MatomoModule':
case 'NgxMatomoModule':
case 'NgxMatomoTrackerModule':
mainModuleImported = true;
mainModuleIdentifier = specifier.name.text;
break;
case 'MatomoRouterModule':
case 'NgxMatomoRouterModule':
routerModuleImported = true;
routerModuleIdentifier = specifier.name.text;
Expand Down

0 comments on commit 946ef9f

Please sign in to comment.