forked from localForage/localForage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
194 lines (185 loc) · 6.33 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* jshint node:true */
var path = require('path');
var saucelabsBrowsers = require(path.resolve('test', 'saucelabs-browsers.js'));
var sourceFiles = [
'Gruntfile.js',
'src/*.js',
'src/**/*.js',
'test/**/test.*.js'
];
module.exports = exports = function(grunt) {
'use strict';
grunt.initConfig({
concat: {
options: {
separator: ''
},
localforage: {
files: {
'dist/localforage.js': [
// https://github.com/jakearchibald/es6-promise
'bower_components/es6-promise/promise.js',
'src/drivers/**/*.js',
'src/localforage.js'
],
'dist/localforage.nopromises.js': [
'src/drivers/**/*.js',
'src/localforage.js'
]
},
options: {
banner:
'/*!\n' +
' localForage -- Offline Storage, Improved\n' +
' Version 0.9.2\n' +
' http://mozilla.github.io/localForage\n' +
' (c) 2013-2014 Mozilla, Apache License 2.0\n' +
'*/\n'
}
}
},
connect: {
test: {
options: {
base: '.',
hostname: '*',
port: 9999,
middleware: function(connect) {
return [
function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin',
'*');
res.setHeader('Access-Control-Allow-Methods',
'*');
return next();
},
connect.static(require('path').resolve('.'))
];
}
}
}
},
es3_safe_recast: {
dist: {
files: [{
src: ['dist/localforage.js'],
dest: 'dist/localforage.js'
}]
},
nopromises: {
files: [{
src: ['dist/localforage.nopromises.js'],
dest: 'dist/localforage.nopromises.js'
}]
}
},
jscs: {
source: sourceFiles
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
source: sourceFiles
},
mocha: {
unit: {
options: {
urls: [
'http://localhost:9999/test/test.component.html',
'http://localhost:9999/test/test.nodriver.html',
'http://localhost:9999/test/test.main.html',
'http://localhost:9999/test/test.min.html',
'http://localhost:9999/test/test.require.html',
'http://localhost:9999/test/test.callwhenready.html'
]
}
}
},
open: {
site: {
path: 'http://localhost:4567/'
}
},
'saucelabs-mocha': {
all: {
options: {
username: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
urls: ['http://localhost:9999/test/test.main.html'],
tunnelTimeout: 5,
build: process.env.TRAVIS_JOB_ID,
concurrency: 3,
browsers: saucelabsBrowsers,
testname: 'localForage Tests'
}
}
},
shell: {
options: {
stdout: true
},
component: {
command: path.resolve('node_modules', 'component', 'bin',
'component-build') +
' --dev -o test -n localforage.component'
},
'publish-site': {
command: 'rake publish ALLOW_DIRTY=true'
},
'serve-site': {
command: 'bundle exec middleman server'
}
},
uglify: {
localforage: {
files: {
'dist/localforage.min.js': ['dist/localforage.js'],
'dist/localforage.nopromises.min.js': [
'dist/localforage.nopromises.js'
],
'site/localforage.min.js': ['dist/localforage.js']
}
}
},
watch: {
build: {
files: ['src/*.js', 'src/**/*.js'],
tasks: ['build']
},
/*jshint scripturl:true */
'mocha:unit': {
files: [
'dist/localforage.js',
'test/runner.js',
'test/test.*.*'
],
tasks: ['jshint', 'jscs', 'shell:component', 'mocha:unit']
}
}
});
require('load-grunt-tasks')(grunt);
grunt.registerTask('default', ['build', 'connect', 'watch']);
grunt.registerTask('build', ['concat', 'es3_safe_recast', 'uglify']);
grunt.registerTask('publish', ['build', 'shell:publish-site']);
grunt.registerTask('serve', ['build', 'connect:test', 'watch']);
grunt.registerTask('site', ['shell:serve-site']);
// These are the test tasks we run regardless of Sauce Labs credentials.
var testTasks = [
'build',
'jshint',
'jscs',
'shell:component',
'connect:test',
'mocha'
];
grunt.registerTask('test:local', testTasks.slice());
// Run tests using Sauce Labs if we are on Travis or have locally
// available Sauce Labs credentials. Use `grunt test:local` to skip
// Sauce Labs tests.
// if (process.env.TRAVIS_JOB_ID ||
// (process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY)) {
// testTasks.push('saucelabs-mocha');
// }
grunt.registerTask('test', testTasks);
};