Skip to content

Commit

Permalink
Merge branch 'develop' into chore/upgrade-ng-to-19
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-rocket committed Jan 2, 2025
2 parents b925368 + 2bea2ec commit 28be36a
Show file tree
Hide file tree
Showing 105 changed files with 1,661 additions and 761 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@
"Theora",
"Unregisters",
"allwindows",
"Johndoe"
"Johndoe",
"minizlib"
],
"useGitignore": true,
"ignorePaths": [
Expand Down
41 changes: 41 additions & 0 deletions apps/api/src/load-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as fs from 'fs';
import * as path from 'path';
import * as dotenv from 'dotenv';

/**
* Load environment variables from a specified file.
*
* @param {string} envPath - The absolute path to the .env file.
* @param {object} options - Options for dotenv configuration.
* @param {boolean} [options.override=false] - Whether to override existing environment variables.
*/
export function loadEnvFile(envPath: string, options: { override?: boolean } = {}): void {
if (fs.existsSync(envPath)) {
console.time(`✔ Load ${path.basename(envPath)} Time`);
console.log(`Loading environment variables from: ${envPath}${options.override ? ' (override)' : ''}`);
dotenv.config({ path: envPath, ...options });
console.timeEnd(`✔ Load ${path.basename(envPath)} Time`);
}
}

/**
* Load environment variables from .env and .env.local files.
*/
export function loadEnv(): void {
const currentDir = process.cwd();
console.log('Current API Directory:', currentDir);

// Define paths for environment files
const envPaths = {
env: path.resolve(currentDir, '.env'),
envLocal: path.resolve(currentDir, '.env.local'),
};

console.log(`API Environment Paths: .env -> ${envPaths.env}, .env.local -> ${envPaths.envLocal}`);

// Load .env file with override
loadEnvFile(envPaths.env, { override: true });

// Load .env.local file without overriding existing variables
loadEnvFile(envPaths.envLocal);
}
6 changes: 6 additions & 0 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import * as chalk from 'chalk';
import { loadEnv } from './load-env';

// Load environment variables
console.log('Loading Environment Variables...');
loadEnv();
console.log('Environment Variables Loaded');

// Start measuring the overall API startup time
console.time(chalk.green(`✔ Total API Startup Time`));
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-timer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as remoteMain from '@electron/remote/main';
import * as Sentry from '@sentry/electron';
import { setupTitlebar } from 'custom-electron-titlebar/main';
import { app, BrowserWindow, ipcMain, Menu, MenuItemConstructorOptions, nativeTheme, shell } from 'electron';
import Store from 'electron-store';
import * as Store from 'electron-store';
import * as path from 'path';
import * as Url from 'url';
import { environment } from './environments/environment';
Expand Down
1 change: 0 additions & 1 deletion apps/desktop-timer/tsconfig.electron.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"downlevelIteration": true,
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2022",
"types": []
Expand Down
24 changes: 16 additions & 8 deletions apps/desktop/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import * as remoteMain from '@electron/remote/main';
import { setupTitlebar } from 'custom-electron-titlebar/main';
import { BrowserWindow, Menu, MenuItemConstructorOptions, app, dialog, ipcMain, nativeTheme, shell } from 'electron';
import * as path from 'path';
import Store from 'electron-store';
import * as Store from 'electron-store';

import { environment } from './environments/environment';

require('module').globalPaths.push(path.join(__dirname, 'node_modules'));
console.log('Desktop Node Modules Path', path.join(__dirname, 'node_modules'));

Object.assign(process.env, environment);

app.setName(process.env.NAME);

console.log('Desktop Node Modules Path', path.join(__dirname, 'node_modules'));

remoteMain.initialize();

import {
Expand Down Expand Up @@ -299,7 +298,7 @@ async function startServer(value, restart = false) {
process.env.DB_NAME = value['postgres']?.dbName;
process.env.DB_USER = value['postgres']?.dbUsername;
process.env.DB_PASS = value['postgres']?.dbPassword;
}
}

try {
const config: any = {
Expand All @@ -325,13 +324,19 @@ async function startServer(value, restart = false) {
}

if (value.isLocalServer) {
console.log(`Starting local server on port ${value.port || environment.API_DEFAULT_PORT}`);
process.env.API_PORT = value.port || environment.API_DEFAULT_PORT;
process.env.API_HOST = '0.0.0.0';
process.env.API_BASE_URL = `http://127.0.0.1:${value.port || environment.API_DEFAULT_PORT}`;

console.log('Setting additional environment variables...', process.env.API_PORT);
console.log('Setting additional environment variables...', process.env.API_HOST);
console.log('Setting additional environment variables...', process.env.API_BASE_URL);

setEnvAdditional();

try {
console.log('Starting local server...', path.join(__dirname, 'api/main.js'));
await server.start({ api: path.join(__dirname, 'api/main.js') }, process.env, setupWindow, signal);
} catch (error) {
console.error('ERROR: Occurred while server start:' + error);
Expand Down Expand Up @@ -443,17 +448,21 @@ export const getApiBaseUrl = (configs: ApiConfig): string => {
}

// Otherwise, build the URL dynamically using the host, protocol, and port
const protocol = configs.protocol ?? 'http'; // default protocol
const host = configs.host ?? '127.0.0.1'; // default host
const port = configs.port ?? environment.API_DEFAULT_PORT;
const protocol = configs.protocol ?? 'http'; // default protocol
const host = '127.0.0.1'; // default host
const port = configs.port ?? environment.API_DEFAULT_PORT; // default port

console.log('get configs.protocol', configs.protocol);
console.log('get configs.host', configs.host);
console.log('get configs.port', configs.port);

console.log('Building API URL...', `${protocol}://${host}:${port}`);
return `${protocol}://${host}:${port}`;
};

/**
* Closes the splash screen.
*/
const closeSplashScreen = () => {
if (splashScreen) {
splashScreen.close();
Expand Down Expand Up @@ -481,7 +490,6 @@ app.on('ready', async () => {

try {
splashScreen = new SplashScreen(pathWindow.timeTrackerUi);

await splashScreen.loadURL();

splashScreen.show();
Expand Down
1 change: 0 additions & 1 deletion apps/desktop/tsconfig.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"target": "ES2022",
"lib": [
"es2020",
Expand Down
1 change: 0 additions & 1 deletion apps/desktop/tsconfig.electron.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"downlevelIteration": true,
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2022",
"types": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Observable } from 'rxjs/internal/Observable';
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
import { Subject } from 'rxjs/internal/Subject';
import { chain, indexBy, pick, sortBy } from 'underscore';
import moment from 'moment-timezone';
import * as moment from 'moment-timezone';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { NbDialogService } from '@nebular/theme';
import { TranslateService } from '@ngx-translate/core';
Expand Down
1 change: 0 additions & 1 deletion apps/server-api/tsconfig.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"target": "ES2022",
"lib": [
"es2020",
Expand Down
1 change: 0 additions & 1 deletion apps/server-api/tsconfig.electron.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"downlevelIteration": true,
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2022",
"types": []
Expand Down
1 change: 0 additions & 1 deletion apps/server/tsconfig.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"target": "ES2022",
"lib": [
"es2020",
Expand Down
1 change: 0 additions & 1 deletion apps/server/tsconfig.electron.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"downlevelIteration": true,
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2022",
"types": []
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@
"migration:generate": "yarn db:migration migration:generate",
"migration:create": "yarn db:migration migration:create",
"migration:command": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn --cwd ./packages/core",
"seed": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed.ts",
"seed:ever": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed-ever.ts",
"seed:all": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed-all.ts",
"seed:jobs": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed-jobs.ts",
"seed:module": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn build:package:all && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed-module.ts --name",
"seed:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn build:package:all && yarn run config:prod && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed.ts",
"seed:base": "cross-env NODE_OPTIONS=--max-old-space-size=12288 yarn run config:dev && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json",
"seed": "yarn seed:base ./apps/api/src/seed.ts",
"seed:ever": "yarn seed:base ./apps/api/src/seed-ever.ts",
"seed:all": "yarn seed:base ./apps/api/src/seed-all.ts",
"seed:jobs": "yarn seed:base ./apps/api/src/seed-jobs.ts",
"seed:module": "yarn seed:base ./apps/api/src/seed-module.ts --name",
"seed:prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=12288 yarn build:package:all:prod && yarn run config:prod && yarn ts-node -r tsconfig-paths/register --project apps/api/tsconfig.app.json ./apps/api/src/seed.ts",
"prebuild": "rimraf dist coverage",
"bootstrap": "yarn install --ignore-scripts && yarn postinstall.manual",
"build": "yarn build:package:all && concurrently --raw \"yarn build:api\" \"yarn build:gauzy\"",
Expand Down Expand Up @@ -376,7 +377,8 @@
"camelcase": "^6.3.0",
"rxjs": "^7.8.0",
"autoprefixer": "^10.4.20",
"locutus": "^2.0.30"
"locutus": "^2.0.30",
"minizlib": "^2.1.2"
},
"dependencies": {
"@angular/animations": "19.0.5",
Expand Down Expand Up @@ -409,6 +411,7 @@
"electron": "^30.0.1",
"jsdom": "^23.0.1",
"lodash-es": "^4.17.21",
"minizlib": "^2.1.2",
"parse5": "^7.1.2",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { useContainer } from 'class-validator';
import * as expressSession from 'express-session';
import RedisStore from 'connect-redis';
import { createClient } from 'redis';
import helmet from 'helmet';
import * as helmet from 'helmet';
import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import multer from 'multer';
import * as multer from 'multer';
import * as path from 'path';
import { FileStorage } from '../file-storage';
import { DirectoryPathGenerator } from './directory-path-generator';
Expand All @@ -8,6 +8,16 @@ import { IDirectoryPathGenerator } from './directory-path-generator.interface';
export class FileStorageFactory {
private static readonly pathGenerator: IDirectoryPathGenerator = new DirectoryPathGenerator();

/**
* Creates a multer storage engine configured with a custom file storage system.
*
* This function generates the base directory and subdirectory paths based on
* the provided `baseDirname`, and returns a `multer.StorageEngine` instance
* that saves files to these paths.
*
* @param {string} baseDirname - The base directory name used to generate the file storage path.
* @returns {multer.StorageEngine} - A multer storage engine configured to store files.
*/
public static create(baseDirname: string): multer.StorageEngine {
const baseDirectory = this.pathGenerator.getBaseDirectory(baseDirname);
const subDirectory = this.pathGenerator.getSubDirectory();
Expand Down
91 changes: 57 additions & 34 deletions packages/core/src/lib/core/seeds/seed-module.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,74 @@
// Modified code from https://github.com/alexitaylor/angular-graphql-nestjs-postgres-starter-kit.
// MIT License, see https://github.com/alexitaylor/angular-graphql-nestjs-postgres-starter-kit/blob/master/LICENSE
// Copyright (c) 2019 Alexi Taylor

import yargs from 'yargs';
import * as chalk from 'chalk';

import { NestFactory } from '@nestjs/core';
import * as yargs from 'yargs';
import * as chalk from 'chalk';
import { ApplicationPluginConfig } from '@gauzy/common';
import { registerPluginConfig } from './../../bootstrap';
import { SeedDataService } from './seed-data.service';
import { SeederModule } from './seeder.module';

/**
* Usage:
* yarn seed:module All
* yarn seed:module Default
* yarn seed:module Jobs
* yarn seed:module Reports
* yarn seed:module Ever
*
*/
export async function seedModule(devConfig: Partial<ApplicationPluginConfig>) {
await registerPluginConfig(devConfig);
* Seeds data for a specified module using the provided configuration.
*
* This function dynamically executes a seeding method in the `SeedDataService`
* based on the module name provided as a command-line argument. The method must
* exist in the `SeedDataService` and be named in the format `run<ModuleName>Seed`.
*
* @param {Partial<ApplicationPluginConfig>} devConfig - The development configuration
* for plugins, which will be registered before running the seeding process.
* @returns {Promise<void>} - A promise that resolves when the seeding process is complete.
*
* ## Usage:
* Run the command with `yarn` and specify the module name:
* ```
* yarn seed:module All
* yarn seed:module Default
* yarn seed:module Jobs
* yarn seed:module Reports
* yarn seed:module Ever
* ```
*/
export async function seedModule(devConfig: Partial<ApplicationPluginConfig>): Promise<void> {
try {
// Register the plugin configuration
await registerPluginConfig(devConfig);

NestFactory.createApplicationContext(SeederModule.forPlugins(), {
logger: ['log', 'error', 'warn', 'debug', 'verbose']
}).then((app) => {
const seeder = app.get(SeedDataService);
const argv: any = yargs(process.argv).argv;
const module = argv.name;
// Create the application context
const app = await NestFactory.createApplicationContext(SeederModule.forPlugins(), {
logger: ['log', 'error', 'warn', 'debug', 'verbose']
});

// Extract the module name from command-line arguments
const { name: module } = yargs(process.argv).argv as { name?: string };
if (!module) {
console.log(chalk.red('No module name provided. Please specify a module name.'));
await app.close();
return;
}

// Build the seed method name dynamically
const methodName = `run${module}Seed`;
const seeder = app.get(SeedDataService);

if (seeder[methodName]) {
seeder[methodName]()
.catch((error) => {
throw error;
})
.finally(() => app.close());
// Check if the method exists in the SeedDataService
if (typeof seeder[methodName] === 'function') {
try {
await seeder[methodName]();
console.log(chalk.green(`Successfully ran seed method: ${methodName}`));
} catch (error) {
console.error(chalk.red(`Error executing ${methodName}: ${error.message}`));
throw error;
}
} else {
console.log(
chalk.red(
`Method ${methodName} not found in SeedDataService`
)
);
app.close();
console.log(chalk.red(`Method ${methodName} not found in SeedDataService`));
}
}).catch((error) => {

// Close the application context
await app.close();
} catch (error) {
console.error(chalk.red(`Failed to seed module: ${error.message}`));
throw error;
});
}
}
Loading

0 comments on commit 28be36a

Please sign in to comment.