This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a64938d
commit 57e65b7
Showing
22 changed files
with
20,392 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Cumulocity widget plugin | ||
|
||
This is the Cumulocity module federation plugin. Plugins can be developed like any Cumulocity application, but can be used at runtime by other applications. Therefore, they export an Angular module which can then be imported by any other application. The exports are defined in `package.json`: | ||
|
||
``` | ||
"exports": [ | ||
{ | ||
"name": "Example widget plugin", | ||
"module": "WidgetPluginModule", | ||
"path": "./widget/widget-plugin.module.ts", | ||
"description": "Adds custom widget" | ||
} | ||
] | ||
``` | ||
|
||
**How to start** | ||
Run the command below to scaffold a `widget` plugin. | ||
|
||
``` | ||
c8ycli new <yourPluginName> widget-plugin | ||
``` | ||
|
||
As the app.module is a typical Cumuloctiy application, any new plugin can be tested via the CLI: | ||
|
||
``` | ||
npm start -- --shell cockpit | ||
``` | ||
|
||
In the Module Federation terminology, `widget` plugin is called `remote` and the `cokpit` is called `shell`. Modules provided by this `widget` will be loaded by the `cockpit` application at the runtime. This plugin provides a basic custom widget that can be accessed through the `Add widget` menu. | ||
|
||
> Note that the `--shell` flag creates a proxy to the cockpit application and provides` WidgetPluginModule` as an `remote` via URL options. | ||
Also deploying needs no special handling and can be simply done via `npm run deploy`. As soon as the application has exports it will be uploaded as a plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
describe('Example test', () => { | ||
/*let testComponent; | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ExampleModule] | ||
}); | ||
testComponent = TestBed.createComponent(TestComponent); | ||
});*/ | ||
|
||
test('Always true', () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { RouterModule as ngRouterModule } from '@angular/router'; | ||
import { BootstrapComponent, CoreModule, RouterModule } from '@c8y/ngx-components'; | ||
import { BsModalRef } from 'ngx-bootstrap/modal'; | ||
import { GpDemoWidgetModule } from './widget/gp-demo-widget.module'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
BrowserAnimationsModule, | ||
ngRouterModule.forRoot([], { enableTracing: false, useHash: true }), | ||
RouterModule.forRoot(), | ||
CoreModule.forRoot(), | ||
GpDemoWidgetModule | ||
], | ||
providers: [BsModalRef], | ||
bootstrap: [BootstrapComponent] | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const {src, dest, series} = require('gulp'); | ||
const zip = require('gulp-zip'); | ||
const del = require('del'); | ||
const pkgJson = require('./package.json'); | ||
|
||
function clean() { | ||
return del(['dist']); | ||
} | ||
|
||
const bundle = series( | ||
function createZip() { | ||
return src(`./dist/apps/${pkgJson.name}/**/*`) | ||
.pipe(zip(`${pkgJson.name}-${pkgJson.version}.zip`)) | ||
.pipe(dest('dist/')) | ||
} | ||
) | ||
|
||
exports.clean = clean; | ||
exports.bundle = bundle; | ||
exports.default = series(bundle, async function success() { | ||
console.log("Build Finished Successfully!"); | ||
console.log(`PluginOutput (Install in the browser): dist/${pkgJson.name}-${pkgJson.version}.zip`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import './polyfills'; | ||
|
||
import { enableProdMode } from '@angular/core'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { AppModule } from './app.module'; | ||
|
||
declare const __MODE__: string; | ||
if (__MODE__ === 'production') { | ||
enableProdMode(); | ||
} | ||
|
||
export function bootstrap() { | ||
platformBrowserDynamic() | ||
.bootstrapModule(AppModule) | ||
.catch(err => console.log(err)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// jest.config.js | ||
module.exports = { | ||
preset: 'jest-preset-angular', | ||
setupFilesAfterEnv: ['<rootDir>/setup-jest.js'], | ||
transformIgnorePatterns: ['/!node_modules\\/lodash-es/'] | ||
}; |
Oops, something went wrong.