Skip to content

Commit

Permalink
fix(cli): create directories when a path is specified in the --output…
Browse files Browse the repository at this point in the history
… option (#513)

Fixes #512
  • Loading branch information
brushmate authored and RomanHotsiy committed May 29, 2018
1 parent bf57c4d commit ac7372b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as zlib from 'zlib';
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';

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

import * as YargsParser from 'yargs';

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

mkdirp.sync(dirname(options.output!));
writeFileSync(options.output!, pageHTML);
const sizeInKiB = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
const time = Date.now() - start;
Expand Down
4 changes: 3 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"handlebars": "^4.0.11",
"isarray": "^2.0.4",
"mkdirp": "^0.5.1",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"redoc": "^2.0.0-alpha.20",
Expand All @@ -24,6 +25,7 @@
},
"devDependencies": {
"@types/handlebars": "^4.0.36",
"@types/mkdirp": "^0.5.2",
"ci-publish": "^1.3.1"
}
}
}
12 changes: 11 additions & 1 deletion cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
version "4.0.37"
resolved "https://registry.yarnpkg.com/@types/handlebars/-/handlebars-4.0.37.tgz#a3bc3eba0c0f03f753cac00841a5b21e26a02c03"

"@types/mkdirp@^0.5.2":
version "0.5.2"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.5.2.tgz#503aacfe5cc2703d5484326b1b27efa67a339c1f"
dependencies:
"@types/node" "*"

"@types/node@*":
version "10.1.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.1.3.tgz#5c16980936c4e3c83ce64e8ed71fb37bd7aea135"

agent-base@2:
version "2.1.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-2.1.1.tgz#d6de10d5af6132d5bd692427d46fc538539094c7"
Expand Down Expand Up @@ -1450,7 +1460,7 @@ minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

mkdirp@^0.5.0:
mkdirp@^0.5.0, mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
Expand Down

0 comments on commit ac7372b

Please sign in to comment.