-
Notifications
You must be signed in to change notification settings - Fork 123
/
plugin-ci-version.cjs
62 lines (52 loc) · 1.73 KB
/
plugin-ci-version.cjs
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
module.exports = {
name: `plugin-ci-version`,
factory: (require) => {
const { BaseCommand, WorkspaceRequiredError } = require(`@yarnpkg/cli`);
const { Cache, Configuration, Project } = require(`@yarnpkg/core`);
const semver = require("semver");
const { Option } = require(`clipanion`);
class CiVersion extends BaseCommand {
static paths = [[`ci-version`]];
strategy = Option.String();
async execute() {
const configuration = await Configuration.find(
this.context.cwd,
this.context.plugins,
);
const { project, workspace } = await Project.find(
configuration,
this.context.cwd,
);
const cache = await Cache.find(configuration);
if (!workspace)
throw new WorkspaceRequiredError(project.cwd, this.context.cwd);
const valid = semver.valid(this.strategy);
if (!valid)
throw new Error(`should be a valid semver: ${this.strategy}`);
const currentVersion = workspace.manifest.version;
if (currentVersion === this.strategy) {
this.context.stdout.write(
`workspace ${workspace.manifest.raw.name} already has specified version ${this.strategy}\n`,
);
return;
}
workspace.manifest.version = this.strategy;
this.context.stdout.write(
`updating workspace ${workspace.manifest.raw.name} from ${currentVersion} to ${this.strategy}\n`,
);
return await project.installWithNewReport(
{
json: this.json,
stdout: this.context.stdout,
},
{
cache,
},
);
}
}
return {
commands: [CiVersion],
};
},
};