Skip to content

Commit

Permalink
fix prebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
weisser-dev committed Jan 23, 2024
1 parent b75eb27 commit f441e0c
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@ const config = require('./src/config/config.json');

if (config.encodeProfileData) {
const profileDataPath = path.join(__dirname, 'src', 'data', 'profileData.json');
const profileData = fs.readFileSync(profileDataPath, 'utf8');
const encodedData = Buffer.from(profileData).toString('base64');
const encodedDataPath = path.join(__dirname, 'public', 'data', 'b64ProfileData.json');
fs.writeFileSync(encodedDataPath, encodedData);

// Check if profileData.json exists
if (fs.existsSync(profileDataPath)) {
const profileDataStat = fs.statSync(profileDataPath);
let shouldEncode = true;

// Check if b64ProfileData.json exists
if (fs.existsSync(encodedDataPath)) {
const encodedDataStat = fs.statSync(encodedDataPath);
// Compare modification times
shouldEncode = profileDataStat.mtime > encodedDataStat.mtime;
}

if (shouldEncode) {
const profileData = fs.readFileSync(profileDataPath, 'utf8');
const encodedData = Buffer.from(profileData).toString('base64');
fs.writeFileSync(encodedDataPath, encodedData);
} else {
console.log("It seems like you always have a newer b64 encoded profileData.json, to overwrite pls update src/data/profileData.json or remove the generated public/data/b64ProfileData.json")
}
} else {
console.log("It seems like you don't have a src/data/profileData.json yet, copy the profileData.template.json file, rename it to profileData.json, fill out your information and run npm run prebuild.");
}
}

0 comments on commit f441e0c

Please sign in to comment.