forked from bluewebtech/angularjs-laravel-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
executable file
·242 lines (205 loc) · 6.19 KB
/
Gruntfile.coffee
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
'use strict';
module.exports = (grunt)->
# Load grunt tasks automatically
#require("load-grunt-tasks")(grunt)
# Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt)
#read env from .htaccess
env = grunt.file.read('public/.htaccess').match(/setEnv\sAPP_ENV\s(.*)\s/im)[1];
if env not in ['production', 'local']
grunt.log.error('env is bad');
return;
config =
base : 'public'
bower : 'public/bower'
lib : 'public/lib'
app:
base : 'public/app'
assets : 'public/app/assets'
ng : 'public/app/ng'
dist:
base : 'public/dist'
assets : 'public/dist/assets'
ng : 'public/dist/ng'
php:
layouts : 'app/views/layouts'
layoutsDist : 'app/views-dist/layouts'
grunt.initConfig
#pkg: grunt.file.readJSON('package.json')
#Directories
config: config
clean: [
'<%= config.app.base %>/.tmp'
'.tmp'
'<%= config.dist.base %>'
'<%= config.lib %>'
'<%= config.php.layoutsDist %>'
]
#инсталируем библиотеки и копируем в папку main файлы
bowercopy:
js:
options:
destPrefix:
'<%= config.base %>/lib/js'
files:
'jquery.js' : 'jquery/dist/jquery.js'
'require.js' : 'requirejs/require.js'
'json3.js' : 'json3/lib/json3.js'
'html5shiv-printshiv.js': 'html5shiv/dist/html5shiv-printshiv.js'
ng:
options:
destPrefix:
'<%= config.base %>/lib/js/ng'
files:
'angular.js' : 'angular/angular.js'
'angular-animate.js' : 'angular-animate/angular-animate.js'
'angular-cookies.js' : 'angular-cookies/angular-cookies.js'
'angular-resource.js' : 'angular-resource/angular-resource.js'
'angular-route.js' : 'angular-route/angular-route.js'
'angular-sanitize.js' : 'angular-sanitize/angular-sanitize.js'
'angular-ui-router.js' : 'angular-ui-router/release/angular-ui-router.js'
'angularLocalStorage.js': 'angularLocalStorage/src/angularLocalStorage.js'
bootstrap:
options:
destPrefix:
'<%= config.base %>/lib/'
files:
'js/bootstrap.js' : 'bootstrap/dist/js/bootstrap.js'
'fonts' : 'bootstrap/dist/fonts/*'
'css/bootstrap.css' : 'bootstrap/dist/css/bootstrap.css'
#компилируем less
less:
compile:
options:
ieCompat: true
yuicompress: true
files:
expand: true,
cwd: '<%= config.app.assets %>/less'
src: '**/*.less'
dest: '<%= config.dist.assets %>/less'
ext: '.less.css'
#компилируем coffee
coffee:
regular:
expand: true
flatten: false
cwd: '<%= config.app.ng %>'
src: ['**/*.coffee']
dest: '<%= config.dist.ng %>'
ext: '.js'
options:
bare: true
#copy all layouts to dist folder and JS CSS files
copy:
dist:
files: [
{
expand: true
dot: true
cwd: '<%= config.php.layouts %>'
dest: '<%= config.php.layoutsDist %>'
src: ['{,*/}*.php']
}
{
expand: true
dot: true
cwd: '<%= config.app.assets %>/css'
dest: '<%= config.dist.assets %>/css'
src: ['{,*/}*']
}
{
expand: true
dot: true
cwd: '<%= config.app.assets %>/js'
dest: '<%= config.dist.assets %>/js'
src: ['{,*/}*']
}
]
#подготавливаем файлы для конкатинации и минификации прописанные в layouts
useminPrepare:
html: ['<%= config.php.layouts %>/{,*/}*.php']
options:
dest: 'public/'
root: 'public/'
flow:
html:
steps:
js: ['concat', 'uglifyjs']
css: ['concat', 'cssmin']
post: {}
#минифицируем сами require.js
uglify:
options:
preserveComments: false
require:
files:
'<%= config.lib %>/js/require.min.js': ['<%= config.lib %>/js/require.js']
# Renames files for browser caching purposes
rev:
dist:
files:
src: ['lib/**/*.min.{js,css}']
#convert dist layouts
usemin:
html: ['app/views-dist/layouts/{,*/}*.php']
options:
assetsDirs: ['public/']
phpunit:
classes:
dir: 'app/tests/'
options:
bin: 'vendor/bin/phpunit'
colors: false
watch:
less:
files: ['<%= config.app.assets %>/less/**/*.less']
tasks: ['newer:less']
copydist:
files: ['<%= config.app.assets %>/css/**/*.css', '<%= config.app.assets %>/js/**/*.js']
tasks: ['newer:copy']
layouts:
files: ['<%= config.php.layouts %>/**/*.php']
tasks: ['newer:copy']
coffee:
files: ['<%= config.app.ng %>/**/*.coffee']
tasks: ['newer:coffee']
tests:
#files: ['app/controllers/*.php','app/models/*.php', 'app/tests/*.php', 'app/view/*php']
files: ['app/**/*.php']
tasks: ['phpunit']
#Run some tasks in parallel to speed up the build process
# concurrent:
# dist: [
# 'bowercopy'
# 'less'
# 'coffee'
# 'copy'
# ]
grunt.event.on 'watch', (action, filepath) ->
# Delete compiled .js file of deleted source .coffee file.
if action == 'deleted'
File = filepath.replace "#{config.app.base}", "#{config.dist.base}"
File = File.replace /\.coffee$/, '.js'
File = File.replace /\.less$/, '.less.css'
if grunt.file.exists File
grunt.file.delete File
grunt.log.ok 'File ' + File + ' deleted'
grunt.loadNpmTasks('grunt-contrib-less') #less
grunt.loadNpmTasks('grunt-contrib-coffee') #coffee
grunt.loadNpmTasks('grunt-contrib-copy') #copy
#grunt.loadNpmTasks('grunt-githooks')
grunt.loadNpmTasks('grunt-contrib-watch') #watch
grunt.loadNpmTasks('grunt-contrib-cssmin') #css-mi
grunt.loadNpmTasks('grunt-contrib-clean') #clean
grunt.loadNpmTasks('grunt-contrib-concat') #concat
grunt.loadNpmTasks('grunt-contrib-uglify') #js-min
grunt.loadNpmTasks('grunt-phpunit'); #phpunit
#grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-newer'); #newer files
grunt.loadNpmTasks('grunt-bowercopy');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-rev');
grunt.registerTask('production', ['clean','bowercopy', 'less', 'coffee', 'copy', 'useminPrepare', 'concat', 'uglify', 'cssmin','rev', 'usemin'])
grunt.registerTask('dev', ['clean','bowercopy', 'less', 'coffee', 'copy', 'uglify'])
grunt.registerTask('default', ['production'])