curist / grunt-bower

grunt task to copy bower installed packages to other folder(s)
MIT License
93 stars 27 forks source link

Multiple Main files aren't copied correctly #20

Closed Kuirak closed 10 years ago

Kuirak commented 10 years ago

hey i am using grunt-bower to copy my bower packages in a new folder, when i tried using bootstrap i stumbled on to a problem: it is copying the files but not only the source files but the complete path

I get _public/js/bowercomponents/dist/js/bootstrap.js instead of public/js/bootstrap.js

other packages work like intended

When adding these to the config:

options: {
                packageSpecific: {
                    bootstrap: {
                        files: [
                            "./dist/js/bootstrap.js",
                            "./dist/css/bootstrap.css",
                            "./dist/fonts/glyphicons-halflings-regular.eot",
                            "./dist/fonts/glyphicons-halflings-regular.svg",
                            "./dist/fonts/glyphicons-halflings-regular.ttf",
                            "./dist/fonts/glyphicons-halflings-regular.woff"
                        ],
                        dest: '.tmp/public/fonts',
                        css_dest: '.tmp/public/css/bootstrap'
                    }
                }

Everything get compied where it should but it copies a extra copy like before

curist commented 10 years ago

Just tested with the config you provided. Except package specified destination doesn't work, the rest works as expected.

Using your config and run grunt bower, I got the following structure:

.tmp
└── public
    ├── css
    │   └── bootstrap
    │       └── bootstrap.css
    └── fonts
        ├── bootstrap.js
        ├── glyphicons-halflings-regular.eot
        ├── glyphicons-halflings-regular.svg
        ├── glyphicons-halflings-regular.ttf
        └── glyphicons-halflings-regular.woff
Kuirak commented 10 years ago

strange because it is copying the complete bowercomponents/dist tree aditionally e.g: .tmp\public\js\components\bowercomponents\bootstrap\dist\js\bootstrap.js .tmp\public\js\components\bootstrap.js

my complete task looks like:

grunt.config.set('bower', {
        dev: {
            dest: '.tmp/public',
            js_dest: '.tmp/public/js/components',
            css_dest: '.tmp/public/styles/components',
            options: {
                packageSpecific: {
                    bootstrap: {
                        files: [
                            "./dist/js/bootstrap.js",
                            "./dist/css/bootstrap.css",
                            "./dist/fonts/glyphicons-halflings-regular.eot",
                            "./dist/fonts/glyphicons-halflings-regular.svg",
                            "./dist/fonts/glyphicons-halflings-regular.ttf",
                            "./dist/fonts/glyphicons-halflings-regular.woff"
                        ],
                        dest: '.tmp/public/fonts',
                        css_dest: '.tmp/public/css/bootstrap'
                    }
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-bower');
curist commented 10 years ago

Duh.. still can't reproduce it. Will look into this again later.

Kuirak commented 10 years ago

Ok , no problem, i put bootstrap in manually for now. Tell me if you need anything else.

curist commented 10 years ago

Please use this gist https://gist.github.com/curist/10078523 and see if you still have this problem.

jooyunghan commented 10 years ago

I had this problem and figured it out. grunt-bower/tasks/lib/helpers.js line 50 and its 'else' part doesn't path.join with components_path I patched as following:

if(typeof main_path === 'string') {
    main_path = path.join(components_path, main_path);
...
} else {
    // array, falling through
    main_path = main_path.map(function(file) {
      return path.join(components_path, file);
    });
    return main_path;
  }

Also, make sure .bowerrc's directory ends with /. Otherwise bower.commands.list will generate quite weird relative paths (with duplicate of last part of path).

curist commented 10 years ago

Eh, that's weird. The main_path is passed from bower.command.list, and it's the full path to the files. What's the result of bower list --paths?

And about the .bowerrc's directory issue, I tested both with or without /, all runs fine for me. Are you guys running a windows machine?

jooyunghan commented 10 years ago

I was wrong about a trailing slash issue. I found 'bower list --path' issue https://github.com/bower/bower/issues/928 For me bower.commands.list 's result list contains inappropriate paths then causes copy failure.

curist commented 10 years ago

That seems to nailed it, will think about how to deal with it. Thanks for reporting this!

jooyunghan commented 10 years ago

I work around that by passing options with 'relative : false'.

On Wed, Apr 9, 2014 at 12:05 PM, Curtis Chang notifications@github.comwrote:

That seems to nailed it, will think about how to deal with it. Thanks for reporting this!

— Reply to this email directly or view it on GitHubhttps://github.com/curist/grunt-bower/issues/20#issuecomment-39924507 .

Jooyung Han

curist commented 10 years ago

Yea, that works. Thanks!