/
Plugin.js
72 lines (60 loc) 路 1.78 KB
/
Plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import debug from 'debug';
import _ from 'lodash';
class Plugin {
static isEnabled() {
return true;
}
static disablePlugin() {
return null;
}
constructor({ namespace, options = {}, container = {} } = {}) {
this.namespace = namespace;
this.options = Object.freeze(this.getInitialOptions(options, namespace));
this.context = {};
this.config = container.config;
this.log = container.log;
this.shell = container.shell;
this.spinner = container.spinner;
this.prompt = container.prompt;
this.debug = debug(`release-it:${namespace}`);
}
getInitialOptions(options, namespace) {
return options[namespace] || {};
}
init() {}
getName() {}
getLatestVersion() {}
getChangelog() {}
getIncrement() {}
getIncrementedVersionCI() {}
getIncrementedVersion() {}
beforeBump() {}
bump() {}
beforeRelease() {}
release() {}
afterRelease() {}
getContext(path) {
const context = Object.assign({}, this.options, this.context);
return path ? _.get(context, path) : context;
}
setContext(context) {
_.merge(this.context, context);
}
exec(command, { options, context = {} } = {}) {
const ctx = Object.assign(context, this.config.getContext(), { [this.namespace]: this.getContext() });
return this.shell.exec(command, options, ctx);
}
registerPrompts(prompts) {
this.prompt.register(prompts, this.namespace);
}
async showPrompt(options) {
options.namespace = this.namespace;
return this.prompt.show(options);
}
step(options) {
const context = Object.assign({}, this.config.getContext(), { [this.namespace]: this.getContext() });
const opts = Object.assign({}, options, { context });
return this.config.isCI ? this.spinner.show(opts) : this.showPrompt(opts);
}
}
export default Plugin;