metalsmith-copy icon indicating copy to clipboard operation
metalsmith-copy copied to clipboard

Doesn't copy

Open plankguy opened this issue 12 years ago • 4 comments

Hey, i'm trying to use this plugin to copy static assets (css, js, images) from my working directory, to the build directory without much success. I'd like my static folder in src:

├─ src
   └─ static
      ├─ css
      ├─ scss
      ├─ js
      └─ images

to be copied to my build dir www:

├─ www
   └─ static (copy)
      ├─ css (copy)
      ├─ js (copy)
      └─ images (copy)

Here's my build.js:

var Metalsmith  = require('metalsmith'),
    markdown    = require('metalsmith-markdown'),
    templates   = require('metalsmith-templates'),
    copy        = require('metalsmith-copy'),
    permalinks  = require('metalsmith-permalinks');

var srcDir      = './src',
    dstDir      = './www';

Metalsmith(__dirname)
    // Use Markdown
    .use(markdown({
        gfm:    true,
        tables: true
    }))
    // Use Swig templates
    .use(templates({
        engine:     'swig',
        directory:  srcDir+'/templates/pages'
    }))
    // Permalinks
    .use(permalinks({
        pattern: ':title'
    }))
    // Copy assets
    .use(copy({
        pattern:    srcDir+'/static/**/*',
        directory:  'static'
    }))
    // Define content source
    .source(srcDir+'/content')
    // Build to /www/
    .destination(dstDir)
    // Do the build
    .build(function(err){
        if (err) throw err;
    });

Am I missing something?!

Also, is there a way to ignore certain files or folders (!./static/scss)?

plankguy avatar Sep 20 '14 23:09 plankguy

Can you try moving the copy earlier in your pipeline? Sometimes earlier steps will move things out of the way and copy can't find them.

I haven't looked at this in a while, so it's probably an incompatibility with a newer version of Metalsmith.

An ignore option would be really nice. I'll implement it when I start working with Metalsmith again.

mattwidmann avatar Sep 22 '14 14:09 mattwidmann

Thanks for the reploy - moving it up didn't work. Oh well...

plankguy avatar Sep 30 '14 06:09 plankguy

Just took a look at this again, and I think it's because the directory you're passing to copy() is static, which is inside of src, but the directory you're passing to the source function is srcDir + '/content', and since copy() looks at directories relative to source, it doesn't see static, which is a subdirectory of src, not content.

Try passing srcDir + '/static/' as directory and '**/*' as pattern.

mattwidmann avatar Nov 05 '14 22:11 mattwidmann

So, my final build.js is:

var Metalsmith  = require('metalsmith'),
    markdown    = require('metalsmith-markdown'),
    templates   = require('metalsmith-templates'),
    copy        = require('metalsmith-copy'),
    permalinks  = require('metalsmith-permalinks');

var srcDir      = './src',
    dstDir      = './www';

Metalsmith(__dirname)
    // Use Markdown
    .use(markdown({
        gfm:    true,
        tables: true
    }))
    // Use Swig templates
    .use(templates({
        engine:     'swig',
        directory:  srcDir+'/content/templates/pages'
    }))
    // Permalinks
    .use(permalinks({
        pattern: ':title'
    }))
    // Copy assets
    .use(copy({
        pattern:    './*',
        directory:  'static'
    }))
    // Define content source
    .source(srcDir)
    // Build to /www/
    .destination(dstDir)
    // Do the build
    .build(function(err){
        if (err) throw err;
    });

mattwidmann avatar Nov 05 '14 22:11 mattwidmann