-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
243 lines (206 loc) · 9.88 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
fs = require 'fs'
module.exports = (grunt) ->
'use strict'
# DEFINE COMPANY/GAME ASSEMBLE TARGETS
#################################################################
# Helper function to clone base options
clone = (obj) ->
if not obj? or typeof obj isnt 'object'
return obj
newInstance = new obj.constructor()
for key of obj
newInstance[key] = clone obj[key]
return newInstance
# Get list of games/projects
games = grunt.file.expand 'data/games/*'
for i in [0..games.length-1]
games[i] = games[i].replace 'data/games/', ''
# Base options for all pages
assembleBaseOptions =
flatten: true
production: false
assets: '<%= site.assets %>'
postprocess: require 'pretty'
pkg: '<%= pkg %>'
site: '<%= site %>'
partials: '<%= site.includes %>'
layoutdir: '<%= site.layouts %>'
layout: '<%= site.layout %>'
helpers: '<%= site.helpers %>'
plugins: '<%= site.plugins %>'
# Options for company page
assembleConfig = {company: {}}
assembleConfig.company.options = clone(assembleBaseOptions)
assembleConfig.company.options.data = 'data/company.yml'
assembleConfig.company.options.games = games
assembleConfig.company.options.logos = grunt.file.expand {cwd: 'data'}, 'logos/*.{png,jpg,gif,tiff}'
assembleConfig.company.options.logos_zip = grunt.file.expand {cwd: 'data'}, 'logos/*.zip'
assembleConfig.company.options.images = grunt.file.expand {cwd: 'data'}, ['images/*.{png,jpg,gif,tiff}', '!images/header.{png,jpg,gif,tiff}']
assembleConfig.company.options.image_header = grunt.file.expand {cwd: 'data'}, 'images/header.{png,jpg,gif,tiff}'
assembleConfig.company.options.images_zip = grunt.file.expand {cwd: 'data'}, 'images/*.zip'
if grunt.file.exists 'data/' + assembleConfig.company.options.images_zip
size = fs.statSync('data/' + assembleConfig.company.options.images_zip).size
if size > 1024 and size < 1048576
size = size / 1024
size = parseInt(size) + 'KB'
else if size >= 1048576
size = (size / 1024) / 1024
size = parseInt(size) + 'MB'
assembleConfig.company.options.images_zip_size = size
if grunt.file.exists 'data/' + assembleConfig.company.options.logos_zip
size = fs.statSync('data/' + assembleConfig.company.options.logos_zip).size
if size > 1024 and size < 1048576
size = size / 1024
size = parseInt(size) + 'KB'
else if size >= 1048576
size = (size / 1024) / 1024
size = parseInt(size) + 'MB'
assembleConfig.company.options.logos_zip_size = size
assembleConfig.company.files = '<%= site.dest %>/index.html': ['<%= site.templates %>/company.hbs']
assembleConfig.credits = {}
assembleConfig.credits.options = clone(assembleBaseOptions)
assembleConfig.credits.files = '<%= site.dest %>/credits.html': ['<%= site.templates %>/credits.hbs']
# Options for game pages
for game in games
destFile = '<%= site.dest %>/games/' + game + '/index.html'
dataFile = 'data/games/' + game + '/game.yml'
assembleConfig[game] = {}
assembleConfig[game].options = clone(assembleBaseOptions)
assembleConfig[game].options.data = [dataFile, 'data/company.yml']
assembleConfig[game].options.logos = grunt.file.expand {cwd: 'data/games/' + game}, 'logos/*.{png,jpg,gif,tiff}'
assembleConfig[game].options.logos_zip = grunt.file.expand {cwd: 'data/games/' + game}, 'logos/*.zip'
assembleConfig[game].options.images = grunt.file.expand {cwd: 'data/games/' + game}, ['images/*.{png,jpg,gif,tiff}', '!images/header.{png,jpg,gif,tiff}']
assembleConfig[game].options.image_header = grunt.file.expand {cwd: 'data/games/' + game}, 'images/header.{png,jpg,gif,tiff}'
assembleConfig[game].options.images_zip = grunt.file.expand {cwd: 'data/games/' + game}, 'images/*.zip'
assembleConfig[game].files = {}
if grunt.file.exists 'data/games/' + game + '/' + assembleConfig[game].options.images_zip
size = fs.statSync('data/games/' + game + '/' + assembleConfig[game].options.images_zip).size
if size > 1024 and size < 1048576
size = size / 1024
size = parseInt(size) + 'KB'
else if size >= 1048576
size = (size / 1024) / 1024
size = parseInt(size) + 'MB'
assembleConfig[game].options.images_zip_size = size
if grunt.file.exists 'data/games/' + game + '/' + assembleConfig[game].options.logos_zip
size = fs.statSync('data/games/' + game + '/' + assembleConfig[game].options.logos_zip).size
if size > 1024 and size < 1048576
size = size / 1024
size = parseInt(size) + 'KB'
else if size >= 1048576
size = (size / 1024) / 1024
size = parseInt(size) + 'MB'
assembleConfig[game].options.logos_zip_size = size
assembleConfig[game].files[destFile] = ['<%= site.templates %>/game.hbs']
# GRUNT CONFIG
#################################################################
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
vendor: grunt.file.readJSON('.bowerrc').directory
site: grunt.file.readYAML '_config.yml'
clean: ['<%= site.dest %>']
copy:
main:
files: [
{
src: ['**/images/*','**/trailers/*','**/logos/*']
dest: 'dist'
cwd: 'data'
expand: true
}
]
less:
main:
options:
paths: ['assets/less']
files:
'dist/assets/css/style.min.css': 'assets/less/app.less'
uglify:
main:
options:
beautify: true;
preserveComments: true;
files:
'dist/assets/js/scripts.min.js': [
'assets/vendor/bower/bootstrap/js/transition.js'
'assets/vendor/bower/bootstrap/js/alert.js'
'assets/vendor/bower/bootstrap/js/button.js'
'assets/vendor/bower/bootstrap/js/carousel.js'
'assets/vendor/bower/bootstrap/js/collapse.js'
'assets/vendor/bower/bootstrap/js/dropdown.js'
'assets/vendor/bower/bootstrap/js/modal.js'
'assets/vendor/bower/bootstrap/js/tooltip.js'
'assets/vendor/bower/bootstrap/js/popover.js'
'assets/vendor/bower/bootstrap/js/scrollspy.js'
'assets/vendor/bower/bootstrap/js/tab.js'
'assets/vendor/bower/bootstrap/js/affix.js'
'assets/vendor/bower/eventEmitter/EventEmitter.js'
'assets/vendor/bower/eventie/eventie.js'
'assets/vendor/bower/doc-ready/doc-ready.js'
'assets/vendor/bower/get-style-property/get-style-property.js'
'assets/vendor/bower/get-size/get-size.js'
'assets/vendor/bower/jquery-bridget/jquery.bridget.js'
'assets/vendor/bower/matches-selector/matches-selector.js'
'assets/vendor/bower/outlayer/item.js'
'assets/vendor/bower/outlayer/outlayer.js'
'assets/vendor/bower/masonry/masonry.js'
'assets/vendor/bower/imagesloaded/imagesloaded.js'
'assets/js/*.js'
'dist/assets/js/*.js'
]
coffee:
main:
expand: true,
cwd: "assets/js/",
src: ["**/*.coffee"],
ext: ".js",
dest: "dist/assets/js/"
connect:
server:
options:
hostname: "localhost"
port: 8080
base: "dist/"
livereload: true
mkdir:
all:
options:
create: [
'data/images',
'data/logos',
'data/trailers',
'data/games/sample_game/images',
'data/games/sample_game/logos',
'data/games/sample_game/trailers'
]
assemble: assembleConfig
watch:
options:
livereload: true
less:
files: ["assets/css/*", "assets/less/*"]
tasks: ["less"]
copy:
files: ["data/images/*", "data/trailers/*", "data/**/images/*", "data/**/trailers/*"]
tasks: ["clean", "coffee", "uglify", "less", "copy", "assemble"]
assemble:
files: ["data/*.yml", "data/**/*.yml", 'templates/*', 'templates/**/*']
tasks: ["clean", "coffee", "uglify", "less", "copy", "assemble"]
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks "grunt-contrib-connect"
grunt.loadNpmTasks 'grunt-contrib-copy'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-less'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-mkdir'
grunt.loadNpmTasks 'assemble'
grunt.registerTask 'default', [
'clean', 'coffee', 'uglify', 'less', 'copy', 'assemble'
]
grunt.registerTask 'dev', [
'clean', 'coffee', 'uglify', 'less', 'copy', 'assemble', 'connect', 'watch'
]
grunt.registerTask 'init', [
'mkdir'
]