Skip to content

Commit

Permalink
Merge pull request #454 from ckeditor/editor-integration/angular/add-…
Browse files Browse the repository at this point in the history
…usage-data

Feature: Align integration to work with self-service for premium features.
  • Loading branch information
Mati365 authored Nov 13, 2024
2 parents 7e60966 + 970b9af commit 2833d50
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"@angular/platform-browser": "^16",
"@angular/platform-browser-dynamic": "^16",
"@angular/router": "^16",
"@ckeditor/ckeditor5-integrations-common": "^2.2.0",
"core-js": "^3.21.1",
"rxjs": "^6.5.5",
"tslib": "^2.0.3",
"zone.js": "~0.13.0",
"@ckeditor/ckeditor5-integrations-common": "^2.0.0"
"zone.js": "~0.13.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16",
Expand Down
17 changes: 16 additions & 1 deletion scripts/preparepackages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const __dirname = upath.dirname( __filename );
const latestVersion = releaseTools.getLastFromChangelog();
const versionChangelog = releaseTools.getChangesForVersion( latestVersion );
const CKEDITOR5_ANGULAR_ROOT_DIR = upath.join( __dirname, '..' );
const SOURCE_DIR = upath.join( CKEDITOR5_ANGULAR_ROOT_DIR, 'src', 'ckeditor' );
const DIST_DIR = upath.join( CKEDITOR5_ANGULAR_ROOT_DIR, 'dist' );
const RELEASE_ANGULAR_DIR = upath.join( CKEDITOR5_ANGULAR_ROOT_DIR, 'release', 'ckeditor5-angular' );

Expand Down Expand Up @@ -68,6 +69,19 @@ const tasks = new Listr( [
return false;
}
},
{
title: 'Updating version in usage data plugin.',
task: async () => {
const pluginPath = upath.join( SOURCE_DIR, 'plugins', 'angular-integration-usage-data.plugin.ts' );
const content = await fs.readFile( pluginPath, 'utf8' );
const updated = content.replace(
/(?<=\/\* replace-version:start \*\/).*?(?=\/\* replace-version:end \*\/)/,
` '${ latestVersion }' `
);

await fs.writeFile( pluginPath, updated );
}
},
{
title: 'Generating the `dist` directory.',
task: () => {
Expand Down Expand Up @@ -119,7 +133,8 @@ const tasks = new Listr( [
return releaseTools.commitAndTag( {
version: latestVersion,
files: [
'package.json'
'package.json',
'src/ckeditor/plugins/angular-integration-usage-data.plugin.ts'
]
} );
},
Expand Down
16 changes: 16 additions & 0 deletions src/ckeditor/ckeditor.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TestBed, type ComponentFixture } from '@angular/core/testing';

import { AngularEditor } from 'src/editor/editor';
import { CKEditorComponent } from './ckeditor.component';
import { AngularIntegrationUsageDataPlugin } from './plugins/angular-integration-usage-data.plugin';

describe( 'CKEditorComponent', () => {
let component: CKEditorComponent;
Expand Down Expand Up @@ -128,6 +129,21 @@ describe( 'CKEditorComponent', () => {
} );
} );

describe( 'getConfig', () => {
it( 'should return config with AngularIntegrationUsageDataPlugin if non-free license passed', async () => {
( window as any ).CKEDITOR_VERSION = '44.0.0';
component.config.licenseKey = 'foo';

fixture.detectChanges();

await waitCycle();

const config = ( component as any ).getConfig();

expect( config.extraPlugins ).toContain( AngularIntegrationUsageDataPlugin );
} );
} );

describe( 'component data', () => {
it( 'initial data should be empty', async () => {
fixture.detectChanges();
Expand Down
3 changes: 2 additions & 1 deletion src/ckeditor/ckeditor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
import type { ControlValueAccessor } from '@angular/forms';

import { uid } from '@ckeditor/ckeditor5-integrations-common';
import { appendAllIntegrationPluginsToConfig } from './plugins/append-all-integration-plugins-to-config';

const ANGULAR_INTEGRATION_READ_ONLY_LOCK_ID = 'Lock from Angular integration (@ckeditor/ckeditor5-angular)';

Expand Down Expand Up @@ -453,7 +454,7 @@ export class CKEditorComponent<TEditor extends Editor = Editor> implements After
config.initialData = initialData;
}

return config;
return appendAllIntegrationPluginsToConfig( config );
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/ckeditor/plugins/angular-integration-usage-data.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

import { VERSION } from '@angular/core';
import { createIntegrationUsageDataPlugin } from '@ckeditor/ckeditor5-integrations-common';

/**
* This part of the code is not executed in open-source implementations using a GPL key.
* It only runs when a specific license key is provided. If you are uncertain whether
* this applies to your installation, please contact our support team.
*/
export const AngularIntegrationUsageDataPlugin = createIntegrationUsageDataPlugin(
'angular',
{
version: /* replace-version:start */ '9.0.0' /* replace-version:end */,
frameworkVersion: VERSION.full
}
);
30 changes: 30 additions & 0 deletions src/ckeditor/plugins/append-all-integration-plugins-to-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

import { appendExtraPluginsToEditorConfig, isCKEditorFreeLicense } from '@ckeditor/ckeditor5-integrations-common';
import type { EditorConfig, PluginConstructor } from 'ckeditor5';

import { AngularIntegrationUsageDataPlugin } from './angular-integration-usage-data.plugin';

/**
* Appends all integration plugins to the editor configuration.
*
* @param editorConfig The editor configuration.
* @returns The editor configuration with all integration plugins appended.
*/
export function appendAllIntegrationPluginsToConfig( editorConfig: EditorConfig ): EditorConfig {
const extraPlugins: Array<PluginConstructor> = [];

if ( !isCKEditorFreeLicense( editorConfig.licenseKey ) ) {
/**
* This part of the code is not executed in open-source implementations using a GPL key.
* It only runs when a specific license key is provided. If you are uncertain whether
* this applies to your installation, please contact our support team.
*/
extraPlugins.push( AngularIntegrationUsageDataPlugin );
}

return appendExtraPluginsToEditorConfig( editorConfig, extraPlugins );
}
33 changes: 4 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@
"@ckeditor/ckeditor5-utils" "43.3.1"
ckeditor5 "43.3.1"

"@ckeditor/ckeditor5-integrations-common@^2.0.0":
"@ckeditor/ckeditor5-integrations-common@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-integrations-common/-/ckeditor5-integrations-common-2.2.0.tgz#3eb75e21eddc880c87a675125ec3fcfe0c258847"
integrity sha512-qH68tqgyMibuejo+VAJ+iSH3ZmZweqBEzaawv9hZb4zzSMkBityWBjSc2hKXMtmJgCNsbSK84cyHpa5J/MNyLg==
Expand Down Expand Up @@ -12055,16 +12055,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.1.tgz#95e2fbec0427ae19184935f816d74aaa4c5c19da"
integrity sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -12105,14 +12096,7 @@ stringify-object@^3.3.0:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -13029,7 +13013,7 @@ workerpool@^6.5.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544"
integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -13047,15 +13031,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 2833d50

Please sign in to comment.