Skip to content

Commit 5b55a3d

Browse files
committed
feat: create output folder if not exists
Also updates the Rollup configuration to import "node:" prefixed built-in packages.
1 parent d1df2b3 commit 5b55a3d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

rollup.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export default [
1212
'assert',
1313
'aws-cdk-lib',
1414
'constructs',
15-
'fs',
15+
'node:fs',
16+
'node:path',
1617
'openapi3-ts'
1718
],
1819
plugins: [typescript()],

src/rest-api-with-spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as assert from 'assert';
2-
import * as fs from 'fs';
2+
import * as fs from 'node:fs';
3+
import * as path from 'node:path';
34
import { Stack, aws_apigateway as apigateway } from 'aws-cdk-lib';
45
import { Construct, Node } from 'constructs';
56
import {
@@ -127,6 +128,11 @@ export class RestApiWithSpec extends apigateway.RestApi implements IRestApiWithS
127128

128129
/** Synthesizes the OpenAPI definition. */
129130
private synthesizeOpenApi(): string[] {
131+
// makes sure that the output folder exists. if not, creates it.
132+
const outputDir = path.dirname(this.props.openApiOutputPath);
133+
if (!fs.existsSync(outputDir)) {
134+
fs.mkdirSync(outputDir, { recursive: true });
135+
}
130136
fs.writeFileSync(
131137
this.props.openApiOutputPath,
132138
this.builder.getSpecAsJson(undefined, 2),

0 commit comments

Comments
 (0)