More cleaning, deps in routes.json, module autodetection
This commit is contained in:
parent
8fc8292e72
commit
af5ab770ec
|
@ -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 \
|
||||
./
|
||||
|
|
|
@ -3,7 +3,6 @@ import './crud';
|
|||
import './acl-service';
|
||||
import './storage-services';
|
||||
import './template';
|
||||
import './spliting-register';
|
||||
import './interpolate';
|
||||
import './copy';
|
||||
import './equals';
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()', () => {
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
class SplitingRegister {
|
||||
constructor() {
|
||||
this.graph = null;
|
||||
this.modules = {};
|
||||
}
|
||||
getDependencies(moduleName) {
|
||||
return this.graph[moduleName];
|
||||
}
|
||||
}
|
||||
|
||||
export default new SplitingRegister();
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
export default function moduleImport(moduleName) {
|
||||
return import(
|
||||
/* webpackInclude: /modules\/[a-z0-9-]+\/front\/index.js$/ */
|
||||
`../modules/${moduleName}/front/index.js`
|
||||
);
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
import ngModule from './module';
|
||||
import deps from '../../modules.yml';
|
||||
import modules from 'spliting';
|
||||
import splitingRegister from 'core/lib/spliting-register';
|
||||
import getMainRoute from 'core/lib/get-main-route';
|
||||
|
||||
function loader(moduleName, validations) {
|
||||
|
@ -14,9 +11,6 @@ function loader(moduleName, validations) {
|
|||
|
||||
config.$inject = ['$stateProvider', '$urlRouterProvider'];
|
||||
function config($stateProvider, $urlRouterProvider) {
|
||||
splitingRegister.graph = deps;
|
||||
splitingRegister.modules = modules;
|
||||
|
||||
$urlRouterProvider.otherwise('/');
|
||||
|
||||
$stateProvider.state('home', {
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
export default {
|
||||
client:
|
||||
cb => require.ensure([], () => cb(require('client/front'))),
|
||||
route:
|
||||
cb => require.ensure([], () => cb(require('route/front'))),
|
||||
item:
|
||||
cb => require.ensure([], () => cb(require('item/front'))),
|
||||
ticket:
|
||||
cb => require.ensure([], () => cb(require('ticket/front'))),
|
||||
order:
|
||||
cb => require.ensure([], () => cb(require('order/front'))),
|
||||
claim:
|
||||
cb => require.ensure([], () => cb(require('claim/front'))),
|
||||
agency:
|
||||
cb => require.ensure([], () => cb(require('agency/front'))),
|
||||
travel:
|
||||
cb => require.ensure([], () => cb(require('travel/front')))
|
||||
};
|
17
gulpfile.js
17
gulpfile.js
|
@ -15,15 +15,15 @@ if (argv.NODE_ENV)
|
|||
let langs = ['es', 'en'];
|
||||
let srcDir = './front';
|
||||
let modulesDir = './modules';
|
||||
let modules = require('./modules.yml');
|
||||
let buildDir = 'dist';
|
||||
|
||||
|
||||
// Development
|
||||
|
||||
const localesRoutes = gulp.parallel(locales, routes);
|
||||
localesRoutes.description = `Builds locales and routes`;
|
||||
|
||||
const front = gulp.series(buildClean, gulp.parallel(localesRoutes, watch, webpackDevServer));
|
||||
const front = gulp.series(clean, gulp.parallel(localesRoutes, watch, webpackDevServer));
|
||||
front.description = `Starts frontend service`;
|
||||
|
||||
const back = gulp.series(dockerStart, backOnly);
|
||||
|
@ -110,9 +110,6 @@ smokesOnly.description = `Runs the smokes tests only`;
|
|||
smokes = gulp.series(docker, smokesOnly);
|
||||
smokes.description = `Restarts database and runs the smokes tests`;
|
||||
|
||||
const clean = gulp.parallel(buildClean);
|
||||
clean.description = 'Cleans all generated project files';
|
||||
|
||||
function install() {
|
||||
const install = require('gulp-install');
|
||||
const print = require('gulp-print');
|
||||
|
@ -136,14 +133,14 @@ i.description = `Alias for the 'install' task`;
|
|||
const build = gulp.series(clean, gulp.parallel(localesRoutes, webpack));
|
||||
build.description = `Generates binaries and configuration files`;
|
||||
|
||||
function buildClean() {
|
||||
function clean() {
|
||||
const del = require('del');
|
||||
const files = [
|
||||
`${buildDir}/*`
|
||||
];
|
||||
return del(files, {force: true});
|
||||
}
|
||||
buildClean.description = `Cleans all files generated by the 'build' task`;
|
||||
clean.description = `Cleans all files generated by the 'build' task`;
|
||||
|
||||
// Webpack
|
||||
|
||||
|
@ -216,7 +213,8 @@ function locales() {
|
|||
let streams = [];
|
||||
let localePaths = [];
|
||||
|
||||
for (let mod in modules)
|
||||
let modules = fs.readdirSync(modulesDir);
|
||||
for (let mod of modules)
|
||||
localePaths[mod] = `${modulesDir}/${mod}`;
|
||||
|
||||
let baseMods = ['core', 'salix'];
|
||||
|
@ -394,11 +392,10 @@ module.exports = {
|
|||
e2e,
|
||||
smokesOnly,
|
||||
smokes,
|
||||
clean,
|
||||
install,
|
||||
i,
|
||||
build,
|
||||
buildClean,
|
||||
clean,
|
||||
webpack,
|
||||
webpackDevServer,
|
||||
locales,
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
"initial:before": {},
|
||||
"initial": {
|
||||
"compression": {},
|
||||
"cors": {
|
||||
"params": {
|
||||
"origin": "*",
|
||||
"credentials": true,
|
||||
"maxAge": 86400
|
||||
}
|
||||
},
|
||||
"helmet#xssFilter": {},
|
||||
"helmet#frameguard": {
|
||||
"params": [
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
let cors = require('cors');
|
||||
|
||||
module.exports = function() {
|
||||
return cors({origin: true});
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
require('require-yaml');
|
||||
const cookieParser = require('cookie-parser');
|
||||
const loopback = require('loopback');
|
||||
const boot = require('loopback-boot');
|
||||
const DataSource = require('loopback-datasource-juggler').DataSource;
|
||||
|
@ -32,9 +31,6 @@ let lbDir = path.resolve(`${rootDir}/..`);
|
|||
let appDir = path.resolve(`${__dirname}/../..`);
|
||||
let localeDir = `${lbDir}/locale`;
|
||||
let modulesDir = `${appDir}/modules`;
|
||||
let modulesPath = `${appDir}/modules.yml`;
|
||||
|
||||
app.use(cookieParser());
|
||||
|
||||
// Internationalization
|
||||
|
||||
|
@ -92,8 +88,8 @@ let bootDirs = [
|
|||
|
||||
addPath(`${appDir}/back`);
|
||||
|
||||
let modules = require(modulesPath);
|
||||
for (let mod in modules)
|
||||
let modules = fs.readdirSync(modulesDir);
|
||||
for (let mod of modules)
|
||||
addPath(`${modulesDir}/${mod}/back`);
|
||||
|
||||
function addPath(path) {
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
client: []
|
||||
item: [client]
|
||||
ticket: [item, client]
|
||||
order: [item, ticket]
|
||||
claim: [item, client]
|
||||
route: []
|
||||
agency: []
|
||||
travel: []
|
|
@ -3,6 +3,7 @@
|
|||
"name": "Claims",
|
||||
"icon": "icon-claims",
|
||||
"validations": true,
|
||||
"dependencies": ["item", "client"],
|
||||
"routes": [
|
||||
{
|
||||
"url": "/claim",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"name": "Items",
|
||||
"icon": "inbox",
|
||||
"validations" : true,
|
||||
"dependencies": ["client"],
|
||||
"routes": [
|
||||
{
|
||||
"url": "/item",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"name": "Orders",
|
||||
"icon": "shopping_cart",
|
||||
"validations": true,
|
||||
"dependencies": ["item", "ticket"],
|
||||
"routes": [
|
||||
{
|
||||
"url": "/order",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"name": "Tickets",
|
||||
"icon": "icon-ticket",
|
||||
"validations": true,
|
||||
"dependencies": ["item", "client"],
|
||||
"routes": [
|
||||
{
|
||||
"url": "/ticket",
|
||||
|
|
|
@ -384,6 +384,15 @@
|
|||
"@babel/helper-plugin-utils": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"@babel/plugin-syntax-dynamic-import": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.2.0.tgz",
|
||||
"integrity": "sha512-mVxuJ0YroI/h/tbFTPGZR8cv6ai+STMKNBq0f8hFxsxWjl94qqhsb+wXbpNMDPU3cfR1TIsVFzU3nXyZMqyK4w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/helper-plugin-utils": "^7.0.0"
|
||||
}
|
||||
},
|
||||
"@babel/plugin-syntax-json-strings": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz",
|
||||
|
@ -3200,15 +3209,6 @@
|
|||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
|
||||
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
|
||||
},
|
||||
"cookie-parser": {
|
||||
"version": "1.4.3",
|
||||
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.3.tgz",
|
||||
"integrity": "sha1-D+MfoZ0AC5X0qt8fU/3CuKIDuqU=",
|
||||
"requires": {
|
||||
"cookie": "0.3.1",
|
||||
"cookie-signature": "1.0.6"
|
||||
}
|
||||
},
|
||||
"cookie-signature": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||
|
@ -3254,15 +3254,6 @@
|
|||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
|
||||
},
|
||||
"cors": {
|
||||
"version": "2.8.5",
|
||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||
"requires": {
|
||||
"object-assign": "^4",
|
||||
"vary": "^1"
|
||||
}
|
||||
},
|
||||
"create-ecdh": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.3.tgz",
|
||||
|
@ -7072,35 +7063,6 @@
|
|||
"requires-port": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"http-proxy-middleware": {
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-0.19.1.tgz",
|
||||
"integrity": "sha512-yHYTgWMQO8VvwNS22eLLloAkvungsKdKTLO8AJlftYIKNfJr3GK3zK0ZCfzDDGUBttdGc8xFy1mCitvNKQtC3Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"http-proxy": "^1.17.0",
|
||||
"is-glob": "^4.0.0",
|
||||
"lodash": "^4.17.11",
|
||||
"micromatch": "^3.1.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-glob": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.0.tgz",
|
||||
"integrity": "sha1-lSHHaEXMJhCoUgPd8ICpWML/q8A=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-extglob": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.11",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"http-signature": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
|
||||
|
@ -8993,6 +8955,11 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"swagger-ui": {
|
||||
"version": "2.2.10",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui/-/swagger-ui-2.2.10.tgz",
|
||||
"integrity": "sha1-sl56IWZOXZC/OR2zDbCN5B6FLXs="
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -11187,7 +11154,8 @@
|
|||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
|
||||
"dev": true
|
||||
},
|
||||
"object-component": {
|
||||
"version": "0.0.3",
|
||||
|
@ -14909,11 +14877,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"swagger-ui": {
|
||||
"version": "2.2.10",
|
||||
"resolved": "http://registry.npmjs.org/swagger-ui/-/swagger-ui-2.2.10.tgz",
|
||||
"integrity": "sha1-sl56IWZOXZC/OR2zDbCN5B6FLXs="
|
||||
},
|
||||
"table": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/table/-/table-5.1.1.tgz",
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"compression": "^1.7.3",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"cors": "^2.8.5",
|
||||
"fs-extra": "^5.0.0",
|
||||
"helmet": "^3.15.0",
|
||||
"i18n": "^0.8.3",
|
||||
|
@ -28,6 +26,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.2.2",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
||||
"@babel/polyfill": "^7.2.5",
|
||||
"@babel/preset-env": "^7.2.0",
|
||||
"@babel/register": "^7.0.0",
|
||||
|
@ -52,7 +51,6 @@
|
|||
"gulp-yaml": "^1.0.1",
|
||||
"html-loader": "^0.4.5",
|
||||
"html-webpack-plugin": "^4.0.0-beta.5",
|
||||
"http-proxy-middleware": "^0.19.1",
|
||||
"jasmine": "^2.99.0",
|
||||
"jasmine-reporters": "^2.3.2",
|
||||
"jasmine-spec-reporter": "^4.2.1",
|
||||
|
|
|
@ -21,7 +21,8 @@ let baseConfig = {
|
|||
loader: 'babel-loader',
|
||||
exclude: /node_modules/,
|
||||
query: {
|
||||
presets: ['@babel/preset-env']
|
||||
presets: ['@babel/preset-env'],
|
||||
plugins: ['@babel/plugin-syntax-dynamic-import']
|
||||
}
|
||||
}, {
|
||||
test: /\.yml$/,
|
||||
|
|
Loading…
Reference in New Issue