Skip to content

Commit ac7372b

Browse files
brushmateRomanHotsiy
authored andcommitted
fix(cli): create directories when a path is specified in the --output option (#513)
Fixes #512
1 parent bf57c4d commit ac7372b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as zlib from 'zlib';
1414
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';
1515

1616
import { createReadStream, existsSync, readFileSync, ReadStream, watch, writeFileSync } from 'fs';
17+
import * as mkdirp from 'mkdirp';
1718

1819
import * as YargsParser from 'yargs';
1920

@@ -186,6 +187,7 @@ async function bundle(pathToSpec, options: Options = {}) {
186187
const spec = await loadAndBundleSpec(pathToSpec);
187188
const pageHTML = await getPageHTML(spec, pathToSpec, { ...options, ssr: true });
188189

190+
mkdirp.sync(dirname(options.output!));
189191
writeFileSync(options.output!, pageHTML);
190192
const sizeInKiB = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
191193
const time = Date.now() - start;

cli/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"handlebars": "^4.0.11",
1212
"isarray": "^2.0.4",
13+
"mkdirp": "^0.5.1",
1314
"react": "^16.3.2",
1415
"react-dom": "^16.3.2",
1516
"redoc": "^2.0.0-alpha.20",
@@ -24,6 +25,7 @@
2425
},
2526
"devDependencies": {
2627
"@types/handlebars": "^4.0.36",
28+
"@types/mkdirp": "^0.5.2",
2729
"ci-publish": "^1.3.1"
2830
}
29-
}
31+
}

cli/yarn.lock

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
version "4.0.37"
77
resolved "https://registry.yarnpkg.com/@types/handlebars/-/handlebars-4.0.37.tgz#a3bc3eba0c0f03f753cac00841a5b21e26a02c03"
88

9+
"@types/mkdirp@^0.5.2":
10+
version "0.5.2"
11+
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.5.2.tgz#503aacfe5cc2703d5484326b1b27efa67a339c1f"
12+
dependencies:
13+
"@types/node" "*"
14+
15+
"@types/node@*":
16+
version "10.1.3"
17+
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.1.3.tgz#5c16980936c4e3c83ce64e8ed71fb37bd7aea135"
18+
919
agent-base@2:
1020
version "2.1.1"
1121
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-2.1.1.tgz#d6de10d5af6132d5bd692427d46fc538539094c7"
@@ -1450,7 +1460,7 @@ minimist@~0.0.1:
14501460
version "0.0.10"
14511461
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
14521462

1453-
mkdirp@^0.5.0:
1463+
mkdirp@^0.5.0, mkdirp@^0.5.1:
14541464
version "0.5.1"
14551465
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
14561466
dependencies:

0 commit comments

Comments
 (0)