forked from scs-sandbox/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
86 lines (79 loc) · 2.67 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
/*
* Copyright (c) 2014-2023 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/
'use strict'
module.exports = function (grunt) {
const os = grunt.option('os') || process.env.PCKG_OS_NAME || ''
const platform = grunt.option('platform') || process.env.PCKG_CPU_ARCH || ''
const 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',
'package.json',
'ctf.key',
'swagger.yml',
'server.ts',
'config.schema.yml',
'build/**',
'!build/reports/**',
'config/*.yml',
'data/*.ts',
'data/static/**',
'data/chatbot/.gitkeep',
'encryptionkeys/**',
'frontend/dist/frontend/**',
'frontend/src/**/*.ts',
'ftp/**',
'i18n/.gitkeep',
'lib/**',
'models/*.ts',
'node_modules/**',
'routes/*.ts',
'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'])
}