Skip to content

Commit

Permalink
feat(index-BS4): added script for creation demo/src/index-BS4.html file
Browse files Browse the repository at this point in the history
  • Loading branch information
macroorganizm committed Dec 2, 2016
1 parent b81ba43 commit 4b51e13
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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');
})
});
});

0 comments on commit 4b51e13

Please sign in to comment.