Skip to content

Commit d891c5d

Browse files
authored
feat: Add singleFile param to generate everything in one index.html (#62)
1 parent c795802 commit d891c5d

File tree

7 files changed

+2038
-2388
lines changed

7 files changed

+2038
-2388
lines changed

.github/workflows/welcome-first-time-contrib.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Welcome first time contributors
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types:
66
- opened
77
issues:

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ npm install -g @asyncapi/generator
2121
|---|---|---|---|---|
2222
|sidebarOrganization|Defines how the sidebar should be organized. Set its value to `byTagsNoRoot` to categorize operations by operations tags. Set its value to `byTags` when you have tags on a root level. These tags are used to model tags navigation and need to have the same tags in operations.|No|`byTags`, `byTagsNoRoot`|`byTagsNoRoot`|
2323
|baseHref|Sets the base URL for links and forms.|No|*Any*|`/docs`|
24+
|singleFile|Set output into one html-file with styles and scripts inside|No|`true`,`false`|`true`|
2425

2526
## Development
2627

hooks/01_removeNotRelevantParts.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
module.exports = {
5+
'generate:after': generator => {
6+
7+
const params = generator.templateParams;
8+
const singleFile = params.singleFile === 'true';
9+
10+
if (singleFile) {
11+
12+
const jsDir = path.resolve(generator.targetDir, 'js');
13+
const cssDir = path.resolve(generator.targetDir, 'css');
14+
15+
const callback = (error) => {
16+
if (error) {
17+
throw error;
18+
}
19+
};
20+
21+
fs.rmdir(jsDir, {recursive: true}, callback);
22+
fs.rmdir(cssDir, {recursive: true}, callback);
23+
}
24+
}
25+
};

package-lock.json

+1,943-2,384
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
"baseHref": {
7272
"description": "Sets the base URL for links and forms.",
7373
"required": false
74+
},
75+
"singleFile": {
76+
"description": "If set this parameter to true generate single html file with scripts and styles inside",
77+
"required": false,
78+
"default": false
7479
}
7580
},
7681
"generator": ">=0.50.0 <2.0.0",

template/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@
77
{% endif %}
88
<title>{{asyncapi.info().title()}} {{asyncapi.info().version()}} documentation</title>
99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
{% if params.singleFile %}
11+
<style type="text/css">
12+
{% include "template/css/tailwind.min.css" %}
13+
</style>
14+
<style type="text/css">
15+
{% include "template/css/atom-one-dark.min.css" %}
16+
</style>
17+
<style type="text/css">
18+
{% include "template/css/main.css" %}
19+
</style>
20+
{% else %}
1021
<link href="css/tailwind.min.css" rel="stylesheet">
1122
<link rel="stylesheet" href="css/atom-one-dark.min.css" />
1223
<link rel="stylesheet" href="css/main.css" />
24+
{% endif %}
1325
</head>
1426
<body>
1527
<div class="relative md:flex lg:flex xl:flex">
@@ -19,7 +31,14 @@
1931
</div>
2032
<div class="examples-panel absolute pin-t pin-r pin-b"></div>
2133
</div>
34+
{% if params.singleFile %}
35+
<script type="text/javascript">
36+
{% include "template/js/highlight.min.js" %}
37+
{% include "template/js/main.js" %}
38+
</script>
39+
{% else %}
2240
<script src="js/highlight.min.js" type="application/javascript"></script>
2341
<script src="js/main.js" type="application/javascript"></script>
42+
{% endif %}
2443
</body>
2544
</html>

template/js/highlight.min.js

+44-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)