@antora/ui-loader
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2
@@ -0,1 +1,3 @@ | ||
'use strict' | ||
module.exports = Object.freeze({ | ||
@@ -2,0 +4,0 @@ UI_CACHE_PATH: '.antora-cache/ui', |
'use strict' | ||
const buffer = require('gulp-buffer') | ||
const collect = require('stream-to-array') | ||
const collectBuffer = require('bl') | ||
const crypto = require('crypto') | ||
const download = require('download') | ||
const File = require('./file') | ||
const fs = require('fs-extra') | ||
const map = require('through2').obj | ||
const got = require('got') | ||
const { obj: map } = require('through2') | ||
const minimatchAll = require('minimatch-all') | ||
const path = require('path') | ||
const ospath = require('path') | ||
const path = ospath.posix | ||
const posixify = ospath.sep === '\\' ? (p) => p.replace(/\\/g, '/') : undefined | ||
const UiCatalog = require('./ui-catalog') | ||
const yaml = require('js-yaml') | ||
const zip = require('gulp-vinyl-zip') | ||
const vzip = require('gulp-vinyl-zip') | ||
@@ -42,20 +44,38 @@ const { UI_CACHE_PATH, UI_CONFIG_FILENAME } = require('./constants') | ||
async function loadUi (playbook) { | ||
const { bundle, startPath, outputDir } = playbook.ui | ||
let bundlePath | ||
if (isUrl(bundle)) { | ||
bundlePath = getCachePath(sha1(bundle) + '.zip') | ||
if (!fs.pathExistsSync(bundlePath)) { | ||
fs.ensureDirSync(path.dirname(bundlePath)) | ||
fs.writeFileSync(bundlePath, await download(bundle)) | ||
} | ||
const { bundle: bundleUri, startPath, outputDir } = playbook.ui | ||
let resolveBundle | ||
if (isUrl(bundleUri)) { | ||
// TODO add support for a forced update flag | ||
const cachePath = getCachePath(sha1(bundleUri) + '.zip') | ||
resolveBundle = fs.pathExists(cachePath).then((exists) => { | ||
if (exists) { | ||
return cachePath | ||
} else { | ||
return got(bundleUri, { encoding: null }).then(({ body }) => | ||
fs.outputFile(cachePath, body).then(() => cachePath) | ||
) | ||
} | ||
}) | ||
} else { | ||
bundlePath = path.resolve(bundle) | ||
const localPath = ospath.resolve(bundleUri) | ||
resolveBundle = fs.pathExists(localPath).then((exists) => { | ||
if (exists) { | ||
return localPath | ||
} else { | ||
throw new Error('Specified UI bundle does not exist: ' + bundleUri) | ||
} | ||
}) | ||
} | ||
const files = await collect( | ||
zip | ||
const bundlePath = await resolveBundle | ||
const files = await new Promise((resolve, reject) => { | ||
vzip | ||
.src(bundlePath) | ||
.on('error', reject) | ||
.pipe(selectFilesStartingFrom(startPath)) | ||
.pipe(buffer()) | ||
) | ||
.pipe(bufferizeContents()) | ||
.on('error', reject) | ||
.pipe(collectFiles(resolve)) | ||
}) | ||
@@ -81,3 +101,3 @@ const config = loadConfig(files, outputDir) | ||
function getCachePath (relative) { | ||
return path.resolve(UI_CACHE_PATH, relative) | ||
return ospath.resolve(UI_CACHE_PATH, relative) | ||
} | ||
@@ -87,16 +107,26 @@ | ||
if (!startPath || (startPath = path.join('/', startPath + '/')) === '/') { | ||
return map((file, encoding, next) => (file.isNull() ? next() : next(null, file))) | ||
return map((file, _, next) => { | ||
if (file.isNull()) { | ||
next() | ||
} else { | ||
next( | ||
null, | ||
new File({ path: posixify ? posixify(file.path) : file.path, contents: file.contents, stat: file.stat }) | ||
) | ||
} | ||
}) | ||
} else { | ||
startPath = startPath.substr(1) | ||
const startPathOffset = startPath.length | ||
return map((file, encoding, next) => { | ||
if (!file.isNull()) { | ||
const filePath = file.path | ||
if (filePath.length > startPathOffset && filePath.startsWith(startPath)) { | ||
file.path = filePath.substr(startPathOffset) | ||
next(null, file) | ||
return | ||
return map((file, _, next) => { | ||
if (file.isNull()) { | ||
next() | ||
} else { | ||
const path_ = posixify ? posixify(file.path) : file.path | ||
if (path_.length > startPathOffset && path_.startsWith(startPath)) { | ||
next(null, new File({ path: path_.substr(startPathOffset), contents: file.contents, stat: file.stat })) | ||
} else { | ||
next() | ||
} | ||
} | ||
next() | ||
}) | ||
@@ -106,5 +136,27 @@ } | ||
function bufferizeContents () { | ||
return map((file, _, next) => { | ||
// NOTE gulp-vinyl-zip automatically converts the contents of an empty file to a Buffer | ||
if (file.isStream()) { | ||
file.contents.pipe( | ||
collectBuffer((err, data) => { | ||
if (err) return next(err) | ||
file.contents = data | ||
next(null, file) | ||
}) | ||
) | ||
} else { | ||
next(null, file) | ||
} | ||
}) | ||
} | ||
function collectFiles (done) { | ||
const accum = [] | ||
return map((file, _, next) => accum.push(file) && next(), () => done(accum)) | ||
} | ||
function loadConfig (files, outputDir) { | ||
const configFileIdx = files.findIndex((file) => file.path === UI_CONFIG_FILENAME) | ||
if (configFileIdx !== -1) { | ||
if (~configFileIdx) { | ||
const configFile = files[configFileIdx] | ||
@@ -129,7 +181,2 @@ files.splice(configFileIdx, 1) | ||
function classifyFile (file, config) { | ||
Object.defineProperty(file, 'relative', { | ||
get: function () { | ||
return this.path | ||
}, | ||
}) | ||
if (config.staticFiles && isStaticFile(file, config.staticFiles)) { | ||
@@ -136,0 +183,0 @@ file.type = 'static' |
{ | ||
"name": "@antora/ui-loader", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-alpha.2", | ||
"description": "Downloads a UI bundle, if necessary, and loads the files into a UI catalog for use in an Antora documentation pipeline.", | ||
"license": "MPL-2.0", | ||
"author": { | ||
"name": "OpenDevise Inc.", | ||
"url": "https://opendevise.com" | ||
}, | ||
"author": "OpenDevise Inc. (https://opendevise.com)", | ||
"contributors": [ | ||
"Dan Allen <dan@opendevise.com>", | ||
"Sarah White <sarah@opendevise.com>", | ||
"Hubert SABLONNIÈRE <hubert.sablonniere@gmail.com>" | ||
], | ||
"homepage": "https://antora.org", | ||
@@ -17,5 +19,5 @@ "repository": "gitlab:antora/antora", | ||
"dependencies": { | ||
"download": "^6.2.5", | ||
"bl": "^1.2.1", | ||
"fs-extra": "^5.0.0", | ||
"gulp-buffer": "^0.0.2", | ||
"got": "^8.0.3", | ||
"gulp-vinyl-zip": "^2.1.0", | ||
@@ -25,4 +27,4 @@ "js-yaml": "^3.10.0", | ||
"minimatch-all": "^1.1.0", | ||
"stream-to-array": "^2.3.0", | ||
"through2": "^2.0.3" | ||
"through2": "^2.0.3", | ||
"vinyl": "^2.1.0" | ||
}, | ||
@@ -29,0 +31,0 @@ "engines": { |
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
9680
7
249
13
+ Addedbl@^1.2.1
+ Addedgot@^8.0.3
+ Addedvinyl@^2.1.0
+ Added@sindresorhus/is@0.7.0(transitive)
+ Addedcacheable-request@2.1.4(transitive)
+ Addedclone-response@1.0.2(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addedfrom2@2.3.0(transitive)
+ Addedgot@8.3.2(transitive)
+ Addedhttp-cache-semantics@3.8.1(transitive)
+ Addedinto-stream@3.1.0(transitive)
+ Addedjson-buffer@3.0.0(transitive)
+ Addedkeyv@3.0.0(transitive)
+ Addedlowercase-keys@1.0.0(transitive)
+ Addednormalize-url@2.0.1(transitive)
+ Addedp-cancelable@0.4.1(transitive)
+ Addedp-is-promise@1.1.0(transitive)
+ Addedp-timeout@2.0.1(transitive)
+ Addedprepend-http@2.0.0(transitive)
+ Addedquery-string@5.1.1(transitive)
+ Addedresponselike@1.0.2(transitive)
+ Addedsort-keys@2.0.0(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)
+ Addedurl-parse-lax@3.0.0(transitive)
- Removeddownload@^6.2.5
- Removedgulp-buffer@^0.0.2
- Removedstream-to-array@^2.3.0
- Removedany-promise@1.3.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedbuffer-alloc@1.2.0(transitive)
- Removedbuffer-alloc-unsafe@1.1.0(transitive)
- Removedbuffer-fill@1.0.0(transitive)
- Removedcaw@2.0.1(transitive)
- Removedcommander@2.20.3(transitive)
- Removedconfig-chain@1.1.13(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removeddecompress@4.2.1(transitive)
- Removeddecompress-tar@4.1.1(transitive)
- Removeddecompress-tarbz2@4.1.1(transitive)
- Removeddecompress-targz@4.1.1(transitive)
- Removeddecompress-unzip@4.0.1(transitive)
- Removeddownload@6.2.5(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedext-list@2.2.2(transitive)
- Removedext-name@5.0.0(transitive)
- Removedfile-type@3.9.05.2.06.2.0(transitive)
- Removedfilename-reserved-regex@2.0.0(transitive)
- Removedfilenamify@2.1.0(transitive)
- Removedfs-constants@1.0.0(transitive)
- Removedget-proxy@2.1.0(transitive)
- Removedget-stream@2.3.1(transitive)
- Removedgot@7.1.0(transitive)
- Removedgulp-buffer@0.0.2(transitive)
- Removedieee754@1.2.1(transitive)
- Removedini@1.3.8(transitive)
- Removedis-natural-number@4.0.1(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmake-dir@1.3.0(transitive)
- Removedmime-db@1.53.0(transitive)
- Removednpm-conf@1.1.3(transitive)
- Removedobject-keys@0.4.0(transitive)
- Removedp-cancelable@0.3.0(transitive)
- Removedp-event@1.3.0(transitive)
- Removedp-timeout@1.2.1(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedproto-list@1.2.4(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedseek-bzip@1.0.6(transitive)
- Removedsort-keys@1.1.2(transitive)
- Removedsort-keys-length@1.0.1(transitive)
- Removedstream-to-array@2.3.0(transitive)
- Removedstring_decoder@0.10.311.3.0(transitive)
- Removedstrip-dirs@2.1.0(transitive)
- Removedstrip-outer@1.0.1(transitive)
- Removedtar-stream@1.6.2(transitive)
- Removedthrough2@0.4.2(transitive)
- Removedto-buffer@1.1.1(transitive)
- Removedtrim-repeated@1.0.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedunbzip2-stream@1.4.3(transitive)
- Removedurl-parse-lax@1.0.0(transitive)
- Removedxtend@2.1.2(transitive)