-
Notifications
You must be signed in to change notification settings - Fork 19
/
Gruntfile.js
144 lines (117 loc) · 3.91 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
module.exports = function (grunt) {
var _ = require('lodash');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks("grunt-mocha-test");
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
contribBanner: "// <%= pkg.name %> v<%= pkg.version %>\n" +
"// =========================\n\n" +
"// > <%= pkg.homepage %>\n" +
"// > (c) 2013 Michael Fogus, DocumentCloud and Investigative Reporters & Editors\n" +
"// > (c) 2016 Refael Ackermann & node4good.org\n" +
"// > <%= pkg.name %> may be freely distributed under the <%= pkg.license %> license.\n\n",
copy: {
main: {
expand: true,
flatten: true,
src: 'gen/lodash*.js',
dest: 'dist/'
}
},
uglify: {
all: {
files: { "gen/lodash-contrib.min.js": "gen/lodash-contrib.js" }
}
},
mochaTest: {
test: {
src: ['test/mocha/*.*'],
options: {
reporter: "spec"
}
}
},
qunit: {
main: ['test/index.html'],
minified: ['test/dist-min.html'],
browserified: ['test/browserified.html']
},
jshint: {
all: [
"*.js",
"test/*.js"
],
options: {
es3: true, // Enforce ES3 compatibility
indent: 2, // Indent by 2 spaces
camelcase: true, // All vars must be camelCase or UPPER_WITH_UNDERSCORES
eqnull: true, // Allow 'x == null' convention
forin: true, // Require `for x in y` to filter with `hasOwnProperty`
newcap: true, // Require constructor names to be capitalized
"-W058": false // Allow 'new Constructor' without parens
}
},
browserWrap: {
all: {
files: [
{
src: ['common-js/*.*'],
dst: 'gen/temp-scaffold.js'
}
]
}
},
commonjsWrap: {
all: {
files: [
{
src: ['gen/temp-scaffold.js'],
dst: 'gen/lodash-contrib.commonjs.js'
}
]
}
},
browserify: {
dist: {
files: {
'gen/lodash-contrib.js': 'gen/temp-scaffold.js'
}
},
test: {
files: {
'gen/double.browserified.js': 'gen/lodash-contrib.js'
},
browserifyOptions: { debug: true }
}
}
});
grunt.registerMultiTask('browserWrap', 'index.js scaffolding task.', function () {
grunt.log.writeln('Generating first pass browserWrap.js');
var setup = this.files.pop();
var code = setup.src.reduce(function (seed, val) { return seed + 'require("../' + val + '")(_);\n'; }, '');
grunt.file.write(setup.dst, code);
});
grunt.registerMultiTask('commonjsWrap', 'index.js scaffolding task.', function () {
grunt.log.writeln('Generating first pass commonjsWrap.js');
var code = 'var _ = module.exports = require("lodash").runInContext();\n\n';
var setup = this.files.pop();
code += setup.src.reduce(function (seed, val) { return seed + grunt.file.read(val); }, '');
grunt.file.write(setup.dst, code);
code += '\n //Adding explicit method names for static analysis\n';
var ctrb1 = require('./' + setup.dst);
_(ctrb1).keys().sortBy().forEach(function (name) {
var len = Math.max(20 - name.length, 2);
var arr = new Array(len);
var aligner = arr.join(' ');
code += 'module.exports.' + name + aligner + ' = _.' + name + ';\n';
});
grunt.file.write(setup.dst, code);
});
grunt.registerTask('gen', ['browserWrap', 'commonjsWrap', 'browserify:dist', 'uglify', 'browserify:test', 'copy']);
grunt.registerTask('test', ['jshint', 'mochaTest', 'qunit:main', 'qunit:browserified', 'qunit:minified']);
grunt.registerTask('default', ['gen', 'test']);
};