Skip to content

Commit a66a5ce

Browse files
committed
feat: system-env option
This option allows reusing a dependency that's already stored somewhere in the environment. In this case, the git clone step is skipped.
1 parent 69cdac1 commit a66a5ce

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

README.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ antora:
3737
repo: 'https://github.com/boostorg/boost.git'
3838
tag: 'develop'
3939
variable: 'BOOST_SRC_ROOT'
40+
system-env: 'BOOST_SRC_ROOT' # <3>
4041
----
4142

4243
* <1> `npm` package name: `@alandefreitas/antora-cpp-reference-extension` (required)
4344
* <2> List of dependencies to be downloaded and extracted. The directory where these dependencies are extracted will be available to all components as an environment variable.
45+
* <3> The name of the environment variable describing where the path can be found. If this path exists and is a valid directory, it will be used as the source root for the dependency, skipping the download and extraction steps. If this is different from `variable`, the extension will set the value of `variable` to the path where the dependency is already located.
4446

4547
=== Components
4648

example/doc/local-playbook.yml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ antora:
3939
tag: 'v0.11.0'
4040
clone-submodules: false
4141
variable: 'FMT_SRC_ROOT'
42+
system-env: 'FMT_SRC_ROOT'
4243

4344
asciidoc:
4445
attributes:

lib/extension.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,29 @@ class CppReferenceExtension {
194194
const DependenciesDir = path.join(cacheDir, 'dependencies')
195195
const dependencies = this.config.dependencies
196196
for (const dependency of dependencies) {
197+
// Check if dependency has a name
198+
if (dependency.name === undefined) {
199+
if (typeof dependency.repo === 'string') {
200+
this.logger.error(`Dependency name is required for ${dependency.repo}`)
201+
} else {
202+
this.logger.error('Dependency name is required')
203+
}
204+
continue
205+
}
206+
197207
const requiredFields = ['name', 'repo', 'variable']
198208
let missingRequired = false
199209
for (const field of requiredFields) {
200210
if (!dependency[field]) {
201-
this.logger.error(`Dependency ${field} is required`)
211+
this.logger.error(`Dependency field "${field}" is required for ${dependency.name}`)
202212
missingRequired = true
203213
}
204214
}
205215
if (missingRequired) {
206216
continue
207217
}
208218

209-
const {name, repo, tag, variable, cloneSubmodules} = dependency
219+
const {name, repo, tag, variable, systemEnv, cloneSubmodules} = dependency
210220
if (!name) {
211221
this.logger.error(`Dependency name is required (${repo})`)
212222
continue
@@ -220,6 +230,21 @@ class CppReferenceExtension {
220230
continue
221231
}
222232

233+
// Check if the dependency is already available from systemEnv
234+
if (systemEnv && process.env[variable]) {
235+
// Check if this is a directory that exists
236+
const dependencyPath = process.env[variable]
237+
const dependencyPathExists = await CppReferenceExtension.fileExists(dependencyPath)
238+
const dependencyPathIsDir = dependencyPathExists && (await fsp.stat(dependencyPath)).isDirectory()
239+
if (dependencyPathIsDir) {
240+
this.logger.debug(`Dependency ${name} already exists at ${dependencyPath}`)
241+
if (variable !== systemEnv) {
242+
process.env[variable] = dependencyPath
243+
}
244+
continue
245+
}
246+
}
247+
223248
let cloneDir = path.join(DependenciesDir, name)
224249
if (tag) {
225250
cloneDir = path.join(cloneDir, tag)

0 commit comments

Comments
 (0)