🚀 Chore: migrate build scripts to fixit-releaser dev dependency

This commit is contained in:
Cell
2024-09-06 20:21:03 +08:00
parent b64908c9e2
commit de0dae97c1
8 changed files with 53 additions and 252 deletions
+1 -1
View File
@@ -1 +1 @@
node build/update-version.js --stage commit
npx fixit-releaser version --dev
-19
View File
@@ -1,19 +0,0 @@
{
"output": "CHANGELOG.md",
"template": "build/changelog/template.hbs",
"handlebarsSetup": "build/changelog/setup.cjs",
"sortCommits": "relevance",
"commitLimit": false,
"ignoreCommitPattern": "(Chore|chore):|\\(ignore\\)",
"replaceText": {
"^(Feat|feat):": ":sparkles: Feat:",
"^(Fix|fix):": ":bug: Fix:",
"^(Build|build):": ":hammer: Build:",
"^(Refactor|refactor):": ":recycle: Refactor:",
"^(Style|style):": ":lipstick: Style:",
"^(Perf|perf):": ":zap: Perf:",
"^(Test|test):": ":white_check_mark: Test:",
"^(Docs|docs):": ":memo: Docs:",
"^(Chore|chore):": ":wrench: Chore:"
}
}
-31
View File
@@ -1,31 +0,0 @@
// Custom Handlebars helpers
module.exports = function (Handlebars) {
/**
* Handlebars helper to replace a string with another string
* @param {String} context the string to replace
* @param {Object} options
* @param {String} options.hash.from the string to replace
* @param {String} options.hash.to the string to replace with
* @example {{replace "foo bar" from="foo" to="baz"}} => "baz bar"
*/
Handlebars.registerHelper('replace', function (context, options) {
return context.replace(options.hash.from, options.hash.to)
})
/**
* Handlebars helper to convert a name to a GitHub username
* @param {String} context name to convert
* @param {Object} options
* @param {Boolean} [options.hash.linked=true] whether to return a linked username
* @example {{githubUser "Cell"}} => "Lruihao"
*/
Handlebars.registerHelper('githubUser', function (context, { hash: { linked = false }}) {
const map = {
'Cell': "Lruihao",
}
const username = map[context] || context
if (linked) {
return `[@${username}](https://github.com/${username})`
}
return `@${username}`
})
}
-70
View File
@@ -1,70 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
{{!-- if need, set replaceText in config.json "#(\\d+)": "[#$1](https://github.com/hugo-fixit/FixIt/issues/$1)" --}}
{{#each releases}}
{{#if href}}
## [{{title}}]({{href}}){{#if tag}} - {{isoDate}}{{/if}}
{{else}}
## {{title}}{{#if tag}} - {{isoDate}}{{/if}}
{{/if}}
{{#if summary}}
{{summary}}
{{/if}}
{{!-- List commits with `Breaking change: ` somewhere in the message --}}
{{#commit-list commits heading='### :boom: Breaking Changes' message='(:boom:|Breaking change:|BREAKING CHANGE:)'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}
{{!-- List commits that add new features, but exclude those that have `:sparkles:` in the message --}}
{{#commit-list commits heading='### :tada: New Features' message='(:tada:|Feat:|feat:)' exclude='^:sparkles:'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}
{{!-- List commits that enhance existing features, but exclude those that have `:tada:` in the message --}}
{{#commit-list commits heading='### :sparkles: Enhancements' message='(:sparkles:|Feat:|feat:|Perf:|perf:)' exclude='^:tada:'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}
{{!-- List commits that bug fixes --}}
{{#commit-list commits heading='### :bug: Bug Fixes' message='(:bug:|Fix:|fix:)'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}
{{!-- List commits that improve the documentation --}}
{{#commit-list commits heading='### :memo: Documentation' message='(:memo:|Docs:|docs:)'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}
{{!-- List other changes commits --}}
{{#commit-list commits heading='### :wrench: Other Changes' message='(Refactor:|refactor:|Style:|style:|Test:|test:|Chore:|chore:|Build:|build:)'}}
- {{subject}} [`{{shorthash}}`]({{href}}) by {{githubUser author}}
{{/commit-list}}
**Full Changelog**: {{href}}
---
### Uncategorized
{{#if merges}}
#### Merged pull requests
{{#each merges}}
{{!-- {{#if href}}[`#{{id}}`]({{href}}){{/if}} --}}
- {{#if commit.breaking}}**Breaking change:** {{/if}}{{message}} by {{githubUser author}} in {{#if id}}#{{id}}{{/if}}
{{/each}}
{{/if}}
{{#if fixes}}
#### Closed issues
{{#each fixes}}
- {{#if commit.breaking}}**Breaking change:** {{/if}}{{commit.subject}}{{#each fixes}} {{#if id}}#{{id}}{{/if}}{{/each}} by {{githubUser commit.author}}
{{/each}}
{{/if}}
{{/each}}
-61
View File
@@ -1,61 +0,0 @@
import fs from 'fs';
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import { execSync } from 'child_process';
// 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/',
'i18n/',
'layouts/',
'static/',
'go.mod',
'hugo.toml',
'package.json',
'package-lock.json',
'theme.toml',
];
const gitDiff = execSync('git diff --cached --name-only').toString().trim();
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)), '../');
const initHtmlPath = join(__root, 'layouts/partials/init/index.html');
const packageJsonPath = join(__root, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const version = packageJson.version;
// Get the short hash of the last commit (can not get this commit hash at pre-commit hook)
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}`;
const initHtml = fs.readFileSync(initHtmlPath, 'utf8');
const latestVersion = stage === 'version' ? version : devVersion;
const lastVersion = initHtml.match(/v\d+\.\d+\.\d+(-\w+)?/)[0].slice(1);
const newInitHtml = initHtml.replace(/v\d+\.\d+\.\d+(-\w+)?/, `v${latestVersion}`);
if (lastVersion === version && gitDiff.includes('layouts/partials/init/index.html')) {
// After running `npm version` or manually modifying the version number, skip the update
console.log(`The FixIt version has been updated to v${lastVersion}.`);
process.exit(0);
}
// Update the version number in layouts/partials/init/index.html
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');
console.log(`Update the FixIt version from v${lastVersion} to v${latestVersion}.`);
export default latestVersion;
+1 -1
View File
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.12-1ca9fdb7" -}}
{{- .Scratch.Set "version" "v0.3.12-788f8b7f" -}}
{{- .Scratch.Set "this" dict -}}
{{- partial "init/detection-env.html" . -}}
+48 -66
View File
@@ -9,10 +9,22 @@
"version": "0.3.11",
"license": "MIT",
"devDependencies": {
"auto-changelog": "^2.4.0",
"@hugo-fixit/fixit-releaser": "^1.0.1",
"husky": "^9.1.4"
}
},
"node_modules/@hugo-fixit/fixit-releaser": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@hugo-fixit/fixit-releaser/-/fixit-releaser-1.0.1.tgz",
"integrity": "sha512-hYCxiwm3eeUNYXbWvan3AhBFbsAdPmk8Ys/3jn02QJzOqKtCxyHloKeM/80EkrBTCXAw//0DJVS+zBMw2cl31A==",
"dev": true,
"dependencies": {
"auto-changelog": "^2.4.0"
},
"bin": {
"fixit-releaser": "scripts/cli.js"
}
},
"node_modules/auto-changelog": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/auto-changelog/-/auto-changelog-2.4.0.tgz",
@@ -63,9 +75,9 @@
}
},
"node_modules/husky": {
"version": "9.1.4",
"resolved": "https://registry.npmjs.org/husky/-/husky-9.1.4.tgz",
"integrity": "sha512-bho94YyReb4JV7LYWRWxZ/xr6TtOTt8cMfmQ39MQYJ7f/YE268s3GdghGwi+y4zAeqewE5zYLvuhV0M0ijsDEA==",
"version": "9.1.5",
"resolved": "https://registry.npmjs.org/husky/-/husky-9.1.5.tgz",
"integrity": "sha512-rowAVRUBfI0b4+niA4SJMhfQwc107VLkBUgEYYAOQAbqDCnra1nYh83hF/MDmhYs9t9n1E3DuKOrs2LYNC+0Ag==",
"dev": true,
"bin": {
"husky": "bin.js"
@@ -77,18 +89,6 @@
"url": "https://github.com/sponsors/typicode"
}
},
"node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/minimist": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
@@ -125,25 +125,22 @@
}
},
"node_modules/parse-github-url": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/parse-github-url/-/parse-github-url-1.0.2.tgz",
"integrity": "sha512-kgBf6avCbO3Cn6+RnzRGLkUsv4ZVqv/VfAYkRsyBcgkshNvVBkRn1FEZcW0Jb+npXQWm2vHPnnOqFteZxRRGNw==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/parse-github-url/-/parse-github-url-1.0.3.tgz",
"integrity": "sha512-tfalY5/4SqGaV/GIGzWyHnFjlpTPTNpENR9Ea2lLldSJ8EWXMsvacWucqY3m3I4YPtas15IxTLQVQ5NSYXPrww==",
"dev": true,
"bin": {
"parse-github-url": "cli.js"
},
"engines": {
"node": ">=0.10.0"
"node": ">= 0.10"
}
},
"node_modules/semver": {
"version": "7.6.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz",
"integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==",
"version": "7.6.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
"integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
@@ -167,9 +164,9 @@
"dev": true
},
"node_modules/uglify-js": {
"version": "3.17.4",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz",
"integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==",
"version": "3.19.3",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.3.tgz",
"integrity": "sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==",
"dev": true,
"optional": true,
"bin": {
@@ -200,15 +197,18 @@
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
"integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==",
"dev": true
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}
},
"dependencies": {
"@hugo-fixit/fixit-releaser": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@hugo-fixit/fixit-releaser/-/fixit-releaser-1.0.1.tgz",
"integrity": "sha512-hYCxiwm3eeUNYXbWvan3AhBFbsAdPmk8Ys/3jn02QJzOqKtCxyHloKeM/80EkrBTCXAw//0DJVS+zBMw2cl31A==",
"dev": true,
"requires": {
"auto-changelog": "^2.4.0"
}
},
"auto-changelog": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/auto-changelog/-/auto-changelog-2.4.0.tgz",
@@ -242,20 +242,11 @@
}
},
"husky": {
"version": "9.1.4",
"resolved": "https://registry.npmjs.org/husky/-/husky-9.1.4.tgz",
"integrity": "sha512-bho94YyReb4JV7LYWRWxZ/xr6TtOTt8cMfmQ39MQYJ7f/YE268s3GdghGwi+y4zAeqewE5zYLvuhV0M0ijsDEA==",
"version": "9.1.5",
"resolved": "https://registry.npmjs.org/husky/-/husky-9.1.5.tgz",
"integrity": "sha512-rowAVRUBfI0b4+niA4SJMhfQwc107VLkBUgEYYAOQAbqDCnra1nYh83hF/MDmhYs9t9n1E3DuKOrs2LYNC+0Ag==",
"dev": true
},
"lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"requires": {
"yallist": "^4.0.0"
}
},
"minimist": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
@@ -278,19 +269,16 @@
}
},
"parse-github-url": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/parse-github-url/-/parse-github-url-1.0.2.tgz",
"integrity": "sha512-kgBf6avCbO3Cn6+RnzRGLkUsv4ZVqv/VfAYkRsyBcgkshNvVBkRn1FEZcW0Jb+npXQWm2vHPnnOqFteZxRRGNw==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/parse-github-url/-/parse-github-url-1.0.3.tgz",
"integrity": "sha512-tfalY5/4SqGaV/GIGzWyHnFjlpTPTNpENR9Ea2lLldSJ8EWXMsvacWucqY3m3I4YPtas15IxTLQVQ5NSYXPrww==",
"dev": true
},
"semver": {
"version": "7.6.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz",
"integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
"version": "7.6.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
"integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==",
"dev": true
},
"source-map": {
"version": "0.6.1",
@@ -305,9 +293,9 @@
"dev": true
},
"uglify-js": {
"version": "3.17.4",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz",
"integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==",
"version": "3.19.3",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.3.tgz",
"integrity": "sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==",
"dev": true,
"optional": true
},
@@ -332,12 +320,6 @@
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
"integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==",
"dev": true
},
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}
}
}
+3 -3
View File
@@ -24,13 +24,13 @@
"server": "hugo server --source=demo --themesDir ../.. --theme $PWD -D --disableFastRender --navigateToChanged --ignoreCache",
"server:production": "npm run server -- -e production",
"server:docs": "hugo server --source=../fixit-docs -D --disableFastRender --navigateToChanged --ignoreCache",
"version": "node build/update-version.js --stage version",
"version": "fixit-releaser version --prod",
"postversion": "git push && git push --tags && npm run release",
"release": "auto-changelog --config build/changelog/config.json",
"release": "fixit-releaser changelog",
"prepare": "husky"
},
"devDependencies": {
"auto-changelog": "^2.4.0",
"@hugo-fixit/fixit-releaser": "^1.0.1",
"husky": "^9.1.4"
}
}