From 4b51e139a98f0f0a8baa14d3e3b8f4a01ce0665c Mon Sep 17 00:00:00 2001 From: "oleg.rybnikov" Date: Wed, 30 Nov 2016 11:15:58 +0200 Subject: [PATCH] feat(index-BS4): added script for creation demo/src/index-BS4.html file --- package.json | 1 + scripts/generate-bs4.js | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 scripts/generate-bs4.js diff --git a/package.json b/package.json index bc6050effd..8ac829346c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/generate-bs4.js b/scripts/generate-bs4.js new file mode 100644 index 0000000000..6d28bd4894 --- /dev/null +++ b/scripts/generate-bs4.js @@ -0,0 +1,52 @@ +const fs = require('fs'); + +const files = { + initial: 'demo/src/index.html', + generated: 'demo/src/index-bs4.html' +}; + +const toReplace = [ + { + from: '', + to: '' + }, { + from: '', + to: '\r\n \r\n ' + } +]; + +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'); + }) + }); +});