3

I am completely new to metalsmith. I've been following this tutorial: http://www.robinthrift.com/post/metalsmith-part-1-setting-up-the-forge/

I want to build my site to the root directory of my project (the same dir as the build script). I want to do this because I want github pages to play nicely with it. But when I try to build, I get this error: Error: EBUSY, resource busy or locked

Here is my dir structure:

  • project_folder/
    • _site-src/
      • index.html
    • node_modules
    • build.js
    • package.json

Here is my build.js source:

var Metalsmith = require("metalsmith");

Metalsmith(__dirname)
    .source("_site_src")
    .destination(".")
    .build();

What I want my project dir to look like:

  • project_folder/
    • _site-src/
      • index.html
    • node_modules
    • build.js
    • package.json
    • index.html

I don't know what I'm doing wrong. I appreciate any help.

James Khoury
  • 21,330
  • 4
  • 34
  • 65
Kyle Paulsen
  • 956
  • 1
  • 8
  • 22
  • I'm not at a machine where I can test this but I would guess that you're trying to overwrite the files that you're reading from. Try changing it to `.destination("\..")`? – James Khoury Sep 03 '14 at 02:41
  • 1
    Besides needing a double \ to do what I think you mean, it didn't work. I tried "\..", "\\..", "..", ".", "/..", "/." and all of them failed. I just ended up using a grunt build script that copies files out of a build dir into the current dir, however I don't consider that an answer to this question because that's just ridiculous. – Kyle Paulsen Sep 04 '14 at 22:12
  • 1
    I agree that its not a solution. I'd say workaround. Have you tried turning the default option `clean` to false? – James Khoury Sep 05 '14 at 00:43
  • James - That was it. That solved it! How did you figure that out? I feel like that should be in plain sight in some documentation somewhere. If you make that into an answer, I'll mark it as the solution. – Kyle Paulsen Sep 17 '14 at 18:11
  • It was pure speculation. – James Khoury Sep 17 '14 at 23:43

1 Answers1

3

The error message:

Error: EBUSY, resource busy or locked

seems to be a file locked/in use error. (I'm not that familiar with Node.js errors)

I would assume this is happening when Metalsmith tries to clean the build folder (which is your solution folder i.e. a really bad idea). This is on by default but it can be turned off.

To turn this off use:

.clean(false)

before you build.


BUT if you remove items from your source folder they won't be removed from your build folder. You might be able to handle this by a custom clean-up script or plugin.

I'm not experienced with github pages but I think there should be a better alternative to the avoid the problem.

You could possibly add a symbolic link to the build folder from the project folder for the index.html file.

James Khoury
  • 21,330
  • 4
  • 34
  • 65
  • 1
    You can use `git subtree` to get github pages to serve a sub-directory up as the root. If your build directory is called 'build' then: `git subtree push --prefix build origin gh-pages` – poshaughnessy Jun 11 '16 at 07:28
  • Git has nothing to do with this question or answer. – James Khoury Jun 12 '16 at 00:59
  • 1
    Yes it does. The question was asked because he wants "github pages to play nicely with it". You answered: "I'm not experienced with github pages but I think there should be a better alternative to the avoid the problem". And I'm saying the better alternative to avoid the problem is to get Github Pages to serve out a specific subdirectory. – poshaughnessy Jun 13 '16 at 06:38
  • @poshaughnessy Ah I see that now. Still if you think that's an answer then post it. Your comment makes no sense attached to this answer as its addressing the metalsmith.js side of things. – James Khoury Jun 14 '16 at 03:22