more refactoring of webide
This commit is contained in:
parent
524b3b8401
commit
427536debb
12 changed files with 105 additions and 70 deletions
0
combined.log
Normal file
0
combined.log
Normal file
|
|
@ -43,7 +43,6 @@ exports.editor = function(ws, req) {
|
|||
case 'self-check-request':
|
||||
winston.debug('self-check-request');
|
||||
editor_setup.health_check(ws);
|
||||
winston.debug('here');
|
||||
break;
|
||||
case 'git-delete':
|
||||
git_helper.remove_commit_push(data.file, ws.request.session, function(err, status) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
var path = require('path'),
|
||||
Datastore = require('nedb'),
|
||||
db = new Datastore({ filename: path.resolve(process.env.PWD, 'db/webide_data_store'), autoload: true }),
|
||||
db = require('../models/webideModel'),
|
||||
scripts_helper = require('../helpers/scripts_helper'),
|
||||
config = require('../config/config'),
|
||||
check = require('validator').check,
|
||||
|
|
|
|||
0
error.log
Normal file
0
error.log
Normal file
|
|
@ -1,29 +1,23 @@
|
|||
var path = require('path'),
|
||||
Datastore = require('nedb'),
|
||||
winston = require('winston'),
|
||||
db = new Datastore({ filename: path.resolve(process.env.PWD, 'db/webide_data_store'), autoload: true }),
|
||||
db = require('../models/webideModel'),
|
||||
exec = require('child_process').exec,
|
||||
fs = require ('fs'),
|
||||
git_helper = require('./git_helper'),
|
||||
git_helper = require('./git_helper.js'),
|
||||
fs_helper = require('./fs_helper'),
|
||||
request_helper = require('./request_helper'),
|
||||
ws_helper = require('./websocket_helper'),
|
||||
config = require('../config/config');
|
||||
|
||||
fs.exists || (fs.exists = path.exists);
|
||||
|
||||
exports.setup_github = function(socket) {
|
||||
git_helper.set_config(function() {
|
||||
this.setup_adafruit_libraries(socket);
|
||||
});
|
||||
};
|
||||
|
||||
exports.setup_adafruit_libraries = function(socket) {
|
||||
exports.setup_adafruit_libraries = function(ws) {
|
||||
git_helper.clone_adafruit_libraries(config.adafruit.repository, config.adafruit.remote, function(cloned_libraries) {
|
||||
socket.emit("self-check-message", "Cloning remote Adafruit repository");
|
||||
ws_helper.send_message(ws, "self-check-message", "Cloning remote Adafruit repository");
|
||||
//cloned_libraries is false if they already existed...if false, let's pull the latest version of the adafruit libraries
|
||||
if (!cloned_libraries) {
|
||||
git_helper.pull(config.adafruit.repository, "origin", "master", function() {
|
||||
socket.emit("self-check-message", "Adafruit repository updated");
|
||||
ws_helper.send_message(ws, "self-check-message", "Adafruit repository updated");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -38,8 +32,40 @@ var path = require('path'),
|
|||
settings = {offline: true};
|
||||
}
|
||||
winston.debug("getting settings", settings);
|
||||
ws.send(JSON.stringify({type: "self-check-settings", data: settings}));
|
||||
ws_helper.send_message(ws, "self-check-settings", settings);
|
||||
})
|
||||
winston.debug('self-check-complete');
|
||||
ws.send(JSON.stringify({type: 'self-check-complete', data: true}));
|
||||
|
||||
this.setup_adafruit_libraries(ws);
|
||||
|
||||
git_helper.set_config(function() {
|
||||
var my_repository = "my-pi-projects";
|
||||
fs_helper.check_for_repository(my_repository, function(err, exists) {
|
||||
ws_helper.send_message(ws, "self-check-message", "Validated my-pi-projects");
|
||||
winston.debug(exists);
|
||||
if (exists) {
|
||||
git_helper.pull(my_repository, "origin", "master", function(err, status) {
|
||||
ws_helper.send_message(ws, "self-check-message", "Updated my-pi-projects");
|
||||
ws_helper.send_message(ws, 'self-check-complete');
|
||||
});
|
||||
} else {
|
||||
git_helper.create_local_repository(my_repository, function(err, response) {
|
||||
ws_helper.send_message(ws, "self-check-message", "Cloned my-pi-projects on local system");
|
||||
fs_helper.create_project_gitignore(function(err, file) {
|
||||
ws_helper.send_message(ws, "self-check-message", "Added .gitignore in my-pi-projects");
|
||||
fs_helper.create_project_readme(function(err, file) {
|
||||
ws_helper.send_message(ws, "self-check-message", "Added README.md in my-pi-projects");
|
||||
winston.debug(file);
|
||||
if (err) winston.error(err);
|
||||
|
||||
git_helper.commit_push_and_save(file, "Added README.md and .gitignore", null, function(err, response) {
|
||||
ws_helper.send_message(ws, "self-check-message", "Pushed changes to my-pi-projects");
|
||||
ws_helper.send_message(ws, 'self-check-complete');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
winston.debug("after everything");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
var path = require('path'),
|
||||
Datastore = require('nedb'),
|
||||
db = new Datastore({ filename: path.resolve(process.env.PWD, 'db/webide_data_store'), autoload: true }),
|
||||
db = require('../models/webideModel'),
|
||||
git = require('gitty'),
|
||||
url = require('url'),
|
||||
winston = require('winston'),
|
||||
|
|
@ -16,7 +15,7 @@ var push_queue = [], pushInterval, PUSH_TIMER = 30000;
|
|||
* The queue is currently set using the PUSH_TIMER to delay the remote pushes.
|
||||
*/
|
||||
function push_queue_interval() {
|
||||
console.log('git push queue init');
|
||||
winston.debug('git push queue init');
|
||||
function push(repository_path, remote, branch, username) {
|
||||
git.push(repository_path, remote, branch, function(obj) {
|
||||
require('../server').get_socket(username, function(socket) {
|
||||
|
|
@ -24,7 +23,7 @@ function push_queue_interval() {
|
|||
winston.error(obj);
|
||||
socket.emit('git-push-error', {err: "Error: Failure pushing code to remote repository"});
|
||||
}
|
||||
//console.log(obj);
|
||||
//winston.debug(obj);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -35,7 +34,7 @@ function push_queue_interval() {
|
|||
}
|
||||
|
||||
while(push_queue.length > 0) {
|
||||
console.log('pushing code to remote repository');
|
||||
winston.debug('pushing code to remote repository');
|
||||
var element = push_queue.shift();
|
||||
push(element.repository_path, element.remote, element.branch, element.username);
|
||||
}
|
||||
|
|
@ -51,7 +50,7 @@ exports.clone_adafruit_libraries = function(adafruit_repository, remote, cb) {
|
|||
fs_helper.check_for_repository(adafruit_repository, function(err, status) {
|
||||
if (!err && !status) {
|
||||
git.clone(REPOSITORY_PATH, remote, function(output) {
|
||||
console.log(output);
|
||||
winston.debug(output);
|
||||
cb(true);
|
||||
});
|
||||
} else {
|
||||
|
|
@ -75,26 +74,32 @@ exports.clone_update_remote_push = function(profile, repository_url, retain_remo
|
|||
var repository_name = path.basename(repository_url, '.git');
|
||||
|
||||
self.clone_repository(repository_url, function(err, results) {
|
||||
console.log("clone repository locally: " + repository_name);
|
||||
winston.debug("clone repository locally: " + repository_name);
|
||||
cb(err, true);
|
||||
});
|
||||
};
|
||||
|
||||
exports.clone_repository = function(repository_path, cb) {
|
||||
console.log(repository_path);
|
||||
winston.debug("clone_repository", repository_path);
|
||||
var repository_url = url.parse(repository_path);
|
||||
|
||||
console.log("cloning", repository_path);
|
||||
winston.debug("cloning", repository_path);
|
||||
git.clone(REPOSITORY_PATH, repository_url.href, function(output) {
|
||||
cb(output.error, output.message);
|
||||
});
|
||||
};
|
||||
|
||||
exports.create_local_repository = function(name, cb) {
|
||||
winston.debug("create_repository", name);
|
||||
git.create(name, "", REPOSITORY_PATH, function(output) {
|
||||
cb(output.error, output.message);
|
||||
});
|
||||
};
|
||||
|
||||
exports.validate_config = function validate_config(cb) {
|
||||
git.config("user.email", null, function(err, email) {
|
||||
git.config("user.name", null, function(err, name) {
|
||||
if (err) winston.error("git_helper.validate_config err", err);
|
||||
|
||||
if (name && email) {
|
||||
cb(true);
|
||||
} else {
|
||||
|
|
@ -108,15 +113,15 @@ exports.set_config = function(cb) {
|
|||
var self = this;
|
||||
self.validate_config(function(is_valid) {
|
||||
if (is_valid) {
|
||||
console.log('git config is valid');
|
||||
winston.debug('git config is valid');
|
||||
cb();
|
||||
} else {
|
||||
winston.error('git config is invalid');
|
||||
db.findOne({type: "user"}, function (err, user) {
|
||||
console.log("set_config user", user);
|
||||
winston.debug("set_config user", user);
|
||||
git.config("user.email", user.email, function(err, email) {
|
||||
git.config("user.name", user.name, function(err, name) {
|
||||
console.log("git config set", email, name);
|
||||
winston.debug("git config set", email, name);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
|
@ -132,7 +137,7 @@ exports.set_config = function(cb) {
|
|||
exports.update_remote = function(profile, repository, cb) {
|
||||
var remote_url = "ssh://git@bitbucket.org/" + profile.username + "/" + repository.toLowerCase() + ".git";
|
||||
git.remote.update(REPOSITORY_PATH + repository, "origin", remote_url, function(output) {
|
||||
//console.log(output);
|
||||
//winston.debug(output);
|
||||
cb(output.error, output.message);
|
||||
});
|
||||
};
|
||||
|
|
@ -142,7 +147,7 @@ exports.update_remote = function(profile, repository, cb) {
|
|||
*/
|
||||
exports.add_remote = function(repository, remote_name, remote_url, cb) {
|
||||
git.remote.add(REPOSITORY_PATH + repository, remote_name, remote_url, function(output) {
|
||||
//console.log(output);
|
||||
//winston.debug(output);
|
||||
cb(output.error, output.message);
|
||||
});
|
||||
};
|
||||
|
|
@ -158,8 +163,8 @@ exports.add = function add(repository, files, cb) {
|
|||
}
|
||||
var repository_path = REPOSITORY_PATH + repository;
|
||||
git.add(repository_path, files, function(output) {
|
||||
//console.log(output.errors);
|
||||
//console.log(output);
|
||||
//winston.debug(output.errors);
|
||||
//winston.debug(output);
|
||||
cb(output.errors, output.added);
|
||||
});
|
||||
};
|
||||
|
|
@ -175,7 +180,7 @@ exports.remove = function remove(repository, files, cb) {
|
|||
}
|
||||
var repository_path = REPOSITORY_PATH + repository;
|
||||
git.remove(repository_path, files, function(output) {
|
||||
//console.log(output.errors);
|
||||
//winston.debug(output.errors);
|
||||
cb(output.errors, output.added);
|
||||
});
|
||||
};
|
||||
|
|
@ -189,7 +194,7 @@ exports.remove_recursive = function remove_recursive(repository, path, cb) {
|
|||
var repository_path = REPOSITORY_PATH + repository;
|
||||
|
||||
git.remove_recursive(repository_path, path, function(output) {
|
||||
console.log(output);
|
||||
winston.debug(output);
|
||||
cb(output.errors, output.added);
|
||||
});
|
||||
};
|
||||
|
|
@ -201,7 +206,7 @@ exports.remove_recursive = function remove_recursive(repository, path, cb) {
|
|||
exports.move = function move(repository, source, destination, cb) {
|
||||
var repository_path = REPOSITORY_PATH + repository;
|
||||
git.move(repository_path, source, destination, function(obj) {
|
||||
//console.log(obj);
|
||||
//winston.debug(obj);
|
||||
cb(obj.error, obj.message);
|
||||
});
|
||||
};
|
||||
|
|
@ -213,9 +218,9 @@ exports.move = function move(repository, source, destination, cb) {
|
|||
*/
|
||||
exports.commit = function commit(repository, message, cb) {
|
||||
var repository_path = REPOSITORY_PATH + repository;
|
||||
console.log(repository_path);
|
||||
winston.debug(repository_path);
|
||||
git.commit(repository_path, message, function(obj) {
|
||||
//console.log(obj);
|
||||
//winston.debug(obj);
|
||||
cb(obj.error, obj.message);
|
||||
});
|
||||
};
|
||||
|
|
@ -233,7 +238,7 @@ exports.is_modified = function (file, cb) {
|
|||
var is_modified = false;
|
||||
git.status(repository_path, function(output) {
|
||||
|
||||
console.log(output);
|
||||
winston.debug(output);
|
||||
|
||||
if (output.not_staged.length > 0) {
|
||||
output.not_staged.forEach(function(item, index) {
|
||||
|
|
@ -261,12 +266,12 @@ exports.is_untracked = function (file, cb) {
|
|||
var repository_path = path.resolve(REPOSITORY_PATH, repository);
|
||||
var item_path = path_array.slice(3).join('/');
|
||||
|
||||
console.log(item_path);
|
||||
winston.debug(item_path);
|
||||
|
||||
var is_untracked = false;
|
||||
git.status(repository_path, function(output) {
|
||||
|
||||
console.log(output);
|
||||
winston.debug(output);
|
||||
|
||||
if (output.untracked.indexOf(item_path) !== -1) {
|
||||
is_untracked = true;
|
||||
|
|
@ -283,7 +288,7 @@ exports.is_untracked = function (file, cb) {
|
|||
exports.push = function push(repository, remote, branch, profile, cb) {
|
||||
var repository_path = REPOSITORY_PATH + repository;
|
||||
var key = repository + remote + branch;
|
||||
console.log('called push ' + key);
|
||||
winston.debug('called push ' + key);
|
||||
|
||||
//if the repository, remote and branch are already on the queue, just skip it...otherwise add it to the end
|
||||
if (push_queue.length > 0) {
|
||||
|
|
@ -291,7 +296,7 @@ exports.push = function push(repository, remote, branch, profile, cb) {
|
|||
if (push_queue[i].key === key) {
|
||||
break;
|
||||
} else {
|
||||
console.log('added to queue ' + key);
|
||||
winston.debug('added to queue ' + key);
|
||||
push_queue.push({
|
||||
key: key,
|
||||
repository_path: repository_path,
|
||||
|
|
@ -322,7 +327,7 @@ exports.push = function push(repository, remote, branch, profile, cb) {
|
|||
exports.pull = function pull(repository, remote, branch, cb) {
|
||||
var repository_path = REPOSITORY_PATH + repository;
|
||||
git.pull(repository_path, remote, branch, function(obj) {
|
||||
//console.log(obj);
|
||||
//winston.debug(obj);
|
||||
if (obj.error) {
|
||||
winston.error(obj.error);
|
||||
cb("Error: Failure updating from remote repository", obj.message);
|
||||
|
|
@ -338,12 +343,12 @@ exports.pull = function pull(repository, remote, branch, cb) {
|
|||
*/
|
||||
exports.remove_commit_push = function(item, profile, cb) {
|
||||
var self = this;
|
||||
console.log(item);
|
||||
winston.debug(item);
|
||||
var path_array = item.path.split('/');
|
||||
var repository = path_array[2];
|
||||
var item_path = path_array.slice(3).join('/');
|
||||
console.log(item_path);
|
||||
console.log(repository);
|
||||
winston.debug(item_path);
|
||||
winston.debug(repository);
|
||||
|
||||
|
||||
if (item.type === 'directory') {
|
||||
|
|
@ -405,18 +410,18 @@ exports.move_commit_push = function(item, profile, cb) {
|
|||
self.move(repository, item_path, destination_path, function(err, status) {
|
||||
var commit_message = "Moved " + item.name;
|
||||
if (err) {
|
||||
console.log ("has error returning");
|
||||
winston.debug ("has error returning");
|
||||
cb("Error: Failure moving file (renaming)");
|
||||
return;
|
||||
}
|
||||
self.commit(repository, commit_message, function(err, status) {
|
||||
console.log("Committed Moved File");
|
||||
winston.debug("Committed Moved File");
|
||||
if (err) {
|
||||
cb("Error: Failure comitting file into git");
|
||||
return;
|
||||
}
|
||||
self.push(repository, "origin", "master", profile, function() {
|
||||
console.log("Pushed latest changes");
|
||||
winston.debug("Pushed latest changes");
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
|
@ -441,24 +446,24 @@ exports.commit_push_and_save = function(file, commit_message, profile, cb) {
|
|||
file_path = file.path;
|
||||
}
|
||||
|
||||
console.log(commit_message);
|
||||
winston.debug(commit_message);
|
||||
|
||||
|
||||
|
||||
self.add(repository, file_path, function(err, status) {
|
||||
console.log("added", err, status);
|
||||
winston.debug("added", err, status);
|
||||
if (err && err.length > 0) {
|
||||
cb("Error: Failure adding file to git", status);
|
||||
return;
|
||||
}
|
||||
self.commit(repository, commit_message, function(err, status) {
|
||||
console.log("committed", err, status);
|
||||
winston.debug("committed", err, status);
|
||||
if (err && err.length > 0) {
|
||||
cb("Error: Failure comitting file into git", status);
|
||||
return;
|
||||
}
|
||||
self.push(repository, "origin", "master", profile, function() {
|
||||
console.log("added to push queue");
|
||||
winston.debug("added to push queue");
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
var path = require('path'),
|
||||
Datastore = require('nedb'),
|
||||
db = new Datastore({ filename: path.resolve(process.env.PWD, 'db/webide_data_store'), autoload: true }),
|
||||
db = require('../models/webideModel'),
|
||||
exec = require('child_process').exec,
|
||||
fs = require ('fs'),
|
||||
winston = require('winston'),
|
||||
|
|
|
|||
3
helpers/websocket_helper.js
Normal file
3
helpers/websocket_helper.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
exports.send_message = function send_message(ws, type, data) {
|
||||
ws.send(JSON.stringify({type: type, data: data}));
|
||||
}
|
||||
11
models/webideModel.js
Normal file
11
models/webideModel.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
var Datastore = require('nedb'),
|
||||
path = require('path');
|
||||
|
||||
var webideDb = new Datastore({
|
||||
filename: path.resolve(process.env.PWD, 'db/webide_data_store'),
|
||||
autoload: true
|
||||
});
|
||||
|
||||
module.exports = webideDb;
|
||||
0
output.log
Normal file
0
output.log
Normal file
|
|
@ -20,8 +20,8 @@
|
|||
"pug": "^2.0.0-rc.4",
|
||||
"request": "2.14.0",
|
||||
"serve-static": "^1.13.1",
|
||||
"validator": "0.4.25",
|
||||
"winston": "0.6.2",
|
||||
"validator": "9.4.0",
|
||||
"winston": "^2.4.0",
|
||||
"xterm": "3.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
server.js
13
server.js
|
|
@ -17,7 +17,6 @@ var express = require('express'),
|
|||
path = require('path'),
|
||||
updater = require('./helpers/updater'),
|
||||
scheduler = require('./helpers/scheduler'),
|
||||
git_helper = require('./helpers/git_helper'),
|
||||
exec_helper = require('./helpers/exec_helper'),
|
||||
fs_helper = require('./helpers/fs_helper'),
|
||||
exec_helper = require('./helpers/exec_helper'),
|
||||
|
|
@ -25,14 +24,14 @@ var express = require('express'),
|
|||
debug_helper = require('./helpers/python/debug_helper'),
|
||||
config = require('./config/config'),
|
||||
winston = require('winston'),
|
||||
Datastore = require('nedb'),
|
||||
db = require('./models/webideModel'),
|
||||
pty = require('node-pty');
|
||||
|
||||
var davServer,
|
||||
HOSTNAME,
|
||||
REPOSITORY_PATH = path.resolve(__dirname + "/repositories");
|
||||
|
||||
winston.info("REPOSITORY_PATH", REPOSITORY_PATH);
|
||||
|
||||
|
||||
var terminals = {}, logs = {};
|
||||
|
||||
|
|
@ -51,7 +50,7 @@ if (!exists) {
|
|||
//winston.remove(winston.transports.Console);
|
||||
|
||||
|
||||
var db = new Datastore({ filename: './database/webide_data_store', autoload: true });
|
||||
winston.info("REPOSITORY_PATH", REPOSITORY_PATH);
|
||||
|
||||
//redirect anything with /filesystem in the url to the WebDav server.
|
||||
app.use(function(req, res, next) {
|
||||
|
|
@ -252,9 +251,3 @@ process.on('SIGINT', function() {
|
|||
});
|
||||
process.exit();
|
||||
});
|
||||
|
||||
process.on('uncaughtException', function(err) {
|
||||
debug_helper.kill_debug(false, function() {
|
||||
//no need to wait for this
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue