-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGruntfile.coffee
332 lines (315 loc) · 13.1 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
module.exports = (grunt) ->
sass = require 'node-sass'
@initConfig
pkg: @file.readJSON('package.json')
release:
branch: ''
repofullname: ''
lasttag: ''
msg: ''
post: ''
url: ''
watch:
files: [
'css/src/**/*.scss',
'!css/src/_themecomment.scss',
'js/src/*.coffee',
'package.json'
]
tasks: ['develop']
postcss:
pkg:
options:
processors: [
require('autoprefixer')()
require('cssnano')()
]
failOnError: true
files:
'css/admin.css': 'css/admin.css'
'css/style.css': 'css/style.css'
'css/template-default.css': 'css/template-default.css'
dev:
options:
map: true
processors: [
require('autoprefixer')()
]
failOnError: true
files:
'css/admin.css': 'css/admin.css'
'css/style.css': 'css/style.css'
'css/template-default.css': 'css/template-default.css'
merge_media:
pkg:
options:
compress: true
files:
'css/style.css': 'css/style.css'
'css/template-default.css': 'css/template-default.css'
'css/admin.css': 'css/admin.css'
dev:
options:
compress: false
files:
'css/style.css': 'css/style.css'
'css/template-default.css': 'css/template-default.css'
'css/admin.css': 'css/admin.css'
sass:
pkg:
options:
implementation: sass
noSourceMap: true
outputStyle: 'compressed'
precision: 4
includePaths: ['node_modules/foundation-sites/scss']
files:
'css/admin.css': 'css/src/admin.scss'
'css/style.css': 'css/src/style.scss'
'css/template-default.css': 'css/src/template-default.scss'
dev:
options:
implementation: sass
sourceMap: true
outputStyle: 'nested'
precision: 4
includePaths: ['node_modules/foundation-sites/scss']
files:
'css/admin.css': 'css/src/admin.scss'
'css/style.css': 'css/src/style.scss'
'css/template-default.css': 'css/src/template-default.scss'
sasslint:
options:
configFile: '.sass-lint.yml'
target: [
'css/**/*.s+(a|c)ss',
'!css/src/_themecomment.scss'
]
jsvalidate:
options:
globals:
jQuery: true
console: true
module: true
document: true
targetName:
files:
src: [
'js/*.js'
]
compress:
main:
options:
archive: '<%= pkg.name %>.zip'
files: [
{src: ['css/*.css']},
{src: ['fields/*.php']},
{src: ['images/**']},
{src: ['js/*.js']},
{src: ['src/**']},
{src: ['templates/**']},
{src: ['vendor/autoload.php', 'vendor/composer/**']},
{src: ['*.php']},
{src: ['readme.md']},
{src: ['style.css']}
]
coffee:
compile:
options:
bare: true
files:
'js/post-type-tile-filters.js': 'js/src/post-type-tile-filters.coffee'
concat:
dist:
options:
stripBanners: true
separator: '\n'
process: (src, filepath) ->
return src.replace(/\n\/\/# sourceMappingURL=[^\n]+\n?/g, '')
src: [
'node_modules/what-input/dist/what-input.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.core.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.triggers.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.mediaQuery.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.keyboard.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.touch.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.nest.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.box.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.motion.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.sticky.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.dropdownMenu.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.drilldown.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.accordionMenu.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.responsiveMenu.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.responsiveToggle.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.smoothScroll.min.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.toggler.min.js'
]
dest: 'js/foundation.concat.js'
dev:
options:
sourceMap: true
src: [
'node_modules/what-input/dist/what-input.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.core.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.triggers.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.mediaQuery.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.keyboard.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.touch.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.nest.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.box.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.util.motion.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.sticky.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.dropdownMenu.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.drilldown.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.accordionMenu.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.responsiveMenu.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.responsiveToggle.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.smoothScroll.js',
'node_modules/foundation-sites/dist/js/plugins/foundation.toggler.js'
]
dest: 'js/foundation.concat.js'
@loadNpmTasks 'grunt-jsvalidate'
@loadNpmTasks 'grunt-contrib-coffee'
@loadNpmTasks 'grunt-contrib-watch'
@loadNpmTasks 'grunt-contrib-compress'
@loadNpmTasks 'grunt-contrib-concat'
@loadNpmTasks 'grunt-sass-lint'
@loadNpmTasks 'grunt-sass'
@loadNpmTasks 'grunt-postcss'
@loadNpmTasks 'grunt-merge-media'
@registerTask 'default', ['themecomment', 'sasslint', 'sass:pkg', 'concat:dist', 'coffee', 'jsvalidate', 'merge_media:pkg', 'postcss:pkg']
@registerTask 'develop', ['themecomment', 'sasslint', 'sass:dev', 'concat:dev', 'coffee', 'jsvalidate', 'merge_media:dev']
@registerTask 'release', ['compress', 'makerelease']
@registerTask 'makerelease', 'Set release branch for use in the release task', ->
done = @async()
# Define simple properties for release object
grunt.config 'release.key', process.env.RELEASE_KEY
grunt.config 'release.file', grunt.template.process '<%= pkg.name %>.zip'
grunt.config 'release.msg', grunt.template.process 'Upload <%= pkg.name %>.zip to your dashboard.'
grunt.util.spawn {
cmd: 'git'
args: [ 'rev-parse', '--abbrev-ref', 'HEAD' ]
}, (err, result, code) ->
if result.stdout isnt ''
matches = result.stdout.match /([^\n]+)$/
grunt.config 'release.branch', matches[1]
grunt.task.run 'setrepofullname'
done(err)
return
return
@registerTask 'setrepofullname', 'Set repo full name for use in the release task', ->
done = @async()
# Get repository owner and name for use in Github REST requests
grunt.util.spawn {
cmd: 'git'
args: [ 'config', '--get', 'remote.origin.url' ]
}, (err, result, code) ->
if result.stdout isnt ''
grunt.log.writeln 'Remote origin url: ' + result
matches = result.stdout.match /([^\/:]+)\/([^\/.]+)(\.git)?$/
grunt.config 'release.repofullname', matches[1] + '/' + matches[2]
grunt.task.run 'setpostdata'
done(err)
return
return
@registerTask 'setpostdata', 'Set post object for use in the release task', ->
val =
tag_name: 'v' + grunt.config.get 'pkg.version'
name: grunt.template.process '<%= pkg.name %> (v<%= pkg.version %>)'
body: grunt.config.get 'release.msg'
draft: false
prerelease: false
grunt.config 'release.post', JSON.stringify val
grunt.log.write JSON.stringify val
grunt.task.run 'createrelease'
return
@registerTask 'createrelease', 'Create a Github release', ->
done = @async()
# Create curl arguments for Github REST API request
args = ['-X', 'POST', '--url']
args.push grunt.template.process 'https://api.github.com/repos/<%= release.repofullname %>/releases?access_token=<%= release.key %>'
args.push '--data'
args.push grunt.config.get 'release.post'
grunt.log.write 'curl args: ' + args
# Create Github release using REST API
grunt.util.spawn {
cmd: 'curl'
args: args
}, (err, result, code) ->
grunt.log.write '\nResult: ' + result + '\n'
grunt.log.write 'Error: ' + err + '\n'
grunt.log.write 'Code: ' + code + '\n'
if result.stdout isnt ''
obj = JSON.parse result.stdout
# Check for error from Github
if 'errors' of obj and obj['errors'].length > 0
grunt.fail.fatal 'Github Error'
else
# We need the resulting "release" ID value before we can upload the .zip file to it.
grunt.config 'release.id', obj.id
grunt.task.run 'uploadreleasefile'
done(err)
return
return
@registerTask 'uploadreleasefile', 'Upload a zip file to the Github release', ->
done = @async()
# Create curl arguments for Github REST API request
args = ['-X', 'POST', '--header', 'Content-Type: application/zip', '--upload-file']
args.push grunt.config.get 'release.file'
args.push '--url'
args.push grunt.template.process 'https://uploads.github.com/repos/<%= release.repofullname %>/releases/<%= release.id %>/assets?access_token=<%= release.key %>&name=<%= release.file %>'
grunt.log.write 'curl args: ' + args
# Upload Github release asset using REST API
grunt.util.spawn {
cmd: 'curl'
args: args
}, (err, result, code) ->
grunt.log.write '\nResult: ' + result + '\n'
grunt.log.write 'Error: ' + err + '\n'
grunt.log.write 'Code: ' + code + '\n'
if result.stdout isnt ''
obj = JSON.parse result.stdout
# Check for error from Github
if 'errors' of obj and obj['errors'].length > 0
grunt.fail.fatal 'Github Error'
done(err)
return
return
@registerTask 'themecomment', 'Add WordPress header to style.css and css/style.css', ->
scss = 'css/src/_themecomment.scss'
css = 'style.css'
options =
encoding: 'utf-8'
output = '/*!\n'
output += ' Theme Name: <%= pkg.org_agrilife.themename %>\n'
output += ' Theme URI: <%= pkg.repository.url %>\n'
output += ' Author: <%= pkg.author %>\n'
output += ' Author URI: <%= pkg.org_agrilife.authoruri %>\n'
output += ' Description: <%= pkg.description %>\n'
output += ' Version: <%= pkg.version %>\n'
output += ' License: <%= pkg.license %>\n'
output += ' License URI: <%= pkg.org_agrilife.licenseuri %>\n'
output += ' Text Domain: <%= pkg.name %>\n'
output += ' Template: <%= pkg.org_agrilife.template %>\n'
output += '*/\n'
output = grunt.template.process output
grunt.file.delete scss
grunt.file.write scss, output, options
output += '\n/* ----------------------------------------------------------------------------\n\n'
output += ' WordPress requires a style.css file located in the theme\'s root folder for\n'
output += ' stuff to work. However, we will not be using vanilla CSS. We\'re using Sass.\n\n'
output += ' Sass is a superset of CSS that adds in amazing features such as variables,\n'
output += ' nested selectors and loops. It\'s also the easiest way to customize\n'
output += ' Foundation. All Sass files are located in the /css/src folder.\n\n'
output += ' Please note that none of your scss files will be compiled to /css/style.css\n'
output += ' before you run "npm start" or "grunt" or "grunt develop".\n\n'
output += ' Please read the README.md file before getting started. More info on how to\n'
output += ' use Sass with Foundation can be found here:\n'
output += ' http://foundation.zurb.com/docs/sass.html\n\n'
output += '---------------------------------------------------------------------------- */'
grunt.file.delete css
grunt.file.write css, output, options
return
@event.on 'watch', (action, filepath) =>
@log.writeln('#{filepath} has #{action}')