salix/gulpfile.js

73 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-10-06 09:18:02 +00:00
var gulp = require ('gulp');
var wrap = require('gulp-wrap');
var concat = require ('gulp-concat');
var babel = require ('gulp-babel');
var fs = require ('fs');
2016-10-10 09:15:05 +00:00
// Routes
2016-10-06 09:18:02 +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
{
return gulp.src ('./@salix/**/routes.js')
.pipe (wrap (fileTpl))
2016-10-10 09:15:05 +00:00
.pipe (concat ('salix.routes.js', {newLine: ','}))
.pipe (wrap (globalTpl))
.pipe (babel ({presets: ['es2015']}))
.pipe (gulp.dest ('./build/private'));
2016-10-06 09:18:02 +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']);