Search code examples
javascriptnode.jsmetalsmith

Metalsmith.js: How to build to same directory as build script?


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.


Solution

  • 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.