<commit_before>import gulp from 'gulp'
import gulpLoadPlugins from 'gulp-load-plugins'
import Util from './build/util/util'
import browserSync from 'browser-sync'

const $ = gulpLoadPlugins({
  lazy: true,
  pattern: ['gulp-*', 'gulp.*', '@*/gulp{-,.}*', 'cssnano', 'autoprefixer', 'delete']
})
const themeDir = Util.themeDir()
const outputDir = Util.outputDir()
const DS = Util.ds();
const reload = browserSync.reload

gulp.task('default', ['clean'], () => {
  if (!Util.isThemeDir()) return
  gulp.start('build')
})

gulp.task('build', (cb) => {
  $.sequence('fonts', 'php', 'cacheClean', 'phtml', 'images', 'styles', 'mergeConfig', 'scripts')(cb)
})

gulp.task('init', () => {
  Util.initDir()
})

gulp.task('babel', () => {
  let fLib = $.filter((file) => {
    return !/lib/ig.test(file.path)
  }, {restore: true})
  return gulp.src([`${themeDir}**/*.js`, `!${themeDir}*/require-config.js`])
    .pipe($.plumber())
    .pipe(fLib)
    .pipe($.babel())
    .pipe($.eslint({
      fix: true,
      envs: [
        'browser'
      ]
    }))
    .pipe($.eslint.format())
    .pipe(fLib.restore)
    .pipe(gulp.dest(`${themeDir}.tmp`))
})

gulp.task('scriptsDep', () => {
  if (Util.excludeShallow().length > 0 || Util.includeJsLib() > 0) {
    let fLibRegExp = new RegExp(`${[...Util.excludeShallow(), ...Util.includeJsLib()].join('|')}`, 'ig')
    let fLib = $.filter((file) => {
      return Boolean(file.path.match(fLibRegExp))
    })
    return gulp.src(`${themeDir}.tmp/**/lib/*.js`)
      .pipe($.plumber())
      .pipe(fLib)
      .pipe($.rename((path) => {
        path.dirname = ''
      }))
      .pipe(gulp.dest(`${outputDir}web`))
  }
})

gulp.task('buildScripts', () => {
  return gulp.src(`${themeDir}.tmp/**/modules/*.js`)
    .pipe($.plumber())
    .pipe($.if(!Util.mode(), $.sourcemaps.init()))
    .pipe($.requirejsOptimize((file) => {
      return {
        'baseUrl': `${themeDir}.tmp`,
        'optimize': `${Util.isUglify()}`,<commit_msg>优化处理js依赖时寻找多级目录<commit_after>import gulp from 'gulp'
import gulpLoadPlugins from 'gulp-load-plugins'
import Util from './build/util/util'
import browserSync from 'browser-sync'

const $ = gulpLoadPlugins({
  lazy: true,
  pattern: ['gulp-*', 'gulp.*', '@*/gulp{-,.}*', 'cssnano', 'autoprefixer', 'delete']
})
const themeDir = Util.themeDir()
const outputDir = Util.outputDir()
const DS = Util.ds();
const reload = browserSync.reload

gulp.task('default', ['clean'], () => {
  if (!Util.isThemeDir()) return
  gulp.start('build')
})

gulp.task('build', (cb) => {
  $.sequence('fonts', 'php', 'cacheClean', 'phtml', 'images', 'styles', 'mergeConfig', 'scripts')(cb)
})

gulp.task('init', () => {
  Util.initDir()
})

gulp.task('babel', () => {
  let fLib = $.filter((file) => {
    return !/lib/ig.test(file.path)
  }, {restore: true})
  return gulp.src([`${themeDir}**/*.js`, `!${themeDir}*/require-config.js`])
    .pipe($.plumber())
    .pipe(fLib)
    .pipe($.babel())
    .pipe($.eslint({
      fix: true,
      envs: [
        'browser'
      ]
    }))
    .pipe($.eslint.format())
    .pipe(fLib.restore)
    .pipe(gulp.dest(`${themeDir}.tmp`))
})

gulp.task('scriptsDep', () => {
  if (Util.excludeShallow().length > 0 || Util.includeJsLib() > 0) {
    let fLibRegExp = new RegExp(`${[...Util.excludeShallow(), ...Util.includeJsLib()].join('|')}`, 'ig')
    let fLib = $.filter((file) => {
      return Boolean(file.path.match(fLibRegExp))
    })
    return gulp.src(`${themeDir}.tmp/**/lib/**/*.js`)
      .pipe($.plumber())
      .pipe(fLib)
      .pipe($.rename((path) => {
        path.dirname = ''
      }))
      .pipe(gulp.dest(`${outputDir}web`))
  }
})

gulp.task('buildScripts', () => {
  return gulp.src(`${themeDir}.tmp/**/modules/*.js`)
    .pipe($.plumber())
    .pipe($.if(!Util.mode(), $.sourcemaps.init()))
    .pipe($.requirejsOptimize((file) => {
      return {
        'baseUrl': `${themeDir}.tmp`,
        'optimize': `${Util.isUglify()}`,
{'fraction_non_alphanumeric': 0.24929971988795518, 'fraction_numerical': 0.0010185892538833714, 'mean_word_length': 3.3259911894273126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1729231', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1484, 'n_words': 229}