Skip to content

Commit

Permalink
Merge pull request #2 from chrisdobler/master
Browse files Browse the repository at this point in the history
Various Updates
  • Loading branch information
chrisdobler committed Aug 25, 2017
2 parents b70d31a + c69f464 commit b9d5446
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 43 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Nebulis Coding Analytics Endpoint · ![TravisCI Status](https://img.shields.io/travis/NebulisAnalytics/nebulis-endpoint.svg) [![Coverage Status](https://coveralls.io/repos/github/NebulisAnalytics/nebulis-endpoint/badge.svg?branch=master)](https://coveralls.io/github/NebulisAnalytics/nebulis-endpoint?branch=master) [![Known Vulnerabilities](https://snyk.io/test/github/NebulisAnalytics/nebulis-endpoint/badge.svg)](https://snyk.io/test/github/NebulisAnalytics/nebulis-endpoint)
# Nebulis Coding Analytics Endpoint
![TravisCI Status](https://img.shields.io/travis/NebulisAnalytics/nebulis-server.svg) ![Coverage Status](https://coveralls.io/repos/github/NebulisAnalytics/nebulis-server/badge.svg?branch=master) [![Known Vulnerabilities](https://snyk.io/test/github/NebulisAnalytics/nebulis-endpoint/badge.svg)](https://snyk.io/test/github/NebulisAnalytics/nebulis-endpoint) [![npm version](https://badge.fury.io/js/nebulis-endpoint.svg)](https://badge.fury.io/js/nebulis-endpoint)

This is the endpoint for tracking Nebulis coding projects.

Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=5.0"
},
"version": "0.2.4",
"version": "0.4.1",
"description": "Endpoint for Nebulis code monitoring",
"main": "index.js",
"scripts": {
Expand All @@ -19,8 +19,11 @@
"Kyle Sherwood"
],
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.9.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.25.0",
"babel-helpers": "^6.24.1",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.5.0",
"chai": "3.5.0",
"chai-as-promised": "5.3.0",
Expand All @@ -32,10 +35,7 @@
"mocha": "^3.5.0"
},
"dependencies": {
"babel-core": "^6.25.0",
"babel-helpers": "^6.24.1",
"babel-polyfill": "^6.23.0",
"colors": "^1.1.2",
"nodemon": "^1.11.0"
"node-watch": "^0.5.5"
}
}
20 changes: 6 additions & 14 deletions src/connect.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import fs from 'fs';
import main from './main'
import {receivedDetails} from './main'
var http = require('http');

const connect = {
init: (config) => {
init: (config, cb) => {
const options = {
host: config.server,
port: config.port,
path: '/api/endpoints/establish',
method: 'POST',
};

var req = http.request(options, function(res) {
let body = '';
// console.log('STATUS: ' + res.statusCode);
Expand All @@ -25,27 +25,19 @@ const connect = {
config.remote = JSON.parse(body).remote;
if(id !== undefined) {
console.log('Endpoint ID: ' + id);
main();
cb();
} else {
console.log('Endpoint Error');
}
})
});
});

req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});

// write data to request body
let str = fs.readFileSync('./.git/config').toString();
str = str.substring(str.indexOf('git@github.com:')+15, str.indexOf('.git'))
const gitConfig = str.split('/');

config.owner = gitConfig[0];
config.project = gitConfig[1],

req.write(JSON.stringify({
owner: config.owner,
owners: config.owners,
project: config.project,
}));
req.end();
Expand Down
63 changes: 63 additions & 0 deletions src/getDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {receivedDetails} from './main'

const readline = require('readline');

const prompter = (sayStuff, processIn, defaultAnswer) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question(sayStuff, (answer) => {
rl.close();
if (answer.length < 1 && defaultAnswer) processIn(defaultAnswer);
else if (answer.length < 1) prompter(sayStuff, processIn, defaultAnswer);
else processIn(answer);
});
};

const config = require(process.cwd() + '/.nebulis.json');
const out = process.stdout;

const getDetails = (GitName, project) => {
config.owners = [];
config.project = project;

const owner = {};

out.write('\nWelcome to Nebulis Analytics 🔥\n');

prompter('\nPlease enter your full name [ex: John Doe]:', (res) => {
owner.fullName = res
prompter('\nWe have detected your github username is ' + GitName + '\nPress enter to confirm [' + GitName + ']:', (res) => {
owner.username = res;
config.owners.push(owner);
checkForNextMember();
}, GitName);
});
};
const checkForNextMember = () => {
prompter('\nDo you have any additional team members? [Y/n]:', (res) => {
if (res === 'Y') {
getNextMember();
} else if (res === 'n') exit();
else checkForNextMember();
});
}

const getNextMember = () => {
const owner = {};
prompter('\nWhat is your team members full name? []:', (res) => {
owner.fullName = res
prompter('\nWhat is your team members github username? []:', (res) => {
owner.username = res;
config.owners.push(owner);
checkForNextMember();
});
});
};

