2015-11-14 03:40:38 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-13 16:47:55 +02:00
|
|
|
const yaml =
|
|
|
|
require(`${__dirname}/../node_modules/eslint/node_modules/js-yaml`);
|
2015-11-14 03:40:38 +01:00
|
|
|
|
|
|
|
function isYAMLBlock(text) {
|
2018-03-25 17:47:22 +02:00
|
|
|
return /^<!-- YAML/.test(text);
|
2015-11-14 03:40:38 +01:00
|
|
|
}
|
|
|
|
|
2016-05-01 01:51:38 +02:00
|
|
|
function arrify(value) {
|
|
|
|
return Array.isArray(value) ? value : [value];
|
|
|
|
}
|
|
|
|
|
2015-11-14 03:40:38 +01:00
|
|
|
function extractAndParseYAML(text) {
|
2018-03-21 15:37:12 +01:00
|
|
|
text = text.trim()
|
|
|
|
.replace(/^<!-- YAML/, '')
|
2015-11-14 03:40:38 +01:00
|
|
|
.replace(/-->$/, '');
|
|
|
|
|
2018-03-30 12:38:45 +02:00
|
|
|
// js-yaml.safeLoad() throws on error.
|
2016-05-01 01:51:38 +02:00
|
|
|
const meta = yaml.safeLoad(text);
|
|
|
|
|
2018-03-21 15:37:12 +01:00
|
|
|
if (meta.added) {
|
2016-05-01 01:51:38 +02:00
|
|
|
// Since semver-minors can trickle down to previous major versions,
|
|
|
|
// features may have been added in multiple versions.
|
2018-03-21 15:37:12 +01:00
|
|
|
meta.added = arrify(meta.added);
|
2016-05-01 01:51:38 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 00:01:13 +01:00
|
|
|
if (meta.napiVersion) {
|
|
|
|
meta.napiVersion = arrify(meta.napiVersion);
|
|
|
|
}
|
|
|
|
|
2018-03-21 15:37:12 +01:00
|
|
|
if (meta.deprecated) {
|
2016-05-01 01:51:38 +02:00
|
|
|
// Treat deprecated like added for consistency.
|
2018-03-21 15:37:12 +01:00
|
|
|
meta.deprecated = arrify(meta.deprecated);
|
2016-05-01 01:51:38 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 20:43:57 +01:00
|
|
|
meta.changes = meta.changes || [];
|
|
|
|
|
2016-05-01 01:51:38 +02:00
|
|
|
return meta;
|
2015-11-14 03:40:38 +01:00
|
|
|
}
|
|
|
|
|
2018-03-25 17:47:22 +02:00
|
|
|
module.exports = { isYAMLBlock, extractAndParseYAML };
|