复制许多文件夹时出错

时间:2015-08-25 14:48:19

标签: gruntjs grunt-contrib-copy

我对咕噜很新,所以我需要一些帮助。

我在官方gruntjs/grunt-contrib-copy上提出这个问题,但没有得到回复。

我想使用grunt-contrib-copy从某个目录复制文件到另一个目录,它们看起来像这样:

parentpath/ (source file)
    /assets/sass/bootstrap/
    /assets/sass/fontawesome/
    /assets/sass/storms/
    /assets/sass/wordpress/
    /assets/sass/_layout.scss
    /assets/sass/_woocommerce.scss

childpath/ (destiny file)
    /assets/sass/bootstrap/
    /assets/sass/fontawesome/
    /assets/sass/storms/
    /assets/sass/wordpress/
    /assets/sass/_layout.scss
    /assets/sass/_woocommerce.scss

我的gruntfile以这种方式配置:

copy: {
    parenttheme_bootstrap: {
        src: '<%= dirs.parentpath %>/assets/sass/bootstrap',
        dest: '<%= dirs.sass %>'
    },
    parenttheme_fontawesome: {
        src: '<%= dirs.parentpath %>/assets/sass/fontawesome',
        dest: '<%= dirs.sass %>'
    },
    parenttheme_storms: {
        src: '<%= dirs.parentpath %>/assets/sass/storms',
        dest: '<%= dirs.sass %>'
    },
    parenttheme_wordpress: {
        src: '<%= dirs.parentpath %>/assets/sass/wordpress',
        dest: '<%= dirs.sass %>'
    },
    parenttheme_partials: {
        files: [{
                expand: true,
                cwd: '<%= dirs.parentpath %>/assets/sass/',
                src: '_layout.scss',
                dest: '<%= dirs.sass %>'
            },
            {
                expand: true,
                cwd: '<%= dirs.parentpath %>/assets/sass/',
                src: '_woocommerce.scss',
                dest: '<%= dirs.sass %>'
        }]
    }
}

// parent Task
grunt.registerTask( 'parent', [
    'copy:parenttheme_bootstrap',
    'copy:parenttheme_fontawesome',
    'copy:parenttheme_storms',
    'copy:parenttheme_wordpress',
    'copy:parenttheme_partials',
    'sass',
    'postcss'
] );

当我运行父任务时,/ assets / sass / bootstrap文件夹被正确复制到他的命运中。部分文件也是如此。

但由于某种原因,所有其他文件夹都没有复制,我没有错误!

运行grunt parent --verbose我明白了:

Running tasks: parent

Running "parent" task

Running "copy:parenttheme_bootstrap" (copy) task
Verifying property copy.parenttheme_bootstrap exists in config...OK
Files: ../../childpath/assets/sass/bootstrap -> ../assets/sass
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Creating ../assets/sass
Created 1 directory

Running "copy:parenttheme_fontawesome" (copy) task
Verifying property copy.parenttheme_fontawesome exists in config...OK
Files: ../../childpath/assets/sass/fontawesome -> ../assets/sass
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Creating ../assets/sass
Created 1 directory

Running "copy:parenttheme_storms" (copy) task
Verifying property copy.parenttheme_storms exists in config...OK
Files: ../../childpath/assets/sass/storms -> ../assets/sass
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Creating ../assets/sass
Created 1 directory

Running "copy:parenttheme_wordpress" (copy) task
Verifying property copy.parenttheme_wordpress exists in config...OK
Files: ../../childpath/assets/sass/wordpress -> ../assets/sass
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Creating ../assets/sass
Created 1 directory

Running "copy:parenttheme_partials" (copy) task
Verifying property copy.parenttheme_partials exists in config...OK
Files: ../../childpath/assets/sass/_layout.scss -> ../assets/sass/_layout.scss
Files: ../../childpath/assets/sass/_woocommerce.scss -> ../assets/sass/_woocommerce.scss
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Copying ../../childpath/assets/sass/_layout.scss -> ../assets/sass/_layout.scss
Reading ../../childpath/assets/sass/_layout.scss...OK
Writing ../assets/sass/_layout.scss...OK
Copying ../../childpath/assets/sass/_woocommerce.scss -> ../assets/sass/_woocommerce.scss
Reading ../../childpath/assets/sass/_woocommerce.scss...OK
Writing ../assets/sass/_woocommerce.scss...OK
Copied 2 files

任何人都知道我在这里做错了什么?

谢谢!

2 个答案:

答案 0 :(得分:1)

我认为您只需要尝试一下您的目录和文件规范。一些事情要尝试:

  1. 在您的源路径中添加一个globbing模式,而不仅仅是目录名,例如.../bootstrap/**/*.scss
  2. 在目标路径中添加一个尾部斜杠,因此它显然是一个目录,如dest: '<%= dirs.sass %>/'。 grunt可能正在复制到单个文件输出,而不是目录树。
  3. 一个小例子:

    copy: {
        parenttheme_bootstrap: {
            src: '<%= dirs.parentpath %>/assets/sass/bootstrap/**/*.scss',
            dest: '<%= dirs.sass %>/'
        },
        parenttheme_fontawesome: {
            src: '<%= dirs.parentpath %>/assets/sass/fontawesome/**/*.scss',
            dest: '<%= dirs.sass %>/'
        },
    

答案 1 :(得分:0)

感谢@James的建议,我通过更改为:

来完成这项工作
        sf2_bootstrap: {
            files: [{
                expand: true,
                cwd: '<%= dirs.sfpath %>/assets/sass/bootstrap/',
                src: '**/*.scss',
                dest: '<%= dirs.sass %>/bootstrap/'
            }]
        },

现在我的文件被正确复制了。

詹姆斯解决方案,复制了我的所有文件,但到了错误的目录,我不知道为什么。