Code coverage report for tasks/new.js

Statements: 42.86% (15 / 35)      Branches: 0% (0 / 2)      Functions: 0% (0 / 13)      Lines: 45.45% (15 / 33)      Ignored: none     

All files » tasks/ » new.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 661 1 1 1 1 1 1 1   1       1       1       1             1                       1                                                 1
var Promise = require('es6-promise').Promise;
var replaceStream = require('replacestream');
var shell = require("shelljs");
var init = require('./init');
var log = require('./utils/log');
var exec = require('./utils/exec').exec;
var fs = require('./utils/fs');
var bower = require('./wrappers/bower');
 
function hyphensToSpaces(str){
    var s = str.replace(/(?:^|-)\S/g, function(a) { return a.toUpperCase(); });
    return s.replace(/-/g, ' ');
}
function hyphensToCamel(str){
    return str.replace(/-(.)/g,function(a,b){return b.toUpperCase();});
}
 
function npmGlobalPath() {
    return shell.exec('npm config get prefix', {silent:true}).output.replace(/\s+$/g, '') + "/lib/node_modules" ;
}
 
function renameFiles(project){
    return Promise.all([
        fs.rename('./dot.gitignore', 'dot',''),
        fs.rename('./**/main.*', 'main',project)
    ]);
}
 
function copyBoilerplate(project){
    log.info(" * Copying Files");
    var moduleDir = npmGlobalPath() + '/web-caddy/boilerplate';
    return fs.copyDirectory(moduleDir, './' + project,
        function(read, write, file){
            read.pipe(replaceStream('{{ project }}', project))
                .pipe(replaceStream('{{ project.toCamelCase }}', hyphensToCamel(project)))
                .pipe(replaceStream('{{ project.toWord }}', hyphensToSpaces(project)))
                .pipe(write);
    });
}
 
function newComponent(project) {
    if (fs.existsSync(project)){
        log.onError('`' + project + '` already exists');
    }
    log.onSuccess('Creating New Project :');
    return copyBoilerplate(project).then(function(output) {
        shell.cd(project);
        return renameFiles(project);
    }).then(function(output){
        return init.localGit();
    }).then(function(output){
        return init.git({project: project});
    }).then(function(){
        log.info(['',
            'Ready!',
            ' * Please go to your new directory:        $ cd ' + project,
            ' * Install Modules:                        $ npm i',
            ' * View the basic site, run:               $ npm start',
            ' * Test on the fly, run in a new tab:      $ npm run tdd',
            ' * To see more tasks please go to : ',
            '   https://github.com/peter-mouland/web-caddy/blob/master/docs'
        ].join('\n'));
    }).catch(log.onError);
}
 
module.exports = newComponent;