@jayree/changelog
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,1 @@ | ||
export default function printChangeLog(cacheDir: string, pluginRootPath: string): string | undefined; | ||
export default function printChangeLog(cacheDir: string, pluginRootPath: string): Promise<string | undefined>; |
@@ -30,3 +30,6 @@ /* | ||
versions.push(coercedVersion); | ||
if (compare(desiredVersion, coercedVersion) >= 0 && compare(coercedVersion, localVersion) === 1) { | ||
if ((!localVersion && compare(desiredVersion, coercedVersion) === 0) || | ||
(localVersion && | ||
compare(desiredVersion, coercedVersion) >= 0 && | ||
compare(coercedVersion, localVersion) === 1)) { | ||
found = true; | ||
@@ -47,40 +50,37 @@ return token; | ||
const closestVersion = semver.maxSatisfying(versions, semverRange); | ||
const warning = marked.lexer(`# ATTENTION: Version ${version} was not found. Showing notes for closest patch version ${closestVersion}.`)[0]; | ||
tokens.unshift(warning); | ||
if (closestVersion !== null) { | ||
findVersion(closestVersion, currentVersion); | ||
if (!tokens.length) | ||
findVersion(closestVersion); | ||
const warning = marked.lexer(`# ATTENTION: Version ${version} was not found. Showing notes for closest patch version ${closestVersion}.`)[0]; | ||
tokens.unshift(warning); | ||
version = closestVersion; | ||
} | ||
} | ||
return tokens; | ||
return { tokens, version }; | ||
}; | ||
export default function printChangeLog(cacheDir, pluginRootPath) { | ||
export default async function printChangeLog(cacheDir, pluginRootPath) { | ||
try { | ||
debug({ cacheDir, pluginRootPath }); | ||
const { name, version } = fs.readJsonSync(join(pluginRootPath, 'package.json')); | ||
const changelogFile = fs.readFileSync(join(pluginRootPath, 'CHANGELOG.md'), 'utf8'); | ||
const { name, version } = (await fs.readJson(join(pluginRootPath, 'package.json'))); | ||
const changelogFile = await fs.readFile(join(pluginRootPath, 'CHANGELOG.md'), 'utf8'); | ||
const versionDir = join(cacheDir, name); | ||
const versionFile = join(versionDir, 'version'); | ||
fs.ensureFileSync(versionFile); | ||
let latestVersion; | ||
await fs.ensureFile(versionFile); | ||
let localVersion; | ||
try { | ||
latestVersion = fs.readJSONSync(versionFile); | ||
localVersion = (await fs.readJSON(versionFile)); | ||
} | ||
catch (error) { | ||
latestVersion = { version: '0.0.0' }; | ||
localVersion = { version: '0.0.0' }; | ||
} | ||
debug({ latestVersion: latestVersion.version, version }); | ||
if (latestVersion.version !== version) { | ||
const tokens = parseChangeLog(changelogFile, version, latestVersion.version); | ||
if (!tokens.length) { | ||
debug(`${name} - didn't find version '${version}'.`); | ||
} | ||
else { | ||
marked.setOptions({ | ||
renderer: new TerminalRenderer({ emoji: false }), | ||
}); | ||
tokens.unshift(marked.lexer(`# Changelog for '${name}':`)[0]); | ||
fs.writeJsonSync(versionFile, { version }); | ||
return marked.parser(tokens); | ||
} | ||
debug({ pluginRootPath, cacheDir, localVersion: localVersion.version, version }); | ||
if (localVersion.version !== version) { | ||
const { tokens, version: parsedVersion } = parseChangeLog(changelogFile, version, localVersion.version); | ||
marked.setOptions({ | ||
renderer: new TerminalRenderer({ emoji: false }), | ||
}); | ||
tokens.unshift(marked.lexer(`# Changelog for '${name}':`)[0]); | ||
await fs.writeJson(versionFile, { version: parsedVersion }); | ||
return marked.parser(tokens); | ||
} | ||
else { | ||
debug(`${name} - no update`); | ||
} | ||
} | ||
@@ -87,0 +87,0 @@ catch (error) { |
{ | ||
"name": "@jayree/changelog", | ||
"version": "1.0.0", | ||
"description": "Parses a CHANGELOG.md file of a package and returns the most recent entry", | ||
"version": "1.0.1", | ||
"description": "Parse a CHANGELOG.md file of a package and return the most recent entry", | ||
"main": "lib/index.js", | ||
@@ -45,6 +45,6 @@ "author": "jayree <jayree.git@icloud.com>", | ||
], | ||
"homepage": "https://github.com/jayree/jayree-changelog", | ||
"homepage": "https://github.com/jayree/changelog", | ||
"keywords": [], | ||
"license": "BSD-3-Clause", | ||
"repository": "jayree/jayree-changelog", | ||
"repository": "jayree/changelog", | ||
"scripts": { | ||
@@ -51,0 +51,0 @@ "build": "wireit", |
@jayree/changelog | ||
=========================================== | ||
Parses a CHANGELOG.md file of a package and returns the most recent entry. | ||
Parse a CHANGELOG.md file of a package and return the most recent entry. | ||
@@ -6,0 +6,0 @@ ## Install |
Sorry, the diff of this file is not supported yet
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
11586