-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(index-BS4): added script for creation demo/src/index-BS4.html file
- Loading branch information
1 parent
b81ba43
commit 4b51e13
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const fs = require('fs'); | ||
|
||
const files = { | ||
initial: 'demo/src/index.html', | ||
generated: 'demo/src/index-bs4.html' | ||
}; | ||
|
||
const toReplace = [ | ||
{ | ||
from: '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">', | ||
to: '<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet">' | ||
}, { | ||
from: '<script src="assets/js/prettify.min.js"></script>', | ||
to: '<script src="assets/js/prettify.min.js"></script>\r\n <!-- Enable bootstrap 4 theme -->\r\n <script>window.__theme = \'bs4\';</script>' | ||
} | ||
]; | ||
|
||
fs.readFile(files.initial, 'utf-8', (err, file) => { | ||
if (err) { | ||
console.error(err); | ||
return process.exit(1); | ||
} | ||
|
||
if (file.length === 0) { | ||
console.error('File is empty'); | ||
return process.exit(1); | ||
} | ||
|
||
toReplace.forEach(pair => { | ||
file = file.replace(pair.from, pair.to); | ||
}); | ||
|
||
fs.open(files.generated, 'w', (err, newFileDescriptor) => { | ||
if (err) { | ||
console.error(err); | ||
return process.exit(1); | ||
} | ||
|
||
if (!newFileDescriptor) { | ||
console.error('File creation error'); | ||
return process.exit(1); | ||
} | ||
|
||
fs.writeFile(newFileDescriptor, file, 'utf8', (err) => { | ||
if (err) { | ||
console.error(err); | ||
return process.exit(1); | ||
} | ||
console.log('File successfully created'); | ||
}) | ||
}); | ||
}); |