1 |
|
2 | var path = require('path');
|
3 | var saucelabsBrowsers = require(path.resolve('test', 'saucelabs-browsers.js'));
|
4 |
|
5 | var sourceFiles = [
|
6 | 'Gruntfile.js',
|
7 | 'src/*.js',
|
8 | 'src/**/*.js',
|
9 | 'test/**/test.*.js'
|
10 | ];
|
11 |
|
12 | module.exports = exports = function(grunt) {
|
13 | 'use strict';
|
14 |
|
15 | var BANNER = '/*!\n' +
|
16 | ' localForage -- Offline Storage, Improved\n' +
|
17 | ' Version ' + grunt.file.readJSON('package.json').version + '\n' +
|
18 | ' https://mozilla.github.io/localForage\n' +
|
19 | ' (c) 2013-2015 Mozilla, Apache License 2.0\n' +
|
20 | '*/\n';
|
21 |
|
22 | var babelModuleIdProvider = function getModuleId(moduleName) {
|
23 | var files = {
|
24 | 'src/localforage': 'localforage',
|
25 | 'src/utils/serializer': 'localforageSerializer',
|
26 | 'src/drivers/indexeddb': 'asyncStorage',
|
27 | 'src/drivers/localstorage': 'localStorageWrapper',
|
28 | 'src/drivers/websql': 'webSQLStorage'
|
29 | };
|
30 |
|
31 | return files[moduleName] || moduleName.replace('src/', '');
|
32 | };
|
33 |
|
34 | grunt.initConfig({
|
35 | babel: {
|
36 | options: {
|
37 | babelrc: false,
|
38 | extends: path.resolve('.babelrc-umd'),
|
39 | moduleIds: true,
|
40 | getModuleId: babelModuleIdProvider
|
41 | },
|
42 | dist: {
|
43 | files: {
|
44 | 'build/es5src/localforage.js': 'src/localforage.js',
|
45 | 'build/es5src/utils/serializer.js': 'src/utils/serializer.js',
|
46 | 'build/es5src/drivers/indexeddb.js': 'src/drivers/indexeddb.js',
|
47 | 'build/es5src/drivers/localstorage.js': 'src/drivers/localstorage.js',
|
48 | 'build/es5src/drivers/websql.js': 'src/drivers/websql.js'
|
49 | }
|
50 | }
|
51 | },
|
52 | browserify: {
|
53 | package_bundling_test: {
|
54 | src: 'test/runner.browserify.js',
|
55 | dest: 'test/localforage.browserify.js'
|
56 | },
|
57 | main: {
|
58 | files: {
|
59 | 'dist/localforage.js': 'src/localforage.js'
|
60 | },
|
61 | options: {
|
62 | browserifyOptions: {
|
63 | standalone: 'localforage'
|
64 | },
|
65 | transform: ['rollupify', 'babelify'],
|
66 | plugin: ['bundle-collapser/plugin']
|
67 | }
|
68 | },
|
69 | no_promises: {
|
70 | files: {
|
71 | 'dist/localforage.nopromises.js': 'src/localforage.js'
|
72 | },
|
73 | options: {
|
74 | browserifyOptions: {
|
75 | standalone: 'localforage'
|
76 | },
|
77 | transform: ['rollupify', 'babelify'],
|
78 | plugin: ['bundle-collapser/plugin'],
|
79 | exclude: ['lie/polyfill']
|
80 | }
|
81 | }
|
82 | },
|
83 | run: {
|
84 | derequire: {
|
85 | exec: 'derequire ' +
|
86 | '< dist/localforage.js > dist/localforage.tmp ' +
|
87 | '&& ncp dist/localforage.tmp dist/localforage.js' +
|
88 | '&& rimraf dist/localforage.tmp'
|
89 | },
|
90 | derequire_no_promises: {
|
91 | exec: 'derequire ' +
|
92 | '< dist/localforage.nopromises.js > dist/localforage.nopromises.tmp ' +
|
93 | '&& ncp dist/localforage.nopromises.tmp dist/localforage.nopromises.js' +
|
94 | '&& rimraf dist/localforage.nopromises.tmp'
|
95 | }
|
96 | },
|
97 | concat: {
|
98 | options: {
|
99 | separator: ''
|
100 | },
|
101 | localforage: {
|
102 |
|
103 |
|
104 | files: {
|
105 | 'dist/localforage.js': [
|
106 | 'dist/localforage.js'
|
107 | ],
|
108 | 'dist/localforage.nopromises.js': [
|
109 | 'dist/localforage.nopromises.js'
|
110 | ]
|
111 | },
|
112 | options: {
|
113 | banner: BANNER
|
114 | }
|
115 | }
|
116 | },
|
117 | connect: {
|
118 | test: {
|
119 | options: {
|
120 | base: '.',
|
121 | hostname: '*',
|
122 | port: 9999,
|
123 | middleware: function(connect) {
|
124 | return [
|
125 | function(req, res, next) {
|
126 | res.setHeader('Access-Control-Allow-Origin',
|
127 | '*');
|
128 | res.setHeader('Access-Control-Allow-Methods',
|
129 | '*');
|
130 |
|
131 | return next();
|
132 | },
|
133 | connect.static(require('path').resolve('.'))
|
134 | ];
|
135 | }
|
136 | }
|
137 | }
|
138 | },
|
139 | es3_safe_recast: {
|
140 | dist: {
|
141 | files: [{
|
142 | src: ['dist/localforage.js'],
|
143 | dest: 'dist/localforage.js'
|
144 | }]
|
145 | },
|
146 | nopromises: {
|
147 | files: [{
|
148 | src: ['dist/localforage.nopromises.js'],
|
149 | dest: 'dist/localforage.nopromises.js'
|
150 | }]
|
151 | }
|
152 | },
|
153 | jscs: {
|
154 | source: sourceFiles
|
155 | },
|
156 | jshint: {
|
157 | options: {
|
158 | jshintrc: '.jshintrc'
|
159 | },
|
160 | source: sourceFiles
|
161 | },
|
162 | mocha: {
|
163 | unit: {
|
164 | options: {
|
165 | urls: [
|
166 | 'http://localhost:9999/test/test.main.html',
|
167 | 'http://localhost:9999/test/test.min.html',
|
168 | 'http://localhost:9999/test/test.callwhenready.html',
|
169 | 'http://localhost:9999/test/test.customdriver.html',
|
170 | 'http://localhost:9999/test/test.faultydriver.html',
|
171 | 'http://localhost:9999/test/test.nodriver.html',
|
172 | 'http://localhost:9999/test/test.browserify.html',
|
173 | 'http://localhost:9999/test/test.require.html',
|
174 | 'http://localhost:9999/test/test.webpack.html'
|
175 | ]
|
176 | }
|
177 | }
|
178 | },
|
179 | 'saucelabs-mocha': {
|
180 | all: {
|
181 | options: {
|
182 | username: process.env.SAUCE_USERNAME,
|
183 | key: process.env.SAUCE_ACCESS_KEY,
|
184 | urls: ['http://localhost:9999/test/test.main.html'],
|
185 | tunnelTimeout: 5,
|
186 | build: process.env.TRAVIS_JOB_ID,
|
187 | concurrency: 3,
|
188 | browsers: saucelabsBrowsers,
|
189 | testname: 'localForage Tests'
|
190 | }
|
191 | }
|
192 | },
|
193 | uglify: {
|
194 | localforage: {
|
195 | files: {
|
196 | 'dist/localforage.min.js': ['dist/localforage.js'],
|
197 | 'dist/localforage.nopromises.min.js': [
|
198 | 'dist/localforage.nopromises.js'
|
199 | ]
|
200 | },
|
201 | options: {
|
202 | banner: BANNER
|
203 | }
|
204 | }
|
205 | },
|
206 | watch: {
|
207 | build: {
|
208 | files: ['src/*.js', 'src/**/*.js'],
|
209 | tasks: ['build']
|
210 | },
|
211 |
|
212 | 'mocha:unit': {
|
213 | files: [
|
214 | 'dist/localforage.js',
|
215 | 'test/runner.js',
|
216 | 'test/test.*.*'
|
217 | ],
|
218 | tasks: [
|
219 | 'jshint',
|
220 | 'jscs',
|
221 | 'browserify:package_bundling_test',
|
222 | 'webpack:package_bundling_test',
|
223 | 'mocha:unit'
|
224 | ]
|
225 | }
|
226 | },
|
227 | webpack: {
|
228 | package_bundling_test: {
|
229 | entry: './test/runner.webpack.js',
|
230 | output: {
|
231 | path: 'test/',
|
232 | filename: 'localforage.webpack.js'
|
233 | }
|
234 | }
|
235 | }
|
236 | });
|
237 |
|
238 | require('load-grunt-tasks')(grunt);
|
239 |
|
240 | grunt.registerTask('default', ['build', 'connect', 'watch']);
|
241 | grunt.registerTask('build', ['browserify:main', 'browserify:no_promises',
|
242 | 'run:derequire', 'run:derequire_no_promises',
|
243 | 'concat', 'es3_safe_recast', 'uglify']);
|
244 | grunt.registerTask('serve', ['build', 'connect:test', 'watch']);
|
245 |
|
246 |
|
247 | var testTasks = [
|
248 | 'build',
|
249 | 'babel',
|
250 | 'jshint',
|
251 | 'jscs',
|
252 | 'browserify:package_bundling_test',
|
253 | 'webpack:package_bundling_test',
|
254 | 'connect:test',
|
255 | 'mocha'
|
256 | ];
|
257 | grunt.registerTask('test:local', testTasks.slice());
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 | grunt.registerTask('test', testTasks);
|
268 | };
|