2016-10-06 09:18:02 +00:00
|
|
|
|
|
|
|
var gulp = require ('gulp');
|
2016-11-11 11:04:50 +00:00
|
|
|
var gutil = require('gulp-util');
|
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-11-11 11:04:50 +00:00
|
|
|
var webpack = require ('webpack-stream');
|
|
|
|
var webpackConfig = require ('./webpack.config.js');
|
2016-10-06 09:18:02 +00:00
|
|
|
|
2016-10-21 06:38:58 +00:00
|
|
|
// Spliting
|
|
|
|
|
2016-11-11 11:04:50 +00:00
|
|
|
var splitingDir = './app/src/spliting';
|
|
|
|
var splitingFiles = splitingDir +'/*';
|
2016-10-21 06:38:58 +00:00
|
|
|
|
2016-11-11 11:04:50 +00:00
|
|
|
gulp.task ('spliting', function ()
|
2016-10-21 06:38:58 +00:00
|
|
|
{
|
2016-11-11 11:04:50 +00:00
|
|
|
var jsonDeps = fs.readFileSync (splitingDir +'/deps.json');
|
|
|
|
var modules = JSON.parse (jsonDeps);
|
|
|
|
|
|
|
|
var importTpl = fs.readFileSync (splitingDir +'/import.tpl.js', 'utf8');
|
|
|
|
var requireTpl = fs.readFileSync (splitingDir +'/require.tpl.js', 'utf8');
|
2016-10-21 06:38:58 +00:00
|
|
|
|
|
|
|
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]));
|
|
|
|
}
|
2016-11-11 11:04:50 +00:00
|
|
|
});
|
2016-10-21 06:38:58 +00:00
|
|
|
|
2016-11-11 11:04:50 +00:00
|
|
|
// Webpack
|
|
|
|
|
|
|
|
gulp.task ('webpack', ['spliting'], function (callback)
|
2016-10-21 06:38:58 +00:00
|
|
|
{
|
2016-11-11 11:04:50 +00:00
|
|
|
return gulp.src (['app/index.js', 'login/index.js'])
|
|
|
|
.pipe (webpack (webpackConfig))
|
|
|
|
.pipe (gulp.dest ('build/public/'));
|
2016-10-21 06:38:58 +00:00
|
|
|
});
|
|
|
|
|
2016-11-11 11:04:50 +00:00
|
|
|
// Routes
|
|
|
|
|
|
|
|
var routeFiles = './crud/**/routes.js';
|
|
|
|
|
|
|
|
gulp.task ('routes', function ()
|
|
|
|
{
|
|
|
|
var fileTpl = '\n"<%=file.relative%>": <%=contents%>';
|
|
|
|
var globalTpl = 'var routes = {<%=contents%>\n}';
|
2016-10-21 06:38:58 +00:00
|
|
|
|
2016-11-11 11:04:50 +00:00
|
|
|
return gulp.src (routeFiles)
|
|
|
|
.pipe (wrap (fileTpl))
|
|
|
|
.pipe (concat ('salix.routes.js', {newLine: ','}))
|
|
|
|
.pipe (wrap (globalTpl))
|
|
|
|
.pipe (babel ({presets: ['es2015']}))
|
|
|
|
.pipe (gulp.dest ('./build/public'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Watch
|
|
|
|
|
|
|
|
gulp.task ('watch', function ()
|
|
|
|
{
|
|
|
|
gulp.watch (routeFiles, ['routes']);
|
|
|
|
gulp.watch (splitingFiles, ['spliting']);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Default
|
2016-10-21 06:38:58 +00:00
|
|
|
|
2016-11-11 11:04:50 +00:00
|
|
|
gulp.task ('build', ['routes', 'webpack']);
|
|
|
|
gulp.task ('default', ['watch', 'build']);
|
2016-10-21 06:38:58 +00:00
|
|
|
|