UNPKG

2.68 kBtext/coffeescriptView Raw
1###
2Copyright (c) 2014, Sean Massa
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
9Redistributions of source code must retain the above copyright notice,
10this list of conditions and the following disclaimer.
11
12Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
16Neither the name of GROUPON nor the names of its contributors may be
17used to endorse or promote products derived from this software without
18specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31###
32
33log = require './log'
34npub = require './index'
35minimist = require 'minimist'
36semver = require 'semver'
37
38clone = (obj) ->
39 JSON.parse(JSON.stringify(obj || {}))
40
41publishVersion = (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
58cli = (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
78argv = minimist process.argv.slice(2)
79directory = process.cwd()
80
81packageJson = require("#{directory}/package.json")
82cli(argv, directory, packageJson)
83