mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-10 01:54: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
14
src/formatting/CsvUserFormatter.ts
Normal file
14
src/formatting/CsvUserFormatter.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { ActionConfig } from '../ActionConfig';
|
||||
import { UserInfo } from '../providers/UserInfo';
|
||||
import { UserFormatter } from './UserFormatter';
|
||||
|
||||
export class CsvUserFormatter implements UserFormatter {
|
||||
|
||||
constructor(config: ActionConfig) {
|
||||
// placeholder for consistency with other formatters
|
||||
}
|
||||
|
||||
public Format(type: string, users: UserInfo[]): string {
|
||||
return users.map(user => `${user.name} <${user.email}>`).join(', ');
|
||||
}
|
||||
}
|
||||
65
src/formatting/DefaultTagFormatter.ts
Normal file
65
src/formatting/DefaultTagFormatter.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import { TagFormatter } from './TagFormatter';
|
||||
import { VersionInformation } from "../providers/VersionInformation";
|
||||
import { ActionConfig } from '../ActionConfig';
|
||||
|
||||
/** Default tag formatter which allows a prefix to be specified */
|
||||
export class DefaultTagFormatter implements TagFormatter {
|
||||
|
||||
private tagPrefix: string;
|
||||
private namespace: string;
|
||||
private namespaceSeperator: string;
|
||||
|
||||
constructor(config: ActionConfig) {
|
||||
this.namespace = config.namespace;
|
||||
this.tagPrefix = config.tagPrefix;
|
||||
this.namespaceSeperator = '-'; // maybe make configurable in the future
|
||||
}
|
||||
|
||||
public Format(versionInfo: VersionInformation): string {
|
||||
const result = `${this.tagPrefix}${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`;
|
||||
|
||||
if (!!this.namespace) {
|
||||
return `${result}${this.namespaceSeperator}${this.namespace}`;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public GetPattern(): string {
|
||||
|
||||
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]`;
|
||||
}
|
||||
|
||||
public Parse(tag: string): [major: number, minor: number, patch: number] {
|
||||
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];
|
||||
};
|
||||
|
||||
}
|
||||
20
src/formatting/DefaultVersionFormatter.ts
Normal file
20
src/formatting/DefaultVersionFormatter.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { VersionFormatter } from './VersionFormatter';
|
||||
import { VersionInformation } from "../providers/VersionInformation";
|
||||
import { ActionConfig } from '../ActionConfig';
|
||||
|
||||
export class DefaultVersionFormatter implements VersionFormatter {
|
||||
|
||||
private formatString: string;
|
||||
|
||||
constructor(config: ActionConfig) {
|
||||
this.formatString = config.versionFormat;
|
||||
}
|
||||
|
||||
public Format(versionInfo: VersionInformation): string {
|
||||
return this.formatString
|
||||
.replace('${major}', versionInfo.major.toString())
|
||||
.replace('${minor}', versionInfo.minor.toString())
|
||||
.replace('${patch}', versionInfo.patch.toString())
|
||||
.replace('${increment}', versionInfo.increment.toString());
|
||||
}
|
||||
}
|
||||
13
src/formatting/JsonUserFormatter.ts
Normal file
13
src/formatting/JsonUserFormatter.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { ActionConfig } from '../ActionConfig';
|
||||
import { UserInfo } from '../providers/UserInfo';
|
||||
import { UserFormatter } from './UserFormatter';
|
||||
|
||||
export class JsonUserFormatter implements UserFormatter {
|
||||
constructor(config: ActionConfig) {
|
||||
// placeholder for consistency with other formatters
|
||||
}
|
||||
public Format(type: string, users: UserInfo[]): string {
|
||||
let result: any = users.map(u => ({ name: u.name, email: u.email }));
|
||||
return JSON.stringify(result).replace('\n', '');
|
||||
}
|
||||
}
|
||||
7
src/formatting/TagFormatter.ts
Normal file
7
src/formatting/TagFormatter.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { VersionInformation } from "../providers/VersionInformation";
|
||||
|
||||
export interface TagFormatter {
|
||||
Format(versionInfo: VersionInformation): string;
|
||||
GetPattern(): string;
|
||||
Parse(tag: string): [major: number, minor: number, patch: number];
|
||||
}
|
||||
6
src/formatting/UserFormatter.ts
Normal file
6
src/formatting/UserFormatter.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { UserInfo } from "../providers/UserInfo";
|
||||
|
||||
/** Formats a list of users as a string (e.g. JSON, YAML, CSV, etc) */
|
||||
export interface UserFormatter {
|
||||
Format(type: string, users: UserInfo[]): string;
|
||||
}
|
||||
6
src/formatting/VersionFormatter.ts
Normal file
6
src/formatting/VersionFormatter.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { VersionInformation } from "../providers/VersionInformation";
|
||||
|
||||
// Formatters
|
||||
export interface VersionFormatter {
|
||||
Format(versionInfo: VersionInformation): string;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue