1/*
2 * Copyright (c) 2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/* eslint-env es6 */
8
9"use strict";
10
11const cz = require("./.cz.json");
12
13/*
14 * Convert the Commitizen types array into the format accepted by the Conventional Changelog
15 * Conventional Commits plugin (which our own plugin extends).
16 */
17const types = cz.types.map(type => {
18    if (!type.hidden) {
19        /*
20         * Conventional Changelog prevents each section from appearing only if it has no designated
21         * title, regardless of the value of the `hidden` flag.
22         */
23        type.section = type.title;
24    }
25
26    delete type.title;
27    delete type.description;
28
29    return type;
30});
31
32module.exports = {
33    "header": "# Change Log & Release Notes\n\nThis document contains a summary of the new features, changes, fixes and known\nissues in each release of Trusted Firmware-A.\n",
34    "preset": {
35        "name": "tf-a",
36        "commitUrlFormat": "https://review.trustedfirmware.org/plugins/gitiles/TF-A/trusted-firmware-a/+/{{hash}}",
37        "compareUrlFormat": "https://review.trustedfirmware.org/plugins/gitiles/TF-A/trusted-firmware-a/+/{{previousTag}}..{{currentTag}}",
38        "userUrlFormat": "https://github.com/{{user}}",
39
40        "types": types,
41        "sections": cz.sections,
42    },
43    "bumpFiles": [
44        {
45            "filename": "Makefile",
46            "updater": {
47                "readVersion": function (contents) {
48                    const major = contents.match(/^VERSION_MAJOR\s*:=\s*(\d+?)$/m)[1];
49                    const minor = contents.match(/^VERSION_MINOR\s*:=\s*(\d+?)$/m)[1];
50
51                    return `${major}.${minor}.0`;
52                },
53
54                "writeVersion": function (contents, version) {
55                    const major = version.split(".")[0];
56                    const minor = version.split(".")[1];
57
58                    contents = contents.replace(/^(VERSION_MAJOR\s*:=\s*)(\d+?)$/m, `$1${major}`);
59                    contents = contents.replace(/^(VERSION_MINOR\s*:=\s*)(\d+?)$/m, `$1${minor}`);
60
61                    return contents;
62                }
63            }
64        }
65    ]
66};
67