Grunt: The target file will have the same name as the source file once it has been templ

I am attempting to template all files within a particular directory and save the output in the bin/admin folder, where each destination file will have the same name as its corresponding source file. However, I am facing an issue with specifying the dest in data, as it appears to only accept the filename and not a destination directory.

module.exports = function(grunt) {
  grunt.initConfig({
    'template': {
      'process-html-template': {
        'options': {
          'data': {
            'api_url': 'My blog post'
          }
        },
        'files': {
          'bin/admin/': ['src/admin/*'] // <-- Here
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-template');
  grunt.registerTask('default', ['template']);
}

Is there a way to template all files within the src/ directory and store them in a destination folder with the same name? I attempted using bin/admin/* as the destination path, but that simply resulted in a file named * within bin/admin. I wish to avoid manually listing out every file within the source directory.

Answer №1

After some investigation, I have discovered the solution. It involves an object containing a 'src' and 'dest' attribute.

module.exports = function(grunt) {
  grunt.initConfig({
    'template': {
      'process-html-template': {
        'options': {
          'data': {
            'api_url': 'My API endpoint'
          }
        },
        'files': [
          {
            expand:true,
            src: 'src/admin/*',
            dest: 'bin/admin/'
          }
        ]
      }
    }
  });

  grunt.loadNpmTasks('grunt-template');
  grunt.registerTask('default', ['template']);
}

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

Ways to parse the data from a response received from an Axios POST request

After sending the same POST request using a cURL command, the response I receive is: {"allowed":[],"error":null} However, when I incorporate the POST request in my code and print it using either console.log("response: ", resp ...

Creating a collection by gathering data from interactive fields with the help of AngularJS

I have a project to create an attendance system for employees. The system requires me to track the attendance status of each employee by generating a dynamic form with text input fields and checkboxes using angularjs ng-repeat inside a table. This form wil ...

steps for incorporating AngularJS code into a bootstrap modal within an asp.net core mvc application

I am encountering an issue with using AngularJS code inside a Bootstrap modal. I am loading the modal using jQuery code, and after loading it, I want to utilize Angular JS code to fetch and insert data. The Angular code works perfectly fine in a separate v ...

Incorporating HTML into the Ajax Response

I recently encountered a strange issue with a service that returns an HTML page as the AJAX response. This page contains a form that is automatically triggered by scripts within the page, resulting in a POST request being sent when the page is rendered. My ...

What is the best way to fetch the data from this API?

function fetchCoinPrice(coinName) { return axios .get( `https://min-api.cryptocompare.com/data/pricemulti?fsyms=${coinName}&tsyms=EUR` ).then((response) => (response.data[coinName]["EUR"])); The JSON response for the coin "BTC" is: ...

Is it possible to integrate the screenfull JavaScript library into the Next.js framework?

Attempting to utilize Dynamic Importing in Nextjs for incorporating the screenfull library has proven unsuccessful. import dynamic from "next/dynamic" import screenfull from 'screenfull'; const Screenfull = dynamic(()=>{return import ...

React error #425: Timezone formatting causing minification issue

Encountering a strange issue that seems to only occur on Vercel. The error message reads: Uncaught Error: Minified React error #425; visit https://reactjs.org/docs/error-decoder.html?invariant=425 for the full message or use the non-minified dev environme ...

Is there a way to bypass end-tags (HTML) in the VS code editor?

After setting up VS code editor with default configurations, I noticed that when I input HTML code like the opening tag <title>, the closing tag </title> is automatically generated. However, once I enter the title inside these tags, I find myse ...

Mastering the art of utilizing $filter alongside select in angular.js

Is there a way to switch between different filters based on the user's selected values? I have three filters ('largeNumber', 'Percentage', 'Bytes') and I want to toggle between these filters based on the selection made by ...

Trying to fix the "E: Malformed entry 1 in list file" error in WSL Ubuntu? Rest assured, the list file is accurate

Recently, I followed the Atlas CLI installation steps outlined on MongoDB's official website here, and everything seemed to go smoothly until I reached this point: To set up the list file /etc/apt/sources.list.d/mongodb-org-6.0.list for my Ubuntu ver ...

Encountering an issue when attempting to update by pressing the button

I am encountering a challenge in my Vue application that involves inserting, updating, and deleting posts using MongoDB. Specifically, I am facing an issue with the update function. Whenever I attempt to update a post by clicking the corresponding button, ...

Anomaly in Date String Comparison within Angular Controller

Having a puzzling issue when attempting to compare two date strings within my Angular Controller. It seems that the comparison is yielding unexpected results. To explain, I first convert today's date to a string ("2/5/2016") and then proceed to use it ...

Loading gltf files with Three.js does not automatically update external variables

When I import a gltf object, it seems to render in the browser but I am unable to access it using an outside variable. What could be causing this issue? let loadedModel; gltfLoader.load('./assets/javaLogo.gltf', function(gltf){ loadedModel = ...

Creating a Vertical Navbar Dropdown in Bootstrap 3.0 Without Appending to the Last List Item Only

Currently, I'm in the process of creating a panel layout that features an elegant vertical navbar. Although everything seems to be aligned correctly and I've managed to implement a dropdown menu in a vertical layout, it keeps appending to the las ...

Extract the ID from the array, save it, and then delete it from the local storage

I am currently developing a mobile application using Angular, JavaScript, Ionic, and Cordova. Within one of my functions, I make use of an array called existingEntries, which is stored as a variable. categories: Array [276] [0...99] 0: Object id ...

Storing a token in NodeJS using JavaScript

We currently have a mobile single-page application built using HTML/CSS/NodeJS. The functionality of this app requires numerous API calls, all of which require a bearer token for authorization purposes. This bearer token is simply a string value that we ge ...

Node.js server allows for accessing AJAX requests seamlessly

I need to send a parsed AST of JavaScript code to a server for processing, and then receive a list of completions back. However, when I log the AST to the client console before sending it, the structure appears like this: [ { "id":0, "type":"Program", "ch ...

Angular Testing - issue with promise returning unexpected results

I'm having trouble with populating vm.chartData in my HomeCtrl. Even though I've mocked data to it in the beforeEach() function, when I console.log(scope.vm.chartData), it returns undefined. However, other scope variables like graphLoading are pr ...

Using Backbone to Handle Different Data Formats

I have a unique text file containing date-time data in the format below: 2014-03-14T16:32 2014-03-15T13:04 2014-03-16T06:44 ... I want to use this static file as a read-only data source for my backbone collection. However, the current format is not suita ...

Is there a way to display the overall count of items in ReCharts?

I'm curious about how to access the additional data items within the 'payload' field of recharts when using material-ui. Despite my efforts to find relevant sources, I have not come across any references pertaining to accessing other group n ...