Browse Source

feat(scripts/upgrade): prompt for update if metadata cannot be found

if the latest.json cannot be found the upgrade script used to bomb. now it will prompt upgrade
instead
pull/149/head
Josh Habdas 2 years ago
parent
commit
db3216df5d
Signed by: jhabdas GPG Key ID: B148B31154C75A74
2 changed files with 28 additions and 16 deletions
  1. +17
    -11
      bin/upgrade
  2. +11
    -5
      docs/content/feature/upgrade-script.md

+ 17
- 11
bin/upgrade View File

@ -17,23 +17,29 @@ generate_help_docs () {
update_module () {
meta_file=themes/"$1"/data/npm/latest.json
current_vers=`sed -n 's/.*"version":"\([^"]*\).*/\1/p' < "$meta_file"`
if ! [ -f "$meta_file" ] ; then
echo "Error: Unable to locate metadata for $1. Cannot proceed with upgrade." >&2; exit 1
if [ -f "$meta_file" ] ; then
current_vers=`sed -n 's/.*"version":"\([^"]*\).*/\1/p' < "$meta_file"`
else
LATEST_META=$(wget -qO - https://registry.npmjs.org/"$1"/latest)
latest_vers=`sed -n 's/.*"version":"\([^"]*\).*/\1/p' <<< "$LATEST_META"`
echo "Cannot detect version. Upgrade $1 anyway (y/n)? \c"
read answer
[ "$answer" = "${answer#[Yy]}" ] && exit 1
fi
LATEST_META=$(wget -qO - https://registry.npmjs.org/"$1"/latest)
latest_vers=`sed -n 's/.*"version":"\([^"]*\).*/\1/p' <<< "$LATEST_META"`
if [ "$current_vers" ] ; then
if [ "$current_vers" = "$latest_vers" ] ; then
echo "Did not upgrade $1. Already using latest version." >&1; exit 0
else
echo "Starting upgrade from $current_vers to $latest_vers ..."
rm -rf themes/"$1"/*
wget -qO - https://registry.npmjs.org/"$1"/-/"$1"-"$latest_vers".tgz | tar --strip-components=1 -xz -C themes/"$1"
echo "Version $latest_vers downloaded to themes/$1"
[ "$1" = "after-dark" ] && generate_help_docs
echo "Upgrade complete! Please see CHANGELOG.md for changes."
echo "Upgrading $1 from $current_vers to $latest_vers ..."
fi
else
echo "Upgrading $1 from unknown version to $latest_vers ..."
fi
rm -rf themes/"$1"/* # maintains dotfiles, e.g. git and env
wget -qO - https://registry.npmjs.org/"$1"/-/"$1"-"$latest_vers".tgz | tar --strip-components=1 -xz -C themes/"$1"
echo "Version $latest_vers downloaded to themes/$1"
[ "$1" = "after-dark" ] && generate_help_docs
echo "Upgrade complete! Please see CHANGELOG.md for changes."
}
set -e

+ 11
- 5
docs/content/feature/upgrade-script.md View File

@ -6,10 +6,6 @@ tags = ["updating", "installation", "scripts"]
features = ["code highlighter", "related content"]
+++
{{< hackcss-alert type="info" >}}
<strong>Note:</strong> Use of the upgrade script requires After Dark version 6.7.5 or better. If you're running an earlier version please follow {{< external href="https://git.habd.as/comfusion/after-dark/commit/6415250769c9c78338893f98b5ab9b77968053f7" text="these steps" />}} first.
{{< /hackcss-alert >}}
To check for updates and automatically upgrade to the latest version simply run the upgrade script from your site directory:
```sh
@ -33,4 +29,14 @@ Generating help documentation ...
Upgrade complete! Please see CHANGELOG.md for changes.</samp>
{{< /hackcss-alert >}}
Upon upgrade the [Release Hash](../release-hashes) will change for accurate [Release Validation](/validate).
If current version can't be detected the script will prompt you:
{{< hackcss-alert >}}
<samp>Cannot detect version. Upgrade after-dark anyway (y/n)? y<br>
Starting upgrade from 6.7.6 to 6.8.0 ...<br>
Version 6.8.0 downloaded to themes/after-dark<br>
Generating help documentation ...<br>
Upgrade complete! Please see CHANGELOG.md for changes.</samp>
{{< /hackcss-alert >}}
Upon upgrade the [Release Hash](../release-hashes) will update for proper [Release Validation](/validate).

Loading…
Cancel
Save