This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Gruntfile.js
167 lines (153 loc) · 6.73 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
const webpackConfig = require('./webpack.config');
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
webpack : {
dist: webpackConfig
},
// Clean build files or folders.
//------------------------------
clean : {
onlyFiles : {
src : ['lib/**'],
filter : 'isFile'
},
// Notice, removal of directories may corrupt svn structure.
// Therefore, be carefull if this is set as default command.
alsoFolders : ['lib/'],
tmpTestFiles : {
// If Grunt tests do not pass, temporary test files, such as _SpecRunner.html,
// may not be removed automatically after test run. Therefore, this is provided
// to make sure it can be removed also separately.
src : ['_SpecRunner.html', 'dest'],
filter : 'isFile'
},
// .grunt folder is used for temporary files. Remove folder.
tmpTestFolders : ['.grunt/']
},
// Detect errors and potential problems in JavaScript code and enforce coding conventions.
//----------------------------------------------------------------------------------------
jshint : {
all : ['src/**/*.js', 'test/**/*.js'],
options : {
"esversion" : 6,
"curly" : true,
"eqeqeq" : true,
"immed" : true,
"latedef" : false,
"newcap" : true,
"noarg" : true,
"sub" : true,
"undef" : true,
"boss" : true,
"eqnull" : true,
"node" : true,
"globals" : {
"it" : false,
"xit" : false,
"describe" : false,
"xdescribe" : false,
"beforeEach" : false,
"afterEach" : false,
"expect" : false,
"spyOn" : false,
"runs" : true,
"waitsFor" : true,
"waits" : true,
"jQuery" : true,
"$" : true,
"_" : true,
"async" : true,
"jasmine" : true,
"Raphael" : true,
"navigator" : true,
"window" : true,
"document" : true,
"XDomainRequest" : true,
"Metolib" : true
}
}
},
// Server connection for jasmine tests.
//-------------------------------------
// Jasmine tests need to be run by using host, such as localhost,
// because ajax operations may not work if only local filesystem is used.
connect : {
server : {
options : {
// Some randomly selected port number.
// Notice, this is used in jasmine tasks for host.
// Also notice, XML-files for local grunt tests may
// contain reference to this port for localhost.
// If port is changed, XML-files may need to be updated.
port : 8987
}
}
},
// Jasmine tests.
//---------------
jasmine : {
// Notice, test/jasmine/js/specconfig.js defines if only local or both local and server tests should be run.
//----------------------------------------------------------------------------------------------------------
metolibBundle : {
src : ['lib/metolib-bundle-<%= pkg.version %>.js'],
options : {
specs : ['test/jasmine/js/*.js', 'test/jasmine/spec/*.js'],
vendor : ['testdeps/async/async-0.2.9.js', 'testdeps/jquery/jquery-1.10.2.js', 'testdeps/lodash/lodash.compat-2.1.0.js'],
// See connect task for this.
host : 'http://localhost:8987/'
}
}
},
// Make sure proper version number is used in source file paths of test HTML files.
//---------------------------------------------------------------------------------
// Notice, these test HTML files are meant to be run separately by hand, not automatically by Grunt.
// Notice, src files do not contain version in filename. They can be ignored here.
"string-replace" : {
metolibBundle : {
files : [{
dest : 'test/jasmine/SpecRunnerBundle.html',
src : ['test/jasmine/SpecRunnerBundle.html']
},
{
dest : 'test/cache-testbench/index.html',
src : ['test/cache-testbench/index.html']
},
{
dest : 'examples/connection.html',
src : ['examples/connection.html']
},
{
dest : 'examples/parser.html',
src : ['examples/parser.html']
}],
options : {
replacements : [{
pattern : /metolib-bundle-.+\.js/g,
replacement : 'metolib-bundle-<%= pkg.version %>.js'
}]
}
}
}
});
// Load the plugins that provide the required tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-webpack');
// Update version strings inside files.
grunt.registerTask('string-replace-versions', ['string-replace:metolibBundle']);
// Build MetOLib.
grunt.registerTask('build', ['clean:onlyFiles', 'webpack:dist', 'string-replace-versions']);
// Test against both local and server data task(s).
grunt.registerTask('test', ['connect', 'jasmine:metolibBundle', 'clean:tmpTestFiles', 'clean:tmpTestFolders']);
// Default task(s).
// As a default, only local data is used for tests. Then, tests can be run also without connection for server data.
// Notice, test can be run separately also for server data.
grunt.registerTask('default', ['build', 'jshint', 'test']);
};