summaryrefslogtreecommitdiffstats
path: root/gulpfile.js/index.js
blob: 11f64ac7418a0726618195f7c91d5cd870957b00 (plain)
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
'use strict'

const { parallel, series, tree, watch } = require('gulp')
const task = require('./lib/task')

const bundleName = 'ui'
const buildDir = 'build'
const previewSrcDir = 'preview-src'
const previewDestDir = 'public'
const srcDir = 'src'
const destDir = `${previewDestDir}/_`
const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {}

const { remove, lintCss, lintJs, format, build, pack, previewPages, serve } = require('./tasks')
const glob = {
  all: [srcDir, previewSrcDir],
  css: `${srcDir}/css/**/*.css`,
  js: ['gulpfile.js/**/*.js', `${srcDir}/{helpers,js}/**/*.js`],
}

const cleanTask = task({
  name: 'clean',
  desc: 'Clean files and folders generated by build',
  call: remove(['build', 'public']),
})

const lintCssTask = task({
  name: 'lint:css',
  desc: 'Lint the CSS source files using stylelint (standard config)',
  call: lintCss(glob.css),
})

const lintJsTask = task({
  name: 'lint:js',
  desc: 'Lint the JavaScript source files using eslint (JavaScript Standard Style)',
  call: lintJs(glob.js),
})

const lintTask = task({
  name: 'lint',
  desc: 'Lint the CSS and JavaScript source files',
  call: parallel(lintCssTask, lintJsTask),
})

const formatTask = task({
  name: 'format',
  desc: 'Format the JavaScript source files using prettify (JavaScript Standard Style)',
  call: format(glob.js),
})

const buildTask = task({
  name: 'build',
  desc: 'Build and stage the UI assets for bundling',
  call: build(srcDir, destDir, tree().nodes.some((name) => ~name.indexOf('preview'))),
})

const bundleBuildTask = task({
  name: 'bundle:build',
  call: series(cleanTask, lintTask, buildTask),
})

const bundlePackTask = task({
  name: 'bundle:pack',
  desc: 'Create a bundle of the staged UI assets for publishing',
  call: pack(destDir, buildDir, bundleName),
})

const bundleTask = task({
  name: 'bundle',
  desc: 'Clean, lint, build, and bundle the UI for publishing',
  call: series(bundleBuildTask, bundlePackTask),
})

const previewPagesTask = task({
  name: 'preview:pages',
  call: previewPages(srcDir, destDir, previewSrcDir, previewDestDir, livereload),
})

const previewBuildTask = task({
  name: 'preview:build',
  desc: 'Process and stage the UI assets and generate pages for the preview',
  call: parallel(buildTask, previewPagesTask),
})

const previewServeTask = task({
  name: 'preview:serve',
  call: serve(previewDestDir, { port: 5252, livereload }, () => watch(glob.all, previewBuildTask)),
})

const previewTask = task({
  name: 'preview',
  desc: 'Generate a preview site and launch a server to view it',
  call: series(previewBuildTask, previewServeTask),
})

module.exports = require('./lib/export-tasks')(
  bundleTask,
  cleanTask,
  lintTask,
  formatTask,
  buildTask,
  bundleTask,
  bundlePackTask,
  previewTask,
  previewBuildTask
)