/
index.js
60 lines (50 loc) 路 2.12 KB
/
index.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
const _ = require('lodash');
const sinon = require('sinon');
const semver = require('semver');
const { parseVersion } = require('../../lib/util');
const Log = require('../../lib/log');
const Config = require('../../lib/config');
const ShellStub = require('../stub/shell');
const Spinner = require('../../lib/spinner');
const Prompt = require('../../lib/prompt');
module.exports.factory = (Definition, { namespace, options = {}, global = {}, container = {} } = {}) => {
_.defaults(global, { isCI: true, isVerbose: false, isDryRun: false, isDebug: false });
const ns = namespace || Definition.name.toLowerCase();
container.config = container.config || new Config(Object.assign({ config: false }, options));
container.log = container.log || sinon.createStubInstance(Log);
const spinner = container.spinner || sinon.createStubInstance(Spinner);
spinner.show.callsFake(({ enabled = true, task }) => (enabled ? task() : () => {}));
container.spinner = spinner;
container.shell = container.shell || new ShellStub({ global, container });
container.prompt = container.prompt || new Prompt({ container });
container.shell.cache = { set: () => {}, has: () => false };
return new Definition({
namespace: ns,
options,
global,
container
});
};
module.exports.runTasks = async plugin => {
await plugin.init();
const name = (await plugin.getName()) || '__test__';
const latestVersion = (await plugin.getLatestVersion()) || '1.0.0';
const changelog = (await plugin.getChangelog(latestVersion)) || null;
const increment = plugin.getContext('increment') || plugin.config.getContext('increment');
plugin.config.setContext({ name, latestVersion, changelog });
const version =
plugin.getIncrementedVersionCI({ latestVersion, increment }) ||
(await plugin.getIncrementedVersion({ latestVersion, increment })) ||
semver.inc(latestVersion, increment || 'patch');
plugin.config.setContext(parseVersion(version));
await plugin.beforeBump();
await plugin.bump(version);
await plugin.beforeRelease();
await plugin.release();
await plugin.afterRelease();
return {
name,
latestVersion,
version
};
};