Comparing version 2.4.5 to 2.4.6
{ | ||
"name": "akkeris", | ||
"version": "2.4.5", | ||
"version": "2.4.6", | ||
"description": "Akkeris CLI", | ||
@@ -5,0 +5,0 @@ "main": "aka.js", |
@@ -370,11 +370,11 @@ "use strict" | ||
appkit.args | ||
.command('builds', 'list available builds', require_app_option, list.bind(null, appkit)) | ||
.command('builds:create', 'create a new build', create_build_option, create.bind(null, appkit)) | ||
.command('builds:info [ID]', 'view build info, ID can be "latest" for latest build.', require_app_option, info.bind(null, appkit)) | ||
.command('builds:output [ID]', 'view output for a build, ID can be "latest" for latest build.', require_logs_option, logs.bind(null, appkit)) | ||
.command('builds:auto', 'set the auto deploy hooks for your source control', require_auto_build_option, auto.bind(null, appkit)) | ||
.command('builds:auto:info', 'get the auto build/deploy information for this app.', require_app_option, info_auto.bind(null, appkit)) | ||
.command('builds:auto:remove', 'remove the auto build (if set)', require_app_option, remove_auto.bind(null, appkit)) | ||
.command('builds:rebuild ID', 'rebuild a previous build.', require_app_build_option, rebuild.bind(null, appkit)) | ||
.command('builds:stop ID', 'stop a running build', require_app_build_option, stop.bind(null, appkit)) | ||
.command('builds', false, /*'list available builds',*/ require_app_option, list.bind(null, appkit)) | ||
.command('builds:create', false, /*'create a new build',*/ create_build_option, create.bind(null, appkit)) | ||
.command('builds:info [ID]', false, /*'view build info, ID can be "latest" for latest build.',*/ require_app_option, info.bind(null, appkit)) | ||
.command('builds:output [ID]', false, /*'view output for a build, ID can be "latest" for latest build.',*/ require_logs_option, logs.bind(null, appkit)) | ||
.command('builds:auto', false, /*'set the auto deploy hooks for your source control',*/ require_auto_build_option, auto.bind(null, appkit)) | ||
.command('builds:auto:info', false, /*'get the auto build/deploy information for this app.',*/ require_app_option, info_auto.bind(null, appkit)) | ||
.command('builds:auto:remove', false, /*'remove the auto build (if set)',*/ require_app_option, remove_auto.bind(null, appkit)) | ||
.command('builds:rebuild ID', false, /*'rebuild a previous build.',*/ require_app_build_option, rebuild.bind(null, appkit)) | ||
.command('builds:stop ID', false, /*'stop a running build',*/ require_app_build_option, stop.bind(null, appkit)) | ||
// aliases. | ||
@@ -381,0 +381,0 @@ .command('build', false, require_app_option, list.bind(null, appkit)) |
@@ -19,3 +19,3 @@ "use strict" | ||
console.assert(args.app && args.app !== '', 'An application name was not provided.'); | ||
let task = appkit.terminal.task((state === true ? 'Enabling' : 'Disabling') + ` maintenance mode for **⬢ ${args.app}**`); | ||
let task = appkit.terminal.task(`${(state === true ? 'Enabling' : 'Disabling')} maintenance mode for **⬢ ${args.app}**`); | ||
task.start(); | ||
@@ -22,0 +22,0 @@ appkit.api.patch(JSON.stringify({"maintenance":state}), '/apps/' + args.app, function(err, info){ |
"use strict" | ||
const util = require('util') | ||
function getDateDiff(date /*: Date */) { | ||
var seconds = Math.floor((new Date() - date) / 1000); | ||
var interval = Math.floor(seconds / 31536000); | ||
if (interval > 1) { | ||
return `${interval} years ago`; | ||
} | ||
if (interval === 1) { | ||
return `${interval} year ago`; | ||
} | ||
interval = Math.floor(seconds / 2592000); | ||
if (interval > 1) { | ||
return `${interval} months ago`; | ||
} | ||
if (interval === 1) { | ||
return `${interval} month ago`; | ||
} | ||
interval = Math.floor(seconds / 86400); | ||
if (interval > 1) { | ||
return `${interval} days ago`; | ||
} | ||
if (interval === 1) { | ||
return `${interval} day ago`; | ||
} | ||
interval = Math.floor(seconds / 3600); | ||
if (interval > 1) { | ||
return `${interval} hours ago`; | ||
} | ||
if (interval === 1) { | ||
return `${interval} hour ago`; | ||
} | ||
interval = Math.floor(seconds / 60); | ||
return `${interval} minutes ago`; | ||
} | ||
function format_release(release) { | ||
return `**• v${release.version} (${release.id}) ${release.current ? "^^^- current^^^" : ""}** | ||
***Build:*** ${release.slug ? release.slug.id : 'unknown'} | ||
***Created:*** ${(new Date(release.created_at)).toLocaleString()} | ||
***Status:*** ${release.status === "succeeded" ? "^^succeeded^^" : "!!" + release.status + "!!"} | ||
***Description:*** ${release.description}\n`; | ||
console.assert(release.build, 'No build information was found.') | ||
let info = [ | ||
release.current ? "^^^current^^^" : "", | ||
release.description, | ||
release.build.source_blob.author, | ||
release.build.source_blob.message ? `##${release.build.source_blob.message.replace(/#/g, '').replace(/\s+/g, ' ')}##` : '', | ||
release.build.source_blob.commit ? `${release.build.source_blob.commit.substring(0, 7)}` : '', | ||
].filter(x => x && x !== '').map((x) => x.toString().replace(/\n/g, ' ')); | ||
return `**• v${release.version}**\t${getDateDiff(new Date(release.created_at))}\t${info.join(' - ')}` | ||
} | ||
function list(appkit, args) { | ||
console.assert(args.app && args.app !== '', 'An application name was not provided.'); | ||
appkit.api.get('/apps/' + args.app + '/releases', | ||
appkit.terminal.format_objects.bind(null, format_release, appkit.terminal.markdown('###===### No releases were found.'))); | ||
async function find_release(appkit, app, release_key) { | ||
let get = util.promisify(appkit.api.get) | ||
if(/^[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}$/.exec(release_key) !== null) { | ||
// uuuid | ||
return await get(`/apps/${app}/releases/${release_key}`) | ||
} else if (/^v[0-9]+$/.exec(release_key) !== null || !Number.isNaN(parseInt(release_key, 10))) { | ||
// vNNN format | ||
let version = parseInt(release_key, 10) | ||
if(Number.isNaN(version)) { | ||
version = parseInt(release_key.substring(1), 10) | ||
} | ||
console.assert(!Number.isNaN(version), 'The version, was not... a version.') | ||
let results = await get(`/apps/${app}/releases`) | ||
results = results.filter((x) => x.version === version) | ||
console.assert(results.length === 1, `The version ${version} was not found.`) | ||
return results[0] | ||
} else if (release_key === 'previous') { | ||
// not current, but one before | ||
let results = await get(`/apps/${app}/releases`) | ||
console.assert(results.length > 1, 'A previous release was not found.') | ||
return results[results.length - 2] | ||
} else { | ||
// current release | ||
let results = await get(`/apps/${app}/releases`) | ||
console.assert(results.length > 0, 'No releases were found.') | ||
return results[results.length - 1] | ||
} | ||
} | ||
function create(appkit, args) { | ||
console.assert(args.app && args.app !== '', 'An application name was not provided.'); | ||
if(args.build === '' || !args.build) { | ||
args.build = 'latest'; | ||
async function list(appkit, args) { | ||
try { | ||
let get = util.promisify(appkit.api.get) | ||
console.assert(args.app && args.app !== '', 'An application name was not provided.'); | ||
let results = await get(`/apps/${args.app}/releases`) | ||
if(results.length === 0) { | ||
return console.log(appkit.terminal.markdown('###===### No releases were found.')) | ||
} | ||
let obj = args.all === true || results.length < 11 ? results : results.slice(results.length - 10) | ||
obj = await Promise.all(obj.map(async (release) => Object.assign(release, {build:await get(`/slugs/${release.slug.id}`)}) )) | ||
obj.map(format_release).map(appkit.terminal.markdown).map((x) => console.log(x)) | ||
} catch (e) { | ||
return appkit.terminal.error(e) | ||
} | ||
let create_release = () => { | ||
let payload = {slug:args.build, description:args.version}; | ||
appkit.api.post(JSON.stringify(payload), '/apps/' + args.app + '/releases', appkit.terminal.print); | ||
}; | ||
} | ||
if(args.build.toLowerCase() === "latest" || args.build.toLowerCase() === "current") { | ||
appkit.api.get('/apps/' + args.app + '/builds', | ||
(err, builds) => { | ||
if(err) { | ||
return appkit.terminal.error(err); | ||
function wait_for_build(appkit, app, build_id, callback, iteration) { | ||
if(typeof(iteration) === 'undefined') { | ||
iteration = 0 | ||
} | ||
if(iteration === 5 * 60) { | ||
return callback(new Error('Timeout occured')) | ||
} else { | ||
appkit.api.get(`/apps/${app}/builds/${build_id}`, (err, build) => { | ||
if(err) { | ||
return callback(err) | ||
} else { | ||
if(build.status === 'succeeded') { | ||
return callback(null, build) | ||
} else if (build.status === 'failed') { | ||
return callback(new Error('build failed.')) | ||
} else { | ||
process.stdout.write('\b..') | ||
setTimeout(wait_for_build.bind(null, appkit, app, build_id, callback, (iteration + 1)), 1000) | ||
} | ||
args.build = builds[builds.length - 1].id; | ||
create_release(); | ||
}); | ||
} else { | ||
create_release(); | ||
} | ||
}); | ||
} | ||
} | ||
function info(appkit, args) { | ||
function create(appkit, args) { | ||
console.assert(args.app && args.app !== '', 'An application name was not provided.'); | ||
if(args.ID === '' || !args.ID) { | ||
args.ID = 'latest'; | ||
} | ||
let fetch_release_info = () => { | ||
appkit.api.get('/apps/' + args.app + '/releases/' + args.ID, appkit.terminal.print); | ||
}; | ||
if(args.ID.toLowerCase() === "latest" || args.ID.toLowerCase() === "current") { | ||
appkit.api.get('/apps/' + args.app + '/releases', (err, releases) => { | ||
if(err) { | ||
return appkit.terminal.error(err); | ||
let task = appkit.terminal.task(`Deploying **⬢ ${args.URL} to ${args.app} **`); | ||
task.start(); | ||
appkit.api.get(`/apps/${args.app}/features`, (err, features) => { | ||
if(err) { | ||
appkit.terminal.error(err) | ||
} else { | ||
let auto_release_enabled = features.filter((x) => x.name === 'auto-release' && x.enabled === true).length === 1 | ||
if(auto_release_enabled) { | ||
let payload = { org:app.organization.name, checksum:'', url:args.URL, repo:'', sha:'', branch:'', version:args.version } | ||
appkit.api.post(JSON.stringify(payload), `/apps/${args.app}/builds`, (err, build) => { | ||
if(err) { | ||
task.end('error') | ||
return appkit.terminal.error(err); | ||
} | ||
task.end('ok'); | ||
}); | ||
} else { | ||
let payload = { checksum:'', url:args.URL, repo:'', sha:'', branch:'', version:args.version } | ||
appkit.api.post(JSON.stringify(payload), `/apps/${args.app}/builds`, (err, build) => { | ||
if(err) { | ||
task.end('error') | ||
return appkit.terminal.error(err); | ||
} | ||
wait_for_build(appkit, args.app, build.id, (err, result) => { | ||
if(err) { | ||
task.end('error') | ||
return appkit.terminal.error(err); | ||
} | ||
appkit.api.post(JSON.stringify({"version":args.version, "slug":result.id}), `/apps/${args.app}/releases`, (err, result) => { | ||
if(err) { | ||
task.end('error') | ||
return appkit.terminal.error(err); | ||
} | ||
task.end('ok'); | ||
}); | ||
}) | ||
}) | ||
} | ||
args.ID = releases[releases.length - 1].id; | ||
fetch_release_info(); | ||
}); | ||
} else { | ||
fetch_release_info(); | ||
} | ||
} | ||
}) | ||
} | ||
function rollback(appkit, args) { | ||
async function info(appkit, args) { | ||
console.assert(args.app && args.app !== '', 'An application name was not provided.'); | ||
let payload = {release:args.release, description:args.version}; | ||
appkit.api.post(JSON.stringify(payload), '/apps/' + args.app + '/releases', appkit.terminal.print); | ||
if(args.RELEASE === '' || !args.RELEASE) { | ||
args.RELEASE = 'latest'; | ||
} | ||
try { | ||
appkit.terminal.print(null, | ||
await find_release(appkit, args.app, args.RELEASE)) | ||
} catch (err) { | ||
return appkit.terminal.error(err) | ||
} | ||
} | ||
async function rollback(appkit, args) { | ||
let post = util.promisify(appkit.api.post) | ||
console.assert(args.app && args.app !== '', 'An application name was not provided.'); | ||
let task = appkit.terminal.task(`Rolling back **⬢ ${args.app}**`); | ||
task.start(); | ||
if(args.RELEASE === '' || !args.RELEASE) { | ||
args.RELEASE = 'previous'; | ||
} | ||
try { | ||
let release = await find_release(appkit, args.app, args.RELEASE) | ||
post(JSON.stringify({release:release.id, description:args.version}), `/apps/${args.app}/releases`); | ||
task.end('ok') | ||
} catch (err) { | ||
task.end('error') | ||
appkit.terminal.error(err) | ||
} | ||
} | ||
module.exports = { | ||
init:function(appkit) { | ||
let all_option = { | ||
'all':{ | ||
'default':false, | ||
'demand':false, | ||
'boolean':true, | ||
'description':'Show all of the releases not just the last 10.' | ||
} | ||
} | ||
let create_release_option = { | ||
@@ -76,14 +212,9 @@ 'app':{ | ||
'string':true, | ||
'description':'The app to act on.' | ||
'description':'The app to deploy to.' | ||
}, | ||
'build':{ | ||
'alias':'b', | ||
'demand':true, | ||
'string':true, | ||
'description':'The build id to release on the app.' | ||
}, | ||
'version':{ | ||
'alias':'v', | ||
'demand':false, | ||
'string':true, | ||
'description':'The version of the release (informative only).' | ||
'description':'Notes or an internal version number for this release.' | ||
} | ||
@@ -104,28 +235,18 @@ } | ||
'string':true, | ||
'description':'The app to act on.' | ||
}, | ||
'release':{ | ||
'alias':'r', | ||
'demand':true, | ||
'string':true, | ||
'description':'The release id to rollback to on the app.' | ||
}, | ||
'version':{ | ||
'alias':'v', | ||
'string':true, | ||
'description':'The version of the release (informative only).' | ||
'description':'The app to rollback.' | ||
} | ||
}; | ||
appkit.args | ||
.command('releases', 'list releases on an app', require_app_option, list.bind(null, appkit)) | ||
.command('releases:create', 'create a new release from an existing build', create_release_option, create.bind(null, appkit)) | ||
.command('releases:info [ID]', 'view release info', require_app_option, info.bind(null, appkit)) | ||
.command('releases:rollback', 'rollback to a previous release on an app', require_rollback_option, rollback.bind(null, appkit)) | ||
.command('releases', 'list releases on an app', Object.assign(require_app_option, all_option), list.bind(null, appkit)) | ||
.command('releases:create URL', 'deploy a new version of code from a zip, tgz or docker URL', create_release_option, create.bind(null, appkit)) | ||
.command('releases:info [RELEASE]', 'view release info', require_app_option, info.bind(null, appkit)) | ||
.command('releases:rollback [RELEASE]', 'rollback to a previous release on an app', require_rollback_option, rollback.bind(null, appkit)) | ||
// aliases | ||
.command('release', false, require_app_option, list.bind(null, appkit)) | ||
.command('releases:list', false, require_app_option, list.bind(null, appkit)) | ||
.command('release:list', false, require_app_option, list.bind(null, appkit)) | ||
.command('release:create', false, create_release_option, create.bind(null, appkit)) | ||
.command('release:info ID', false, require_app_option, info.bind(null, appkit)) | ||
.command('release:rollback', false, require_rollback_option, rollback.bind(null, appkit)) | ||
.command('release', false, Object.assign(require_app_option, all_option), list.bind(null, appkit)) | ||
.command('releases:list', false, Object.assign(require_app_option, all_option), list.bind(null, appkit)) | ||
.command('release:list', false, Object.assign(require_app_option, all_option), list.bind(null, appkit)) | ||
.command('release:create URL', false, create_release_option, create.bind(null, appkit)) | ||
.command('release:info [RELEASE]', false, require_app_option, info.bind(null, appkit)) | ||
.command('release:rollback [RELEASE]', false, require_rollback_option, rollback.bind(null, appkit)) | ||
.command('rollback [RELEASE]', false, require_rollback_option, rollback.bind(null, appkit)) | ||
}, | ||
@@ -132,0 +253,0 @@ update:function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171736
30
4706