UNPKG

5.24 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var __metadata = (this && this.__metadata) || function (k, v) {
9 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10};
11var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12 return new (P || (P = Promise))(function (resolve, reject) {
13 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
16 step((generator = generator.apply(thisArg, _arguments || [])).next());
17 });
18};
19Object.defineProperty(exports, "__esModule", { value: true });
20const commons_config_1 = require("commons-config");
21const typedi_1 = require("typedi");
22const Invoker_1 = require("../base/Invoker");
23const Tasks_1 = require("../libs/tasks/Tasks");
24const Console_1 = require("../libs/logging/Console");
25const Tasks_api_1 = require("../api/Tasks.api");
26const System_1 = require("../libs/system/System");
27const TasksHelper_1 = require("../libs/tasks/TasksHelper");
28const Log_1 = require("../libs/logging/Log");
29/**
30 * Starts a task direct or in a running worker
31 * Command: typexs task test [--targetId abc] [--outputMode worker|local]
32 *
33 * outputMode is per default 'worker' if one exists else startup local
34 *
35 */
36class TaskCommand {
37 constructor() {
38 this.command = 'task';
39 this.aliases = 't';
40 this.describe = 'Start task';
41 }
42 beforeStartup() {
43 System_1.System.enableDistribution(false);
44 }
45 builder(yargs) {
46 return yargs;
47 }
48 handler(argv) {
49 return __awaiter(this, void 0, void 0, function* () {
50 const targetId = commons_config_1.Config.get('argv.targetId', null);
51 let isLocal = true; // Config.get('argv.local', false);
52 const isRemote = commons_config_1.Config.get('argv.remote', false);
53 if (targetId === null && !isRemote) {
54 isLocal = true;
55 // wait moment for
56 }
57 else {
58 isLocal = false;
59 }
60 // filter task names from request
61 const taskNames = [];
62 let start = false;
63 let notask = false;
64 for (let i = 0; i < process.argv.length; i++) {
65 if (process.argv[i] === 'task') {
66 start = true;
67 continue;
68 }
69 if (!start) {
70 continue;
71 }
72 if (process.argv[i].match(/^\-\-/)) {
73 // parameter
74 notask = true;
75 }
76 else {
77 if (!notask) {
78 taskNames.push(process.argv[i]);
79 }
80 }
81 }
82 yield this.init();
83 if (taskNames.length > 0) {
84 const args = commons_config_1.Config.get('argv');
85 try {
86 const results = yield TasksHelper_1.TasksHelper.exec(taskNames, Object.assign({ isLocal: isLocal, remote: isRemote, targetId: targetId, skipTargetCheck: true }, args));
87 Console_1.Console.log(JSON.stringify(results, null, 2));
88 }
89 catch (e) {
90 Log_1.Log.error(e);
91 }
92 }
93 else {
94 const res = this.tasks.names();
95 Console_1.Console.log('List of supported tasks:');
96 Console_1.Console.log('\t- ' + res.join('\n\t') + '\n');
97 }
98 yield this.shutdown();
99 });
100 }
101 init() {
102 return __awaiter(this, void 0, void 0, function* () {
103 yield this.invoker.use(Tasks_api_1.TasksApi).onInit();
104 });
105 }
106 shutdown() {
107 return __awaiter(this, void 0, void 0, function* () {
108 yield this.invoker.use(Tasks_api_1.TasksApi).onShutdown();
109 });
110 }
111}
112__decorate([
113 typedi_1.Inject(Tasks_1.Tasks.NAME),
114 __metadata("design:type", Tasks_1.Tasks)
115], TaskCommand.prototype, "tasks", void 0);
116__decorate([
117 typedi_1.Inject(Invoker_1.Invoker.NAME),
118 __metadata("design:type", Invoker_1.Invoker)
119], TaskCommand.prototype, "invoker", void 0);
120__decorate([
121 typedi_1.Inject(System_1.System.NAME),
122 __metadata("design:type", System_1.System)
123], TaskCommand.prototype, "system", void 0);
124exports.TaskCommand = TaskCommand;
125
126//# sourceMappingURL=TaskCommand.js.map