UNPKG

@nx-dotnet/core

Version:

- Have an existing nx workspace. For creating this, see [nrwl's documentation](https://nx.dev/latest/angular/getting-started/nx-setup). - .NET SDK is installed, and `dotnet` is available on the path. For help on this, see [Microsoft's documentation](https

71 lines 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = runExecutor; const devkit_1 = require("@nx/devkit"); const child_process_1 = require("child_process"); function runExecutor(options, context) { if (options.useOpenApiGenerator) { return runOpenAPIGenerator(options, context); } return runNxDotnetOpenAPIGenerator(options); } function runNxDotnetOpenAPIGenerator(options) { return new Promise((resolve, reject) => { (0, child_process_1.exec)(`${(0, devkit_1.getPackageManagerCommand)().exec} nx g @nx-dotnet/core:swagger-typescript --openapiJsonPath="${options.openapiJsonPath}" --outputProject="${options.outputProject}"`, { cwd: devkit_1.workspaceRoot, windowsHide: true }, (error, stdout) => { if (error) { devkit_1.logger.error(error); reject({ success: false, error, }); } else { devkit_1.logger.info(stdout); resolve({ success: true, }); } }); }); } function runOpenAPIGenerator(options, context) { return new Promise((resolve, reject) => { const outputProjectRoot = context.projectGraph?.nodes[options.outputProject]?.data.root; if (!outputProjectRoot) { reject({ success: false, error: new Error(`Could not find project with name ${options.outputProject}`), }); return; } const childProcess = (0, child_process_1.spawn)('npx', [ 'openapi-generator-cli', 'generate', `-g=${options.openApiGenerator}`, `-i=${options.openapiJsonPath}`, `-o=${outputProjectRoot}`, ...(options.openApiGeneratorArgs ?? []), ], { shell: true, stdio: 'inherit', windowsHide: true }); childProcess.on('error', (error) => { devkit_1.logger.error(error); reject({ success: false, error, }); }); childProcess.on('exit', (code) => { if (code === 0) { resolve({ success: true, }); } else { reject({ success: false, error: new Error('OpenAPI generator failed'), }); } }); }); } //# sourceMappingURL=executor.js.map