From cf2c56c7061b7ed40fdd3b40a352ddb9c9b7371f Mon Sep 17 00:00:00 2001 From: alexwl Date: Tue, 2 Oct 2018 13:17:04 +0300 Subject: Initial commit --- javascript/server/.eslintrc.js | 5 + javascript/server/index.js | 30 +++ javascript/server/mocks/packages.js | 397 ++++++++++++++++++++++++++++++++++++ 3 files changed, 432 insertions(+) create mode 100644 javascript/server/.eslintrc.js create mode 100644 javascript/server/index.js create mode 100644 javascript/server/mocks/packages.js (limited to 'javascript/server') diff --git a/javascript/server/.eslintrc.js b/javascript/server/.eslintrc.js new file mode 100644 index 0000000..1147d29 --- /dev/null +++ b/javascript/server/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + env: { + node: true + } +}; diff --git a/javascript/server/index.js b/javascript/server/index.js new file mode 100644 index 0000000..eadf932 --- /dev/null +++ b/javascript/server/index.js @@ -0,0 +1,30 @@ +/* eslint-env node */ +'use strict'; + +//https://discuss.emberjs.com/t/how-to-disable-http-mock-server-within-environment-config-file/6660/9 + +//To use http mocks from server/mocks for testing: +//ember server +//To use real server: +//ember server --proxy=http://localhost:8080/ + +function usingProxy() { + return !!process.argv.filter(function (arg) { + return arg.indexOf('--proxy') === 0; + }).length; +} + +module.exports = function(app) { + if (usingProxy()) { return; } + + const globSync = require('glob').sync; + const mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require); + const proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require); + + // Log proxy requests + const morgan = require('morgan'); + app.use(morgan('dev')); + + mocks.forEach(route => route(app)); + proxies.forEach(route => route(app)); +}; diff --git a/javascript/server/mocks/packages.js b/javascript/server/mocks/packages.js new file mode 100644 index 0000000..5da80b2 --- /dev/null +++ b/javascript/server/mocks/packages.js @@ -0,0 +1,397 @@ +/* eslint-env node */ +'use strict'; + +const packages = [ + { + "versions": [ + "0.1.0.0" + ], + "name": "test-package" + } +]; + +const testPackage = { + "directoryTree": { + "tag": "Dir", + "contents": [ + { + "tag": "File", + "path": "Setup.hs", + "isHaskellModule": false, + "name": "Setup.hs" + }, + { + "tag": "File", + "path": "stack-8.0.2.yaml", + "isHaskellModule": false, + "name": "stack-8.0.2.yaml" + }, + { + "tag": "File", + "path": "stack.yaml", + "isHaskellModule": false, + "name": "stack.yaml" + }, + { + "tag": "Dir", + "contents": [ + { + "tag": "File", + "path": "src/Lib.hs", + "isHaskellModule": true, + "name": "Lib.hs" + }, + { + "tag": "File", + "path": "src/Types.hs", + "isHaskellModule": true, + "name": "Types.hs" + } + ], + "name": "src" + }, + { + "tag": "Dir", + "contents": [ + { + "tag": "File", + "path": "app/Main.hs", + "isHaskellModule": true, + "name": "Main.hs" + } + ], + "name": "app" + }, + { + "tag": "Dir", + "contents": [ + { + "tag": "File", + "path": "test/Spec.hs", + "isHaskellModule": true, + "name": "Spec.hs" + } + ], + "name": "test" + }, + { + "tag": "File", + "path": "package.yaml", + "isHaskellModule": false, + "name": "package.yaml" + }, + { + "tag": "File", + "path": "test-package.cabal", + "isHaskellModule": false, + "name": "test-package.cabal" + } + ], + "name": "test-package" + }, + "modules": { + "app/Main.hs": [], + "src/Types.hs": [], + "test/Spec.hs": [], + "src/Lib.hs": [] + }, + "id": "test-package-0.1.0.0" +}; + +const testModuleInfo = { + "occurrences": { + "3-8-11": { + "sort": { + "tag": "ModuleId", + "contents": { + "packageId": { + "name": "test-package", + "version": "0.1.0.0" + }, + "tag": "ApproximateLocation", + "moduleName": "Lib", + "name": "Lib", + "componentId": "exe-test-package-exe", + "entity": "Mod" + } + }, + "description": "ImportDecl" + }, + "6-8-16": { + "internalId": "4", + "sort": { + "tag": "ValueId" + }, + "description": "HsVar" + }, + "5-1-5": { + "internalId": "0", + "sort": { + "tag": "ValueId" + }, + "description": "TypeSig" + }, + "5-9-11": { + "internalId": "2", + "sort": { + "tag": "TypeId" + }, + "description": "HsTyVar" + }, + "6-1-5": { + "isBinder": true, + "internalId": "0", + "sort": { + "tag": "ValueId" + }, + "description": "Match" + }, + "5-12-14": { + "internalId": "3", + "sort": { + "tag": "TypeId" + }, + "description": "HsTupleTy" + } + }, + "identifiers": { + "7": { + "isExported": false, + "idType": { + "components": [ + { + "tag": "TyCon", + "name": "RuntimeRep", + "internalId": "6" + } + ] + }, + "locationInfo": { + "packageId": { + "name": "ghc-prim", + "version": "0.5.1.1" + }, + "tag": "ApproximateLocation", + "haddockAnchorId": "LiftedRep", + "moduleName": "GHC.Types", + "name": "LiftedRep", + "componentId": "lib", + "entity": "Val" + }, + "nameSpace": "DataName", + "internalId": "7", + "sort": "External", + "occName": "LiftedRep", + "externalId": "ghc-prim-0.5.1.1|GHC.Types|Val|LiftedRep", + "demangledOccName": "LiftedRep" + }, + "0": { + "isExported": true, + "idType": { + "components": [ + { + "tag": "TyCon", + "name": "IO", + "internalId": "2" + }, + { + "tag": "Text", + "contents": " ()" + } + ] + }, + "locationInfo": { + "packageId": { + "name": "test-package", + "version": "0.1.0.0" + }, + "tag": "ExactLocation", + "moduleName": "Main", + "startLine": 6, + "endLine": 6, + "modulePath": "app/Main.hs", + "startColumn": 1, + "endColumn": 5 + }, + "nameSpace": "VarName", + "internalId": "0", + "details": "VanillaId", + "sort": "External", + "occName": "main", + "externalId": "test-package-0.1.0.0|Main|Val|main", + "demangledOccName": "main" + }, + "4": { + "isExported": false, + "idType": { + "components": [ + { + "tag": "TyCon", + "name": "IO", + "internalId": "2" + }, + { + "tag": "Text", + "contents": " ()" + } + ] + }, + "doc": "

