@antora/site-generator-default
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
@@ -7,5 +7,5 @@ 'use strict' | ||
async function generateSite (playbook) { | ||
const context = new GeneratorContext(module) | ||
try { | ||
const context = new GeneratorContext(playbook, module) | ||
const { fxns, vars } = context | ||
const { fxns, vars } = await GeneratorContext.start(context, playbook) | ||
await context.notify('playbookBuilt') | ||
@@ -59,3 +59,6 @@ playbook = vars.lock('playbook') | ||
} catch (err) { | ||
if (!GeneratorContext.isHaltSignal(err)) throw err | ||
if (!GeneratorContext.isStopSignal(err)) throw err | ||
await err.notify() | ||
} finally { | ||
await GeneratorContext.close(context) | ||
} | ||
@@ -62,0 +65,0 @@ } |
@@ -23,4 +23,7 @@ 'use strict' | ||
class HaltSignal extends Error {} | ||
const FUNCTION_WITH_POSITIONAL_PARAMETER_RX = /^(?:function *)?(?:\w+ *)?\( *\w|^\w+(?: *, *\w+)* *=>/ | ||
const NEWLINES_RX = /\r?\n/g | ||
class StopSignal extends Error {} | ||
class GeneratorContext extends EventEmitter { | ||
@@ -30,8 +33,7 @@ #fxns | ||
constructor (playbook, module_) { | ||
constructor (module_) { | ||
super() | ||
// deprecated method aliases - remove for Antora 3.0.0 | ||
Object.defineProperties(this, { halt: { value: this.stop }, updateVars: { value: this.updateVariables } }) | ||
if (!('path' in (this.module = module_))) module_.path = require('path').dirname(module_.filename) | ||
this._registerFunctions(module_) | ||
this._registerExtensions(playbook, this._initVariables(playbook), module_) | ||
Object.defineProperties(this, { _initVariables: {}, _registerExtensions: {}, _registerFunctions: {} }) | ||
} | ||
@@ -51,6 +53,2 @@ | ||
halt () { | ||
throw new HaltSignal() | ||
} | ||
async notify (eventName) { | ||
@@ -66,3 +64,3 @@ if (!this.listenerCount(eventName)) return | ||
const fxns = this.#fxns | ||
Object.entries(updates).map(([name, fxn]) => { | ||
Object.entries(updates).forEach(([name, fxn]) => { | ||
if (name in fxns) fxns[name] = fxn.bind(this) | ||
@@ -76,2 +74,7 @@ }) | ||
stop (code) { | ||
if (code != null) process.exitCode = code | ||
throw Object.assign(new StopSignal(), { notify: this.notify.bind(this, 'contextStopped') }) | ||
} | ||
updateVariables (updates) { | ||
@@ -88,35 +91,43 @@ try { | ||
// TODO remove updateVars before Antora 3.0.0 | ||
updateVars (updates) { | ||
return this.updateVariables(updates) | ||
static async close (instance) { | ||
await instance.notify('contextClosed').catch(() => undefined) | ||
} | ||
static isHaltSignal (err) { | ||
return err instanceof HaltSignal | ||
static isStopSignal (err) { | ||
return err instanceof StopSignal | ||
} | ||
static async start (instance, playbook) { | ||
const returnValue = instance._init(playbook) | ||
await instance.notify('contextStarted') | ||
return returnValue | ||
} | ||
_init (playbook) { | ||
this._registerFunctions() | ||
this._registerExtensions(playbook, this._initVariables(playbook)) | ||
Object.defineProperties(this, { _init: {}, _initVariables: {}, _registerExtensions: {}, _registerFunctions: {} }) | ||
return { fxns: this.#fxns, vars: this.#vars } | ||
} | ||
_initVariables (playbook) { | ||
Object.defineProperty(this, 'vars', { | ||
configurable: true, | ||
get: () => { | ||
delete this.vars | ||
return Object.setPrototypeOf(this.#vars, { | ||
lock (name) { | ||
return Object.defineProperty(this, name, { configurable: false, writable: false })[name] | ||
}, | ||
remove (name) { | ||
const currentValue = this[name] | ||
delete this[name] | ||
return currentValue | ||
}, | ||
}) | ||
}, | ||
}) | ||
return (this.#vars = { playbook }) | ||
return (this.#vars = Object.setPrototypeOf( | ||
{ playbook }, | ||
{ | ||
lock (name) { | ||
return Object.defineProperty(this, name, { configurable: false, writable: false })[name] | ||
}, | ||
remove (name) { | ||
const currentValue = this[name] | ||
delete this[name] | ||
return currentValue | ||
}, | ||
} | ||
)) | ||
} | ||
_registerExtensions (playbook, vars, module_) { | ||
_registerExtensions (playbook, vars) { | ||
const extensions = (playbook.antora || {}).extensions || [] | ||
if (extensions.length) { | ||
const requireContext = { dot: playbook.dir, paths: [playbook.dir || '', module_.path] } | ||
const requireContext = { dot: playbook.dir, paths: [playbook.dir || '', this.module.path] } | ||
extensions.forEach((ext) => { | ||
@@ -128,3 +139,3 @@ const { enabled = true, id, require: request, ...config } = ext.constructor === String ? { require: ext } : ext | ||
if (register.length) { | ||
if (/^(?:function *)?(?:\w+ *)?\( *\w|^\w+(?: *, *\w+)* *=>/.test(register.toString().replace(/\r?\n/g, ' '))) { | ||
if (FUNCTION_WITH_POSITIONAL_PARAMETER_RX.test(register.toString().replace(NEWLINES_RX, ' '))) { | ||
register.length === 1 ? register(this) : register(this, Object.assign({ config }, vars)) | ||
@@ -139,6 +150,8 @@ } else { | ||
} | ||
this.notify = this.eventNames().length ? this.notify.bind(this) : async () => undefined | ||
if (this.eventNames().length) return | ||
const notify = async () => undefined | ||
Object.defineProperty(this, 'notify', { value: notify }) | ||
} | ||
_registerFunctions (module_) { | ||
_registerFunctions () { | ||
this.#fxns = Object.entries( | ||
@@ -150,3 +163,3 @@ Object.entries(FUNCTION_PROVIDERS).reduce((accum, [fxnName, moduleKey]) => { | ||
).reduce((accum, [moduleKey, fxnNames]) => { | ||
const defaultExport = module_.require('@antora/' + moduleKey) | ||
const defaultExport = this.require('@antora/' + moduleKey) | ||
const defaultExportName = defaultExport.name | ||
@@ -159,9 +172,2 @@ fxnNames.forEach((fxnName) => { | ||
}, {}) | ||
Object.defineProperty(this, 'fxns', { | ||
configurable: true, | ||
get: () => { | ||
delete this.fxns | ||
return this.#fxns | ||
}, | ||
}) | ||
} | ||
@@ -168,0 +174,0 @@ } |
{ | ||
"name": "@antora/site-generator-default", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "The default site generator for producing and publishing static documentation sites with Antora.", | ||
@@ -18,17 +18,17 @@ "license": "MPL-2.0", | ||
"dependencies": { | ||
"@antora/asciidoc-loader": "3.0.0-beta.1", | ||
"@antora/content-aggregator": "3.0.0-beta.1", | ||
"@antora/content-classifier": "3.0.0-beta.1", | ||
"@antora/document-converter": "3.0.0-beta.1", | ||
"@antora/logger": "3.0.0-beta.1", | ||
"@antora/navigation-builder": "3.0.0-beta.1", | ||
"@antora/page-composer": "3.0.0-beta.1", | ||
"@antora/redirect-producer": "3.0.0-beta.1", | ||
"@antora/site-mapper": "3.0.0-beta.1", | ||
"@antora/site-publisher": "3.0.0-beta.1", | ||
"@antora/ui-loader": "3.0.0-beta.1", | ||
"@antora/asciidoc-loader": "3.0.0-beta.2", | ||
"@antora/content-aggregator": "3.0.0-beta.2", | ||
"@antora/content-classifier": "3.0.0-beta.2", | ||
"@antora/document-converter": "3.0.0-beta.2", | ||
"@antora/logger": "3.0.0-beta.2", | ||
"@antora/navigation-builder": "3.0.0-beta.2", | ||
"@antora/page-composer": "3.0.0-beta.2", | ||
"@antora/redirect-producer": "3.0.0-beta.2", | ||
"@antora/site-mapper": "3.0.0-beta.2", | ||
"@antora/site-publisher": "3.0.0-beta.2", | ||
"@antora/ui-loader": "3.0.0-beta.2", | ||
"@antora/user-require-helper": "~2.0" | ||
}, | ||
"devDependencies": { | ||
"@antora/playbook-builder": "3.0.0-beta.1" | ||
"@antora/playbook-builder": "3.0.0-beta.2" | ||
}, | ||
@@ -50,3 +50,3 @@ "engines": { | ||
], | ||
"gitHead": "7c5ef1ea93dd489af533c80a936c736013c41769" | ||
"gitHead": "5cd3f9cc70622e465cb44daf1aa2035ed5a35f54" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28173
247
0
+ Added@antora/asciidoc-loader@3.0.0-beta.2(transitive)
+ Added@antora/content-aggregator@3.0.0-beta.2(transitive)
+ Added@antora/content-classifier@3.0.0-beta.2(transitive)
+ Added@antora/document-converter@3.0.0-beta.2(transitive)
+ Added@antora/logger@3.0.0-beta.2(transitive)
+ Added@antora/navigation-builder@3.0.0-beta.2(transitive)
+ Added@antora/page-composer@3.0.0-beta.2(transitive)
+ Added@antora/redirect-producer@3.0.0-beta.2(transitive)
+ Added@antora/site-mapper@3.0.0-beta.2(transitive)
+ Added@antora/site-publisher@3.0.0-beta.2(transitive)
+ Added@antora/ui-loader@3.0.0-beta.2(transitive)
+ Addedfastify-warning@0.2.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedon-exit-leak-free@0.2.0(transitive)
+ Addedpino@7.2.0(transitive)
+ Addedpino-pretty@7.2.0(transitive)
+ Addedpino-std-serializers@4.0.0(transitive)
+ Addedreal-require@0.1.0(transitive)
+ Addedsafe-stable-stringify@2.5.0(transitive)
+ Addedthread-stream@0.13.2(transitive)
- Removed@antora/asciidoc-loader@3.0.0-beta.1(transitive)
- Removed@antora/content-aggregator@3.0.0-beta.1(transitive)
- Removed@antora/content-classifier@3.0.0-beta.1(transitive)
- Removed@antora/document-converter@3.0.0-beta.1(transitive)
- Removed@antora/logger@3.0.0-beta.1(transitive)
- Removed@antora/navigation-builder@3.0.0-beta.1(transitive)
- Removed@antora/page-composer@3.0.0-beta.1(transitive)
- Removed@antora/redirect-producer@3.0.0-beta.1(transitive)
- Removed@antora/site-mapper@3.0.0-beta.1(transitive)
- Removed@antora/site-publisher@3.0.0-beta.1(transitive)
- Removed@antora/ui-loader@3.0.0-beta.1(transitive)
- Removedduplexify@4.1.3(transitive)
- Removedflatstr@1.0.12(transitive)
- Removedpino@6.13.4(transitive)
- Removedpino-abstract-transport@0.4.0(transitive)
- Removedpino-pretty@7.1.0(transitive)
- Removedpino-std-serializers@3.2.0(transitive)
- Removedprocess-warning@1.0.0(transitive)
- Removedsonic-boom@1.4.1(transitive)
- Removedsplit2@3.2.2(transitive)
Updated@antora/logger@3.0.0-beta.2