UNPKG

europa-build

Version:

Tool for generating and maintaining Europa plugins and presets

91 lines 3.94 kB
"use strict"; /* * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ScriptRunner = void 0; const Logger_1 = require("../logger/Logger"); const BuildScriptProvider_1 = require("./provider/BuildScriptProvider"); const FixLintScriptProvider_1 = require("./provider/FixLintScriptProvider"); const FormatScriptProvider_1 = require("./provider/FormatScriptProvider"); const LintScriptProvider_1 = require("./provider/LintScriptProvider"); const TestScriptProvider_1 = require("./provider/TestScriptProvider"); const _logger = Symbol(); const _providers = Symbol(); /** * A runner for scripts that relate to generated plugin and preset packages. */ class ScriptRunner { /** * Creates an instance of {@link ScriptRunner} using the `options` provided. * * @param [options] - The options to be used. */ constructor(options = {}) { var _a; const parentLogger = (_a = options.parentLogger) !== null && _a !== void 0 ? _a : (0, Logger_1.createLogger)({ outputStream: options.outputStream }); this[_logger] = parentLogger.child({ name: 'ScriptRunner' }); this[_providers] = [ new BuildScriptProvider_1.BuildScriptProvider({ parentLogger }), new FixLintScriptProvider_1.FixLintScriptProvider({ parentLogger }), new FormatScriptProvider_1.FormatScriptProvider({ parentLogger }), new LintScriptProvider_1.LintScriptProvider({ parentLogger }), new TestScriptProvider_1.TestScriptProvider({ parentLogger }), ]; } /** * Returns the names of all available scripts. * * @return The available script names. */ getScriptNames() { return this[_providers].map((provider) => provider.getName()); } /** * Runs the script with the specified name using the `options` provided. * * @param scriptName - The name of the script to run. * @param [options] - The options to be used. * @throws If no script could be found for `scriptName` or if any error occurs while running the script. */ async run(scriptName, options = {}) { var _a; const cwd = (_a = options.cwd) !== null && _a !== void 0 ? _a : process.cwd(); const provider = this[_providers].find((provider) => provider.getName() === scriptName); if (!provider) { throw new Error(`Unexpected script name: ${scriptName}`); } let ranScript = false; try { await provider.runScript(cwd); ranScript = true; await provider.afterScript(cwd); } catch (e) { if (!ranScript) { await provider.afterScript(cwd); } throw e; } } } exports.ScriptRunner = ScriptRunner; //# sourceMappingURL=ScriptRunner.js.map