diff --git a/bin/cli.js b/bin/cli.js index e5284f22..e4847ad5 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -2,44 +2,6 @@ "use strict"; -const chalk = require("chalk"); -const Changelog = require("../").Changelog; -const ConfigurationError = require("../").ConfigurationError; +var cli = require("../lib/cli"); -const argv = require("yargs") - .usage("Usage: lerna-changelog [options]") - .options({ - "tag-from": { - type: "string", - desc: "A git tag that determines the lower bound of the range of commits (defaults to last available)" - }, - "tag-to": { - type: "string", - desc: "A git tag that determines the upper bound of the range of commits" - } - }) - .example( - "lerna-changelog", - "create a changelog for the changes after the latest available tag" - ) - .example( - "lerna-changelog --tag-from 0.1.0 --tag-to 0.3.0", - "create a changelog for the changes in all tags within the given range" - ) - .version() - .help() - .argv; - -try { - (new Changelog(argv)).createMarkdown().then((result) => { - console.log(result); - }).catch((e) => { - console.log(chalk.red(e.stack)); - }); -} catch (e) { - if (e instanceof ConfigurationError) { - console.log(chalk.red(e.message)); - } else { - throw (e); - } -} +cli.run(); diff --git a/src/cli.ts b/src/cli.ts new file mode 100644 index 00000000..e306a14e --- /dev/null +++ b/src/cli.ts @@ -0,0 +1,42 @@ +const chalk = require("chalk"); + +import Changelog from "./changelog"; +import ConfigurationError from "./configuration-error"; + +export async function run() { + const argv = require("yargs") + .usage("Usage: lerna-changelog [options]") + .options({ + "tag-from": { + type: "string", + desc: "A git tag that determines the lower bound of the range of commits (defaults to last available)" + }, + "tag-to": { + type: "string", + desc: "A git tag that determines the upper bound of the range of commits" + } + }) + .example( + "lerna-changelog", + "create a changelog for the changes after the latest available tag" + ) + .example( + "lerna-changelog --tag-from 0.1.0 --tag-to 0.3.0", + "create a changelog for the changes in all tags within the given range" + ) + .version() + .help() + .argv; + + try { + let result = await (new Changelog(argv)).createMarkdown(); + console.log(result); + + } catch (e) { + if (e instanceof ConfigurationError) { + console.log(chalk.red(e.message)); + } else { + console.log(chalk.red(e.stack)); + } + } +}