const exit = () => {
receivedDetails(config);
}

export { getDetails as default };
18 changes: 10 additions & 8 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,33 @@ const git = {
return [
handler(spawn('git', [GIT_DIR, WORK_TREE, 'init']), false, false),
handler(spawn('git', [GIT_DIR, WORK_TREE, 'remote', 'add', 'origin', remote]), false, false),
handler(spawn('git', [GIT_DIR, WORK_TREE, 'config', 'core.autocrlf', 'false']), false, false),
// handler(spawn('git', [GIT_DIR, WORK_TREE, 'checkout', '-b', 'nebutrack']), false, false),
];
},
status: () => {
out.write('Checking Storage... ');
status: () => {
out.write('Checking Storage... ');
return handler(spawn('git', [GIT_DIR, WORK_TREE, 'status']), false, false); },
stage: () => {
out.write('Preparing Stage... ');
return handler(spawn('git', [GIT_DIR, WORK_TREE, 'add', '.']));
},
commit: (verbose = false, errors = false) => {
out.write('Checking for changes... ');
out.write('Checking for changes... ');
return handler(spawn('git', [GIT_DIR, WORK_TREE, 'commit', '-m', Date()]), verbose, errors);
},
push: () => {
out.write('Syncing endpoint to server... ');
return handler(spawn('git', [GIT_DIR, WORK_TREE, 'push', '--set-upstream', 'origin', 'nebutrack']));
}
out.write('Syncing endpoint to server... ');
return handler(spawn('git', [GIT_DIR, WORK_TREE, 'push', '-f', '--all', 'origin']), true, true, true);
}
}

const handler = (proc, verbose = false, errors = true) => {
const handler = (proc, verbose = false, errors = true, grace = false) => {
if (proc.stderr.length < 1 || errors === false) {
verbose ? out.write(` ${'[DONE]\n'.magenta} ${proc.stdout.toString().red}`) : out.write(' [DONE]\n'.magenta);
} else {
if(errors) outErr.write(`${'[ERROR]'.red} output: "${proc.stderr}"`);
if (errors && !grace) outErr.write(`${'[ERROR]'.red}\noutput: "${proc.stderr}"`);
else if (grace) out.write(`[DONE]\n${proc.stderr}`);
}
return proc;
}
Expand Down
71 changes: 58 additions & 13 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import fs from 'fs';
import colors from 'colors';
import messages from './messages';
import git from './git';
import getDetails from './getDetails';
import connect from './connect';
import watch from 'node-watch';

const logPath = `${__dirname}/../logs/api.log`;
const accessLogStream = fs.createWriteStream(logPath, { flags: 'a' });
Expand All @@ -15,27 +17,56 @@ console.log(process.cwd());

messages.logo();

try {
config = require(process.cwd() + `/.nebulis.json`);
if (!config.server || !config.port) { throw 'error'; }
//////////////////////////////////
// The order:
// 1. check if project has .nebulis server details
// 2. check if the repo is initiated.
// a. try to extract git config data for the github user
// b. check to see if we have .nebulis user details
// I. prompt for user to enter details
// II. init the local repo
//

connect.init(config);
} catch (err) {
out.write('Welcome to Nebulis. To get started please insert a .nebulis.json file in your app directory, per the instructions.')
}

const main = () => {
out.write('\nNebulis endpoint is connected\n'.yellow);
const start = () => {
//TODO: detect if this is endpoint has user name info stored already.

if (git.status().stderr.toString().indexOf('Not a git repository') >= 0) {

out.write('[NEW ENDPOINT DETECTED]\n'.red);

//read configuration data from git config file
let str = fs.readFileSync('./.git/config').toString();
str = str.substring(str.indexOf('github.com')+11, str.indexOf('.git'));
const gitConfig = str.split('/');

// these are for reference
// config.owner = gitConfig[0];
// config.project = gitConfig[1];
getDetails(gitConfig[0], gitConfig[1]);

} else main();

}

const receivedDetails = (details) => {
connect.init(details, () => {
git.init(config.remote);
}
main();
});
}

const main = () => {

out.write('\nNebulis endpoint is connected\n'.yellow);

git.stage();
git.commit();

fs.watch(process.cwd(), function (event, filename) {
const filter = (name) => {
return !/\.nebugit|\.git|node_modules/.test(name);
};

watch(process.cwd(), { recursive: true, filter }, function(event, filename) {
if (filename) {
out.write('\nFile was modified: '.blue + filename.blue + '\n');
git.stage();
Expand All @@ -53,4 +84,18 @@ const main = () => {

}

export { main as default };
//1. check if project has .nebulis server details
try {
config = require(process.cwd() + `/.nebulis.json`);
if (!config.server || !config.port) { throw 'error'; }
else {
start();
}

} catch (err) {
console.log(err);

out.write('Welcome to Nebulis. To get started please insert a .nebulis.json file in your app directory, per the instructions.')
}

export { main, start, receivedDetails};

0 comments on commit b9d5446

Please sign in to comment.