Add getVersion function to exports for easy access by tooling (ex: CLI).

This commit is contained in:
David Anson 2020-10-17 14:17:35 -07:00
parent bd50a15a96
commit a971361cf2
4 changed files with 28 additions and 1 deletions

View file

@ -5,6 +5,9 @@ import markdownlint from "../..";
const assert = require("assert");
const markdownlintJsonPath = "../../.markdownlint.json";
const version: string = markdownlint.getVersion();
assert(/^\d+\.\d+\.\d+$/.test(version));
function assertConfiguration(config: markdownlint.Configuration) {
assert(!!config);
assert.equal(config["line-length"], false);

View file

@ -8,7 +8,7 @@ export = markdownlint;
*/
declare function markdownlint(options: Options, callback: LintCallback): void;
declare namespace markdownlint {
export { markdownlintSync as sync, readConfig, readConfigSync, promises, RuleFunction, RuleParams, MarkdownItToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintCallback, Configuration, RuleConfiguration, ConfigurationParser, ReadConfigCallback };
export { markdownlintSync as sync, readConfig, readConfigSync, getVersion, promises, RuleFunction, RuleParams, MarkdownItToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintCallback, Configuration, RuleConfiguration, ConfigurationParser, ReadConfigCallback };
}
/**
* Configuration options.
@ -82,6 +82,12 @@ declare function readConfig(file: string, parsers: ConfigurationParser[] | ReadC
* @returns {Configuration} Configuration object.
*/
declare function readConfigSync(file: string, parsers?: ConfigurationParser[]): Configuration;
/**
* Gets the (semantic) version of the library.
*
* @returns {string} SemVer string.
*/
declare function getVersion(): string;
declare namespace promises {
export { markdownlintPromise as markdownlint };
export { readConfigPromise as readConfig };

View file

@ -985,10 +985,20 @@ function readConfigSync(file, parsers) {
return config;
}
/**
* Gets the (semantic) version of the library.
*
* @returns {string} SemVer string.
*/
function getVersion() {
return require("../package.json").version;
}
// Export a/synchronous/Promise APIs
markdownlint.sync = markdownlintSync;
markdownlint.readConfig = readConfig;
markdownlint.readConfigSync = readConfigSync;
markdownlint.getVersion = getVersion;
markdownlint.promises = {
"markdownlint": markdownlintPromise,
"readConfig": readConfigPromise

View file

@ -1443,3 +1443,11 @@ $$\n`
test.end();
});
});
tape("getVersion", (test) => {
test.plan(1);
const actual = markdownlint.getVersion();
const expected = packageJson.version;
test.equal(actual, expected, "Version string not correct.");
test.end();
});