Skip to content

Commit 696bc50

Browse files
committed
Allow to pass data-root to command line
1 parent c737da9 commit 696bc50

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

bin/generate.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ program
1010
.option('-c, --config <location>', 'Location of the exported Insomnia JSON config.')
1111
.option('-l, --logo <location>', 'Project logo location (48x48px PNG).')
1212
.option('-o, --output <location>', 'Where to save the file (defaults to current working directory).')
13+
.option('-d, --data-root <docs-root>', 'Docs root for the API documentation.', '')
1314
.parse(process.argv);
1415

15-
const { config, logo, output } = program;
16+
const { config, logo, output, dataRoot } = program;
1617

1718
if (!config) {
1819
console.log('You must provide an exported Insomnia config (Preferences -> Data -> Export Data -> Current Workspace).');
@@ -47,6 +48,19 @@ mkdirp(outputPath, err => {
4748
fs.copyFileSync(logoPath, path.join(outputPath, 'logo.png'));
4849
}
4950

51+
try {
52+
const data = fs.readFileSync(path.join(outputPath, 'index.html'), 'utf8')
53+
var result = data.replace('DATAROOT', dataRoot);
54+
} catch (err) {
55+
console.error(err)
56+
}
57+
58+
try {
59+
fs.writeFileSync(path.join(outputPath, 'index.html'), result)
60+
} catch (err) {
61+
console.error(err)
62+
}
63+
5064
console.log('\n * * * Done! * * *\nYour documentation has been created and it\'s ready to be deployed!');
5165

5266
process.exit();

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
</head>
1313
<body>
1414
<noscript>In order to view this documentation page, you have to enable JavaScript in your web browser.</noscript>
15-
<div id="app"></div>
15+
<div id="app" data-root="DATAROOT"></div>
1616
</body>
1717
</html>

0 commit comments

Comments
 (0)