Skip to content

Commit 447682c

Browse files
committed
adding update warnings, output fix
1 parent 69df1c3 commit 447682c

File tree

7 files changed

+102
-65
lines changed

7 files changed

+102
-65
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ The Chrome extension is auto-updated. However the npm module has to be manually
5959

6060
## TODO
6161

62-
* Test Windows and Linux
62+
* Test Windows
6363
* registerMultiTask support
64+
* send tasks into background right away
6465

6566
### Release History
6667

68+
* 0.1.0.7 - Fixes, added update warnings.
6769
* 0.1.0.6 - Various fixes.
6870
* 0.1.0.5 - Updating UI, Adding a way to set flags `--force` and `--verbose`, output fixes, background task updates.
6971
* 0.1.0.4 - Adding Background Task support. You can now press `(B)` to send

extension/css/devtools.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ h2, label {
3535
#backgroundTasks, #killTask {
3636
display: none;
3737
}
38-
#backgroundTasks.show {
38+
#backgroundTasks.show, #updateWarning.show {
3939
display: block;
4040
}
4141

@@ -287,6 +287,22 @@ button {
287287
display: block;
288288
}
289289

290+
#updateWarning {
291+
display: none;
292+
position: absolute;
293+
bottom: 0;
294+
left: 0;
295+
border: 1px solid rgb(64%, 64%, 64%);
296+
border-left: none;
297+
border-bottom: none;
298+
background: -webkit-linear-gradient(top, #fefcea 0%,#f1da36 100%);
299+
font-size: 10px;
300+
}
301+
302+
#updateWarning p {
303+
padding: 0 10px;
304+
}
305+
290306
@media all and (max-width: 250px) {
291307
#output {
292308
display: none;

extension/js/devtools.js

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
'use strict';
22

3-
/**
4-
* Grunt project setting
5-
*/
3+
// Chrome extension
4+
var manifest = chrome.runtime.getManifest(),
5+
extVersion = manifest.version;
6+
7+
// Grunt project setting
68
var socket,
79
projects = [],
810
currentProject;
911

10-
/**
11-
* Port settings
12-
*/
12+
// Port settings
1313
var startPort = 61749,
1414
currentPort = startPort,
1515
maxPort = currentPort + 5;
1616

17-
/**
18-
* Templates
19-
*/
17+
// Templates
2018
var projectListTpl = _.template($("#projectList").html()),
2119
taskListTpl = _.template($("#taskList").html()),
2220
bgTasksTpl = _.template($("#bgTaskList").html());
2321

24-
/**
25-
* UI Selectors
26-
*/
22+
// UI Selectors
2723
var $output = $("#placeOutput"),
2824
$outputWrap = $('#output'),
2925
$body = $('body'),
@@ -32,7 +28,8 @@ var $output = $("#placeOutput"),
3228
$bgTasks = $('#placeBackgroundTasks'),
3329
$regularTasks = $('#placeTasks'),
3430
$aliasTasks = $('#placeAliasTasks'),
35-
$projects = $('#placeProjects');
31+
$projects = $('#placeProjects'),
32+
$warning = $('#updateWarning');
3633

3734
/**
3835
* Connect to a devtools socket
@@ -82,13 +79,14 @@ function handleSocketMessage(event) {
8279
// connecting a new project
8380
// add this new project
8481
projects.push({
85-
name:data.project,
86-
port:parseInt(data.port),
87-
socket:socket,
88-
taskListAlias:data.alias,
89-
taskListGeneric:data.tasks,
90-
tasks:[],
91-
running:false
82+
name: data.project,
83+
port: parseInt(data.port),
84+
socket: socket,
85+
taskListAlias: data.alias,
86+
taskListGeneric: data.tasks,
87+
tasks: [],
88+
running: false,
89+
devtoolsVersion: data.devtoolsVersion
9290
});
9391

9492
// add new project button
@@ -107,7 +105,7 @@ function handleSocketMessage(event) {
107105
}
108106
// process started
109107
else if (data && data.action === 'start') {
110-
currentProject.currentTask = {name:data.name, pid:data.pid, output:[]};
108+
currentProject.currentTask = {name: data.name, pid: data.pid, output: []};
111109
currentProject.tasks.push(currentProject.currentTask);
112110
updateTaskList();
113111
}
@@ -117,21 +115,25 @@ function handleSocketMessage(event) {
117115
$output.html('');
118116
} else if (data.length > 1) {
119117
if (currentProject.tasks.length > 0) {
120-
var msg = data.split("|");
121-
var pid = msg[0];
122-
var timestamp = new Date().toString().split(' ')[4];
123-
var output = '<pre>' + timestamp + ' - ' + msg[1] + '</pre>';
118+
var msg = data.split("|"),
119+
pid = msg[0],
120+
timestamp = new Date().toString().split(' ')[4],
121+
output = '<pre>' + timestamp + ' - ' + _.escape(msg[1]) + '</pre>';
122+
123+
// find a task with a process id of the message
124124
var pidTask = _.find(currentProject.tasks, function (task) {
125125
return task.pid === parseInt(pid);
126126
});
127+
128+
// if we found a task with a pid
127129
if (pidTask) {
128130
pidTask.output.push(output);
129131
}
130-
// append output
132+
133+
// append output to the current view if the process id matches
131134
if (currentProject.currentTask && parseInt(pid) === currentProject.currentTask.pid) {
132135
$output.append(output);
133-
// TODO: fix this
134-
$outputWrap.scrollTop(99999);
136+
$outputWrap.scrollTop($output.height());
135137
}
136138
}
137139
}
@@ -175,7 +177,7 @@ function handleSocketClose(e) {
175177
*/
176178
function handleSocketError() {
177179
// TODO: update this
178-
alert('Something went really wrong, please report this...');
180+
console.log('Something went really wrong, please report this...');
179181
}
180182

181183
function updateProjectList() {
@@ -185,8 +187,8 @@ function updateProjectList() {
185187

186188
function updateTaskList() {
187189
// set the tasks
188-
$regularTasks.html(taskListTpl({buttons:currentProject.taskListGeneric}));
189-
$aliasTasks.html(taskListTpl({buttons:currentProject.taskListAlias}));
190+
$regularTasks.html(taskListTpl({buttons: currentProject.taskListGeneric}));
191+
$aliasTasks.html(taskListTpl({buttons: currentProject.taskListAlias}));
190192

191193
if (currentProject.currentTask) {
192194
$('.task[value="' + currentProject.currentTask.name + '"]')
@@ -203,7 +205,7 @@ function updateTaskList() {
203205

204206
if (bgTasks.length > 0) {
205207
$bgSection.addClass('show');
206-
$bgTasks.html(bgTasksTpl({tasks:bgTasks}));
208+
$bgTasks.html(bgTasksTpl({tasks: bgTasks}));
207209
} else {
208210
$bgSection.removeClass('show');
209211
}
@@ -223,6 +225,14 @@ function setProject(idx) {
223225
var buttons = $projects.find('button');
224226
buttons.removeClass('active');
225227
$(buttons.get(idx)).addClass('active');
228+
console.log(currentProject.devtoolsVersion);
229+
// check version
230+
if (currentProject.devtoolsVersion == null || currentProject.devtoolsVersion.replace(/-/g, '.') !== extVersion) {
231+
$warning.addClass('show');
232+
} else {
233+
$warning.removeClass('show');
234+
}
235+
226236
// clear output
227237
if (currentProject && currentProject.currentTask) {
228238
$output.html(currentProject.currentTask.output);
@@ -304,16 +314,16 @@ $tasks.on('click', '.b-kill', function () {
304314

305315
// if there's a pid, use it instead
306316
if (btn.data('pid')) {
307-
taskInfo = {name:btn.val(), pid:btn.data('pid')};
317+
taskInfo = {name: btn.val(), pid: btn.data('pid')};
308318
// TODO: validate this?
309319
currentProject.tasks = _.reject(currentProject.tasks, function (task) {
310320
return task.pid === btn.data('pid');
311321
});
312322
updateTaskList();
313323
}
314324
currentProject.socket.send(JSON.stringify({
315-
action:'killTask',
316-
task:taskInfo
325+
action: 'killTask',
326+
task: taskInfo
317327
}));
318328
});
319329

extension/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Grunt Devtools",
3-
"version": "0.1.0.6",
3+
"version": "0.1.0.7",
44
"description": "Extends the Developer Tools, adding tools for Grunt",
55
"icons": {
66
"16": "img/icon16.png",

extension/panel.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ <h2>Projects</h2>
99
<div id='placeProjects'></div>
1010
</header>
1111
<div id='tools'>
12+
<aside id='updateWarning'>
13+
<p>
14+
The version of <code>grunt-devtools</code> does not match for this project.
15+
Please update using '<code>npm install grunt-devtools --save-dev</code>' or update the extension.
16+
</p>
17+
</aside>
1218
<section id='tasks'>
1319
<div id='backgroundTasks'>
1420
<header><h2>Background Tasks</h2></header>

grunt-plugin/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "grunt-devtools",
33
"description": "Experimental! Grunt integration with Chrome Dev Tools",
4-
"version": "0.1.0-6",
4+
"version": "0.1.0-7",
55
"homepage": "https://github.com/vladikoff/grunt-devtools",
66
"author": {
77
"name": "vladikoff",
@@ -33,15 +33,18 @@
3333
"grunt-contrib-clean": "~0.4.0",
3434
"grunt-contrib-nodeunit": "~0.1.2",
3535
"grunt": "~0.4.0",
36+
"grunt-contrib-watch": "~0.2.0",
3637
"grunt-contrib-connect": "~0.1.2"
3738
},
3839
"peerDependencies": {
3940
"grunt": "~0.4.0"
4041
},
41-
"keywords": [],
42+
"keywords": [
43+
"gruntplugin",
44+
"devtools"
45+
],
4246
"dependencies": {
4347
"websocket": "~1.0.8",
44-
"portscanner": "~0.1.3",
45-
"grunt-contrib-watch": "~0.2.0"
48+
"portscanner": "~0.1.3"
4649
}
4750
}

grunt-plugin/tasks/devtools.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@ module.exports = function (grunt) {
55
grunt.registerTask('devtools', 'Runs a server for devtools', function () {
66
this.async();
77
var WebSocketServer = require('websocket').server;
8-
var fs = require("fs");
9-
var spawn = require("child_process").spawn;
8+
9+
var fs = require("fs"),
10+
spawn = require("child_process").spawn,
11+
http = require('http'),
12+
portscanner = require('portscanner');
13+
1014
var workers = [];
11-
var http = require('http');
12-
var portscanner = require('portscanner');
1315

14-
var version = 0; // TODO
15-
var pjson = require('../package.json');
16-
if (pjson.version) {
16+
var pjson = require('../package.json'),
1717
version = pjson.version;
18-
}
1918

2019
// TODO: update this
21-
var projectPath = process.cwd().split('/');
22-
var projectName = projectPath[projectPath.length - 1];
23-
var aliasTasks = getAliasTasks();
24-
var allTasks = Object.keys(grunt.task._tasks);
25-
var basicTasks = grunt.util._.difference(allTasks, aliasTasks);
20+
var projectPath = process.cwd().split('/'),
21+
projectName = projectPath[projectPath.length - 1],
22+
aliasTasks = getAliasTasks(),
23+
allTasks = Object.keys(grunt.task._tasks),
24+
basicTasks = grunt.util._.difference(allTasks, aliasTasks);
2625

2726
var server = http.createServer(function (request, response) {
2827
response.writeHead(404);
@@ -43,8 +42,8 @@ module.exports = function (grunt) {
4342
});
4443

4544
var wsServer = new WebSocketServer({
46-
httpServer:server,
47-
autoAcceptConnections:false
45+
httpServer: server,
46+
autoAcceptConnections: false
4847
});
4948

5049
wsServer.on('request', function (request) {
@@ -72,20 +71,21 @@ module.exports = function (grunt) {
7271

7372
if (cmd[0] === 'handleSocketOpen') {
7473
connection.sendUTF(JSON.stringify({
75-
tasks:basicTasks,
76-
alias:aliasTasks,
77-
project:projectName,
78-
port:projectPort
74+
tasks: basicTasks,
75+
alias: aliasTasks,
76+
project: projectName,
77+
port: projectPort,
78+
devtoolsVersion: version
7979
}));
8080
}
8181
else if (allTasks.indexOf(cmd[0]) > -1) {
8282
var watcher = spawn('grunt', cmd);
8383
watcher.key = key;
8484
workers.push(watcher);
8585
connection.sendUTF(JSON.stringify({
86-
action:'start',
87-
name:cmd[0],
88-
pid:watcher.pid
86+
action: 'start',
87+
name: cmd[0],
88+
pid: watcher.pid
8989
}));
9090
// TODO: fix bug here with running task return
9191
connection.send('Running Task: ' + cmd[0]);
@@ -100,7 +100,7 @@ module.exports = function (grunt) {
100100
connection.send(watcher.pid + '|' + data.toString());
101101
grunt.log.writeln().write(data.toString());
102102
}
103-
connection.sendUTF(JSON.stringify({ action:'done', pid:watcher.pid }));
103+
connection.sendUTF(JSON.stringify({ action: 'done', pid: watcher.pid }));
104104
});
105105
watcher.stderr.on('data', function (data) {
106106
if (data) {

0 commit comments

Comments
 (0)