Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new file structure and added required files
- Loading branch information
Mark Parolisi
committed
Mar 21, 2013
1 parent
23adb02
commit fea7864
Showing
8 changed files
with
277 additions
and
159 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* peon-gui | ||
* Creates a local webserver GUI tool to run Grunt tasks | ||
* | ||
* Copyright (c) 2013 Mark Parolisi, contributors | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
/*global module */ | ||
module.exports = function (grunt) { | ||
"use strict"; | ||
grunt.initConfig({ | ||
jshint: { | ||
all: [ | ||
'Gruntfile.js', | ||
'app/js/*.js', | ||
'<%= nodeunit.tests %>' | ||
], | ||
options: { } | ||
}, | ||
coffeelint: { | ||
app: ['lib/*.coffee', 'tasks/*.coffee'] | ||
}, | ||
nodeunit: { | ||
tests: ['tests/*_test.js'] | ||
} | ||
}); | ||
|
||
grunt.loadTasks('tasks'); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-coffeelint'); | ||
grunt.loadNpmTasks('grunt-contrib-nodeunit'); | ||
grunt.registerTask('default', ['jshint', 'coffeelint', 'nodeunit']); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2013 Mark Parolisi, contributors | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class PeonGUIServer | ||
grunt: require('grunt') | ||
connect: require('connect') | ||
path: require('path') | ||
server: false | ||
startPort = 8080 | ||
endPort = 8088 | ||
|
||
constructor: (worker) -> | ||
@worker = worker | ||
|
||
run: () -> | ||
ps = require('portscanner') | ||
that = @ | ||
workerPort = @worker.getSocket() | ||
ps.findAPortNotInUse(startPort, endPort, 'localhost', (err, port) -> | ||
appPath = that.path.resolve(__dirname, '../app') | ||
that.server = that.connect.createServer(that.connect.static(appPath)) | ||
that.server.listen(port) | ||
that.grunt.log.writeln "GUI running on localhost:#{port}" | ||
url = "http://localhost:#{port}/?socket=#{workerPort}" | ||
that.grunt.log.writeln "Manage this project on #{url}" | ||
) | ||
|
||
module.exports = PeonGUIServer |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
class PeonWebSocket | ||
grunt = require "grunt" | ||
spawn = require("child_process").spawn | ||
pkg: require(process.cwd() + '/package.json') | ||
workers: [] | ||
projectPort: 0 | ||
server: require('http').createServer((request, response) -> | ||
response.writeHead(404) | ||
response.end() | ||
) | ||
|
||
constructor: () -> | ||
process.on("uncaughtException", @killWorkers) | ||
process.on("SIGINT", @killWorkers) | ||
process.on("SIGTERM", @killWorkers) | ||
@tasks = grunt.task._tasks | ||
@removeTasks(['gui']) | ||
@addConfigToTasks() | ||
peonFile = __dirname.replace("tasks/peon-gui/tasks", "peon.coffee") | ||
if grunt.file.exists(peonFile) | ||
gruntFilePath = peonFile | ||
else if grunt.file.exists("Gruntfile.cofee") | ||
gruntFilePath = "Gruntfile.coffee" | ||
else if grunt.file.exists("Gruntfile.js") | ||
gruntFilePath = "Gruntfile.js" | ||
else | ||
grunt.fatal("No Gruntfile found") | ||
|
||
addConfigToTasks: () -> | ||
config = grunt.config.get() | ||
that = @ | ||
grunt.util._.forEach(@tasks, (task, k)-> | ||
taskConfig = JSON.stringify(config[k], null, 4) || "No configuration" | ||
that.tasks[k].config = taskConfig | ||
) | ||
|
||
removeTasks: (taskList) -> | ||
that = @ | ||
grunt.util._.forEach(@tasks, (task, k)-> | ||
if grunt.util._.indexOf(taskList, task.name) > -1 | ||
delete that.tasks[k] | ||
) | ||
|
||
killWorkers: () -> | ||
@workers.forEach((worker) -> | ||
process.kill(worker) | ||
) | ||
process.exit() | ||
|
||
getSocket: ()-> | ||
@projectPort | ||
|
||
startWorker: ()-> | ||
ps = require('portscanner') | ||
that = @ | ||
ps.findAPortNotInUse(61750, 61755, 'localhost', (err, port) -> | ||
that.projectPort = port | ||
pgs = require("./PeonGUIServer") | ||
new pgs(that).run() | ||
if that.projectPort | ||
that.server.listen(port, () -> | ||
grunt.log.writeln("WebSocket running on localhost:#{port}") | ||
) | ||
else | ||
grunt.log.writeln("Too many Peon WebSockets open. Close one.") | ||
) | ||
@listen() | ||
|
||
listen: () -> | ||
WebSocketServer = require('websocket').server | ||
wsServer = new WebSocketServer( | ||
httpServer: @server | ||
autoAcceptConnections: false | ||
) | ||
that = @ | ||
wsServer.on('request', (request) -> | ||
connection = request.accept('echo-protocol', request.origin) | ||
connection.on('message', (message) -> | ||
if message.type is 'utf8' | ||
msg = message.utf8Data | ||
if msg is 'connect' | ||
connection.sendUTF(JSON.stringify( | ||
tasks: that.tasks | ||
project: that.pkg.name | ||
port: that.projectPort | ||
action: "connected" | ||
)) | ||
else if Object.keys(that.tasks).indexOf(msg) > -1 | ||
connection.send("Running Task: #{msg}") | ||
args = [ | ||
'--gruntfile' | ||
gruntFilePath | ||
'--base' | ||
'.' | ||
msg | ||
] | ||
command = spawn('grunt', args) | ||
that.workers.push(command) | ||
command.stdout.on('data', (data) -> | ||
if data then connection.send(data.toString()) | ||
) | ||
command.stdout.on('end', (data) -> | ||
connection.sendUTF(JSON.stringify({ action: 'done'})) | ||
) | ||
command.stderr.on('data', (stderr) -> | ||
grunt.log.writeln stderr | ||
if stderr then connection.send(stderr.toString()) | ||
) | ||
) | ||
connection.on('close', () -> | ||
|
||
) | ||
) | ||
|
||
module.exports = PeonWebSocket |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
{ | ||
"name": "peon-gui", | ||
"description": "Web interface for Peon tasks", | ||
"version": "0.1.0", | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "~0.1.1", | ||
"grunt-contrib-clean": "~0.4.0", | ||
"grunt-contrib-nodeunit": "~0.1.2", | ||
"grunt": "~0.4.0" | ||
}, | ||
"peerDependencies": { | ||
"grunt": "~0.4.0" | ||
}, | ||
"dependencies": { | ||
"websocket": "~1.0.8", | ||
"portscanner": "~0.1.3", | ||
"connect": "latest" | ||
} | ||
"name": "peon-gui", | ||
"description": "Web interface for Grunt tasks", | ||
"keywords": [ | ||
"gruntplugin", | ||
"server", | ||
"http", | ||
"gui" | ||
], | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/", | ||
"author": { | ||
"name": "Mark Parolisi", | ||
"url": "http://markparolisi.com/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/ /issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/ /blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"main": "Gruntfile.js", | ||
"scripts": { | ||
"test": "grunt test" | ||
}, | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "latest", | ||
"grunt-contrib-nodeunit": "latest", | ||
"grunt-coffeelint" : "latest", | ||
"grunt": "~0.4.0" | ||
}, | ||
"peerDependencies": { | ||
"grunt": "~0.4.0" | ||
}, | ||
"dependencies": { | ||
"websocket": "~1.0.8", | ||
"portscanner": "~0.1.3", | ||
"connect": "latest" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = (grunt) -> | ||
|
||
grunt.registerTask('gui', 'Launch a GUI web interface', () -> | ||
@async() | ||
peonWebSocket = require "../lib/peon-web-socket" | ||
new peonWebSocket().startWorker() | ||
|
||
) | ||
|
Oops, something went wrong.