UNPKG

@naxodev/gonx

Version:

Modern Nx plugin to use Go in a Nx workspace

51 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = runExecutor; const utils_1 = require("../../utils"); const node_path_1 = require("node:path"); /** * This executor builds an executable using the `go build` command. * * @param options options passed to the executor * @param context context passed to the executor */ async function runExecutor(options, context) { var _a; return (0, utils_1.executeCommand)(buildParams(options, context), { cwd: (0, utils_1.extractCWD)(options, context), env: options.env, executable: (_a = options.compiler) !== null && _a !== void 0 ? _a : 'go', }); } const buildParams = (options, context) => { var _a, _b; const projectName = context.projectName; if (!projectName) { throw new Error('Project name is not provided'); } const projectRoot = (_a = context.projectsConfigurations.projects[context.projectName]) === null || _a === void 0 ? void 0 : _a.root; if (!projectRoot) { throw new Error(`Cannot find project root for ${context.projectName}`); } const runPath = options.main ? '.' : './...'; return [ 'build', '-o', buildOutputPath(context.root, (0, utils_1.extractProjectRoot)(context), options.outputPath), ...(0, utils_1.buildStringFlagIfValid)('-buildmode', options.buildMode), ...((_b = options.flags) !== null && _b !== void 0 ? _b : []), runPath, ]; }; /** * Builds the output path of the executable based on the project root. * * @param projectRoot project root * @param customPath custom path to use first */ function buildOutputPath(workspaceRoot, projectRoot, customPath) { const normalizedCustomPath = customPath && (0, node_path_1.join)(workspaceRoot, customPath); const defaultPath = (0, node_path_1.join)(workspaceRoot, `dist/${projectRoot}/`); return normalizedCustomPath || defaultPath; } //# sourceMappingURL=executor.js.map