From 8905d685f794bd3cb84cae6a59974561bb61c921 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 21 Oct 2016 08:38:58 +0200 Subject: [PATCH] Rutas y splitings generados automaticamente --- .gitignore | 1 + @salix/app/dependencies.js | 4 -- @salix/app/src/configroutes.js | 13 ++-- @salix/app/src/fake.js | 17 ----- @salix/app/src/spliting.js | 40 ----------- @salix/app/src/spliting/deps.json | 5 ++ @salix/app/src/spliting/import.tpl.js | 1 + @salix/app/src/spliting/require.tpl.js | 11 +++ @salix/buys/index.js | 2 + .../src/compras.js => buys/src/buys.js} | 0 @salix/compras/index.js | 2 - @salix/compras/src/spliting.js | 12 ---- @salix/crud/src/crud.js | 6 +- @salix/crud/src/spliting.js | 0 @salix/pagos/index.js | 6 -- @salix/ventas/index.js | 4 -- gulpfile.js | 68 ++++++++++++++++--- index.html | 4 ++ package.json | 1 + 19 files changed, 93 insertions(+), 104 deletions(-) delete mode 100644 @salix/app/dependencies.js delete mode 100644 @salix/app/src/fake.js delete mode 100644 @salix/app/src/spliting.js create mode 100644 @salix/app/src/spliting/deps.json create mode 100644 @salix/app/src/spliting/import.tpl.js create mode 100644 @salix/app/src/spliting/require.tpl.js create mode 100644 @salix/buys/index.js rename @salix/{compras/src/compras.js => buys/src/buys.js} (100%) delete mode 100644 @salix/compras/index.js delete mode 100644 @salix/compras/src/spliting.js delete mode 100644 @salix/crud/src/spliting.js delete mode 100644 @salix/pagos/index.js delete mode 100644 @salix/ventas/index.js diff --git a/.gitignore b/.gitignore index dd87e2d73..b5f56d603 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules build +spliting.js diff --git a/@salix/app/dependencies.js b/@salix/app/dependencies.js deleted file mode 100644 index 65b9c87bf..000000000 --- a/@salix/app/dependencies.js +++ /dev/null @@ -1,4 +0,0 @@ -{ - compras: ["crud"], - crud: [] -} diff --git a/@salix/app/src/configroutes.js b/@salix/app/src/configroutes.js index 326f77c7a..54ca22fb5 100644 --- a/@salix/app/src/configroutes.js +++ b/@salix/app/src/configroutes.js @@ -1,26 +1,24 @@ import * as core from '@salix/core'; import * as spliting from './spliting'; -import * as routes from './fake'; +import * as deps from './spliting/deps.json'; function loader(route) { - return function ($ocLazyLoad, $q) { return $q((resolve) => { core.splitingRegister.execute(route.module).then(function (dependencies) { var array = dependencies.map((item) => { return { name: item } }); resolve($ocLazyLoad.load(array)); }); - }); }; - } function config($stateProvider, $urlRouterProvider) { - core.splitingRegister.registerGraph(routes.graphRoutes.graphDependendies); + core.splitingRegister.registerGraph(deps); - - routes.graphRoutes.routes.forEach(function (route) { + for (var file in routes) + routes[file].forEach(function (route) { + console.debug (route); $stateProvider.state(route.state, { url: route.url, template: route.template, @@ -29,7 +27,6 @@ function config($stateProvider, $urlRouterProvider) { } }) }); - } core.module.config(config); diff --git a/@salix/app/src/fake.js b/@salix/app/src/fake.js deleted file mode 100644 index 06d01245e..000000000 --- a/@salix/app/src/fake.js +++ /dev/null @@ -1,17 +0,0 @@ -export const graphRoutes = { - routes: [ - { - url: '/index', - state: 'index', - template: '', - module: 'crud', - description: '', - image: '', - } - ], - - graphDependendies: { - compras: ["crud"], - crud: [] - } -}; \ No newline at end of file diff --git a/@salix/app/src/spliting.js b/@salix/app/src/spliting.js deleted file mode 100644 index 139d4dec5..000000000 --- a/@salix/app/src/spliting.js +++ /dev/null @@ -1,40 +0,0 @@ -import * as core from '@salix/core'; - -export const compras = () => { - return new Promise(resolve => { - require.ensure([], () => { - require('@salix/compras'); - resolve('compras'); - }, "salix.compras"); - }); -}; - -core.splitingRegister.register('compras', compras); - -export const ventas = () => { - require.ensure([], () => { - require('@salix/ventas') - }, "salix.ventas"); -}; - -core.splitingRegister.register('ventas', ventas); - -export const pagos = () => { - require.ensure([], () => { - require('@salix/pagos') - }, "salix.pagos"); -}; - -core.splitingRegister.register('pagos', pagos); - - -export const crud = () => { - return new Promise(resolve => { - require.ensure([], () => { - require('@salix/crud'); - resolve('crud'); - }, "salix.crud"); - }); -}; - -core.splitingRegister.register('crud', crud); \ No newline at end of file diff --git a/@salix/app/src/spliting/deps.json b/@salix/app/src/spliting/deps.json new file mode 100644 index 000000000..33c88e890 --- /dev/null +++ b/@salix/app/src/spliting/deps.json @@ -0,0 +1,5 @@ +{ + "app": ["buys", "crud"], + "buys": ["crud"], + "crud": [] +} diff --git a/@salix/app/src/spliting/import.tpl.js b/@salix/app/src/spliting/import.tpl.js new file mode 100644 index 000000000..9c17e355d --- /dev/null +++ b/@salix/app/src/spliting/import.tpl.js @@ -0,0 +1 @@ +import * as core from '@salix/core'; diff --git a/@salix/app/src/spliting/require.tpl.js b/@salix/app/src/spliting/require.tpl.js new file mode 100644 index 000000000..345fc1685 --- /dev/null +++ b/@salix/app/src/spliting/require.tpl.js @@ -0,0 +1,11 @@ + +export const $module = () => { + return new Promise(resolve => { + require.ensure([], () => { + require('@salix/$module'); + resolve('$module'); + }, "salix.$module"); + }); +}; + +core.splitingRegister.register('$module', $module); diff --git a/@salix/buys/index.js b/@salix/buys/index.js new file mode 100644 index 000000000..af578bfcd --- /dev/null +++ b/@salix/buys/index.js @@ -0,0 +1,2 @@ +export * from './src/buys'; + diff --git a/@salix/compras/src/compras.js b/@salix/buys/src/buys.js similarity index 100% rename from @salix/compras/src/compras.js rename to @salix/buys/src/buys.js diff --git a/@salix/compras/index.js b/@salix/compras/index.js deleted file mode 100644 index deb604b56..000000000 --- a/@salix/compras/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from './src/compras'; - diff --git a/@salix/compras/src/spliting.js b/@salix/compras/src/spliting.js deleted file mode 100644 index d55880521..000000000 --- a/@salix/compras/src/spliting.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as core from '@salix/core'; - -export const crud = () => { - return new Promise(resolve => { - require.ensure([], () => { - require('@salix/crud'); - resolve('crud'); - }, "salix.crud"); - }); -}; - -core.splitingRegister.register('crud', crud); \ No newline at end of file diff --git a/@salix/crud/src/crud.js b/@salix/crud/src/crud.js index 90229cbb4..b8e3ce4aa 100644 --- a/@salix/crud/src/crud.js +++ b/@salix/crud/src/crud.js @@ -1,8 +1,8 @@ export * from './module'; export {NAME as CUSTOMER_INDEX, - COMPONENT as CUSTOMER_INDEX_COMPONENT} from './customer/index'; + COMPONENT as CUSTOMER_INDEX_COMPONENT} from './customer/index'; export {NAME as CUSTOMER_ADD, - COMPONENT as CUSTOMER_ADD_COMPONENT} from './customer/index/add'; + COMPONENT as CUSTOMER_ADD_COMPONENT} from './customer/index/add'; export {NAME as CUSTOMER_LIST, - COMPONENT as CUSTOMER_LIST_COMPONENT} from './customer/index/list'; + COMPONENT as CUSTOMER_LIST_COMPONENT} from './customer/index/list'; diff --git a/@salix/crud/src/spliting.js b/@salix/crud/src/spliting.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/@salix/pagos/index.js b/@salix/pagos/index.js deleted file mode 100644 index 83329dc8a..000000000 --- a/@salix/pagos/index.js +++ /dev/null @@ -1,6 +0,0 @@ -import * as core from '@salix/core' -import * as vendors from '@salix/vendor' -import * as crud from '@salix/crud' -import * as ventas from '@salix/ventas' -import * as compras from '@salix/compras' -console.log('pagos') \ No newline at end of file diff --git a/@salix/ventas/index.js b/@salix/ventas/index.js deleted file mode 100644 index 3e815f50d..000000000 --- a/@salix/ventas/index.js +++ /dev/null @@ -1,4 +0,0 @@ -import * as core from '@salix/core' -import * as vendors from '@salix/vendor' -import * as crud from '@salix/crud' -console.log('ventas'); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 901302888..bcd4d2443 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,20 +1,72 @@ var gulp = require ('gulp'); +var wrap = require('gulp-wrap'); var concat = require ('gulp-concat'); -var insert = require ('gulp-insert'); var babel = require ('gulp-babel'); -var wrap = require("gulp-wrap"); +var fs = require ('fs'); -var template = '\n"<%=file.path%>": <%=contents%>'; +// Routes -gulp.task ('default', function () +var fileTpl = '\n"<%=file.path%>": <%=contents%>'; +var globalTpl = 'var routes = {<%=contents%>\n}'; + +gulp.task ('routes', function () { - var js = gulp.src ('./@salix/**/routes.js') - .pipe (wrap (template)) + return gulp.src ('./@salix/**/routes.js') + .pipe (wrap (fileTpl)) .pipe (concat ('salix.routes.js', {newLine: ','})) - .pipe (insert.prepend ('var routes = {')) - .pipe (insert.append ('\n};')) + .pipe (wrap (globalTpl)) .pipe (babel ({presets: ['es2015']})) .pipe (gulp.dest ('./build/private')); }); +// Spliting + +var baseDir = './@salix/app/src/spliting'; +var depsFile = baseDir +'/deps.json'; + +function splitingFunc () +{ + try { + var jsonDeps = fs.readFileSync (depsFile); + var modules = JSON.parse (jsonDeps); + } + catch (e) + { + console.error (e); + return; + } + + var importTpl = fs.readFileSync (baseDir +'/import.tpl.js', 'utf8'); + var requireTpl = fs.readFileSync (baseDir +'/require.tpl.js', 'utf8'); + + for (var modName in modules) + { + var deps = modules[modName]; + var splitFile = './@salix/'+ modName +'/src/spliting.js'; + + try { + fs.unlinkSync (splitFile); + } + catch (e) {} + + fs.appendFileSync (splitFile, importTpl); + + var i = deps.length; + while (i--) + fs.appendFileSync (splitFile, + requireTpl.replace (/\$module/g, deps[i])); + } +} + +gulp.task ('spliting', function () +{ + splitingFunc (); + //gulp.watch (depsFile, splitingFunc); +}); + +// Default + +gulp.task ('default', ['routes', 'spliting']); + + diff --git a/index.html b/index.html index e093cae62..0059fda9a 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,10 @@ edit delete +