1 | 'use strict'
|
2 |
|
3 | path = require 'path'
|
4 | async = require 'async'
|
5 | omit = require 'lodash.omit'
|
6 | resolveUp = require 'resolve-up'
|
7 | globalNpmPath = require 'global-modules'
|
8 | updateNotifier = require 'update-notifier'
|
9 | clone = require 'lodash.clonedeep'
|
10 | MSG = require './Bumped.messages'
|
11 | Animation = require './Bumped.animation'
|
12 | isEmpty = require('./Bumped.util').isEmpty
|
13 | spawnSync = require('child_process').spawnSync
|
14 |
|
15 | npmInstallGlobal = (pkg) ->
|
16 | spawnSync 'npm', [ 'install', pkg ],
|
17 | stdio: 'inherit'
|
18 | cwd: globalNpmPath
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | module.exports = class Plugin
|
28 |
|
29 | constructor: (bumped) ->
|
30 | @bumped = bumped
|
31 | @prerelease = @bumped.config.rc.plugins.prerelease
|
32 | @postrelease = @bumped.config.rc.plugins.postrelease
|
33 | @cache = {}
|
34 |
|
35 | pluginPath: (plugin) ->
|
36 | pluginPath = resolveUp plugin
|
37 | return pluginPath[0] if pluginPath.length > 0
|
38 | @bumped.logger.warn MSG.INSTALLING_PLUGIN plugin
|
39 | @bumped.logger.warn MSG.INSTALLING_PLUGIN_2()
|
40 | npmInstallGlobal plugin
|
41 | path.resolve globalNpmPath, plugin
|
42 |
|
43 | buildOptions: (opts) ->
|
44 | opts: omit(opts, 'plugin')
|
45 | title: opts.plugin
|
46 | logger: @bumped.logger
|
47 | path: @pluginPath opts.plugin
|
48 |
|
49 | exec: (opts, cb) ->
|
50 | pluginType = @[opts.type]
|
51 | return cb null if isEmpty Object.keys pluginType
|
52 |
|
53 | async.forEachOfSeries pluginType, (settings, description, next) =>
|
54 | pluginOptions = @buildOptions settings
|
55 |
|
56 | if @cache[settings.plugin]
|
57 | plugin = @cache[settings.plugin]
|
58 | else
|
59 | plugin = @cache[settings.plugin] = require pluginOptions.path
|
60 | @notifyPlugin pluginOptions.path
|
61 |
|
62 | animation = new Animation
|
63 | text : description
|
64 | logger : @bumped.logger
|
65 | plugin : settings.plugin
|
66 | type : opts.type
|
67 |
|
68 | animation.start =>
|
69 | plugin @bumped, pluginOptions, (err) ->
|
70 | animation.stop err, next
|
71 | , cb
|
72 |
|
73 | notifyPlugin: (pluginPath) ->
|
74 | pkgPath = path.join pluginPath, 'package.json'
|
75 | updateNotifier({pkg: require(pkgPath)}).notify()
|