forked from AgustinSRG/Pokemon-Showdown-Node-Bot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
127 lines (110 loc) · 3.44 KB
/
gulpfile.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
var path = require('path');
var util = require('util');
var gulp = require('gulp');
var lazypipe = require('lazypipe');
var merge = require('merge-stream');
var cache = require('gulp-cache');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var replace = require('gulp-replace');
var FileCache = require('cache-swap');
var jshintStylish = require('jshint-stylish');
var globals = {};
var globalList = [
'Bot', 'AppOptions', 'CommandParser', 'Config', 'DataDownloader', 'Features', 'Formats', 'Settings', 'Tools',
'colors', 'sys', 'fs', 'path', 'PSClient', 'reloadFeatures', 'SecurityLog',
'toId', 'toRoomid', 'ok', 'info', 'error', 'errlog', 'debug', 'cmdr', 'recv', 'sent', 'monitor'
];
globalList.forEach(function (identifier) {globals[identifier] = false;});
function transformLet () {
// Replacing `var` with `let` is sort of a hack that stops jsHint from
// complaining that I'm using `var` like `let` should be used, but
// without having to deal with iffy `let` support.
return lazypipe()
.pipe(replace.bind(null, /\bvar\b/g, 'let'))();
}
function lint (jsHintOptions, jscsOptions) {
function cachedJsHint () {
return cache(jshint(jsHintOptions, {timeout: 450000}), {
success: function (file) {
return file.jshint.success;
},
value: function (file) {
return {jshint: file.jshint};
},
fileCache: new FileCache({tmpDir: '.', cacheDirName: 'gulp-cache'})
});
}
return lazypipe()
.pipe(cachedJsHint)
.pipe(jscs.bind(jscs, {configPath: jscsOptions}))
.pipe(jscs.reporter.bind(jscs.reporter))
.pipe(jscs.reporter.bind(jscs.reporter, 'fail'))();
}
var jsHintOptions = {};
jsHintOptions.base = {
"nonbsp": true,
"nonew": true,
"noarg": true,
"loopfunc": true,
"latedef": 'nofunc',
"freeze": true,
"undef": true,
"sub": true,
"evil": true,
"esnext": true,
"node": true,
"eqeqeq": true,
"globals": globals
};
jsHintOptions.test = util._extend(util._extend({}, jsHintOptions.base), {
"mocha": true
});
jsHintOptions.externalScripts = util._extend(util._extend({}, jsHintOptions.base), {
"globals": {}
});
var jscsOptions = {};
jscsOptions.base = "./test/.jscsrc";
jscsOptions.config = "./test/.jscsrc";
var lintData = [
{
dirs: ['./command-parser.js', './data-downloader.js', './index.js', './security-log.js', './settings.js', 'showdown-client.js', './tools.js', './commands/*.js', './features/*/*.js', './languages/*/*.js', './features/battle/battle-ai/*.js', './features/battle/battle-ai/modules/*.js'],
jsHint: jsHintOptions.base,
jscs: jscsOptions.base
}, {
dirs: ['./config-example.js', './data/*-example.js', './data/typechart.js'],
jsHint: jsHintOptions.base,
jscs: jscsOptions.config
}, {
dirs: ['./test/*.js', './testfiles/*.js'],
jsHint: jsHintOptions.test,
jscs: jscsOptions.config
}, {
dirs: ['./getserver.js', './bot-setup.js'],
jsHint: jsHintOptions.externalScripts,
jscs: jscsOptions.base
}
];
var linter = function () {
return (
merge.apply(
null,
lintData.map(function (source) {
return gulp.src(source.dirs)
.pipe(transformLet())
.pipe(lint(source.jsHint, source.jscs));
})
).pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'))
);
};
gulp.task('fastlint', function () {
var source = lintData[0];
return gulp.src(source.dirs)
.pipe(transformLet())
.pipe(lint(source.jsHint, source.jscs))
.pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'));
});
gulp.task('lint', linter);
gulp.task('default', linter);