UNPKG

2.39 kBPlain TextView Raw
1/*
2 * Copyright © 2019 Atomist, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {
18 AnyPush,
19 DefaultGoalNameGenerator,
20 FulfillableGoalDetails,
21 FulfillableGoalWithRegistrations,
22 getGoalDefinitionFrom,
23 Goal,
24 ImplementationRegistration,
25} from "@atomist/sdm";
26import {
27 executeVersioner,
28 ProjectVersioner,
29} from "../../internal/delivery/build/local/projectVersioner";
30
31/**
32 * Register a ProjectVersioner for a certain type of push
33 */
34export interface ProjectVersionerRegistration extends Partial<ImplementationRegistration> {
35 versioner: ProjectVersioner;
36}
37
38/**
39 * Goal that performs project visioning: For example using Maven to increment the project version number
40 */
41export class Version extends FulfillableGoalWithRegistrations<ProjectVersionerRegistration> {
42
43 constructor(goalDetailsOrUniqueName: FulfillableGoalDetails | string = DefaultGoalNameGenerator.generateName("version"),
44 ...dependsOn: Goal[]) {
45
46 super({
47 workingDescription: "Calculating project version",
48 completedDescription: "Versioned",
49 ...getGoalDefinitionFrom(goalDetailsOrUniqueName, DefaultGoalNameGenerator.generateName("version")),
50 displayName: "version",
51 }, ...dependsOn);
52 }
53
54 public with(registration: ProjectVersionerRegistration): this {
55 this.addFulfillment({
56 goalExecutor: executeVersioner(registration.versioner),
57 name: DefaultGoalNameGenerator.generateName("versioner"),
58 ...registration as ImplementationRegistration,
59 });
60 return this;
61 }
62
63 public withVersioner(versioner: ProjectVersioner): this {
64 this.with({
65 name: DefaultGoalNameGenerator.generateName("versioner"),
66 pushTest: AnyPush,
67 versioner,
68 });
69 return this;
70 }
71}