forked from openpgpjs/openpgpjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
329 lines (315 loc) · 9.74 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
module.exports = function(grunt) {
var version = grunt.option('release');
var fs = require('fs');
var browser_capabilities;
if (process.env.SELENIUM_BROWSER_CAPABILITIES !== undefined) {
browser_capabilities = JSON.parse(process.env.SELENIUM_BROWSER_CAPABILITIES);
}
var getSauceKey = function getSaucekey () {
return '60ffb656-2346-4b77-81f3-bc435ff4c103';
};
// Project configuration.
const dev = !!grunt.option('dev');
const compat = !!grunt.option('compat');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
openpgp: {
files: {
'dist/openpgp.js': ['./src/index.js']
},
options: {
browserifyOptions: {
fullPaths: dev,
debug: dev,
standalone: 'openpgp'
},
cacheFile: 'browserify-cache' + (compat ? '-compat' : '') + '.json',
// Don't bundle these packages with openpgp.js
external: ['crypto', 'zlib', 'node-localstorage', 'node-fetch', 'asn1.js', 'stream', 'buffer'].concat(
compat ? [] : [
'whatwg-fetch',
'core-js/fn/array/fill',
'core-js/fn/array/find',
'core-js/fn/array/includes',
'core-js/fn/array/from',
'core-js/fn/promise',
'core-js/fn/typed/uint8-array',
'core-js/fn/string/repeat',
'core-js/fn/symbol',
'core-js/fn/object/assign',
]
),
transform: [
["babelify", {
global: true,
// Only babelify web-stream-tools, asmcrypto, address-rfc2822 and seek-bzip in node_modules
only: /^(?:.*\/node_modules\/web-stream-tools\/|.*\/node_modules\/asmcrypto\.js\/|.*\/node_modules\/address-rfc2822\/|.*\/node_modules\/seek-bzip\/|(?!.*\/node_modules\/)).*$/,
plugins: compat ? [
"transform-async-to-generator",
"syntax-async-functions",
"transform-regenerator",
"transform-runtime"
] : [],
ignore: ['*.min.js'],
presets: [["env", {
targets: {
browsers: compat ? [
'IE >= 11',
'Safari >= 9',
'Last 2 Chrome versions',
'Last 2 Firefox versions',
'Last 2 Edge versions'
] : [
'Last 2 Chrome versions',
'Last 2 Firefox versions',
'Last 2 Safari versions',
'Last 2 Edge versions'
]
}
}]]
}]
],
plugin: ['browserify-derequire']
}
},
worker: {
files: {
'dist/openpgp.worker.js': ['./src/worker/worker.js']
},
options: {
cacheFile: 'browserify-cache-worker.json'
}
},
unittests: {
files: {
'test/lib/unittests-bundle.js': ['./test/unittests.js']
},
options: {
cacheFile: 'browserify-cache-unittests.json',
external: ['buffer', 'openpgp', '../../dist/openpgp', '../../../dist/openpgp'],
transform: [
["babelify", {
global: true,
// Only babelify chai-as-promised in node_modules
only: /^(?:.*\/node_modules\/chai-as-promised\/|(?!.*\/node_modules\/)).*$/,
plugins: ["transform-async-to-generator",
"syntax-async-functions",
"transform-regenerator",
"transform-runtime",
"transform-remove-strict-mode"],
ignore: ['*.min.js'],
presets: ["env"]
}]
]
}
}
},
replace: {
openpgp: {
src: ['dist/openpgp.js'],
dest: ['dist/openpgp.js'],
replacements: [{
from: /OpenPGP.js VERSION/g,
to: 'OpenPGP.js v<%= pkg.version %>'
}]
},
openpgp_min: {
src: ['dist/openpgp.min.js'],
dest: ['dist/openpgp.min.js'],
replacements: [{
from: "openpgp.worker.js",
to: "openpgp.worker.min.js"
}]
},
worker_min: {
src: ['dist/openpgp.worker.min.js'],
dest: ['dist/openpgp.worker.min.js'],
replacements: [{
from: "openpgp.js",
to: "openpgp.min.js"
}]
}
},
terser: {
openpgp: {
files: {
'dist/openpgp.min.js' : ['dist/openpgp.js'],
'dist/openpgp.worker.min.js' : ['dist/openpgp.worker.js']
},
options: {
safari10: true
},
}
},
header: {
openpgp: {
options: {
text: '/*! OpenPGP.js v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> - ' +
'this is LGPL licensed code, see LICENSE/our website <%= pkg.homepage %> for more information. */'
},
files: {
'dist/openpgp.min.js': 'dist/openpgp.min.js',
'dist/openpgp.worker.min.js': 'dist/openpgp.worker.min.js'
}
}
},
jsbeautifier: {
files: ['src/**/*.js'],
options: {
indent_size: 2,
preserve_newlines: true,
keep_array_indentation: false,
keep_function_indentation: false,
wrap_line_length: 120
}
},
eslint: {
target: ['src/**/*.js'],
options: { configFile: '.eslintrc.js' }
},
jsdoc: {
dist: {
src: ['README.md', 'src'],
options: {
configure: '.jsdocrc.js',
destination: 'doc',
recurse: true
}
}
},
mocha_istanbul: {
coverage: {
src: 'test',
options: {
root: '.',
timeout: 240000
}
}
},
mochaTest: {
unittests: {
options: {
reporter: 'spec',
timeout: 120000
},
src: ['test/unittests.js']
}
},
copy: {
browsertest: {
expand: true,
flatten: true,
cwd: 'node_modules/',
src: ['mocha/mocha.css', 'mocha/mocha.js'],
dest: 'test/lib/'
},
openpgp_compat: {
expand: true,
cwd: 'dist/',
src: ['*.js'],
dest: 'dist/compat/'
}
},
clean: ['dist/'],
connect: {
dev: {
options: {
port: 3001,
base: '.',
keepalive: true
}
},
test: {
options: {
port: 3000,
base: '.'
}
}
},
'saucelabs-mocha': {
all: {
options: {
username: 'openpgpjs',
key: getSauceKey,
urls: [
'http://localhost:3000/test/unittests.html?saucelabs=true&grep=' + encodeURIComponent('Sauce Labs Group 1'),
'http://localhost:3000/test/unittests.html?saucelabs=true&grep=' + encodeURIComponent('Sauce Labs Group 2'),
'http://localhost:3000/test/unittests.html?saucelabs=true&grep=' + encodeURIComponent('^(?!.*Sauce Labs Group [1-2])')
],
build: process.env.TRAVIS_BUILD_ID,
testname: 'Sauce Unit Test for openpgpjs',
browsers: [browser_capabilities],
public: "public",
maxRetries: 3,
throttled: 3,
pollInterval: 10000,
sauceConfig: {maxDuration: 1800, commandTimeout: 600, idleTimeout: 1000},
statusCheckAttempts: 200
}
}
},
watch: {
src: {
files: ['src/**/*.js'],
tasks: ['browserify:openpgp', 'browserify:worker']
},
test: {
files: ['test/*.js', 'test/crypto/**/*.js', 'test/general/**/*.js', 'test/worker/**/*.js'],
tasks: ['browserify:unittests']
}
}
});
// Load the plugin(s)
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-terser');
grunt.loadNpmTasks('grunt-header');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-jsbeautifier');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('gruntify-eslint');
grunt.loadNpmTasks('grunt-mocha-istanbul');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-saucelabs');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('set_version', function() {
if (!version) {
throw new Error('You must specify the version: "--release=1.0.0"');
}
patchFile({
fileName: 'package.json',
version: version
});
patchFile({
fileName: 'npm-shrinkwrap.json',
version: version
});
patchFile({
fileName: 'bower.json',
version: version
});
});
function patchFile(options) {
var path = './' + options.fileName,
file = require(path);
if (options.version) {
file.version = options.version;
}
fs.writeFileSync(path, JSON.stringify(file, null, 2) + '\n');
}
// Build tasks
grunt.registerTask('version', ['replace:openpgp']);
grunt.registerTask('replace_min', ['replace:openpgp_min', 'replace:worker_min']);
grunt.registerTask('build', ['browserify:openpgp', 'browserify:worker', 'version', 'terser', 'header', 'replace_min']);
grunt.registerTask('documentation', ['jsdoc']);
grunt.registerTask('default', ['build']);
// Test/Dev tasks
grunt.registerTask('test', ['eslint', 'mochaTest']);
grunt.registerTask('coverage', ['mocha_istanbul:coverage']);
grunt.registerTask('saucelabs', ['build', 'browserify:unittests', 'copy:browsertest', 'connect:test', 'saucelabs-mocha']);
grunt.registerTask('browsertest', ['build', 'browserify:unittests', 'copy:browsertest', 'connect:test', 'watch']);
};