@antora/site-publisher 3.0.0-beta.3 → 3.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/lib/index.js +2 -5
- package/package.json +8 -8
- package/lib/constants.js +0 -6
- package/lib/providers/archive.js +0 -17
- package/lib/providers/common/publish-stream.js +0 -26
- package/lib/providers/fs.js +0 -28
- package/lib/publish-site.js +0 -102
- package/lib/readable-output-file-array.js +0 -34
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# Antora Site Publisher
|
|
2
2
|
|
|
3
|
-
The Site Publisher is a component in Antora responsible for publishing (i.e., writing) the
|
|
4
|
-
|
|
3
|
+
The Site Publisher is a component in Antora responsible for publishing (i.e., writing) files in the virtual file catalog(s) to the destination(s) specified in the playbook.
|
|
4
|
+
This component supports different destination types (via providers) such as a filesystem directory or an archive file.
|
|
5
|
+
More than one destination may be specified.
|
|
5
6
|
Custom providers can be used to add support for additional destinations.
|
|
6
7
|
|
|
8
|
+
*This package is an alias for the `@antora/file-publisher` package.*
|
|
9
|
+
|
|
7
10
|
[Antora](https://antora.org) is a modular static site generator designed for creating documentation sites from AsciiDoc documents.
|
|
8
11
|
Its site generator aggregates documents from versioned content repositories and processes them using [Asciidoctor](https://asciidoctor.org).
|
|
9
12
|
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Publishes the files generated by the Antora generator to the destination(s)
|
|
7
|
-
* specified in the playbook.
|
|
4
|
+
* An alias for the @antora/file-publisher package.
|
|
8
5
|
*
|
|
9
6
|
* @namespace site-publisher
|
|
10
7
|
*/
|
|
11
|
-
module.exports = require('
|
|
8
|
+
module.exports = require('@antora/file-publisher')
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/site-publisher",
|
|
3
|
-
"version": "3.0.0-
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
4
|
+
"description": "An alias for the @antora/file-publisher package.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|
|
7
7
|
"contributors": [
|
|
@@ -14,12 +14,11 @@
|
|
|
14
14
|
"url": "https://gitlab.com/antora/antora/issues"
|
|
15
15
|
},
|
|
16
16
|
"main": "lib/index.js",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "_mocha"
|
|
19
|
+
},
|
|
17
20
|
"dependencies": {
|
|
18
|
-
"@antora/
|
|
19
|
-
"@antora/user-require-helper": "~2.0",
|
|
20
|
-
"gulp-vinyl-zip": "~2.5",
|
|
21
|
-
"vinyl": "~2.2",
|
|
22
|
-
"vinyl-fs": "~3.0"
|
|
21
|
+
"@antora/file-publisher": "3.0.0-rc.1"
|
|
23
22
|
},
|
|
24
23
|
"engines": {
|
|
25
24
|
"node": ">=12.21.0"
|
|
@@ -31,9 +30,10 @@
|
|
|
31
30
|
"antora",
|
|
32
31
|
"antora-component",
|
|
33
32
|
"publisher",
|
|
33
|
+
"files",
|
|
34
34
|
"documentation",
|
|
35
35
|
"static site",
|
|
36
36
|
"web publishing"
|
|
37
37
|
],
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "044371a33e2c0fed9724d30945bbb549d64845d5"
|
|
39
39
|
}
|
package/lib/constants.js
DELETED
package/lib/providers/archive.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const expandPath = require('@antora/expand-path-helper')
|
|
4
|
-
const publishStream = require('./common/publish-stream')
|
|
5
|
-
const { dest: vzipDest } = require('gulp-vinyl-zip')
|
|
6
|
-
|
|
7
|
-
const { DEFAULT_DEST_ARCHIVE } = require('../constants.js')
|
|
8
|
-
|
|
9
|
-
// FIXME right now we're assuming the archive is a zip
|
|
10
|
-
function publishToArchive (config, files, playbook) {
|
|
11
|
-
const destFile = config.path || DEFAULT_DEST_ARCHIVE
|
|
12
|
-
const absDestFile = expandPath(destFile, { dot: playbook.dir })
|
|
13
|
-
const report = { provider: 'archive', path: destFile, resolvedPath: absDestFile }
|
|
14
|
-
return publishStream(vzipDest(absDestFile), files).then(() => report)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = publishToArchive
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Pipes the stream of files to the specified Vinyl destination adapter.
|
|
5
|
-
*
|
|
6
|
-
* Pipes a stream of virtual files to the specified Vinyl destination adapter
|
|
7
|
-
* (a stream transform function) and returns a Promise that resolves when the
|
|
8
|
-
* stream ends.
|
|
9
|
-
*
|
|
10
|
-
* @memberof site-publisher
|
|
11
|
-
*
|
|
12
|
-
* @param {Function} destAdapter - A Vinyl destination adapter, preconfigured to
|
|
13
|
-
* write to a destination (e.g., `require('vinyl-fs').dest('path/to/dir')`).
|
|
14
|
-
* @param {Readable<File>} files - A Readable stream of virtual files to publish.
|
|
15
|
-
* @returns {Promise} A promise that resolves when the stream has ended.
|
|
16
|
-
*/
|
|
17
|
-
function publishStream (destAdapter, files) {
|
|
18
|
-
return new Promise((resolve, reject) =>
|
|
19
|
-
files
|
|
20
|
-
.pipe(destAdapter)
|
|
21
|
-
.on('error', reject)
|
|
22
|
-
.on('end', resolve)
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = publishStream
|
package/lib/providers/fs.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const expandPath = require('@antora/expand-path-helper')
|
|
4
|
-
const { promises: fsp } = require('fs')
|
|
5
|
-
const ospath = require('path')
|
|
6
|
-
const posixify = ospath.sep === '\\' ? (p) => p.replace(/\\/g, '/') : undefined
|
|
7
|
-
const publishStream = require('./common/publish-stream')
|
|
8
|
-
const { dest: vfsDest } = require('vinyl-fs')
|
|
9
|
-
|
|
10
|
-
const { DEFAULT_DEST_FS } = require('../constants.js')
|
|
11
|
-
|
|
12
|
-
function publishToFs (config, files, playbook) {
|
|
13
|
-
const destDir = config.path || DEFAULT_DEST_FS
|
|
14
|
-
const absDestDir = expandPath(destDir, { dot: playbook.dir })
|
|
15
|
-
const report = {
|
|
16
|
-
provider: 'fs',
|
|
17
|
-
path: destDir,
|
|
18
|
-
resolvedPath: absDestDir,
|
|
19
|
-
fileUri: 'file://' + (posixify ? '/' + posixify(absDestDir) : absDestDir),
|
|
20
|
-
}
|
|
21
|
-
return config.clean
|
|
22
|
-
? fsp['rm' in fsp ? 'rm' : 'rmdir'](absDestDir, { recursive: true, force: true })
|
|
23
|
-
.then(() => publishStream(vfsDest(absDestDir), files))
|
|
24
|
-
.then(() => report)
|
|
25
|
-
: publishStream(vfsDest(absDestDir), files).then(() => report)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = publishToFs
|
package/lib/publish-site.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const ReadableOutputFileArray = require('./readable-output-file-array')
|
|
4
|
-
const userRequire = require('@antora/user-require-helper')
|
|
5
|
-
|
|
6
|
-
const { DEFAULT_DEST_FS } = require('./constants.js')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Publishes all publishable files in the specified catalogs using the
|
|
10
|
-
* destination providers specified in the playbook.
|
|
11
|
-
*
|
|
12
|
-
* This function starts by retrieving all publishable files from the specified
|
|
13
|
-
* collection of catalogs (currently those files with an out property). It then
|
|
14
|
-
* resolves the publish function for each destination provider specified in the
|
|
15
|
-
* playbook (i.e., `output.destinations`). If the provider is not known, the
|
|
16
|
-
* publish function for that provider is resolved by requiring a module (or
|
|
17
|
-
* relative path) having the same name as the provider. Once the publish
|
|
18
|
-
* function is resolved, the configuration specified in the playbook for that
|
|
19
|
-
* provider is bound to the function as its first argument. This function then
|
|
20
|
-
* iterates over all publish providers and passes a Readable of the publishable
|
|
21
|
-
* files as the second argument and the playbook as the third. The path of each
|
|
22
|
-
* file has been updated to match the `out.path` value (currently by
|
|
23
|
-
* instantiating a copy of the file).
|
|
24
|
-
*
|
|
25
|
-
* If a directory is specified directly on the output property of the playbook
|
|
26
|
-
* (i.e., `output.dir`), that directory is used to create or override the first
|
|
27
|
-
* fs provider in the list of destinations. If the clean property is set directly
|
|
28
|
-
* on the output property of the playbook (i.e., `output.clean`), the clean
|
|
29
|
-
* property is added to the configuration for each provider.
|
|
30
|
-
*
|
|
31
|
-
* @memberof site-publisher
|
|
32
|
-
*
|
|
33
|
-
* @param {Object} playbook - The configuration object for Antora that provides
|
|
34
|
-
* access to the output destinations.
|
|
35
|
-
* @param {Array<Catalog>} catalogs - The collection of catalogs from which to retrieve the
|
|
36
|
-
* publishable virtual files.
|
|
37
|
-
* @returns Nothing.
|
|
38
|
-
*/
|
|
39
|
-
// QUESTION should this function return a report of virtual files that were published (by provider)
|
|
40
|
-
async function publishSite (playbook, catalogs) {
|
|
41
|
-
const output = playbook.output
|
|
42
|
-
const destinations = getDestinations(output)
|
|
43
|
-
|
|
44
|
-
if (!destinations.length) return []
|
|
45
|
-
|
|
46
|
-
const clean = output.clean
|
|
47
|
-
const publishers = destinations.map((destination) => {
|
|
48
|
-
const { provider, options } = resolveDestination(destination, clean)
|
|
49
|
-
switch (provider) {
|
|
50
|
-
case 'archive':
|
|
51
|
-
case 'fs':
|
|
52
|
-
return require('./providers/' + provider).bind(null, options)
|
|
53
|
-
default:
|
|
54
|
-
try {
|
|
55
|
-
const userRequireContext = { dot: playbook.dir, paths: [playbook.dir || '', __dirname] }
|
|
56
|
-
return userRequire(provider, userRequireContext).bind(null, options)
|
|
57
|
-
} catch (err) {
|
|
58
|
-
const prettyErr = new Error('Unsupported destination provider: ' + provider)
|
|
59
|
-
prettyErr.stack += `\nCaused by: ${err.stack || err}`
|
|
60
|
-
throw prettyErr
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
// Q: add getPublishableFiles / getOutFiles; return a stream? or getOutFilesAsStream?
|
|
66
|
-
const filesToPublish = catalogs.reduce((accum, catalog) => {
|
|
67
|
-
// remove fallback check for getFiles on site catalog in Antora 4
|
|
68
|
-
accum.push(...(catalog.getFiles || catalog.getAll).apply(catalog).filter((file) => file.out))
|
|
69
|
-
return accum
|
|
70
|
-
}, [])
|
|
71
|
-
|
|
72
|
-
return Promise.all(publishers.map((publish) => publish(new ReadableOutputFileArray(filesToPublish), playbook)))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getDestinations (output) {
|
|
76
|
-
let destinations = output.destinations
|
|
77
|
-
if (output.dir) {
|
|
78
|
-
if (destinations && destinations.length) {
|
|
79
|
-
destinations = destinations.slice()
|
|
80
|
-
const primaryFsDestIdx = destinations.findIndex(({ provider: candidate }) => candidate === 'fs')
|
|
81
|
-
if (~primaryFsDestIdx) {
|
|
82
|
-
;(destinations[primaryFsDestIdx] = Object.assign({}, destinations[primaryFsDestIdx])).path = output.dir
|
|
83
|
-
} else {
|
|
84
|
-
destinations.unshift({ provider: 'fs', path: output.dir })
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
destinations = [{ provider: 'fs', path: output.dir }]
|
|
88
|
-
}
|
|
89
|
-
} else if (!destinations) {
|
|
90
|
-
destinations = [{ provider: 'fs', path: DEFAULT_DEST_FS }]
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return destinations
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function resolveDestination (destination, clean) {
|
|
97
|
-
const { provider, ...options } = destination
|
|
98
|
-
if (clean) options.clean = true
|
|
99
|
-
return { provider, options }
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = publishSite
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Readable } = require('stream')
|
|
4
|
-
const Vinyl = require('vinyl')
|
|
5
|
-
|
|
6
|
-
class File extends Vinyl {
|
|
7
|
-
get relative () {
|
|
8
|
-
return this.path
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class ReadableOutputFileArray extends Readable {
|
|
13
|
-
constructor (array) {
|
|
14
|
-
super({ objectMode: true })
|
|
15
|
-
this._array = array.slice().reverse()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
_read (size) {
|
|
19
|
-
const array = this._array
|
|
20
|
-
while (size--) {
|
|
21
|
-
const next = array.pop()
|
|
22
|
-
if (next === undefined) break
|
|
23
|
-
this.push(toOutputFile(next))
|
|
24
|
-
}
|
|
25
|
-
if (size > -1) this.push(null)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function toOutputFile (file) {
|
|
30
|
-
// Q: do we also need to clone contents and stat?
|
|
31
|
-
return new File({ contents: file.contents, path: file.out.path, stat: file.stat })
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = ReadableOutputFileArray
|