@atomist/rugs
Version:
Helper functions for Rugs
63 lines (62 loc) • 1.96 kB
JavaScript
/*
* Copyright © 2017 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 });
/**
* Build a plan instruction for the given decorated
* editor, extracting its present property values, which
* follow a convention, with names like __name
* @param p project or name of project to edit
* @param ed editor to use
*/
function editWith(p, ed) {
var obj = instruction(ed, "edit");
var proj = p;
var projectKey = "project";
obj[projectKey] = proj.name ? proj.name() : p;
return obj;
}
exports.editWith = editWith;
function handleCommand(ed) {
return instruction(ed, "command");
}
exports.handleCommand = handleCommand;
/**
* Emit an instruction for the given decorated operation type
* @param op operation to emit instruction for
* @param kind kind of the instruction, such as "edit"
*/
function instruction(op, kind) {
var params = {};
for (var _i = 0, _a = op.__parameters; _i < _a.length; _i++) {
var param = _a[_i];
params[param.name] = op[param.name];
}
return {
kind: kind,
name: op.__name,
parameters: params,
};
}
/**
* Build an 'execute' Rug Function
* @param name Rug Function to call
* @param params any params, if any
*/
function execute(name, params) {
return { instruction: { kind: "execute", name: name, parameters: params } };
}
exports.execute = execute;