This repository has been archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·69 lines (57 loc) · 1.8 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
# check that there is a src directory i.e. we're in the parent dir
if [ -d "src" ]
then
echo Found src directory.
else
echo Active directory must contain src directory.
exit 1
fi
# check if components folder already exists, if not create
if [ -d "src/components" ]
then
# components folder exists, so do nothing
echo Found src/components subdirectory.
else
# components folder doesn't exist, so create
echo src/components doesn\'t exist, creating.
mkdir src/components
fi
# loop through all of the arguments, which should correspond to component names and initialize files and folders
for COMPONENT in "$@"
do
if [ -d src/components/$COMPONENT ]
then
# folder already exists
echo $COMPONENT folder already exists, skipping.
else
# create the component directory
mkdir src/components/$COMPONENT
# get location of build.sh
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# create index.js
sh $DIR/create-index.js.sh $COMPONENT
# create $COMPONENT.js
sh $DIR/create-component.js.sh $COMPONENT
# create $COMPONENT.test.js
sh $DIR/create-component.test.js.sh $COMPONENT
# create $COMPONENT.test.js
sh $DIR/create-readme.md.sh $COMPONENT
# Inform user that everything was created
echo $COMPONENT component was created. Looks like:
echo "
src
├── components
├── $COMPONENT
├── index.js
├── $COMPONENT.js
├── $COMPONENT.test.js
├── README.md"
fi
done