Code Monkey home page Code Monkey logo

Comments (20)

tkellen avatar tkellen commented on August 21, 2024 7

Try this:

copy: {
  html: {
    expand: true,
    cwd: 'src/html/',
    src: '*',
    dest: 'build/html/'
  }
}

from grunt-contrib-copy.

tkellen avatar tkellen commented on August 21, 2024

Please post the contents of your Gruntfile.

from grunt-contrib-copy.

 avatar commented on August 21, 2024

Gruntfile.js

module.exports = function(grunt) {
  // Project configuration.
  grunt.initConfig({
      // Metadata.
      pkg: grunt.file.readJSON('package.json'),
    copy: {
      main: {
        files: {
          //src: ["src/html/*.html"], dest: "build/html/", filter: "isFile"
          //"build/html/": ["src/html/*"]
          //src: ['src/html/*'], dest: 'build/html/', filter: 'isFile' // includes files in path
          //src: ['src/html/**'], dest: 'build/html/' // includes files in path and its subdirs
          expand: true, cwd: 'src/html/', src: ['*'], dest: 'build/html/' // makes all src relative to cwd
        }
      },
    watch: {
      html: {
        files: ["src/html/*.html"],
        tasks: ['copy']
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.registerTask("watch--",["watch"]);
};

from grunt-contrib-copy.

bobspace avatar bobspace commented on August 21, 2024

I'm having the same problem. I stripped down my Gruntfile to only show the relevant pieces.

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({

    copy: {
        the-thing: {
            files: [
                {
                    src:"../other-project/release/other-project/**",
                    dest:"main-project/lib/plugins/other-project/"
                }
            ]    
        }
    },
});


grunt.loadNpmTasks('grunt-contrib-copy');

// Default task.
grunt.registerTask('default', ['copy:the-thing']);

};

// The result is a folder structure like this: main-project/lib/plugins/other-project/release/other-project.
// The desired result is: main-project/lib/plugins/other-project.

from grunt-contrib-copy.

tkellen avatar tkellen commented on August 21, 2024

@bobspace you need to define a cwd, please see:
http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically

from grunt-contrib-copy.

tkellen avatar tkellen commented on August 21, 2024

@niusaul I'm sorry, I don't quite understand the question. Can you please rephrase, or post an example tree listing of what you're trying to get from and to?

from grunt-contrib-copy.

bobspace avatar bobspace commented on August 21, 2024

Should the working directory be the source, or destination directory?

from grunt-contrib-copy.

tkellen avatar tkellen commented on August 21, 2024

cwd should be the source path. anything not included in the cwd will be included in the destination files. try running grunt with --verbose to see what you're expanding to if you are confused.

from grunt-contrib-copy.

 avatar commented on August 21, 2024

I want to copy all the files from "src/html/" to "build/html/".

The my-project structure is: "my-project/src/html/some-files.html".

The desired result is: "my-project/build/html/some-files.html"

With options "expand: true, cwd: 'src/html/', src: ['*'], dest: 'build/html/", the undesired result is "my-project/build/html/src/html/some-files.html".

I've also tried all the other options, but still can't get the desired result.

Hope this is clearer.

Thx

from grunt-contrib-copy.

tkellen avatar tkellen commented on August 21, 2024

The configuration you've defined there should work fine. Could you please post the console log from running this task with --verbose please?

from grunt-contrib-copy.

 avatar commented on August 21, 2024

here a new simplified Gruntfile.js, but there's an error that I am trying debugging...

module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
copy: {
target: {
options: {
cwd: "src/html/"
},
files: {
"build/html/": ["*.html"]
}
}
}
});

grunt.loadNpmTasks('grunt-contrib-copy');

grunt.registerTask("copy--",["copy"]);

};

error running grunt copy --verbose:

MacPro:template Chinh$ grunt copy --verbose
Initializing
Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt-contrib-copy" local Npm module tasks.
Reading /Users/Chinh/Google Drive/DEV/template/node_modules/grunt-contrib-copy/package.json...OK
Parsing /Users/Chinh/Google Drive/DEV/template/node_modules/grunt-contrib-copy/package.json...OK
Loading "copy.js" tasks...OK

  • copy
    Loading "Gruntfile.js" tasks...OK
  • copy--

Running tasks: copy

Running "copy" task

Running "copy:target" (copy) task
Verifying property copy.target exists in config...OK
Files: [no src] -> build/html/
Options: processContent=false, processContentExclude=[], cwd="src/html/"

Done, without errors.

from grunt-contrib-copy.

 avatar commented on August 21, 2024

pls see previous updated comment, no error with different issue "Files: [no src] -> build/html/"

from grunt-contrib-copy.

 avatar commented on August 21, 2024

with the last config above,
if set to "build/html/": [""], I get all the files/dirs of the root
if set to "build/html/": ["
*"], I get all the files/dirs/subdirs/subfiles of the root (everything from the root)

from grunt-contrib-copy.

 avatar commented on August 21, 2024

You're the man!

Thank you very much

from grunt-contrib-copy.

tkellen avatar tkellen commented on August 21, 2024

:)

from grunt-contrib-copy.

jpdevries avatar jpdevries commented on August 21, 2024

Just had the same issue but @tkellen solution worked for me also. thanks!

from grunt-contrib-copy.

henrypenny avatar henrypenny commented on August 21, 2024

Just a thought...
I often find linking files is an easier method than copying.
Its also much faster than copying files.

Have a look at grunt-shell...

shell: {
link: {
options: {
stdout: true
},
command: 'ln -sF ../vendor ./source/vendor; '
}
}

With this approach I only ever have one real copy of my vendor files.

It is a platform specific option though... works for me on Mac and Debian.
I haven't seen any other down side so far...

from grunt-contrib-copy.

simshanith avatar simshanith commented on August 21, 2024

@henrypenny check out grunt-contrib-symlink

from grunt-contrib-copy.

henrypenny avatar henrypenny commented on August 21, 2024

@simshanith even better. :)

from grunt-contrib-copy.

vgrinko avatar vgrinko commented on August 21, 2024

@tkellen very helpful, thank you!

from grunt-contrib-copy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.