-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump to TypeScript 5.6 /w strictPropertyInit
This commit migrates from TypeScript 5.5 to 5.6 with `strictPropertyInitialization` flag enabled for stricter quality controls. Supporting changes: - Move GitHubProjectDetails to application layer for better SRP - Convert mutable fields to immutable states with getters - Initialize test stubs with default values - Split complex state updates into pure functions - Improve error messages in test assertions - Upgrade `nanoid` dependency to avoid security issues
- Loading branch information
1 parent
ce09243
commit 4dd8e11
Showing
32 changed files
with
391 additions
and
310 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/application/Parser/Project/GitHubProjectDetailsFactory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { assertInRange } from '@/application/Common/Enum'; | ||
import { OperatingSystem } from '@/domain/OperatingSystem'; | ||
import type { ProjectDetailsParameters, ProjectDetailsFactory } from './ProjectDetailsFactory'; | ||
|
||
export const createGitHubProjectDetails: ProjectDetailsFactory = (parameters) => { | ||
validateParameters(parameters); | ||
const githubRepositoryWebUrl = getWebUrl(parameters.repositoryUrl); | ||
return { | ||
name: parameters.name, | ||
version: parameters.version, | ||
slogan: parameters.slogan, | ||
repositoryUrl: parameters.repositoryUrl, | ||
homepage: parameters.homepage, | ||
repositoryWebUrl: githubRepositoryWebUrl, | ||
feedbackUrl: `${githubRepositoryWebUrl}/issues`, | ||
releaseUrl: `${githubRepositoryWebUrl}/releases/tag/${parameters.version}`, | ||
getDownloadUrl: (os) => { | ||
const fileName = getFileName(os, parameters.version.toString()); | ||
return `${githubRepositoryWebUrl}/releases/download/${parameters.version}/${fileName}`; | ||
}, | ||
}; | ||
}; | ||
|
||
function validateParameters(parameters: ProjectDetailsParameters) { | ||
if (!parameters.name) { | ||
throw new Error('name is undefined'); | ||
} | ||
if (!parameters.slogan) { | ||
throw new Error('undefined slogan'); | ||
} | ||
if (!parameters.repositoryUrl) { | ||
throw new Error('repositoryUrl is undefined'); | ||
} | ||
if (!parameters.homepage) { | ||
throw new Error('homepage is undefined'); | ||
} | ||
} | ||
|
||
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]}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { ProjectDetails } from '@/domain/Project/ProjectDetails'; | ||
import type { Version } from '@/domain/Version'; | ||
|
||
export interface ProjectDetailsParameters { | ||
readonly name: string, | ||
readonly version: Version, | ||
readonly slogan: string, | ||
readonly repositoryUrl: string, | ||
readonly homepage: string, | ||
} | ||
|
||
export type ProjectDetailsFactory = ( | ||
args: ProjectDetailsParameters, | ||
) => ProjectDetails; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { ProjectDetails } from '@/domain/Project/ProjectDetails'; | ||
import type { IAppMetadata } from '@/infrastructure/EnvironmentVariables/IAppMetadata'; | ||
import { Version } from '@/domain/Version'; | ||
import { EnvironmentVariablesFactory } from '@/infrastructure/EnvironmentVariables/EnvironmentVariablesFactory'; | ||
import { createGitHubProjectDetails } from './GitHubProjectDetailsFactory'; | ||
import type { ProjectDetailsFactory } from './ProjectDetailsFactory'; | ||
|
||
export const parseProjectDetails: MetadataProjectDetailsParser = ( | ||
metadata: IAppMetadata = EnvironmentVariablesFactory.Current.instance, | ||
createProjectDetails: ProjectDetailsFactory = createGitHubProjectDetails, | ||
) => { | ||
return createProjectDetails({ | ||
name: metadata.name, | ||
version: new Version( | ||
metadata.version, | ||
), | ||
slogan: metadata.slogan, | ||
repositoryUrl: metadata.repositoryUrl, | ||
homepage: metadata.homepageUrl, | ||
}); | ||
}; | ||
|
||
export type MetadataProjectDetailsParser = ProjectDetailsParser & (( | ||
metadata?: IAppMetadata, | ||
createProjectDetails?: ProjectDetailsFactory, | ||
) => ProjectDetails); | ||
|
||
export interface ProjectDetailsParser { | ||
(): ProjectDetails; | ||
} |
Oops, something went wrong.