11cb0ef41Sopenharmony_ci#!/bin/sh
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci# Shell script to update acorn 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 dist-tags.latest)
161cb0ef41Sopenharmony_ciCURRENT_VERSION=$("$NODE" -p "require('./deps/acorn/acorn/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 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
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci(
301cb0ef41Sopenharmony_ci    rm -rf acorn-tmp
311cb0ef41Sopenharmony_ci    mkdir acorn-tmp
321cb0ef41Sopenharmony_ci    cd acorn-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@$NEW_VERSION"
371cb0ef41Sopenharmony_ci)
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci# update version information in src/acorn_version.h
401cb0ef41Sopenharmony_cicat > "$ROOT/src/acorn_version.h" <<EOF
411cb0ef41Sopenharmony_ci// This is an auto generated file, please do not edit.
421cb0ef41Sopenharmony_ci// Refer to tools/update-acorn.sh
431cb0ef41Sopenharmony_ci#ifndef SRC_ACORN_VERSION_H_
441cb0ef41Sopenharmony_ci#define SRC_ACORN_VERSION_H_
451cb0ef41Sopenharmony_ci#define ACORN_VERSION "$NEW_VERSION"
461cb0ef41Sopenharmony_ci#endif  // SRC_ACORN_VERSION_H_
471cb0ef41Sopenharmony_ciEOF
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_cimv acorn-tmp/node_modules/acorn deps/acorn
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_cirm -rf acorn-tmp/
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciecho "All done!"
541cb0ef41Sopenharmony_ciecho ""
551cb0ef41Sopenharmony_ciecho "Please git add acorn, commit the new version:"
561cb0ef41Sopenharmony_ciecho ""
571cb0ef41Sopenharmony_ciecho "$ git add -A deps/acorn src/acorn_version.h"
581cb0ef41Sopenharmony_ciecho "$ git commit -m \"deps: update acorn to $NEW_VERSION\""
591cb0ef41Sopenharmony_ciecho ""
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci# The last line of the script should always print the new version,
621cb0ef41Sopenharmony_ci# as we need to add it to $GITHUB_ENV variable.
631cb0ef41Sopenharmony_ciecho "NEW_VERSION=$NEW_VERSION"
64