Skip to content

Commit

Permalink
[ACA-3877] Add the possibility to ADF Extension to be used in compila… (
Browse files Browse the repository at this point in the history
#6097)

* [ACA-3877] Add the possibility to ADF Extension to be used in compilation time

* Fix interface

* Fix cspell

* Fix unit tests

* Add tests
  • Loading branch information
popovicsandras authored and Silviu Popa committed Sep 15, 2020
1 parent 5ba982c commit 1851357
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
"processwithstarteventform",
"processstring",
"typeahed",
"minmax"
"minmax",
"jsons"
],
"dictionaries": [
"html",
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/src/lib/config/action.extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ export interface ContentActionRef extends ExtensionElement {
export interface ActionRef {
id: string;
type: string;
payload?: string;
payload?: any;
}
2 changes: 1 addition & 1 deletion lib/extensions/src/lib/config/extension.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface ExtensionRef {
$version: string;
$vendor: string;
$license: string;
$runtime: string;
$runtime?: string;
$description?: string;

$dependencies?: Array<string>;
Expand Down
3 changes: 2 additions & 1 deletion lib/extensions/src/lib/services/extension.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('ExtensionService', () => {
loader = new ExtensionLoaderService(null);
componentRegister = new ComponentRegisterService();
ruleService = new RuleService(loader);
service = new ExtensionService(loader, componentRegister, ruleService);
service = new ExtensionService(loader, componentRegister, ruleService, []);
});

it('should load and setup a config', async () => {
Expand All @@ -56,6 +56,7 @@ describe('ExtensionService', () => {
await service.load();

expect(loader.load).toHaveBeenCalled();
expect(loader.load).toHaveBeenCalledWith('assets/app.extensions.json', 'assets/plugins', []);
expect(service.setup).toHaveBeenCalledWith(blankConfig);
});

Expand Down
23 changes: 19 additions & 4 deletions lib/extensions/src/lib/services/extension.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* limitations under the License.
*/

import { Injectable, Type } from '@angular/core';
import { Injectable, Type, InjectionToken, Inject } from '@angular/core';
import { RuleEvaluator, RuleRef, RuleContext } from '../config/rule.extensions';
import { ExtensionConfig } from '../config/extension.config';
import { ExtensionConfig, ExtensionRef } from '../config/extension.config';
import { ExtensionLoaderService } from './extension-loader.service';
import { RouteRef } from '../config/routing.extensions';
import { ActionRef } from '../config/action.extensions';
Expand All @@ -26,6 +26,19 @@ import { ComponentRegisterService } from './component-register.service';
import { RuleService } from './rule.service';
import { ExtensionElement } from '../config/extension-element';

const EXTENSION_JSONS = new InjectionToken<ExtensionRef[][]>('extension-jsons', {
providedIn: 'root',
factory: () => []
});

export function provideExtensionConfig(jsons: ExtensionRef[]) {
return {
provide: EXTENSION_JSONS,
useValue: jsons,
multi: true
};
}

@Injectable({
providedIn: 'root'
})
Expand All @@ -44,7 +57,8 @@ export class ExtensionService {
constructor(
protected loader: ExtensionLoaderService,
protected componentRegister: ComponentRegisterService,
protected ruleService: RuleService
protected ruleService: RuleService,
@Inject(EXTENSION_JSONS) protected extensionJsons: ExtensionRef[]
) {
}

Expand All @@ -55,7 +69,8 @@ export class ExtensionService {
async load(): Promise<ExtensionConfig> {
const config = await this.loader.load(
this.configPath,
this.pluginsPath
this.pluginsPath,
this.extensionJsons.flat()
);
this.setup(config);
return config;
Expand Down
2 changes: 1 addition & 1 deletion lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@alfresco/adf-core": ["./core/"],
"@alfresco/adf-insights": ["./analytics"]
},
"lib": ["es2018", "dom"],
"lib": ["es2018", "esnext.array", "dom"],
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
],
"lib": [
"es2018",
"esnext.array",
"dom"
],
"paths": {
Expand Down

0 comments on commit 1851357

Please sign in to comment.