-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_disector.js
88 lines (66 loc) · 2.37 KB
/
project_disector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var fs = require('fs');
const git = require('simple-git')();
var readline = require('readline-sync');
var count = 0
function errorlog(err, idk){
console.log(err);
console.log(idk);
}
var repo_link = readline.question("Enter the link to the repo\n");
console.log(repo_link);
repo_link = "https://github.com/codingandcommunity/disector_test_project.git";
var repo_path = readline.question("Where would you like this to be stored (type h or here for wrking dir)\n");
if(repo_path == 'here' || repo_path == 'h'){
repo_path = process.cwd() + "\\converted_repo";
}
console.log(repo_path);
function projectStatHandler(err, stat) {
//if the directory exists then create the directory and then the callback function clones the repo
if(err && err.code == "ENOENT"){
fs.mkdir(repo_path, errorlog);
console.log("made the Directory at " + repo_path);
gitstuff(repo_path);
}
//otherwise add one to project path and then check the path again
else{
console.log('Directory already exists.');
count = count + 1;
if(count > 1){
repo_path = repo_path.substr(0,repo_path.length-3);
}
repo_path = repo_path + "(" + count + ")";
return projectCheck();
}
}
//calls fs.stat which checks the status of a directory
function projectCheck(){
let promise = new Promise((resolve, reject) => {
fs.stat(repo_path, resolve);
}).then((err, stat) => {
projectStatHandler(err, stat)
});
return promise;
}
count = 0;
//the button code to find the correct project directory and clone it from github
let promise = projectCheck();
promise.then(
console.log("hi2") //git.cwd(repo_path).clone("https://github.com/codingandcommunity/test-curriculum.git").log(errorlog) )
);
function gitstuff(repo_path){
console.log("hi3");
//git.cwd(repo_path).clone("https://github.com/codingandcommunity/test-curriculum.git").log(errorlog);
git.cwd(repo_path, errorlog);
git.clone(repo_link);//.log(errorlog);
console.log("LOOK HERE");
console.log("repo link is " + repo_link);
console.log(repo_link.lastIndexOf("/"));
var clone_path = repo_path + "\\" + repo_link.substr(repo_link.lastIndexOf("/")+1,(repo_link.length));
clone_path = clone_path.substr(0,clone_path.length-4);
console.log("clone path is " + clone_path);
var log_output;
git.cwd(clone_path).log((err, log) => processLogOutput(log));
}
function processLogOutput(log){
console.log(log);
}