Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 9385c5b

Browse files
Changes to octorun to take usage data as a file path
1 parent ff65115 commit 9385c5b

File tree

3 files changed

+33
-35
lines changed

3 files changed

+33
-35
lines changed

octorun/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.env
2+
node_modules
23
npm-debug.log

octorun/src/bin/app-publish.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var ApiWrapper = require('../api')
44

55
commander
66
.version(package.version)
7-
.option('-r, --repository <value>')
8-
.option('-d, --description <value>')
9-
.option('-o, --organization <value>')
7+
.option('-r, --repository <repository>')
8+
.option('-d, --description <description>')
9+
.option('-o, --organization <organization>')
1010
.option('-p, --private')
1111
.parse(process.argv);
1212

octorun/src/bin/app-usage.js

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
var commander = require("commander");
22
var package = require('../../package.json')
33
var endOfLine = require('os').EOL;
4+
var fs = require('fs');
5+
var util = require('util');
6+
var https = require('https');
47

58
commander
69
.version(package.version)
10+
.option('-h, --host <host>')
11+
.option('-p, --port <port>')
712
.parse(process.argv);
813

9-
var processData = function (postData) {
10-
var https = require('https');
14+
var host = commander.host;
15+
var port = 443;
1116

17+
if (commander.port) {
18+
port = commander.port;
19+
}
20+
21+
var fileContents = null;
22+
if (commander.args.length == 1) {
23+
var filePath = commander.args[0];
24+
25+
if (fs.existsSync(filePath)) {
26+
fileContents = fs.readFileSync(filePath, 'utf8');
27+
}
28+
}
29+
30+
if (fileContents && host && util.isNumber(port)) {
1231
var options = {
13-
hostname: 'central.github.com',
32+
protocol: "https:",
33+
hostname: host,
34+
port: port,
1435
path: '/api/usage/unity',
1536
method: 'POST',
1637
headers: {
@@ -19,49 +40,25 @@ var processData = function (postData) {
1940
};
2041

2142
var req = https.request(options, function (res) {
22-
process.stdout.write('statusCode:', res.statusCode);
23-
2443
res.on('data', function (d) {
2544
process.stdout.write(d);
2645
process.stdout.write(endOfLine);
2746
});
2847

2948
res.on('end', function (d) {
30-
process.exit();
49+
process.exit(res.statusCode == 200 ? 0 : -1);
3150
});
3251
});
3352

3453
req.on('error', function (e) {
35-
console.error(e);
54+
console.log(e);
3655
process.exit(-1);
3756
});
3857

39-
req.write(postData);
58+
req.write(fileContents);
4059
req.end();
4160
}
42-
43-
if (process.stdin.isTTY) {
44-
var readlineSync = require("readline-sync");
45-
var postData = readlineSync.question();
46-
47-
processData(postData);
48-
}
4961
else {
50-
var data = '';
51-
process.stdin.setEncoding(encoding);
52-
53-
process.stdin.on('readable', function () {
54-
var chunk;
55-
while (chunk = process.stdin.read()) {
56-
data += chunk;
57-
}
58-
});
59-
60-
process.stdin.on('end', function () {
61-
var items = data.toString()
62-
.split(/\r?\n/)
63-
.filter(function (item) { return item; });
64-
65-
processData(items[0]);
66-
});
62+
commander.help();
63+
process.exit(-1);
6764
}

0 commit comments

Comments
 (0)