This repository has been archived by the owner on Dec 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Gruntfile.js
56 lines (43 loc) · 1.58 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
"use strict";
var Mocha = require("mocha"),
uglify = require("uglify-js"),
ESLint = require("eslint").CLIEngine,
browserify = require("browserify");
module.exports = function(grunt) {
grunt.registerTask("default", ["lint", "test"]);
grunt.registerTask("lint", "Lints code with ESLint", function() {
var lint = new ESLint(),
files = ["index.js", "Gruntfile.js", "lib", "spec", "examples"],
formatter = lint.getFormatter();
var report = lint.executeOnFiles(files),
results = report.results;
grunt.log.write(formatter(results));
return report.errorCount === 0;
});
grunt.registerTask("test", "Runs specs with Mocha", function() {
var mocha = new Mocha({ reporter: "dot" }),
files = grunt.file.expand("spec/helper.js", "spec/lib/**/*.js"),
done = this.async();
files.forEach(mocha.addFile.bind(mocha));
mocha.run(function(errs) {
done(errs === 0);
});
});
grunt.registerTask("dist", "Builds UMD distributable", function() {
var b = browserify("index.js", { standalone: "sphero" }),
banner = "/*! Sphero.js (c) 2015 Orbotix. MIT License */\n",
done = this.async();
// don't include node-serialport, since the assumption is that this will be
// running in the browser
b.ignore("serialport");
b.bundle(function(err, buffer) {
if (err) {
console.error(err);
done(false);
}
var result = uglify.minify(buffer.toString(), { fromString: true });
grunt.file.write("dist/sphero.min.js", banner + result.code);
done(true);
});
});
};