Skip to content

Instantly share code, notes, and snippets.

@redwansikder
Forked from whitep4nth3r/reset-next.sh
Created September 22, 2024 14:49
Show Gist options
  • Save redwansikder/cc2e4a2c3d635e98ecef6091a23c20ce to your computer and use it in GitHub Desktop.
Save redwansikder/cc2e4a2c3d635e98ecef6091a23c20ce to your computer and use it in GitHub Desktop.

Revisions

  1. @whitep4nth3r whitep4nth3r revised this gist Sep 6, 2021. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions reset-next.sh
    Original file line number Diff line number Diff line change
    @@ -53,11 +53,6 @@ add_custom_document () {
    cd pages
    echo 'import Document, { Html, Head, Main, NextScript } from "next/document";
    class MyDocument extends Document {
    static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
    return { ...initialProps };
    }
    render() {
    return (
    <Html lang="'$LANG'">
  2. @whitep4nth3r whitep4nth3r revised this gist Jul 9, 2021. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions reset-next.sh
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,6 @@ APP_NAME=""
    # The directory path must be relative to where the script lives
    DIR=""

    # Example script usage
    # ./reset-next.sh --lang=en --appname="my cool app" --dir=this-test

    # Loop through arguments and process them
    for arg in "$@"
    do
  3. @whitep4nth3r whitep4nth3r revised this gist Jul 9, 2021. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions reset-next.sh
    Original file line number Diff line number Diff line change
    @@ -9,12 +9,18 @@ APP_NAME=""
    DIR=""

    # Example script usage
    # ./reset-next.sh --lang=en --appname=my-cool-app --dir=this-test
    # ./reset-next.sh --lang=en --appname="my cool app" --dir=this-test

    # Loop through arguments and process them
    for arg in "$@"
    do
    case $arg in
    -h|--help)
    echo "⚡️ Example script usage ⚡️"
    echo "./reset-next.sh --lang=en --appname=\"my cool app\" --dir=this-test"
    shift
    exit;
    ;;
    -l=*|--lang=*)
    LANG="${arg#*=}"
    shift
    @@ -130,4 +136,7 @@ add_custom_document
    replace_index
    replace_globals_css

    echo "📣 DONE"
    echo "✨ Opening project in VSCode"
    code .

    echo "📣 DONE. Have a nice day!"
  4. @whitep4nth3r whitep4nth3r revised this gist Jul 9, 2021. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion reset-next.sh
    Original file line number Diff line number Diff line change
    @@ -100,7 +100,6 @@ replace_globals_css () {
    echo "✅  Replacing styles/globals.css"
    cd styles
    rm globals.css
    touch globals.css
    echo 'html {
    font-size: 100%;
    }
  5. @whitep4nth3r whitep4nth3r revised this gist Jul 9, 2021. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion reset-next.sh
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,6 @@ replace_index () {
    echo "✅  Replacing pages/index.js"
    cd pages
    rm index.js
    touch index.js
    echo 'import Head from "next/head";
    export default function Home() {
  6. @whitep4nth3r whitep4nth3r revised this gist Jul 9, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion reset-next.sh
    Original file line number Diff line number Diff line change
    @@ -130,4 +130,6 @@ delete_vercel_svg
    delete_home_css
    add_custom_document
    replace_index
    replace_globals_css
    replace_globals_css

    echo "📣 DONE"
  7. @whitep4nth3r whitep4nth3r revised this gist Jul 9, 2021. No changes.
  8. @whitep4nth3r whitep4nth3r created this gist Jul 9, 2021.
    133 changes: 133 additions & 0 deletions reset-next.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,133 @@
    #!/bin/bash

    # Input flags

    LANG=""
    APP_NAME=""

    # The directory path must be relative to where the script lives
    DIR=""

    # Example script usage
    # ./reset-next.sh --lang=en --appname=my-cool-app --dir=this-test

    # Loop through arguments and process them
    for arg in "$@"
    do
    case $arg in
    -l=*|--lang=*)
    LANG="${arg#*=}"
    shift
    ;;
    -a=*|--appname=*)
    APP_NAME="${arg#*=}"
    shift
    ;;
    -d=*|--dir=*)
    DIR="${arg#*=}"
    shift
    ;;
    esac
    done

    change_dir () {
    echo "✨ Changing directory to $1"
    cd $1
    }

    delete_vercel_svg () {
    echo "❌ Deleting vercel.svg"
    rm public/vercel.svg
    }

    delete_home_css () {
    echo "❌  Deleting Home.module.css"
    rm styles/Home.module.css
    }

    add_custom_document () {
    echo "✅ Adding custom _document.js with lang=$LANG"
    cd pages
    echo 'import Document, { Html, Head, Main, NextScript } from "next/document";
    class MyDocument extends Document {
    static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
    return { ...initialProps };
    }
    render() {
    return (
    <Html lang="'$LANG'">
    <Head />
    <body>
    <Main />
    <NextScript />
    </body>
    </Html>
    );
    }
    }
    export default MyDocument;' >> _document.js
    cd ..
    }

    replace_index () {
    echo "✅  Replacing pages/index.js"
    cd pages
    rm index.js
    touch index.js
    echo 'import Head from "next/head";
    export default function Home() {
    return (
    <>
    <Head>
    <title>'$APP_NAME'</title>
    <meta name="description" content="Description for '$APP_NAME'" />
    <link rel="icon" href="/favicon.ico" />
    </Head>
    <main>
    <h1>This new Next.js app has been reset!</h1>
    </main>
    </>
    );
    }' >> index.js
    cd ..
    }

    replace_globals_css () {
    echo "✅  Replacing styles/globals.css"
    cd styles
    rm globals.css
    touch globals.css
    echo 'html {
    font-size: 100%;
    }
    body {
    font-size: 1rem;
    padding: 0;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell,
    Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
    }
    * {
    box-sizing: border-box;
    }
    ' >> globals.css
    cd ..
    }

    echo "🔥 Resetting Next.js app in $DIR"
    echo "✨ Language: $LANG"
    echo "✨ App name: $APP_NAME"

    change_dir $DIR
    delete_vercel_svg
    delete_home_css
    add_custom_document
    replace_index
    replace_globals_css