Skip to content

Commit 784a67a

Browse files
refactor to read more from package.json
1 parent 19a092d commit 784a67a

30 files changed

+374
-158
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
"version": "0.7.5",
44
"author": "undergroundwires",
55
"description": "Enforce privacy & security best-practices on Windows, because privacy is sexy 🍑🍆",
6+
"homepage": "https://privacy.sexy",
67
"private": true,
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/undergroundwires/privacy.sexy.git"
11+
},
712
"scripts": {
813
"serve": "vue-cli-service serve",
914
"build": "vue-cli-service build",

src/application/Environment/BrowserOs/BrowserOsDetector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OperatingSystem } from '../OperatingSystem';
1+
import { OperatingSystem } from '@/domain/OperatingSystem';
22
import { DetectorBuilder } from './DetectorBuilder';
33
import { IBrowserOsDetector } from './IBrowserOsDetector';
44

src/application/Environment/BrowserOs/DetectorBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IBrowserOsDetector } from './IBrowserOsDetector';
2-
import { OperatingSystem } from '../OperatingSystem';
2+
import { OperatingSystem } from '@/domain/OperatingSystem';
33

44
export class DetectorBuilder {
55
private readonly existingPartsInUserAgent = new Array<string>();

src/application/Environment/BrowserOs/IBrowserOsDetector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OperatingSystem } from '../OperatingSystem';
1+
import { OperatingSystem } from '@/domain/OperatingSystem';
22

33
export interface IBrowserOsDetector {
44
detect(userAgent: string): OperatingSystem;

src/application/Environment/Environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BrowserOsDetector } from './BrowserOs/BrowserOsDetector';
22
import { IBrowserOsDetector } from './BrowserOs/IBrowserOsDetector';
33
import { IEnvironment } from './IEnvironment';
4-
import { OperatingSystem } from './OperatingSystem';
4+
import { OperatingSystem } from '@/domain/OperatingSystem';
55

66
interface IEnvironmentVariables {
77
readonly window: Window & typeof globalThis;

src/application/Environment/IEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OperatingSystem } from './OperatingSystem';
1+
import { OperatingSystem } from '@/domain/OperatingSystem';
22

