forked from matteodem/meteor-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meteor-boilerplate
executable file
·137 lines (124 loc) · 6.08 KB
/
meteor-boilerplate
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# Overall check
if [ ! -d ".meteor" ]
then echo 'Please use the meteor-boilerplate console tool out of your project root (./meteor-boilerplate)'
exit
fi
# Helper Function to copy the template files
function createFile {
UPPERCASE="$(tr '[:lower:]' '[:upper:]' <<< ${3:0:1})${3:1}";
ESCAPED=$(sed 's/[\*\.]/\\&/g' <<<"$CTMP")
# First parameter is the file name, path, then all the parameter names passed into the command
sed "s/ReplaceFirstUpperCase/${UPPERCASE}/g" private/templates/${1} > ${1}
sed "s/ReplaceFirst/${3}/g" ${1} > ${1}.test
sed "s/ReplaceSecond/${ESCAPED}/g" ${1}.test > ${2}
rm ${1} ${1}.test
}
case ${1} in
create:view)
if [ -z ${2} ]; then echo "Define a view name!"; exit; fi
if [ -d "client/views/$2" ]; then echo "Remove the existing view ($2) folder manually!"; exit; fi
if [ -d "client/modules/$2" ]; then echo "There's already a module called $2!"; exit; fi
if [ -f "client/views/common/$2.html" ]; then echo "Remove the existing common view ($2) manually!"; exit; fi
# Create folder
mkdir -p client/views/${2}
# Create files
createFile view.html client/views/${2}/${2}.html $2 $3
createFile view.js client/views/${2}/${2}.js $2 $3
createFile view.less client/views/${2}/${2}.less $2 $3
# Succesful
echo "Successfully created a view called \"${2}\""
;;
create:common)
if [ -z ${2} ]; then echo "Define a common view name!"; exit; fi
if [ -f "client/views/common/$2.html" ]; then echo "Remove the existing common view ($2) manually!"; exit; fi
if [ -d "client/views/$2" ]; then echo "Remove the existing view ($2) folder manually!"; exit; fi
if [ -d "client/modules/$2" ]; then echo "There's already a module called $2!"; exit; fi
# Create folder
mkdir -p client/views/common
# Fill files
createFile "view.html" "client/views/common/${2}.html" $2 $3
# Succesful
echo "Successfully created a common view called \"${2}\""
;;
create:layout)
if [ -z ${2} ]; then echo "Define a layout view name!"; exit; fi
if [ -f "client/views/layouts/$2.html" ]; then echo "Remove the existing layout ($2) manually!"; exit; fi
# Create folder
mkdir -p client/views/layouts
# Create file
createFile layout.html client/views/layouts/${2}.html $2 $3
# Succesful
echo "Successfully created a layout called \"${2}\""
;;
create:route)
if [ -z ${2} ] || [ -z ${3} ]; then echo "The first parameter is the route / template name and the second one the path (e. g. create:route home /)"; exit; fi
if [ -f "client/routes/${2}Route.js" ]; then echo "Remove the existing route $2 manually!"; exit; fi
# Create folder
mkdir -p client/routes
# Create file
createFile route.js client/routes/${2}Route.js $2 $3
# Succesful
routeName="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}"
echo "Successfully created route \"${routeName}Route\" with the path ${3}"
;;
create:module)
if [ -z ${2} ]; then echo "Define a module name!"; exit; fi
if [ -d "client/modules/$2" ]; then echo "Remove the existing module ($2) folder manually!"; exit; fi
if [ -d "client/views/$2" ]; then echo "There's already a view called $2!"; exit; fi
if [ -f "client/views/common/$2.html" ]; then echo "Remove the existing common view ($2) manually!"; exit; fi
# Create folder
mkdir -p client/modules/${2}
# Create files
createFile module.html client/modules/${2}/${2}.html $2 $3
createFile module.js client/modules/${2}/${2}.js $2 $3
createFile module.less client/modules/${2}/${2}.less $2 $3
# Succesful
echo "Successfully created a module called \"${2}\""
;;
create:model)
if [ -z ${2} ]; then echo "Define a model name!"; exit; fi
if [ -f "model/$2.js" ]; then echo "Remove the existing model $2 manually!"; exit; fi
if [ -f "server/publications/$2.js" ]; then echo "Remove the existing publication file $2 manually!"; exit; fi
if [ -f "client/subscriptions/$2.js" ]; then echo "Remove the existing subscription file $2 manually!"; exit; fi
# Create folder
mkdir -p model
mkdir -p server/publications
mkdir -p client/subscriptions
# Create file
touch model/${2}.js
touch server/publications/$2.js
touch client/subscriptions/$2.js
# Fill files
createFile model.js model/${2}.js $2 $3
createFile publication.js server/publications/${2}.js $2 $3
createFile subscription.js client/subscriptions/${2}.js $2 $3
# Succesful
echo "Successfully created a model called \"${2}\" (with files in model, client/subscriptions and server/publications)"
;;
create:test)
if [ -z ${2} ]; then echo "Define a test name!"; exit; fi
if [ -f "tests/$2.js" ]; then echo "Remove the existing test $2 manually!"; exit; fi
# Create file
createFile test.js tests/${2}.js $2 $3
# Succesful
echo "Successfully created a test called ${2}.js under tests"
;;
*)
if [ -z ${1} ]; then
echo ""
else
echo "Could not find the command!"
echo ""
fi
echo "List of possible operations: "
echo -e "create:test - Test file under tests"
echo -e "create:view - View folder under client/views with html, js and less files in it"
echo -e "create:layout - Create a layout template which yields your content, used by iron-router"
echo -e "create:common - Html template file under client/views/common"
echo -e "create:route - Route javascript file under client/routes"
echo -e "create:model - Model with files in model/, client/subscriptions and server/publications"
echo -e "create:module - Module, such as a searchbar, form etc."
echo ""
;;
esac