Comparing version 2.9.13 to 2.9.16
@@ -964,3 +964,2 @@ #!/usr/bin/env node | ||
headers['user-agent'] = 'akkeris-cli'; | ||
let full_url = rurl.startsWith("http") ? rurl : | ||
@@ -967,0 +966,0 @@ ( (module.exports.config.akkeris_api_host.startsWith("http") ? |
{ | ||
"name": "akkeris", | ||
"version": "2.9.13", | ||
"version": "2.9.16", | ||
"description": "Akkeris CLI", | ||
@@ -5,0 +5,0 @@ "main": "aka.js", |
@@ -108,3 +108,2 @@ "use strict" | ||
await appkit.api.post(JSON.stringify({"filter":{"id":filter_info.id}, options}),`/apps/${args.app}/filters`); | ||
await appkit.api.patch(JSON.stringify({"RESTART":Math.random()}),`/apps/${args.app}/config-vars`); // TODO: REMOVE | ||
} catch (e) { | ||
@@ -128,3 +127,2 @@ task.end('error'); | ||
await appkit.api.delete(`/apps/${args.app}/filters/${args.FILTER_ATTACHMENT_ID}`); | ||
await appkit.api.patch(JSON.stringify({"RESTART":Math.random()}),`/apps/${args.app}/config-vars`); // TODO: REMOVE | ||
} catch (e) { | ||
@@ -131,0 +129,0 @@ task.end('error'); |
@@ -7,15 +7,42 @@ "use strict" | ||
function quiet(data) { | ||
return data.replace(/^([A-z0-9\:\-\+\.]+Z) ([A-z\-0-9\.]+) ([A-z\.0-9\/\[\]\-]+)\: /gm, ''); | ||
} | ||
function highlight(data) { | ||
process.stdout.write(data.replace(/^([A-z0-9\:\-\+\.]+Z) ([A-z\-0-9\.]+) ([A-z\.0-9\/\[\]\-]+)\: /gm, '\u001b[36m$1\u001b[0m $2 \u001b[38;5;104m$3:\u001b[0m ')); | ||
return data.replace(/^([A-z0-9\:\-\+\.]+Z) ([A-z\-0-9\.]+) ([A-z\.0-9\/\[\]\-]+)\: /gm, '\u001b[36m$1\u001b[0m $2 \u001b[38;5;104m$3:\u001b[0m '); | ||
} | ||
async function stream_logs(appkit, colors, uri, payload) { | ||
function find_source(source, data) { | ||
if(!(new RegExp('^([A-z0-9\\:\\-\\+\\.]+Z) ([A-z\\-0-9\\.]+) ' + source + '.*', 'gm')).test(data)) { | ||
return ''; | ||
} | ||
return data; | ||
} | ||
function find_dyno(dyno, data) { | ||
if(!(new RegExp('^([A-z0-9\\:\\-\\+\\.]+Z) ([A-z\\-0-9\\.]+) app\\[' + dyno.toLowerCase() + '.*', 'gm')).test(data)) { | ||
return ''; | ||
} | ||
return data; | ||
} | ||
async function stream_logs(appkit, colors, uri, payload, silent, source, dyno) { | ||
let log_session = await appkit.api.post(JSON.stringify(payload), uri); | ||
let logging_stream_url = url.parse(log_session.logplex_url); | ||
let chain = colors ? | ||
(silent ? (data) => highlight(quiet(data)) : (data) => highlight(data)) : | ||
(silent ? (data) => quiet(data) : (data) => data); | ||
let filter = source ? | ||
(dyno ? (data) => find_source(find_dyno(dyno, data)) : (data) => find_source(source, data)) : | ||
(dyno ? (data) => find_dyno(dyno, data) : (data) => data); | ||
let req = https.request(logging_stream_url, (res) => { | ||
if(!colors) { | ||
if(!colors && !silent && !source && !dyno) { | ||
res.pipe(process.stdout); | ||
} else if (!source && !dyno) { | ||
res.setEncoding('utf8'); | ||
res.on('data', (data) => process.stdout.write(chain(data))); | ||
} else { | ||
res.setEncoding('utf8'); | ||
res.on('data', highlight); | ||
res.on('data', (data) => process.stdout.write(chain(filter(data)))); | ||
} | ||
@@ -45,3 +72,3 @@ res.on('error', (e) => { | ||
} | ||
await stream_logs(appkit, args.colors, uri, payload); | ||
await stream_logs(appkit, args.colors, uri, payload, args.quiet, args.source, args.dyno); | ||
} catch(e) { | ||
@@ -61,8 +88,2 @@ appkit.terminal.error(e) | ||
}, | ||
'site':{ | ||
'alias':'s', | ||
'demand':false, | ||
'string':true, | ||
'description': 'The site to view logs for (cannot be used with -a option)' | ||
}, | ||
'num':{ | ||
@@ -88,2 +109,23 @@ 'alias':'n', | ||
'description': 'Allow tty colors in logs' | ||
}, | ||
'source':{ | ||
'alias':'s', | ||
'demand':false, | ||
'string':true, | ||
'default':'', | ||
'description':'Show output only from a specific source (e.g., "akkeris/router", "app", "build")' | ||
}, | ||
'dyno':{ | ||
'alias':'d', | ||
'demand':false, | ||
'string':true, | ||
'default':'', | ||
'description':'Show output only from a dyno type (e.g., "web", "worker")' | ||
}, | ||
'quiet':{ | ||
'alias':'q', | ||
'demand':false, | ||
'boolean':true, | ||
'default':false, | ||
'description':'Suppress timestamp and process annotations' | ||
} | ||
@@ -90,0 +132,0 @@ }; |
@@ -36,2 +36,8 @@ "use strict" | ||
let data = null; | ||
let subpath = ''; | ||
if(args.site.startsWith("https://")) { | ||
let parsed = new URL(args.site); | ||
args.site = parsed.hostname; | ||
subpath = parsed.pathname; | ||
} | ||
if(!args.site && !args.app) { | ||
@@ -56,3 +62,3 @@ return appkit.terminal.error('Please specify either an app or a site (-a or -s).') | ||
} | ||
let routes = data.sort((x, y) => x.source_path.length < y.source_path.length ? -1 : 1) | ||
let routes = data.sort((x, y) => x.source_path < y.source_path ? -1 : 1).filter((x) => x.source_path.startsWith(subpath)); | ||
for (let route of routes) { | ||
@@ -59,0 +65,0 @@ let route_app = route.app.name |
248163
6521