refactor(hooks): replace cz-conventional-changelog with cz-commitlint

This change replaces cz-conventional-changelog with cz-commitlint, which
automatically configures Commitizen using our commitlint configuration
file. Currently, we use some manual Javascript magic to load our
Commitizen configuration into commitlint (the opposite of what's
introduced by this change), which can be removed.

With this change, we also move our commitlint configuration into a
new `changelog.yaml` file. This file holds the same data as `.cz.json`
previously did.

Change-Id: I14ff2308f1a0b2b293c2128b28ca2df578ce9c1c
Signed-off-by: Chris Kay <chris.kay@arm.com>
diff --git a/.versionrc.js b/.versionrc.js
index 1046b28..5005c73 100644
--- a/.versionrc.js
+++ b/.versionrc.js
@@ -8,26 +8,56 @@
 
 "use strict";
 
-const cz = require("./.cz.json");
+const fs = require("fs");
+const yaml = require("js-yaml");
 
 /*
- * Convert the Commitizen types array into the format accepted by the Conventional Changelog
- * Conventional Commits plugin (which our own plugin extends).
+ * The types and scopes accepted by both Commitlint and Commitizen are defined by the changelog
+ * configuration file - `changelog.yaml` - as they decide which section of the changelog commits
+ * with a given type and scope are placed in.
  */
-const types = cz.types.map(type => {
-    if (!type.hidden) {
-        /*
-         * Conventional Changelog prevents each section from appearing only if it has no designated
-         * title, regardless of the value of the `hidden` flag.
-         */
-        type.section = type.title;
-    }
 
-    delete type.title;
-    delete type.description;
+let changelog;
 
-    return type;
-});
+try {
+    const contents = fs.readFileSync("changelog.yaml", "utf8");
+
+    changelog = yaml.load(contents);
+} catch (err) {
+    console.log(err);
+
+    throw err;
+}
+
+/*
+ * The next couple of functions are just used to transform the changelog YAML configuration
+ * structure into one accepted by the Conventional Changelog adapter (conventional-changelog-tf-a).
+ */
+
+function getTypes(sections) {
+    return sections.map(section => {
+        return {
+            "type": section.type,
+            "section": section.hidden ? undefined : section.title,
+            "hidden": section.hidden || false,
+        };
+    })
+}
+
+function getSections(subsections) {
+    return subsections.flatMap(subsection => {
+        const scope = subsection.scope ? [ subsection.scope ] : [];
+
+        return {
+            "title": subsection.title,
+            "sections": getSections(subsection.subsections || []),
+            "scopes": scope.concat(subsection.deprecated || []),
+        };
+    })
+};
+
+const types = getTypes(changelog.sections);
+const sections = getSections(changelog.subsections);
 
 module.exports = {
     "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",
@@ -38,7 +68,7 @@
         "userUrlFormat": "https://github.com/{{user}}",
 
         "types": types,
-        "sections": cz.sections,
+        "sections": sections,
     },
     "bumpFiles": [
         {