Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit e6763ff

Browse files
committed
clean up commands/scripts for redoc docs build
1 parent 860eb41 commit e6763ff

File tree

6 files changed

+59
-36
lines changed

6 files changed

+59
-36
lines changed

README.md

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
After cloning this repo...
66

77
```shell
8-
npm install -g . && npm install -g swagger-repo
8+
npm install -g . && npm install -g swagger-repo && npm install -g redoc-cli
99
```
1010

1111
## Set up
@@ -14,19 +14,20 @@ Within a repo directory that contains an OpenAPI spec, create a config file name
1414

1515
```json
1616
{
17-
"apiSpecPath": "openapi/swagger.yaml",
17+
"apiSpecPath": "openapi/openapi.yaml",
1818
"contactUrl": ""
1919
}
2020
```
2121

22+
**Note:** an OpenAPI spec for testing can be found at [`test/test-spec/combined/openapi.yaml`](test/test-spec/combined/openapi.yaml).
23+
2224
## Outputs
2325

24-
This package is designed to create artifacts in the following locations:
26+
This package is designed to create artifacts in the following path(s):
2527

26-
- `{branchPath}/docs/` (not currently implemented; might be replaced by ReDoc)
27-
- `{branchPath}/swagger-ui/` (might be replaced by ReDoc)
28-
- `{branchPath}/redoc-ui/` (not currently implemented)
29-
- `shared/` (common assets to use for Swagger UI; might be irrelevant with switch to ReDoc)
28+
- `{branchPath}/docs/index.html`
29+
- `{branchPath}/openapi.json`
30+
- `{branchPath}/openapi.yaml`
3031

3132
Where `branchPath` is the repo root if the current branch is `master`, otherwise `preview/<branchName>`.
3233

@@ -41,7 +42,7 @@ gh-openapi-docs
4142
You should see console logs that look like this:
4243

4344
```shell
44-
{ apiSpecPath: 'openapi/swagger.yaml',
45+
{ apiSpecPath: 'openapi/openapi.yaml',
4546
docsRoot: 'docs',
4647
uiRoot: 'swagger-ui',
4748
redocRoot: 'redoc-ui',
@@ -52,32 +53,34 @@ You should see console logs that look like this:
5253
abbreviatedSha: '<abbreviated-commit-sha>',
5354
branch: 'develop',
5455
tag: null,
55-
committer: null,
56-
committerDate: null,
57-
author: null,
58-
authorDate: null,
59-
commitMessage: null,
60-
root:
61-
'<repo-path>',
62-
commonGitDir:
63-
'<repo-path>/.git',
64-
worktreeGitDir:
65-
'<repo-path>/.git',
56+
committer: 'James Eddy <[email protected]>',
57+
committerDate: '2020-03-13T05:25:03.000Z',
58+
author: 'James Eddy <[email protected]>',
59+
authorDate: '2020-03-13T05:25:03.000Z',
60+
commitMessage: 'replace swagger-ui and docs with redoc (for both)',
61+
root: '<repo-path>',
62+
commonGitDir: '<repo-path>/.git',
63+
worktreeGitDir: '<repo-path>/.git',
6664
lastTag: null,
67-
commitsSinceLastTag: Infinity,
65+
commitsSinceLastTag: 0,
6866
env: undefined,
6967
repoOrigin:
7068
'https://github.com/<gh-org>/<repo-name>',
7169
branchPath:
7270
'<repo-path>/preview/develop' }
7371

74-
Preparing docs for API spec at 'openapi/swagger.yaml' (develop)
72+
Preparing docs for API spec at 'openapi/openapi.yaml' (develop)
7573
Cloning 'gh-pages' branch into '<repo-path>/.ghpages-tmp'
7674
Cloning into '.'...
77-
7875
...
76+
Branch folder:
77+
<repo-path>/preview/use-redoc
78+
Spec location:
79+
<repo-path>/openapi/openapi.yaml
7980

8081
Bundling API spec...
82+
Storing to:
83+
<repo-path>/preview/develop/openapi.json
8184

8285
> <repo-name>[email protected] swagger <repo-path>
8386
> swagger-repo "bundle" "-o" "<repo-path>/preview/develop/openapi.json"
@@ -88,10 +91,16 @@ Created "<repo-path>/preview/develop/openapi.json" openapi file.
8891
> swagger-repo "bundle" "--yaml" "-o" "<repo-path>/preview/develop/openapi.yaml"
8992

9093
Created "<repo-path>/preview/develop/openapi.yaml" openapi file.
91-
Copying Swagger UI index to '<repo-path>/preview/develop/swagger-ui'
92-
Swagger UI folder contents:
94+
Generating OpenAPI docs index at '<repo-path>/preview/develop/docs/index.html'
95+
96+
> <repo-name>[email protected] redoc <repo-path>
97+
> redoc-cli "bundle" "<repo-path>/preview/develop/openapi.yaml" "--output" "<repo-path>/preview/develop/docs/index.html"
98+
99+
Prerendering docs
100+
101+
🎉 bundled successfully in: <repo-path>/preview/use-redoc/docs/index.html (957 KiB) [⏱ 0.234s]
102+
OpenAPI docs folder contents:
93103
index.html
94104

95-
Updating API spec path for '<repo-path>/preview/develop/swagger-ui/index.html'
96-
Done (in 6s.)
105+
Done (in 13s.)
97106
```

