diff --git a/.dockerignore b/.dockerignore index 27ca60b47..aaa5f610a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ node_modules -front -services -!services/nginx \ No newline at end of file +front/node_modules +services \ No newline at end of file diff --git a/.gitignore b/.gitignore index 50d3f3f91..864883743 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ npm-debug.log .eslintcache datasources.*.json print.*.json -db.json \ No newline at end of file +db.json +junitresults.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 510faa06b..12708bcc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,10 +25,8 @@ RUN npm install --only=prod COPY loopback loopback COPY back back COPY modules modules -COPY dist/webpack-assets.json dist/ COPY print print COPY \ - modules.yml \ LICENSE \ README.md \ ./ diff --git a/Jenkinsfile b/Jenkinsfile index 72988ce92..7706e4a58 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,9 +45,6 @@ pipeline { } } stage('Build') { - environment { - CREDS = credentials('docker-registry') - } steps { nodejs('node-lts') { withEnv(['NODE_ENV=']) { @@ -56,6 +53,29 @@ pipeline { } sh 'gulp build' } + } + } + stage('Test') { + environment { + NODE_ENV = "" + FIREFOX_BIN = "/opt/firefox/firefox-bin" + } + steps { + nodejs('node-lts') { + sh 'karma start --junit' + + // FIXME: Docker isn't at localhost + // sh 'gulp docker' + // sh 'gulp backendUnitTest --junit' + // sh 'docker rm -f salix-db' + } + } + } + stage('Docker') { + environment { + CREDS = credentials('docker-registry') + } + steps { sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY' sh 'docker-compose build --parallel' sh 'docker-compose push' @@ -98,6 +118,7 @@ pipeline { } post { always { + junit '*/junit.xml' script { if (!env.GIT_COMMITTER_EMAIL) return try { diff --git a/back/tests.js b/back/tests.js index 8e21985c5..c715c96bf 100644 --- a/back/tests.js +++ b/back/tests.js @@ -17,13 +17,10 @@ let SpecReporter = require('jasmine-spec-reporter').SpecReporter; let serviceSpecs = [ `${__dirname}/**/*[sS]pec.js`, - `${__dirname}/../loopback/**/*[sS]pec.js` + `${__dirname}/../loopback/**/*[sS]pec.js`, + `${__dirname}/../modules/*/back/**/*.[sS]pec.js` ]; -let services = require(`../modules.yml`); -for (let service of services) - serviceSpecs.push(`${__dirname}/../modules/${service}/back/**/*[sS]pec.js`); - jasmine.loadConfig({ spec_dir: '.', spec_files: serviceSpecs, diff --git a/docker-compose.yml b/docker-compose.yml index cc66e2ab2..fa6259adb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: restart: unless-stopped build: context: . - dockerfile: services/nginx/Dockerfile + dockerfile: front/Dockerfile ports: - ${PORT}:80 links: diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index a55c2ae1b..b52889611 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -1,10 +1,10 @@ /* eslint no-invalid-this: "off" */ -import config from './config.js'; import Nightmare from 'nightmare'; import {URL} from 'url'; -let currentUser; +import config from './config.js'; +let currentUser; Nightmare.asyncAction = function(name, func) { Nightmare.action(name, function(...args) { @@ -25,17 +25,42 @@ Nightmare.asyncAction('clearInput', async function(selector) { let actions = { login: function(userName, done) { - this.goto(`${config.url}#!/login`) - .wait(`vn-login input[name=user]`) - .write(`vn-login input[name=user]`, userName) - .write(`vn-login input[name=password]`, 'nightmare') - .click(`vn-login input[type=submit]`) - // FIXME: Wait for dom to be ready: https://github.com/segmentio/nightmare/issues/481 - // .wait(1000) - .then(() => { - currentUser = userName; - done(); - }) + if (currentUser) + this.waitToClick('#logout'); + + let doLogin = () => { + this.wait(`vn-login input[name=user]`) + .write(`vn-login input[name=user]`, userName) + .write(`vn-login input[name=password]`, 'nightmare') + .click(`vn-login input[type=submit]`) + .then(() => { + currentUser = userName; + done(); + }) + .catch(done); + }; + + this.waitForURL('#!/login') + .then(doLogin) + .catch(() => { + this.goto(`${config.url}/#!/login`) + .then(doLogin) + .catch(done); + }); + }, + + waitForLogin: function(userName, done) { + if (currentUser === userName) { + return this.waitToClick('vn-topbar a[ui-sref="home"]') + .waitForURL('#!/') + .then(done) + .catch(done); + } + return this.login(userName) + .waitForURL('#!/') + .url() + .changeLanguageToEnglish() + .then(done) .catch(done); }, @@ -65,21 +90,6 @@ let actions = { }); }, - waitForLogin: function(userName, done) { - if (currentUser === userName) { - return this.waitToClick('vn-topbar a[ui-sref="home"]') - .waitForURL('#!/') - .then(done) - .catch(done); - } - return this.login(userName) - .waitForURL('#!/') - .url() - .changeLanguageToEnglish() - .then(done) - .catch(done); - }, - selectModule: function(moduleName, done) { this.waitToClick(`vn-home a[ui-sref="${moduleName}.index"]`) .waitForURL(moduleName) diff --git a/e2e/helpers/nightmare.js b/e2e/helpers/nightmare.js index b4d0cad41..53fac12df 100644 --- a/e2e/helpers/nightmare.js +++ b/e2e/helpers/nightmare.js @@ -1,5 +1,6 @@ /* eslint no-console: 0 */ import Nightmare from 'nightmare'; + let nightmare; export default function createNightmare(width = 1280, height = 720) { @@ -22,7 +23,6 @@ export default function createNightmare(width = 1280, height = 720) { }); nightmare.header('Accept-Language', 'en'); - return nightmare; } diff --git a/services/nginx/Dockerfile b/front/Dockerfile similarity index 88% rename from services/nginx/Dockerfile rename to front/Dockerfile index e34994382..d6fe5d4f8 100644 --- a/services/nginx/Dockerfile +++ b/front/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update \ && ln -sf /dev/stderr /var/log/nginx/error.log WORKDIR /etc/nginx -COPY services/nginx/temp/nginx.conf sites-available/salix +COPY front/nginx.conf sites-available/salix RUN rm sites-enabled/default && ln -s ../sites-available/salix sites-enabled/salix COPY dist /salix/dist diff --git a/front/core/lib/index.js b/front/core/lib/index.js index e7f610e57..3aab29228 100644 --- a/front/core/lib/index.js +++ b/front/core/lib/index.js @@ -3,7 +3,6 @@ import './crud'; import './acl-service'; import './storage-services'; import './template'; -import './spliting-register'; import './interpolate'; import './copy'; import './equals'; diff --git a/front/core/lib/module-loader.js b/front/core/lib/module-loader.js index 4ecc179b4..163d103bb 100644 --- a/front/core/lib/module-loader.js +++ b/front/core/lib/module-loader.js @@ -1,5 +1,5 @@ import ngModule from '../module'; -import splitingRegister from './spliting-register'; +import moduleImport from 'module-import'; factory.$inject = ['$http', '$window', '$ocLazyLoad', '$translatePartialLoader', '$translate', '$q']; export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $translate, $q) { @@ -8,6 +8,10 @@ export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $t this._loaded = {}; } load(moduleName, validations) { + let moduleConf = $window.routes.find(i => i && i.module == moduleName); + if (!moduleConf) + return $q.reject(new Error(`Module not found: ${moduleName}`)); + let loaded = this._loaded; if (loaded[moduleName] === true) @@ -19,8 +23,8 @@ export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $t loaded[moduleName] = false; - let deps = splitingRegister.getDependencies(moduleName); let depPromises = []; + let deps = moduleConf.dependencies; if (deps) { for (let dep of deps) @@ -48,9 +52,7 @@ export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $t })); } - promises.push(new Promise(resolve => { - splitingRegister.modules[moduleName](resolve); - })); + promises.push(moduleImport(moduleName)); Promise.all(promises).then(() => { loaded[moduleName] = true; diff --git a/front/core/lib/specs/module-loader.spec.js b/front/core/lib/specs/module-loader.spec.js index d63148d34..c8def1634 100644 --- a/front/core/lib/specs/module-loader.spec.js +++ b/front/core/lib/specs/module-loader.spec.js @@ -4,9 +4,10 @@ describe('factory vnModuleLoader', () => { beforeEach(ngModule('vnCore')); - beforeEach(angular.mock.inject((_vnModuleLoader_, $rootScope) => { + beforeEach(angular.mock.inject((_vnModuleLoader_, $rootScope, $window) => { vnModuleLoader = _vnModuleLoader_; $scope = $rootScope; + $window.routes = [{module: 'myModule'}]; })); describe('load()', () => { diff --git a/front/core/lib/spliting-register.js b/front/core/lib/spliting-register.js deleted file mode 100644 index d6af3de64..000000000 --- a/front/core/lib/spliting-register.js +++ /dev/null @@ -1,12 +0,0 @@ - -class SplitingRegister { - constructor() { - this.graph = null; - this.modules = {}; - } - getDependencies(moduleName) { - return this.graph[moduleName]; - } -} - -export default new SplitingRegister(); diff --git a/front/core/module.js b/front/core/module.js index d1c347cf8..d5fc76578 100644 --- a/front/core/module.js +++ b/front/core/module.js @@ -7,7 +7,7 @@ config.$inject = ['$translateProvider', '$translatePartialLoaderProvider']; export function config($translateProvider, $translatePartialLoaderProvider) { $translatePartialLoaderProvider.addPart('core'); - let conf = {urlTemplate: '/static/locale/{part}/{lang}.json'}; + let conf = {urlTemplate: '/locale/{part}/{lang}.json'}; let fallbackLang = 'es'; let langs = ['en', 'es']; diff --git a/front/module-import.js b/front/module-import.js new file mode 100755 index 000000000..8929b5fda --- /dev/null +++ b/front/module-import.js @@ -0,0 +1,7 @@ + +export default function moduleImport(moduleName) { + return import( + /* webpackInclude: /modules\/[a-z0-9-]+\/front\/index.js$/ */ + `../modules/${moduleName}/front/index.js` + ); +} \ No newline at end of file diff --git a/front/modules.yml b/front/modules.yml deleted file mode 100644 index abcd1eace..000000000 --- a/front/modules.yml +++ /dev/null @@ -1,11 +0,0 @@ -auth: [] -client: [] -core: [] -item: [client] -salix: [] -ticket: [item, client] -order: [item, ticket] -claim: [item, client] -route: [] -agency: [] -travel: [] diff --git a/services/nginx/nginx.mst b/front/nginx.conf similarity index 51% rename from services/nginx/nginx.mst rename to front/nginx.conf index 39d72115d..c8f6cea3a 100644 --- a/services/nginx/nginx.mst +++ b/front/nginx.conf @@ -7,19 +7,12 @@ server { root /usr/share/nginx/html; - {{#services}} - location ~ ^/{{.}}(?:/(.*))?$ { + location ~ ^(/[a-zA-Z0-9_-]+)?/(?api(/.*)?)$ { resolver 127.0.0.11; - proxy_pass http://api:{{defaultPort}}/$1$is_args$args; + proxy_pass http://api:3000/$path$is_args$args; } - {{/services}} - - location ~ ^/static(?:/(.*))?$ { + location ~ ^(?:/(.*))?$ { alias /salix/dist/$1; autoindex on; } - location ~ ^(?:/(.*))?$ { - resolver 127.0.0.11; - proxy_pass http://api:{{defaultPort}}/$1$is_args$args; - } } diff --git a/front/salix/components/left-menu/left-menu.html b/front/salix/components/left-menu/left-menu.html index be5b7cd68..31dcb7903 100644 --- a/front/salix/components/left-menu/left-menu.html +++ b/front/salix/components/left-menu/left-menu.html @@ -1,6 +1,7 @@