Last active
May 28, 2020 12:33
-
-
Save vicsstar/458108180dcc9a93ba403a98552967ce to your computer and use it in GitHub Desktop.
Tiny script to quickly turn/ your Scrimba (scrimba.com) React project downloaded as a zip file, into a new "create-react-app" project.
This file contains hidden or 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
#### Disclaimer #### | |
#### THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
#!/bin/bash | |
#### | |
#### Tiny script to quickly turn/ your Scrimba (scrimba.com) React project downloaded as a zip file, into a new "create-react-app" project. | |
#### This script is at least specific to the "React Bootcamp - Become a professional React developer" course by Bob Ziroll (@bobziroll on Twitter). | |
#### | |
# Author: Victor Igbokwe (https://github.com/vicsstar) | |
#### Requirements: must have "npm" installed - get it at: https://www.npmjs.com/get-npm | |
#### After migration, you should inspect package.json and add any missing dependencies. | |
#### You should be able to find the Scrimba package.json in your react project's "src/" directory. | |
## Important: remember to run `chmod 755 sr-migrate.sh`, to make the file executable. | |
# path to zip file, containing project files to move to new react app | |
ZIP_FILE=$1 | |
# new react app name (optional). Default is "react-app" | |
REACT_APP_NAME=$2 | |
ZIP_OUTPUT_DIR="zip_output_dir" | |
if ! [ -e "$ZIP_FILE" ]; then | |
echo "Must provide a zip path containing project files" | |
echo "Usage: ./sr-migrate.sh <zip_file_path> <react_app_name | optional>" | |
exit 1 | |
fi | |
if [ -z "$REACT_APP_NAME" ]; then | |
echo "No react app name provided, using default 'react-app'" | |
REACT_APP_NAME="react-app" | |
else | |
echo "Using react project name $REACT_APP_NAME" | |
fi | |
if ! [ -x "$(command -v npx)" ]; then | |
echo "npx not installed. Falling back to npm..." | |
if ! [ -x "$(command -v create-react-app)" ]; then | |
echo "create-react-app not installed. Installing..." | |
npm install create-react-app -g | |
fi | |
create-react-app $REACT_APP_NAME | |
else | |
echo "Using npx to run create-react-app" | |
npx create-react-app $REACT_APP_NAME | |
fi | |
APP_SOURCE_DIR=$REACT_APP_NAME/src | |
unzip -o $ZIP_FILE -d $ZIP_OUTPUT_DIR | |
# new directory that was created as a result of running "unzip" | |
NEW_UNZIP_DIR=$ZIP_OUTPUT_DIR/$(ls zip_output_dir) | |
cp -R $NEW_UNZIP_DIR/ $APP_SOURCE_DIR | |
# clean up | |
rm -rf $ZIP_OUTPUT_DIR | |
# install dependencies | |
echo "Installing dependencies in package.json ..." | |
cd $REACT_APP_NAME && npm install | |
# start the react development server | |
npm run start | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment