Last active
December 6, 2015 22:49
-
-
Save pixelhandler/d67892f44f4ee14628f0 to your computer and use it in GitHub Desktop.
Bash script to update dependencies (based on release notes) for an ember-cli app or addon, v1.13.8 -> v1.13.13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Use with arg $1 as --app or --addon and optional arg $2 as --backup to keep a copy of the original files | |
# | |
# Upgrade Ember-CLI dependencies from 1.13.8 to 1.13.13 | |
# | |
# - https://github.com/twokul/ember-cli-release-notes/commit/1cee41eb91bf7c534917fdd4cd42a1cd1a481c75 | |
# - https://github.com/ember-cli/ember-cli/releases/tag/v1.13.12 | |
# - https://github.com/ember-cli/ember-cli/releases/tag/v1.13.13 | |
# update bower.js … | |
function updateCommonBowerDependencies() { | |
file="bower.json" | |
echo "Updading Bower dependencies in "$file"…" | |
# ember / ember-data versions | |
ls $file | xargs sed -i.bak 's/"ember": "[\^\~]\{0,1\}[1-2]\.[0-9]\{2\}\.[0-9]\{1,2\}"/"ember": "1.13.11"/g' | |
ls $file | xargs sed -i.bak 's/"ember-data":\ "1\.[0-9]\{2\}\.[0-9]\{1,2\}"/"ember-data": "1.13.15"/g' | |
ls $file | xargs sed -i.bak 's/ember-cli\/ember-cli-shims#0\.[0-9]\.[0-9]/0.0.6/g' | |
ls $file | xargs sed -i.bak 's/ember-cli-test-loader#0\.[0-9]\.[0-9]/0.2.1/g' | |
ls $file | xargs sed -i.bak 's/ember-cli\/ember-load-initializers#0\.[0-9]\.[0-9]/0.1.7/g' | |
ls $file | xargs sed -i.bak 's/"ember-qunit":\ "[0-9]\.[0-9]\.[0-9]\{1,2\}"/"ember-qunit": "0.4.16"/g' | |
ls $file | xargs sed -i.bak 's/"ember-qunit-notifications":\ "0\.[0-9]\.[0-9]"/"ember-qunit-notifications": "0.1.0"/g' | |
ls $file | xargs sed -i.bak 's/"ember-resolver":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-resolver": "~0.1.20"/g' | |
ls $file | xargs sed -i.bak 's/"loader.js":\ "ember-cli\/loader.js#[0-3]\{1\}\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"loader.js": "ember-cli\/loader.js#3.4.0"/g' | |
ls $file | xargs sed -i.bak 's/"qunit":\ "~1.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"qunit": "~1.20.0"/g' | |
} | |
function updateBowerAppDependencies() { | |
updateCommonBowerDependencies | |
} | |
function updateBowerAddonDependencies() { | |
updateCommonBowerDependencies | |
} | |
# update package.json … | |
function updateCommonPackageDependencies() { | |
file="package.json" | |
echo "Updading NPM dependencies in "$file"…" | |
# ember-data version | |
ls $file | xargs sed -i.bak 's/"ember-data":\ "1\.[0-9]\{2\}\.[0-9]\{1,2\}"/"ember-data": "1.13.15"/g' | |
ls $file | xargs sed -i.bak 's/"broccoli-asset-rev":\ "[\^\~]\{0,1\}[0-2]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"broccoli-asset-rev": "^2.2.0"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli": "[\^\~]\{0,1\}[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-cli": "1.13.13"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-app-version":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\.[0-9]"/"ember-cli-app-version": "^1.0.0"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-babel":\ "[\^\~]\{0,1\}[0-9].[0-9]\{1,2\}.[0-9]\{1,2\}"/"ember-cli-babel": "^5.1.5"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-dependency-checker":\ "[\^\~]\{0,1\}[0-1].[0-9]\{1,2\}.[0-9]\{1,2\}"/"ember-cli-dependency-checker": "^1.1.0"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-htmlbars":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-cli-htmlbars": "^1.0.1"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-htmlbars-inline-precompile":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-cli-htmlbars-inline-precompile": "^0.3.1"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-ic-ajax":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-cli-ic-ajax": "0.2.4"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-qunit":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-cli-qunit": "^1.0.4"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-release":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-cli-release": "0.2.8"/g' | |
ls $file | xargs sed -i.bak 's/"ember-cli-sri":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-cli-sri": "^1.2.0"/g' | |
ls $file | xargs sed -i.bak 's/"ember-disable-proxy-controllers":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-disable-proxy-controllers": "^1.0.1"/g' | |
ls $file | xargs sed -i.bak 's/"ember-export-application-global":\ "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-export-application-global": "^1.0.4"/g' | |
} | |
function updatePackageAppDependencies() { | |
echo "Updading App specfic dependencies…" | |
updateCommonPackageDependencies | |
} | |
function updatePackageAddonDependencies() { | |
echo "Updading Addon specfic dependencies…" | |
updateCommonPackageDependencies | |
file="package.json" | |
ls $file | xargs sed -i.bak 's/"ember-try": "[\^\~]\{0,1\}[0-1]\.[0-9]\{1,2\}\.[0-9]\{1,2\}"/"ember-try": "~0.0.8"/g' | |
} | |
# File specific changes | |
function updateTestIndexFile() { | |
file='tests/index.html' | |
echo "Updating the "$file" file" | |
ls $file | xargs sed -i.bak 's/\<script\ src="testem.js"\>\<\/script\>/AAAABBBBCCCC/g' | |
ls $file | xargs sed -i.bak 's/BBBB/\ | |
/g' | |
ls $file | xargs sed -i.bak 's/AAAA/<script src="testem.js" integrity=""><\/script>/g' | |
ls $file | xargs sed -i.bak 's/CCCC/ <script src="assets\/tests.js"><\/script>/g' | |
} | |
function cleanupCaches() { | |
echo "Would you like to run clear bower and npm caches now?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) echo "Cleaning npm and bower caches…"; npm cache clean; bower cache clean; break;; | |
No ) break;; | |
esac | |
done | |
} | |
function wipeOutDirectories() { | |
echo "Do you want to wipe out node_modules bower_components dist and tmp directories now?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) echo "Removing node_modules bower_components dist and tmp directories…"; rm -rf node_modules bower_components dist tmp; break;; | |
No ) break;; | |
esac | |
done | |
} | |
function applyChanges() { | |
# based on args apply the dependency updates | |
if [ "$1" == "--app" ]; then | |
updateBowerAppDependencies | |
updatePackageAppDependencies | |
updateTestIndexFile | |
elif [ "$1" == "--addon" ]; then | |
updateBowerAddonDependencies | |
updatePackageAddonDependencies | |
updateTestIndexFile | |
else | |
updateCommonBowerDependencies | |
updateCommonPackageDependencies | |
updateTestIndexFile | |
fi | |
if [ "$2" != "--backup" ]; then | |
rm bower.json.bak | |
rm package.json.bak | |
rm tests/index.html.bak | |
fi | |
echo "All set, bower.json, package.json and tests/index.html updated per release notes instructions." | |
} | |
function installEmberCli() { | |
echo "Would you like run 'npm install [email protected]' now?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) echo "Installing ember-cli 1.13.13 for this repo…"; npm install [email protected]; break;; | |
No ) break;; | |
esac | |
done | |
} | |
function installDependencies() { | |
echo "Would you like install NPM and Bower dependencies now?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) echo "Installing node modules…"; npm install; echo "Installing bower components…"; bower install; break;; | |
No ) break;; | |
esac | |
done | |
} | |
function doInitialize() { | |
echo "Would you like to run 'ember init' now?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) ember init; break;; | |
No ) break;; | |
esac | |
done | |
} | |
# Upgrade procedure | |
function doIt() { | |
echo "Upgrading ember-cli from 1.13.8 to 1.13.13…" | |
cleanupCaches | |
wipeOutDirectories | |
applyChanges | |
installEmberCli | |
installDependencies | |
doInitialize | |
} | |
# The upgrade routine… | |
echo "Let's upgrade to Ember CLI v1.13.13" | |
echo "See https://github.com/ember-cli/ember-cli/releases/tag/v1.13.13" | |
echo "Have you already upgraded your global Ember CLI module to v1.13.13 ? And, is your current version using v1.13.8 ?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) doIt; break;; | |
No ) echo 'First you need to uninstall ember-cli, then clear module caches and reinstall with "npm install -g [email protected]"'; exit;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. Would be good to merge into http://emberwatch.com/recipes/ember_cli/installing_and_updating.html perhaps?