How should I move or delete files in a Yeoman Generator?

yeoman, yeoman-generator

Solution

I just use rimraf like this:

MyGenerator.prototype.removeDir = function removeDir () {
    var cb = this.async(),
        self = this;

    rimraf('path/to/dir', function () {
        self.log.info('Removing dir');
        cb();
    });
};

Remember to add `rimraf` as a dependency in your `package.json` file. Not sure if there's a built-in function for this but this one's been working fine for me so far.

Problem

I'm building a generator that in part includes scaffolding from another project created with `exec`. Depending on user input I need to move or delete parts of this scaffolding. Right now I'm doing it with node's `fs.child_process.spawn` and `shelljs`, but seeing as the Yo generator has `mkdir`, `write`, `template`, and `copy`, I'm wondering if there's a Yo way to move or delete files and directories.

Original source