2016-10-06 09:18:02 +00:00
|
|
|
|
|
|
|
var gulp = require ('gulp');
|
2016-10-21 06:38:58 +00:00
|
|
|
var wrap = require('gulp-wrap');
|
2016-10-07 09:44:24 +00:00
|
|
|
var concat = require ('gulp-concat');
|
|
|
|
var babel = require ('gulp-babel');
|
2016-10-21 06:38:58 +00:00
|
|
|
var fs = require ('fs');
|
2016-10-10 09:15:05 +00:00
|
|
|
|
2016-10-21 06:38:58 +00:00
|
|
|
// Routes
|
2016-10-06 09:18:02 +00:00
|
|
|
|
2016-10-21 06:38:58 +00:00
|
|
|
var fileTpl = '\n"<%=file.path%>": <%=contents%>';
|
|
|
|
var globalTpl = 'var routes = {<%=contents%>\n}';
|
|
|
|
|
|
|
|
gulp.task ('routes', function ()
|
2016-10-06 09:18:02 +00:00
|
|
|
{
|
2016-10-21 06:38:58 +00:00
|
|
|
return gulp.src ('./@salix/**/routes.js')
|
|
|
|
.pipe (wrap (fileTpl))
|
2016-10-10 09:15:05 +00:00
|
|
|
.pipe (concat ('salix.routes.js', {newLine: ','}))
|
2016-10-21 06:38:58 +00:00
|
|
|
.pipe (wrap (globalTpl))
|
2016-10-07 09:44:24 +00:00
|
|
|
.pipe (babel ({presets: ['es2015']}))
|
|
|
|
.pipe (gulp.dest ('./build/private'));
|
2016-10-06 09:18:02 +00:00
|
|
|
});
|
|
|
|
|
2016-10-21 06:38:58 +00:00
|
|
|
// 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']);
|
|
|
|
|
|
|
|
|