From 54c91c3d9e5080259ef69bbfa95cdbcc81faa488 Mon Sep 17 00:00:00 2001 From: nelo Date: Fri, 7 Oct 2016 12:10:24 +0200 Subject: [PATCH 1/8] Arreglo merge --- @salix/app/src/routes.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/@salix/app/src/routes.js b/@salix/app/src/routes.js index fd5750bd7..2fc5204f1 100644 --- a/@salix/app/src/routes.js +++ b/@salix/app/src/routes.js @@ -1,14 +1,5 @@ import * as core from '@salix/core'; import * as spliting from './spliting'; -<<<<<<< HEAD - -function config($stateProvider, $urlRouterProvider) { - function loader($ocLazyLoad, $q) { - return $q(resolve => { - spliting.crud(() => { - resolve($ocLazyLoad.load({name: 'crud'})); -======= -import * as routes from './fake'; core.module.config(function ($stateProvider, $urlRouterProvider) { core.splitingRegister.registerGraph(routes.graphRoutes.graphDependendies); @@ -20,7 +11,7 @@ core.module.config(function ($stateProvider, $urlRouterProvider) { var array = dependencies.map((item) => { return { name: item } }); resolve($ocLazyLoad.load(array)); }); ->>>>>>> 0bfbc5e0642bb669d8568ea1ce1782fde1702aa6 + }); }); } From 301588e0ed7dce7f383b4eccaeae65544ca8597e Mon Sep 17 00:00:00 2001 From: nelo Date: Fri, 7 Oct 2016 12:51:31 +0200 Subject: [PATCH 2/8] Prueba concepto rutas --- @salix/app/src/fake.js | 26 +---------------------- @salix/app/src/routes.js | 34 +++++++++++++++++------------- @salix/app/src/spliting.js | 14 +++++++++++- @salix/crud/src/customer/routes.js | 8 +++++++ @salix/crud/src/spliting.js | 0 5 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 @salix/crud/src/customer/routes.js create mode 100644 @salix/crud/src/spliting.js diff --git a/@salix/app/src/fake.js b/@salix/app/src/fake.js index 39683e7cc..06d01245e 100644 --- a/@salix/app/src/fake.js +++ b/@salix/app/src/fake.js @@ -4,31 +4,7 @@ export const graphRoutes = { url: '/index', state: 'index', template: '', - module: 'compras', - description: '', - image: '', - }, - { - url: '/add', - state: 'add', - template: '', - module: 'compras', - description: '', - image: '', - }, - { - url: '/edit', - state: 'edit', - template: '', - module: 'compras', - description: '', - image: '', - }, - { - url: '/delete', - state: 'delete', - template: '', - module: 'compras', + module: 'crud', description: '', image: '', } diff --git a/@salix/app/src/routes.js b/@salix/app/src/routes.js index 2fc5204f1..326f77c7a 100644 --- a/@salix/app/src/routes.js +++ b/@salix/app/src/routes.js @@ -1,22 +1,24 @@ import * as core from '@salix/core'; import * as spliting from './spliting'; +import * as routes from './fake'; -core.module.config(function ($stateProvider, $urlRouterProvider) { +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); - function loader(route) { - return function loader($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)); - }); - - }); - }); - } - - $urlRouterProvider.otherwise("/"); routes.graphRoutes.routes.forEach(function (route) { $stateProvider.state(route.state, { @@ -27,5 +29,7 @@ core.module.config(function ($stateProvider, $urlRouterProvider) { } }) }); -}); +} + +core.module.config(config); diff --git a/@salix/app/src/spliting.js b/@salix/app/src/spliting.js index fb7680727..139d4dec5 100644 --- a/@salix/app/src/spliting.js +++ b/@salix/app/src/spliting.js @@ -25,4 +25,16 @@ export const pagos = () => { }, "salix.pagos"); }; -core.splitingRegister.register('pagos', pagos); \ No newline at end of file +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/crud/src/customer/routes.js b/@salix/crud/src/customer/routes.js new file mode 100644 index 000000000..d5158a39b --- /dev/null +++ b/@salix/crud/src/customer/routes.js @@ -0,0 +1,8 @@ +{ + url: '/index', + state: 'index', + template: '', + module: 'crud', + description: '', + image: '', +} diff --git a/@salix/crud/src/spliting.js b/@salix/crud/src/spliting.js new file mode 100644 index 000000000..e69de29bb From d9bfd1b579d138ad76170dd853be3542f9bf1748 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 10 Oct 2016 11:15:05 +0200 Subject: [PATCH 3/8] Concatenar rutas con Gulp --- @salix/crud/src/provider/routes.js | 8 ++++++++ gulpfile.js | 11 +++++++++-- package.json | 10 +++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 @salix/crud/src/provider/routes.js diff --git a/@salix/crud/src/provider/routes.js b/@salix/crud/src/provider/routes.js new file mode 100644 index 000000000..f585a8c74 --- /dev/null +++ b/@salix/crud/src/provider/routes.js @@ -0,0 +1,8 @@ +[{ + url: '/provider', + state: 'provider', + template: '', + module: 'crud', + description: '', + image: '', +}] diff --git a/gulpfile.js b/gulpfile.js index e17bbfd1e..d2286aca0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,12 +1,19 @@ var gulp = require ('gulp'); var concat = require ('gulp-concat'); +var insert = require ('gulp-insert'); var babel = require ('gulp-babel'); +var wrap = require("gulp-wrap"); + +var template = '"<%=file.path%>": <%=contents%>'; gulp.task ('default', function () { - var js = gulp.src ('./@salix/crud/**/routes.js') - .pipe (concat ('salix.routes.js')) + var js = gulp.src ('./@salix/**/routes.js') + .pipe (wrap (template)) + .pipe (concat ('salix.routes.js', {newLine: ','})) + .pipe (insert.prepend ('var routes = {')) + .pipe (insert.append ('};')) .pipe (babel ({presets: ['es2015']})) .pipe (gulp.dest ('./build/private')); }); diff --git a/package.json b/package.json index 499ebbcf8..88395183b 100644 --- a/package.json +++ b/package.json @@ -19,16 +19,18 @@ "babel-core": "*", "babel-loader": "*", "babel-preset-es2015": "*", + "cors": "^2.8.1", "css-loader": "^0.25.0", "eslint": "^3.7.1", "eslint-config-angular": "^0.5.0", "eslint-config-google": "^0.6.0", "eslint-plugin-angular": "^1.4.1", "gulp": "^3.9.1", - "pre-commit": "^1.1.3", - "cors": "^2.8.1", "gulp-babel": "^6.1.2", "gulp-concat": "^2.6.0", + "gulp-insert": "^0.5.0", + "gulp-wrap": "^0.13.0", + "pre-commit": "^1.1.3", "raw-loader": "*", "style-loader": "^0.13.1", "webpack": "*", @@ -41,5 +43,7 @@ "gulp": "gulp", "express": "node server.js" }, - "pre-commit": [ "lint" ] + "pre-commit": [ + "lint" + ] } From 9f7be0dbbe5e482ef8f3c18784f4f1f3def81a0f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 18 Oct 2016 10:36:16 +0200 Subject: [PATCH 4/8] Errores al generar rutas solucionados --- @salix/app/dependencies.js | 4 ++++ @salix/app/src/app.js | 2 +- @salix/app/src/{routes.js => configroutes.js} | 0 @salix/crud/src/customer/routes.js | 4 ++-- gulpfile.js | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 @salix/app/dependencies.js rename @salix/app/src/{routes.js => configroutes.js} (100%) diff --git a/@salix/app/dependencies.js b/@salix/app/dependencies.js new file mode 100644 index 000000000..65b9c87bf --- /dev/null +++ b/@salix/app/dependencies.js @@ -0,0 +1,4 @@ +{ + compras: ["crud"], + crud: [] +} diff --git a/@salix/app/src/app.js b/@salix/app/src/app.js index b3ac02fdd..833374e39 100644 --- a/@salix/app/src/app.js +++ b/@salix/app/src/app.js @@ -1,5 +1,5 @@ import {bootstrap} from './bootstrap'; import * as spliting from './spliting'; -import * as routes from './routes'; +import * as routes from './configroutes'; bootstrap(); diff --git a/@salix/app/src/routes.js b/@salix/app/src/configroutes.js similarity index 100% rename from @salix/app/src/routes.js rename to @salix/app/src/configroutes.js diff --git a/@salix/crud/src/customer/routes.js b/@salix/crud/src/customer/routes.js index d5158a39b..d68ceeac3 100644 --- a/@salix/crud/src/customer/routes.js +++ b/@salix/crud/src/customer/routes.js @@ -1,8 +1,8 @@ -{ +[{ url: '/index', state: 'index', template: '', module: 'crud', description: '', image: '', -} +}] diff --git a/gulpfile.js b/gulpfile.js index d2286aca0..901302888 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,7 @@ var insert = require ('gulp-insert'); var babel = require ('gulp-babel'); var wrap = require("gulp-wrap"); -var template = '"<%=file.path%>": <%=contents%>'; +var template = '\n"<%=file.path%>": <%=contents%>'; gulp.task ('default', function () { @@ -13,7 +13,7 @@ gulp.task ('default', function () .pipe (wrap (template)) .pipe (concat ('salix.routes.js', {newLine: ','})) .pipe (insert.prepend ('var routes = {')) - .pipe (insert.append ('};')) + .pipe (insert.append ('\n};')) .pipe (babel ({presets: ['es2015']})) .pipe (gulp.dest ('./build/private')); }); From 8905d685f794bd3cb84cae6a59974561bb61c921 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 21 Oct 2016 08:38:58 +0200 Subject: [PATCH 5/8] 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 + + + +