@antora/site-generator-default 3.0.0-beta.1 → 3.0.0-beta.2
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/lib/generate-site.js +6 -3
- package/lib/generator-context.js +51 -45
- package/package.json +14 -14
package/lib/generate-site.js
CHANGED
|
@@ -4,9 +4,9 @@ const GeneratorContext = require('./generator-context')
|
|
|
4
4
|
const SiteCatalog = require('./site-catalog')
|
|
5
5
|
|
|
6
6
|
async function generateSite (playbook) {
|
|
7
|
+
const context = new GeneratorContext(module)
|
|
7
8
|
try {
|
|
8
|
-
const
|
|
9
|
-
const { fxns, vars } = context
|
|
9
|
+
const { fxns, vars } = await GeneratorContext.start(context, playbook)
|
|
10
10
|
await context.notify('playbookBuilt')
|
|
11
11
|
playbook = vars.lock('playbook')
|
|
12
12
|
vars.asciidocConfig = fxns.resolveAsciiDocConfig(playbook)
|
|
@@ -55,7 +55,10 @@ async function generateSite (playbook) {
|
|
|
55
55
|
.then(() => vars.remove('publications'))
|
|
56
56
|
})
|
|
57
57
|
} catch (err) {
|
|
58
|
-
if (!GeneratorContext.
|
|
58
|
+
if (!GeneratorContext.isStopSignal(err)) throw err
|
|
59
|
+
await err.notify()
|
|
60
|
+
} finally {
|
|
61
|
+
await GeneratorContext.close(context)
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
|
package/lib/generator-context.js
CHANGED
|
@@ -20,18 +20,20 @@ const FUNCTION_PROVIDERS = {
|
|
|
20
20
|
resolveAsciiDocConfig: 'asciidoc-loader',
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const FUNCTION_WITH_POSITIONAL_PARAMETER_RX = /^(?:function *)?(?:\w+ *)?\( *\w|^\w+(?: *, *\w+)* *=>/
|
|
24
|
+
const NEWLINES_RX = /\r?\n/g
|
|
25
|
+
|
|
26
|
+
class StopSignal extends Error {}
|
|
24
27
|
|
|
25
28
|
class GeneratorContext extends EventEmitter {
|
|
26
29
|
#fxns
|
|
27
30
|
#vars
|
|
28
31
|
|
|
29
|
-
constructor (
|
|
32
|
+
constructor (module_) {
|
|
30
33
|
super()
|
|
34
|
+
// deprecated method aliases - remove for Antora 3.0.0
|
|
35
|
+
Object.defineProperties(this, { halt: { value: this.stop }, updateVars: { value: this.updateVariables } })
|
|
31
36
|
if (!('path' in (this.module = module_))) module_.path = require('path').dirname(module_.filename)
|
|
32
|
-
this._registerFunctions(module_)
|
|
33
|
-
this._registerExtensions(playbook, this._initVariables(playbook), module_)
|
|
34
|
-
Object.defineProperties(this, { _initVariables: {}, _registerExtensions: {}, _registerFunctions: {} })
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
getFunctions () {
|
|
@@ -46,10 +48,6 @@ class GeneratorContext extends EventEmitter {
|
|
|
46
48
|
return Object.assign({}, this.#vars)
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
halt () {
|
|
50
|
-
throw new HaltSignal()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
51
|
async notify (eventName) {
|
|
54
52
|
if (!this.listenerCount(eventName)) return
|
|
55
53
|
for (const listener of this.rawListeners(eventName)) {
|
|
@@ -60,7 +58,7 @@ class GeneratorContext extends EventEmitter {
|
|
|
60
58
|
|
|
61
59
|
replaceFunctions (updates) {
|
|
62
60
|
const fxns = this.#fxns
|
|
63
|
-
Object.entries(updates).
|
|
61
|
+
Object.entries(updates).forEach(([name, fxn]) => {
|
|
64
62
|
if (name in fxns) fxns[name] = fxn.bind(this)
|
|
65
63
|
})
|
|
66
64
|
}
|
|
@@ -69,6 +67,11 @@ class GeneratorContext extends EventEmitter {
|
|
|
69
67
|
return this.module.require(request)
|
|
70
68
|
}
|
|
71
69
|
|
|
70
|
+
stop (code) {
|
|
71
|
+
if (code != null) process.exitCode = code
|
|
72
|
+
throw Object.assign(new StopSignal(), { notify: this.notify.bind(this, 'contextStopped') })
|
|
73
|
+
}
|
|
74
|
+
|
|
72
75
|
updateVariables (updates) {
|
|
73
76
|
try {
|
|
74
77
|
Object.assign(this.#vars, updates)
|
|
@@ -80,46 +83,54 @@ class GeneratorContext extends EventEmitter {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
static async close (instance) {
|
|
87
|
+
await instance.notify('contextClosed').catch(() => undefined)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static isStopSignal (err) {
|
|
91
|
+
return err instanceof StopSignal
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static async start (instance, playbook) {
|
|
95
|
+
const returnValue = instance._init(playbook)
|
|
96
|
+
await instance.notify('contextStarted')
|
|
97
|
+
return returnValue
|
|
86
98
|
}
|
|
87
99
|
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
_init (playbook) {
|
|
101
|
+
this._registerFunctions()
|
|
102
|
+
this._registerExtensions(playbook, this._initVariables(playbook))
|
|
103
|
+
Object.defineProperties(this, { _init: {}, _initVariables: {}, _registerExtensions: {}, _registerFunctions: {} })
|
|
104
|
+
return { fxns: this.#fxns, vars: this.#vars }
|
|
90
105
|
}
|
|
91
106
|
|
|
92
107
|
_initVariables (playbook) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
})
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
return (this.#vars = { playbook })
|
|
108
|
+
return (this.#vars = Object.setPrototypeOf(
|
|
109
|
+
{ playbook },
|
|
110
|
+
{
|
|
111
|
+
lock (name) {
|
|
112
|
+
return Object.defineProperty(this, name, { configurable: false, writable: false })[name]
|
|
113
|
+
},
|
|
114
|
+
remove (name) {
|
|
115
|
+
const currentValue = this[name]
|
|
116
|
+
delete this[name]
|
|
117
|
+
return currentValue
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
))
|
|
110
121
|
}
|
|
111
122
|
|
|
112
|
-
_registerExtensions (playbook, vars
|
|
123
|
+
_registerExtensions (playbook, vars) {
|
|
113
124
|
const extensions = (playbook.antora || {}).extensions || []
|
|
114
125
|
if (extensions.length) {
|
|
115
|
-
const requireContext = { dot: playbook.dir, paths: [playbook.dir || '',
|
|
126
|
+
const requireContext = { dot: playbook.dir, paths: [playbook.dir || '', this.module.path] }
|
|
116
127
|
extensions.forEach((ext) => {
|
|
117
128
|
const { enabled = true, id, require: request, ...config } = ext.constructor === String ? { require: ext } : ext
|
|
118
129
|
if (!enabled) return
|
|
119
130
|
const { register } = userRequire(request, requireContext)
|
|
120
131
|
if (typeof register !== 'function') return
|
|
121
132
|
if (register.length) {
|
|
122
|
-
if (
|
|
133
|
+
if (FUNCTION_WITH_POSITIONAL_PARAMETER_RX.test(register.toString().replace(NEWLINES_RX, ' '))) {
|
|
123
134
|
register.length === 1 ? register(this) : register(this, Object.assign({ config }, vars))
|
|
124
135
|
} else {
|
|
125
136
|
register.call(this, Object.assign({ config }, vars))
|
|
@@ -129,17 +140,19 @@ class GeneratorContext extends EventEmitter {
|
|
|
129
140
|
}
|
|
130
141
|
})
|
|
131
142
|
}
|
|
132
|
-
|
|
143
|
+
if (this.eventNames().length) return
|
|
144
|
+
const notify = async () => undefined
|
|
145
|
+
Object.defineProperty(this, 'notify', { value: notify })
|
|
133
146
|
}
|
|
134
147
|
|
|
135
|
-
_registerFunctions (
|
|
148
|
+
_registerFunctions () {
|
|
136
149
|
this.#fxns = Object.entries(
|
|
137
150
|
Object.entries(FUNCTION_PROVIDERS).reduce((accum, [fxnName, moduleKey]) => {
|
|
138
151
|
accum[moduleKey] = (accum[moduleKey] || []).concat(fxnName)
|
|
139
152
|
return accum
|
|
140
153
|
}, {})
|
|
141
154
|
).reduce((accum, [moduleKey, fxnNames]) => {
|
|
142
|
-
const defaultExport =
|
|
155
|
+
const defaultExport = this.require('@antora/' + moduleKey)
|
|
143
156
|
const defaultExportName = defaultExport.name
|
|
144
157
|
fxnNames.forEach((fxnName) => {
|
|
145
158
|
const fxn = fxnName === defaultExportName ? defaultExport : defaultExport[fxnName]
|
|
@@ -147,13 +160,6 @@ class GeneratorContext extends EventEmitter {
|
|
|
147
160
|
})
|
|
148
161
|
return accum
|
|
149
162
|
}, {})
|
|
150
|
-
Object.defineProperty(this, 'fxns', {
|
|
151
|
-
configurable: true,
|
|
152
|
-
get: () => {
|
|
153
|
-
delete this.fxns
|
|
154
|
-
return this.#fxns
|
|
155
|
-
},
|
|
156
|
-
})
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
165
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/site-generator-default",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"description": "The default site generator for producing and publishing static documentation sites with Antora.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|
|
@@ -15,21 +15,21 @@
|
|
|
15
15
|
},
|
|
16
16
|
"main": "lib/index.js",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@antora/asciidoc-loader": "3.0.0-beta.
|
|
19
|
-
"@antora/content-aggregator": "3.0.0-beta.
|
|
20
|
-
"@antora/content-classifier": "3.0.0-beta.
|
|
21
|
-
"@antora/document-converter": "3.0.0-beta.
|
|
22
|
-
"@antora/logger": "3.0.0-beta.
|
|
23
|
-
"@antora/navigation-builder": "3.0.0-beta.
|
|
24
|
-
"@antora/page-composer": "3.0.0-beta.
|
|
25
|
-
"@antora/redirect-producer": "3.0.0-beta.
|
|
26
|
-
"@antora/site-mapper": "3.0.0-beta.
|
|
27
|
-
"@antora/site-publisher": "3.0.0-beta.
|
|
28
|
-
"@antora/ui-loader": "3.0.0-beta.
|
|
18
|
+
"@antora/asciidoc-loader": "3.0.0-beta.2",
|
|
19
|
+
"@antora/content-aggregator": "3.0.0-beta.2",
|
|
20
|
+
"@antora/content-classifier": "3.0.0-beta.2",
|
|
21
|
+
"@antora/document-converter": "3.0.0-beta.2",
|
|
22
|
+
"@antora/logger": "3.0.0-beta.2",
|
|
23
|
+
"@antora/navigation-builder": "3.0.0-beta.2",
|
|
24
|
+
"@antora/page-composer": "3.0.0-beta.2",
|
|
25
|
+
"@antora/redirect-producer": "3.0.0-beta.2",
|
|
26
|
+
"@antora/site-mapper": "3.0.0-beta.2",
|
|
27
|
+
"@antora/site-publisher": "3.0.0-beta.2",
|
|
28
|
+
"@antora/ui-loader": "3.0.0-beta.2",
|
|
29
29
|
"@antora/user-require-helper": "~2.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@antora/playbook-builder": "3.0.0-beta.
|
|
32
|
+
"@antora/playbook-builder": "3.0.0-beta.2"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=12.21.0"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"static site",
|
|
47
47
|
"web publishing"
|
|
48
48
|
],
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "5cd3f9cc70622e465cb44daf1aa2035ed5a35f54"
|
|
50
50
|
}
|