|
16 | 16 |
|
17 | 17 | import { KubeConfig } from '@kubernetes/client-node'; |
18 | 18 | import { Context } from '@kubernetes/client-node/dist/config_types'; |
19 | | -import { execSync } from 'child_process'; |
20 | 19 | import { question } from 'cli-interact'; |
21 | 20 | import { mkdtempSync, unlinkSync, writeFileSync } from 'fs'; |
22 | 21 | import { tmpdir } from 'os'; |
23 | | -import { resolve } from 'path'; |
| 22 | +import { resolve, delimiter } from 'path'; |
24 | 23 | import * as request from 'request-promise'; |
25 | | -import { CLI_PACKAGE } from '../paths'; |
26 | 24 | import * as format from '../utils/format'; |
27 | 25 | import { log } from '../utils/log'; |
28 | 26 | import * as validator from '../utils/validator'; |
29 | 27 | import { failure } from '../utils/format'; |
| 28 | +import { spawnSync } from 'child_process'; |
| 29 | +import { CLI_PACKAGE } from '../paths'; |
30 | 30 |
|
31 | 31 | export async function typeCreate(packageDir: string) { |
32 | 32 | const desc = 'Generating types from OpenAPI spec.'; |
@@ -60,16 +60,26 @@ export async function typeCreate(packageDir: string) { |
60 | 60 | const tmp = mkdtempSync(resolve(tmpdir(), 'kpt-init')); |
61 | 61 | const swaggerFile = resolve(tmp, 'swagger.json'); |
62 | 62 | const typegenOutDir = resolve(packageDir, 'src', 'gen'); |
63 | | - try { |
64 | | - writeFileSync(swaggerFile, out); |
65 | | - // Generate types. |
66 | | - execSync(`${CLI_PACKAGE.typegen} ${swaggerFile} ${typegenOutDir}`); |
67 | | - log(`Generated ${typegenOutDir}`); |
68 | | - } finally { |
69 | | - // Delete swagger.json. |
70 | | - unlinkSync(swaggerFile); |
| 63 | + |
| 64 | + writeFileSync(swaggerFile, out); |
| 65 | + const typegen = spawnSync('typegen', [swaggerFile, typegenOutDir], { |
| 66 | + env: { |
| 67 | + PATH: `${CLI_PACKAGE.binDir}${delimiter}${process.env.PATH}`, |
| 68 | + }, |
| 69 | + stdio: 'inherit', |
| 70 | + }); |
| 71 | + unlinkSync(swaggerFile); |
| 72 | + |
| 73 | + if (typegen.status !== 0) { |
| 74 | + let msg = 'Failed to build docker image'; |
| 75 | + if (typegen.error) { |
| 76 | + msg = `${msg}: ${typegen.error}`; |
| 77 | + } |
| 78 | + throw new Error(msg); |
71 | 79 | } |
72 | 80 |
|
| 81 | + log(`Generated ${typegenOutDir}`); |
| 82 | + |
73 | 83 | log(format.finishMarker(desc)); |
74 | 84 | } |
75 | 85 |
|
|
0 commit comments