Skip to content

Instantly share code, notes, and snippets.

@CamonZ
Forked from paridin/rename-component.md
Created October 6, 2016 18:07
Show Gist options
  • Save CamonZ/151a9189013a8c59290cb0386df2cb9f to your computer and use it in GitHub Desktop.
Save CamonZ/151a9189013a8c59290cb0386df2cb9f to your computer and use it in GitHub Desktop.
Ember rename component, shell helper

Rename a component file.

I made a mistake to naming some components, I don't want to erase it and create again, the problem is, I need to rename the files by hand, it's a boring task, and maybe in the future I will get the same issue, to make me the life easier I developed the following snippet, you should use it if you have the same problem.

The snippet

#!/usr/bin/env bash
# purpose: rename files, in same path
# if you make a mistake to defining the name of ember component, 
# and you want to rename the files. This snippet is for you. 
# NOTE: You should change the component calls in your code, 
# this feature is not implemented yet.

# For DEBUG purposes uncomment the following line:
# set -x
if [ ! -z $1 ] && [ ! -z $2 ]
 then
   NAME="$1"
   RENAME="$2"
   for i in $(find . -path ./tmp -prune -o -name "${NAME}*")
   do
    if [[ $i != "./tmp" ]]
     then
       OUT=$(echo $i | sed -e "s/${NAME}/${RENAME}/g")
       echo "rename $i to $OUT"
       mv $i $OUT
     fi
   done
else
   echo "You must specify the NAME and RENAME parameters to rename the file";
fi

The output looks like this: ./rename.sh section-medium section-index-medium

rename ./app/components/layers/section-medium.js to ./app/components/layers/section-index-medium.js
rename ./app/templates/components/layers/section-medium.hbs to ./app/templates/components/layers/section-index-medium.hbs
rename ./tests/integration/components/layers/section-medium-test.js to ./tests/integration/components/layers/section-index-medium-test.js

NOTE: put the snipped in your root project.

/your-project/app
/your-project/config
/your-project/...
/your-project/ember-cli-build.js
/your-project/rename.sh
.... and so on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment