Skip to content

Commit

Permalink
refactor: ⚡ Changed to a JS replace approach
Browse files Browse the repository at this point in the history
  • Loading branch information
JamsRepos committed Jun 2, 2024
1 parent 2b85862 commit 6de82c2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ jobs:

- name: Run semantic-release
id: release
run: npm run semantic-release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: npm run semantic-release
14 changes: 5 additions & 9 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ const config = {
[
"@semantic-release/exec",
{
prepareCmd: 'echo "${nextRelease.version}" > VERSION.txt',
prepareCmd: `
echo "Branch: ${branch}"
`,
successCmd: `
echo "\${nextRelease.version}" > VERSION.txt &&
echo "Updating CDN links to version \${nextRelease.version}" &&
for file in $(find . -name "README.md" -o -name "complete.css"); do
sed -i "s|https://cdn.jsdelivr.net/gh/JamsRepos/Jamfin@[0-9.]*|https://cdn.jsdelivr.net/gh/JamsRepos/Jamfin@\${nextRelease.version}|g" "$file"
done
node replace-version.js \${nextRelease.version} .
`
},
],
Expand Down Expand Up @@ -72,11 +73,6 @@ const config = {
{
assets: ["CHANGELOG.md", "VERSION.txt", "README.md", "theme/complete.css"],
message: "chore: 🧹 \${nextRelease.version}\n\n\${nextRelease.notes}",
gitPushArgs: [
"--follow-tags",
"--set-upstream origin main"
],
gitCredentials: `https://${process.env.GH_TOKEN}@github.com/JamsRepos/Jamfin.git`
},
],
],
Expand Down
27 changes: 27 additions & 0 deletions replace.version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require('fs');
const path = require('path');

const version = process.argv[2];
const directory = process.argv[3];

const replaceInFile = (filePath) => {
const content = fs.readFileSync(filePath, 'utf8');
const updatedContent = content.replace(/https:\/\/cdn\.jsdelivr\.net\/gh\/JamsRepos\/Jamfin@[0-9.]*/g, `https://cdn.jsdelivr.net/gh/JamsRepos/Jamfin@${version}`);
if (content !== updatedContent) {
fs.writeFileSync(filePath, updatedContent, 'utf8');
console.log(`Updated file: ${filePath}`);
}
};

const processDirectory = (dir) => {
fs.readdirSync(dir).forEach(file => {
const fullPath = path.join(dir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
processDirectory(fullPath);
} else if (fullPath.endsWith('README.md') || fullPath.endsWith('complete.css')) {
replaceInFile(fullPath);
}
});
};

processDirectory(directory);
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.5
1.0.7

0 comments on commit 6de82c2

Please sign in to comment.