From fc935e89c69eda4ac4b04cd7f83b5dd3ec9857d3 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Tue, 8 Apr 2025 21:08:45 -0700 Subject: [PATCH] Removed grunt-contrib-concat --- Gruntfile.js | 109 +++++++++++++++++- grunt/config/concat.js | 56 --------- ...enseBanner.js.jst => licenseBanner.js.ejs} | 0 lib/jasmine-core/boot0.js | 1 + lib/jasmine-core/boot1.js | 1 + lib/jasmine-core/jasmine-html.js | 1 + lib/jasmine-core/jasmine.js | 1 + package.json | 2 +- 8 files changed, 113 insertions(+), 58 deletions(-) delete mode 100644 grunt/config/concat.js rename grunt/templates/{licenseBanner.js.jst => licenseBanner.js.ejs} (100%) diff --git a/Gruntfile.js b/Gruntfile.js index 584f81af..b1de9b01 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,10 +1,13 @@ +const fs = require('fs'); +const glob = require('glob'); +const ejs = require('ejs'); + module.exports = function(grunt) { var pkg = require("./package.json"); global.jasmineVersion = pkg.version; grunt.initConfig({ pkg: pkg, - concat: require('./grunt/config/concat.js'), sass: require('./grunt/config/sass.js'), cssUrlEmbed: require('./grunt/config/cssUrlEmbed.js') }); @@ -39,6 +42,110 @@ module.exports = function(grunt) { grunt.registerTask('default', ['sass:dist', "cssUrlEmbed"]); + grunt.registerTask('concat', + 'Concatenate files', + function() { + try { + const configs = [ + { + src: [ + 'src/html/requireHtml.js', + 'src/html/HtmlReporter.js', + 'src/html/HtmlSpecFilter.js', + 'src/html/ResultsNode.js', + 'src/html/QueryString.js', + 'src/html/**/*.js' + ], + dest: 'lib/jasmine-core/jasmine-html.js', + }, + { + dest: 'lib/jasmine-core/jasmine.js', + src: [ + 'src/core/requireCore.js', + 'src/core/matchers/requireMatchers.js', + 'src/core/base.js', + 'src/core/util.js', + 'src/core/Spec.js', + 'src/core/Order.js', + 'src/core/Env.js', + 'src/core/JsApiReporter.js', + 'src/core/PrettyPrinter', + 'src/core/Suite', + 'src/core/**/*.js', + { + template: 'src/version.js', + data: {version: jasmineVersion} + }, + ], + }, + { + dest: 'lib/jasmine-core/boot0.js', + src: ['src/boot/boot0.js'], + }, + { + dest: 'lib/jasmine-core/boot1.js', + src: ['src/boot/boot1.js'], + } + ]; + const licenseBanner = { + template: 'grunt/templates/licenseBanner.js.ejs', + data: {currentYear: new Date(Date.now()).getFullYear()} + }; + + for (const {src, dest} of configs) { + src.unshift(licenseBanner); + + function expand(srcListEntry) { + if (typeof srcListEntry === 'object') { + return srcListEntry; + } + + return glob.sync(srcListEntry) + .sort(function (a, b) { + // Match the sort order of previous build tools, so that the + // output is the same. + a = a.toLowerCase(); + b = b.toLowerCase(); + + if (a < b) { + return -1; + } else if (a === b) { + return 0; + } else { + return 1; + } + }); + } + + const srcs = src.flatMap(expand); + const seen = new Set(); + const chunks = []; + + for (const s of srcs) { + let content; + + if (!seen.has(s)) { + if (s.template) { + const template = fs.readFileSync(s.template, {encoding: 'utf8'}); + content = ejs.render(template, s.data); + } else { + content = fs.readFileSync(s, {encoding: 'utf8'}); + } + + chunks.push(content); + seen.add(s); + } + } + + fs.writeFileSync(dest, chunks.join('\n'), {encoding: 'utf8'}); + } + } catch (e) { + console.error(e); + throw e; + } + } + ); + grunt.registerTask('buildDistribution', 'Builds and lints jasmine.js, jasmine-html.js, jasmine.css', [ diff --git a/grunt/config/concat.js b/grunt/config/concat.js deleted file mode 100644 index a9c6eedf..00000000 --- a/grunt/config/concat.js +++ /dev/null @@ -1,56 +0,0 @@ -var grunt = require('grunt'); - -function license() { - var currentYear = "" + new Date(Date.now()).getFullYear(); - - return grunt.template.process( - grunt.file.read("grunt/templates/licenseBanner.js.jst"), - { data: { currentYear: currentYear}}); -} - -module.exports = { - 'jasmine-html': { - src: [ - 'src/html/requireHtml.js', - 'src/html/HtmlReporter.js', - 'src/html/HtmlSpecFilter.js', - 'src/html/ResultsNode.js', - 'src/html/QueryString.js', - 'src/html/**/*.js' - ], - dest: 'lib/jasmine-core/jasmine-html.js' - }, - jasmine: { - src: [ - 'src/core/requireCore.js', - 'src/core/matchers/requireMatchers.js', - 'src/core/base.js', - 'src/core/util.js', - 'src/core/Spec.js', - 'src/core/Order.js', - 'src/core/Env.js', - 'src/core/JsApiReporter.js', - 'src/core/PrettyPrinter', - 'src/core/Suite', - 'src/core/**/*.js', - 'src/version.js' - ], - dest: 'lib/jasmine-core/jasmine.js' - }, - boot0: { - src: ['src/boot/boot0.js'], - dest: 'lib/jasmine-core/boot0.js' - }, - boot1: { - src: ['src/boot/boot1.js'], - dest: 'lib/jasmine-core/boot1.js' - }, - options: { - banner: license(), - process: { - data: { - version: global.jasmineVersion - } - } - } -}; diff --git a/grunt/templates/licenseBanner.js.jst b/grunt/templates/licenseBanner.js.ejs similarity index 100% rename from grunt/templates/licenseBanner.js.jst rename to grunt/templates/licenseBanner.js.ejs diff --git a/lib/jasmine-core/boot0.js b/lib/jasmine-core/boot0.js index 6f0f3739..5403bdf3 100644 --- a/lib/jasmine-core/boot0.js +++ b/lib/jasmine-core/boot0.js @@ -21,6 +21,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + /** This file starts the process of "booting" Jasmine. It initializes Jasmine, makes its globals available, and creates the env. This file should be loaded diff --git a/lib/jasmine-core/boot1.js b/lib/jasmine-core/boot1.js index 6368eceb..8c12f8c7 100644 --- a/lib/jasmine-core/boot1.js +++ b/lib/jasmine-core/boot1.js @@ -21,6 +21,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + /** This file finishes 'booting' Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 060604d5..102eaee0 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -21,6 +21,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + // eslint-disable-next-line no-var var jasmineRequire = window.jasmineRequire || require('./jasmine.js'); diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index c3ba71f5..c6665c2f 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -21,6 +21,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + // eslint-disable-next-line no-unused-vars,no-var var getJasmineRequireObj = (function(jasmineGlobal) { let jasmineRequire; diff --git a/package.json b/package.json index 9dc1afa8..b2f0ef41 100644 --- a/package.json +++ b/package.json @@ -38,13 +38,13 @@ "@eslint/js": "^9.24.0", "archiver": "^7.0.1", "css-url-embed": "github:sgravrock/css-url-embed", + "ejs": "^3.1.10", "eslint": "^9.24.0", "eslint-plugin-compat": "^6.0.2", "glob": "^10.2.3", "globals": "^16.0.0", "grunt": "^1.0.4", "grunt-cli": "^1.3.2", - "grunt-contrib-concat": "^2.0.0", "grunt-sass": "^4.0.0", "jasmine": "^5.0.0", "jasmine-browser-runner": "github:jasmine/jasmine-browser-runner",