Rutas y splitings generados automaticamente

This commit is contained in:
Juan Ferrer Toribio 2016-10-21 08:38:58 +02:00
parent 9f7be0dbbe
commit 8905d685f7
19 changed files with 93 additions and 104 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules
build
spliting.js

View File

@ -1,4 +0,0 @@
{
compras: ["crud"],
crud: []
}

View File

@ -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);

View File

@ -1,17 +0,0 @@
export const graphRoutes = {
routes: [
{
url: '/index',
state: 'index',
template: '<customer-index></customer-index>',
module: 'crud',
description: '',
image: '',
}
],
graphDependendies: {
compras: ["crud"],
crud: []
}
};

View File

@ -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);

View File

@ -0,0 +1,5 @@
{
"app": ["buys", "crud"],
"buys": ["crud"],
"crud": []
}

View File

@ -0,0 +1 @@
import * as core from '@salix/core';

View File

@ -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);

2
@salix/buys/index.js Normal file
View File

@ -0,0 +1,2 @@
export * from './src/buys';

View File

@ -1,2 +0,0 @@
export * from './src/compras';

View File

@ -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);

View File

@ -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';

View File

@ -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')

View File

@ -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');

View File

@ -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']);

View File

@ -11,6 +11,10 @@
<a ui-sref="edit">edit</a>
<a ui-sref="delete">delete</a>
</div>
<script
type="text/javascript"
src="build/private/salix.routes.js">
</script>
<script
type="text/javascript"
src="build/public/salix.app.js"

View File

@ -30,6 +30,7 @@
"gulp-concat": "^2.6.0",
"gulp-insert": "^0.5.0",
"gulp-wrap": "^0.13.0",
"json-loader": "^0.5.4",
"pre-commit": "^1.1.3",
"raw-loader": "*",
"style-loader": "^0.13.1",