Add Rake task :version

For updating all hard-coded version numbers from `package.json`
This commit is contained in:
iBug 2024-05-05 05:52:08 +08:00
parent f33349c2ee
commit 7e7b901974
6 changed files with 38 additions and 13 deletions

View File

@ -126,17 +126,12 @@ To install:
<!--
Dev note: The version number is currently hard-coded in these files:
- README.md (this file)
- package.json
- README.md (this file)
- docs/_config.yml (as theme_version)
- docs/_pages/home.md (in Front Matter "excerpt")
For every release, files listed above should be manually updated with the new version number.
Additionally, the license year is hard-coded in these files:
- README.md (this file, near the end)
- LICENSE
`package.json` holds the authoritative version number, and the others can be updated with `bundle exec rake version`.
The following files should also be regenerated:
@ -144,7 +139,12 @@ To install:
(Run `bundle exec rake clean` then `bundle exec rake copyright` - all three references `package.json`)
- assets/js/main.min.js (Run `bundle exec rake js`, references `_includes/copyright.js`)
Tip: The default Rake task will update all of the above files at once.
*Tip*: The default Rake task will update all of the above files at once.
Additionally, the license year is hard-coded in these files and are NOT covered by a Rake task:
- README.md (this file, near the end)
- LICENSE
-->
**Looking for an example?** Use the [Minimal Mistakes remote theme starter](https://github.com/mmistakes/mm-github-pages-starter/generate) for the quickest method of getting a GitHub Pages hosted site up and running. Generate a new repository from the starter, replace sample content with your own, and configure as needed.

View File

@ -7,7 +7,7 @@ require "shellwords"
require "time"
require "yaml"
task :default => [:copyright, :changelog, :js]
task :default => %i[copyright changelog js version]
package_json = JSON.parse(File.read("package.json"))
@ -106,6 +106,7 @@ file "docs/_docs/18-history.md" => "CHANGELOG.md" do |t|
f.puts "<!--\n Sourced from CHANGELOG.md\n See Rakefile `task :changelog` for details\n-->"
f.puts ""
f.puts "{% raw %}"
# Remove H1
changelog = File.read(t.prerequisites.first).gsub(/^# [^\n]*$/m, "").strip
f.write changelog
f.puts ""
@ -179,3 +180,25 @@ task :watch_js do
rescue ThreadError
end
end
task :version => ["docs/_data/theme.yml", "README.md", "docs/_pages/home.md"]
file "docs/_data/theme.yml" => "package.json" do |t|
theme = { "version" => package_json["version"] }
File.open(t.name, "w") do |f|
f.puts "# for use with in-page templates"
f.puts theme.to_yaml
end
end
file "README.md" => "package.json" do |t|
content = File.read(t.name)
content = content.gsub(/(mmistakes\/minimal-mistakes@)[\d.]+/, '\1' + package_json["version"])
File.write(t.name, content)
end
file "docs/_pages/home.md" => "package.json" do |t|
content = File.read(t.name)
content = content.gsub(/(\breleases\/tag\/|Latest release v)[\d.]+/, '\1' + package_json["version"])
File.write(t.name, content)
end

View File

@ -6,7 +6,6 @@
# `jekyll serve`. If you change this file, please restart the server process.
remote_theme : "mmistakes/minimal-mistakes@master"
theme_version : "4.25.1" # for use with in-page templates
minimal_mistakes_skin : "default" # "air", "aqua", "contrast", "dark", "dirt", "neon", "mint", "plum", "sunrise"

3
docs/_data/theme.yml Normal file
View File

@ -0,0 +1,3 @@
# for use with in-page templates
---
version: 4.25.1

View File

@ -78,7 +78,7 @@ To install as a remote theme:
bundle
```
4. Add `remote_theme: "mmistakes/minimal-mistakes@{{ site.theme_version }}"` to your `_config.yml` file. Remove any other `theme:` or `remote_theme:` entry.
4. Add `remote_theme: "mmistakes/minimal-mistakes@{{ site.data.theme.version }}"` to your `_config.yml` file. Remove any other `theme:` or `remote_theme:` entry.
You may also optionally specify a branch, [tag](https://github.com/mmistakes/minimal-mistakes/tags), or commit to use by appending an @ and the Git ref (e.g., `mmistakes/minimal-mistakes@4.9.0` or `mmistakes/minimal-mistakes@bbf3cbc5fd64a3e1885f3f99eb90ba92af84063d`). This is useful when rolling back to older versions of the theme. If you don't specify a Git ref, the latest on `master` will be used.

View File

@ -23,7 +23,7 @@ Simply run `bundle update` if you're using Bundler (have a `Gemfile`) or `gem up
When using Bundler you can downgrade or lock the theme to a specific release ([tag][tag]), branch, or commit. Instead of `gem "minimal-mistakes-jekyll"` you'd add the following to your `Gemfile`:
```ruby
gem "minimal-mistakes-jekyll", :git => "https://github.com/mmistakes/minimal-mistakes.git", :tag => "{{ site.theme_version }}"
gem "minimal-mistakes-jekyll", :git => "https://github.com/mmistakes/minimal-mistakes.git", :tag => "{{ site.data.theme.version }}"
```
[tag]: https://github.com/mmistakes/minimal-mistakes/tags
@ -32,7 +32,7 @@ For more information on [installing gems from Git repositories](https://bundler.
## Remote theme
When setting `remote_theme: "mmistakes/minimal-mistakes@{{ site.theme_version }}"` in your `_config.yml` you may also optionally specify a branch, [tag][tag], or commit to use by appending an @ and the Git ref.
When setting `remote_theme: "mmistakes/minimal-mistakes@{{ site.data.theme.version }}"` in your `_config.yml` you may also optionally specify a branch, [tag][tag], or commit to use by appending an @ and the Git ref.
For example, you can roll back to release 4.8.1 with `mmistakes/minimal-mistakes@4.8.1` or a specific commit with `mmistakes/minimal-mistakes@bbf3cbc5fd64a3e1885f3f99eb90ba92af84063d`). For a complete list of theme versions consult the [releases page](https://github.com/mmistakes/minimal-mistakes/releases).