-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathINSTALL.sh
executable file
·191 lines (168 loc) · 5.2 KB
/
INSTALL.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
ask() {
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question - use /dev/tty in case stdin is redirected from somewhere else
read -p "$1 [$prompt] " REPLY </dev/tty
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
installGulp () {
OS=$1;
INSTALL=()
echo "Checking Nodejs & NPM are installed..."
#Check to see if 'nodejs' is installed
if ! type -P nodejs > /dev/null; then
INSTALL+=('nodejs ');
fi
#Check to see if 'npm' is installed
if ! type -P npm > /dev/null; then
INSTALL+=('npm ');
fi
if [[ $OS == "osx" ]]; then
if [ ${#INSTALL[@]} -gt 0 ]; then
echo "Installing ${INSTALL[@]}...";
brew install ${INSTALL[@]} -y;
fi
elif [[ $OS == "fedora" ]]; then
if [ ${#INSTALL[@]} -gt 0 ]; then
echo "Installing ${INSTALL[@]}...";
sudo yum install ${INSTALL[@]} -y;
fi
elif [[ $OS == "ubuntu" ]]; then
if [ ${#INSTALL[@]} -gt 0 ]; then
echo "Installing ${INSTALL[@]}...";
sudo apt-get install ${INSTALL[@]} -y;
fi
fi
if ! type -P node > /dev/null; then
sudo ln -s /usr/bin/nodejs /usr/bin/node
fi
echo "Installed! Moving on...";
installGulpTasks
}
installGulpTasks () {
#NPM modules installation...
echo "Installing Gulp globally..."
sudo npm install --global gulp
#clear
echo "Installing basic gulp tasks..."
npm install require-dir
npm install --save-dev gulp gulp-require jshint-stylish gulp-minify-css gulp-less path gulp-watch gulp-html5-lint gulp-jshint gulp-livereload gulp-bootlint
clear
if ask "Would you like to specify your own file paths for your Bootstrap/LESS/JS files? (Defaults: './*.html', './index.php', './**/*.html', './**/*.php', './*.less', './**/*.less', './*.js', './**/*.js') " N; then
#If user would like to specify directories
#Setup project directories to watch
clear
echo "Which directory/directories are your Bootstrap files located? (Syntax INCLUDING single quotes: './*.html', './index.php', './**/*.html', './**/*.php') ";
read BOOTSTRAP_DIR
clear
echo "Which directory/directories are your LESS files located? (Syntax INCLUDING single quotes: './*.less', './**/*.less')";
read LESS_DIR
clear
echo "Where do you want your css file to be compiled to? (Syntax INCLUDING single quotes: './css/style.css')";
read CSS_DIR
clear
echo "Which directory/directories are your JS files located? (Syntax INCLUDING single quotes: './*.js', './**/*.js')";
read JS_DIR
else
BOOTSTRAP_DIR="'./*.html', './index.php', './**/*.html', './**/*.php'";
LESS_DIR="'./*.less', './**/*.less'";
CSS_DIR="'./css/style.css'";
JS_DIR="'./*.js', './**/*.js'";
fi
clear
echo "Making required gulp files and folders..."
DIRECTORY="gulp-tasks"
#Todo: Create gulpfile
#Create Gulpfile.js
cat > gulpfile.js <<EOF
var html_dir = [${BOOTSTRAP_DIR}],
less_dir = [${LESS_DIR}],
css_dir = [${CSS_DIR}],
js_dir = [${JS_DIR}];
/*Require All Gulp Tasks*/
var gulp = require('gulp'),
requireDir = require('require-dir'),
tasks = requireDir('./${DIRECTORY}');
gulp.task('default', function() {});
EOF
if [ ! -d "$DIRECTORY" ]; then
mkdir $DIRECTORY;
fi
#Create watch gulptasks
cat > ./$DIRECTORY/watch.js <<EOF
/*Project Vars*/
var paths = {
html_dir: ['./index.html', './*.php', './**/*.html', './**/*.php'],
less_dir: ['./*.less', './**/*.less'],
css_dir: './css/',
js_dir: ['./*.js', './**/*.js']
}
/*Gulp Requires*/
var gulp = require('gulp'),
minifyCss = require('gulp-minify-css'),
less = require('gulp-less'),
path = require('path'),
watch = require('gulp-watch'),
html5Lint = require('gulp-html5-lint'),
jshint = require('gulp-jshint'),
livereload = require('gulp-livereload'),
bootlint = require('gulp-bootlint');
/*Watch Task*/
gulp.task('watch', function() {
livereload.listen();
gulp.watch(paths.less_dir).on('change', function(file) {
return gulp.src(file.path)
.pipe(less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(minifyCss({keepBreaks: false}))
.pipe(gulp.dest(paths.css_dir))
.pipe(livereload());
});
gulp.watch(paths.html_dir).on('change', function(file) {
return gulp.src(file.path)
.pipe(bootlint({disabledIds: ['E001', 'W001', 'W002', 'W003', 'W005']}));
});
gulp.watch(paths.js_dir).on('change', function(file) {
return gulp.src(file.path)
.pipe(jshint());
});
});
EOF
echo "node_modules/
gulp-tasks/
gulpfile.js
INSTALL.sh" >> ".gitignore"
echo "...Done! Go to https://github.com/rapidwebltd to keep up to date with the latest news and updates!"
echo "Run 'gulp watch' to start watching your files for changes and have fun!! :)"
}
#OS Detect
if [[ "$OSTYPE" == "darwin"* ]]; then
installGulp "osx"
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
if [ -f /etc/redhat-release ]; then
installGulp "fedora";
elif [ -f /etc/lsb-release ]; then
installGulp "ubuntu";
fi
fi