Integrate JavaScript date into the gulp-rev workflow

I have been encountering an issue while using the gulp-rev plugin to add a revision of my app/html page generated by the Yeomann webapp generator. My workflow involves zipping the app and then adding a revision, but I am having trouble replacing the hash that is created by the gulp-rev plugin.

In my gruntfile.js :

var rev = require('gulp-rev');
var date = new Date(dateString);
gulp.task('rev', function () {
  return gulp.src('app/*.zip')
    .pipe(rev(new Date().toString()))
    .pipe(gulp.dest('deploy/'));
});

The rev-all plugin uses rev-hash to generate the hash:

'use strict';
var crypto = require('crypto');

module.exports = function (buf) {
    if (!Buffer.isBuffer(buf)) {
        throw new TypeError('Expected a buffer');
    }

    return crypto.createHash('md5').update(buf).digest('hex').slice(0, 10);
};

and rev-path to add it to the file name:

      'use strict';
var modifyFilename = require('modify-filename');

module.exports = function (pth, hash) {
    if (arguments.length !== 2) {
        throw new Error('`path` and `hash` required');
    }

    return modifyFilename(pth, function (filename, ext) {
        return filename + '_' + hash + ext;
    });
};

module.exports.revert = function (pth, hash) {
    if (arguments.length !== 2) {
        throw new Error('`path` and `hash` required');
    }

    return modifyFilename(pth, function (filename, ext) {
        return filename.replace(new RegExp('_' + hash + '$'), '') + ext;
    });
};

When I added (new Date().toString()) to the .pipe(rev()), it returned a date string object error. I want to create a custom revision string with the current date or version number e.g., v.1.0.0.

Can someone assist me in replacing the md5 hex with a timestamp in this file?

Answer №1

If you're interested, check out gulp-replace-task. It allows you to define a pattern and insert a timestamp.

.pipe(replace({
  patterns: [
    {
      match: 'timestamp',
      replacement: new Date().getTime()
    }
  ]
}))

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

Using Jquery, take out each parent element and duplicate the child element

It seems to be partially working, but I encounter multiple instances of the cloned element. My goal is to rearrange elements in my JavaScript when the browser viewport reaches a mobile size. Original Order: <div class="sar--img-right-first"> ...

What is the purpose of using a hash in a WebSocket handshake?

When establishing a Websocket connection, the client initiates by connecting to a tcp socket on a server and then performs a handshake. In the client's handshake, there is a base64 encoded key (Sec-WebScoket-Key). The expected response from the serv ...

Can you explain how to retrieve the header value from ng-table?

Is there a way to retrieve the table header for each column from JavaScript? When I call tableTest, it only returns data of each row, not the header names like 'name' and 'description'. Is there a method like tableTest.data-title to acc ...

Navigate to the following input field upon a keyup event occurring within the table

I have a table that contains multiple input fields in a single row within a td element. I am trying to implement functionality that will automatically shift focus to the next input field when any number is entered. The code works perfectly without the tabl ...

Activate Pop-up for a single instance on BigCommerce

After researching and adding my own code, I am still struggling to get this question answered correctly. Here are the key points I am trying to achieve: 1. Automatically open a popup when the homepage loads. 2. Ensure that the popup is centered on all brow ...

CSS to target every second visible tr element using the :nth-child(2n)

My table has a unique appearance (shown below) thanks to the application of CSS nth-child(2n). tr:nth-child(2n) {background-color: #f0f3f5;} I made some elements hidden on the vID, ID, and MO_Sub tr. <tr style="display:none"> The table's new ...

Is it true that Firefox fails to display javascript errors on AJAX 'threads'?

Currently, I have a function called test_fn that is being called in two ways: (a) Through an onclick event of a button; or (b) from the success callback within a jQuery AJAX request, as shown here: $.ajax({ type: 'POST', ... succes ...

Transformation from a class component to a function component in React JS

I have a class component that I need to convert into a functional component. So, I started by refactoring the constructor. Below is the original class component: class EventCalendar extends React.Component { constructor(props) { super(props) ...

Having issues with reading files in PHP using AJAX? Explore alternative methods for downloading files seamlessly

I need to store a value in a txt file and allow the user to download it. Currently, the value is successfully written to the txt file, but the readfile function does not execute, preventing the download from starting. The PHP code is on the same page as ...

What is the best approach for encoding text inputs automatically?

In order to prevent my application from crashing due to the error "A potentially dangerous Request.Form value was detected...", I initially disabled page validation. However, I am now reassessing this approach and aiming to resolve it properly. Is there a ...

Error encountered: ENOSELF - Installation of package "mermaid" denied within the current package context

npm ERROR: code ENOSELF npm ERROR: This package cannot be installed with the name "mermaid" due to a conflicting package already named "mermaid". Please ensure that your project name does not match any dependencies you are installing. ...

In the world of React in Meteor, the command event.preventDefault() doesn't seem

I have encountered an issue with my application development. I am utilizing a submit form in Meteor with React, and although I am using event.preventDefault(), the page continues to reload every time the submit button is clicked. Following a brief delay, i ...

"Error: Vue prop is not defined when passed to computed functions during initial call

I am encountering an issue with my Vue component. Here is the code for reference: Vue.component('result', { props: ['stuff'], data: () => ({}), template: "<img :src='tag' class='result'></img>", ...

Steps to incorporate this jQuery script

After receiving a solution to my problem, I'm struggling with how to actually put it into practice. $(function(){ $.get('file1.php', function(data){ $('#dropdown1').html( data ); }); // when dropdown1 is chang ...

I am experiencing difficulty with jQuery connecting to the elements on my server-generated webpage

My issue lies in using jQuery functionality within the Software AG webMethods IDE, where pages are generated automatically. I am providing jQuery's functions with a server-generated element ID, but it seems that jQuery is unable to interact with it - ...

Issue with MUI Data Grid sorting: Data Grid sortComparator function returning undefined

I'm attempting to organize data with nested values in a data grid, but I keep receiving 'undefined' on the sortComparator of Data Grid Columns. Code: Column Data Setup: { headerName: 'Title', field: `${this.props.type} ...

Is there a way to continuously submit a form in React every 10 seconds, even if it includes events?

I have a form with input fields where I collect data upon form submission. However, I want the form to submit automatically every 10 seconds without the need to click a button or press enter. I tried using useEffect to create an interval, but it resulted i ...

Troubleshooting: ReactJS CSS Class Issue

I'm fairly new to working with ReactJS and I've encountered an issue while trying to create a class for a specific form. Below is the code I've written: import React, { Component, PropTypes } from 'react'; import s from './s ...

Exploring node.js global cli files

I am working on a CLI module that offers the option to be installed either locally or globally. This module utilizes local templates for various functions within the CLI (such as copying them into the current directory). Is there a way to determine the lo ...

ReactJS is in need of extracting certain values from a promise

Within my Firebase database, I have organized data into two Documents: "users" and "posts". Each post in the "posts" collection is linked to a specific user using their unique id from the "users" collection. My goal is to retrieve user data associated wi ...