tsdocker/ts/npmdocker.cli.ts

82 lines
3.1 KiB
TypeScript
Raw Normal View History

2017-02-11 22:37:01 +00:00
import * as plugins from './npmdocker.plugins'
import * as paths from './npmdocker.paths'
// modules
import * as ConfigModule from './npmdocker.config'
import * as DockerModule from './npmdocker.docker'
2017-04-21 11:44:18 +00:00
/**
* smartanalytics
* this data is fully anonymized (no Ips or any other personal information is tracked).
* It just keeps track which of our tools are really used...
* ... so we know where to spend our limited resources for improving them.
* Since yarn is out and there is heavy caching going on,
* pure download stats are just not reliable enough for us anymore
* Feel free to dig into the smartanalytics package, if you are interested in how it works.
* It is just an https call to Google Analytics.
* Our privacy policy can be found here: https://lossless.gmbh/privacy.html
*/
let npmdockerAnalytics = new plugins.smartanalytics.AnalyticsAccount('npmdocker','UA-64087619-5')
npmdockerAnalytics.sendEvent('npm','exec','git.zone')
2017-02-11 22:37:01 +00:00
let npmdockerCli = new plugins.smartcli.Smartcli()
export let run = () => {
2017-03-28 23:01:37 +00:00
npmdockerCli.standardTask().then(async (argvArg) => {
2017-07-16 11:58:41 +00:00
plugins.beautylog.figletSync('npmdocker')
2017-03-28 23:01:37 +00:00
let configArg = await ConfigModule.run()
2017-02-11 22:37:01 +00:00
.then(DockerModule.run)
if (configArg.exitCode === 0) {
plugins.beautylog.success('container ended all right!')
} else {
2017-04-20 19:57:44 +00:00
plugins.beautylog.error(`container ended with error! Exit Code is ${configArg.exitCode}`)
2017-02-11 22:37:01 +00:00
process.exit(1)
}
})
2017-07-16 11:58:41 +00:00
/**
* this command is executed inside docker and meant for use from outside docker
*/
2017-04-02 12:48:23 +00:00
npmdockerCli.addCommand('runinside').then(async (argvArg) => {
plugins.beautylog.ok('Allright. We are now in Docker!')
plugins.beautylog.log('now trying to run your specified command')
let configArg = await ConfigModule.run()
await plugins.smartshell.exec(configArg.command).then(response => {
if (response.exitCode !== 0) {
process.exit(1)
}
})
})
2017-03-28 23:01:37 +00:00
npmdockerCli.addCommand('clean').then(async (argvArg) => {
plugins.beautylog.ora.start()
2017-02-11 22:37:01 +00:00
plugins.beautylog.ora.text('cleaning up docker env...')
if (argvArg.all) {
plugins.beautylog.ora.text('killing any running docker containers...')
2017-03-28 23:01:37 +00:00
await plugins.smartshell.exec(`docker kill $(docker ps -q)`)
2017-02-11 22:37:01 +00:00
plugins.beautylog.ora.text('removing stopped containers...')
2017-03-28 23:01:37 +00:00
await plugins.smartshell.exec(`docker rm $(docker ps -a -q)`)
2017-02-11 22:37:01 +00:00
plugins.beautylog.ora.text('removing images...')
2017-03-28 23:01:37 +00:00
await plugins.smartshell.exec(`docker rmi $(docker images -q -f dangling=true)`)
2017-02-11 22:37:01 +00:00
plugins.beautylog.ora.text('removing all other images...')
2017-03-28 23:01:37 +00:00
await plugins.smartshell.exec(`docker rmi $(docker images -a -q)`)
2017-02-12 14:17:59 +00:00
plugins.beautylog.ora.text('removing all volumes...')
2017-03-28 23:01:37 +00:00
await plugins.smartshell.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`)
2017-02-11 22:37:01 +00:00
}
plugins.beautylog.ora.endOk('docker environment now is clean!')
})
2017-03-28 23:01:37 +00:00
npmdockerCli.addCommand('speedtest').then(async (argvArg) => {
2017-07-16 11:58:41 +00:00
plugins.beautylog.figletSync('npmdocker')
2017-03-28 23:01:37 +00:00
plugins.beautylog.ok('Starting speedtest')
await plugins.smartshell.exec(`docker pull tianon/speedtest && docker run --rm tianon/speedtest`)
2017-02-12 15:04:27 +00:00
})
2017-02-11 22:37:01 +00:00
npmdockerCli.startParse()
}