UNPKG

2.29 kBtext/coffeescriptView Raw
1'use strict'
2
3path = require 'path'
4async = require 'async'
5omit = require 'lodash.omit'
6resolveUp = require 'resolve-up'
7globalNpmPath = require 'global-modules'
8updateNotifier = require 'update-notifier'
9clone = require 'lodash.clonedeep'
10MSG = require './Bumped.messages'
11Animation = require './Bumped.animation'
12isEmpty = require('./Bumped.util').isEmpty
13spawnSync = require('child_process').spawnSync
14
15npmInstallGlobal = (pkg) ->
16 spawnSync 'npm', [ 'install', pkg ],
17 stdio: 'inherit'
18 cwd: globalNpmPath
19
20###*
21 * Bumped.plugin
22 *
23 * Module to call each plugin declared for the user in the configuration file.
24 * Modules follow a duck type interface and are sorted.
25 * If any plugin throw and error, automatically stop the rest of the plugins.
26###
27module.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()