someFunc documentation

", + "locationInfo": { + "packageId": { + "name": "test-package", + "version": "0.1.0.0" + }, + "tag": "ExactLocation", + "moduleName": "Lib", + "startLine": 9, + "endLine": 9, + "modulePath": "src/Lib.hs", + "startColumn": 1, + "endColumn": 9 + }, + "nameSpace": "VarName", + "internalId": "4", + "details": "VanillaId", + "sort": "External", + "occName": "someFunc", + "externalId": "test-package-0.1.0.0|Lib|Val|someFunc", + "demangledOccName": "someFunc" + }, + "2": { + "isExported": false, + "idType": { + "components": [ + { + "tag": "Text", + "contents": "* -> *" + } + ] + }, + "locationInfo": { + "packageId": { + "name": "ghc-prim", + "version": "0.5.1.1" + }, + "tag": "ApproximateLocation", + "haddockAnchorId": "IO", + "moduleName": "GHC.Types", + "name": "IO", + "componentId": "lib", + "entity": "Typ" + }, + "nameSpace": "TcClsName", + "internalId": "2", + "sort": "External", + "occName": "IO", + "externalId": "ghc-prim-0.5.1.1|GHC.Types|Typ|IO", + "demangledOccName": "IO" + }, + "5": { + "isExported": false, + "idType": { + "components": [ + { + "tag": "TyCon", + "name": "RuntimeRep", + "internalId": "6" + }, + { + "tag": "Text", + "contents": " -> *" + } + ] + }, + "locationInfo": { + "packageId": { + "name": "ghc-prim", + "version": "0.5.1.1" + }, + "tag": "ApproximateLocation", + "haddockAnchorId": "TYPE", + "moduleName": "GHC.Prim", + "name": "TYPE", + "componentId": "lib", + "entity": "Typ" + }, + "nameSpace": "TcClsName", + "internalId": "5", + "sort": "External", + "occName": "TYPE", + "externalId": "ghc-prim-0.5.1.1|GHC.Prim|Typ|TYPE", + "demangledOccName": "TYPE" + }, + "3": { + "isExported": false, + "idType": { + "components": [ + { + "tag": "Text", + "contents": "*" + } + ] + }, + "locationInfo": { + "packageId": { + "name": "ghc-prim", + "version": "0.5.1.1" + }, + "tag": "ApproximateLocation", + "haddockAnchorId": "-40--41-", + "moduleName": "GHC.Tuple", + "name": "()", + "componentId": "lib", + "entity": "Typ" + }, + "nameSpace": "TcClsName", + "internalId": "3", + "sort": "External", + "occName": "()", + "externalId": "ghc-prim-0.5.1.1|GHC.Tuple|Typ|()", + "demangledOccName": "()" + } + }, + "name": "Main", + "sourceCodeHtml": "
1module Main where
2
3import Lib
4
5main :: IO ()
6main = someFunc
7
8
", + "id": "app/Main.hs", + "declarations": [ + { + "isExported": true, + "lineNumber": 6, + "declType": { + "components": [ + { + "tag": "TyCon", + "name": "IO", + "internalId": "2" + }, + { + "tag": "Text", + "contents": " ()" + } + ] + }, + "name": "main", + "sort": "ValD" + } + ] +}; + +module.exports = function(app) { + const express = require('express'); + let packagesRouter = express.Router(); + + packagesRouter.get('/api/packages', function(req, res) { + res.send(packages); + }); + + packagesRouter.get('/files/test-package-0.1.0.0/.haskell-code-explorer/packageInfo.json', function(req, res) { + res.send(testPackage); + }); + + packagesRouter.get('/files/test-package-0.1.0.0/.haskell-code-explorer/app%252FMain.hs.json', function(req, res) { + res.send(testModuleInfo); + }); + + app.use('/', packagesRouter); +}; -- cgit v1.2.3