UNPKG

1.34 kBtext/coffeescriptView Raw
1'use strict'
2
3async = require 'async'
4Semver = require './Bumped.semver'
5Config = require './Bumped.config'
6Logger = require './Bumped.logger'
7Plugin = require './Bumped.plugin'
8DEFAULT = require './Bumped.default'
9MSG = require './Bumped.messages'
10
11module.exports = class Bumped
12
13 constructor: (opts = {}) ->
14 process.chdir opts.cwd if opts.cwd
15 @pkg = require '../package.json'
16 @config = new Config this
17 @semver = new Semver this
18 @logger = new Logger opts.logger
19 @plugin = new Plugin this
20
21 this
22
23 ###*
24 * Load a previously cofinguration file declared.
25 ###
26 load: ->
27 [opts, cb] = DEFAULT.args arguments
28
29 return cb() unless @config.rc.config
30
31 tasks = [
32 (next) => @config.load opts, next
33 (next) => @semver.sync opts, next
34 ]
35
36 async.series tasks, cb
37
38 ###*
39 * Initialize a new configuration file in the current path.
40 ###
41 init: =>
42 [opts, cb] = DEFAULT.args arguments
43
44 tasks = [
45 (next) => @config.autodetect opts, next
46 (next) => @config.save opts, next
47 (next) => @semver.sync opts, next
48 ]
49
50 async.waterfall tasks, (err, result) =>
51 return @logger.errorHandler err, cb if err
52 @end opts, cb
53
54 end: ->
55 [opts, cb] = DEFAULT.args arguments
56
57 @semver.version opts, =>
58 @logger.success MSG.CONFIG_CREATED()
59 cb()