forked from mschmidt712/kubernetes-ci-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
executable file
·84 lines (63 loc) · 2.29 KB
/
start.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
#!/usr/bin/node
YAML = require('yamljs');
var inquirer = require('inquirer');
var Rx = require('rx');
const execSync = require('child_process').execSync;
var environment = process.env;
var config = {
maxBuffer: 10000 * 1024,
env: environment
};
var fs = require('fs');
var markdown = "# Kubernetes ci/cd whitepaper for Linux.com\n\n This readme is dynamically generated when the interactive tutorial is run";
markdown = markdown + "## Interactive tutorial version\n\n"
markdown = markdown + "* clone this repo\n"
markdown = markdown + "* Ensure you are starting with a clean slate: `minikube delete; minikube rm -rf ~/.minikube; rm -rf ~/.kube`\n"
markdown = markdown + "* run `npm install`\n"
markdown = markdown + "Begin the tutorial `npm start`"
var prompts = new Rx.Subject();
var stepIndex = 1;
var commands = [];
inquirer.prompt(prompts).ui.process.subscribe(
function (answers) {
answerIndex = answers.name*1
answerIndex = answerIndex - 1;
// //answerIndex--;
//console.log("answerIndex " + answerIndex)
cmd = commands[answerIndex];
//console.log("command is " + cmd);
execSync(cmd, {stdio:[0,1,2], env: environment})
},
function(err){
console.log('error')
},
function(message){
console.log('complete')
fs.writeFile("README.md", markdown, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
);
prompts.onNext({type: 'confirm',name: "Begin", message: "Welcome to the Linux.com interactive Kubernetes tutorial by Kenzan. Press enter to begin\n", default: true});
YAML.load('steps.yml', function(docs)
{
docList = docs.parts;
var parts = docs.parts;
parts.forEach(function (item) {
markdown = markdown + "## " + item.name + "\n"
var part = item.name;
var stepNum = 0;
var stepList = item.steps;
// console.log(item.steps);
stepList.forEach(function (step) {
stepNum++;
commands.push(step.com)
prompts.onNext({type: 'confirm',name: stepIndex, message: "\n \n \n" + part + " Step: " + stepNum + "\n" + step.cap + "\n \n" + step.com + "\n \nPress enter to the run the above command for the step.", default: true});
stepIndex++;
})
})
prompts.onCompleted();
});