Major refactoring using ESLint with rules from AirBnb and Vue. Enable most of the ESLint rules and do necessary linting in the code. Also add more information for rules that are disabled to describe what they are and why they are disabled. Allow logging (`console.log`) in test files, and in development mode (e.g. when working with `npm run serve`), but disable it when environment is production (as pre-configured by Vue). Also add flag (`--mode production`) in `lint:eslint` command so production linting is executed earlier in lifecycle. Disable rules that requires a separate work. Such as ESLint rules that are broken in TypeScript: no-useless-constructor (eslint/eslint#14118) and no-shadow (eslint/eslint#13014).
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { assertInRange } from '@/application/Common/Enum';
|
|
import { IProjectInformation } from './IProjectInformation';
|
|
import { OperatingSystem } from './OperatingSystem';
|
|
|
|
export class ProjectInformation implements IProjectInformation {
|
|
public readonly repositoryWebUrl: string;
|
|
|
|
constructor(
|
|
public readonly name: string,
|
|
public readonly version: string,
|
|
public readonly repositoryUrl: string,
|
|
public readonly homepage: string,
|
|
) {
|
|
if (!name) {
|
|
throw new Error('name is undefined');
|
|
}
|
|
if (!version || +version <= 0) {
|
|
throw new Error('version should be higher than zero');
|
|
}
|
|
if (!repositoryUrl) {
|
|
throw new Error('repositoryUrl is undefined');
|
|
}
|
|
if (!homepage) {
|
|
throw new Error('homepage is undefined');
|
|
}
|
|
this.repositoryWebUrl = getWebUrl(this.repositoryUrl);
|
|
}
|
|
|
|
public getDownloadUrl(os: OperatingSystem): string {
|
|
return `${this.repositoryWebUrl}/releases/download/${this.version}/${getFileName(os, this.version)}`;
|
|
}
|
|
|
|
public get feedbackUrl(): string {
|
|
return `${this.repositoryWebUrl}/issues`;
|
|
}
|
|
|
|
public get releaseUrl(): string {
|
|
return `${this.repositoryWebUrl}/releases/tag/${this.version}`;
|
|
}
|
|
}
|
|
|
|
function getWebUrl(gitUrl: string) {
|
|
if (gitUrl.endsWith('.git')) {
|
|
return gitUrl.substring(0, gitUrl.length - 4);
|
|
}
|
|
return gitUrl;
|
|
}
|
|
|
|
function getFileName(os: OperatingSystem, version: string): string {
|
|
assertInRange(os, OperatingSystem);
|
|
switch (os) {
|
|
case OperatingSystem.Linux:
|
|
return `privacy.sexy-${version}.AppImage`;
|
|
case OperatingSystem.macOS:
|
|
return `privacy.sexy-${version}.dmg`;
|
|
case OperatingSystem.Windows:
|
|
return `privacy.sexy-Setup-${version}.exe`;
|
|
default:
|
|
throw new RangeError(`Unsupported os: ${OperatingSystem[os]}`);
|
|
}
|
|
}
|