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