Assign values to the 'files' property of a Grunt task configuration using a custom function

Can the files property of a task configuration in Grunt be dynamically populated via a function?

For example:

concat: {
    angularSourceJs: {
        src: function() { 
            return angularSort(grunt.file.expand('src/**/*.js')); 
        },
        dest: 'dist/site.js'
    }
}
karma: {
    unit: {
        files: function() { 
            return angularSort(grunt.file.expand('src/**/*.js')); 
        },
        ...
    }
}

This feature would be beneficial especially when using grunt-contrib-watch and avoiding Grunt reloads.

Answer №1

To achieve this, you can use the following code snippet:

concatenate: {
    sortedAngularJs: {
        sources: angularSort(grunt.files.match('src/**/*.js')),
        destination: 'dist/app.js'
    }
}

The code above expects that the function angularSort will provide an array of file paths in sorted order.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to substitute the template for the Angular UI Bootstrap accordion?

I'm currently using the Angular UI Bootstrap accordion alongside templates. My goal is to find a way to replace the injected template that comes with the accordion directive, without having to modify the actual UI library. Is there any possible method ...

Creating a TeeChart for HTML5 that combines both stacked and normal series can be done by following these steps

Hey there! I'm currently utilizing TeeChart for HTML5 and I'm wondering how to create a chart with both stacked and normal series. Specifically, I need two series to be stacked and a third one to remain unstacked (normal). I attempted to utilize ...

Struggling to adjust the width of a div accurately following the population of AJAX content

This particular piece of code is responsible for populating an inner div within an image slider by making an Ajax call : $.ajax({ type: "GET", dataType: 'json', url: $(this).attr('href') }).done(function (result) { ...

Do not generate an HTML cookie

I've encountered an issue while trying to create a cookie using the following code: window.onload = function() { var value = readCookie('username'); if(value == null){ alert("null"); document.cookie = "username=Bob; expires=Thu, 18 ...

Dealing with Typescript: Reducing an object containing other objects

Having some difficulties implementing a reduce function with TypeScript - struggling with types and return value. Facing issues with omitting controls from Storybook, causing two TypeScript errors indicated in the code marked ** ERROR ** Seeking advice on ...

Navigate to the initial visible element on the specified webpage via the page hash link

In my handlebars HTML template, I have a partial view that includes different pieces of content for desktop and mobile. I use different CSS classes to hide and show these elements accordingly. <div class='hideOnMobile showOnDesktop'> < ...

Divide a JSON dataset into two distinct JSON files and incorporate them within the code

My JSON file structure is as follows: { "rID": "1", "rFI": "01", "rTN": "0011", "rAN": "11", "sID&quo ...

Encountering error TS2307: Module 'redux' not found when trying to implement redux in Angular 7

Currently, I am diving into the world of Redux and attempting to integrate it into my Angular 7 project using ng2-redux. However, upon visiting the npm page, I discovered that the recommended approach was to install it with npm install @angular-redux/store ...

Is foreach not iterating through the elements properly?

In my code, I have a loop on rxDetails that is supposed to add a new field payAmount if any rxNumber matches with the data. However, when I run the forEach loop as shown below, it always misses the rxNumber 15131503 in the return. I'm not sure what I ...

Interactive Div that Adapts

Hello everyone, I'm new to this forum and seeking some assistance. I have a requirement where multiple div contents need to fade in and out dynamically. I found this jsfiddle example that works for 2 divs, but I want it to work for more, say 5 differ ...

The authentication token interceptor fails to capture the request/response of a new route

I have been working on implementing JWT authentication for my Node.js, Express, and AngularJS application. I successfully generated the token and stored it in the localStorage. Following a tutorial on this website, I implemented the authInterceptor in an A ...

How to dynamically create an object with a key and a value as a list in AngularJS

Hello, I have an object with the following structure: [{name: 'abc', country : 'US'},{name: 'xyz', country : 'IN'},{name: 'mno', country : 'US'},{name: 'pqr', country : 'IN'}] ...

Transferring values from jQuery AJAX to Node.js

Is there a way to successfully pass a variable from jQuery to nodejs without getting the [object Object] response? I want to ensure that nodejs can return a string variable instead. $('.test').click(function(){ var tsId = "Hello World"; ...

Retrieve no data from Firebase using Cloud Functions

I am a beginner with Google Firebase and Cloud Functions, and I recently attempted a basic "hello world" program: Established a connection to Cloud Firestore [beta], which contains over 100,000 records. Retrieved the top record from the database. Below ...

How to effectively utilize JSON responses with jQuery Mobile?

I've been facing an issue with working on my JSON result in JavaScript. Can anyone provide some insight? Even though the JSON call returns a success status code (200) and I can view the data in Firebug, no alert is being displayed. $(document).on(& ...

When working with Express router callbacks, the Array.includes() method will always return false, the Array.indexOf() method will always return -1, and

After utilizing fs.readFile() and fs.readFileSync() functions to access the content of 'words_alpha.txt', I discovered that the file can be accessed publicly from this link: https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha. ...

How come my game is not registering a failure when I click on the same card twice?

UI image of the game. Cards with instruments that are clickableThe objective of the game is to avoid clicking the same card twice. If you do, you lose the game. The issue lies in the fact that it continues to cycle through the cards without ending when the ...

Reading a string as JSON with key-value pairs enclosed in single quotes instead of double quotes

const sentence = "{'a':'Your's'}"; JSON.parse(str); When my server responses like the string above, I encounter issues parsing it as JSON. This is just an example text and when attempting to parse, I receive the following error: ...

What advantages does Protractor offer for non-angular applications?

I am in the process of setting up automated tests and am curious about the advantages of using Protractor to automate non-angular applications. Can anyone shed some light on the benefits compared to solely using webdriverJS? ...

Implementing React router for dynamic page rendering

I'm struggling to make sense of a particular piece of code. Can someone provide an explanation? I'm particularly confused about the role of "props" in this section and how it is essential for the code to work correctly. If I remove "props," my co ...