UNPKG

2.13 kBPlain TextView Raw
1#!/usr/bin/env node
2'use strict';
3
4var pkg = require('../package.json');
5var commands = require('../lib/commands.js');
6
7var program = require('commander');
8var prompt = require('prompt');
9
10program.version(pkg.version);
11
12program
13 .command('init')
14 .description('Create the CHANGELOG.md in the current directory')
15 .action(function(args){
16 commands.init({}, function(err, changeLogFile) {
17 if (err) return console.error(err.message);
18
19 console.log(changeLogFile +' created');
20 });
21 });
22
23program
24 .command('add [line]')
25 .description('Add one line to the changelog')
26 .action(function(line, info){
27 commands.add(line, {}, function(err, line) {
28 if (err) return console.error(err.message);
29
30 console.log('Change added: '+ line);
31 });
32 });
33
34program
35 .command('release [version]')
36 .description('Move unreleased changes under a new release heading')
37 .option('-d, --date [date]', 'Specify a date (defaults to today)')
38 .option('-y, --yes', 'Use defaults, do not prompt you for options')
39 .action(function(version, info){
40 var options = {};
41
42 if (info.date) {
43 options.date = info.date;
44 }
45
46 if (info.yes) {
47 options.noprompt = true;
48 }
49
50 commands.release(version, options, function(err, changes) {
51 if (err) return console.error(err.message);
52
53 console.log('Changelog updated with new release: '+ changes.title);
54 });
55 });
56
57program
58 .command('find [version]')
59 .description('Find a specific release by version number')
60 .action(function(version) {
61 commands.find(version, options, function(err, release) {
62 if (err) return console.error(err.message);
63
64 console.log('Title: '+ release.title);
65 console.log('Changes: '+ release.changesRaw);
66 });
67 });
68
69program
70 .command('delete')
71 .description('Delete the changelog')
72 .action(function(info){
73 commands.delete({}, function(err, changeLogFile) {
74 if (err) return console.error(err.message);
75
76 console.log(changeLogFile +' deleted.');
77 });
78 });
79
80program.parse(process.argv);
81
82// default to help if no commands
83if (program.args.length === 0) {
84 program.help();
85}