tsdocker/dist/npmdocker.cli.js
2017-10-13 16:44:25 +02:00

85 lines
7.8 KiB
JavaScript

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./npmdocker.plugins");
// modules
const ConfigModule = require("./npmdocker.config");
const DockerModule = require("./npmdocker.docker");
/**
* 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.Analytics({
apiEndPoint: 'https://pubapi.lossless.one',
appName: 'npmdocker',
projectId: 'gitzone'
});
npmdockerAnalytics.recordEvent('npmtoolexecution', {
somedata: 'somedata'
});
let npmdockerCli = new plugins.smartcli.Smartcli();
exports.run = () => {
npmdockerCli.standardTask().then((argvArg) => __awaiter(this, void 0, void 0, function* () {
plugins.beautylog.figletSync('npmdocker');
let configArg = yield ConfigModule.run()
.then(DockerModule.run);
if (configArg.exitCode === 0) {
plugins.beautylog.success('container ended all right!');
}
else {
plugins.beautylog.error(`container ended with error! Exit Code is ${configArg.exitCode}`);
process.exit(1);
}
}));
/**
* this command is executed inside docker and meant for use from outside docker
*/
npmdockerCli.addCommand('runinside').then((argvArg) => __awaiter(this, void 0, void 0, function* () {
plugins.beautylog.ok('Allright. We are now in Docker!');
plugins.beautylog.log('now trying to run your specified command');
let configArg = yield ConfigModule.run();
yield plugins.smartshell.exec(configArg.command).then(response => {
if (response.exitCode !== 0) {
process.exit(1);
}
});
}));
npmdockerCli.addCommand('clean').then((argvArg) => __awaiter(this, void 0, void 0, function* () {
plugins.beautylog.ora.start();
plugins.beautylog.ora.text('cleaning up docker env...');
if (argvArg.all) {
plugins.beautylog.ora.text('killing any running docker containers...');
yield plugins.smartshell.exec(`docker kill $(docker ps -q)`);
plugins.beautylog.ora.text('removing stopped containers...');
yield plugins.smartshell.exec(`docker rm $(docker ps -a -q)`);
plugins.beautylog.ora.text('removing images...');
yield plugins.smartshell.exec(`docker rmi $(docker images -q -f dangling=true)`);
plugins.beautylog.ora.text('removing all other images...');
yield plugins.smartshell.exec(`docker rmi $(docker images -a -q)`);
plugins.beautylog.ora.text('removing all volumes...');
yield plugins.smartshell.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`);
}
plugins.beautylog.ora.endOk('docker environment now is clean!');
}));
npmdockerCli.addCommand('speedtest').then((argvArg) => __awaiter(this, void 0, void 0, function* () {
plugins.beautylog.figletSync('npmdocker');
plugins.beautylog.ok('Starting speedtest');
yield plugins.smartshell.exec(`docker pull tianon/speedtest && docker run --rm tianon/speedtest`);
}));
npmdockerCli.startParse();
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLCtDQUE4QztBQUc5QyxVQUFVO0FBQ1YsbURBQWtEO0FBQ2xELG1EQUFrRDtBQUdsRDs7Ozs7Ozs7OztHQVVHO0FBQ0gsSUFBSSxrQkFBa0IsR0FBRyxJQUFJLE9BQU8sQ0FBQyxjQUFjLENBQUMsU0FBUyxDQUFDO0lBQzVELFdBQVcsRUFBRSw2QkFBNkI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