updating assets and rendering

This commit is contained in:
Jonas Pfalzgraf 2022-08-15 17:58:47 +02:00
parent 977831157f
commit 60bc8c71e9
17 changed files with 106 additions and 104 deletions

View file

@ -1,7 +1,8 @@
var fs = require('fs');
var path = require('path');
var DEPLOY_ENTRY = "./public";
var DEPLOY_TARGET = "./dist";
import * as fs from 'fs';
import * as path from 'path';
const appConfig = JSON.parse(fs.readFileSync('./app.config.json', 'utf8'));
var DEPLOY_ENTRY = "./public/";
var DEPLOY_TARGET = "./dist/";
function deleteFolderRecursive(path: string) {
if (fs.existsSync(path)) {
@ -17,6 +18,39 @@ function deleteFolderRecursive(path: string) {
}
}
function findHtmlFilesRecursive(source: string): string[] {
var files: string[] = [];
var dir = fs.readdirSync(source);
dir.forEach(function(file: any) {
var sourceFile = path.join(source, file);
var stat = fs.lstatSync(sourceFile);
if (stat.isDirectory()) {
files = files.concat(findHtmlFilesRecursive(sourceFile));
} else {
if (path.extname(sourceFile) == '.html') {
files.push(sourceFile);
}
}
});
return files;
}
function replaceKeywordsInHtmlFile(file: string, keywords: string[], values: string[]) {
var content = fs.readFileSync(file, 'utf8');
for (var i = 0; i < keywords.length; i++) {
content = content.replace(new RegExp(keywords[i], 'g'), values[i]);
}
file = file.replace("public\\", DEPLOY_TARGET);
fs.writeFileSync(file, content);
}
function buildHtmlFiles(source: string, keywords: string[], values: string[]) {
var files = findHtmlFilesRecursive(source);
files.forEach(function(file: string) {
replaceKeywordsInHtmlFile(file, keywords, values);
});
}
function mkdirSync(path: string) {
try {
fs.mkdirSync(path);
@ -43,5 +77,6 @@ function copyFiles(source: string, target: string) {
deleteFolderRecursive(DEPLOY_TARGET);
mkdirSync(DEPLOY_TARGET);
copyFiles(DEPLOY_ENTRY, DEPLOY_TARGET);
buildHtmlFiles(DEPLOY_ENTRY, ["{{BET}}"], [appConfig.AppData.name]);
console.log("Deployed to " + DEPLOY_TARGET);