lib/bundle.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,34 @@ var OPENAPI_JSON_PATH = path.join(config.branchPath, 'openapi.json');
1111
var OPENAPI_YAML_PATH = path.join(config.branchPath, 'openapi.yaml');
1212

1313
const bundleSpec = async function() {
14-
shell.mkdir('-p', 'spec');
14+
log.preview({
15+
'title': 'Branch folder',
16+
'text': config.branchPath
17+
})
18+
shell.mkdir('-p', config.branchPath);
19+
var specDir = path.join(config.root, 'spec');
20+
shell.mkdir('-p', specDir);
1521

1622
var specPath = path.join(config.root, config.apiSpecPath);
17-
var baseDir = path.dirname(specPath);
18-
shell.cp(specPath, 'spec/openapi.yaml');
23+
log.preview({
24+
'title': 'Spec location',
25+
'text': specPath
26+
})
27+
shell.cp(specPath, path.join(config.root, 'spec/openapi.yaml'));
1928

2029
log.log("\nBundling API spec...");
30+
log.preview({
31+
'title': 'Storing to',
32+
'text': OPENAPI_JSON_PATH
33+
});
2134
shell.exec(
22-
`npm run swagger bundle -- -o ${OPENAPI_JSON_PATH}`
35+
`npm run swagger bundle -- -b ${specDir} -o ${OPENAPI_JSON_PATH}`
2336
);
2437
shell.exec(
25-
`npm run swagger bundle -- --yaml -o ${OPENAPI_YAML_PATH}`
38+
`npm run swagger bundle -- --yaml -b ${specDir} -o ${OPENAPI_YAML_PATH}`
2639
);
27-
shell.rm('-rf', 'spec');
40+
shell.rm('-rf', specDir);
2841
};
2942

43+
bundleSpec();
3044
module.exports.bundleSpec = bundleSpec;

lib/gh-pages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const fetchPages = function() {
1616
shell.exec(`git clone --depth=1 --branch=gh-pages ${config.repoOrigin} .`);
1717
shell.cp('-Rn', '.', config.root)
1818
shell.cd(startDir);
19-
rm('-rf', '.ghpages-tmp')
19+
shell.rm('-rf', '.ghpages-tmp')
2020
};
2121

2222
// TODO: add logic to move all rendered artifacts to correct location

lib/redoc-ui.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const setupUI = function() {
1515
var indexPath = path.join(uiPath, 'index.html');
1616
log.log(`Generating OpenAPI docs index at '${indexPath}'`);
1717
shell.exec(
18-
`npm run redoc -- ${OPENAPI_YAML_PATH} --output ${indexPath}`
18+
`npm run redoc bundle -- ${OPENAPI_YAML_PATH} --output ${indexPath}`
1919
);
2020
log.preview({
2121
'title': 'OpenAPI docs folder contents',

lib/tasks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const runTasks = function(opts, di) {
1717

1818
console.log(container.config);
1919
log.obtrusive(`Preparing docs for API spec at '${container.config.apiSpecPath}' (${container.config.branch})`);
20-
// fetchPages();
20+
fetchPages();
2121
bundleSpec();
2222
setupUI();
2323

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"scripts": {
2727
"fetch": "node src/fetchpages.js",
2828
"swagger": "swagger-repo",
29-
"redoc": "redoc-cli bundle",
29+
"redoc": "redoc-cli",
3030
"build:swagger": "node src/swagger-ui.js",
3131
"build:redoc": "node src/redoc-ui.js"
3232
}

0 commit comments

Comments
 (0)