componentjs / builder2.js

builder for component
50 stars 20 forks source link

Example from documentation does not copy files #69

Closed ismay closed 10 years ago

ismay commented 10 years ago

The example from the documentation does not copy files to the destination folder when the copy() plugin is used instead of the symlink() plugin.

  // only copy `images` to the build folder
  build.files(tree)
    .use('images', build.plugins.copy())
    .end(); // callback optional

It seems like there's something missing from the example (I assume that the actual copying still has to be done, with a callback maybe?), but I'm not able to figure it out from the docs alone, as I couldn't find any documentation on what the copy plugin actually does. My full code is:

var fs = require('fs');
var resolve = require('component-resolver');
var build = require('component-builder');
var mkdirp = require('mkdirp');

var argv = require('minimist')(process.argv.slice(2), {boolean: true}); // parse argument options
var src = process.cwd() + '/' + argv.src;
var dest = process.cwd() + '/' + argv.dest;
var components = process.cwd() + '/' + argv.components;
var buildname = argv.buildname;
var dev = argv.dev || false;

// resolve the dependency tree
resolve(src, {
  install: true, // install the remote components locally
  development: dev, // whether to include development components
  out: components // folder to install components to
}, function (err, tree) {
  if (err) throw err;

  // create 'dest' path
  mkdirp(dest, function (err) {
    if (err) throw err;
  });

  // build `.js` files from components' `.scripts` field
  build.scripts(tree)
    .use('scripts', build.plugins.js())
    .end(function (err, string) {
      if (err) throw err;
      fs.writeFileSync(dest + '/' + buildname + '.js', string);
    });

  // build `.css` files from components' `.styles` field
  build.styles(tree)
    .use('styles', build.plugins.css())
    .end(function (err, string) {
      if (err) throw err;
      fs.writeFileSync(dest + '/' + buildname + '.css', string);
    });

  // copy other files to the build folder
  build.files(tree)
    .use('files', build.plugins.copy())
    .use('fonts', build.plugins.copy())
    .use('images', build.plugins.copy())
    .end(); // callback optional
})

and the component I'm trying to compile is:

{
  "name": "boot",
  "images": [
    "logo.jpg"
  ]
}

Maybe the docs could be expanded with an example for .copy(), or elaborate a little on what the .copy() plugin actually does?

ismay commented 10 years ago

Ok, so since I was building to a different folder than build I didn't notice that that's where it was putting the files. Figured out that passing it a different destination like so:

// copy other files to the build folder
build.files(tree, {destination: 'my-build-folder'})
  .use('files', build.plugins.copy())
  .use('fonts', build.plugins.copy())
  .use('images', build.plugins.copy())
  .end(); // callback optional

does the job. Hope that this helps should anyone encounter the same problem.

godserahul1986 commented 8 years ago

Hi,

I know component is no longer maintained. But just wanted to understand the copy process. Is it true that it doesn't copy directories and copies only files present.

{
  "name": "boot",
  "images": [
    "logo.jpg",
    "homepage/adbanner.jpg"
  ]
}

here adbanner.jpg won't be copied right?

timaschew commented 8 years ago

Not sure, but here is the source code: https://github.com/componentjs/builder2.js/blob/master/lib/plugins/copy.js

It uses the cp module https://www.npmjs.com/package/cp