-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- upgrade to Gulp 4 - refactor tasks to use Gulp 4 task system - switch from map-stream to through2.obj - switch from fs to fs-extra - fix Gulp prettier+eslint integration - rename tasks
- Loading branch information
1 parent
336b32a
commit 260cc89
Showing
17 changed files
with
1,369 additions
and
1,556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"description": "Build tasks for the Antora default UI project", | ||
"flags.tasksDepth": 0 | ||
"flags.tasksDepth": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8 | ||
10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,114 @@ | ||
'use strict' | ||
|
||
const connect = require('gulp-connect') | ||
const { parallel, series, tree } = require('gulp') | ||
const camelcase = (name) => name.replace(/[-]./g, (m) => m.substr(1).toUpperCase()) | ||
const exportTasks = require('./tasks/lib/export-tasks') | ||
const task = require('./tasks/lib/task') | ||
const taskFns = require('require-directory')(module, './tasks', { recurse: false, rename: camelcase }) | ||
const path = require('path') | ||
const gulp = require('gulp') | ||
|
||
const build = require('./tasks/build') | ||
const buildPreview = require('./tasks/build-preview') | ||
const format = require('./tasks/format') | ||
const lintCss = require('./tasks/lint-css') | ||
const lintJs = require('./tasks/lint-js') | ||
const pack = require('./tasks/pack') | ||
const preview = require('./tasks/preview') | ||
|
||
const bundleName = 'ui' | ||
const buildDir = 'build' | ||
const previewSiteSrcDir = 'preview-site-src' | ||
const previewSiteDestDir = 'public' | ||
const srcDir = 'src' | ||
const destDir = path.join(previewSiteDestDir, '_') | ||
const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {} | ||
|
||
const jsFiles = ['gulpfile.js', 'tasks/**/*.js', path.join(srcDir, '{helpers,js}/**/*.js')] | ||
const cssFileGlobs = path.join(srcDir, 'css/**/*.css') | ||
const jsFileGlobs = ['gulpfile.js', 'tasks/**/*.js', path.join(srcDir, '{helpers,js}/**/*.js')] | ||
|
||
gulp.task('lint:css', () => lintCss(`${srcDir}/css/**/*.css`)) | ||
gulp.task('lint:js', () => lintJs(jsFiles)) | ||
gulp.task('lint', ['lint:css', 'lint:js']) | ||
const { remove, lintCss, lintJs, format, build, pack, previewPages, previewServe } = taskFns | ||
|
||
gulp.task('format', () => format(jsFiles)) | ||
const cleanTask = task({ | ||
name: 'clean', | ||
desc: 'Clean files and folders generated by build', | ||
then: remove(['build', 'public']), | ||
}) | ||
|
||
gulp.task('build', function () { | ||
return build(srcDir, destDir, this.seq.slice(0).some((name) => ~name.indexOf('preview'))) | ||
const lintCssTask = task({ | ||
name: 'lint:css', | ||
desc: 'Lint the CSS source files using stylelint (standard config)', | ||
then: lintCss(cssFileGlobs), | ||
}) | ||
|
||
gulp.task('build:preview', ['build'], () => | ||
buildPreview(srcDir, destDir, previewSiteSrcDir, previewSiteDestDir, connect.reload) | ||
) | ||
const lintJsTask = task({ | ||
name: 'lint:js', | ||
desc: 'Lint the JavaScript source files using eslint (JavaScript Standard Style)', | ||
then: lintJs(jsFileGlobs), | ||
}) | ||
|
||
const lintTask = task({ | ||
name: 'lint', | ||
desc: 'Lint the CSS and JavaScript source files', | ||
then: parallel(lintCssTask, lintJsTask), | ||
}) | ||
|
||
const formatTask = task({ | ||
name: 'format', | ||
desc: 'Format the JavaScript source files using prettify (JavaScript Standard Style)', | ||
then: format(jsFileGlobs), | ||
}) | ||
|
||
const buildTask = task({ | ||
name: 'build', | ||
desc: 'Build and stage the UI assets for bundling', | ||
then: build(srcDir, destDir, tree().nodes.some((name) => ~name.indexOf('preview'))), | ||
}) | ||
|
||
const bundleBuildTask = task({ | ||
name: 'bundle:build', | ||
desc: 'Lint the source files and build and stage the UI assets for bundling', | ||
then: series(cleanTask, lintTask, buildTask), | ||
}) | ||
|
||
gulp.task('preview', ['build:preview'], () => | ||
preview(previewSiteDestDir, { | ||
const bundlePackTask = task({ | ||
name: 'bundle:pack', | ||
desc: 'Create a bundle of the staged UI assets for publishing', | ||
then: pack(destDir, buildDir, bundleName), | ||
}) | ||
|
||
const bundleTask = task({ | ||
name: 'bundle', | ||
desc: 'Clean, lint, build, and bundle the UI for publishing', | ||
then: series(bundleBuildTask, bundlePackTask), | ||
}) | ||
|
||
const previewPagesTask = task({ | ||
name: 'preview:pages', | ||
desc: 'Generate pages for the preview by applying the specified layout template', | ||
then: previewPages(srcDir, destDir, previewSiteSrcDir, previewSiteDestDir, livereload), | ||
}) | ||
|
||
const previewBuildTask = task({ | ||
name: 'preview:build', | ||
desc: 'Process and stage the UI assets and generate pages for the preview', | ||
then: parallel(buildTask, previewPagesTask), | ||
}) | ||
|
||
const previewServeTask = task({ | ||
name: 'preview:serve', | ||
desc: 'Launch server to preview UI', | ||
then: previewServe(previewSiteDestDir, { | ||
port: 5252, | ||
livereload: process.env.LIVERELOAD === 'true', | ||
watch: { | ||
src: [srcDir, previewSiteSrcDir], | ||
onChange: () => gulp.start('build:preview'), | ||
}, | ||
}) | ||
) | ||
livereload, | ||
watch: { src: [srcDir, previewSiteSrcDir], onChange: previewBuildTask }, | ||
}), | ||
}) | ||
|
||
gulp.task('pack', ['build', 'lint'], () => pack(destDir, buildDir, bundleName)) | ||
const previewTask = task({ | ||
name: 'preview', | ||
desc: 'Generate a preview site and launch a server to view it', | ||
then: series(previewBuildTask, previewServeTask), | ||
}) | ||
|
||
gulp.task('default', ['build']) | ||
module.exports = exportTasks( | ||
task({ name: 'default', desc: `(${bundleTask.displayName})`, then: series(bundleTask) }), | ||
cleanTask, | ||
lintTask, | ||
formatTask, | ||
buildTask, | ||
bundleTask, | ||
previewTask, | ||
previewBuildTask | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.