mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-13 19:04:18 +00:00
Rewrite/refactor for v5, migrate to TypeScript (MAJOR)
Set Jest config file in package script Include module path Include tests in project folders Remove index module exports Hardcode configuration parameters Move parameter binding into main run function Use alias imports Run test sequentially Remove cleanup (async conflict) Revert Jest option Increase test timeout to 15 seconds
This commit is contained in:
parent
dc8f0c5755
commit
31f4e3fdf0
74 changed files with 9422 additions and 4342 deletions
12
lib/formatting/CsvUserFormatter.js
Normal file
12
lib/formatting/CsvUserFormatter.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CsvUserFormatter = void 0;
|
||||
class CsvUserFormatter {
|
||||
constructor(config) {
|
||||
// placeholder for consistency with other formatters
|
||||
}
|
||||
Format(type, users) {
|
||||
return users.map(user => `${user.name} <${user.email}>`).join(', ');
|
||||
}
|
||||
}
|
||||
exports.CsvUserFormatter = CsvUserFormatter;
|
||||
51
lib/formatting/DefaultTagFormatter.js
Normal file
51
lib/formatting/DefaultTagFormatter.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultTagFormatter = void 0;
|
||||
/** Default tag formatter which allows a prefix to be specified */
|
||||
class DefaultTagFormatter {
|
||||
constructor(config) {
|
||||
this.namespace = config.namespace;
|
||||
this.tagPrefix = config.tagPrefix;
|
||||
this.namespaceSeperator = '-'; // maybe make configurable in the future
|
||||
}
|
||||
Format(versionInfo) {
|
||||
const result = `${this.tagPrefix}${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`;
|
||||
if (!!this.namespace) {
|
||||
return `${result}${this.namespaceSeperator}${this.namespace}`;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
GetPattern() {
|
||||
if (!!this.namespace) {
|
||||
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]${this.namespaceSeperator}${this.namespace}`;
|
||||
}
|
||||
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
|
||||
}
|
||||
Parse(tag) {
|
||||
let stripedTag;
|
||||
if (this.tagPrefix.includes('/') && tag.includes(this.tagPrefix)) {
|
||||
let tagParts = tag
|
||||
.replace(this.tagPrefix, '<--!PREFIX!-->')
|
||||
.split('/');
|
||||
stripedTag = tagParts[tagParts.length - 1]
|
||||
.replace('<--!PREFIX!-->', this.tagPrefix);
|
||||
}
|
||||
else {
|
||||
let tagParts = tag.split('/');
|
||||
stripedTag = tagParts[tagParts.length - 1];
|
||||
}
|
||||
let versionValues = stripedTag
|
||||
.substring(this.tagPrefix.length)
|
||||
.slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1))
|
||||
.split('.');
|
||||
let major = parseInt(versionValues[0]);
|
||||
let minor = versionValues.length > 1 ? parseInt(versionValues[1]) : 0;
|
||||
let patch = versionValues.length > 2 ? parseInt(versionValues[2]) : 0;
|
||||
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
||||
throw `Invalid tag ${tag} (${versionValues})`;
|
||||
}
|
||||
return [major, minor, patch];
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.DefaultTagFormatter = DefaultTagFormatter;
|
||||
16
lib/formatting/DefaultVersionFormatter.js
Normal file
16
lib/formatting/DefaultVersionFormatter.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultVersionFormatter = void 0;
|
||||
class DefaultVersionFormatter {
|
||||
constructor(config) {
|
||||
this.formatString = config.versionFormat;
|
||||
}
|
||||
Format(versionInfo) {
|
||||
return this.formatString
|
||||
.replace('${major}', versionInfo.major.toString())
|
||||
.replace('${minor}', versionInfo.minor.toString())
|
||||
.replace('${patch}', versionInfo.patch.toString())
|
||||
.replace('${increment}', versionInfo.increment.toString());
|
||||
}
|
||||
}
|
||||
exports.DefaultVersionFormatter = DefaultVersionFormatter;
|
||||
13
lib/formatting/JsonUserFormatter.js
Normal file
13
lib/formatting/JsonUserFormatter.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JsonUserFormatter = void 0;
|
||||
class JsonUserFormatter {
|
||||
constructor(config) {
|
||||
// placeholder for consistency with other formatters
|
||||
}
|
||||
Format(type, users) {
|
||||
let result = users.map(u => ({ name: u.name, email: u.email }));
|
||||
return JSON.stringify(result).replace('\n', '');
|
||||
}
|
||||
}
|
||||
exports.JsonUserFormatter = JsonUserFormatter;
|
||||
2
lib/formatting/TagFormatter.js
Normal file
2
lib/formatting/TagFormatter.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
lib/formatting/UserFormatter.js
Normal file
2
lib/formatting/UserFormatter.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
lib/formatting/VersionFormatter.js
Normal file
2
lib/formatting/VersionFormatter.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
16
lib/formatting/YamlUserFormatter.js
Normal file
16
lib/formatting/YamlUserFormatter.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.YamlUserFormatter = void 0;
|
||||
class YamlUserFormatter {
|
||||
constructor(config) {
|
||||
this.lineBreak = config.userFormatLineBreak || '\n';
|
||||
this.includeType = config.includeType || false;
|
||||
}
|
||||
Format(type, users) {
|
||||
const result = users.flatMap(u => [`- name: "${u.name}"`, ` email: "${u.email}"`]).join(this.lineBreak);
|
||||
return this.includeType ?
|
||||
`${type}:${this.lineBreak}${result}` :
|
||||
result;
|
||||
}
|
||||
}
|
||||
exports.YamlUserFormatter = YamlUserFormatter;
|
||||
11
lib/formatting/index.js
Normal file
11
lib/formatting/index.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JsonUserFormatter = exports.DefaultVersionFormatter = exports.DefaultTagFormatter = exports.CsvUserFormatter = void 0;
|
||||
var CsvUserFormatter_1 = require("./CsvUserFormatter");
|
||||
Object.defineProperty(exports, "CsvUserFormatter", { enumerable: true, get: function () { return CsvUserFormatter_1.CsvUserFormatter; } });
|
||||
var DefaultTagFormatter_1 = require("./DefaultTagFormatter");
|
||||
Object.defineProperty(exports, "DefaultTagFormatter", { enumerable: true, get: function () { return DefaultTagFormatter_1.DefaultTagFormatter; } });
|
||||
var DefaultVersionFormatter_1 = require("./DefaultVersionFormatter");
|
||||
Object.defineProperty(exports, "DefaultVersionFormatter", { enumerable: true, get: function () { return DefaultVersionFormatter_1.DefaultVersionFormatter; } });
|
||||
var JsonUserFormatter_1 = require("./JsonUserFormatter");
|
||||
Object.defineProperty(exports, "JsonUserFormatter", { enumerable: true, get: function () { return JsonUserFormatter_1.JsonUserFormatter; } });
|
||||
Loading…
Add table
Add a link
Reference in a new issue