@antora/site-publisher 3.0.0-alpha.6 → 3.0.0-beta.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 +1 -1
- package/lib/index.js +2 -2
- package/lib/providers/archive.js +1 -1
- package/lib/providers/fs.js +2 -32
- package/lib/publish-site.js +8 -5
- package/lib/readable-output-file-array.js +8 -4
- package/package.json +6 -5
- package/lib/require-provider.js +0 -51
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ More than one destination may be specified, and this component supports differen
|
|
|
5
5
|
Custom providers can be used to add support for additional destinations.
|
|
6
6
|
|
|
7
7
|
[Antora](https://antora.org) is a modular static site generator designed for creating documentation sites from AsciiDoc documents.
|
|
8
|
-
Its site generator
|
|
8
|
+
Its site generator aggregates documents from versioned content repositories and processes them using [Asciidoctor](https://asciidoctor.org).
|
|
9
9
|
|
|
10
10
|
## Copyright and License
|
|
11
11
|
|
package/lib/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Site Publisher component for Antora
|
|
5
5
|
*
|
|
6
|
-
* Publishes the files generated
|
|
7
|
-
*
|
|
6
|
+
* Publishes the files generated by the Antora generator to the destination(s)
|
|
7
|
+
* specified in the playbook.
|
|
8
8
|
*
|
|
9
9
|
* @namespace site-publisher
|
|
10
10
|
*/
|
package/lib/providers/archive.js
CHANGED
|
@@ -9,7 +9,7 @@ const { DEFAULT_DEST_ARCHIVE } = require('../constants.js')
|
|
|
9
9
|
// FIXME right now we're assuming the archive is a zip
|
|
10
10
|
function publishToArchive (config, files, playbook) {
|
|
11
11
|
const destFile = config.path || DEFAULT_DEST_ARCHIVE
|
|
12
|
-
const absDestFile = expandPath(destFile,
|
|
12
|
+
const absDestFile = expandPath(destFile, { dot: playbook.dir })
|
|
13
13
|
const report = { provider: 'archive', path: destFile, resolvedPath: absDestFile }
|
|
14
14
|
return publishStream(vzipDest(absDestFile), files).then(() => report)
|
|
15
15
|
}
|
package/lib/providers/fs.js
CHANGED
|
@@ -11,7 +11,7 @@ const { DEFAULT_DEST_FS } = require('../constants.js')
|
|
|
11
11
|
|
|
12
12
|
function publishToFs (config, files, playbook) {
|
|
13
13
|
const destDir = config.path || DEFAULT_DEST_FS
|
|
14
|
-
const absDestDir = expandPath(destDir,
|
|
14
|
+
const absDestDir = expandPath(destDir, { dot: playbook.dir })
|
|
15
15
|
const report = {
|
|
16
16
|
provider: 'fs',
|
|
17
17
|
path: destDir,
|
|
@@ -19,40 +19,10 @@ function publishToFs (config, files, playbook) {
|
|
|
19
19
|
fileUri: 'file://' + (posixify ? '/' + posixify(absDestDir) : absDestDir),
|
|
20
20
|
}
|
|
21
21
|
return config.clean
|
|
22
|
-
? rmdir(absDestDir)
|
|
22
|
+
? fsp['rm' in fsp ? 'rm' : 'rmdir'](absDestDir, { recursive: true, force: true })
|
|
23
23
|
.then(() => publishStream(vfsDest(absDestDir), files))
|
|
24
24
|
.then(() => report)
|
|
25
25
|
: publishStream(vfsDest(absDestDir), files).then(() => report)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
* Removes the specified directory (including all of its contents) or file.
|
|
30
|
-
* Equivalent to fs.promises.rmdir(dir, { recursive: true }) in Node 12.
|
|
31
|
-
*/
|
|
32
|
-
function rmdir (dir) {
|
|
33
|
-
return fsp
|
|
34
|
-
.readdir(dir, { withFileTypes: true })
|
|
35
|
-
.then((lst) =>
|
|
36
|
-
Promise.all(
|
|
37
|
-
lst.map((it) =>
|
|
38
|
-
it.isDirectory()
|
|
39
|
-
? rmdir(ospath.join(dir, it.name))
|
|
40
|
-
: fsp.unlink(ospath.join(dir, it.name)).catch((unlinkErr) => {
|
|
41
|
-
if (unlinkErr.code !== 'ENOENT') throw unlinkErr
|
|
42
|
-
})
|
|
43
|
-
)
|
|
44
|
-
)
|
|
45
|
-
)
|
|
46
|
-
.then(() => fsp.rmdir(dir))
|
|
47
|
-
.catch((err) => {
|
|
48
|
-
if (err.code === 'ENOENT') return
|
|
49
|
-
if (err.code === 'ENOTDIR') {
|
|
50
|
-
return fsp.unlink(dir).catch((unlinkErr) => {
|
|
51
|
-
if (unlinkErr.code !== 'ENOENT') throw unlinkErr
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
throw err
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
28
|
module.exports = publishToFs
|
package/lib/publish-site.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const ReadableOutputFileArray = require('./readable-output-file-array')
|
|
4
|
-
const
|
|
4
|
+
const userRequire = require('@antora/user-require-helper')
|
|
5
5
|
|
|
6
6
|
const { DEFAULT_DEST_FS } = require('./constants.js')
|
|
7
7
|
|
|
@@ -52,9 +52,12 @@ async function publishSite (playbook, catalogs) {
|
|
|
52
52
|
return require('./providers/' + provider).bind(null, options)
|
|
53
53
|
default:
|
|
54
54
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
})
|
|
@@ -73,7 +76,7 @@ function getDestinations (output) {
|
|
|
73
76
|
let destinations = output.destinations
|
|
74
77
|
if (output.dir) {
|
|
75
78
|
if (destinations && destinations.length) {
|
|
76
|
-
destinations = destinations.slice(
|
|
79
|
+
destinations = destinations.slice()
|
|
77
80
|
const primaryFsDestIdx = destinations.findIndex(({ provider: candidate }) => candidate === 'fs')
|
|
78
81
|
if (~primaryFsDestIdx) {
|
|
79
82
|
;(destinations[primaryFsDestIdx] = Object.assign({}, destinations[primaryFsDestIdx])).path = output.dir
|
|
@@ -12,13 +12,17 @@ class File extends Vinyl {
|
|
|
12
12
|
class ReadableOutputFileArray extends Readable {
|
|
13
13
|
constructor (array) {
|
|
14
14
|
super({ objectMode: true })
|
|
15
|
-
this.array = array.slice(
|
|
15
|
+
this.array = array.slice().reverse()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
_read (size) {
|
|
19
|
-
const
|
|
20
|
-
while (
|
|
21
|
-
|
|
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)
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/site-publisher",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "Publishes the files generated in an Antora documentation pipeline to the destination(s) specified in the playbook.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
},
|
|
16
16
|
"main": "lib/index.js",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@antora/expand-path-helper": "~
|
|
19
|
-
"
|
|
18
|
+
"@antora/expand-path-helper": "~2.0",
|
|
19
|
+
"@antora/user-require-helper": "~2.0",
|
|
20
|
+
"gulp-vinyl-zip": "~2.5",
|
|
20
21
|
"vinyl": "~2.2",
|
|
21
22
|
"vinyl-fs": "~3.0"
|
|
22
23
|
},
|
|
23
24
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
25
|
+
"node": ">=12.21.0"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"lib/"
|
|
@@ -34,5 +35,5 @@
|
|
|
34
35
|
"static site",
|
|
35
36
|
"web publishing"
|
|
36
37
|
],
|
|
37
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "7c5ef1ea93dd489af533c80a936c736013c41769"
|
|
38
39
|
}
|
package/lib/require-provider.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const ospath = require('path')
|
|
4
|
-
|
|
5
|
-
const DOT_RELATIVE_RX = new RegExp(`^\\.{1,2}[/${ospath.sep.replace('/', '').replace('\\', '\\\\')}]`)
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Generates a function to resolve and require a custom provider.
|
|
9
|
-
*
|
|
10
|
-
* @memberof site-publisher
|
|
11
|
-
*
|
|
12
|
-
* @returns {Function} A function to require a provider.
|
|
13
|
-
*/
|
|
14
|
-
function createRequireProvider () {
|
|
15
|
-
const requestCache = new Map()
|
|
16
|
-
/**
|
|
17
|
-
* Requires a provider, first resolving the path if necessary.
|
|
18
|
-
*
|
|
19
|
-
* If the request is an absolute path, that value is used as is. If the
|
|
20
|
-
* request begins with a dot (.), the value is resolved relative to the
|
|
21
|
-
* specified base directory. Otherwise, the request is resolved as the name
|
|
22
|
-
* of a node module, a search which includes the node_modules folder in the
|
|
23
|
-
* specified base directory. The resolved value is then passed to the require
|
|
24
|
-
* function and the result returned.
|
|
25
|
-
*
|
|
26
|
-
* @param {String} request - The path or module name to resolve.
|
|
27
|
-
* @param {String} requireBase - The absolute path from which to resolve a
|
|
28
|
-
* relative path or module name.
|
|
29
|
-
*
|
|
30
|
-
* @returns {Object} The object returned by calling require on the resolved path.
|
|
31
|
-
*/
|
|
32
|
-
return function requireProvider (request, requireBase) {
|
|
33
|
-
let resolved = requestCache.get(request)
|
|
34
|
-
if (!resolved) {
|
|
35
|
-
if (request.charAt() === '.' && DOT_RELATIVE_RX.test(request)) {
|
|
36
|
-
resolved = ospath.resolve(requireBase, request)
|
|
37
|
-
} else if (ospath.isAbsolute(request)) {
|
|
38
|
-
resolved = request
|
|
39
|
-
} else {
|
|
40
|
-
// NOTE appending node_modules prevents require from looking elsewhere before looking in these paths
|
|
41
|
-
const paths = [requireBase, ospath.dirname(__dirname)].map((start) => ospath.join(start, 'node_modules'))
|
|
42
|
-
resolved = require.resolve(request, { paths })
|
|
43
|
-
}
|
|
44
|
-
requestCache.set(request, resolved)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return require(resolved)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = createRequireProvider
|