@atomist/sdm
Version:
Atomist Software Delivery Machine SDK
42 lines • 1.7 kB
JavaScript
;
/*
* Copyright © 2019 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.adaptHandleCommand = void 0;
const metadataReading_1 = require("@atomist/automation-client/lib/internal/metadata/metadataReading");
const constructionUtils_1 = require("@atomist/automation-client/lib/util/constructionUtils");
const _ = require("lodash");
/**
* Convert an decorator-style HandleCommand to a SDM-style CommandHandlerRegistration
*/
function adaptHandleCommand(maker) {
const md = metadataReading_1.metadataFromInstance(constructionUtils_1.toFactory(maker)());
return {
name: md.name,
intent: md.intent,
description: md.description,
tags: (md.tags || []).map(t => t.name),
autoSubmit: md.auto_submit,
paramsMaker: maker,
listener: async (ci) => {
const h = constructionUtils_1.toFactory(maker)();
_.forEach(ci.parameters, (v, k) => h[k] = v);
return h.handle(ci.context, ci.parameters);
},
};
}
exports.adaptHandleCommand = adaptHandleCommand;
//# sourceMappingURL=adaptHandleCommand.js.map