This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
161 lines (148 loc) · 4.11 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
var serverRootUri = 'http://127.0.0.1:8000';
var mochaPhantomJsTestRunner = serverRootUri + '/public/test/index.html';
module.exports = function (grunt) {
function getBanner (pkg) {
return [
'/*! ' + pkg.name + ' - v' + pkg.version + ' - ',
grunt.template.today('yyyy-mm-dd') + '\n',
'* Copyright (c) ' + grunt.template.today('yyyy') + ' ' + pkg.author + ';*/\n'
].join('');
}
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: getBanner(grunt.file.readJSON('package.json')),
files: {
src: [
'src/index.js'
],
require: [
'src/index.js'
],
test: {
commonJS: [
'test/commonJS/*.js'
],
amd: [
'test/commonJS/*.js',
'test/AMD/*.js'
]
}
},
jshint: {
files: [
'<%= files.src %>',
'<%= files.test.commonJS %>',
'Gruntfile.js'
],
options: {
jshintrc: '.jshintrc'
}
},
// mochaTests for commonjs testing before cleaning and browserifying the
// public files
mochaTest: {
test: {
options: {
reporter: 'spec'
},
src: [ '<%= files.test.commonJS %>' ]
}
},
clean: {
files: ['./public/dist/*']
},
// less: {
// src: "",
// dest: "",
// build_less: {
// options: {
// modifyVars: {
// primaryColor: "red"
// }
// }
// }
// },
browserify: {
options: {
banner: '<%= banner %>'
},
// This browserify build be used by users of the module. It contains a
// UMD (universal module definition) and can be used via an AMD module
// loader like RequireJS or by simply placing a script tag in the page,
// which registers mymodule as a global var. You can see examples for both
// usages in browser/example/index.html (script tag) and
// browser/example/index-require.html (RequireJS).
standalone: {
src: [ '<%= files.src %>' ],
dest: './public/dist/<%= pkg.name %>.standalone.js',
options: {
standalone: '<%= pkg.name %>'
}
},
// This browserify build can be required by other browserify modules that
// have been created with an --external parameter. See
// browser/test/index.html for an example.
require: {
banner: '<%= banner %>',
src: [ '<%= files.require %>' ],
dest: './public/dist/<%= pkg.name %>.require.js',
options: {
alias: [ './src/index.js:' ]
}
},
// These are the browserified tests. We need to browserify the tests to
// be able to run the mocha tests while writing the tests as clean,
// simple CommonJS mocha tests (that is, without cross-platform
// boilerplate code). This build will also include the testing libs
// chai, sinon and sinon-chai but must not include the module under test.
tests: {
src: [ '<%= files.test.amd %>' ],
dest: './public/test/test_bundle.js',
external: [ './src/index.js' ]
}
},
// compress public dist files using uglify
uglify: {
dist: {
files: {
'public/dist/<%= pkg.name %>.standalone.min.js':
['<%= browserify.standalone.dest %>'],
'public/dist/<%= pkg.name %>.require.min.js':
['<%= browserify.require.dest %>']
}
}
},
// Used for mocha-phantomjs tests
connect: {
server: {},
keepalive: {
options: {
keepalive: true
}
}
},
// run the mocha tests in the browser via PhantomJS
'mocha_phantomjs': {
all: {
options: {
urls: [
mochaPhantomJsTestRunner
]
}
}
}
});
// These plugins provide necessary tasks.
require('matchdep').filterAll('grunt-*').forEach(grunt.loadNpmTasks);
// Default task.
grunt.registerTask('default', [
'jshint',
'mochaTest',
'clean',
'browserify',
'uglify',
'connect:server',
'mocha_phantomjs'
]);
};