forked from finom/seemple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
202 lines (196 loc) · 5.92 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
/*jshint multistr: true */
module.exports = function(grunt) {
"use strict";
var commentMatreshka = '/*\n\tMatreshka v<%= pkg.version %> (<%= grunt.template.today("yyyy-mm-dd") %>)\n\tJavaScript Framework by Andrey Gubanov\n\tReleased under the MIT license\n\tMore info: http://matreshka.io\n*/\n',
commentMagic = '/*\n\tMatreshka Magic v<%= pkg.version %> (<%= grunt.template.today("yyyy-mm-dd") %>), the part of Matreshka project \n\tJavaScript Framework by Andrey Gubanov\n\tReleased under the MIT license\n\tMore info: http://matreshka.io/#magic\n*/\n',
pkg = grunt.file.readJSON('package.json'),
dirtyMatreshkaAMDCleanHack = function() {
// hack for systemjs builder
var d = "define";
// I don't know how to define modules with no dependencies (since we use AMDClean)
// so I have to hack it, unfortunatelly
if (typeof __root != 'undefined') {
/* global matreshka, balalaika, matreshka_magic, xclass, __root */
if (typeof define == 'function' && define.amd) {
if(__root[d]) {
__root[d]('matreshka', function() {
return matreshka;
});
__root[d]('balalaika', function() {
return matreshka.$b;
});
__root[d]('xclass', function() {
return matreshka.Class;
});
__root[d]('matreshka-magic', function() {
return matreshka_magic;
});
}
define(function() {
return matreshka;
});
} else if (typeof exports == "object") {
module.exports = matreshka;
} else {
__root.Matreshka = __root.MK = matreshka;
__root.$b = matreshka.$b;
__root.Class = matreshka.Class;
}
}
},
dirtyMagicAMDCleanHack = function() {
// hack for systemjs builder
var d = "define";
// I don't know how to define modules with no dependencies (since we use AMDClean)
// so I have to hack it, unfortunatelly
if (typeof __root != 'undefined') {
/* global matreshka, balalaika, matreshka_magic, xclass, __root */
if (typeof define == 'function' && define.amd) {
if(__root[d]) {
__root[d]('matreshka-magic', function() {
return matreshka_magic;
});
}
define(function() {
return matreshka_magic;
});
} else if (typeof exports == "object") {
module.exports = matreshka_magic;
} else {
__root.magic = __root.MatreshkaMagic = matreshka_magic;
}
}
};
grunt.initConfig({
pkg: pkg,
jshint: {
options: {
globals: {
Symbol: true,
define: true,
XDomainRequest: true,
document: true,
navigator: true,
clearTimeout: true,
setTimeout: true,
getComputedStyle: true,
window: true,
FileReader: true
},
// turns off some jshint errors, value is description instead of "true"
'-W001': "'hasOwnProperty' is a really bad name.",
'-W014': "Bad line breaking before '{a}'.",
'-W055': "A constructor name should start with an uppercase letter.",
'-W030': "Expected an assignment or function call and instead saw an expression.",
'-W084': "Expected a conditional expression and instead saw an assignment.",
'-W040': "Possible strict violation.",
'-W083': "Don't make functions within a loop.",
'-W093': "Did you mean to return a conditional instead of an assignment?",
'-W064': "Missing 'new' prefix when invoking a constructor."
},
all: ['src/**/*.js', 'Gruntfile.js', '!src/core/dom-lib/balalaika.js', '!src/core/dom-lib/balalaika-extended.js']
},
karma: {
unit: {
configFile: 'test/karma.conf.js',
singleRun: true
}
},
requirejs: {
matreshka: {
options: {
baseUrl: 'src',
name: "matreshka",
out: "matreshka.js",
optimize: "none",
preserveLicenseComments: false,
paths: {
matreshka_dir: ''
},
wrap: {
start: commentMatreshka
},
onModuleBundleComplete: function(data) {
var fs = require('fs'),
amdclean = require('amdclean'),
outputFile = data.path;
fs.writeFileSync(outputFile, amdclean.clean({
'filePath': outputFile,
'transformAMDChecks': false,
'wrap': {
'start': ';(function(__root) {\n',
'end': '\n matreshka.version="' + pkg.version + '";\
(' + dirtyMatreshkaAMDCleanHack + ')()\
})(typeof window != "undefined" ? window : Function("return this")());'
},
}));
}
}
},
matreshka_magic: {
options: {
baseUrl: 'src',
name: "matreshka-magic",
out: "magic/matreshka-magic.js",
optimize: "none",
preserveLicenseComments: false,
paths: {
matreshka_dir: ''
},
wrap: {
start: commentMagic
},
onModuleBundleComplete: function(data) {
var fs = require('fs'),
amdclean = require('amdclean'),
outputFile = data.path;
fs.writeFileSync(outputFile, amdclean.clean({
'filePath': outputFile,
'transformAMDChecks': false,
'wrap': {
'start': ';(function(__root) {\n',
'end': '\n matreshka_magic.version="' + pkg.version + '";\
(' + dirtyMagicAMDCleanHack + ')()\
})(typeof window != "undefined" ? window : Function("return this")());'
},
}));
}
}
}
},
uglify: {
options: {
sourceMap: true,
maxLineLen: 1000,
compress: {
keep_fnames: 1
},
mangle: {
keep_fnames: 1
}
},
matreshka: {
options: {
sourceMapName: 'matreshka.min.map',
banner: commentMatreshka
},
src: 'matreshka.js',
dest: 'matreshka.min.js'
},
matreshka_magic: {
options: {
sourceMapName: 'magic/matreshka-magic.min.map',
banner: commentMagic
},
src: 'magic/matreshka-magic.js',
dest: 'magic/matreshka-magic.min.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.registerTask('test', ['karma']);
grunt.registerTask('default', ['jshint', 'requirejs', 'uglify', 'test']);
};