Skip to content

Commit

Permalink
Merge pull request #3026 from ever-co/develop
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
evereq authored Sep 15, 2024
2 parents 2d63204 + 8f3fd05 commit a27f0b9
Show file tree
Hide file tree
Showing 160 changed files with 2,696 additions and 997 deletions.
12 changes: 10 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,14 @@
"posthog",
"pageviews",
"pageleave",
"pageview"
"pageview",
"serverweb",
"intefaces",
"Environtment",
"asar",
"icns",
"nsis",
"WARNING️"
],
"useGitignore": true,
"ignorePaths": [
Expand Down Expand Up @@ -415,6 +422,7 @@
"apps/mobile/android/**",
"apps/mobile/ios/**",
"apps/desktop/i18n/**",
"apps/**/*.{svg,css,scss}"
"apps/**/*.{svg,css,scss}",
".scripts/icon-utils/icons/**",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { IContentGenerator } from '../intefaces/i-content-generator';
import { Env } from '../../env';


export class CommonEnvironmentContent implements IContentGenerator {
public generate(variable: Partial<Env>): string {
return `
I18N_FILES_URL: '${variable.I18N_FILES_URL}',
COMPANY_SITE_LINK: '${variable.COMPANY_SITE_LINK}',
COMPANY_GITHUB_LINK: '${variable.COMPANY_GITHUB_LINK}',
`
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IContentGenerator } from '../intefaces/i-content-generator';
import { IDesktopEnvironment } from '../intefaces/i-desktop-environment';

export class DesktopServerWebEnvironmentContent implements IContentGenerator {
public generate(variable: Partial<IDesktopEnvironment>): string {
return `
NAME: '${variable.DESKTOP_SERVER_WEB_APP_NAME || variable.NAME}',
DESCRIPTION: '${variable.DESKTOP_SERVER_WEB_APP_DESCRIPTION || variable.DESCRIPTION}',
APP_ID: '${variable.DESKTOP_SERVER_WEB_APP_ID || variable.APP_ID}',
REPO_NAME: '${variable.DESKTOP_SERVER_WEB_APP_REPO_NAME || variable.REPO_NAME}',
REPO_OWNER: '${variable.DESKTOP_SERVER_WEB_APP_REPO_OWNER || variable.REPO_OWNER}',
WELCOME_TITLE: '${variable.DESKTOP_SERVER_WEB_APP_WELCOME_TITLE || variable.WELCOME_TITLE}',
WELCOME_CONTENT: '${variable.DESKTOP_SERVER_WEB_APP_WELCOME_CONTENT || variable.WELCOME_CONTENT}',
PLATFORM_LOGO: '${variable.PLATFORM_LOGO}',
DESKTOP_SERVER_WEB_APP_DESKTOP_APP_LOGO_512X512: '${variable.DESKTOP_SERVER_WEB_APP_DESKTOP_APP_LOGO_512X512}',
`;
}
}
108 changes: 108 additions & 0 deletions .scripts/electron-desktop-environment/desktop-environment-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { DesktopEnvirontmentContentFactory } from './desktop-environtment-content-factory';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import * as path from 'path';
import * as fs from 'fs';
import { env } from '../env';
import { IDesktopEnvironment } from './intefaces/i-desktop-environment';

const argv: any = yargs(hideBin(process.argv)).argv;


export class DesktopEnvironmentManager {
private static _instance: DesktopEnvironmentManager;
private readonly desktop: string;
private readonly fileDir: string;
private readonly fileName: string;
private readonly isProd: boolean;

private constructor() {
console.log(argv);
this.desktop = String(argv.desktop);
this.isProd = argv.environment === 'prod';
this.fileName = 'config';
this.fileDir = path.join('apps', this.desktop, 'src', 'configs');
}


private static get instance(): DesktopEnvironmentManager {
if (!this._instance) {
this._instance = new DesktopEnvironmentManager();
}
return this._instance;
}

public static get environment(): any {
if (
fs.existsSync(
path.join(
this.instance.fileDir,
this.instance.fileName.concat(`.ts`)
)
)
) {
return require(path.join(
'..',
'..',
this.instance.fileDir,
this.instance.fileName
)).config;
}
return null;
}

public static update(): void {
const environment: IDesktopEnvironment = Object.assign(
{},
this.environment
);
const filePath = path.join(
this.instance.fileDir,
this.instance.fileName.concat('.ts')
);

if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
fs.writeFileSync(
filePath,
this.instance.content(environment, this.instance.isProd)
);
return;
}
console.log(`WARNING: File ${filePath} does not exist`);
}

public static generate(): void {
const files = ['config.ts'];
const environment: Partial<IDesktopEnvironment> = Object.assign({}, env);

for (const file of files) {
const isProd = file === 'config.ts';
const filePath = path.join(this.instance.fileDir, file);
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
fs.writeFileSync(
filePath,
this.instance.content(environment, isProd)
);

console.log(`✔ Generated desktop ${isProd} environment file: ${filePath}`)
}
}


private content(variable: Partial<IDesktopEnvironment>, isProd: boolean): string {
return `
export const config = {
production: ${isProd},
${DesktopEnvirontmentContentFactory.generate(
this.desktop,
variable
)}
};
`;
}
}

DesktopEnvironmentManager.update();
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import { IDesktopEnvironment } from './intefaces/i-desktop-environment';
import { CommonEnvironmentContent } from './concrete-environment-content/common-environment-content';
import { DesktopServerWebEnvironmentContent } from './concrete-environment-content/desktop-server-web-environment-content';

export class DesktopEnvirontmentContentFactory {
public static generate(
desktop: string,
environtment: Partial<IDesktopEnvironment>
) {
const common = new CommonEnvironmentContent();
switch (desktop) {
case 'server-web':
const desktopServerWeb = new DesktopServerWebEnvironmentContent();
return `
${common.generate(environtment)}
${desktopServerWeb.generate(environtment)}
`;
default:
return `
${common.generate(environtment)}
`;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IDesktopEnvironment } from './i-desktop-environment'

export interface IContentGenerator {
generate(variable: Partial<IDesktopEnvironment>): string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Env } from '../../env';

export interface IDesktopEnvironment extends Env {
NAME: string;
DESCRIPTION: string;
APP_ID: string;
REPO_NAME: string;
REPO_OWNER: string;
WELCOME_TITLE: string;
WELCOME_CONTENT: string;
PLATFORM_LOGO: string;
DESKTOP_SERVER_WEB_APP_DESKTOP_APP_LOGO_512X512: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { IPackage } from '../interfaces/i-package';
import { IPackager } from '../interfaces/i-packager';
import { IPackageBuild } from '../interfaces/i-package-build';
import { env } from '../../env';

export class DesktopPackager implements IPackager {
public prepare(pkg: IPackage): IPackage {
pkg.name = env.DESKTOP_SERVER_WEB_APP_NAME || pkg.name;
pkg.productName = env.DESKTOP_SERVER_WEB_APP_DESCRIPTION || pkg.productName;
pkg.description = env.DESKTOP_SERVER_WEB_APP_DESCRIPTION || pkg.description;
pkg.homepage = env.COMPANY_SITE_LINK || pkg.homepage;
pkg.build.appId = env.DESKTOP_SERVER_WEB_APP_ID || pkg.build.appId;
pkg.build.productName =
env.DESKTOP_SERVER_WEB_APP_DESCRIPTION || pkg.build.productName;
pkg.build.linux.executableName =
env.DESKTOP_SERVER_WEB_APP_NAME || pkg.build.linux.executableName;
return pkg;
}

public prepareBuild(pkg: IPackageBuild): IPackageBuild {
pkg.description = env.DESKTOP_SERVER_WEB_APP_DESCRIPTION || pkg.description;
pkg.name = env.DESKTOP_SERVER_WEB_APP_NAME || pkg.name;
return pkg;
}
}
10 changes: 10 additions & 0 deletions .scripts/electron-package-utils/interfaces/i-package-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface IPackageBuild {
name: string;
version: string;
description: string;
author: {
name: string;
email: string;
url: string;
}
}
68 changes: 68 additions & 0 deletions .scripts/electron-package-utils/interfaces/i-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export interface IPackage {
name: string;
productName: string;
version: string;
description: string;
license: string;
homepage: string;
repository: { type: string; url: string };
bugs: { url: string };
private: boolean;
author: { name: string; email: string; url: string };
main: string;
workspaces: { packages: string[] };
build: {
appId: string;
artifactName: string;
productName: string;
copyright: string;
afterSign: string;
dmg: { sign: boolean };
asar: boolean;
npmRebuild: boolean;
asarUnpack: string[];
directories: { buildResources: string; output: string };
publish: {}[];
mac: {
category: string;
icon: string;
target: any[];
asarUnpack: string;
artifactName: string;
hardenedRuntime: boolean;
gatekeeperAssess: boolean;
entitlements: string;
entitlementsInherit: string;
extendInfo: {};
};
win: {
publisherName: string;
target: any[];
icon: string;
verifyUpdateCodeSignature: boolean;
};
linux: {
icon: string;
target: any[];
executableName: string;
artifactName: string;
synopsis: string;
category: string;
};
nsis: {
oneClick: boolean;
perMachine: boolean;
createDesktopShortcut: boolean;
createStartMenuShortcut: boolean;
allowToChangeInstallationDirectory: boolean;
allowElevation: boolean;
installerIcon: string;
artifactName: string;
deleteAppDataOnUninstall: boolean;
menuCategory: boolean;
};
extraResources: (string | object[])[];
extraFiles: string[];
};
dependencies: { [key: string]: string };
}
6 changes: 6 additions & 0 deletions .scripts/electron-package-utils/interfaces/i-packager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IPackage } from './i-package';
import { IPackageBuild } from './i-package-build';
export interface IPackager {
prepare(pkg: IPackage): IPackage;
prepareBuild(pkg: IPackageBuild): IPackageBuild;
}
Loading

0 comments on commit a27f0b9

Please sign in to comment.