@antora/content-classifier
Advanced tools
Comparing version 1.0.0-rc.1 to 1.0.0-rc.2
@@ -23,3 +23,3 @@ 'use strict' | ||
(catalog, { name: component, version, title, start_page: startPage, nav, files }) => { | ||
files.forEach((file) => apportionSrc(file, component, version, nav) && catalog.addFile(file)) | ||
files.forEach((file) => allocateSrc(file, component, version, nav) && catalog.addFile(file)) | ||
catalog.addComponentVersion(component, version, title, startPage) | ||
@@ -34,4 +34,3 @@ return catalog | ||
// classifySrc? bisectSrc? subdivideSrc? partitionSrc? | ||
function apportionSrc (file, component, version, nav) { | ||
function allocateSrc (file, component, version, nav) { | ||
const filepath = file.path | ||
@@ -59,3 +58,3 @@ const pathSegments = filepath.split('/') | ||
file.src.relative = pathSegments.slice(4).join('/') | ||
} else if (file.src.mediaType === 'text/asciidoc' && file.src.basename !== '_attributes.adoc') { | ||
} else if (file.src.mediaType === 'text/asciidoc') { | ||
file.src.family = 'page' | ||
@@ -62,0 +61,0 @@ // relative to modules/<module>/pages |
@@ -41,6 +41,7 @@ 'use strict' | ||
const versions = component.versions | ||
const insertIdx = versions.findIndex((candidate) => { | ||
const verdict = versionCompare(candidate.version, version) | ||
if (verdict === 0) throw new Error(`Duplicate version detected for component ${name}: ${version}`) | ||
return verdict > 0 | ||
const insertIdx = versions.findIndex(({ version: candidateVersion }) => { | ||
if (candidateVersion === version) { | ||
throw new Error(`Duplicate version detected for component ${name}: ${version}`) | ||
} | ||
return versionCompare(candidateVersion, version) > 0 | ||
}) | ||
@@ -73,18 +74,18 @@ const versionEntry = { title, version, url } | ||
const id = this[$generateId](_.pick(file.src, 'component', 'version', 'module', 'family', 'relative')) | ||
if (id in this[$files]) throw new Error(`Duplicate ${file.src.family}: ${id.substr(id.indexOf('/') + 1)}`) | ||
if (this[$files][id]) throw new Error(`Duplicate ${file.src.family}: ${id.substr(id.indexOf('/') + 1)}`) | ||
if (!File.isVinyl(file)) file = new File(file) | ||
const family = file.src.family | ||
const actingFamily = family === 'alias' ? file.rel.src.family : family | ||
if (!('out' in file) && (actingFamily === 'page' || actingFamily === 'image' || actingFamily === 'attachment')) { | ||
let publishable | ||
if (file.out) { | ||
publishable = true | ||
} else if ( | ||
(actingFamily === 'page' || actingFamily === 'image' || actingFamily === 'attachment') && | ||
!~('/' + file.src.relative).indexOf('/_') | ||
) { | ||
publishable = true | ||
file.out = computeOut(file.src, actingFamily, this.htmlUrlExtensionStyle) | ||
} | ||
if ( | ||
!('pub' in file) && | ||
(actingFamily === 'page' || | ||
actingFamily === 'image' || | ||
actingFamily === 'attachment' || | ||
actingFamily === 'navigation') | ||
) { | ||
if (!file.pub && (publishable || actingFamily === 'navigation')) { | ||
file.pub = computePub(file.src, file.out, actingFamily, this.htmlUrlExtensionStyle) | ||
//if (family === 'alias' && this.urlRedirectFacility !== 'static') delete file.out | ||
} | ||
@@ -91,0 +92,0 @@ this[$files][id] = file |
'use strict' | ||
const semverCompare = require('semver-compare') | ||
/** | ||
* A modified semantic version comparison function. | ||
* | ||
* Based on a semantic version comparison algorithm with the following | ||
* enhancements: | ||
* Based on a semantic version comparison algorithm with the following enhancements: | ||
* | ||
* * Drops the leading "v" character, if present. | ||
* * Promotes the string "master" to the highest version. | ||
* * Compares in descending order (e.g., 2.0.0 comes before 1.0.0). | ||
* * Drops the leading "v" character from a semantic version, if present. | ||
* * Compares semantic versions in descending order (e.g., 2.0.0 comes before 1.0.0). | ||
* * Bubbles non-semantic versions to the top (e.g., dev, master). | ||
* * Compares non-semantic versions as strings. | ||
* | ||
* This function assumes the string is a semantic version if it contains a "." character. | ||
* | ||
* @param {String} a - The left version string. | ||
@@ -21,7 +21,50 @@ * @param {String} b - The right version string. | ||
if (a === b) return 0 | ||
if (a === 'master') return -1 | ||
if (b === 'master') return 1 | ||
return -1 * semverCompare(a.charAt() === 'v' ? a.substr(1) : a, b.charAt() === 'v' ? b.substr(1) : b) | ||
const semverA = a.charAt() === 'v' ? a.substr(1) : a | ||
const semverB = b.charAt() === 'v' ? b.substr(1) : b | ||
if (~a.indexOf('.') || isNumber(semverA)) { | ||
return ~b.indexOf('.') || isNumber(semverB) ? -1 * semverCompare(semverA, semverB) : 1 | ||
} else { | ||
return ~b.indexOf('.') || isNumber(semverB) ? -1 : -1 * a.localeCompare(b, 'en', { numeric: true }) | ||
} | ||
} | ||
function isNumber (str) { | ||
return !isNaN(Number(str)) | ||
} | ||
function semverCompare (a, b) { | ||
let preA | ||
let preB | ||
const preOffsetA = a.indexOf('-') | ||
const preOffsetB = b.indexOf('-') | ||
if (~preOffsetA) { | ||
preA = a.substr(preOffsetA + 1) | ||
a = a.substr(0, preOffsetA) | ||
} | ||
if (~preOffsetB) { | ||
preB = b.substr(preOffsetB + 1) | ||
b = b.substr(0, preOffsetB) | ||
} | ||
const numsA = a.split('.') | ||
const numsB = b.split('.') | ||
for (let i = 0; i < 3; i++) { | ||
const numA = numsA[i] ? Number(numsA[i]) : 0 | ||
const numB = numsB[i] ? Number(numsB[i]) : 0 | ||
if (numA > numB) { | ||
return 1 | ||
} else if (numB > numA) { | ||
return -1 | ||
} else if (isNaN(numA)) { | ||
if (!isNaN(numB)) return -1 | ||
} else if (isNaN(numB)) { | ||
return 1 | ||
} | ||
} | ||
if (preA == null) { | ||
return preB == null ? 0 : 1 | ||
} else { | ||
return preB == null ? -1 : preA.localeCompare(preB, 'en', { numeric: true }) | ||
} | ||
} | ||
module.exports = versionCompareDesc |
{ | ||
"name": "@antora/content-classifier", | ||
"version": "1.0.0-rc.1", | ||
"version": "1.0.0-rc.2", | ||
"description": "Organizes aggregated content into a virtual file catalog for use in an Antora documentation pipeline.", | ||
@@ -20,7 +20,6 @@ "license": "MPL-2.0", | ||
"lodash": "^4.17.5", | ||
"semver-compare": "^1.0.0", | ||
"vinyl": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"@antora/content-aggregator": "1.0.0-rc.1" | ||
"@antora/content-aggregator": "1.0.0-rc.2" | ||
}, | ||
@@ -27,0 +26,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
21472
2
513
- Removedsemver-compare@^1.0.0
- Removedsemver-compare@1.0.0(transitive)