|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors. |
| 3 | + * SPDX-License-Identifier: MIT |
| 4 | + */ |
| 5 | + |
| 6 | +'use strict' |
| 7 | + |
| 8 | +module.exports = function (grunt) { |
| 9 | + const os = grunt.option('os') || process.env.PCKG_OS_NAME || '' |
| 10 | + const platform = grunt.option('platform') || process.env.PCKG_CPU_ARCH || '' |
| 11 | + const node = grunt.option('node') || process.env.nodejs_version || process.env.PCKG_NODE_VERSION || '' |
| 12 | + |
| 13 | + grunt.initConfig({ |
| 14 | + pkg: grunt.file.readJSON('package.json'), |
| 15 | + |
| 16 | + replace_json: { |
| 17 | + manifest: { |
| 18 | + src: 'package.json', |
| 19 | + changes: { |
| 20 | + 'engines.node': (node || '<%= pkg.engines.node %>'), |
| 21 | + os: (os ? [os] : '<%= pkg.os %>'), |
| 22 | + cpu: (platform ? [platform] : '<%= pkg.cpu %>') |
| 23 | + } |
| 24 | + } |
| 25 | + }, |
| 26 | + |
| 27 | + compress: { |
| 28 | + pckg: { |
| 29 | + options: { |
| 30 | + mode: os === 'linux' ? 'tgz' : 'zip', |
| 31 | + archive: 'dist/<%= pkg.name %>-<%= pkg.version %>' + (node ? ('_node' + node) : '') + (os ? ('_' + os) : '') + (platform ? ('_' + platform) : '') + (os === 'linux' ? '.tgz' : '.zip') |
| 32 | + }, |
| 33 | + files: [ |
| 34 | + { |
| 35 | + src: [ |
| 36 | + '.well-known/**', |
| 37 | + 'LICENSE', |
| 38 | + '*.md', |
| 39 | + 'package.json', |
| 40 | + 'ctf.key', |
| 41 | + 'swagger.yml', |
| 42 | + 'server.ts', |
| 43 | + 'config.schema.yml', |
| 44 | + 'build/**', |
| 45 | + '!build/reports/**', |
| 46 | + 'bom.json', |
| 47 | + 'bom.xml', |
| 48 | + 'config/*.yml', |
| 49 | + 'data/*.ts', |
| 50 | + 'data/static/**', |
| 51 | + 'data/chatbot/.gitkeep', |
| 52 | + 'encryptionkeys/**', |
| 53 | + 'frontend/dist/frontend/**', |
| 54 | + 'frontend/dist/bom/**', |
| 55 | + 'frontend/src/**/*.ts', |
| 56 | + 'ftp/**', |
| 57 | + 'i18n/.gitkeep', |
| 58 | + 'lib/**', |
| 59 | + 'models/*.ts', |
| 60 | + 'node_modules/**', |
| 61 | + 'routes/*.ts', |
| 62 | + 'uploads/complaints/.gitkeep', |
| 63 | + 'views/**' |
| 64 | + ], |
| 65 | + dest: 'juice-shop_<%= pkg.version %>/' |
| 66 | + } |
| 67 | + ] |
| 68 | + } |
| 69 | + } |
| 70 | + }) |
| 71 | + |
| 72 | + grunt.registerTask('checksum', 'Create .md5 checksum files', function () { |
| 73 | + const fs = require('fs') |
| 74 | + const crypto = require('crypto') |
| 75 | + fs.readdirSync('dist/').forEach(file => { |
| 76 | + const buffer = fs.readFileSync('dist/' + file) |
| 77 | + const md5 = crypto.createHash('md5') |
| 78 | + md5.update(buffer) |
| 79 | + const md5Hash = md5.digest('hex') |
| 80 | + const md5FileName = 'dist/' + file + '.md5' |
| 81 | + grunt.file.write(md5FileName, md5Hash) |
| 82 | + grunt.log.write(`Checksum ${md5Hash} written to file ${md5FileName}.`).verbose.write('...').ok() |
| 83 | + grunt.log.writeln() |
| 84 | + }) |
| 85 | + }) |
| 86 | + |
| 87 | + grunt.loadNpmTasks('grunt-replace-json') |
| 88 | + grunt.loadNpmTasks('grunt-contrib-compress') |
| 89 | + grunt.registerTask('package', ['replace_json:manifest', 'compress:pckg', 'checksum']) |
| 90 | +} |
0 commit comments