From 4bd2feda7d0db0d8696c0733a5afb7d93fad1948 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Tue, 8 Apr 2025 18:47:53 -0700 Subject: [PATCH] Use archiver directly rather than grunt-contrib-compress Removes two old copies of glob and is another step towards removing Grunt. --- Gruntfile.js | 1 - grunt/config/compress.js | 57 --------------------------- grunt/tasks/build_standalone.js | 70 ++++++++++++++++++++++++++++++++- package.json | 2 +- 4 files changed, 70 insertions(+), 60 deletions(-) delete mode 100644 grunt/config/compress.js diff --git a/Gruntfile.js b/Gruntfile.js index ec3820b2..584f81af 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -6,7 +6,6 @@ module.exports = function(grunt) { pkg: pkg, concat: require('./grunt/config/concat.js'), sass: require('./grunt/config/sass.js'), - compress: require('./grunt/config/compress.js'), cssUrlEmbed: require('./grunt/config/cssUrlEmbed.js') }); diff --git a/grunt/config/compress.js b/grunt/config/compress.js deleted file mode 100644 index a732e147..00000000 --- a/grunt/config/compress.js +++ /dev/null @@ -1,57 +0,0 @@ -var standaloneLibDir = "lib/jasmine-" + jasmineVersion; - -function root(path) { return "./" + path; } -function libJasmineCore(path) { return root("lib/jasmine-core/" + path); } -function dist(path) { return root("dist/" + path); } - -module.exports = { - standalone: { - options: { - archive: root("dist/jasmine-standalone-" + global.jasmineVersion + ".zip") - }, - - files: [ - { src: [ root("LICENSE") ] }, - { - src: [ "jasmine_favicon.png"], - dest: standaloneLibDir, - expand: true, - cwd: root("images") - }, - { - src: [ - "jasmine.js", - "jasmine-html.js", - "jasmine.css" - ], - dest: standaloneLibDir, - expand: true, - cwd: libJasmineCore("") - }, - { - src: [ "boot0.js", "boot1.js" ], - dest: standaloneLibDir, - expand: true, - cwd: libJasmineCore("") - }, - { - src: [ "SpecRunner.html" ], - dest: root(""), - expand: true, - cwd: dist("tmp") - }, - { - src: [ "*.js" ], - dest: "src", - expand: true, - cwd: libJasmineCore("example/src/") - }, - { - src: [ "*.js" ], - dest: "spec", - expand: true, - cwd: libJasmineCore("example/spec/") - } - ] - } -}; diff --git a/grunt/tasks/build_standalone.js b/grunt/tasks/build_standalone.js index 1abccf28..e0bbb075 100644 --- a/grunt/tasks/build_standalone.js +++ b/grunt/tasks/build_standalone.js @@ -1,4 +1,8 @@ var grunt = require("grunt"); +const fs = require('fs'); +const path = require('path'); +const archiver = require('archiver'); +const glob = require('glob'); function standaloneTmpDir(path) { return "dist/tmp/" + path; } @@ -20,12 +24,76 @@ grunt.registerTask("build:cleanSpecRunner", } ); +const standaloneFileGroups = [ + { + src: [ + 'LICENSE', + 'dist/tmp/SpecRunner.html', + ] + }, + { + src: [ + 'images/jasmine_favicon.png', + 'lib/jasmine-core/jasmine.js', + 'lib/jasmine-core/jasmine-html.js', + 'lib/jasmine-core/jasmine.css', + 'lib/jasmine-core/boot0.js', + 'lib/jasmine-core/boot1.js', + ], + destDir: 'lib/jasmine-' + jasmineVersion + }, + { + src: glob.sync('lib/jasmine-core/example/src/*.js'), + destDir: 'src' + }, + { + src: glob.sync('lib/jasmine-core/example/spec/*.js'), + destDir: 'spec' + } +]; + +grunt.registerTask("zipStandaloneDist", + "Creates a zip file for the standalone distribution", + function() { + const done = this.async(); + const destPath = `./dist/jasmine-standalone-${global.jasmineVersion}.zip`; + const output = fs.createWriteStream(destPath); + const archive = archiver('zip'); + + output.on('close', done); + + archive.on('warning', function (err) { + grunt.fail.warn(err) + }); + + archive.on('error', function (err) { + grunt.fail.warn(err) + }); + + archive.pipe(output); + + for (const group of standaloneFileGroups) { + for (const srcPath of group.src) { + let destPath = path.basename(srcPath); + + if (group.destDir) { + destPath = `${group.destDir}/${destPath}`; + } + + archive.file(srcPath, {name: destPath}); + } + } + + archive.finalize(); + } +); + grunt.registerTask("buildStandaloneDist", "Builds a standalone distribution", [ "buildDistribution", "build:compileSpecRunner", - "compress:standalone", + "zipStandaloneDist", "build:cleanSpecRunner" ] ); diff --git a/package.json b/package.json index a238104a..9dc1afa8 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "devDependencies": { "@eslint/eslintrc": "^3.3.1", "@eslint/js": "^9.24.0", + "archiver": "^7.0.1", "css-url-embed": "github:sgravrock/css-url-embed", "eslint": "^9.24.0", "eslint-plugin-compat": "^6.0.2", @@ -43,7 +44,6 @@ "globals": "^16.0.0", "grunt": "^1.0.4", "grunt-cli": "^1.3.2", - "grunt-contrib-compress": "^2.0.0", "grunt-contrib-concat": "^2.0.0", "grunt-sass": "^4.0.0", "jasmine": "^5.0.0",