11cb0ef41Sopenharmony_ci#!/bin/sh
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci# Shell script to update acorn-walk in the source tree to the latest release.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci# This script must be in the tools directory when it runs because it uses the
61cb0ef41Sopenharmony_ci# script source file path to determine directories to work in.
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciset -ex
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciROOT=$(cd "$(dirname "$0")/../.." && pwd)
111cb0ef41Sopenharmony_ci[ -z "$NODE" ] && NODE="$ROOT/out/Release/node"
121cb0ef41Sopenharmony_ci[ -x "$NODE" ] || NODE=$(command -v node)
131cb0ef41Sopenharmony_ciNPM="$ROOT/deps/npm/bin/npm-cli.js"
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciNEW_VERSION=$("$NODE" "$NPM" view acorn-walk dist-tags.latest)
161cb0ef41Sopenharmony_ciCURRENT_VERSION=$("$NODE" -p "require('./deps/acorn/acorn-walk/package.json').version")
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciecho "Comparing $NEW_VERSION with $CURRENT_VERSION"
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciif [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
211cb0ef41Sopenharmony_ci  echo "Skipped because Acorn-walk is on the latest version."
221cb0ef41Sopenharmony_ci  exit 0
231cb0ef41Sopenharmony_cifi
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cicd "$( dirname "$0" )/../.." || exit
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_cirm -rf deps/acorn/acorn-walk
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci(
301cb0ef41Sopenharmony_ci    rm -rf acorn-walk-tmp
311cb0ef41Sopenharmony_ci    mkdir acorn-walk-tmp
321cb0ef41Sopenharmony_ci    cd acorn-walk-tmp || exit
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci    "$NODE" "$NPM" init --yes
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci    "$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts "acorn-walk@$NEW_VERSION"
371cb0ef41Sopenharmony_ci)
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_cimv acorn-walk-tmp/node_modules/acorn-walk deps/acorn
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_cirm -rf acorn-walk-tmp/
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciecho "All done!"
441cb0ef41Sopenharmony_ciecho ""
451cb0ef41Sopenharmony_ciecho "Please git add acorn-walk, commit the new version:"
461cb0ef41Sopenharmony_ciecho ""
471cb0ef41Sopenharmony_ciecho "$ git add -A deps/acorn-walk"
481cb0ef41Sopenharmony_ciecho "$ git commit -m \"deps: update acorn-walk to $NEW_VERSION\""
491cb0ef41Sopenharmony_ciecho ""
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci# The last line of the script should always print the new version,
521cb0ef41Sopenharmony_ci# as we need to add it to $GITHUB_ENV variable.
531cb0ef41Sopenharmony_ciecho "NEW_VERSION=$NEW_VERSION"
54