Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Commit ef83478

Browse files
committed
format jobs create ip address and ports as links
1 parent 823ace5 commit ef83478

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

lib/jobs/create.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var projectConfig = require('./../projectConfig');
1313
var jobs_logs = require('./../jobs/logs.js');
1414
var jobs_waitfor = require('./../jobs/waitfor.js');
1515
var jobs_show = require('./../jobs/show.js');
16+
const chalk = require('chalk');
1617

1718
/**
1819
* @memberof jobs
@@ -136,6 +137,32 @@ function directorySize(_path, cb, size) {
136137
});
137138
}
138139

140+
function LinksFromIpPortMappings(ipAddress, ports) {
141+
var result = [];
142+
var portMappings = ('' + ports).split(",");
143+
for (var i = 0; i < portMappings.length; i++) {
144+
var portMapping = portMappings[i];
145+
var portMappingParts = portMapping.split(":");
146+
if (portMappingParts.length > 0) {
147+
var portMappedTo = portMappingParts[0].trim();
148+
if (portMappedTo) {
149+
var scheme = 'http';
150+
if (portMappingParts.length > 2) {
151+
var portMappingSchme = portMappingParts[2].trim();
152+
if (portMappingSchme) scheme = portMappingSchme;
153+
} else if (portMappingParts.length > 1) {
154+
var portMappedFrom = portMappingParts[1].trim();
155+
if (portMappedFrom == '22') scheme = 'ssh';
156+
if (portMappedFrom == '443') scheme = 'https';
157+
}
158+
var link = scheme + '://' + ipAddress + ':' + portMappedTo + '/';
159+
result.push(link);
160+
}
161+
}
162+
}
163+
return result;
164+
}
165+
139166
var MAX_UPLOAD_SIZE = 104857600; // 100MB
140167

141168
function create(params, cb) {
@@ -244,7 +271,19 @@ function create(params, cb) {
244271
return cb();
245272
}
246273
if (res.storageRegion) console.log('Storage Region: ' + res.storageRegion);
247-
if (res.ports && res.ipAddress) console.log('IP Address: ' + res.ipAddress);
274+
if (res.ports && res.ipAddress) {
275+
var links = LinksFromIpPortMappings(res.ipAddress, res.ports);
276+
if (links.length > 0) {
277+
var link_str = '';
278+
for (var i = 0; i < links.length; i++) {
279+
var link = links[i];
280+
if (i > 0) link_str += ', ';
281+
link_str += chalk.underline(link);
282+
}
283+
if (links.length > 1) console.log('Links: ' + link_str);
284+
else console.log('Link: ' + link_str);
285+
} else console.log('IP Address: ' + res.ipAddress);
286+
}
248287
console.log('Awaiting logs...');
249288
return jobs_logs({ jobId: jobId, tail: true }, function _logsCb(err) {
250289
if (err) return cb(err);

0 commit comments

Comments
 (0)