2023-05-21 11:59:27 +00:00
|
|
|
const fs = require('fs');
|
2023-05-23 13:31:23 +00:00
|
|
|
// const path = require('path');
|
|
|
|
const readline = require('readline')
|
2023-05-21 11:59:27 +00:00
|
|
|
|
2023-05-23 13:31:23 +00:00
|
|
|
const files = ["src/index.html",
|
2023-05-23 13:55:01 +00:00
|
|
|
"src/projects/2016-XXXX.html",
|
|
|
|
"src/projects/2023-Pepperstone.html"]; // this list should be generated.
|
2023-05-23 13:31:23 +00:00
|
|
|
|
|
|
|
files.forEach( file => {
|
|
|
|
var file_buffer = "";
|
|
|
|
|
|
|
|
const rl = readline.createInterface({
|
|
|
|
input: fs.createReadStream(file),
|
|
|
|
output: process.stdout,
|
|
|
|
terminal: false
|
|
|
|
});
|
|
|
|
|
|
|
|
const re = new RegExp('{% include \'*(.*)\' %}');
|
|
|
|
|
|
|
|
rl.on('line', line => {
|
|
|
|
const match = line.match(re);
|
|
|
|
if (match) {
|
|
|
|
file_buffer += fs.readFileSync(match[1], 'utf8');
|
|
|
|
} else {
|
|
|
|
file_buffer += line + "\n";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
rl.on('close', () => {
|
2023-05-23 13:55:01 +00:00
|
|
|
ensureDirectoryExists('build/' + file.split('/').slice(1).join('/')); // all this quatch is to remove the /src/.
|
2023-05-23 13:31:23 +00:00
|
|
|
fs.writeFileSync('build/' + file.split('/').slice(1).join('/'), file_buffer, 'utf8');
|
|
|
|
});
|
2023-05-21 11:59:27 +00:00
|
|
|
});
|
2023-05-23 13:31:23 +00:00
|
|
|
|
|
|
|
fs.cp('./src/styles','./build/styles', { recursive: true }, (err) => {
|
|
|
|
if (err) throw err;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function ensureDirectoryExists(filePath) {
|
|
|
|
var dirname = filePath.split('/').slice(0,-1).join('/');
|
|
|
|
if (fs.existsSync(dirname)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ensureDirectoryExists(dirname);
|
|
|
|
fs.mkdirSync(dirname);
|
|
|
|
}
|