-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·215 lines (186 loc) · 5.5 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env node
var program = require('commander');
const http = require('http');
var Commands = require('./js/commands');
var Devices = require('./js/getDevices');
var Setup = require('./js/setup');
const hostname = '127.0.0.1';
const port = 3000;
var git = require("nodegit");
var mkdirp = require('mkdirp');
var ProgressBar = require('progress');
var pjson = require('./package.json');
var TestFeed = require('./js/testfeed');
var del = require('del');
var colors = require('colors/safe');
var inits = require('inits');
var express = require('express');
var open = require('opn');
var path = require('path');
var fs = require('fs');
var Update = require('./js/update');
var analytics = require('universal-analytics');
var visitor = analytics('UA-120621204-1');
var ip = require('ip');
inits.options.logTimes=false;
inits.options.showErrors=false;
inits.init(function(callback) {
new Setup().instDeps();
new Update().updateOptimus();
callback();
});
function createproject(args,callback) {
var projectfolder;
if(args.includes(" ")) {
projectfolder = args.replace(" ","");
} else {
projectfolder = args;
}
fs.stat(projectfolder, function(err,callback){
if(err) {
process.stdout.write(colors.magenta("creating project '"+projectfolder+"'.."));
mkdirp(projectfolder, function (err) {
if (err) console.error(err)
});
var projCreated;
var obj = git.Clone("https://github.com/testvagrant/optimusTemplate.git",projectfolder,{}).then(function (repo) {
del([projectfolder+"/.git"]);
del([projectfolder+"/docs"]);
projCreated = true;
console.log(colors.green("\nCreated project '"+projectfolder+"'"));
}).catch(function (err) {
console.log(err);
});
var bar = new ProgressBar('Estimated time to download :total, time elapsed so far :elapsed', {
complete: '=',
incomplete: ' ',
width: 20,
total: 20000
});
var iv = setInterval(function () {
if(projCreated===undefined) {
// bar.tick();
process.stdout.write(colors.magenta("."));
}
if (projCreated!=undefined) {
clearInterval(iv);
}
}, 350);
function progress() {
iv;
}
} else {
console.log(colors.red('Error: Project '+ projectfolder+' is already present in this directory. Create project with a different name.'));
}
});
visitor.pageview("createProject",projectfolder,ip.address()).send()
visitor.event(ip.address(),projectfolder).send()
}
function createtestfeed(args,callback) {
visitor.pageview("createtestfeed",ip.address()).send()
var app = express();
app.use(express.static(path.join(__dirname, 'web')))
app.listen(3000);
open('http://localhost:3000/testfeed.html');
}
function doctor(args,callback) {
visitor.pageview("doctor",ip.address()).send()
new Update().updateOptimus();
var commands = new Commands();
commands.verifyJava();
commands.verifyAppium();
commands.verifyMongoDB();
commands.verifyAPT();
commands.verifyXcode();
commands.verifyGradle();
}
function setup(args,callback) {
visitor.pageview("setup",ip.address()).send()
var commands = new Commands();
commands.installJava();
commands.installAppium();
commands.installMongoDB();
commands.installAPT();
commands.installFBSimctl();
commands.installGradle();
}
function getAndroidDevices(args,callback) {
visitor.pageview("getAndroidDevices",ip.address()).send()
var commands = new Devices();
commands.getAndroidDevices();
}
function getIOSDevices(args,callback) {
visitor.pageview("getiOSDevices",ip.address()).send()
var commands = new Devices();
commands.getIOSDevices();
}
function getAllConnectedDevices(args,callback) {
visitor.pageview("getAllConnectedDevices",ip.address()).send()
var commands = new Devices();
commands.getAllConnectedDevices();
}
function appVersion() {
visitor.pageview("appVersion",ip.address()).send()
console.log(pjson.version);
}
function track(args, callback) {
var projectfolder;
if(args.includes(" ")) {
projectfolder = args.replace(" ","");
} else {
projectfolder = args;
}
visitor.pageview("createProject",projectfolder,ip.address()).send()
visitor.event(ip.address(),projectfolder).send()
}
function help(){
program.outputHelp();
}
program
.command('new <project_name>')
.description('creates a new optimus project')
.action(createproject);
program
.command('testfeed')
.description('Create a testfeed for the project')
.action(createtestfeed);
program
.command('doctor')
.description('verifies the workspace for dependencies')
.action(doctor);
program
.command('setup')
.description('sets up the optimus environment')
.action(setup);
program
.command('version')
.description('displays the present optimus version')
.action(appVersion);
program
.option('')
.action(help);
program
.command('getandroiddevices')
.description('gets all the connected android devices')
.action(getAndroidDevices);
program
.command('getiosdevices')
.description('gets all the connected iOS devices')
.action(getIOSDevices);
program
.command('getallconnecteddevices')
.description('gets all the connected devices')
.action(getAllConnectedDevices);
program
.command('track')
.description('gets all the connected devices')
.action(track);
// program
// .command('getdevices')
// .description('')
// .action(getAllDevices)
program.parse(process.argv);
var NO_COMMAND_SPECIFIED = program.args.length === 0;
if (NO_COMMAND_SPECIFIED) {
program.help();
}