1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var chg = require('./chg.js');
|
11 | var prompt = require('prompt');
|
12 | var fs = require('fs');
|
13 |
|
14 | var commands = module.exports = {};
|
15 |
|
16 | commands.init = function(options, callback){
|
17 | chg.init(options, callback);
|
18 | };
|
19 |
|
20 | commands.add = function(line, options, callback){
|
21 | if (line) {
|
22 | chg.add(line, options, callback);
|
23 | } else {
|
24 | textPrompt('Add one line to the changelog', {}, function(err, text){
|
25 | if (err) { return callback(err); }
|
26 | chg.add(text, {}, callback);
|
27 | });
|
28 | }
|
29 | };
|
30 |
|
31 | commands.release = function(version, options, callback){
|
32 | options = options || {};
|
33 |
|
34 | if (version) {
|
35 | chg.release(version, options, callback);
|
36 | } else {
|
37 |
|
38 | if (fs.existsSync('./package.json')) {
|
39 | options.default = require(process.cwd() + '/package.json').version;
|
40 | }
|
41 |
|
42 | textPrompt('What is the release version number?', options, function(err, text){
|
43 | if (err) { return callback(err); }
|
44 | chg.release(text, options, callback);
|
45 | });
|
46 | }
|
47 | };
|
48 |
|
49 | commands.delete = function(options, callback){
|
50 | prompt.start();
|
51 | prompt.get({
|
52 | name: 'yesno',
|
53 | message: 'Are you sure you want to delete the changelog?',
|
54 | validator: /y[es]*|n[o]?/,
|
55 | warning: 'Must respond yes or no',
|
56 | default: 'yes'
|
57 | }, function (err) {
|
58 | if (err) { return callback(err); }
|
59 | chg.delete(options, callback);
|
60 | });
|
61 | };
|
62 |
|
63 | function textPrompt(message, options, callback){
|
64 | if (!options) {
|
65 | callback = options;
|
66 | options = {};
|
67 | }
|
68 |
|
69 | options.name = 'text';
|
70 | options.message = message;
|
71 | options.required = true;
|
72 |
|
73 | prompt.start();
|
74 | prompt.get(options, function (err, result) {
|
75 | if (err) {
|
76 | return callback(err);
|
77 | }
|
78 | callback(null, result.text);
|
79 | });
|
80 | } |
\ | No newline at end of file |