@antora/ui-loader 3.0.0-beta.3 → 3.0.0-rc.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/lib/file.js +1 -1
- package/lib/load-ui.js +32 -30
- package/package.json +6 -3
package/lib/file.js
CHANGED
package/lib/load-ui.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const { compile: bracesToGroup } = require('braces')
|
|
4
4
|
const camelCaseKeys = require('camelcase-keys')
|
|
5
|
-
const concat = require('simple-concat')
|
|
6
5
|
const { createHash } = require('crypto')
|
|
7
6
|
const expandPath = require('@antora/expand-path-helper')
|
|
8
7
|
const { File, MemoryFile, ReadableFile } = require('./file')
|
|
@@ -14,8 +13,9 @@ const ospath = require('path')
|
|
|
14
13
|
const { posix: path } = ospath
|
|
15
14
|
const picomatch = require('picomatch')
|
|
16
15
|
const posixify = ospath.sep === '\\' ? (p) => p.replace(/\\/g, '/') : undefined
|
|
17
|
-
const { pipeline, Transform } = require('stream')
|
|
18
|
-
const
|
|
16
|
+
const { pipeline, Transform, Writable } = require('stream')
|
|
17
|
+
const forEach = (write, final) => new Writable({ objectMode: true, write, final })
|
|
18
|
+
const map = (transform) => new Transform({ objectMode: true, transform })
|
|
19
19
|
const UiCatalog = require('./ui-catalog')
|
|
20
20
|
const yaml = require('js-yaml')
|
|
21
21
|
const vzip = require('gulp-vinyl-zip')
|
|
@@ -40,7 +40,7 @@ const EXT_RX = /\.[a-z]{2,3}$/
|
|
|
40
40
|
* the playbook. If the path is a URI, it downloads the file and caches it at a
|
|
41
41
|
* unique path to avoid this step in future calls. It then reads all the files
|
|
42
42
|
* from the bundle into memory, skipping any files that fall outside of the
|
|
43
|
-
* start path specified in the ui.startPath property of the playbook.
|
|
43
|
+
* start path specified in the ui.startPath property of the playbook. Finally,
|
|
44
44
|
* it classifies the files and adds them to a UiCatalog, which is then
|
|
45
45
|
* returned.
|
|
46
46
|
*
|
|
@@ -103,7 +103,7 @@ async function loadUi (playbook) {
|
|
|
103
103
|
resolveBundle.then((bundleFile) =>
|
|
104
104
|
new Promise((resolve, reject) =>
|
|
105
105
|
bundleFile.isDirectory()
|
|
106
|
-
? srcFs(bundleFile.path).then(resolve, reject)
|
|
106
|
+
? srcFs(ospath.join(bundleFile.path, bundle.startPath || '', '.')).then(resolve, reject)
|
|
107
107
|
: vzip
|
|
108
108
|
.src(bundleFile.path)
|
|
109
109
|
.on('error', (err) => reject(Object.assign(err, { message: `not a valid zip file; ${err.message}` })))
|
|
@@ -186,12 +186,12 @@ function downloadBundle (url, to, agent) {
|
|
|
186
186
|
.on('error', (err) =>
|
|
187
187
|
reject(Object.assign(err, { message: `not a valid zip file; ${err.message}`, summary: 'Invalid UI bundle' }))
|
|
188
188
|
)
|
|
189
|
-
.on('finish',
|
|
189
|
+
.on('finish', () =>
|
|
190
190
|
fsp
|
|
191
191
|
.mkdir(ospath.dirname(to), { recursive: true })
|
|
192
192
|
.then(() => fsp.writeFile(to, contents))
|
|
193
193
|
.then(() => resolve(new File({ path: to, stat: { isDirectory: () => false } })))
|
|
194
|
-
|
|
194
|
+
)
|
|
195
195
|
})
|
|
196
196
|
}).catch((err) => {
|
|
197
197
|
const wrapped = new Error(`${err.summary || 'Failed to download UI bundle'}: ${url}`)
|
|
@@ -234,25 +234,25 @@ function bufferizeContents () {
|
|
|
234
234
|
return map((file, _, next) => {
|
|
235
235
|
// NOTE gulp-vinyl-zip automatically converts the contents of an empty file to a Buffer
|
|
236
236
|
if (file.isStream()) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
file.contents
|
|
240
|
-
|
|
241
|
-
|
|
237
|
+
const buffer = []
|
|
238
|
+
pipeline(
|
|
239
|
+
file.contents,
|
|
240
|
+
forEach((chunk, _, done) => buffer.push(chunk) && done()),
|
|
241
|
+
(err) => (err ? next(err) : next(null, Object.assign(file, { contents: Buffer.concat(buffer) })))
|
|
242
|
+
)
|
|
242
243
|
} else {
|
|
243
244
|
next(null, file)
|
|
244
245
|
}
|
|
245
246
|
})
|
|
246
247
|
}
|
|
247
248
|
|
|
248
|
-
function collectFiles (
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
(file, _, next) => {
|
|
249
|
+
function collectFiles (resolve, files = new Map()) {
|
|
250
|
+
return forEach(
|
|
251
|
+
(file, _, done) => {
|
|
252
252
|
files.set(file.path, file)
|
|
253
|
-
|
|
253
|
+
done()
|
|
254
254
|
},
|
|
255
|
-
() => done(files)
|
|
255
|
+
(done) => done() || resolve(files)
|
|
256
256
|
)
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -283,13 +283,13 @@ function srcSupplementalFiles (filesSpec, startDir) {
|
|
|
283
283
|
).then((files) => files.reduce((accum, file) => accum.set(file.path, file) && accum, new Map()))
|
|
284
284
|
} else {
|
|
285
285
|
const cwd = expandPath(filesSpec, { dot: startDir })
|
|
286
|
-
return fsp
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
.catch((err) => {
|
|
286
|
+
return fsp.access(cwd).then(
|
|
287
|
+
() => srcFs(cwd),
|
|
288
|
+
(err) => {
|
|
290
289
|
// Q: should we skip unreadable files?
|
|
291
290
|
throw Object.assign(err, { message: `problem encountered while reading ui.supplemental_files: ${err.message}` })
|
|
292
|
-
}
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
|
|
@@ -340,23 +340,25 @@ function resolveOut (file, outputDir = '_') {
|
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
function srcFs (cwd) {
|
|
343
|
-
|
|
343
|
+
const relpathStart = cwd.length + 1
|
|
344
|
+
return new Promise((resolve, reject, cache = Object.create(null), files = new Map()) =>
|
|
344
345
|
pipeline(
|
|
345
346
|
globStream(UI_SRC_GLOB, Object.assign({ cache, cwd }, UI_SRC_OPTS)),
|
|
346
|
-
|
|
347
|
+
forEach(({ path: abspathPosix }, _, done) => {
|
|
348
|
+
if (Array.isArray(cache[abspathPosix])) return done() // detects some directories, but not all
|
|
347
349
|
const abspath = posixify ? ospath.normalize(abspathPosix) : abspathPosix
|
|
348
|
-
const relpath = abspath.substr(
|
|
350
|
+
const relpath = abspath.substr(relpathStart)
|
|
349
351
|
symlinkAwareStat(abspath).then(
|
|
350
352
|
(stat) => {
|
|
351
|
-
if (stat.isDirectory()) return
|
|
353
|
+
if (stat.isDirectory()) return done() // detects remaining directories
|
|
352
354
|
fsp.readFile(abspath).then(
|
|
353
355
|
(contents) => {
|
|
354
356
|
const path_ = posixify ? posixify(relpath) : relpath
|
|
355
357
|
files.set(path_, new File({ cwd, path: path_, contents, stat, local: true }))
|
|
356
|
-
|
|
358
|
+
done()
|
|
357
359
|
},
|
|
358
360
|
(readErr) => {
|
|
359
|
-
|
|
361
|
+
done(Object.assign(readErr, { message: readErr.message.replace(`'${abspath}'`, relpath) }))
|
|
360
362
|
}
|
|
361
363
|
)
|
|
362
364
|
},
|
|
@@ -369,7 +371,7 @@ function srcFs (cwd) {
|
|
|
369
371
|
} else {
|
|
370
372
|
statErr.message = statErr.message.replace(`'${abspath}'`, relpath)
|
|
371
373
|
}
|
|
372
|
-
|
|
374
|
+
done(statErr)
|
|
373
375
|
}
|
|
374
376
|
)
|
|
375
377
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/ui-loader",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
4
4
|
"description": "Downloads a UI bundle, if necessary, and loads the files into a UI catalog for use in an Antora documentation pipeline.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|
|
@@ -16,17 +16,20 @@
|
|
|
16
16
|
"url": "https://gitlab.com/antora/antora/issues"
|
|
17
17
|
},
|
|
18
18
|
"main": "lib/index.js",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "_mocha"
|
|
21
|
+
},
|
|
19
22
|
"dependencies": {
|
|
20
23
|
"@antora/expand-path-helper": "~2.0",
|
|
21
24
|
"braces": "~3.0",
|
|
22
25
|
"cache-directory": "~2.0",
|
|
23
26
|
"camelcase-keys": "~7.0",
|
|
27
|
+
"glob-stream": "~7.0",
|
|
24
28
|
"gulp-vinyl-zip": "~2.5",
|
|
25
29
|
"hpagent": "~0.1.0",
|
|
26
30
|
"js-yaml": "~4.1",
|
|
27
31
|
"picomatch": "~2.3",
|
|
28
32
|
"should-proxy": "~1.0",
|
|
29
|
-
"simple-concat": "~1.0",
|
|
30
33
|
"simple-get": "~4.0",
|
|
31
34
|
"vinyl": "~2.2"
|
|
32
35
|
},
|
|
@@ -45,5 +48,5 @@
|
|
|
45
48
|
"static site",
|
|
46
49
|
"web publishing"
|
|
47
50
|
],
|
|
48
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "044371a33e2c0fed9724d30945bbb549d64845d5"
|
|
49
52
|
}
|