From d392fc7a3da0b269a71dbf30fad7dc91fa7f01a9 Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Thu, 4 Oct 2018 16:29:56 +0200 Subject: [PATCH] feat: added version to data attr feat: allow for bundledplugins --- README.md | 4 +++- package.json | 2 +- src/atlasViewer/atlasViewer.component.ts | 3 +++ .../atlasViewer.dataService.service.ts | 15 +++++++-------- src/main-aot.ts | 4 ++-- src/main.ts | 2 +- src/plugin_examples/newWebJugex/manifest.json | 4 ++-- src/plugin_examples/newWebJugex/script.js | 2 +- typings/index.d.ts | 3 ++- webpack.staticassets.js | 15 ++++++++++++--- 10 files changed, 34 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fc2c32b09..d0b76d06a 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,10 @@ The contents inside the folder in `./src/plugin_examples` will be automatically ## AOT compilation +Define `BUNDLEPLUGINS` as a comma separated environment variables to bundle the plugins. + ``` -npm run build-aot +[BUNDLEDPLUGINS=pluginDir1[,pluginDir2...]] npm run build-aot ``` ## JIT Compilation diff --git a/package.json b/package.json index 6c1cc0050..40cd5ffae 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build-export": "webpack --config webpack.export.js", "build-export-min": "webpack --config webpack.export.min.js", "build-export-aot": "webpack --config webpack.export.aot.js", - "build-aot": "webpack --config webpack.aot.js", + "build-aot": "GIT_HASH=`git rev-parse --short HEAD` webpack --config webpack.aot.js", "build-min": "webpack --config webpack.prod.js", "build": "webpack --config webpack.dev.js", "dev-plugin": "PLUGINDEV=true npm run dev-server & node ./src/plugin_examples/server.js", diff --git a/src/atlasViewer/atlasViewer.component.ts b/src/atlasViewer/atlasViewer.component.ts index f82a6f1da..13a7758d7 100644 --- a/src/atlasViewer/atlasViewer.component.ts +++ b/src/atlasViewer/atlasViewer.component.ts @@ -484,6 +484,9 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit { this.mousePos = [event.clientX, event.clientY] } + @HostBinding('attr.version') + public _version : string = VERSION + get floatingMouseContextualContainerTransform() { return `translate(${this.mousePos[0]}px,${this.mousePos[1]}px)` } diff --git a/src/atlasViewer/atlasViewer.dataService.service.ts b/src/atlasViewer/atlasViewer.dataService.service.ts index cfe257e14..bf763c4ee 100644 --- a/src/atlasViewer/atlasViewer.dataService.service.ts +++ b/src/atlasViewer/atlasViewer.dataService.service.ts @@ -18,15 +18,14 @@ export class AtlasViewerDataService implements OnDestroy{ PLUGINDEV ? fetch('http://localhost:10080/allPluginmanifests').then(res=>res.json()) : Promise.resolve([]), - BUNDLEPLUGIN - ? fetch('pluginsManifests.json').then(res => res.json()) - : Promise.resolve([]), - fetch('res/plugins/manifest.json') - .then(res => res.json()) - .then(json => [json]) - .catch(e => Promise.resolve([])) + Promise.all( + BUNDLEDPLUGINS + .filter(v => typeof v === 'string') + .map(v => fetch(`res/plugin_examples/${v}/manifest.json`).then(res => res.json())) + ) + .then(arr => arr.reduce((acc,curr) => acc.concat(curr) ,[])) ]) - .then(arr => resolve(arr[0].concat(arr[1], arr[2]))) + .then(arr => resolve( [ ... arr[0], ... arr[1] ] )) .catch(reject) }) diff --git a/src/main-aot.ts b/src/main-aot.ts index cae586c56..cf8708595 100644 --- a/src/main-aot.ts +++ b/src/main-aot.ts @@ -7,9 +7,9 @@ import { enableProdMode } from '@angular/core'; const requireAll = (r:any) => {r.keys().forEach(r)} requireAll(require.context('./res/ext', false, /\.json$/)) requireAll(require.context('./res/images', true, /\.jpg|\.png/)) -requireAll(require.context('./plugin_examples/jugex', false)) +requireAll(require.context(`./plugin_examples`, true)) -/* aot = production mode */ +/* aot === production mode */ enableProdMode() platformBrowserDynamic().bootstrapModule(MainModule) \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 6565a7e50..5eec78190 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,6 @@ import { MainModule } from './main.module'; const requireAll = (r:any) => {r.keys().forEach(r)} requireAll(require.context('./res/ext',false, /\.json$/)) requireAll(require.context('./res/images',true,/\.jpg|\.png/)) -requireAll(require.context('./plugin_examples/jugex', false)) +requireAll(require.context(`./plugin_examples`, true)) platformBrowserDynamic().bootstrapModule(MainModule) \ No newline at end of file diff --git a/src/plugin_examples/newWebJugex/manifest.json b/src/plugin_examples/newWebJugex/manifest.json index ed04ef109..97462a280 100644 --- a/src/plugin_examples/newWebJugex/manifest.json +++ b/src/plugin_examples/newWebJugex/manifest.json @@ -2,6 +2,6 @@ "name" : "fzj.xg.webjugex", "displayName":"JuGEx differential gene expression analysis", "type" : "plugin", - "templateURL" : "http://localhost:10080/newWebJugex/template.html", - "scriptURL" : "http://localhost:10080/newWebJugex/script.js" + "templateURL" : "res/plugin_examples/newWebJugex/template.html", + "scriptURL" : "res/plugin_examples/newWebJugex/script.js" } \ No newline at end of file diff --git a/src/plugin_examples/newWebJugex/script.js b/src/plugin_examples/newWebJugex/script.js index 363677022..95655365e 100644 --- a/src/plugin_examples/newWebJugex/script.js +++ b/src/plugin_examples/newWebJugex/script.js @@ -22,7 +22,7 @@ // }]) const backendRoot = null - const srcRoot = 'http://localhost:10080/newWebJugex' + const srcRoot = 'res/plugin_examples/newWebJugex' const manifestID = 'fzj.xg.webjugex' /* so that on shutdown, we could unload these libraries */ diff --git a/typings/index.d.ts b/typings/index.d.ts index 66994ab97..aded50e45 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -9,4 +9,5 @@ declare module '*.css' { } declare var PLUGINDEV : boolean -declare var BUNDLEPLUGIN : boolean \ No newline at end of file +declare var BUNDLEDPLUGINS : string[] +declare var VERSION : string \ No newline at end of file diff --git a/webpack.staticassets.js b/webpack.staticassets.js index 54db495c1..ae3714c2e 100644 --- a/webpack.staticassets.js +++ b/webpack.staticassets.js @@ -31,8 +31,9 @@ module.exports = { use : [{ loader : 'file-loader', options : { - name : '[name].[ext]', - outputPath : 'res/plugins' + name : '[path][name].[ext]', + outputPath : 'res', + context : 'src' } }] } @@ -41,7 +42,15 @@ module.exports = { plugins : [ new webpack.DefinePlugin({ PLUGINDEV : process.env.PLUGINDEV ? true : false, - BUNDLEPLUGIN : process.env.BUNDLEPLUGIN ? true : false + BUNDLEDPLUGINS : process.env.BUNDLEDPLUGINS + ? JSON.stringify(process.env.BUNDLEDPLUGINS.split(',')) + : JSON.stringify([]), + VERSION : process.env.VERSION + ? JSON.stringify(process.env.VERSION) + : process.env.GIT_HASH + ? JSON.stringify(process.env.GIT_HASH) + : JSON.stringify('unspecificied hash') }) + // ...ignoreArr.map(dirname => new webpack.IgnorePlugin(/\.\/plugin_examples/)) ] } \ No newline at end of file -- GitLab