All files / gulpfile.ts index.ts

0% Statements 0/71
0% Branches 0/69
100% Functions 0/0
0% Lines 0/69

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164                                                                                                                                                                                                                                                                                                                                       
/**
 * gulpfile
 */
 
import * as RBrowserSync from 'browser-sync'
import * as gulp from 'gulp'
import {
  browserSync as createBrowserSync,
  checkAndLabel,
  clean as createClean,
  fonts as createFonts,
  html as createHtml,
  images as createImages,
  init as createInit,
  initConfig as createInitConfig,
  ITimplaHelper,
  open as createOpen,
  openAnalyzer as createOpenAnalyzer,
  projectDestPath,
  projectSrcPath,
  rev as createRev,
  sizeReport as createSizeReport,
  staticFiles as createStaticFiles,
  stylesheets as createStylesheets,
  svg as createSvg,
  TIMPLA_CONFIG as TC,
  TIMPLA_PROCESS as TP,
  watch as createWatch,
  webpackProduction as createWebpackProduction,
} from './internal'
 
// Create gulp tasks using the timpla config
const browserSync = createBrowserSync(TC)
const clean = createClean(TC)
const open = createOpen(TC)
const openAnalyzer = createOpenAnalyzer(TC)
const javascripts = createWebpackProduction(TC)
const rev = createRev(TC)
const sizeReport = createSizeReport(TC)
const init = createInit()
const initJS = createInit(false)
const initConfig = createInitConfig(TC)
 
// Grab alternative tasks
const alternateHtmlTask = TC.html && TC.html.alternate
const alternateSvgTask = TC.svg && TC.svg.alternate
const alternateStylesheetsTask = TC.stylesheets && TC.stylesheets.alternate
const alternateImagesTask = TC.images && TC.images.alternate
const alternateFontsTask = TC.fonts && TC.fonts.alternate
const alternateStaticFilesTask = TC.staticFiles && TC.staticFiles.alternate
 
// Create alternateable tasks
const timplaHelper: ITimplaHelper = {
  browserSync: RBrowserSync,
  gulp,
  projectDestPath,
  projectSrcPath,
  timplaConfig: TC,
  timplaProcess: TP,
}
 
const createExtraTasks = TC.additionalTasks && TC.additionalTasks.initialize
if (createExtraTasks) {
  createExtraTasks(timplaHelper)
}
const fonts = alternateFontsTask ? alternateFontsTask(timplaHelper) : createFonts(TC)
const images = alternateImagesTask ? alternateImagesTask(timplaHelper) : createImages(TC)
const staticFiles = alternateStaticFilesTask
  ? alternateStaticFilesTask(timplaHelper)
  : createStaticFiles(TC)
const html = alternateHtmlTask ? alternateHtmlTask(timplaHelper) : createHtml(TC)
const svg = alternateSvgTask ? alternateSvgTask(timplaHelper) : createSvg(TC)
const stylesheets = alternateStylesheetsTask
  ? alternateStylesheetsTask(timplaHelper)
  : createStylesheets(TC)
 
// Init development watch
// We're passing the created functions to keep the gulp task references
const watch = createWatch(TC, {
  fonts,
  html,
  images,
  staticFiles,
  stylesheets,
  svg,
})
 
checkAndLabel(browserSync, 'browserSync')
checkAndLabel(fonts, 'fonts')
checkAndLabel(clean, 'clean')
checkAndLabel(open, 'open')
checkAndLabel(javascripts, 'javascripts')
checkAndLabel(rev, 'rev')
checkAndLabel(sizeReport, 'sizeReport')
checkAndLabel(images, 'images')
checkAndLabel(staticFiles, 'staticFiles')
checkAndLabel(html, 'html')
checkAndLabel(svg, 'svg')
checkAndLabel(stylesheets, 'stylesheets')
checkAndLabel(watch, 'watch')
 
// Common tasks are used by both prod and dev runs
const commonTasks = [
  TC.fonts && fonts,
  TC.html && html,
  TC.images && images,
  TC.svg && svg,
  TC.stylesheets && stylesheets,
  TC.staticFiles && staticFiles,
].filter(Boolean) as []
 
const parallelCommon = commonTasks.length && gulp.parallel(...commonTasks)
 
const currentEnv = TP.isProduction ? 'production' : 'development'
const { prebuild: prebuildT = false, postbuild: postbuildT = false } =
  (TC.additionalTasks && TC.additionalTasks[currentEnv]) || {}
const prebuild = prebuildT && prebuildT(timplaHelper)
const postbuild = postbuildT && postbuildT(timplaHelper)
const isOpenEnabled = !TP.isTimplaReloaded && TC[currentEnv] && TC[currentEnv].open
const isCleanEnabled = !!TC.clean
 
const devSeries = [
  prebuild,
  isCleanEnabled && clean,
  parallelCommon,
  postbuild,
  browserSync,
  watch,
  isOpenEnabled && open,
].filter(Boolean) as []
 
const prodSeries = [
  prebuild,
  isCleanEnabled && clean,
  parallelCommon,
  TC.javascripts && javascripts,
  TC.production && TC.production.rev && rev,
  sizeReport,
  postbuild,
  isOpenEnabled && open,
].filter(Boolean) as []
 
const development = gulp.series(...devSeries)
const build = gulp.series(...prodSeries)
 
export {
  build,
  fonts,
  clean,
  javascripts,
  rev,
  init,
  initJS,
  initConfig,
  sizeReport,
  images,
  staticFiles,
  html,
  svg,
  stylesheets,
  openAnalyzer,
}
export default development