Skip to content

Commit

Permalink
change prebuild.js
Browse files Browse the repository at this point in the history
  • Loading branch information
weisser-dev committed Jan 23, 2024
1 parent f441e0c commit 9fe9af6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,6 @@ jobs:
ENCODE_PROFILE_DATA=$(node -pe "require('./src/config/config.json').encodeProfileData")
echo "ENCODE_PROFILE_DATA=$ENCODE_PROFILE_DATA" >> $GITHUB_ENV
- name: Prepare profile data (encodeProfileData= true)
if: env.ENCODE_PROFILE_DATA == 'true'
run: |
if [ -f public/data/b64ProfileData.json ]; then
echo "b64ProfileData.json already exists."
else
if [ -f src/data/profileData.json ]; then
npm run prebuild
else
cp src/data/profileData.template.json src/data/profileData.json
npm run prebuild
fi
fi
- name: Prepare profile data (encodeProfileData= false)
if: env.ENCODE_PROFILE_DATA == 'false'
run: |
if [ ! -f src/data/profileData.json ]; then
cp src/data/profileData.template.json src/data/profileData.json
npm run prebuild
fi
- name: Build project
run: |
PUBLIC_URL="https://$(echo $GITHUB_REPOSITORY | awk -F / '{print tolower($1)}').github.io/$(echo $GITHUB_REPOSITORY | awk -F / '{print tolower($2)}')" npm run build
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ Feel free to fork this project and make it your own. Here's how to deploy your v
2. Customize images to avoid using the default ones, such as my dog's photo.
3. Prepare your data for deployment with `npm run prebuild`.
4. Commit the base64 encoded data file.
5. Deploy to your preferred service, like GitHub Pages (Works out of the box).

5. Deploy to your preferred service, like GitHub Pages (Works out of the box, just enable Actions and give them the correct permissions: Actions -> General -> Workflow -> Read and write permissions ).
6. Enable GH Pages -> Pages -> "Deploy from a branch" -> "gh-pages"
Happy sharing of your professional digital business card!

## Screenshots
Expand Down
45 changes: 29 additions & 16 deletions prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,41 @@ const config = require('./src/config/config.json');

if (config.encodeProfileData) {
const profileDataPath = path.join(__dirname, 'src', 'data', 'profileData.json');
const profileTemplatePath = path.join(__dirname, 'src', 'data', 'profileData.template.json');
const encodedDataPath = path.join(__dirname, 'public', 'data', 'b64ProfileData.json');

// Check if profileData.json exists
if (fs.existsSync(profileDataPath)) {
const profileDataStat = fs.statSync(profileDataPath);
let shouldEncode = true;
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;
// Check if profileData.json exists, if not create it from template
if (!fs.existsSync(profileDataPath)) {
if (fs.existsSync(profileTemplatePath)) {
fs.copyFileSync(profileTemplatePath, profileDataPath);
console.log("No profileData.json existing, generating a new one, please fill out your personal information here, or ignore this log, if your b64ProfileData.json is up to date.");
shouldEncode = false; // The newly created file will be identical to the template
} else {
console.log("profileData.template.json is missing, unable to create profileData.json.");
return;
}
} else if (fs.existsSync(encodedDataPath)) {
const profileDataStat = fs.statSync(profileDataPath);
const encodedDataStat = fs.statSync(encodedDataPath);

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")
// Compare modification times
shouldEncode = profileDataStat.mtime > encodedDataStat.mtime;

// Check if the content of profileData.json is identical to the template
const profileDataContent = fs.readFileSync(profileDataPath, 'utf8');
const templateContent = fs.readFileSync(profileTemplatePath, 'utf8');
if (profileDataContent === templateContent) {
shouldEncode = false;
}
}

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 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.");
console.log("The profile data is up to date and does not need to be encoded.");
}
}

0 comments on commit 9fe9af6

Please sign in to comment.