Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 36 additions & 38 deletions gulp.d/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const autoprefixer = require('autoprefixer')
const browserify = require('browserify')
const buffer = require('vinyl-buffer')
const concat = require('gulp-concat')
const cssnano = require('cssnano')
const fs = require('fs')
Expand Down Expand Up @@ -44,10 +43,7 @@ module.exports = (src, dest, preview) => () => {
const abspath = require.resolve(relpath)
const basename = ospath.basename(abspath)
const destpath = ospath.join(dest, 'font', basename)
if (!fs.existsSync(destpath)) {
fs.mkdirSync(ospath.join(dest, 'font'), { recursive: true })
fs.copyFileSync(abspath, destpath)
}
if (!fs.existsSync(destpath)) fs.cpSync(abspath, destpath, { recursive: true })
return path.join('..', 'font', basename)
},
},
Expand All @@ -66,43 +62,19 @@ module.exports = (src, dest, preview) => () => {

return merge(
vfs
.src('js/+([0-9])-*.js', { ...opts, sourcemaps })
.pipe(uglify())
.src('js/+([0-9])-*.js', { ...opts, read: false, sourcemaps })
.pipe(bundle(opts))
.pipe(uglify({ output: { comments: /^! / } }))
// NOTE concat already uses stat from newest combined file
.pipe(concat('js/site.js')),
vfs
.src('js/vendor/*.js', { ...opts, read: false })
.pipe(
// see https://gulpjs.org/recipes/browserify-multiple-destination.html
map((file, enc, next) => {
if (file.relative.endsWith('.bundle.js')) {
const mtimePromises = []
const bundlePath = file.path
browserify(file.relative, { basedir: src, detectGlobals: false })
.plugin('browser-pack-flat/plugin')
.on('file', (bundledPath) => {
if (bundledPath !== bundlePath) mtimePromises.push(fsp.stat(bundledPath).then(({ mtime }) => mtime))
})
.bundle((bundleError, bundleBuffer) =>
Promise.all(mtimePromises).then((mtimes) => {
const newestMtime = mtimes.reduce((max, curr) => (curr > max ? curr : max), file.stat.mtime)
if (newestMtime > file.stat.mtime) file.stat.mtimeMs = +(file.stat.mtime = newestMtime)
if (bundleBuffer !== undefined) file.contents = bundleBuffer
file.path = file.path.slice(0, file.path.length - 10) + '.js'
next(bundleError, file)
})
)
} else {
fsp.readFile(file.path, 'UTF-8').then((contents) => {
file.contents = Buffer.from(contents)
next(null, file)
})
}
})
)
.pipe(buffer())
.src('js/vendor/*([^.])?(.bundle).js', { ...opts, read: false })
.pipe(bundle(opts))
.pipe(uglify({ output: { comments: /^! / } })),
// NOTE use this statement to bundle a JavaScript library that cannot be browserified, like jQuery
vfs
.src('js/vendor/*.min.js', opts)
.pipe(map((file, enc, next) => next(null, Object.assign(file, { extname: '' }, { extname: '.js' })))),
// NOTE use the next line to bundle a JavaScript library that cannot be browserified, like jQuery
//vfs.src(require.resolve('<package-name-or-require-path>'), opts).pipe(concat('js/vendor/<library-name>.js')),
vfs
.src(['css/site.css', 'css/vendor/*.css'], { ...opts, sourcemaps })
Expand Down Expand Up @@ -132,6 +104,32 @@ module.exports = (src, dest, preview) => () => {
).pipe(vfs.dest(dest, { sourcemaps: sourcemaps && '.' }))
}

function bundle ({ base: basedir, ext: bundleExt = '.bundle.js' }) {
return map((file, enc, next) => {
if (bundleExt && file.relative.endsWith(bundleExt)) {
const mtimePromises = []
const bundlePath = file.path
browserify(file.relative, { basedir, detectGlobals: false })
.plugin('browser-pack-flat/plugin')
.on('file', (bundledPath) => {
if (bundledPath !== bundlePath) mtimePromises.push(fsp.stat(bundledPath).then(({ mtime }) => mtime))
})
.bundle((bundleError, bundleBuffer) =>
Promise.all(mtimePromises).then((mtimes) => {
const newestMtime = mtimes.reduce((max, curr) => (curr > max ? curr : max), file.stat.mtime)
if (newestMtime > file.stat.mtime) file.stat.mtimeMs = +(file.stat.mtime = newestMtime)
if (bundleBuffer !== undefined) file.contents = bundleBuffer
next(bundleError, Object.assign(file, { path: file.path.slice(0, file.path.length - 10) + '.js' }))
})
)
return
}
fsp.readFile(file.path, 'UTF-8').then((contents) => {
next(null, Object.assign(file, { contents: Buffer.from(contents) }))
})
})
}

function postcssPseudoElementFixer (css, result) {
css.walkRules(/(?:^|[^:]):(?:before|after)/, (rule) => {
rule.selector = rule.selectors.map((it) => it.replace(/(^|[^:]):(before|after)$/, '$1::$2')).join(',')
Expand Down
62 changes: 26 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@asciidoctor/tabs": "1.0.0-alpha.8",
"@fontsource/roboto": "~4.5",
"@fontsource/roboto-mono": "~4.5",
"@springio/asciidoctor-extensions": "1.0.0-alpha.4",
"autoprefixer": "~10.4",
"browser-pack-flat": "~3.5",
"browserify": "~17.0",
Expand Down Expand Up @@ -57,7 +58,6 @@
"require-from-string": "~2.0",
"stylelint": "~13.13",
"stylelint-config-standard": "~22.0",
"vinyl-buffer": "~1.0",
"vinyl-fs": "~3.0"
}
}
89 changes: 88 additions & 1 deletion preview-src/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Author Name
:!example-caption:
:!table-caption:
:page-pagination:
:chomp-package-replacement: com.acme
:tabs-sync-option:

image:multirepo-ssg.svg[Multirepo SSG,200,float=right]
Expand Down Expand Up @@ -51,6 +52,93 @@ This is an example paragraph.
[example]
This is an example paragraph.

=== Code Folding

Fold with no replacement text.

[,java]
----
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
// @fold:on
// @formatter:off
SpringApplication.run(MyApplication.class, args);
// @formatter:on
// @fold:off
}
}
----

Same fold with replacement text.

[,java]
----
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
// @fold:on // reveal logic...
// @formatter:off
SpringApplication.run(MyApplication.class, args);
// @formatter:on
// @fold:off
}
}
----

Another example of folds.

[,java,chomp=all]
----
package org.example;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("my.service")
public class MyProperties {
// @fold:on // fields...
private boolean enabled;

private InetAddress remoteAddress;

private final Security security = /* @chomp:line // instantiate your instance of the Security class... */ new Security();
// @fold:off

// @fold:on // getters / setters...
public boolean isEnabled() {
return this.enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public InetAddress getRemoteAddress() {
return this.remoteAddress;
}

public void setRemoteAddress(InetAddress remoteAddress) {
this.remoteAddress = remoteAddress;
}

public Security getSecurity() {
return this.security;
}
// @fold:off
}
----

=== Tabs

You can have code in different tabs:
Expand Down Expand Up @@ -349,4 +437,3 @@ ____
== Fin

That's all, folks!

1 change: 1 addition & 0 deletions preview-src/ui-model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ asciidoc:
extensions:
# TIP uncomment the next line to switch to Asciidoctor Tabs
#- '@asciidoctor/tabs'
- '@springio/asciidoctor-extensions'
site:
url: http://localhost:5252
title: Spring
Expand Down
Loading