-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gruntfile.js
250 lines (232 loc) · 8.37 KB
/
Gruntfile.js
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
//Build grunt file
module.exports = function (grunt) {
"use strict";
// load all tasks from the package.json file using load-grunt-tasks
require('load-grunt-tasks')(grunt, {
scope: ['devDependencies', 'optionalDependencies']
});
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
karma: {
watch: {
options: {
configFile: 'tests/config/karma.unit.js',
singleRun: false
}
},
single: {
options: {
configFile: 'tests/config/karma.unit.js',
singleRun: true
}
}
},
jsdoc: {
dist: {
src: ['js/**/*.js', 'README.md'],
options: {
destination: 'docs',
template: 'node_modules/ink-docstrap/template',
configure: 'node_modules/ink-docstrap/template/jsdoc.conf.json'
}
}
},
prompt: {
buildprompt: {
options: {
questions: [
{
config: 'prompt.buildType',
message: 'Select option:',
default: 'default',
type: 'list',
choices: function () {
var json = grunt.file.readJSON('version.json');
grunt.config.set('version', json.version);
return [{
name: 'Build package v.' + grunt.config.get('version'),
value: 'build'
}, {
name: 'Generate Doc',
value: 'generateDoc'
}, {
name: 'Build i18n',
value: 'i18n'
}];
}
},
{
config: 'prompt.execute',
type: 'confirm',
message: 'Tasks ready to run. Continue?'
}
],
then: function (results, done) {
var buildType = results['prompt.buildType'];
if (results['prompt.execute']) {
grunt.config.set('buildType', results['prompt.buildType']);
if (buildType === 'build') {
grunt.task.run(['doBuild']);
} else if (buildType === 'generateDoc') {
grunt.task.run(['generateDoc']);
} else if (buildType === 'i18n') {
grunt.task.run(['i18n']);
}
}
}
}
}
},
template: {
semver: {
options: {
data: {
builddate: new Date(),
version: grunt.config.get('version'),
ENV: 'PROD'
}
},
files: [
{src: 'js/Constants.tpl.js', dest: 'js/Constants.js'},
{src: 'start.tpl.frag', dest: 'start.frag'}
]
}
},
/**
* Compile JS files to a single file
*/
requirejs: {
dev: {
options: {
baseUrl: 'js',
name: 'RealUploader',
mainConfigFile: 'js/main.js',
out: 'build/temp/realuploader.js',
almond: true,
wrap: {
startFile: 'start.frag',
endFile: 'end.frag'
},
optimize: "none"
}
},
min: {
options: {
baseUrl: 'js',
name: 'RealUploader',
mainConfigFile: 'js/main.js',
out: 'build/temp/realuploader-min.js',
almond: true,
wrap: {
startFile: 'start.frag',
endFile: 'end.frag'
},
optimize: 'uglify'
}
}
},
/**
* Compile sass files to create the final CSS
*/
compass: {
dev: {
options: {
config: 'config.rb'
}
}
},
/**
* Copy created files to create the packages
*/
copy: {
build: {
files: [
//License
{
expand: true,
src: ['LICENSE_COMMERCIAL.TXT'],
dest: 'build/prod/',
filter: 'isFile',
flatten: true
},
{
expand: true,
src: ['LICENSE_ENTERPRISE.TXT'],
dest: 'build/prod/',
filter: 'isFile',
flatten: true
},
//copy all CSS files, all themes
{expand: true, src: ['css/*.css'], dest: 'build/prod/css/', filter: 'isFile', flatten: true},
//copy minifield and not compressed files
{expand: true, src: ['build/temp/*.js'], dest: 'build/prod/js/', filter: 'isFile', flatten: true},
{expand: false, src: ['examples.html'], dest: 'build/prod/', filter: 'isFile'},
{expand: false, src: ['upload.php', 'upload.jsp'], dest: 'build/prod/', filter: 'isFile'},
//copy all project source
{
expand: true,
src: ['js/**', 'sass/**', 'libs/**', 'tests/**', '!js/*.tpl.js'],
dest: 'build/prod/source/'
}
]
}
},
compress: {
build: {
options: {
archive: 'build/v<%=version%>.zip'
},
files: [
{expand: true, cwd: 'build/prod/', src: ['**'], dest: ''} // includes files in path and its subdirs
]
}
},
watch: {
scripts: {
files: ['js/**/*.js'],
tasks: ['compass:dev'],
options: {
spawn: false
}
},
styles: {
files: ['sass/**/*.scss'],
tasks: ['compass:dev'],
options: {
spawn: false
}
}
}
});
grunt.registerTask('default', ['prompt:buildprompt']);
grunt.registerTask('test', ['karma']);
grunt.registerTask('build', 'Just build the requirejs', function () {
grunt.task.run('requirejs:dev');//compile js
});
grunt.registerTask('doBuild', 'Main task runner', function () {
var tasks = [];
tasks.push('template:semver');//set version
tasks.push('requirejs:dev');//compile js
tasks.push('requirejs:min');//compile js min
tasks.push('compass:dev');//compile sass to css (not needed in this case)
tasks.push('copy:build');
tasks.push('compress:build');
grunt.task.run(tasks);
});
grunt.registerTask('generateDoc', '', function () {
var tasks = [];
tasks.push('jsdoc');
grunt.task.run(tasks);
});
grunt.registerTask('i18n', '', function () {
var files = grunt.file.expand(['js/*.js']);
for (var i = 0; i < files.length; i++) {
var matches = grunt.file.read(files[i]).match(/\_\((.*?)\)/gmi);
if (matches) {
for (var j = 0; j < matches.length; j++) {
console.log(matches[j].replace('_(', '').replace(')', ''));
}
}
}
});
};