diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index bb743d078038b89ededfd85266e2ea49948df958..3bdd1cb587205bddb5e487e44b67153fda5a715a 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -6,6 +6,10 @@ For a detailed view of what's changed, refer to the {url-repo}/commits[commit hi == Unreleased +=== Added + +* Add `build.cwd` to allow current directory for command to be specified (#132) + === Fixed * integrate Asciidoctor log messages properly when jsonl formatter is not enabled (#133) diff --git a/docs/assembler/modules/ROOT/pages/configure-build.adoc b/docs/assembler/modules/ROOT/pages/configure-build.adoc index b94f7a2fbce73197731316113cb3ad277c1117be..62934cb0b5baf81a07a5eea7116746a2099d31cc 100644 --- a/docs/assembler/modules/ROOT/pages/configure-build.adoc +++ b/docs/assembler/modules/ROOT/pages/configure-build.adoc @@ -29,6 +29,11 @@ asciidoctor-pdf for the PDF extension |Boolean |Controls whether the directory specified by the `dir` key should be removed before Assembler runs. +|<> +|./netlify +|String (absolute path, path relative to start path if starts with ./, or path relative to content source root) +|The directory in which the command is launched. + |<> |./build/assembler- |String (absolute path, path relative to start path if starts with ./, or path relative to content source root) @@ -183,6 +188,24 @@ build: // FIXME this advice is confusing This key should only be set when using multiple extension instances since leaving behind generated and staged files from a previous run can lead to unexpected and non-reproducible behavior. +[#cwd-key] +== cwd key + +The `cwd` key specifies the directory in which the command is launched. +From the perspective of the command, this is its current working directory (CWD). + +The `cwd` key accepts a directory path and uses the same path resolution rules as the output directory in the Antora playbook. +By default, the value is the directory in which the playbook is found. + +.antora-assembler.yml +[,yaml] +---- +build: + cwd: ./ci +---- + +Typically, you change this key if the command to run is not installed globally, but also not installed at the root of the playbook project. + [#dir-key] == dir key diff --git a/packages/assembler/lib/load-config.js b/packages/assembler/lib/load-config.js index 5198dd1dbb63630485181e917a8f0009812f60f6..88dad9b4182e8b6266699bac4be2b4c52f3084fa 100644 --- a/packages/assembler/lib/load-config.js +++ b/packages/assembler/lib/load-config.js @@ -78,7 +78,8 @@ function loadConfig (playbook, configSource = './antora-assembler.yml') { throw new Error('Not implemented') } build.dir &&= expandPath(build.dir, { dot: playbook.dir }) - build.cwd = playbook.dir // use playbook.dir for finding and loading require scripts + // used as cwd of command (and any scripts it requires) + build.cwd = build.cwd == null ? playbook.dir : expandPath(build.cwd, { dot: playbook.dir }) if (!('clean' in build) && 'output' in playbook) build.clean = playbook.output.clean if (!('publish' in build)) build.publish = true if ('keepAggregateSource' in build) { diff --git a/packages/assembler/test/assemble-content-test.js b/packages/assembler/test/assemble-content-test.js index 715d91eadf635a141331b730b52e8809401af7a3..75fde39a9a68e62ff2c1cfac1b7d7fe97e536c76 100644 --- a/packages/assembler/test/assemble-content-test.js +++ b/packages/assembler/test/assemble-content-test.js @@ -490,7 +490,7 @@ describe('assembleContent()', () => { const scenario = 'insert-page' const playbook = { dir: ospath.join(FIXTURES_DIR, 'project-with-command') } const { contentCatalog, assemblerConfig: configSource } = await loadScenario(scenario, __dirname) - Object.assign(configSource.build, { command: './convert-to-pdf', mkdirs: true, publish: false }) + Object.assign(configSource.build, { command: './convert-to-pdf', cwd: playbook.dir, mkdirs: true, publish: false }) let actualConvertAttributes const convert = (doc, convertAttributes, buildConfig) => { const { cwd, command } = buildConfig diff --git a/packages/assembler/test/load-config-test.js b/packages/assembler/test/load-config-test.js index afc604dc02b9a2fffe66d3897e02ab62ae533f06..f85ff1855081d51d3f99fa368f584c201106e21c 100644 --- a/packages/assembler/test/load-config-test.js +++ b/packages/assembler/test/load-config-test.js @@ -193,6 +193,13 @@ describe('loadConfig()', () => { assert.equal(actual.build.clean, false) }) + it('should not override value of build.cwd key if specified', async () => { + const input = { build: { cwd: './netlify' } } + const actual = await loadConfig(playbook, input) + assertx.instanceOf(actual, Object) + assert.equal(actual.build.cwd, ospath.join(playbook.dir, 'netlify')) + }) + it('should set value of build.processLimit key to Infinity if value is falsy', async () => { const input = { build: { processLimit: null } } const actual = await loadConfig(playbook, input)