33
export interface IEnvironment {
44
isDesktop: boolean;

src/application/Parser/ApplicationParser.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
import { Category } from '@/domain/Category';
22
import { Application } from '@/domain/Application';
33
import { IApplication } from '@/domain/IApplication';
4+
import { IProjectInformation } from '@/domain/IProjectInformation';
45
import { ApplicationYaml } from 'js-yaml-loader!./../application.yaml';
56
import { parseCategory } from './CategoryParser';
7+
import { ProjectInformation } from '../../domain/ProjectInformation';
68

7-
export function parseApplication(content: ApplicationYaml): IApplication {
9+
10+
export function parseApplication(content: ApplicationYaml, env: NodeJS.ProcessEnv = process.env): IApplication {
811
validate(content);
912
const categories = new Array<Category>();
1013
for (const action of content.actions) {
1114
const category = parseCategory(action);
1215
categories.push(category);
1316
}
17+
const info = readAppInformation(env);
1418
const app = new Application(
15-
content.name,
16-
content.repositoryUrl,
17-
process.env.VUE_APP_VERSION,
19+
info,
1820
categories);
1921
return app;
2022
}
2123

24+
function readAppInformation(environment): IProjectInformation {
25+
return new ProjectInformation(
26+
environment.VUE_APP_NAME,
27+
environment.VUE_APP_VERSION,
28+
environment.VUE_APP_REPOSITORY_URL,
29+
environment.VUE_APP_HOMEPAGE_URL,
30+
);
31+
}
32+
2233
function validate(content: ApplicationYaml): void {
2334
if (!content) {
2435
throw new Error('application is null or undefined');

src/application/State/ApplicationState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ApplicationState implements IApplicationState {
3939
/** Initially selected scripts */
4040
public readonly defaultScripts: Script[]) {
4141
this.selection = new UserSelection(app, defaultScripts.map((script) => new SelectedScript(script, false)));
42-
this.code = new ApplicationCode(this.selection, app.version);
42+
this.code = new ApplicationCode(this.selection, app.info.version);
4343
this.filter = new UserFilter(app);
4444
}
4545
}

src/application/application.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Structure documented in "./application.yaml.d.ts" (as code)
2-
name: privacy.sexy
3-
repositoryUrl: https://github.com/undergroundwires/privacy.sexy
42
actions:
53
-
64
category: Privacy cleanup

src/application/application.yaml.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ declare module 'js-yaml-loader!*' {
1919
}
2020

2121
export interface ApplicationYaml {
22-
name: string;
23-
repositoryUrl: string;
2422
actions: ReadonlyArray<YamlCategory>;
2523
}
2624

src/domain/Application.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IEntity } from '../infrastructure/Entity/IEntity';
22
import { ICategory } from './ICategory';
33
import { IScript } from './IScript';
44
import { IApplication } from './IApplication';
5+
import { IProjectInformation } from './IProjectInformation';
56

67
export class Application implements IApplication {
78
public get totalScripts(): number { return this.flattened.allScripts.length; }
@@ -10,13 +11,11 @@ export class Application implements IApplication {
1011
private readonly flattened: IFlattenedApplication;
1112

1213
constructor(
13-
public readonly name: string,
14-
public readonly repositoryUrl: string,
15-
public readonly version: string,
14+
public readonly info: IProjectInformation,
1615
public readonly actions: ReadonlyArray<ICategory>) {
17-
if (!name) { throw Error('Application has no name'); }
18-
if (!repositoryUrl) { throw Error('Application has no repository url'); }
19-
if (!version) { throw Error('Version cannot be empty'); }
16+
if (!info) {
17+
throw new Error('info is undefined');
18+
}
2019
this.flattened = flatten(actions);
2120
ensureValid(this.flattened);
2221
ensureNoDuplicates(this.flattened.allCategories);

src/domain/IApplication.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { IScript } from '@/domain/IScript';
22
import { ICategory } from '@/domain/ICategory';
3+
import { IProjectInformation } from './IProjectInformation';
34

45
export interface IApplication {
5-
readonly name: string;
6-
readonly repositoryUrl: string;
7-
readonly version: string;
6+
readonly info: IProjectInformation;
87
readonly totalScripts: number;
98
readonly totalCategories: number;
109
readonly actions: ReadonlyArray<ICategory>;

src/domain/IProjectInformation.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { OperatingSystem } from './OperatingSystem';
2+
export interface IProjectInformation {
3+
readonly name: string;
4+
readonly version: string;
5+
readonly repositoryUrl: string;
6+
readonly homepage: string;
7+
readonly feedbackUrl: string;
8+
readonly releaseUrl: string;
9+
readonly repositoryWebUrl: string;
10+
getDownloadUrl(os: OperatingSystem): string;
11+
}

src/domain/ProjectInformation.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { IProjectInformation } from './IProjectInformation';
2+
import { OperatingSystem } from './OperatingSystem';
3+
4+
export class ProjectInformation implements IProjectInformation {
5+
public readonly repositoryWebUrl: string;
6+
constructor(
7+
public readonly name: string,
8+
public readonly version: string,
9+
public readonly repositoryUrl: string,
10+
public readonly homepage: string,
11+
) {
12+
if (!name) {
13+
throw new Error('name is undefined');
14+
}
15+
if (!version || +version <= 0) {
16+
throw new Error('version should be higher than zero');
17+
}
18+
if (!repositoryUrl) {
19+
throw new Error('repositoryUrl is undefined');
20+
}
21+
if (!homepage) {
22+
throw new Error('homepage is undefined');
23+
}
24+
this.repositoryWebUrl = getWebUrl(this.repositoryUrl);
25+
}
26+
public getDownloadUrl(os: OperatingSystem): string {
27+
return `${this.repositoryWebUrl}/releases/download/${this.version}/${getFileName(os, this.version)}`;
28+
}
29+
public get feedbackUrl(): string {
30+
return `${this.repositoryWebUrl}/issues`;
31+
}
32+
public get releaseUrl(): string {
33+
return `${this.repositoryWebUrl}/releases/tag/${this.version}`;
34+
}
35+
}
36+
37+
function getWebUrl(gitUrl: string) {
38+
if (gitUrl.endsWith('.git')) {
39+
return gitUrl.substring(0, gitUrl.length - 4);
40+
}
41+
return gitUrl;
42+
}
43+
44+
function getFileName(os: OperatingSystem, version: string): string {
45+
switch (os) {
46+
case OperatingSystem.Linux:
47+
return `privacy.sexy-${version}.AppImage`;
48+
case OperatingSystem.macOS:
49+
return `privacy.sexy-${version}.dmg`;
50+
case OperatingSystem.Windows:
51+
return `privacy.sexy-Setup-${version}.exe`;
52+
default:
53+
throw new Error(`Unsupported os: ${OperatingSystem[os]}`);
54+
}
55+
}

src/presentation/Scripts/TheScripts.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
7575
public async mounted() {
7676
const state = await this.getCurrentStateAsync();
77-
this.repositoryUrl = state.app.repositoryUrl;
77+
this.repositoryUrl = state.app.info.repositoryWebUrl;
7878
state.filter.filterRemoved.on(() => {
7979
this.isSearching = false;
8080
});

src/presentation/TheFooter/DownloadUrlList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<script lang="ts">
1818
import { Component, Vue } from 'vue-property-decorator';
1919
import { Environment } from '@/application/Environment/Environment';
20-
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
20+
import { OperatingSystem } from '@/domain/OperatingSystem';
2121
import DownloadUrlListItem from './DownloadUrlListItem.vue';
2222
2323
@Component({

src/presentation/TheFooter/DownloadUrlListItem.vue

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import { Component, Prop, Watch } from 'vue-property-decorator';
1313
import { StatefulVue } from '@/presentation/StatefulVue';
1414
import { Environment } from '@/application/Environment/Environment';
15-
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
15+
import { OperatingSystem } from '@/domain/OperatingSystem';
1616
1717
@Component
1818
export default class DownloadUrlListItem extends StatefulVue {
@@ -39,7 +39,7 @@ export default class DownloadUrlListItem extends StatefulVue {
3939
4040
private async getDownloadUrlAsync(os: OperatingSystem): Promise<string> {
4141
const state = await this.getCurrentStateAsync();
42-
return `${state.app.repositoryUrl}/releases/download/${state.app.version}/${getFileName(os, state.app.version)}`;
42+
return state.app.info.getDownloadUrl(os);
4343
}
4444
}
4545
@@ -62,18 +62,6 @@ function getOperatingSystemName(os: OperatingSystem): string {
6262
}
6363
}
6464
65-
function getFileName(os: OperatingSystem, version: string): string {
66-
switch (os) {
67-
case OperatingSystem.Linux:
68-
return `privacy.sexy-${version}.AppImage`;
69-
case OperatingSystem.macOS:
70-
return `privacy.sexy-${version}.dmg`;
71-
case OperatingSystem.Windows:
72-
return `privacy.sexy-Setup-${version}.exe`;
73-
default:
74-
throw new Error(`Unsupported os: ${OperatingSystem[os]}`);
75-
}
76-
}
7765
</script>
7866

7967
<style scoped lang="scss">

src/presentation/TheFooter/PrivacyPolicy.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export default class TheFooter extends StatefulVue {
4848
4949
public async mounted() {
5050
const state = await this.getCurrentStateAsync();
51-
this.repositoryUrl = state.app.repositoryUrl;
52-
this.feedbackUrl = `${state.app.repositoryUrl}/issues`;
51+
this.repositoryUrl = state.app.info.repositoryWebUrl;
52+
this.feedbackUrl = state.app.info.feedbackUrl;
5353
}
5454
}
5555
</script>

src/presentation/TheFooter/TheFooter.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="footer__section">
55
<span v-if="isDesktop" class="footer__section__item">
66
<font-awesome-icon class="icon" :icon="['fas', 'globe']" />
7-
<span>Online version at <a href="https://privacy.sexy" target="_blank">https://privacy.sexy</a></span>
7+
<span>Online version at <a :href="homepageUrl" target="_blank">{{ homepageUrl }}</a></span>
88
</span>
99
<span v-else class="footer__section__item">
1010
<DownloadUrlList />
@@ -66,6 +66,7 @@ export default class TheFooter extends StatefulVue {
6666
public repositoryUrl: string = '';
6767
public releaseUrl: string = '';
6868
public feedbackUrl: string = '';
69+
public homepageUrl: string = '';
6970
7071
constructor() {
7172
super();
@@ -74,12 +75,15 @@ export default class TheFooter extends StatefulVue {
7475
7576
public async mounted() {
7677
const state = await this.getCurrentStateAsync();
77-
this.version = state.app.version;
78-
this.repositoryUrl = state.app.repositoryUrl;
79-
this.releaseUrl = `${state.app.repositoryUrl}/releases/tag/${state.app.version}`;
80-
this.feedbackUrl = `${state.app.repositoryUrl}/issues`;
78+
const info = state.app.info;
79+
this.version = info.version;
80+
this.homepageUrl = info.homepage;
81+
this.repositoryUrl = info.repositoryWebUrl;
82+
this.releaseUrl = info.releaseUrl;
83+
this.feedbackUrl = info.feedbackUrl;
8184
}
8285
}
86+
8387
</script>
8488

8589
<style scoped lang="scss">

src/presentation/TheHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class TheHeader extends StatefulVue {
1616
1717
public async mounted() {
1818
const state = await this.getCurrentStateAsync();
19-
this.title = state.app.name;
19+
this.title = state.app.info.name;
2020
}
2121
}
2222
</script>

tests/unit/application/Environment/BrowserOs/BrowserOsDetector.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
2+
import { OperatingSystem } from '@/domain/OperatingSystem';
33
import { BrowserOsDetector } from '@/application/Environment/BrowserOs/BrowserOsDetector';
44
import { BrowserOsTestCases } from './BrowserOsTestCases';
55

tests/unit/application/Environment/BrowserOs/BrowserOsTestCases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
1+
import { OperatingSystem } from '@/domain/OperatingSystem';
22

33
interface IBrowserOsTestCase {
44
userAgent: string;

tests/unit/application/Environment/DesktopOsTestCases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
1+
import { OperatingSystem } from '@/domain/OperatingSystem';
22

33
interface IDesktopTestCase {
44
processPlatform: string;

tests/unit/application/Environment/Environment.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IBrowserOsDetector } from '@/application/Environment/BrowserOs/IBrowserOsDetector';
2-
import { OperatingSystem } from '@/application/Environment/OperatingSystem';
2+
import { OperatingSystem } from '@/domain/OperatingSystem';
33
import { DesktopOsTestCases } from './DesktopOsTestCases';
44
import { Environment } from '@/application/Environment/Environment';
55
import { expect } from 'chai';

0 commit comments

Comments
 (0)