Skip to content

Commit

Permalink
Copy hooks assets not only in api/hooks folder but in production and …
Browse files Browse the repository at this point in the history
…tmp folder too
  • Loading branch information
Pierre-Gilles committed Dec 6, 2018
1 parent f474b75 commit 9131b1a
Showing 1 changed file with 53 additions and 43 deletions.
96 changes: 53 additions & 43 deletions tasks/register/copyHooksAssets.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
var fs = require('fs');
var fse = require('fs-extra')

module.exports = function (grunt) {

grunt.registerTask('copyHooksAssets', 'Copy all hooks assets', function() {

var done = this.async();
var path = './api/hooks/';
var assetsDestination = './assets/hooks/';

// we first get sure that the hooks directory exist
fse.ensureDirSync(path);

// first, we clean the assets hooks directory
// if the directory does not exist, it is created
fse.emptyDirSync(assetsDestination);

// we read all the modules
var modules = fs.readdirSync(path);

// foreach module
modules.forEach(function(module){

// we test if it's a directory
if(fs.lstatSync(path + module).isDirectory()){

// we test if there is an assets folder to copy
try{
var assetsDir = path + module + '/assets';
if(fs.lstatSync(assetsDir).isDirectory()){

// copying assets of module
console.log('Copying assets of module ' + module);
fse.copySync(assetsDir, assetsDestination + module);
}
} catch(e){
console.log('No assets to copy for module ' + module);
}

}
});
done();
var fse = require('fs-extra');

module.exports = function(grunt) {

grunt.registerTask('copyHooksAssets', 'Copy all hooks assets', function() {

var done = this.async();
var path = './api/hooks/';
var assetsDestination = './assets/hooks/';

// we first get sure that the hooks directory exist
fse.ensureDirSync(path);

// first, we clean the assets hooks directory
// if the directory does not exist, it is created
fse.emptyDirSync(assetsDestination);

// we read all the modules
var modules = fs.readdirSync(path);

// foreach module
modules.forEach(function(module) {

// we test if it's a directory
if (fs.lstatSync(path + module).isDirectory()) {

// we test if there is an assets folder to copy
try {
var assetsDir = path + module + '/assets';
if (fs.lstatSync(assetsDir).isDirectory()) {

// copying assets of module
console.log('Copying assets of module ' + module);
fse.copySync(assetsDir, assetsDestination + module);
}
} catch (e) {
console.log('No assets to copy for module ' + module);
}

}
});
};

var assetsDestinationProd = './www/hooks/';
var assetsDestinationProdTmp = './.tmp/public/hooks/';

console.log('Copying all assets to ' + assetsDestinationProd);
fse.copySync(assetsDestination, assetsDestinationProd);

console.log('Copying all assets to ' + assetsDestinationProdTmp);
fse.copySync(assetsDestination, assetsDestinationProdTmp);

done();
});
};

0 comments on commit 9131b1a

Please sign in to comment.