Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(index-BS4): added script for creation demo/src/index-BS4.html file #1278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build": "ngm build -p src",
"start": "ng serve",
"pretest": "run-s build link",
"generate-bs4": "node scripts/generate-bs4.js",
"test": "ng test --watch false",
"preversion": "npm test",
"wm-update": "webdriver-manager update",
Expand Down
52 changes: 52 additions & 0 deletions scripts/generate-bs4.js
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');
})
});
});