javascriptgulpgulp-ftpvinyl-ftp

Gulp deploy ftp to production


I am using some gulp task to deploy to production, but i have problem with gulp-deploy, i need some other files form other folder to be copied on diferrent location on server this is my task

//Gulp APP ftp deploy
gulp.task('deploy-app', function () {

    var conn = ftp.create({
        host: 'xxx',
        user: 'xxx',
        password: 'xxx',
        parallel: 10,
        log: gutil.log
    });

    var globs = [
        './css/**/*{css,png,jpg,gif,ttf,woff,eof,svg,woff2}',
        './img/**',
        './views/**',
        './scripts/**',
        'index.html',
        'Web.config'
    ];

    // using base = '.' will transfer everything to /public_html correctly 
    // turn off buffering in gulp.src for best performance 

    return gulp.src(globs, { base: '.', buffer: false })
        .pipe(conn.newer('/site/wwwroot')) // only upload newer files 
        .pipe(conn.dest('/site/wwwroot'));

});

The problem I have here is that i dont need index.html from root, because i have another index.html that is inside folder dist but it has to go in root of the server folder, how to do that


Solution

  • Use gulp-if in combination with gulp-rename to change only the destination directory for your index.html file without affecting any of the other files:

    var gulpIf = require('gulp-if');
    var rename = require('gulp-rename');
    
    gulp.task('deploy-app', function () {
    
        var conn = ftp.create({
            host: 'xxx',
            user: 'xxx',
            password: 'xxx',
            parallel: 10,
            log: gutil.log
        });
    
        var globs = [
            './css/**/*{css,png,jpg,gif,ttf,woff,eof,svg,woff2}',
            './img/**',
            './views/**',
            './scripts/**',
            './dist/index.html',
            'Web.config'
        ];
    
        return gulp.src(globs, { base: '.', buffer: false })
            .pipe(gulpIf('dist/index.html', rename({dirname:''})))
            .pipe(conn.newer('/site/wwwroot')) 
            .pipe(conn.dest('/site/wwwroot'));
    });