-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·88 lines (80 loc) · 3.03 KB
/
index.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
#!/usr/bin/env node
const fetch = require("node-fetch");
const prompt = require('prompt-sync')();
var shell = require('shelljs');
const readline = require('readline');
const chalk = require('chalk');
var Git = require("nodegit");
// console.log(process.argv);
const firstArgument = process.argv[2];
const secondArgument = process.argv[3];
const currentUser = shell.exec('whoami');
// let answers;
//
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });
//
// console.log("ini answer : ", answers)
switch (firstArgument){
case "clone" :
const gitUrlValidatePattern = /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/;
const isValidGitUrl = gitUrlValidatePattern.test(secondArgument)
if(isValidGitUrl){
// Git.Clone(secondArgument, `./${currentUser}/` + secondArgument.split('/').pop().split('.')[0])
// // Look up this known commit.
// .then(function(repo) {
// // Use a known commit sha from this repository.
// console.log("| Ini repo : ", repo)
// return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5");
// })
// // Look up a specific file within that commit.
// .then(function(commit) {
// return commit.getEntry("README.md");
// })
// // Get the blob contents from the file.
// .then(function(entry) {
// // Patch the blob to contain a reference to the entry.
// return entry.getBlob().then(function(blob) {
// blob.entry = entry;
// return blob;
// });
// })
// // Display information about the blob.
// .then(function(blob) {
// // Show the path, sha, and filesize in bytes.
// console.log(blob.entry.path() + blob.entry.sha() + blob.rawsize() + "b");
//
// // Show a spacer.
// console.log(Array(72).join("=") + "\n\n");
//
// // Show the entire file.
// console.log(String(blob));
// })
// .catch(function(err) { console.log(err); });
let arrCommand = [];
const time = prompt('How much time you need to automating deployment on this git..? [e.g: 60s - minimum 1s] : ');
console.log("What command you usually to build & running this git..? [this support multiple command just add '\\' on the end of command]")
const commands = prompt("[Command - 1] : ");
arrCommand.push(commands)
console.log("Ini commnad : ", commands)
if(commands[commands.length - 1] === "\\"){
let isTimetoStopLoop = false;
let totalCommand = 2;
while ( !isTimetoStopLoop ){
let ask = prompt(`[Command - ${totalCommand}] : `);
arrCommand.push(ask);
totalCommand++
ask[ask.length - 1] === "\\" ? isTimetoStopLoop = false : isTimetoStopLoop = true
}
}
console.log(arrCommand)
} else {
console.log("It's look like wrong git url");
}
break;
default :
// console.log("Not found");
break;
}/**/