-
Notifications
You must be signed in to change notification settings - Fork 0
Adding dependencies
When you create a plugin or application it is common to use additional Phovea modules or external libraries to avoid re-inventing the wheel again. There are slightly different ways how to add dependencies for the client-side and the server-side.
A client-side dependency can be another Phovea module or a JavaScript library available on the npm registry.
- Open the command line and navigate to the plugin directory
- Run
yo phovea:add-dependency
- Select the additional (Phovea) modules that should be included
- Confirm your selection with Enter and move the next step
- Select additional libraries (e.g., jQuery, D3) that are known by the Phovea framwork
- Confirm your selection with Enter
- Override files if you will be asked to
- (Optional, but recommended: Commit the changes)
- Update your setup
Follow theses steps only, if you cannot find the library in the known libraries by the Phovea framework (using the Phovea generator in the step above).
- Research if the library and the @types (TypeScript typings) are available on npmjs
- If yes, continue. If not, ask the library author to publish the library on npmjs.
- Open the package.json of the application/plugin repository
- Add the library and typings in the corresponding versions to the dependencies section. For example:
"dependencies": {
"@types/d3": "3.5.36",
"d3": "3.5.17"
},
- (Optional, but recommended: Commit the changes)
- Update your setup
Most of the Phovea repositories (e.g., phovea_vis and phovea_clue) use D3 v3. If you want to use code that uses D3 v4 add the specific D3 module (e.g., d3-selection) and the @type dependency (as described above) to the package.json.
"dependencies": {
"@types/d3-scale": "^1.0.4",
"d3-scale": "^1.0.3"
},
Note, that you must import the specific D3 v4 modules to your TypeScript file as follows to avoid conflicts with the D3 v3 library:
import {scaleLinear} from 'd3-scale';
Import a jQuery UI widget, here Sortable, as follows:
- Run
npm install -save jquery-ui
in the plugin directory - Update your setup
- Import the widget in TypeScript, as follows:
import * as $ from 'jquery';
import 'jquery-ui/ui/widgets/sortable'; // specify the widget here
import 'style-loader!css-loader!jquery-ui/themes/base/all.css'; // use Webpack CSS loader to import base style for all widgets
Important: Make sure you specified the particular widget and use the style loader in the import
statements.
A server-side dependency can be another Phovea module or pip package available on PyPI Python Package Index.
- Open the command line and navigate to the directory of the server library
- Run
yo phovea:add-dependency
- Select the additional (Phovea) modules that should be included
- Confirm your selection with Enter and move the next step
- Select additional libraries (e.g., MongoDB, Redis) that are known by the Phovea framwork
- Confirm your selection with Enter
- Override files if you will be asked to
- (Optional, but recommended: Commit the changes)
- Update your setup
Follow theses steps only, if you cannot find a suitable Phovea plugin (using the Phovea generator in the step above).
- Navigate to the server library directory
- Open the requirements.txt
- Add the pip dependencies and version (one per line) as follows:
ujson==1.33
enum==0.4.6
- (Optional, but recommended: Commit the changes)
- Update your setup
NOTE: A bug (addressed here) in the Phovea generator is overriding changes made to the requirements.txt when running yo phovea:update
. You have to restore the modifications manually until the bug is fixed.
- Navigate to the workspace directory
- Run
yo phovea:workspace
to merge the dependencies of all cloned repos in the workspace directory - Override files if you will be asked to
- Run
docker-compose build
for server-side changes - Run
npm install
for client-side changes
- Run
npm install
to install new npm dependencies