Skip to content

Commit

Permalink
cli: Wrap script in run() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Jul 12, 2017
1 parent f9b1854 commit 6f729e7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
4 changes: 3 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

"use strict";

require("../lib/cli");
var cli = require("../lib/cli");

cli.run();
70 changes: 36 additions & 34 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,42 @@ const chalk = require("chalk");
import Changelog from "./changelog";
import ConfigurationError from "./configuration-error";

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;
export 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 {
(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);
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);
}
}
}

0 comments on commit 6f729e7

Please sign in to comment.