Example #1
0
function addItem(all, itemPath) {
    return fs.lstatAsync(itemPath)
    .then(function(stat) {
        if (stat.isFile()) {
            all.files.push(itemPath);
        } else if (stat.isDirectory()) {
            all.dirs.push(itemPath);
        }
    });
}
Example #2
0
// if target exists fails, if forced removes it
function removeTarget(target, opts) {
    return fs.lstatAsync(target)
    .then(function() {
        if (!opts.force) throw new Error('Target ' + chalk.gray(target) + ' exists. Use ' + chalk.bold('--force') + ' flag to remove it before linking.');
        console.log('Removing ' + chalk.gray(target));
        return fs.removeAsync(target);
    })
    .catch(function(e) {
        if (e.code === 'ENOENT') return true;
        throw e;
    });
}
Example #3
0
 return projects.map(function (project) {
     var projectDirectory = project.Path;
     return fs.lstatAsync(projectDirectory).then(function (stats) {
         if (stats.isFile()) {
             projectDirectory = path.dirname(projectDirectory);
         }
         return {
             label: "dotnet restore - (" + (project.Name || path.basename(project.Path)) + ")",
             description: projectDirectory,
             execute: function () {
                 return runDotnetRestore(projectDirectory);
             }
         };
     });
 });
Example #4
0
function doUnlink(target) {
    return fs.lstatAsync(target)
        .then(function(stats) {
            if (stats.isSymbolicLink()) {
                console.log('Removing ' + chalk.gray(target));
                return fs.removeAsync(target)
                .then(function() {
                    utils.ok('Done.');
                });
            } else {
                throw new Error(chalk.gray(target) + ' is not a symlink.');
            }
        })
    .catch(function(e) {
        if (e.code === 'ENOENT') throw new Error(chalk.gray(target) + ' does not exist.');
        throw e;
    });
}
Example #5
0
        .then(function(r) {
            bbrest = r.bbrest;
            jxon = r.jxon;
            cfg = r.config.cli;

            if (cfg.dashboard) return importDashboard();

            if (!cfg.target) return error(new Error('Target is not defined.'));

            return fs.lstatAsync(cfg.target)
            .then(function(stats) {
                if (stats.isDirectory()) {
                    return importDir();
                } else if (stats.isFile()) {
                    var pth = path.parse(cfg.target);
                    if (pth.ext === '.xml') return bbrest.import().post(cfg.target);
                    else if (pth.ext === '.zip') return bbrest.import().file(cfg.target).post();
                    throw new Error('File must be xml or zip archive');
                }
                throw new Error('Target is not directory or file.');
            })
            .then(function(bbr) {
                if (bbr.error) {
                    var emsg = jxon.stringToJs(bbr.body);
                    emsg = emsg.errorMessage || emsg.importErrorMessage || {message: 'Unknown import message.'};
                    console.log(bbr);
                    throw new Error(emsg.message);
                } else ok(bbr);
            })
            .catch(function(err) {
                console.log(err);
                if (err.code === 'ENOENT') return error(new Error('Target does not exist.'));
                return error(new Error(err.statusInfo || err));
            });


        });