El servicio de Nginx ahora se inicia desde Gulp. Añadido alias de instalacion "gulp i".

This commit is contained in:
Joan Sanchez 2018-02-05 19:22:38 +01:00
parent d24058bab1
commit 692a226b69
5 changed files with 51 additions and 67 deletions

View File

@ -19,3 +19,4 @@ rules:
no-eq-null: 0
no-console: 0
no-warning-comments: 0
no-empty: 0

View File

@ -101,6 +101,9 @@ gulp.task('install', () => {
}));
});
// Gulp install alias
gulp.task('i', ['install']);
// Deployment
gulp.task('build', ['clean'], () => {
@ -141,15 +144,50 @@ gulp.task('docker-compose', async () => {
// Nginx & services
gulp.task('nginx', ['nginx-conf'], callback => {
let command = isWindows ? 'start.cmd' : 'start.sh';
command = path.join(`${nginxDir}/${command}`);
exec(command, (err, stdout, stderr) => {
// if (stderr) console.log(stderr);
callback(err);
let nginxConf = 'temp/nginx.conf';
let nginxTemp = `${nginxDir}/temp`;
async function nginxGetBin() {
if (isWindows)
return 'nginx';
try {
let nginxBin = '/usr/sbin/nginx';
await fs.stat(nginxBin);
return nginxBin;
} catch (e) {
return 'nginx';
}
}
gulp.task('nginx', ['nginx-stop'], async () => {
let nginxBin = await nginxGetBin();
if (isWindows)
nginxBin = `start /B ${nginxBin}`;
return new Promise((resolve, reject) => {
exec(`${nginxBin} -c "${nginxConf}" -p "${nginxDir}"`, err => {
if (err) return reject(err);
resolve();
});
});
});
gulp.task('nginx-stop', ['nginx-conf'], async () => {
try {
let nginxBin = await nginxGetBin();
await fs.stat(`${nginxTemp}/nginx.pid`);
let command = `${nginxBin} -c "${nginxConf}" -p "${nginxDir}" -s stop`;
return new Promise((resolve, reject) => {
exec(command, err => {
if (err) return reject(err);
resolve();
});
});
} catch (e) {}
});
gulp.task('nginx-conf', async () => {
const mustache = require('mustache');

12
package-lock.json generated
View File

@ -244,7 +244,7 @@
"aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
"integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==",
"integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo=",
"dev": true
},
"archy": {
@ -10103,7 +10103,7 @@
"karma-chrome-launcher": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-2.2.0.tgz",
"integrity": "sha512-uf/ZVpAabDBPvdPdveyk1EPgbnloPvFFGgmRhYLTDH7gEB4nZdSBk8yTU47w1g/drLSx5uMOkjKk7IWKfWg/+w==",
"integrity": "sha1-zxudBxNswY/iOTJ9JGVMPbw2is8=",
"dev": true,
"requires": {
"fs-access": "1.0.1",
@ -10134,7 +10134,7 @@
"karma-webpack": {
"version": "2.0.9",
"resolved": "https://registry.npmjs.org/karma-webpack/-/karma-webpack-2.0.9.tgz",
"integrity": "sha512-F1j3IG/XhiMzcunAXbWXH95uizjzr3WdTzmVWlta8xqxcCtAu9FByCb4sccIMxaVFAefpgnUW9KlCo0oLvIX6A==",
"integrity": "sha1-YciAkffdkQY1E0wDKyZqRlr/tX8=",
"dev": true,
"requires": {
"async": "0.9.2",
@ -11183,7 +11183,7 @@
"node-sass": {
"version": "4.7.2",
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.7.2.tgz",
"integrity": "sha512-CaV+wLqZ7//Jdom5aUFCpGNoECd7BbNhjuwdsX/LkXBrHl8eb1Wjw4HvWqcFvhr5KuNgAk8i/myf/MQ1YYeroA==",
"integrity": "sha1-k2Z3i6FGnrAUOKnoWS9CYry2eU4=",
"dev": true,
"requires": {
"async-foreach": "0.1.3",
@ -11401,7 +11401,7 @@
"npmlog": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
"integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==",
"integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=",
"dev": true,
"requires": {
"are-we-there-yet": "1.1.4",
@ -15164,7 +15164,7 @@
"wide-align": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz",
"integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==",
"integrity": "sha1-Vx4PGwYEY268DfwhsDObvjE0FxA=",
"dev": true,
"requires": {
"string-width": "1.0.2"

View File

@ -1,27 +0,0 @@
@echo off
set nginxDir=%~dp0
set nginxTemp=%nginxDir%\temp
set nginxConf=temp\nginx.conf
if "%1"=="" goto caseStart
if "%1"=="start" goto caseStart
if "%1"=="stop" goto caseStop
goto caseUsage
:caseStart
call "%0" stop
echo Starting nginx.
if not exist "%nginxTemp%" (mkdir "%nginxTemp%")
start /I nginx -c "%nginxConf%" -p "%nginxDir%"
goto caseEnd
:caseStop
echo Stoping nginx.
if exist "%nginxTemp%\nginx.pid" (nginx -c "%nginxConf%" -p "%nginxDir%" -s stop)
goto caseEnd
:caseUsage
echo "Usage: %0 [start|stop]"
:caseEnd

View File

@ -1,28 +0,0 @@
#!/bin/bash
nginxDir="$(dirname $0)"
nginxTemp="$nginxDir/temp"
nginxConf="temp/nginx.conf"
nginxBin="/usr/sbin/nginx"
if [ ! -f $nginxBin ]; then
nginxBin="nginx"
fi
case "$1" in
start|"")
$0 stop
echo "Starting nginx."
mkdir -p "$nginxTemp"
"$nginxBin" -c "$nginxConf" -p "$nginxDir"
;;
stop)
echo "Stoping nginx."
if [ -f "$nginxTemp/nginx.pid" ]; then
"$nginxBin" -c "$nginxConf" -p "$nginxDir" -s stop
fi
;;
*)
echo "Usage: `basename "$0"` [start|stop]"
exit 1
esac