From 5a4a41d630b9956f24891264f436dd7dd50eac72 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 7 Oct 2016 11:44:24 +0200 Subject: [PATCH 1/2] Concat de rutas JS con Gulp, servidor express sirve routes.js --- @salix/app/index.js | 2 +- @salix/compras/index.js | 2 +- gulpfile.js | 15 ++++++--------- index.html | 7 +++---- npm-debug.log | 27 --------------------------- package.json | 26 +++++++++++++++----------- server.js | 13 +++++-------- webpack.config.js | 7 ++++--- 8 files changed, 35 insertions(+), 64 deletions(-) delete mode 100644 npm-debug.log diff --git a/@salix/app/index.js b/@salix/app/index.js index 4d375b31f6..cb9a3f1789 100644 --- a/@salix/app/index.js +++ b/@salix/app/index.js @@ -1 +1 @@ -export * from './src/app' \ No newline at end of file +export * from './src/app' diff --git a/@salix/compras/index.js b/@salix/compras/index.js index 8f9f546294..133f88ede6 100644 --- a/@salix/compras/index.js +++ b/@salix/compras/index.js @@ -1,4 +1,4 @@ import * as core from '@salix/core' import * as vendors from '@salix/vendor' import * as crud from '@salix/crud' -console.log('compras'); \ No newline at end of file +console.log('compras'); diff --git a/gulpfile.js b/gulpfile.js index eecadce9c5..e17bbfd1e0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,16 +1,13 @@ var gulp = require ('gulp'); -var jsoncombine = require ('gulp-jsoncombine'); - -function combineFunc (data) -{ - return new Buffer (JSON.stringify (data)); -} +var concat = require ('gulp-concat'); +var babel = require ('gulp-babel'); gulp.task ('default', function () { - var json = gulp.src ('./@salix/**/routes.json') - .pipe (jsoncombine ('salix.routes.json', combineFunc)) - .pipe (gulp.dest ('./build')); + var js = gulp.src ('./@salix/crud/**/routes.js') + .pipe (concat ('salix.routes.js')) + .pipe (babel ({presets: ['es2015']})) + .pipe (gulp.dest ('./build/private')); }); diff --git a/index.html b/index.html index e9699e82c3..e093cae628 100644 --- a/index.html +++ b/index.html @@ -13,9 +13,8 @@ + src="build/public/salix.app.js" + selector="#app"> + diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 9d648ec6bc..0000000000 --- a/npm-debug.log +++ /dev/null @@ -1,27 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/usr/local/Cellar/node/6.3.1/bin/node', -1 verbose cli '/usr/local/bin/npm', -1 verbose cli 'run', -1 verbose cli 'dev' ] -2 info using npm@3.10.3 -3 info using node@v6.3.1 -4 verbose stack Error: missing script: dev -4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19) -4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5 -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5 -4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45) -4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3) -4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5) -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:311:12 -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 -4 verbose stack at tryToString (fs.js:455:3) -4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12) -5 verbose cwd /Users/nelo/Documents/node/salix -6 error Darwin 16.0.0 -7 error argv "/usr/local/Cellar/node/6.3.1/bin/node" "/usr/local/bin/npm" "run" "dev" -8 error node v6.3.1 -9 error npm v3.10.3 -10 error missing script: dev -11 error If you need help, you may report this error at: -11 error -12 verbose exit [ 1, true ] diff --git a/package.json b/package.json index 8cc3727e6b..d1fb870451 100644 --- a/package.json +++ b/package.json @@ -11,24 +11,28 @@ "dependencies": { "angular": "^1.5.8", "angular-ui-router": "^1.0.0-beta.3", - "cors": "^2.8.1", "express": "^4.14.0", "material-design-lite": "^1.2.1", "oclazyload": "^0.6.3" }, "devDependencies": { - "gulp": "^3.9.1", - "gulp-jsoncombine": "^1.0.3", - "webpack": "*", - "webpack-dev-server": "*", - "raw-loader": "*", - "css-loader": "^0.25.0", - "style-loader": "^0.13.1", - "babel-loader": "*", "babel-core": "*", - "babel-preset-es2015": "*" + "babel-loader": "*", + "babel-preset-es2015": "*", + "cors": "^2.8.1", + "css-loader": "^0.25.0", + "gulp": "^3.9.1", + "gulp-babel": "^6.1.2", + "gulp-concat": "^2.6.0", + "raw-loader": "*", + "style-loader": "^0.13.1", + "webpack": "*", + "webpack-dev-server": "*" }, "scripts": { - "build": "webpack --progress --colors --watch" + "build": "webpack --progress --colors --watch", + "dev": "webpack-dev-server --progress --colors --inline --hot", + "gulp": "gulp", + "express": "node server.js" } } diff --git a/server.js b/server.js index e5a13d32ca..04801bb911 100644 --- a/server.js +++ b/server.js @@ -2,11 +2,8 @@ var express = require ('express'); var cors = require ('cors'); -function getRoutes (req, res) -{ - var routes = require ('./build/salix.routes.json'); - res.send (JSON.stringify (routes)); -} +var port = 3000; +var routesUrl = '/private/salix.routes.js'; function getDefault (res, res) { @@ -15,11 +12,11 @@ function getDefault (res, res) function onListen () { - console.log ('HTTP server started.'); + console.log ('HTTP server started on port '+ port); } var app = express (); -app.get ('/routes', cors (), getRoutes); +app.use ('/private', cors (), express.static (__dirname +'/build/private')); app.all (/.*/, cors (), getDefault); -app.listen (8080, onListen); +app.listen (port, onListen); diff --git a/webpack.config.js b/webpack.config.js index 6ff905c056..f6de35fb7a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -8,9 +8,9 @@ module.exports = 'salix.app': ['@salix/app'] }, output: { - path: path.join(__dirname, 'build'), + path: path.join(__dirname, 'build', 'public'), filename: '[name].js', - publicPath: 'build/', + publicPath: 'build/public/', chunkFilename: "[name].js" }, module: { @@ -39,5 +39,6 @@ module.exports = __dirname, 'node_modules' ] - } + }, + devtool: 'cheap-module-eval-source-map' // 'source-map' }; From 8c88988ebf3e8718c449faf2e864752a97e0fdac Mon Sep 17 00:00:00 2001 From: nelo Date: Fri, 7 Oct 2016 11:45:37 +0200 Subject: [PATCH 2/2] =?UTF-8?q?calculo=20de=20modelos=20dependientes=20de?= =?UTF-8?q?=20manera=20as=C3=ADncrona?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @salix/app/src/fake.js | 4 +- @salix/app/src/routes.js | 35 +++++++-------- @salix/app/src/spliting.js | 21 ++++++--- @salix/compras/index.js | 5 +-- @salix/compras/src/compras.js | 1 + @salix/compras/src/spliting.js | 12 +++++ @salix/core/src/splitingregister.js | 59 ++++++++++++++++++------- @salix/crud/src/crud.js | 2 - @salix/crud/src/customer/index/index.js | 2 +- @salix/crud/src/customer/routes.js | 31 ------------- @salix/crud/src/spliting.js | 8 ---- npm-debug.log | 27 ----------- 12 files changed, 91 insertions(+), 116 deletions(-) create mode 100644 @salix/compras/src/compras.js create mode 100644 @salix/compras/src/spliting.js delete mode 100644 @salix/crud/src/customer/routes.js delete mode 100644 @salix/crud/src/spliting.js delete mode 100644 npm-debug.log diff --git a/@salix/app/src/fake.js b/@salix/app/src/fake.js index df7f4a45f0..39683e7cc3 100644 --- a/@salix/app/src/fake.js +++ b/@salix/app/src/fake.js @@ -35,7 +35,7 @@ export const graphRoutes = { ], graphDependendies: { - compras:["crud"], - crud:[] + compras: ["crud"], + crud: [] } }; \ No newline at end of file diff --git a/@salix/app/src/routes.js b/@salix/app/src/routes.js index d0f3817f3e..2e174fa180 100644 --- a/@salix/app/src/routes.js +++ b/@salix/app/src/routes.js @@ -1,34 +1,33 @@ import * as core from '@salix/core'; import * as spliting from './spliting'; -import {routes} from './fake'; +import * as routes from './fake'; -core.module.config(function($stateProvider, $urlRouterProvider) { - - core.splitingRegister.registerGraph('hello'); +core.module.config(function ($stateProvider, $urlRouterProvider) { - function xxx(route){ - return function loader($ocLazyLoad, $q){ + core.splitingRegister.registerGraph(routes.graphRoutes.graphDependendies); + + function loader(route) { + return function loader($ocLazyLoad, $q) { return $q((resolve) => { - core.splitingRegister.execute(route.module) - spliting[route.module](() => { - //resolve($ocLazyLoad.load({name: route.module})); - - }); + core.splitingRegister.execute(route.module).then(function(dependencies){ + var array = dependencies.map((item) => { return { name: item } }); + resolve($ocLazyLoad.load(array)); + }); }); }; } - + $urlRouterProvider.otherwise("/"); - - routes.forEach(function(route) { + + routes.graphRoutes.routes.forEach(function (route) { $stateProvider.state(route.state, { url: route.url, - template :route.template, + template: route.template, resolve: { - loader: xxx(route) + loader: loader(route) } - }) - }, this); + }) + }, this); }); diff --git a/@salix/app/src/spliting.js b/@salix/app/src/spliting.js index f60b2d5c36..a522bb428d 100644 --- a/@salix/app/src/spliting.js +++ b/@salix/app/src/spliting.js @@ -1,21 +1,28 @@ import * as core from '@salix/core'; - - -export const compras = (cb) => { - require.ensure([], () => { - require('@salix/compras') - cb(); - }, "salix.compras"); +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); diff --git a/@salix/compras/index.js b/@salix/compras/index.js index 8f9f546294..283db8c3bc 100644 --- a/@salix/compras/index.js +++ b/@salix/compras/index.js @@ -1,4 +1 @@ -import * as core from '@salix/core' -import * as vendors from '@salix/vendor' -import * as crud from '@salix/crud' -console.log('compras'); \ No newline at end of file +export * from './src/compras'; \ No newline at end of file diff --git a/@salix/compras/src/compras.js b/@salix/compras/src/compras.js new file mode 100644 index 0000000000..a0e102befc --- /dev/null +++ b/@salix/compras/src/compras.js @@ -0,0 +1 @@ +export * from './spliting'; \ No newline at end of file diff --git a/@salix/compras/src/spliting.js b/@salix/compras/src/spliting.js new file mode 100644 index 0000000000..d55880521d --- /dev/null +++ b/@salix/compras/src/spliting.js @@ -0,0 +1,12 @@ +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/core/src/splitingregister.js b/@salix/core/src/splitingregister.js index e60c5c7e14..725efab452 100644 --- a/@salix/core/src/splitingregister.js +++ b/@salix/core/src/splitingregister.js @@ -1,32 +1,59 @@ -const _SplitingRegister = ()=>{ +const _SplitingRegister = () => { var _graph; var dependencies = {}; + function getDependencies(dependency) { + var array = []; + array.push(dependency); + var first = _graph[dependency]; + + while (first && first.length > 0) { + dependency = first.shift(); + array = array.concat(getDependencies(dependency)); + } + return array; + } + return { - registerGraph: function(graph){ + registerGraph: function (graph) { _graph = graph; }, - register: function(dependency,loader){ - dependencies[dependecy]=loader; + register: function (dependency, loader) { + dependencies[dependency] = loader; }, - execute: function(dependency){ - - var _array=[]; - _array.push(dependency); - var fist =graph[dependency]; + execute: function (dependency) { + return new Promise(resolve => { - //TODO:create dependy graph + var array = getDependencies(dependency); + var arrayClone = array.concat([]); + + function getDependency() { + var key = array.shift(); + return dependencies[key]; + } + + (function loadDependency(dependency) { + + if(!dependency){ + resolve(arrayClone); + return; + } + dependency().then(function (data) { + var _dependency = getDependency(); + loadDependency(_dependency); + }); + } (getDependency())) + + }); - while(key=array.pop()){ - dependencies[key](); - } - }, - write:function(){ + + write: function () { console.log(_graph); } } }; -export const SplitingRegister = _SplitingRegister(); +window.dependencies = _SplitingRegister(); +export const SplitingRegister = window.dependencies; diff --git a/@salix/crud/src/crud.js b/@salix/crud/src/crud.js index 7d4627b16d..58323041fd 100644 --- a/@salix/crud/src/crud.js +++ b/@salix/crud/src/crud.js @@ -1,4 +1,2 @@ export * from './module'; -export * from './customer/routes'; - export {NAME as CUSTOMER_INDEX, COMPONENT as CUSTOMER_INDEX_COMPONENT} from './customer/index' \ No newline at end of file diff --git a/@salix/crud/src/customer/index/index.js b/@salix/crud/src/customer/index/index.js index 3f404ca5af..4a195604a1 100644 --- a/@salix/crud/src/customer/index/index.js +++ b/@salix/crud/src/customer/index/index.js @@ -1,7 +1,7 @@ import template from './index.html'; import {module} from '../../module'; -export const NAME = 'customerAdd'; +export const NAME = 'customerIndex'; export const COMPONENT = { template: template, controller: function() { diff --git a/@salix/crud/src/customer/routes.js b/@salix/crud/src/customer/routes.js deleted file mode 100644 index 92032b1531..0000000000 --- a/@salix/crud/src/customer/routes.js +++ /dev/null @@ -1,31 +0,0 @@ -import * as core from '@salix/core'; -import * as index from './index'; - -core.module.config(function($stateProvider, $urlRouterProvider) { - - $urlRouterProvider.otherwise("/"); - - $stateProvider - .state('index', { - url: "/index", - component: index.CUSTOMER_INDEX, - resolve:{ - load:function(){ - console.log('hello'); - } - } - }) - .state('add', { - url: "/add", - template: "
add
" - }) - .state('edit', { - url: "/edit", - template: "
edit
" - }) - .state('delete', { - url: "/delete", - template: "
delete
" - }) - -}); diff --git a/@salix/crud/src/spliting.js b/@salix/crud/src/spliting.js deleted file mode 100644 index ba7ec12a6b..0000000000 --- a/@salix/crud/src/spliting.js +++ /dev/null @@ -1,8 +0,0 @@ - - -export const crud = (cb) => { - require.ensure([], () => { - require('@salix/crud'); - cb(); - }, "salix.crud"); -}; \ No newline at end of file diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 9d648ec6bc..0000000000 --- a/npm-debug.log +++ /dev/null @@ -1,27 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/usr/local/Cellar/node/6.3.1/bin/node', -1 verbose cli '/usr/local/bin/npm', -1 verbose cli 'run', -1 verbose cli 'dev' ] -2 info using npm@3.10.3 -3 info using node@v6.3.1 -4 verbose stack Error: missing script: dev -4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19) -4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5 -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5 -4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45) -4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3) -4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5) -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:311:12 -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 -4 verbose stack at tryToString (fs.js:455:3) -4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12) -5 verbose cwd /Users/nelo/Documents/node/salix -6 error Darwin 16.0.0 -7 error argv "/usr/local/Cellar/node/6.3.1/bin/node" "/usr/local/bin/npm" "run" "dev" -8 error node v6.3.1 -9 error npm v3.10.3 -10 error missing script: dev -11 error If you need help, you may report this error at: -11 error -12 verbose exit [ 1, true ]