forked from HerronTech/soajs.artifact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
185 lines (171 loc) · 5.59 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
'use strict';
var fs = require('fs');
var path = require('path');
var lib = {
/**
* Function that find the root path where grunt plugins are installed.
*
* @method findRoot
* @return String rootPath
*/
findRoot: function () {
var cwd = process.cwd();
var rootPath = cwd;
var newRootPath = null;
while (!fs.existsSync(path.join(process.cwd(), "node_modules/grunt"))) {
process.chdir("..");
newRootPath = process.cwd();
if (newRootPath === rootPath) {
return;
}
rootPath = newRootPath;
}
process.chdir(cwd);
return rootPath;
},
/**
* Function load the npm tasks from the root path
*
* @method loadTasks
* @param grunt {Object} The grunt instance
* @param tasks {Array} Array of tasks as string
*/
loadTasks: function (grunt, rootPath, tasks) {
tasks.forEach(function (name) {
if (name === 'grunt-cli') return;
var cwd = process.cwd();
process.chdir(rootPath); // load files from proper root, I don't want to install everything locally per module!
grunt.loadNpmTasks(name);
process.chdir(cwd);
});
}
};
module.exports = function (grunt) {
//Loading the needed plugins to run the grunt tasks
var pluginsRootPath = lib.findRoot();
lib.loadTasks(grunt, pluginsRootPath, ['grunt-contrib-jshint', 'grunt-jsdoc', 'grunt-contrib-clean', 'grunt-mocha-test', 'grunt-env'
, 'grunt-istanbul', 'grunt-coveralls']);
grunt.initConfig({
//Defining jshint tasks
jshint: {
options: {
"bitwise": true,
"eqeqeq": true,
"forin": true,
"newcap": true,
"noarg": true,
"undef": true,
"unused": false,
"eqnull": true,
"laxcomma": true,
"loopfunc": true,
"sub": true,
"supernew": true,
"validthis": true,
"node": true,
"maxerr": 100,
"indent": 2,
"globals": {
"describe": false,
"it": false,
"before": false,
"beforeEach": false,
"after": false,
"afterEach": false
},
ignores: ['test/coverage/**/*.js']
},
files: {
src: ['**/*.js']
},
gruntfile: {
src: 'Gruntfile.js'
}
},
jsdoc: {
dist: {
src: ['index.js', 'config.js', 'lib/*.js', 'model/*.js'],
options: {
destination: 'doc'
}
}
},
env: {
coverage: {
SOAJS_TEST: true,
SOAJS_ENV: "dev",
APP_DIR_FOR_CODE_COVERAGE: '../test/coverage/instrument/'
},
artifact: {
SOAJS_TEST: true,
SOAJS_ENV: "dev",
SOAJS_PROFILE:"/opt/soajs/node_modules/soajs.utilities/data/artifact/profile.js"
}
},
clean: {
doc: {
src: ['doc/']
},
coverage: {
src: ['test/coverage/']
}
},
instrument: {
files: ['config.js', 'index.js', 'lib/*.js', 'model/*.js', 'model/**/*.js', 'data/*.js'],
options: {
lazy: false,
basePath: 'test/coverage/instrument/'
}
},
storeCoverage: {
options: {
dir: 'test/coverage/reports'
}
},
makeReport: {
src: 'test/coverage/reports/**/*.json',
options: {
type: 'lcov',
dir: 'test/coverage/reports',
print: 'detail'
}
},
mochaTest: {
// unit: {
// options: {
// reporter: 'spec',
// timeout: 90000
// },
// src: ['test/unit/*.js']
// },
integration: {
options: {
reporter: 'spec',
timeout: 90000
},
src: ['test/integration/_server.js']
}
},
coveralls: {
options: {
// LCOV coverage file relevant to every target
src: 'test/coverage/reports/lcov.info',
// When true, grunt-coveralls will only print a warning rather than
// an error, to prevent CI builds from failing unnecessarily (e.g. if
// coveralls.io is down). Optional, defaults to false.
force: false
},
your_target: {
// Target-specific LCOV coverage file
src: 'test/coverage/reports/lcov.info'
}
}
});
process.env.SHOW_LOGS = grunt.option('showLogs');
grunt.registerTask("default", ['jshint']);
grunt.registerTask("doc", ['jsdoc']);
grunt.registerTask("integration", ['env:coverage', 'mochaTest:integration']);
grunt.registerTask("data", ['env:artifact', 'mochaTest:integration']);
grunt.registerTask("test", ['clean', 'env:coverage', 'instrument', 'mochaTest:integration']);
grunt.registerTask("coverage", ['clean', 'env:coverage', 'instrument', 'mochaTest:integration', 'storeCoverage', 'makeReport', 'coveralls']);
};