Grunt-newer with Grunt-uglify and Bower

I have a project using Grunt and Bower. Grunt-uglify will concatenate / minimize files from the Bower directory to the deploy/scripts.js . I use Grunt-newer, so it will only update deploy/scripts.js if new files are added or changed. Everything works fine ... except ...

When I add a new library with Bower, the file date reflects when the file was downloaded to the Bower library (or the one who places it), not the date that it created on my computer. Thus, Grunt-newer sees that the new Bower libraries are older than deploy/scripts.js and do not update the file.

One cumbersome solution is to open a new library .js file and save it. It changes the dates of the file, and thus grunt-newer creates the deploy/script.js file. However, Bauer's usefulness seems controversial with such an awkward decision.

+5
source share
1 answer

You can use Bower hooks to manipulate file modification time. This is a kind of hack, but you can achieve what you are looking for.
You will need to register the postinstall hook and pass the list of updated components as an argument. When the script is called,% will be replaced by a space-separated list of components that will be installed or removed.
Hooks must be registered in the .bowerrc file:

 { "scripts": { "postinstall": "hook.sh %" } } 

Then you need a script that iterates over the components and changes the file modification time.
For example, a shell script:

 #!/bin/bash for var in " $@ " do find "./bower_components/$var" -exec touch {} \; done 

Here is another example node.js script for the same purpose:

 var fs = require('fs'); var path = require('path') var components = process.argv.slice(2) components.forEach(function (comp) { var comp_path = path.join(process.cwd(),"bower_components",comp); var files = fs.readdirSync(comp_path); files.forEach(function(file) { fs.utimesSync(path.join(comp_path, file), new Date(), new Date()); }); }); 
+2
source

Source: https://habr.com/ru/post/1202195/


All Articles