var chokidar = require('chokidar');
var path = require("path");
const { exec } = require('child_process');

var cssDiv = "/home/ubuntu/workspace/c9sdk/build/standalone/skin/workspace-smartface";
var lessDiv = "/home/ubuntu/workspace/c9sdk/node_modules/@smartface/smartface.ui-editor/ui-editor-styles/";
// One-liner for current directory, ignores .dotfiles

chokidar.watch(lessDiv +"*.less", {ignored: /(^|[\/\\])\../}).on('all', (event, lessFile) => {
   console.log(event,` - ` , path.basename(lessFile) ,"  -  Removing build/standalone/skin/workspace-smartface");
   rmAsync(cssDiv).then(res => console.log(res), err => console.log(err));
});

function rmAsync(target){
    return new Promise((resolve, reject) => {
        exec(`rm -rf ${target} `, (error, stdout, stderr) => {
            if (error || stderr)
                reject(error || stderr);
            else
                resolve(stdout);
        });
    });
}