/
Gruntfile.js
110 lines (99 loc) · 2.34 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
/**
* @license
* Copyright SOAJS All Rights Reserved.
*
* Use of this source code is governed by an Apache license that can be
* found in the LICENSE file at the root of this repository
*/
'use strict';
const fs = require('fs');
const path = require('path');
let lib = {
/**
* Function that find the root path where grunt plugins are installed.
*
* @method findRoot
* @return String rootPath
*/
findRoot: () => {
let cwd = process.cwd();
let rootPath = cwd;
let 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: (grunt, rootPath, tasks) => {
tasks.forEach((name) => {
if (name === 'grunt-cli') {
return;
}
let 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 = (grunt) => {
//Loading the needed plugins to run the grunt tasks
let pluginsRootPath = lib.findRoot();
lib.loadTasks(grunt, pluginsRootPath, ['grunt-contrib-jshint']);
grunt.initConfig({
//Defining jshint tasks
jshint: {
options: {
"bitwise": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"esversion": 6,
"forin": true,
"latedef": "nofunc",
"leanswitch": true,
"maxerr": 100,
"noarg": true,
"nonbsp": true,
"strict": "global",
"undef": true,
"unused": true,
"varstmt": true,
//"validthis": true,
//"loopfunc": true,
//"sub": true,
//"supernew": true,
"node": true,
"globals": {
"describe": false,
"it": false,
"before": false,
"beforeEach": false,
"after": false,
"afterEach": false
}
},
files: {
src: ['Gruntfile.js', 'example01/*.js', 'example02/*.js', 'example03/*.js',]
},
gruntfile: {
src: 'Gruntfile.js'
}
},
});
process.env.SHOW_LOGS = grunt.option('showLogs');
grunt.registerTask("default", ['jshint']);
};