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-11-04 10:32:27 +00:00
|
|
|
return gulp.src ('./**/routes.js')
|
2016-10-21 06:38:58 +00:00
|
|
|
.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
|
|
|
|
|
2016-11-04 10:32:27 +00:00
|
|
|
var baseDir = './app/src/spliting';
|
2016-10-21 06:38:58 +00:00
|
|
|
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];
|
2016-11-04 10:32:27 +00:00
|
|
|
var splitFile = './'+ modName +'/src/spliting.js';
|
2016-10-21 06:38:58 +00:00
|
|
|
|
|
|
|
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']);
|
|
|
|
|
|
|
|
|