Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antora/ui-loader

Package Overview
Dependencies
Maintainers
2
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antora/ui-loader - npm Package Compare versions

Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2

lib/file.js

2

lib/constants.js

@@ -0,1 +1,3 @@

'use strict'
module.exports = Object.freeze({

@@ -2,0 +4,0 @@ UI_CACHE_PATH: '.antora-cache/ui',

117

lib/load-ui.js
'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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc