text: /**
   * Created by ximing on 2018/5/12.
   */
  "use strict";
  const gulp = require("gulp");
  const path = require("path");
  const babel = require("gulp-babel");
  const sourcemaps = require("gulp-sourcemaps");
  const jsonminify = require("gulp-jsonminify");
  const cssnano = require("gulp-cssnano");
  const rename = require("gulp-rename");
  const htmlmin = require("gulp-htmlmin");
  const imagemin = require("gulp-imagemin");
  const sass = require("gulp-sass");
  
  const notify = require('gulp-notify');
  const plumber = require('gulp-plumber');
  const del = require("del");
  const runSequence = require("run-sequence");
  const gulpIf = require("gulp-if");
  const uglify = require("gulp-uglify");
  const gwcn = require('./plugins/copy-npm');
  
  const isProd = () => process.env.NODE_ENV === "production";
  
  const NODE_ENV = process.env.NODE_ENV;
  const debug = NODE_ENV != 'production' ? true : program.debug ? true : false;
  
  gulp.task("js", () =>
      gulp
          .src(["src/**/*.js"])
          .pipe(gulpIf(debug, plumber({errorHandler: notify.onError("Babel Error: <%= error.message %>")})))
          .pipe(gulpIf(!isProd, sourcemaps.init()))
          .pipe(
              babel({
                  presets: ["es2015", "stage-1"],
                  plugins: ['transform-runtime', 'transform-object-rest-spread'],
                  ignore: ["src/npm"]
              })
          )
          .pipe(gwcn({}))
          .pipe(gulpIf(isProd, uglify()))
          .pipe(gulpIf(!isProd, sourcemaps.write(".")))
          .pipe(gulp.dest("dist"))
  );
  
  gulp.task("wxml", () =>
      gulp
          .src(["src/**/*.{wxml,xml,html}"])
          .pipe(
              gulpIf(
                  debug,
                  plumber({
                      errorHandler: notify.onError('Wxml Check Error: <%= error.message %>')
                  })
              )
          )
          .pipe(
              gulpIf(
                  isProd,
                  htmlmin({
                      collapseWhitespace: true,
                      includeAutoGeneratedTags: false,
                      keepClosingSlash: true,
                      removeComments: true,
                      removeEmptyAttributes: true,
                      removeScriptTypeAttributes: true,
                      removeStyleLinkTypeAttributes: true
                  })
              )
          )
          .pipe(rename({ extname: ".wxml" }))
          .pipe(gulp.dest("dist"))
  );
  
  gulp.task("wxss", () =>
      gulp
          .src(["src/**/*.{wxss,css,scss}"])
          .pipe(sass().on("error", sass.logError))
          .pipe(gulpIf(isProd, cssnano()))
          .pipe(rename({ extname: ".wxss" }))
          .pipe(gulp.dest("dist"))
  );
  
  gulp.task("json", () =>
      gulp
          .src(["src/**/*.json"])
          .pipe(gulpIf(isProd, jsonminify()))
          .pipe(gulp.dest("dist"))
  );
  
  gulp.task("image", () =>
      gulp
          .src(["src/**/*.{jpg,jpeg,png,gif,svg}"])
          .pipe(gulpIf(isProd, imagemin()))
          .pipe(gulp.dest("dist"))
  );
  
  gulp.task("source", () =>
      gulp
          .src(["src/**/*.*", "!src/**/*.{js,wxml,xml,html,wxss,json,css,jpg,jpeg,png,gif,svg}"])
          .pipe(gulp.dest("dist"))
  );
  
  gulp.task("clean", () => del(["dist/*","!dist/project.config.json"]));
  
  gulp.task("build", () => runSequence("clean", ["js", "wxml", "wxss", "json", "image", "source"]));
  
  gulp.task("watch", ["build"], () => {
      gulp.watch("src/**/*.js", ["js"]);
      gulp.watch("src/**/*.{wxml,xml,html}", ["wxml"]);
      gulp.watch("src/**/*.{wxss,css}", ["wxss"]);
      gulp.watch("src/**/*.json", ["json"]);
      gulp.watch("src/**/*.{jpg,jpeg,png,gif,svg}", ["image"]);
      gulp.watch(
          ["src/**/*.*", "!src/**/*.{js,wxml,xml,html,wxss,json,css,jpg,jpeg,png,gif,svg}"],
          ["source"]
      );
  });
  
  gulp.task("default", ["watch"]);
  