blob: 0c3d19efcbda0f48b3d3e6a2437d071133b386ec [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/* eslint-disable strict */
// Variables will be replaced before the code is loaded
// path to actual action sources
const path = "$$sourcePath$$";
// main function
const mainFn = "$$main$$";
// name of module file (for helpful errors)
const sourceFile = "$$sourceFile$$";
// load and validate on /init for quick feedback
try {
require(path);
} catch (e) {
throw `Cannot load module '${sourceFile}': ${e}`;
}
if (typeof require(path)[mainFn] !== "function") {
throw `'${mainFn}' is not a function in '${sourceFile}'. Specify the right function in wskdebug using --main.`;
}
// eslint-disable-next-line no-unused-vars
function main(args) { // lgtm [js/unused-local-variable]
// force reload of mounted action on every invocation
delete require.cache[require.resolve(path)];
// require and invoke main function
return require(path)[mainFn](args);
}