Grunt-发送HTTP请求后,如何复制文件/文件夹?

问题描述

我有以下module.exports = function(grunt) { // Project configuration. grunt.initConfig({ //to create a new directory mkdir: { all: { options: { create: ['dest/'] },},copy: { main: { files: [ // includes files within path and its sub-directories {expand: true,cwd: 'cs-template/',src: ['**/*'],dest: 'dest/'},],watch: { copy: { files: 'api/routes/*.js',tasks: ['copy'] },} }); //grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-mkdir'); grunt.loadNpmTasks('grunt-contrib-copy'); //grunt.loadNpmTasks('grunt-exec'); grunt.loadNpmTasks('grunt-contrib-watch'); // Default task(s). grunt.registerTask('default',['mkdir','copy','watch']); };

const router = require('express').Router();
var art_categories = require('../controllers/art_categoriesController');

router.get('/art_categories',async(req,res) => {
  art_categories.list_all_art_categories(req,res);
});

router.post('/art_categories',res) => {
  art_categories.create_a_art_category(req,res);
});

router.get('/art_categories/:art_categoryId',res) => {
  art_categories.read_a_art_category(req,res);
});

router.put('/art_categories/:art_categoryId',res) => {
  art_categories.update_a_art_category(req,res);
});

router.delete('/art_categories/:art_categoryId',res) => {
  art_categories.delete_a_art_category(req,res);
});

module.exports = router;

还假设我在api / routes /文件夹中有一个这样的JS文件:

art_category

我想做的是,每当发送HTTP请求时(例如,我发送POST请求以创建新的cs-template),我都希望通过复制从目录({{1} })到另一个destcs-templatedest处于同一级别(在Gruntfile.js中定义了复制逻辑,请检查)。我怎样才能做到这一点?我可以运行grunt copy来复制文件夹/文件,但是我希望在发送发帖请求时自动进行。

cs-template目录的结构:

cs-template
  |_
    public
    |_
      someFile.js
  |_
    src
  |_
   .env
  |_
    package.json

P.S:还有一件事,当我使用grunt copy复制cs-template的内容时,.env文件似乎没有被复制。为什么呢?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)