From 9131b1ae7722d9e50265fab0421da0b4edfcb51d Mon Sep 17 00:00:00 2001 From: Pierre-Gilles Leymarie Date: Thu, 6 Dec 2018 17:15:37 +0800 Subject: [PATCH] Copy hooks assets not only in api/hooks folder but in production and tmp folder too --- tasks/register/copyHooksAssets.js | 96 +++++++++++++++++-------------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/tasks/register/copyHooksAssets.js b/tasks/register/copyHooksAssets.js index 1e87cc02c4..7114a6aaee 100644 --- a/tasks/register/copyHooksAssets.js +++ b/tasks/register/copyHooksAssets.js @@ -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(); + }); +}; \ No newline at end of file