forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 342
/
Gruntfile.js
84 lines (77 loc) · 2.55 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
/*
* Copyright (c) 2014-2021 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
'use strict'
module.exports = function (grunt) {
var os = grunt.option('os') || process.env.PCKG_OS_NAME || ''
var platform = grunt.option('platform') || process.env.PCKG_CPU_ARCH || ''
var node = grunt.option('node') || process.env.nodejs_version || process.env.PCKG_NODE_VERSION || ''
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
replace_json: {
manifest: {
src: 'package.json',
changes: {
'engines.node': (node || '<%= pkg.engines.node %>'),
os: (os ? [os] : '<%= pkg.os %>'),
cpu: (platform ? [platform] : '<%= pkg.cpu %>')
}
}
},
compress: {
pckg: {
options: {
mode: os === 'linux' ? 'tgz' : 'zip',
archive: 'dist/<%= pkg.name %>-<%= pkg.version %>' + (node ? ('_node' + node) : '') + (os ? ('_' + os) : '') + (platform ? ('_' + platform) : '') + (os === 'linux' ? '.tgz' : '.zip')
},
files: [
{
src: [
'LICENSE',
'*.md',
'app.js',
'server.js',
'package.json',
'ctf.key',
'swagger.yml',
'config.schema.yml',
'config/*.yml',
'data/*.js',
'data/static/**',
'data/chatbot/.gitkeep',
'encryptionkeys/**',
'frontend/dist/frontend/**',
'ftp/**',
'i18n/.gitkeep',
'lib/**',
'models/*.js',
'node_modules/**',
'routes/*.js',
'uploads/complaints/.gitkeep',
'views/**'
],
dest: 'juice-shop_<%= pkg.version %>/'
}
]
}
}
})
grunt.registerTask('checksum', 'Create .md5 checksum files', function () {
const fs = require('fs')
const crypto = require('crypto')
fs.readdirSync('dist/').forEach(file => {
const buffer = fs.readFileSync('dist/' + file)
const md5 = crypto.createHash('md5')
md5.update(buffer)
const md5Hash = md5.digest('hex')
const md5FileName = 'dist/' + file + '.md5'
grunt.file.write(md5FileName, md5Hash)
grunt.log.write(`Checksum ${md5Hash} written to file ${md5FileName}.`).verbose.write('...').ok()
grunt.log.writeln()
})
})
grunt.loadNpmTasks('grunt-replace-json')
grunt.loadNpmTasks('grunt-contrib-compress')
grunt.registerTask('package', ['replace_json:manifest', 'compress:pckg', 'checksum'])
}