Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Pass cli variables into scripts (fixes #3365) #3366

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions grunt/tasks/scripts.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
module.exports = function(grunt) {

const Helpers = require('../helpers')(grunt);
const buildConfig = Helpers.generateConfigData();

grunt.registerTask('scripts', 'Run plugin build tasks', function(mode) {

if (!mode) return;

var path = require('path');
var fs = require('fs');
var options = this.options({});
var chalk = require('chalk');
var async = require('async');
var taskCallback = this.async();
const path = require('path');
const fs = require('fs');
const options = this.options({});
const chalk = require('chalk');
const async = require('async');
const taskCallback = this.async();

if (options.plugins) {

var paths = [];
for (var i = 0, l = options.plugins.length; i < l; i++) {
var src = options.plugins[i];
paths = paths.concat(grunt.file.expand({
const paths = options.plugins.reduce((paths, src) => {
paths.push(...grunt.file.expand({
filter: options.pluginsFilter
}, src));
}
return paths;
}, [])

async.each(paths, function(bowerJSONPath, done) {

if (bowerJSONPath === undefined) return done();
var bowerJSON = grunt.file.readJSON(bowerJSONPath);
const bowerJSON = grunt.file.readJSON(bowerJSONPath);

if (!bowerJSON.scripts) return done();

var plugindir = path.dirname(bowerJSONPath);
var script = bowerJSON.scripts[mode];
const plugindir = path.dirname(bowerJSONPath);
const script = bowerJSON.scripts[mode];

if (!script) return done();

try {
var buildModule = require(path.join(process.cwd(), plugindir, script));
const buildModule = require(path.join(process.cwd(), plugindir, script));
buildModule(fs, path, grunt.log.writeln, {
sourcedir: options.sourcedir,
outputdir: options.outputdir,
plugindir: plugindir
...buildConfig,
...options,
plugindir
}, done);
} catch (err) {
grunt.log.writeln(chalk.red(err));
Expand Down