Skip to content

Commit

Permalink
🔧 Chore: update version automatic update script
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Aug 29, 2024
1 parent 64529c9 commit a67efe4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions build/update-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import { execSync } from 'child_process';

// node build/update-version.js --stage [stage]
// node build/update-version.js --stage [version/commit]
const stage = process.argv[3] || 'commit';
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
const match = [
'archetypes/',
'assets/',
Expand All @@ -18,9 +19,17 @@ const match = [
'theme.toml',
];
const gitDiff = execSync('git diff --cached --name-only').toString().trim();
if (stage !== 'version' && !match.some((item) => gitDiff.includes(item))) {
// console.log('No need to update the FixIt version.');
process.exit(0);

if (stage !== 'version') {
// Avoid conflicts when creating a Pull Request
if (!['dev', 'master'].includes(branch)) {
console.log(`The current branch is ${branch}, no need to update the FixIt version.`);
process.exit(0);
}
if (!match.some((item) => gitDiff.includes(item))) {
console.log('No need to update the FixIt version.');
process.exit(0);
}
}

const __root = join(dirname(fileURLToPath(import.meta.url)), '../');
Expand All @@ -32,12 +41,12 @@ const version = packageJson.version;
const shortHash = execSync('git rev-parse --short HEAD').toString().trim();
// Build the development version v{major}.{minor}.{patch+1}-{shortHash}
const devVersion = `${version.replace(/(\d+)$/, (match, part) => parseInt(part) + 1)}-${shortHash}`;

// Update the version number in layouts/partials/init/index.html
const initHtml = fs.readFileSync(initHtmlPath, 'utf8');
const latestVersion = stage === 'version' ? version : devVersion;
const lastVersion = initHtml.match(/v\d+\.\d+\.\d+(-\w+)?/)[0];
const newInitHtml = initHtml.replace(/v\d+\.\d+\.\d+(-\w+)?/, `v${latestVersion}`);

fs.writeFileSync(initHtmlPath, newInitHtml);
// Add the updated files to the git stage
execSync('git add layouts/partials/init/index.html package.json package-lock.json');
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.10-ede47a2b" -}}
{{- .Scratch.Set "version" "v0.3.10-08d4c12c" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down

0 comments on commit a67efe4

Please sign in to comment.