Udders
Udders

Reputation: 6986

grunt copy moving build folder outside of project

Hello I have a file structure that looks like this,

|-App
|------|src
|----------|js
|----------|img
|----------|css
|----------|less
|----------|tpl
|----------|index.php
|- Gruntfile.js (withing parent app folder)
|- package.json (withing parent app folder)

What I am trying to do is move all the contents of the src folder into a build folder, the build folder gets created but outside of the App folder, and I don't really understand why, secondly when it does copy the src folder it copies the actual src folder, I want to copy all its children but no the parent src folder, and thirdly the copy ignores the index.php file why? Below is my current Gruntfile.js

    module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({

      copy: {
        build: {
            cwd: '.',
            src: ['src/*/*'],
            dest: '../build',
            expand: true
        }
      },
      clean: {
        build: {
            cwd: '.',
            src: ['build']
        }
      }

  });

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

  grunt.registerTask('move', 'Moves the project to the build folder', ['copy', 'clean']);

};

Upvotes: 0

Views: 1204

Answers (1)

thibaultcha
thibaultcha

Reputation: 1320

Your paths are wrong. Change the build options to:

build: {
  cwd: '.',
  src: ['src/**/*'],
  dest: './build',
  expand: true
}
  • ../build meant the build directory was created in the parent dir (.. is the parent dir)
  • src/**/* means recursively copy all files and files of descendent folders.

Upvotes: 1

Related Questions