From 6499abc5d002e7698d7fc6d508f248edfa55ee0a Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Thu, 1 May 2025 16:10:10 +0100 Subject: [PATCH 1/4] New: customscriptsdir added to migrations grunt task --- grunt/tasks/migration.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/grunt/tasks/migration.js b/grunt/tasks/migration.js index 43c251c91..3b205007d 100644 --- a/grunt/tasks/migration.js +++ b/grunt/tasks/migration.js @@ -32,6 +32,7 @@ module.exports = function(grunt) { const next = this.async(); const buildConfig = Helpers.generateConfigData(); const fileNameIncludes = grunt.option('file'); + const customScriptsDir = grunt.option('customscriptsdir'); (async function() { const migrations = await import('adapt-migrations'); @@ -80,13 +81,16 @@ module.exports = function(grunt) { logger.debug(`Using ${toFramework.useOutputData ? toFramework.outputPath : toFramework.sourcePath} folder for course data...`); const plugins = toFramework.getPlugins().getAllPackageJSONFileItems().map(fileItem => fileItem.item); const migrationScripts = Array.from(await new Promise(resolve => { - globs([ - '*/*/migrations/**/*.js', - 'core/migrations/**/*.js' - ], { cwd: path.join(cwd, './src/'), absolute: true }, (err, files) => resolve(err ? null : files)); + const globPatterns = [ + 'src/*/*/migrations/**/*.js', + 'src/core/migrations/**/*.js' + ]; + if (customScriptsDir) globPatterns.push(`${customScriptsDir}/*.js`); + + globs(globPatterns, { cwd, absolute: true }, (err, files) => resolve(err ? null : files)); })).filter(filePath => { if (!fileNameIncludes) return true; - return minimatch(filePath, '**/' + fileNameIncludes) || filePath.includes(fileNameIncludes); + return new RegExp(`(^|\\W)${fileNameIncludes}(\\W|$)`).test(filePath); }); if (!migrationScripts.length) { From 2f47f84ec5efe900f38a8cda30e4b2944b4db962 Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Thu, 1 May 2025 17:31:33 +0100 Subject: [PATCH 2/4] match fileNameIncludes RegExp moved to function --- grunt/tasks/migration.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/grunt/tasks/migration.js b/grunt/tasks/migration.js index 3b205007d..990dcf7cc 100644 --- a/grunt/tasks/migration.js +++ b/grunt/tasks/migration.js @@ -1,3 +1,5 @@ +const { match } = require('assert'); + module.exports = function(grunt) { const Helpers = require('../helpers')(grunt); @@ -28,6 +30,11 @@ module.exports = function(grunt) { return clone; } + function matchFileNameIncludes(filePath, fileNameIncludes) { + const regex = new RegExp(`(^|\\/)${fileNameIncludes}(\\W|$)`); + return regex.test(filePath); + } + grunt.registerTask('migration', 'Migrate from one version to another', function(mode) { const next = this.async(); const buildConfig = Helpers.generateConfigData(); @@ -86,11 +93,10 @@ module.exports = function(grunt) { 'src/core/migrations/**/*.js' ]; if (customScriptsDir) globPatterns.push(`${customScriptsDir}/*.js`); - globs(globPatterns, { cwd, absolute: true }, (err, files) => resolve(err ? null : files)); })).filter(filePath => { if (!fileNameIncludes) return true; - return new RegExp(`(^|\\W)${fileNameIncludes}(\\W|$)`).test(filePath); + return matchFileNameIncludes(filePath, fileNameIncludes); }); if (!migrationScripts.length) { From 4293d676fc7b1b2654783e9cd1b36e66c766bb55 Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Thu, 1 May 2025 17:42:44 +0100 Subject: [PATCH 3/4] removed uneccessary requires --- grunt/tasks/migration.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/grunt/tasks/migration.js b/grunt/tasks/migration.js index 990dcf7cc..e47733190 100644 --- a/grunt/tasks/migration.js +++ b/grunt/tasks/migration.js @@ -1,5 +1,3 @@ -const { match } = require('assert'); - module.exports = function(grunt) { const Helpers = require('../helpers')(grunt); @@ -7,7 +5,6 @@ module.exports = function(grunt) { const path = require('path'); const fs = require('fs-extra'); const _ = require('underscore'); - const minimatch = require('minimatch'); function unix(path) { return path.replace(/\\/g, '/'); From 8af62b3a2117895aed37f507d490c7d0ad54cdc8 Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Mon, 12 May 2025 14:44:31 +0100 Subject: [PATCH 4/4] regex ramoved --- grunt/tasks/migration.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/grunt/tasks/migration.js b/grunt/tasks/migration.js index e47733190..8d34f4700 100644 --- a/grunt/tasks/migration.js +++ b/grunt/tasks/migration.js @@ -5,6 +5,7 @@ module.exports = function(grunt) { const path = require('path'); const fs = require('fs-extra'); const _ = require('underscore'); + const minimatch = require('minimatch'); function unix(path) { return path.replace(/\\/g, '/'); @@ -27,11 +28,6 @@ module.exports = function(grunt) { return clone; } - function matchFileNameIncludes(filePath, fileNameIncludes) { - const regex = new RegExp(`(^|\\/)${fileNameIncludes}(\\W|$)`); - return regex.test(filePath); - } - grunt.registerTask('migration', 'Migrate from one version to another', function(mode) { const next = this.async(); const buildConfig = Helpers.generateConfigData(); @@ -93,7 +89,7 @@ module.exports = function(grunt) { globs(globPatterns, { cwd, absolute: true }, (err, files) => resolve(err ? null : files)); })).filter(filePath => { if (!fileNameIncludes) return true; - return matchFileNameIncludes(filePath, fileNameIncludes); + return minimatch(filePath, '**/' + fileNameIncludes) || filePath.includes(fileNameIncludes); }); if (!migrationScripts.length) {