Skip to content

Instantly share code, notes, and snippets.

@matb33
Last active August 29, 2015 14:07
Show Gist options
  • Save matb33/de19befd66ff7e4b40a7 to your computer and use it in GitHub Desktop.
Save matb33/de19befd66ff7e4b40a7 to your computer and use it in GitHub Desktop.
Temporary measure to install a different version of Cordova in Meteor
#!/bin/bash
# Make sure to update METEOR_VERSIONS below to point to your app's versions file
TARGET_VERSION=$1
BASEPATH="$(dirname "$0")"
BASEPATH="$(cd "$BASEPATH" && pwd)"
METEOR_VERSIONS=$BASEPATH/../app/.meteor/versions
if [ "$TARGET_VERSION" == "" ]; then
echo "Specify target version. Example: ./install-meteor-cordova.sh 4.0.0"
exit 1
fi
METEOR_TOOL_VER=$(cat $METEOR_VERSIONS | perl -lne 'print $1 if /meteor-tool@([0-9a-z-_\.]+)/')
LIB_PATH=~/.meteor/packages/meteor-tool/$METEOR_TOOL_VER/meteor-tool*/dev_bundle/lib
LIB_PATH=$(cd $(dirname $LIB_PATH); pwd)/$(basename $LIB_PATH)
CORDOVA_PATH="$LIB_PATH/node_modules/cordova"
CURRENT_VERSION=$(cat $CORDOVA_PATH/VERSION)
CORDOVA_PATH_ARCHIVE="$LIB_PATH/cordova-archive"
CORDOVA_PATH_ARCHIVE_CURRENT="$CORDOVA_PATH_ARCHIVE/cordova-$CURRENT_VERSION"
CORDOVA_PATH_ARCHIVE_TARGET="$CORDOVA_PATH_ARCHIVE/cordova-$TARGET_VERSION"
if [ "$CURRENT_VERSION" == "" ]; then
echo "Existing cordova version could not be determined using VERSION file technique."
echo ""
echo "CURRENT_VERSION: $CURRENT_VERSION"
echo "TARGET_VERSION: $TARGET_VERSION"
echo "METEOR_TOOL_VER: $METEOR_TOOL_VER"
echo "LIB_PATH: $LIB_PATH"
echo "CORDOVA_PATH: $CORDOVA_PATH"
echo "CORDOVA_PATH_ARCHIVE_CURRENT: $CORDOVA_PATH_ARCHIVE_CURRENT"
echo "CORDOVA_PATH_ARCHIVE_TARGET: $CORDOVA_PATH_ARCHIVE_TARGET"
exit 3
fi
if [ "$CURRENT_VERSION" == "$TARGET_VERSION" ]; then
echo "Cordova version $TARGET_VERSION already installed."
exit 2
fi
echo "Cordova versions different: is $CURRENT_VERSION, need $TARGET_VERSION."
( set -e; echo "Installing cordova@$TARGET_VERSION..."
mkdir -p "$CORDOVA_PATH_ARCHIVE"
if [ ! -d "$CORDOVA_PATH_ARCHIVE_CURRENT" ]; then
cp -r "$CORDOVA_PATH" "$CORDOVA_PATH_ARCHIVE_CURRENT"
fi
rm -rf "$CORDOVA_PATH"
if [ -d "$CORDOVA_PATH_ARCHIVE_TARGET" ]; then
cp -r "$CORDOVA_PATH_ARCHIVE_TARGET" "$CORDOVA_PATH"
else
cd $LIB_PATH
npm install cordova@$TARGET_VERSION
#npm install "https://github.com/meteor/cordova-cli/tarball/898040e71f6d6900cac4d477986b0451fb196ff1"
echo $TARGET_VERSION > $CORDOVA_PATH/VERSION
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/browser-pack/node_modules/JSONStream/test/fixtures
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/browserify-zlib/node_modules/pako/benchmark
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/browserify-zlib/node_modules/pako/test
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/buffer/perf
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/crypto-browserify/test
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/derequire/node_modules/esprima-fb/test
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/derequire/node_modules/esrefactor/node_modules/esprima/test
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/insert-module-globals/node_modules/lexical-scope/node_modules/astw/node_modules/esprima-fb/test
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/module-deps/node_modules/detective/node_modules/escodegen/node_modules/esprima/test
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/module-deps/node_modules/detective/node_modules/esprima-fb/test
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/syntax-error/node_modules/esprima-fb/test
rm -rf node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-js/node_modules/browserify/node_modules/umd/node_modules/ruglify/test
fi
); if [[ $? > 0 ]]; then echo -e "\033[0;31m FAIL\033[0m"; exit 3; else echo -e "\033[0;32m OK\033[0m"; fi
@matb33
Copy link
Author

matb33 commented Nov 16, 2014

FYI I just updated the script above to keep copies of the various versions being installed so that one can swap back to the meteor version (3.5.0-0.2.4) and then back to whatever version without a re-install via npm. Useful when maintaining different apps using different cordova versions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment