From a989d72e6fe2e04c7b5fbe9fe64656bc0e646a08 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Sun, 6 Nov 2016 16:57:16 +0100 Subject: [PATCH] yo phovea:migrate --- .editorconfig | 21 ++ .gitattributes | 1 + .gitignore | 15 +- .npmignore | 6 - .travis.yml | 39 +++ .yo-rc.json | 192 ++++++++++++ LICENSE | 38 +-- README.md | 38 ++- __init__.py | 1 - debian_packages.txt | 0 karma.conf.js | 52 ++++ package.json | 251 ++++++---------- phovea.js | 74 +++++ phovea_registry.js | 18 ++ redhat_packages.txt | 0 requirements.txt | 5 + requirements_dev.txt | 4 + setup.cfg | 14 + setup.py | 78 +++++ Dialogs.ts => src/Dialogs.ts | 0 FormBuilder.ts => src/FormBuilder.ts | 0 LineUpCommands.ts => src/LineUpCommands.ts | 0 LineUpView.ts => src/LineUpView.ts | 0 LoginFirstView.ts => src/LoginFirstView.ts | 0 SessionList.ts => src/SessionList.ts | 0 SimpleView.ts => src/SimpleView.ts | 0 StartMenu.ts => src/StartMenu.ts | 0 Targid.ts => src/Targid.ts | 0 View.ts => src/View.ts | 0 WelcomeView.ts => src/WelcomeView.ts | 0 main.ts => src/index.ts | 0 storage.ts => src/storage.ts | 0 style.scss => src/style.scss | 0 src/tsd.d.ts | 13 + targid2/__init__.py | 42 +++ config.json => targid2/config.json | 0 processing.py => targid2/processing.py | 0 proxy.py => targid2/proxy.py | 0 sql.py => targid2/sql.py | 0 .../sql_use_gevent.py | 0 storage.py => targid2/storage.py | 0 tasks.py => targid2/tasks.py | 0 tests.webpack.js | 13 + tox.ini | 28 ++ tsconfig.json | 20 ++ tsd.d.ts | 39 ++- tslint.json | 81 +++++ typedoc.json | 13 + webpack.config.js | 279 ++++++++++++++++++ 49 files changed, 1168 insertions(+), 207 deletions(-) create mode 100644 .editorconfig delete mode 100644 .npmignore create mode 100644 .travis.yml create mode 100644 .yo-rc.json delete mode 100644 __init__.py create mode 100644 debian_packages.txt create mode 100644 karma.conf.js create mode 100644 phovea.js create mode 100644 phovea_registry.js create mode 100644 redhat_packages.txt create mode 100644 requirements.txt create mode 100644 requirements_dev.txt create mode 100644 setup.cfg create mode 100644 setup.py rename Dialogs.ts => src/Dialogs.ts (100%) rename FormBuilder.ts => src/FormBuilder.ts (100%) rename LineUpCommands.ts => src/LineUpCommands.ts (100%) rename LineUpView.ts => src/LineUpView.ts (100%) rename LoginFirstView.ts => src/LoginFirstView.ts (100%) rename SessionList.ts => src/SessionList.ts (100%) rename SimpleView.ts => src/SimpleView.ts (100%) rename StartMenu.ts => src/StartMenu.ts (100%) rename Targid.ts => src/Targid.ts (100%) rename View.ts => src/View.ts (100%) rename WelcomeView.ts => src/WelcomeView.ts (100%) rename main.ts => src/index.ts (100%) rename storage.ts => src/storage.ts (100%) rename style.scss => src/style.scss (100%) create mode 100644 src/tsd.d.ts create mode 100644 targid2/__init__.py rename config.json => targid2/config.json (100%) rename processing.py => targid2/processing.py (100%) rename proxy.py => targid2/proxy.py (100%) rename sql.py => targid2/sql.py (100%) rename sql_use_gevent.py => targid2/sql_use_gevent.py (100%) rename storage.py => targid2/storage.py (100%) rename tasks.py => targid2/tasks.py (100%) create mode 100644 tests.webpack.js create mode 100644 tox.ini create mode 100644 tsconfig.json create mode 100644 tslint.json create mode 100644 typedoc.json create mode 100644 webpack.config.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..c2cdfb8ad --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] + +# Change these settings to your own preference +indent_style = space +indent_size = 2 + +# We recommend you to keep these unchanged +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes index dd9ee06a0..833eaab46 100644 --- a/.gitattributes +++ b/.gitattributes @@ -20,6 +20,7 @@ *.less text *.styl text *.js text +*.ts text *.coffee text *.json text *.htm text diff --git a/.gitignore b/.gitignore index 44c6a8e46..ef3807032 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ - -*.log -*.pot -*.pyc -*.swp -*.lock +/.tscache +/.idea +/build/ +/dist/ +node_modules/ +/src/**/*.js +/tests/**/*.js *.map *.css -*.js \ No newline at end of file +*.log diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 1624fd7f4..000000000 --- a/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -*.log -*.pot -*.pyc -*.swp -*.lock -*.map \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..37c277413 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,39 @@ +language: python +sudo: required +env: + - TOXENV=py27 + - TOXENV=py34 + +node_js: +- 6 + +before_install: +- export DISPLAY=:99.0 +- sh -e /etc/init.d/xvfb start +- nvm install 6 +- if [[ `npm -v` != 3* ]]; then npm i -g npm@3; fi + +install: + - npm install + - sudo apt-get install cython + - pip install -r requirements_dev.txt + - pip install -r requirements.txt + +script: npm run dist + +deploy: + provider: releases + api_key: + secure: TK9/P34Bi3WuppiDrBCwVcn41yCBwmILaU8hXTBzUPbT7TbeFIwsC6/4CtH85Z+ZrUve4S5pTmWRNf2dQDxWw3uYu7+bJuemV2J1LHG76mognj+TNEiYxfLQUt3Gql4W7C7FcI4Rlx5/uMN9wY1wro8TWUBMwT6jjSrUWIvK3GXoojd5bHvJx07XpjWl9wCon4D0ruZiFoM2mdeP23lbc2GckETi32oEKswnQXxkMACmxbPzoWbvkxH4aK8Bt2Rj2sl2TbPhVkN6DAkHGkGAvLI+2/aRfG27+oo3OKsaDjbuGABct8TfZccJ970CbQ8kbnCjYxstvqkg1JWjF0W67sX/flBZZOEUA5l0OLWo6HqMGMxm7/lEQhIdPMsRmvXL+HVOxkMrB2dda58QzxVwiZp+rRqUaeabPZp8Kl5xodGrVxsBvxe6zAbJ5jCtCSumG6+kLyKI00/kYlghqQNrgUw0ZsYJlQ34h3lo/24QpaeyDpQoCkGWQgtgqiXGpeKSu7bCnOqIqAy3nbT9Utwj7K8gIasTG5idosEAz/THMampNbGDuyxxc340sYGNMg9Bhm1g2ILWRdtV470p5hwBtIDTKi3/PAizEO26+Wh0zI47Sg3ao57avcbCsTmzbZUeA5J4bojmchhJCHX8su9cSCGh/2fJA/1eBIgEvOQ8LNE= + file_glob: true + file: + - dist/targid2*.egg + - dist/targid2.tar.gz + on: + tags: true + +notifications: + slack: + secure: LH7fnnRykIAmW6H1qwuq0v6om7FeMUbcXTw5Y3jxavXXIlqVMFPCqz8ymBaLze1n0X6dtg1YLHV5M6XJozHr0ApGEdq9fIW8RimUtjHjDZ04hiZJdiIQwNIJHecRT7DbCJwOV67h9MekmMA1GRA6k/KUB9wGYy8FX7Hz9+XoV6K+/6tuIiMULApaJO3p5vhl1IGfmsU9Y2eWcx4Z3FuZdVhfB2TNjtmempiQvEUtj7BI3gkH5nX7yxxXV+aW1aiFLSWHYlzlYHLT03A22xSfrSdBXMxc/ESWMO/zUP3VE07DDssPnwdK4nmPU+f1rW8OzQBECqp8gloMP41kss0SFDn7ZhVnMbVxABR/F9Qd9/7gFI+/FJdZFwsA8em8PUFPPzsD/6cXUhuVksRVfax5fCe/NLNS20XDwpMSE4xkzkL2ZG0lT1XMv7uCgpMAlv2g+qtfBq7/D0rluzx3CCDODclWsx/avUFeFz98P0I573BpSYJFjTYJdF0jLd0Szev4MPqy1UqAqI5Dg49IdCYvxUGWvXdTqeFX5OIijr6WvgpxO6/swOzAa+i0kEV8PmC1Sa72jHoG2rJhvbZqxWLsyvNCtZU76osZuUr+efvAhFWmAKKpuhM19Dzt8xlanITm/r/a1MBoFU2D20DBE4jU/Ji2peuhJkMVv95656mYNa0= + on_success: change + on_failure: change diff --git a/.yo-rc.json b/.yo-rc.json new file mode 100644 index 000000000..eaa780d50 --- /dev/null +++ b/.yo-rc.json @@ -0,0 +1,192 @@ +{ + "generator-phovea": { + "type": "app-server", + "name": "targid2", + "author": "The Caleydo Team", + "githubAccount": "phovea", + "modules": [ + "phovea_clue", + "phovea_vis_lineup", + "phovea_data_mongo", + "phovea_data_redis" + ], + "extensions": [ + { + "type": "application", + "id": "targid2", + "module": "", + "extras": { + "name": "Target Discovery Platform" + } + }, + { + "type": "targidView", + "id": "startMenu", + "module": "StartMenu", + "extras": { + "name": "startMenu", + "factory": "create", + "idtype": "none", + "selection": "none" + } + }, + { + "type": "targidView", + "id": "login_first", + "module": "LoginFirstView", + "extras": { + "name": "Login First", + "factory": "create", + "idtype": "none", + "selection": "none" + } + }, + { + "type": "targidView", + "id": "welcome", + "module": "WelcomeView", + "extras": { + "name": "Welcome", + "factory": "create", + "idtype": "none", + "selection": "none" + } + }, + { + "type": "actionFactory", + "id": "targid2", + "module": "Targid", + "extras": { + "factory": "createCmd", + "creates": "(targidCreateView|targidRemoveView|targidReplaceView)" + } + }, + { + "type": "actionFactory", + "id": "targid2", + "module": "LineUpCommands", + "extras": { + "factory": "createCmd", + "creates": "(lineupAddRanking|lineupSetRankingSortCriteria|lineupSetColumn|lineupAddColumn)" + } + }, + { + "type": "actionCompressor", + "id": "targidCreateRemoveCompressor", + "module": "Targid", + "extras": { + "factory": "compressCreateRemove", + "matches": "(targidCreateView|targidRemoveView|targidReplaceView)" + } + }, + { + "type": "actionFactory", + "id": "targid2", + "module": "View", + "extras": { + "factory": "createCmd", + "creates": "(targidSetParameter|targidSetSelection)" + } + }, + { + "type": "actionCompressor", + "id": "targidCompressSetParameter", + "module": "View", + "extras": { + "factory": "compressSetParameter", + "matches": "(targidSetParameter)" + } + }, + { + "type": "actionCompressor", + "id": "targidCompressSetSelection", + "module": "View", + "extras": { + "factory": "compressSetSelection", + "matches": "(targidSetSelection)" + } + }, + { + "type": "targidStartSession", + "id": "targid_session_start", + "module": "SessionList", + "extras": { + "name": "Last Sessions", + "factory": "createStartFactory", + "idtype": "none", + "selection": "none" + } + } + ], + "sextensions": [ + { + "type": "namespace", + "id": "targid2", + "module": "proxy", + "extras": { + "namespace": "/api/targid/proxy" + } + }, + { + "type": "namespace", + "id": "db_connector", + "module": "sql", + "extras": { + "namespace": "/api/targid/db" + } + }, + { + "type": "namespace", + "id": "targid_storage", + "module": "storage", + "extras": { + "namespace": "/api/targid/storage" + } + }, + { + "type": "namespace", + "id": "processing", + "module": "processing", + "extras": { + "namespace": "/api/targid/processing" + } + }, + { + "type": "processing-task", + "id": "targid_tasks", + "module": "tasks", + "extras": {} + } + ], + "libraries": [ + "d3", + "lineupjs" + ], + "unknown": { + "requirements": [ + "requests==2.2.1", + "SQLAlchemy==1.0.12" + ], + "debianPackages": [], + "redhatPackages": [] + }, + "app": "", + "entries": { + "app": "./src/index.ts" + }, + "libraryAliases": { + "d3": "d3/d3" + }, + "libraryExternals": [ + "d3", + "lineupjs", + "marked", + "marked", + "lineupjs", + "d3", + "font-awesome" + ], + "ignores": [], + "today": "Sun, 06 Nov 2016 15:02:36 GMT" + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE index 2df8c26bd..fd6f461ca 100644 --- a/LICENSE +++ b/LICENSE @@ -1,28 +1,22 @@ -Copyright (c) 2014, The Caleydo Team +Copyright (c) 2016, The Caleydo Team All rights reserved. -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. + Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -* Neither the name of the {organization} nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + Neither the name of the Caleydo Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 1cd27dd21..d9a1c42ce 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,44 @@ -Caleydo Target Discovery Platform ![Caleydo Web Application](https://img.shields.io/badge/Caleydo%20Web-Application-1BA64E.svg) -=================== +targid2 [![Phovea][phovea-image]][phovea-url] [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] +===================== Target discovery platform for exploring rankings of genes, disease models, and other entities. Installation ------------ -[Set up a virtual machine using Vagrant](http://www.caleydo.org/documentation/vagrant/) and run these commands inside the virtual machine: +``` +git clone https://github.com/phovea/targid2.git +cd targid2 +npm install +``` + +Testing +------- -```bash -./manage.sh clone Caleydo/targid2 -./manage.sh resolve +``` +npm run test ``` +Building +-------- + +``` +npm run build +``` + + *** -This repository is part of **[Caleydo Web](http://caleydo.org/)**, a platform for developing web-based visualization applications. For tutorials, API docs, and more information about the build and deployment process, see the [documentation page](http://caleydo.org/documentation/). +This repository is part of **[Phovea](http://phovea.caleydo.org/)**, a platform for developing web-based visualization applications. For tutorials, API docs, and more information about the build and deployment process, see the [documentation page](http://caleydo.org/documentation/). + + +[phovea-image]: https://img.shields.io/badge/Phovea-Client%20Plugin-F47D20.svg +[phovea-url]: https://phovea.caleydo.org +[npm-image]: https://badge.fury.io/js/targid2.svg +[npm-url]: https://npmjs.org/package/targid2 +[travis-image]: https://travis-ci.org/phovea/targid2.svg?branch=master +[travis-url]: https://travis-ci.org/phovea/targid2 +[daviddm-image]: https://david-dm.org/phovea/targid2.svg?theme=shields.io +[daviddm-url]: https://david-dm.org/phovea/targid2 diff --git a/__init__.py b/__init__.py deleted file mode 100644 index 1a8c7e974..000000000 --- a/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'Samuel Gratzl' diff --git a/debian_packages.txt b/debian_packages.txt new file mode 100644 index 000000000..e69de29bb diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..d15ca8bf6 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,52 @@ +/* ***************************************************************************** + * Caleydo - Visualization for Molecular Biology - http://caleydo.org + * Copyright (c) The Caleydo Team. All rights reserved. + * Licensed under the new BSD license, available at http://caleydo.org/license + **************************************************************************** */ + +const webpack = require('./webpack.config.js'); + +module.exports = (config) => { + config.set({ + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + // list of files / patterns to load in the browser + files: [ + 'tests.webpack.js' //just load this file + ], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + // add webpack as preprocessor + 'tests.webpack.js': ['webpack', 'sourcemap'] + }, + + webpack: webpack('test'), + + failOnEmptyTestSuite: false, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: false, + + // middleware: ['polyfill'], + // BUG that install everything "karma-polyfill-service": "github:sgratzl/karma-polyfill-service", + polyfill: { + // features: '', // feature set, see polyfill-service docs for details, defaults to `{default: {}}` + // path: '' // path to serve the polyfill script under, defaults to '/polyfill.js' + }, + + browsers: [process.env.CONTINUOUS_INTEGRATION ? 'Firefox' : 'Chrome'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true + }); +}; diff --git a/package.json b/package.json index e6d2a7d75..a10c2d247 100644 --- a/package.json +++ b/package.json @@ -1,163 +1,104 @@ { + "files": [ + "src", + "index.js", + "phovea.js", + "phovea_registry.js", + "build", + "targid2", + "__init__.py", + "__main__.py", + "requirements.txt", + "requirements_dev.txt", + "debian_packages.txt", + "redhat_packages.txt" + ], + "scripts": { + "check": "flake8", + "pretest": "echo hybrid", + "test": "npm run test:web && npm run test:python", + "predist": "echo hybrid", + "dist": "npm run dist:web && npm run dist:web", + "compile": "tsc", + "lint": "tslint -c tslint.json src/**.ts tests/**.ts", + "docs": "typedoc --options typedoc.json src/**.ts", + "prebuild": "npm run test", + "posttest": "echo hybrid", + "test:watch": "karma start --autoWatch=true --singleRun=false", + "build:dev": "webpack", + "build": "webpack --env prod", + "start": "webpack-dev-server --inline", + "start:hot": "webpack-dev-server --inline --hot", + "watch": "webpack --watch", + "release:major": "npm version major && npm publish && git push --follow-tags", + "release:minor": "npm version minor && npm publish && git push --follow-tags", + "release:patch": "npm version patch && npm publish && git push --follow-tags", + "pretest:web": "npm run compile", + "pretest:python": "npm run check", + "posttest:web": "npm run lint", + "test:web": "karma start", + "test:python": "python setup.py test", + "predist:web": "npm run build", + "dist:web": "mkdirp dist && cd build && tar cvzf ../dist/targid2.tar.gz *", + "dist:python": "python setup.py bdist_egg" + }, + "main": "build/targid2.js", + "engines": { + "npm": ">= 3", + "node": ">= 6", + "iojs": ">= 3" + }, + "devDependencies": { + "@types/jasmine": "^2.5.35", + "awesome-typescript-loader": "^2.2.4", + "css-loader": "^0.25.0", + "extract-text-webpack-plugin": "^2.0.0-beta.4", + "file-loader": "^0.9.0", + "html-loader": "^0.4.4", + "imports-loader": "^0.6.5", + "jasmine": "^2.5.2", + "json-loader": "^0.5.4", + "karma": "^1.3.0", + "karma-chrome-launcher": "^2.0.0", + "karma-firefox-launcher": "^1.0.0", + "karma-jasmine": "^1.0.2", + "karma-junit-reporter": "^1.1.0", + "karma-sourcemap-loader": "^0.3.7", + "karma-webpack": "^1.8.0", + "mkdirp": "^0.5.1", + "node-sass": "^3.10.0", + "null-loader": "^0.1.1", + "raw-loader": "^0.5.1", + "sass-loader": "^4.0.2", + "style-loader": "^0.13.1", + "tslint": "^3.15.1", + "typedoc": "^0.5.1", + "typescript": "^2.0.6", + "url-loader": "^0.5.7", + "webpack": "^2.1.0-beta.25", + "webpack-dev-server": "^2.1.0-beta.10" + }, + "dependencies": { + "phovea_vis_lineup": "github:phovea/phovea_vis_lineup", + "@types/d3": "^3.5.36", + "d3": "^3.5.17", + "lineupjs": "github:Caleydo/lineup.js#feature_146_react" + }, "name": "targid2", - "title": "Target Discovery Platform", "description": "Target discovery platform for exploring rankings of genes, disease models, and other entities.", + "homepage": "https://phovea.caleydo.org", "version": "0.0.1", - "license": "SEE LICENSE IN LICENSE", - "repository": "Caleydo/targid2", - "dependencies": { - }, - "peerDependencies": { - "caleydo_clue": "*", - "caleydo_vis_lineup": "*", - "caleydo_data_mongo": "*", - "caleydo_data_redis": "*" + "author": { + "name": "The Caleydo Team", + "email": "contact@caleydo.org", + "url": "https://caleydo.org" }, - "caleydo": { - "plugins": { - "web": [ - { - "type": "application", - "name": "Target Discovery Platform" - }, - { - "id": "startMenu", - "name": "startMenu", - "type": "targidView", - "file": "StartMenu", - "factory": "create", - "idtype": "none", - "selection": "none" - }, - { - "id": "login_first", - "name": "Login First", - "type": "targidView", - "file": "LoginFirstView", - "factory": "create", - "idtype": "none", - "selection": "none" - }, - { - "id": "welcome", - "name": "Welcome", - "type": "targidView", - "file": "WelcomeView", - "factory": "create", - "idtype": "none", - "selection": "none" - }, - { - "type": "actionFactory", - "file": "Targid", - "factory": "createCmd", - "creates": "(targidCreateView|targidRemoveView|targidReplaceView)" - }, - { - "type": "actionFactory", - "file": "LineUpCommands", - "factory": "createCmd", - "creates": "(lineupAddRanking|lineupSetRankingSortCriteria|lineupSetColumn|lineupAddColumn)" - }, - { - "type": "actionCompressor", - "id": "targidCreateRemoveCompressor", - "file": "Targid", - "factory": "compressCreateRemove", - "matches": "(targidCreateView|targidRemoveView|targidReplaceView)" - }, - { - "type": "actionFactory", - "file": "View", - "factory": "createCmd", - "creates": "(targidSetParameter|targidSetSelection)" - }, - { - "type": "actionCompressor", - "id": "targidCompressSetParameter", - "file": "View", - "factory": "compressSetParameter", - "matches": "(targidSetParameter)" - }, - { - "type": "actionCompressor", - "id": "targidCompressSetSelection", - "file": "View", - "factory": "compressSetSelection", - "matches": "(targidSetSelection)" - }, - { - "id": "targid_session_start", - "name": "Last Sessions", - "type": "targidStartSession", - "file": "SessionList", - "factory": "createStartFactory", - "idtype": "none", - "selection": "none" - } - ], - "python": [ - { - "type": "namespace", - "file": "proxy", - "namespace": "/api/targid/proxy" - }, - { - "type": "namespace", - "id": "db_connector", - "file": "sql", - "namespace": "/api/targid/db" - }, - { - "type": "namespace", - "id": "targid_storage", - "file": "storage", - "namespace": "/api/targid/storage" - }, - { - "type": "namespace", - "id": "processing", - "file": "processing", - "namespace": "/api/targid/processing" - }, - { - "type": "processing-task", - "id": "targid_tasks", - "file": "tasks" - } - ] - }, - "dependencies": { - "web": { - "d3": "~3.5.5", - "lineupjs": "https://github.com/Caleydo/lineup.js.git", - "scrollTo": "https://github.com/flesler/jquery.scrollTo.git", - "select2": "~4.0.3", - "select2-bootstrap-theme": "0.1.0-beta.9" - }, - "python": { - "requests": "==2.2.1", - "SQLAlchemy": "==1.0.12" - }, - "tsd": { - "select2": "f4efd4" - } - }, - "requirejs-config": { - "paths": { - "select2": "${baseUrl}/bootstrap/dist/js/select2.full.min" - }, - "shim": { - "select2": [ - "jquery", - "bootstrap", - "css!${baseUrl}/select2/dist/css/select2.min.css", - "css!${baseUrl}/select2-bootstrap-theme/dist/select2-bootstrap.min.css" - ] - } - } + "license": "BSD-3-Clause", + "bugs": { + "url": "https://github.com/phovea/targid2/issues" }, - "publishConfig": { - "registry": "http://registry.caleydo.org/" + "repository": { + "type": "git", + "url": "https://github.com/phovea/targid2.git" } } diff --git a/phovea.js b/phovea.js new file mode 100644 index 000000000..baf354592 --- /dev/null +++ b/phovea.js @@ -0,0 +1,74 @@ +/* ***************************************************************************** + * Caleydo - Visualization for Molecular Biology - http://caleydo.org + * Copyright (c) The Caleydo Team. All rights reserved. + * Licensed under the new BSD license, available at http://caleydo.org/license + **************************************************************************** */ + +//register all extensions in the registry following the given pattern +module.exports = function(registry) { + //registry.push('extension-type', 'extension-id', function() { return System.import('./src/extension_impl'); }, {}); + // generator-phovea:begin + registry.push('application', 'targid2', function() { return System.import('./src/'); }, { + 'name': 'Target Discovery Platform' + }); + + registry.push('targidView', 'startMenu', function() { return System.import('./src/StartMenu'); }, { + 'name': 'startMenu', + 'factory': 'create', + 'idtype': 'none', + 'selection': 'none' + }); + + registry.push('targidView', 'login_first', function() { return System.import('./src/LoginFirstView'); }, { + 'name': 'Login First', + 'factory': 'create', + 'idtype': 'none', + 'selection': 'none' + }); + + registry.push('targidView', 'welcome', function() { return System.import('./src/WelcomeView'); }, { + 'name': 'Welcome', + 'factory': 'create', + 'idtype': 'none', + 'selection': 'none' + }); + + registry.push('actionFactory', 'targid2', function() { return System.import('./src/Targid'); }, { + 'factory': 'createCmd', + 'creates': '(targidCreateView|targidRemoveView|targidReplaceView)' + }); + + registry.push('actionFactory', 'targid2', function() { return System.import('./src/LineUpCommands'); }, { + 'factory': 'createCmd', + 'creates': '(lineupAddRanking|lineupSetRankingSortCriteria|lineupSetColumn|lineupAddColumn)' + }); + + registry.push('actionCompressor', 'targidCreateRemoveCompressor', function() { return System.import('./src/Targid'); }, { + 'factory': 'compressCreateRemove', + 'matches': '(targidCreateView|targidRemoveView|targidReplaceView)' + }); + + registry.push('actionFactory', 'targid2', function() { return System.import('./src/View'); }, { + 'factory': 'createCmd', + 'creates': '(targidSetParameter|targidSetSelection)' + }); + + registry.push('actionCompressor', 'targidCompressSetParameter', function() { return System.import('./src/View'); }, { + 'factory': 'compressSetParameter', + 'matches': '(targidSetParameter)' + }); + + registry.push('actionCompressor', 'targidCompressSetSelection', function() { return System.import('./src/View'); }, { + 'factory': 'compressSetSelection', + 'matches': '(targidSetSelection)' + }); + + registry.push('targidStartSession', 'targid_session_start', function() { return System.import('./src/SessionList'); }, { + 'name': 'Last Sessions', + 'factory': 'createStartFactory', + 'idtype': 'none', + 'selection': 'none' + }); + // generator-phovea:end +}; + diff --git a/phovea_registry.js b/phovea_registry.js new file mode 100644 index 000000000..0d1f38023 --- /dev/null +++ b/phovea_registry.js @@ -0,0 +1,18 @@ +/* ***************************************************************************** + * Caleydo - Visualization for Molecular Biology - http://caleydo.org + * Copyright (c) The Caleydo Team. All rights reserved. + * Licensed under the new BSD license, available at http://caleydo.org/license + **************************************************************************** */ + +import {register} from 'phovea_core/src/plugin'; + +/** + * build a registry by registering all phovea modules + */ +//other modules +import 'phovea_clue/phovea_registry.js'; +import 'phovea_vis_lineup/phovea_registry.js'; +import 'phovea_data_mongo/phovea_registry.js'; +import 'phovea_data_redis/phovea_registry.js'; +//self +register('targid2',require('./phovea.js')); diff --git a/redhat_packages.txt b/redhat_packages.txt new file mode 100644 index 000000000..e69de29bb diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..6c538e8f0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +-e git+https://github.com/phovea/phovea_clue.git#egg=phovea_clue +-e git+https://github.com/phovea/phovea_data_mongo.git#egg=phovea_data_mongo +-e git+https://github.com/phovea/phovea_data_redis.git#egg=phovea_data_redis +requests==2.2.1 +SQLAlchemy==1.0.12 \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 000000000..0e2902f5b --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,4 @@ +flake8==3.0.4 +pep8-naming==0.4.1 +pytest==3.0.3 +pytest-runner==2.9 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..5519f8559 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,14 @@ +############################################################################### +# Caleydo - Visualization for Molecular Biology - http://caleydo.org +# Copyright (c) The Caleydo Team. All rights reserved. +# Licensed under the new BSD license, available at http://caleydo.org/license +############################################################################### + +[bdist_wheel] +# This flag says that the code is written to work on both Python 2 and Python +# 3. If at all possible, it is good practice to do this. If you cannot, you +# will need to generate wheels for each Python version that you support. +universal=1 + +[aliases] +test=pytest diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..707d47c0f --- /dev/null +++ b/setup.py @@ -0,0 +1,78 @@ +############################################################################### +# Caleydo - Visualization for Molecular Biology - http://caleydo.org +# Copyright (c) The Caleydo Team. All rights reserved. +# Licensed under the new BSD license, available at http://caleydo.org/license +############################################################################### +from __future__ import with_statement, print_function +from setuptools import setup +from codecs import open +from os import path + +here = path.abspath(path.dirname(__file__)) + + +def read_it(name): + with open(path.join(here, name), encoding='utf-8') as f: + return f.read() + +# read package.json information +with open(path.join(here, 'package.json'), encoding='utf-8') as json_data: + import json + pkg = json.load(json_data) + + +def packaged(*files): + r = {} + global pkg + r[pkg['name'].encode('ascii')] = list(files) + return r + +setup( + name=pkg['name'], + version=pkg['version'], + description=pkg['description'], + long_description=read_it('README.md'), + keywords=pkg.get('keywords', ''), + author=pkg['author']['name'], + author_email=pkg['author']['email'], + license=pkg['license'], + zip_safe=False, + + entry_points={ + 'phovea.registry': ['{0} = {0}:phovea'.format(pkg['name'])], + 'phovea.config': ['{0} = {0}:phovea_config'.format(pkg['name'])] + }, + + # See https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + 'Intended Audience :: Developers', + 'Operating System :: OS Independent', + # Pick your license as you wish (should match "license" above) + 'License :: OSI Approved :: ' + pkg['license'], + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4' + ], + + # You can just specify the packages manually here if your project is + # simple. Or you can use find_packages(). + py_modules=[pkg['name']], + + # List run-time dependencies here. These will be installed by pip when + # your project is installed. For an analysis of "install_requires" vs pip's + # requirements files see: + # https://packaging.python.org/en/latest/requirements.html + install_requires=read_it('requirements.txt').split('\n'), + tests_require=read_it('requirements_dev.txt').split('\n'), + + # If there are data files included in your packages that need to be + # installed, specify them here. If using Python 2.6 or less, then these + # have to be included in MANIFEST.in as well. + package_data=packaged('config.json'), + + # Although 'package_data' is the preferred approach, in some case you may + # need to place data files outside of your packages. See: + # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa + # In this case, 'data_file' will be installed into '/my_data' + data_files=[] # [('my_data', ['data/data_file'])], +) diff --git a/Dialogs.ts b/src/Dialogs.ts similarity index 100% rename from Dialogs.ts rename to src/Dialogs.ts diff --git a/FormBuilder.ts b/src/FormBuilder.ts similarity index 100% rename from FormBuilder.ts rename to src/FormBuilder.ts diff --git a/LineUpCommands.ts b/src/LineUpCommands.ts similarity index 100% rename from LineUpCommands.ts rename to src/LineUpCommands.ts diff --git a/LineUpView.ts b/src/LineUpView.ts similarity index 100% rename from LineUpView.ts rename to src/LineUpView.ts diff --git a/LoginFirstView.ts b/src/LoginFirstView.ts similarity index 100% rename from LoginFirstView.ts rename to src/LoginFirstView.ts diff --git a/SessionList.ts b/src/SessionList.ts similarity index 100% rename from SessionList.ts rename to src/SessionList.ts diff --git a/SimpleView.ts b/src/SimpleView.ts similarity index 100% rename from SimpleView.ts rename to src/SimpleView.ts diff --git a/StartMenu.ts b/src/StartMenu.ts similarity index 100% rename from StartMenu.ts rename to src/StartMenu.ts diff --git a/Targid.ts b/src/Targid.ts similarity index 100% rename from Targid.ts rename to src/Targid.ts diff --git a/View.ts b/src/View.ts similarity index 100% rename from View.ts rename to src/View.ts diff --git a/WelcomeView.ts b/src/WelcomeView.ts similarity index 100% rename from WelcomeView.ts rename to src/WelcomeView.ts diff --git a/main.ts b/src/index.ts similarity index 100% rename from main.ts rename to src/index.ts diff --git a/storage.ts b/src/storage.ts similarity index 100% rename from storage.ts rename to src/storage.ts diff --git a/style.scss b/src/style.scss similarity index 100% rename from style.scss rename to src/style.scss diff --git a/src/tsd.d.ts b/src/tsd.d.ts new file mode 100644 index 000000000..d6bc7a6ef --- /dev/null +++ b/src/tsd.d.ts @@ -0,0 +1,13 @@ +/** + * declare lineup mock + */ + +declare var lineupjs: any; +declare module 'lineupjs' { + export = lineupjs; +} + +declare var scrollto: any; +declare module 'scrollto' { + export = scrollto; +} diff --git a/targid2/__init__.py b/targid2/__init__.py new file mode 100644 index 000000000..8e8d3bb6f --- /dev/null +++ b/targid2/__init__.py @@ -0,0 +1,42 @@ +############################################################################### +# Caleydo - Visualization for Molecular Biology - http://caleydo.org +# Copyright (c) The Caleydo Team. All rights reserved. +# Licensed under the new BSD license, available at http://caleydo.org/license +############################################################################### + + +def phovea(registry): + """ + register extension points + :param registry: + """ + # generator-phovea:begin + registry.append('namespace', 'targid2', 'targid2.proxy', { + 'namespace': '/api/targid/proxy' + }) + + registry.append('namespace', 'db_connector', 'targid2.sql', { + 'namespace': '/api/targid/db' + }) + + registry.append('namespace', 'targid_storage', 'targid2.storage', { + 'namespace': '/api/targid/storage' + }) + + registry.append('namespace', 'processing', 'targid2.processing', { + 'namespace': '/api/targid/processing' + }) + + registry.append('processing-task', 'targid_tasks', 'targid2.tasks', {}) + # generator-phovea:end + pass + + +def phovea_config(): + """ + :return: file pointer to config file + """ + from os import path + here = path.abspath(path.dirname(__file__)) + config_file = path.join(here, 'config.json') + return config_file if path.exists(config_file) else None diff --git a/config.json b/targid2/config.json similarity index 100% rename from config.json rename to targid2/config.json diff --git a/processing.py b/targid2/processing.py similarity index 100% rename from processing.py rename to targid2/processing.py diff --git a/proxy.py b/targid2/proxy.py similarity index 100% rename from proxy.py rename to targid2/proxy.py diff --git a/sql.py b/targid2/sql.py similarity index 100% rename from sql.py rename to targid2/sql.py diff --git a/sql_use_gevent.py b/targid2/sql_use_gevent.py similarity index 100% rename from sql_use_gevent.py rename to targid2/sql_use_gevent.py diff --git a/storage.py b/targid2/storage.py similarity index 100% rename from storage.py rename to targid2/storage.py diff --git a/tasks.py b/targid2/tasks.py similarity index 100% rename from tasks.py rename to targid2/tasks.py diff --git a/tests.webpack.js b/tests.webpack.js new file mode 100644 index 000000000..e0b87546a --- /dev/null +++ b/tests.webpack.js @@ -0,0 +1,13 @@ +/* ***************************************************************************** + * Caleydo - Visualization for Molecular Biology - http://caleydo.org + * Copyright (c) The Caleydo Team. All rights reserved. + * Licensed under the new BSD license, available at http://caleydo.org/license + **************************************************************************** */ + +//build registry +require('./phovea_registry.js'); +/** + * find all tests in the spec directory and load them + */ +var context = require.context('./tests', true, /\.test\.ts$/); //make sure you have your directory and regex test set correctly! +context.keys().forEach(context); diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000..f2734b2ba --- /dev/null +++ b/tox.ini @@ -0,0 +1,28 @@ +############################################################################### +# Caleydo - Visualization for Molecular Biology - http://caleydo.org +# Copyright (c) The Caleydo Team. All rights reserved. +# Licensed under the new BSD license, available at http://caleydo.org/license +############################################################################### + +[tox] +envlist = py{27,34} + +[testenv] +basepython = + py27: python2.7 + py34: python3.4 +deps = + flake8 + pytest +commands = + check-manifest --ignore tox.ini,tests* + python setup.py check -m -r -s + flake8 . + py.test tests + +[flake8] +ignore=E111,E114,E501 +exclude = .tox,*.egg,build,data,.git,__pycache__,docs,node_modules + +[pytest] +testpaths = tests diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..aa39f1023 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "es6", + "target": "es5", + "noImplicitAny": false, + "sourceMap": true, + "moduleResolution": "node", + "lib": [ + "dom", + "es2015" + ], + "baseUrl": "../" + }, + "include": [ + "src/**/*.ts", + "tests/**/*.ts", + "index.ts", + "tsd.d.ts" + ] +} diff --git a/tsd.d.ts b/tsd.d.ts index d6bc7a6ef..b13f4f9f7 100644 --- a/tsd.d.ts +++ b/tsd.d.ts @@ -1,13 +1,34 @@ -/** - * declare lineup mock - */ +/* ***************************************************************************** + * Caleydo - Visualization for Molecular Biology - http://caleydo.org + * Copyright (c) The Caleydo Team. All rights reserved. + * Licensed under the new BSD license, available at http://caleydo.org/license + **************************************************************************** */ -declare var lineupjs: any; -declare module 'lineupjs' { - export = lineupjs; +//allow sass modules +declare module "*.scss" { + const content:string; + export default content; } +declare module "*.png"; +//allow html dependencies +declare module "*.html" { + const content:string; + export default content; +} +//allow json dependencies +declare module "*.json"; +//allow file dependencies +declare module "file!*"; +//allow file dependencies +declare module "raw!*"; +//allow url dependencies +declare module "url!*"; +//allow html dependencies +declare module "import!*"; + -declare var scrollto: any; -declare module 'scrollto' { - export = scrollto; +//define System.import as understood by webpack2 +interface ISystem { + import(module: string): Promise; } +declare const System: ISystem; diff --git a/tslint.json b/tslint.json new file mode 100644 index 000000000..0818c82ba --- /dev/null +++ b/tslint.json @@ -0,0 +1,81 @@ +{ + "rules": { + "ban": [true, ["_", "extend"], + ["_", "isNull"], + ["_", "isDefined"] + ], + "class-name": true, + "comment-format": false, + "curly": true, + "eofline": true, + "forin": true, + "indent": [true, 2], + "interface-name": true, + "jsdoc-format": true, + "label-position": true, + "label-undefined": true, + "max-line-length": false, + "member-ordering": [false, + "public-before-private", + "static-before-instance", + "variables-before-functions" + ], + "no-arg": true, + "no-bitwise": true, + "no-console": [true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": true, + "no-eval": true, + "no-string-literal": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-unreachable": true, + "no-use-before-declare": true, + "no-var-requires": true, + "one-line": [true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [true, "single"], + "radix": true, + "semicolon": true, + "triple-equals": [true, "allow-null-check"], + "typedef": [false, + "callSignature", + "indexSignature", + "parameter", + "propertySignature", + "variableDeclarator" + ], + "typedef-whitespace": [true, ["callSignature", "noSpace"], + ["catchClause", "noSpace"], + ["indexSignature", "space"] + ], + "use-strict": [false, + "check-module", + "check-function" + ], + "variable-name": false, + "whitespace": [false, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +} diff --git a/typedoc.json b/typedoc.json new file mode 100644 index 000000000..b2127db6d --- /dev/null +++ b/typedoc.json @@ -0,0 +1,13 @@ +{ + "mode": "modules", + "out": "./docs", + "theme": "minimal", + "ignoreCompilerErrors": false, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "preserveConstEnums": true, + "stripInternal": true, + "suppressExcessPropertyErrors": true, + "suppressImplicitAnyIndexErrors": true, + "exclude": "**/*.test.ts" +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 000000000..78d1eabeb --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,279 @@ +/* ***************************************************************************** + * Caleydo - Visualization for Molecular Biology - http://caleydo.org + * Copyright (c) The Caleydo Team. All rights reserved. + * Licensed under the new BSD license, available at http://caleydo.org/license + **************************************************************************** */ + +const {libraryAliases, libraryExternals, modules, entries, ignores, type} = require('./.yo-rc.json')['generator-phovea']; +const resolve = require('path').resolve; +const pkg = require('./package.json'); +const webpack = require('webpack'); +const exists = require('fs').existsSync; +const ExtractTextPlugin = require('extract-text-webpack-plugin'); + +const year = (new Date()).getFullYear(); +const banner = '/*! ' + (pkg.title || pkg.name) + ' - v' + pkg.version + ' - ' + year + '\n' + + (pkg.homepage ? '* ' + pkg.homepage + '\n' : '') + + '* Copyright (c) ' + year + ' ' + pkg.author.name + ';' + + ' Licensed ' + pkg.license + '*/\n'; + + +//list of loaders and their mappings +const webpackloaders = [ + {test: /\.scss$/, loader: 'style!css!sass'}, + {test: /\.tsx?$/, loader: 'awesome-typescript-loader'}, + {test: /\.json$/, loader: 'json-loader'}, + { + test: /\.(png|jpg)$/, + loader: 'url-loader', + query: { + limit: 10000, //inline <= 10kb + } + }, + { + test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, + loader: 'url-loader', + query: { + limit: 10000, //inline <= 10kb + mimetype: 'application/font-woff' + } + }, + { + test: /\.svg(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, + loader: 'url-loader', + query: { + limit: 10000, //inline <= 10kb + mimetype: 'image/svg+xml' + } + }, + {test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader'} +]; + +/** + * tests whether the given phovea module name is matching the requested file and if so convert it to an external lookup + * depending on the loading type + **/ +function testPhoveaModule(moduleName, request) { + if (!(new RegExp('^' + moduleName + '/src.*')).test(request)) { + return false; + } + const subModule = request.match(/.*\/src\/?(.*)/)[1]; + //skip empty modules = root + const path = subModule === '' ? [moduleName] : [moduleName, subModule]; + //phovea_ ... phovea.name + const rootPath = /phovea_.*/.test(moduleName) ? ['phovea', moduleName.slice(7)].concat(path.slice(1)) : path; + return { + root: rootPath, + commonjs2: path, + commonjs: path, + amd: request + (subModule === '' ? '/main' : '') + }; +} + +function testPhoveaModules(modules) { + return (context, request, callback) => { + for (let i = 0; i < modules.length; ++i) { + var r = testPhoveaModule(modules[i], request); + if (r) { + return callback(null, r); + } + } + callback(); + }; +} + +// use ueber registry file if available +const registryFile = exists(resolve(__dirname, '..', 'phovea_registry.js')) ? '../phovea_registry.js' : './phovea_registry.js'; + +/** + * inject the registry to be included + * @param entry + * @returns {*} + */ +function injectRegistry(entry) { + //build also the registry + if (typeof entry === 'string') { + return [registryFile].concat(entry); + } else { + var transformed = {}; + Object.keys(entry).forEach((eentry) => { + transformed[eentry] = [registryFile].concat(entry[eentry]); + }); + return transformed; + } + +} +/** + * generate a webpack configuration + */ +function generateWebpack(options) { + var base = { + entry: injectRegistry(options.entries), + output: { + path: resolve(__dirname, 'build'), + filename: (options.name || (pkg.name + (options.bundle ? '_bundle' : ''))) + (options.min ? '.min' : '') + '.js', + publicPath: '' //no public path = relative + }, + resolve: { + // Add `.ts` and `.tsx` as a resolvable extension. + extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js'], + alias: Object.assign({}, options.libs || {}), + //fallback to the directory above if they are siblings + modules: [ + resolve(__dirname, '../'), + 'node_modules' + ] + }, + plugins: [ + new webpack.BannerPlugin({ + banner: banner, + raw: true + }), + //define magic constants that are replaced + new webpack.DefinePlugin({ + __VERSION__: JSON.stringify(pkg.version), + __LICENSE__: JSON.stringify(pkg.license) + }), + new webpack.optimize.MinChunkSizePlugin({ + minChunkSize: 10000 //at least 10.000 characters + }), + new webpack.optimize.AggressiveMergingPlugin() + //rest depends on type + ], + externals: [], + module: { + loaders: webpackloaders.slice() + }, + devServer: { + proxy: { + '/api/*': { + target: 'http://localhost:9000', + secure: false + } + }, + contentBase: resolve(__dirname, 'build') + } + }; + if (options.library) { + //generate a library, i.e. output the last entry element + //create library name + var libName = /phovea_.*/.test(pkg.name) ? ['phovea', pkg.name.slice(7)] : pkg.name; + if (options.moduleBundle) { + libName = 'phovea'; + } + base.output.library = libName; + base.output.libraryTarget = 'umd'; + base.output.umdNamedDefine = false; //anonymous require module + } + + + if (!options.bundle) { + //if we don't bundle don't include external libraries and other phovea modules + base.externals.push(...(options.externals || Object.keys(options.libs || {}))); + + //ignore all phovea modules + if (options.modules) { + base.externals.push(testPhoveaModules(options.modules)); + } + + //ignore extra modules + (options.ignore || []).forEach(function (d) { + base.module.loaders.push({test: new RegExp(d), loader: 'null'}); //use null loader + }); + //ingore phovea module registry calls + (options.modules || []).forEach(function (m) { + base.module.loaders.push({test: new RegExp('.*[\\\\/]' + m + '[\\\\/]phovea_registry.js'), loader: 'null'}); //use null loader + }); + + //extract the included css file to own file + var p = new ExtractTextPlugin('style' + (options.min ? '.min' : '') + '.css'); + base.plugins.push(p); + base.module.loaders[0] = { + test: /\.scss$/, + loader: p.extract(['css', 'sass']) + }; + } + if (options.commons) { + //build a commons plugin + base.plugins.push(new webpack.optimize.CommonsChunkPlugin({ + // The order of this array matters + names: ['common'], + minChunks: 2 + })); + } + if (options.min) { + //use a minifier + base.plugins.push( + new webpack.LoaderOptionsPlugin({ + minimize: true, + debug: false + }), + new webpack.optimize.UglifyJsPlugin({ + compress: { + warnings: false + }, + output: { + comments: false + }, + sourceMap: false + })); + } else { + //generate source maps + base.devtool = 'source-map'; + } + return base; +} + +function generateWebpackConfig(env) { + const isTest = env === 'test'; + const isProduction = env === 'prod'; + const isDev = !isProduction && !isTest; + + const base = { + entries: entries, + libs: libraryAliases, + externals: libraryExternals, + modules: modules, + ignore: ignores + }; + + if (isTest) { + return generateWebpack(Object.assign({}, base, { + bundle: true + })); + } + + if (type === 'app') { + base.bundle = true; //bundle everything together + base.name = '[name]'; //multiple entries case + base.commons = true; //extract commons module + } else if (type === 'bundle') { + base.library = true; //expose as library + base.moduleBundle = true; //expose as library 'phovea' + base.name = pkg.name; //to avoid adding _bundle + base.bundle = true; + } else { //type === 'lib' + base.library = true; + } + + //single generation + if (isDev) { + return generateWebpack(base); + } else if (type === 'app') { //isProduction app + return generateWebpack(Object.assign({}, base, { + min: true + })); + } else { //isProduction + return [ + //plain + generateWebpack(base), + //minified + generateWebpack(Object.assign({}, base, { + min: true + })) + ]; + } +} + +module.exports = generateWebpackConfig; +module.exports.generateWebpack = generateWebpack;