const gulp = require(“gulp”);
    const ftp = require(“vinyl-ftp”);
    const filter = require(“gulp-custom-filter”);
    const hashsrc = require(“gulp-hash-src”);
    const moment = require(“moment”);
    const
    = require(“lodash”);
    const clean = require(‘gulp-clean’);
    const runSequence = require(‘run-sequence’);
    const logger = require(“gulplog”);

    // js压缩
    const uglify = require(‘gulp-uglify’);
    const babel = require(‘gulp-babel’);

    const destPath = ‘./dist-aspx’;
    const basePath = “../CrmStand”;

    /**

    • 筛选最近修改的文件

    • @param {File} file

    • @returns
      /
      function MyFilter(file) {
      const flag = moment(file.stat.mtime).isAfter(moment().add(-60
      8, “minutes”));
      return flag;
      }

    /**

    • 获取忽略的文件夹

    • @param {String} basePath

    • @returns
      */
      function GetIgnoreList(basePath) {
      const folders = [
      “bin”,
      “obj”,
      “Log”,
      “static”,
      “static-com”,
      “img”
      ];

    return _.flatten(
    folders.map(t => [!${basePath}/${t}, !${basePath}/${t}/**])
    );
    }

    gulp.task(‘build-clean’, function () {
    return gulp.src(destPath, {
    read: false
    })
    .pipe(clean({
    force: true
    }));
    });

    // html css aspx 文件添加hash
    gulp.task(“build-aspx”, function () {
    const globs = [
    …GetIgnoreList(basePath),
    “!” + basePath + “/.html”,
    basePath + “/**/.{aspx,html,css,Master,ascx}”
    ];

    return gulp
    .src(globs)
    .pipe(filter(MyFilter))
    .pipe(
    hash_src({
    build_dir: basePath,
    src_path: basePath
    })
    )
    .pipe(gulp.dest(destPath));
    });

    // js文件 转es5/压缩
    gulp.task(‘build-scripts’, function () {
    const globs = [
    …GetIgnoreList(basePath),
    basePath + “/*/.js”
    ];

    return gulp.src(globs)
    .pipe(filter(MyFilter))
    // .pipe(babel({
    // presets: [‘@babel/env’] //babel转义
    // })) //取消注释 会进行babel转义
    // .pipe(uglify({
    // mangle: false //取消变量压缩 angularjs
    // })) //取消注释 会压缩文件
    .pipe(gulp.dest(destPath));
    });

    function CreateGulp(remotePath) {
    const config = {
    host: “39.106.122.138”,
    user: “ftp_user”,
    password: “aXyD0BZSQT4If7gt5wnSLabbMBtATPfq”,
    port: 21,
    parallel: 10,
    log: logger.info
    };

    return function () {
    const conn = ftp.create(config);

    1. const globs = [
    2. destPath + '/**/*',
    3. ]
    4. // using base = '.' will transfer everything to /public_html correctly
    5. // turn off buffering in gulp.src for best performance
    6. return gulp
    7. .src(globs, {
    8. base: destPath,
    9. buffer: false
    10. })
    11. .pipe(filter(MyFilter))
    12. .pipe(conn.newerOrDifferentSize(remotePath))
    13. .pipe(conn.dest(remotePath));

    };
    }

    gulp.task(“ftp-aspx1”, CreateGulp(“/crm/CrmStand”));
    gulp.task(“ftp-aspx2”, CreateGulp(“/crm_sha/CrmStand”));

    // This will run in this order:
    // build-clean
    //
    build-scripts and build-styles in parallel
    // build-html
    //
    Finally call the callback function
    gulp.task(‘aspx’, function (callback) {
    runSequence(‘build-clean’,
    [‘build-scripts’, ‘build-aspx’],
    [‘ftp-aspx1’, ‘ftp-aspx2’],
    callback);
    });