narirou / gulp-develop-server Goto Github PK
View Code? Open in Web Editor NEWDevelopment assistant for node.js server by gulp
License: MIT License
Development assistant for node.js server by gulp
License: MIT License
Hi,
I use livereload and it doesn't work properly with develop-server:
// run server
gulp.task( 'server:start', function() {
server.listen( { path: 'server/app.js', env: require('./config.json') } );
});
// restart server and then livereload
gulp.task( 'server:restart', function() {
gulp.src( 'server/app.js' )
.pipe( server() );
});
// watching server scripts
gulp.task( 'watch', [ 'less', 'server:start' ], function() {
livereload.listen();
gulp.watch( [ 'server/*.js', 'config.json' ], [ 'server:restart' ] ).on('change', livereload.changed);
});
Output:
[14:55:03] app.js was reloaded.
[14:55:03] Starting 'server:restart'...
[14:55:03] Finished 'server:restart' after 3.88 ms
[14:55:03] Development server was stopped. ( PID: 42602 )
[14:55:03] Development server listening. ( PID: 42603 )
[14:55:03] Development server was restarted.
[14:55:03] app.js was reloaded.
[14:55:04] Development server has error.
[14:55:04] app.js was reloaded.
events.js:72
throw er; // Unhandled 'error' event
^
Error: no writecb in Transform class
at afterTransform (_stream_transform.js:90:33)
at TransformState.afterTransform (_stream_transform.js:74:12)
at /node_modules/gulp-develop-server/index.js:56:5
at /node_modules/gulp-develop-server/index.js:41:4
at Socket.<anonymous> (/node_modules/gulp-develop-server/index.js:144:4)
at Socket.g (events.js:180:16)
at Socket.EventEmitter.emit (events.js:117:20)
at Socket.<anonymous> (_stream_readable.js:745:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:407:10)
I'm not sure if this is a bug or if I'm just doing something wrong.
I have a gulpfile.js that looks like this:
var gulp = require( 'gulp' ),
server = require( 'gulp-develop-server' );
// run server
gulp.task( 'server:start', function() {
server.listen( { path: 'app.js' } );
});
When I run the task the server seems to start listening but gulp stops immediately after that.
breakfast[ master*]$ gulp server:start
[12:55:50] Using gulpfile ~/projects/breakfast/gulpfile.js
[12:55:50] Starting 'server:start'...
[12:55:50] Finished 'server:start' after 5.68 ms
[12:55:51] Development server listening. (PID:64753)
breakfast[ master*]$
launching using execArgv: ['--debug']
is interpreted wrongly as an error.
var devServerOpts;
devServerOpts = {
path: path.join(binServer, 'main.js'),,
execArgv: ['--debug']
};
gulp.task('server-start', function() {
return devServer.listen(devServerOpts);
});
gulp.task('server-reload', function() {
return devServer.restart(function(err) {
if (err != null) {
return console.log(err);
} else {
return livereload.reload();
}
});
});
$ gulp server-start
[23:47:50] Using gulpfile D:\Sync\git\untitled-gulp-build-system\generator\Gulpfile.js
[23:47:50] Starting 'server-start'...
[23:47:50] Finished 'server-start' after 8.47 ms
[23:47:50] Development server has error.
--- server starts running correctly ---
After inserting logging message in
// run callback with error message if the server has error
child.stderr.once( 'data', function( error ) {
if( ! called && error ) {
if( timer ) {
timer = clearTimeout( timer );
}
var msg = 'Development server has error.';
gutil.log( gutil.colors.red( msg ) );
called = true;
started( msg, callback );
}
});
in gulp-develop-server index.js
i found that error is at this point is a buffer pipe.
The code assumes that any content in error
is an error even though error
might be a empty pipe.
Hi,
I have a bootstrap coffee script that I run with gulp-develop-server:
#!/usr/bin/env coffee
app = require '../src/app'
http = require 'http'
port = process.env.PORT or '3000'
app.set 'port', port
server = http.createServer app
server.listen port
I have tried to pass my script with path
option to gulp-develop-server but it would run my script with node instead. Then I looked at the source code and figured that there is an execPath parameter which seem to do the trick.
gulp.task 'server:start', ->
server.listen
path: ''
execPath: 'bin/www'
env: require './config.json'
return
gulp.task 'server:restart', ->
server.restart()
return
My question is, is it normal that I pass an empty path and provide custom execPath for my coffee script?
Hi,
When I run my script directly, I get nice colorful output in console, however when I run it with gulp-develop-server the output is standard without colors. Is it possible to proxy the original colorful output?
·
/home/ubuntu/weidian/backend/node_modules/gulp-develop-server/index.js:188 │············
var pid = gutil.colors.magenta( app.child.pid ); │············
^ │············
TypeError: Cannot read property 'pid' of null │············
at ChildProcess.stopped (/home/ubuntu/weidian/backend/node_modules/gulp-develop-server/index.js:188:45) │············
at ChildProcess.g (events.js:199:16) │············
at ChildProcess.emit (events.js:129:20) │············
at maybeClose (child_process.js:1015:16) │············
at Socket. (child_process.js:1183:11) │············
at Socket.emit (events.js:107:17) │············
at Pipe.close (net.js:485:12)
When server process crash, server.reset does not work. It should start server even if it's down.
My folder structure is:
<app_name>
logs/
server/
public/
server.js
gulpfile.js
bower.json
package.json
And my gulp file is setup as follows:
var FILES = {};
FILES.FRONTEND_JS = ['./public/app/**/*.js'];
FILES.FRONTEND_HTML = ['./public/app/**/*.html'];
FILES.FRONTEND_SASS = ['./public/assets/sass/**/*.scss'];
FILES.FRONTEND_ALL = [].concat(FILES.FRONTEND_JS, FILES.FRONTEND_HTML, FILES.FRONTEND_SASS);
FILES.SERVER_JS = ['./server/**/*.js', './server.js', './config.js'];
FILES.BUILD_FILES = ['./gulpfile.js'];
FILES.JS_ALL = [].concat(FILES.FRONTEND_JS, FILES.SERVER_JS);
gulp.task('watch', [ 'serve' ], function() {
function restart( file ) {
server.changed( function( error ) {
if( ! error ) {
reloadBrowser('Backend file changed.', file.path);
}
});
}
function reloadBrowser( message, path ) {
gutil.log(message ? message : 'Something changed.', gutil.colors.bgBlue.white.bold('Reloading browser...'));
livereload.changed( path );
}
gulp.watch(FILES.JS_ALL, ['lint-js']);
gulp.watch(FILES.FRONTEND_SASS, ['styles']);
gulp.watch(FILES.SERVER_JS).on( 'change', restart );
gulp.watch(FILES.FRONTEND_ALL).on( 'change', function(file) {reloadBrowser('Frontend file changed.', file.path);} );
});
Even though non of the gulp.watch
calls that I do should reload (by liveReload
which is managed by gulp-develop-server
) since the logs/
folder isn't present in those paths, I get the following reload:
[21:12:55] Development server was stopped. (PID:6600)
[21:12:55] Development server already received restart requests.
[21:12:55] Backend file changed. Reloading browser...
[21:12:55] ...\<app_name>\logs reloaded.
why should it reload on any change in logs/
?
I'm currently testing this on a windows 10 machine. I'll check if the same happens on ubuntu and os x.
Is it possible to change the current working directory? Maybe something for example like where the application runs relative to api2/index.js
:
gulp.task('serve', function(callback) {
server.listen( {
cwd: 'api2/',
env: {
NODE_ENV: 'development',
DEBUG_COLORS: 1
},
path: 'index.js'
}, callback);
});
It would be very useful to have the option to pipe the output to a cli tool like the one bunyan provides.
Expected behavior: node app.js | bunyan
Currently I do not see a way to do something like that. If I'm wrong please correct me.
Would be great to be able to know when the server is running so i can change my build tasks accordingly.
Example if i'm building my source code and the server is running I want to pipe it to server() otherwise I'd not do it because it throws an error. Something that can be used with gulp-if would be even better.
There is no way to pass arguments to the script. Instead, arguments can be passed only to the node.js executable using option execArgv.
var server = require('gulp-develop-server');
server.listen({
path: './stub/server.js',
execArgv : ['--param']
});
Expected behaviour:
"C:\Program Files\nodejs\node.exe" ./stub/server.js --param
Actual behaviour:
"C:\Program Files\nodejs\node.exe" --param ./stub/server.js
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.