Scripts de arranque, entorno desarrollo optimizado
This commit is contained in:
parent
e62fc745d4
commit
f260a45499
|
@ -1,22 +1,22 @@
|
||||||
|
|
||||||
var path = require ('path');
|
var path = require('path');
|
||||||
var gulp = require ('gulp');
|
var gulp = require('gulp');
|
||||||
var gutil = require('gulp-util');
|
var gutil = require('gulp-util');
|
||||||
var wrap = require('gulp-wrap');
|
var wrap = require('gulp-wrap');
|
||||||
var concat = require ('gulp-concat');
|
var concat = require('gulp-concat');
|
||||||
var babel = require ('gulp-babel');
|
var babel = require('gulp-babel');
|
||||||
var fs = require ('fs');
|
var fs = require('fs');
|
||||||
var del = require ('del');
|
var del = require('del');
|
||||||
var webpack = require ('webpack-stream');
|
var webpack = require('webpack');
|
||||||
var webpackConfig = require ('./webpack.config.js');
|
var WebpackDevServer = require("webpack-dev-server");
|
||||||
|
var webpackConfig = require('./webpack.config.js');
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
|
|
||||||
var buildDir = '../services/nginx/static'
|
var buildDir = '../services/nginx/static'
|
||||||
|
|
||||||
gulp.task ('clean', function ()
|
gulp.task('clean', function() {
|
||||||
{
|
return del(buildDir +'/*', {force: true});
|
||||||
return del (buildDir +'/*', {force: true});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Spliting
|
// Spliting
|
||||||
|
@ -24,83 +24,95 @@ gulp.task ('clean', function ()
|
||||||
var splitingDir = './app/src/spliting';
|
var splitingDir = './app/src/spliting';
|
||||||
var splitingFiles = splitingDir +'/*';
|
var splitingFiles = splitingDir +'/*';
|
||||||
|
|
||||||
gulp.task ('spliting', function ()
|
gulp.task('spliting', function() {
|
||||||
{
|
var jsonDeps = fs.readFileSync(splitingDir +'/deps.json');
|
||||||
var jsonDeps = fs.readFileSync (splitingDir +'/deps.json');
|
var modules = JSON.parse(jsonDeps);
|
||||||
var modules = JSON.parse (jsonDeps);
|
|
||||||
|
|
||||||
var importTpl = fs.readFileSync (splitingDir +'/import.tpl.js', 'utf8');
|
var importTpl = fs.readFileSync(splitingDir +'/import.tpl.js', 'utf8');
|
||||||
var requireTpl = fs.readFileSync (splitingDir +'/require.tpl.js', 'utf8');
|
var requireTpl = fs.readFileSync(splitingDir +'/require.tpl.js', 'utf8');
|
||||||
|
|
||||||
for (var modName in modules)
|
for(var modName in modules)
|
||||||
{
|
{
|
||||||
var deps = modules[modName];
|
var deps = modules[modName];
|
||||||
var splitFile = './'+ modName +'/src/spliting.js';
|
var splitFile = './'+ modName +'/src/spliting.js';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync (splitFile);
|
fs.unlinkSync(splitFile);
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch(e) {}
|
||||||
|
|
||||||
fs.appendFileSync (splitFile, importTpl);
|
fs.appendFileSync(splitFile, importTpl);
|
||||||
|
|
||||||
var i = deps.length;
|
var i = deps.length;
|
||||||
while (i--)
|
while(i--)
|
||||||
fs.appendFileSync (splitFile,
|
fs.appendFileSync(splitFile,
|
||||||
requireTpl.replace (/\$module/g, deps[i]));
|
requireTpl.replace(/\$module/g, deps[i]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Webpack
|
// Webpack
|
||||||
|
|
||||||
gulp.task ('webpack-watch', ['spliting'], function ()
|
gulp.task('webpack', ['spliting'], function(callback) {
|
||||||
{
|
var myDevConfig = Object.create(webpackConfig);
|
||||||
webpackConfig.watch = true;
|
myDevConfig.debug = true;
|
||||||
return gulp.src (['app/index.js', 'login/index.js'])
|
|
||||||
.pipe (webpack (webpackConfig))
|
var devCompiler = webpack(myDevConfig);
|
||||||
.pipe (gulp.dest (buildDir));
|
|
||||||
|
devCompiler.run(function(err, stats) {
|
||||||
|
if(err) throw new gutil.PluginError('webpack', err);
|
||||||
|
gutil.log('[webpack]', stats.toString({colors: true}));
|
||||||
|
callback();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task ('webpack', ['spliting'], function ()
|
gulp.task('webpack-dev-server', ['spliting'], function() {
|
||||||
{
|
var myConfig = Object.create(webpackConfig);
|
||||||
return gulp.src (['app/index.js', 'login/index.js'])
|
myConfig.debug = true;
|
||||||
.pipe (webpack (webpackConfig))
|
|
||||||
.pipe (gulp.dest (buildDir));
|
for (var entry in myConfig.entry)
|
||||||
|
myConfig.entry[entry]
|
||||||
|
.unshift('webpack-dev-server/client?http://0.0.0.0:8081/');
|
||||||
|
|
||||||
|
var devServer = new WebpackDevServer(webpack(myConfig), {
|
||||||
|
publicPath: '/',
|
||||||
|
stats: {colors: true},
|
||||||
|
contentBase: buildDir
|
||||||
|
})
|
||||||
|
.listen(8081, '0.0.0.0', function(err) {
|
||||||
|
if(err) throw new gutil.PluginError('webpack-dev-server', err);
|
||||||
|
gutil.log('[webpack-dev-server]', 'Listening');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
|
|
||||||
var routeFiles = './crud/**/routes.js';
|
var routeFiles = './crud/**/routes.js';
|
||||||
|
|
||||||
gulp.task ('routes', function ()
|
gulp.task('routes', function() {
|
||||||
{
|
|
||||||
var fileTpl = '\n"<%=file.relative%>": <%=contents%>';
|
var fileTpl = '\n"<%=file.relative%>": <%=contents%>';
|
||||||
var globalTpl = 'var routes = {<%=contents%>\n}';
|
var globalTpl = 'var routes = {<%=contents%>\n}';
|
||||||
|
|
||||||
return gulp.src (routeFiles)
|
return gulp.src(routeFiles)
|
||||||
.pipe (wrap (fileTpl))
|
.pipe(wrap(fileTpl))
|
||||||
.pipe (concat ('salix.routes.js', {newLine: ','}))
|
.pipe(concat('salix.routes.js', {newLine: ','}))
|
||||||
.pipe (wrap (globalTpl))
|
.pipe(wrap(globalTpl))
|
||||||
.pipe (babel ({presets: ['es2015']}))
|
.pipe(babel({presets: ['es2015']}))
|
||||||
.pipe (gulp.dest (buildDir));
|
.pipe(gulp.dest(buildDir));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Watch
|
// Watch
|
||||||
|
|
||||||
gulp.task ('watch', function ()
|
gulp.task('watch', function() {
|
||||||
{
|
gulp.watch(routeFiles, ['routes']);
|
||||||
gulp.watch (routeFiles, ['routes']);
|
gulp.watch(splitingFiles, ['spliting']);
|
||||||
gulp.watch (splitingFiles, ['spliting']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Default
|
// Default
|
||||||
|
|
||||||
gulp.task ('build', ['clean'], function ()
|
gulp.task('build', ['clean'], function() {
|
||||||
{
|
return gulp.start('routes', 'webpack');
|
||||||
return gulp.start ('routes', 'webpack');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task ('default', ['clean'], function ()
|
gulp.task('default', ['clean'], function() {
|
||||||
{
|
return gulp.start('watch', 'routes', 'webpack-dev-server');
|
||||||
return gulp.start ('watch', 'routes', 'webpack-watch');
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,8 +39,7 @@
|
||||||
"sass-loader": "^4.0.2",
|
"sass-loader": "^4.0.2",
|
||||||
"style-loader": "^0.13.1",
|
"style-loader": "^0.13.1",
|
||||||
"webpack": "^1.13.3",
|
"webpack": "^1.13.3",
|
||||||
"webpack-dev-server": "^1.16.2",
|
"webpack-dev-server": "^1.16.2"
|
||||||
"webpack-stream": "^3.2.0"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack --progress --colors --watch",
|
"build": "webpack --progress --colors --watch",
|
||||||
|
|
|
@ -45,10 +45,6 @@ var config = {
|
||||||
'node_modules'
|
'node_modules'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
devServer: {
|
|
||||||
inline: true,
|
|
||||||
host: '0.0.0.0'
|
|
||||||
},
|
|
||||||
devtool: 'source-map'
|
devtool: 'source-map'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
25
env.cmd
25
env.cmd
|
@ -1,34 +1,31 @@
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
|
set currentDir=%~dp0
|
||||||
|
set nginxPrefix=%currentDir%\services\nginx
|
||||||
|
set nginxConf=%nginxPrefix%\conf-dev.conf
|
||||||
|
|
||||||
if "%1"=="" goto caseStart
|
if "%1"=="" goto caseStart
|
||||||
if "%1"=="start" goto caseStart
|
if "%1"=="start" goto caseStart
|
||||||
if "%1"=="stop" goto caseStop
|
if "%1"=="stop" goto caseStop
|
||||||
goto caseUsage
|
goto caseUsage
|
||||||
|
|
||||||
:caseStart
|
:caseStart
|
||||||
echo ######################
|
|
||||||
echo "Arrancando Servicios"
|
|
||||||
echo ######################
|
|
||||||
echo.
|
|
||||||
call "%0" stop
|
call "%0" stop
|
||||||
|
echo "################################ Starting services"
|
||||||
call forever start forever.json
|
call forever start forever.json
|
||||||
call forever list
|
call forever list
|
||||||
call nginx -c conf-dev.conf
|
call nginx -c "%nginxConf%" -p "%nginxPrefix%"
|
||||||
call cd @salix
|
call cd @salix
|
||||||
call gulp
|
call gulp
|
||||||
goto salir
|
goto caseExit
|
||||||
|
|
||||||
:caseStop
|
:caseStop
|
||||||
echo ######################
|
echo "################################ Stoping services"
|
||||||
echo "Parando Servicios"
|
|
||||||
echo ######################
|
|
||||||
echo.
|
|
||||||
call forever stopall
|
call forever stopall
|
||||||
call forever list
|
call nginx -c "%nginxConf%" -p "%nginxPrefix%" -s stop
|
||||||
call nginx -c conf-dev.conf -p @salix -s stop
|
goto caseExit
|
||||||
goto salir
|
|
||||||
|
|
||||||
:caseUsage
|
:caseUsage
|
||||||
echo "Usage: %0 [start|stop]"
|
echo "Usage: %0 [start|stop]"
|
||||||
|
|
||||||
:salir
|
:caseExit
|
17
env.sh
17
env.sh
|
@ -1,19 +1,26 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
nginxDir="${PWD}/services/nginx"
|
nginxBin="/usr/sbin/nginx"
|
||||||
|
nginxPrefix="${PWD}/services/nginx"
|
||||||
|
nginxConf="$nginxPrefix/conf-dev.conf"
|
||||||
|
|
||||||
|
if [ ! -f $nginxBin ]; then
|
||||||
|
nginxBin="nginx"
|
||||||
|
fi
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start|"")
|
start|"")
|
||||||
|
$0 stop
|
||||||
|
echo "################################ Starting services"
|
||||||
forever start forever.json
|
forever start forever.json
|
||||||
forever list
|
forever list
|
||||||
/usr/sbin/nginx -c "$nginxDir/conf-dev.conf" -p "$nginxDir"
|
"$nginxBin" -c "$nginxConf" -p "$nginxPrefix"
|
||||||
cd @salix && gulp
|
cd @salix && gulp
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
|
echo "################################ Stoping services"
|
||||||
forever stopall
|
forever stopall
|
||||||
forever list
|
"$nginxBin" -c "$nginxConf" -p "$nginxPrefix" -s stop
|
||||||
/usr/sbin/nginx -c "$nginxDir/conf-dev.conf" -p "$nginxDir" -s stop
|
|
||||||
cd @salix && gulp clean
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: `basename "$0"` [start|stop]"
|
echo "Usage: `basename "$0"` [start|stop]"
|
||||||
|
|
|
@ -25,9 +25,8 @@ http {
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
autoindex off;
|
autoindex off;
|
||||||
|
|
||||||
location /static {
|
location ~ ^/static(?:/(.*))?$ {
|
||||||
alias static/;
|
proxy_pass http://127.0.0.1:8081/$1$is_args$args;
|
||||||
autoindex on;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~ ^/account(?:/(.*))?$ {
|
location ~ ^/account(?:/(.*))?$ {
|
||||||
|
|
Loading…
Reference in New Issue