Last active
August 29, 2015 14:06
-
-
Save damrem/f79a80f58fed26147645 to your computer and use it in GitHub Desktop.
divshot/divshot-cli/lib/commands/server.js for Windows (fixes spawn ENOENT error)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var spawn = require('child_process').spawn; | |
module.exports = function (cli) { | |
var command = cli.command('server <optional directory>', 's <optional directory>'); | |
command.description('start server for local development'); | |
command.handler(function (customDir, done) { | |
var cmd = path.resolve(__dirname, '../../node_modules/.bin/superstatic'); | |
//for(var prop in process.env){ cli.log('process.env.'+prop+' = '+process.env[prop]); } | |
var server; | |
if(process && process.env && process.env.OS.toLowerCase().indexOf('windows') >= 0) { | |
cli.log('[divshot-cli/lib/command/server.js] Running on Windows: spawn workaround.'); | |
server = spawn('cmd', ['/s','/c',cmd,process.argv.splice(3)], { | |
windowsVerbatimArguments: true | |
}); | |
} | |
else { | |
server = spawn(cmd , process.argv.splice(3)); | |
} | |
server.stdout.on('data', function (data) { | |
cli.log(data.toString()); | |
}); | |
server.stderr.on('data', function (data) { | |
done(cli.errors.SERVER_ERROR); | |
}); | |
server.on('close', function () { | |
done(); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment