1 | ###
|
2 | Copyright (c) 2014, Sean Massa
|
3 | All rights reserved.
|
4 |
|
5 | Redistribution and use in source and binary forms, with or without
|
6 | modification, are permitted provided that the following conditions
|
7 | are met:
|
8 |
|
9 | Redistributions of source code must retain the above copyright notice,
|
10 | this list of conditions and the following disclaimer.
|
11 |
|
12 | Redistributions in binary form must reproduce the above copyright
|
13 | notice, this list of conditions and the following disclaimer in the
|
14 | documentation and/or other materials provided with the distribution.
|
15 |
|
16 | Neither the name of GROUPON nor the names of its contributors may be
|
17 | used to endorse or promote products derived from this software without
|
18 | specific prior written permission.
|
19 |
|
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
22 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
23 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
26 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31 | ###
|
32 |
|
33 | log = require './log'
|
34 | npub = require './index'
|
35 | minimist = require 'minimist'
|
36 | semver = require 'semver'
|
37 |
|
38 | clone = (obj) ->
|
39 | JSON.parse(JSON.stringify(obj || {}))
|
40 |
|
41 | publishVersion = (str, currentVersion) ->
|
42 | if !str?
|
43 | log.error '<version> required for command: npub publish <version>'
|
44 | process.exit(2)
|
45 |
|
46 | version = switch str
|
47 | when "patch", "minor", "major"
|
48 | semver.inc(currentVersion, str)
|
49 | else
|
50 | semver.valid(str)
|
51 |
|
52 | if !version
|
53 | log.error "'#{version}' is invalid."
|
54 | process.exit(2)
|
55 |
|
56 | return version
|
57 |
|
58 | cli = (argv, directory, packageJson) ->
|
59 | command = argv._[0]
|
60 | config = clone(packageJson.publishConfig)
|
61 |
|
62 | switch command
|
63 | when 'prep'
|
64 | return npub.prep(directory, log, config)
|
65 |
|
66 | when 'publish'
|
67 | version = publishVersion(argv._[1], packageJson.version)
|
68 | testCommand = argv.t || argv.test
|
69 | return npub.publish(directory, log, config, version, testCommand)
|
70 |
|
71 | when 'verify'
|
72 | npub.verify directory, (err) ->
|
73 | process.exit(2) if err
|
74 |
|
75 | else
|
76 | log.error "invalid command: \"#{command}\""
|
77 |
|
78 | argv = minimist process.argv.slice(2)
|
79 | directory = process.cwd()
|
80 |
|
81 | packageJson = require("#{directory}/package.json")
|
82 | cli(argv, directory, packageJson)
|
83 |
|