-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathfix-title.js
31 lines (24 loc) · 975 Bytes
/
fix-title.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const fs = require('fs');
const path = require('path');
function fixTitle(filePath, title) {
const htmlDocumentPath = path.resolve(__dirname, filePath);
const htmlDocument = fs.readFileSync(htmlDocumentPath, 'utf-8');
const updatedHtmlDocument = htmlDocument.replace(/<title>.*<\/title>/, `<title>${title}</title>`);
fs.writeFileSync(htmlDocumentPath, updatedHtmlDocument);
}
try {
const args = process.argv.slice(2);
const [title, distPath] = args;
const storybookDistPath = `${distPath}/storybook`;
const indexPath = `${storybookDistPath}/index.html`;
const iframePath = `${storybookDistPath}/iframe.html`;
console.log(`Rewriting index.html document title to ${title}.`);
fixTitle(indexPath, title);
console.log(`Rewriting iframe.html document title to ${title}.`);
fixTitle(iframePath, title);
console.log('Title rewrite complete.');
} catch (error) {
console.log('Title rewrite failed.');
console.error(error);
process.exit(1);
}