Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev Tool: Create styled-component #1385

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tools/scripts/create-styled-component.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
# Create a styled component with the given name, this script will also create the styled folder if none exists already as well as the
# index.ts file if none exists already. If they do exist, it will append the export statement to the index.ts file.
# Usage: create-styled-component.sh <component-name>
# Example: create-styled-component.sh Button
# Create a symbolic link to this file in your /usr/local/bin directory to use it from anywhere.
# Example: ln -s ~/create-styled-component.sh /usr/local/bin/create-styled-component
if [ $# -eq 0 ]; then
echo "No arguments supplied, please provide a component name."
exit 1
fi

if [ -f $1.tsx ]; then
echo "Component with name $1 already exists."
exit 1
fi

echo "Creating styled component in $(pwd)..."

# -p flag creates the directory if it doesn't exist already
mkdir -p styled

if [ ! -f styled/index.ts ]; then
echo "Creating styled/index.ts..."
touch styled/index.ts
fi

touch styled/$1.tsx
echo "import styled from 'styled-components';" >> styled/$1.tsx
touch $1.tsx

if [ -f index.ts ]; then
echo "Appending export statement to index.ts..."
echo "export * from './$1';" >> index.ts
fi

echo "import React from 'react';" >> $1.tsx
echo "import * as styled from './styled';" >> $1.tsx
echo "export * from './$1';" >> styled/index.ts

echo "Done..."