Skip to content

Instantly share code, notes, and snippets.

@jling90
Last active September 30, 2019 07:49
Show Gist options
  • Save jling90/4b7531f1a1faeb0b71a3a7c655189bed to your computer and use it in GitHub Desktop.
Save jling90/4b7531f1a1faeb0b71a3a7c655189bed to your computer and use it in GitHub Desktop.
Create react directory
# Creates a index.js, {ComponentName}.jsx, styled/{ComponentName}.js at specified path
# $1 - Path to create files at
# $2 - Component name
# Example usage:
# crdir "src/components/shared" "Foo"
#
# src/components/shared
# |-- index.js, Foo.jsx
# --- styled/
# |--Foo.js
#
function crdir() {
mkdir -p "$1/$2/styled"
touch "$1/$2/"{index.js,$2.jsx,styled/$2.js}
echo "export { default } from './$2';" >> "$1/$2/index.js"
cat << EOF > $1/$2/$2.jsx
import React from 'react';
import PropTypes from 'prop-types';
const $2 = () => {};
$2.propTypes = {
};
export default $2;
EOF
echo "import styled from 'styled-components';" >> "$1/$2/styled/$2.js"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment