-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into chore/upgrade-ng-to-19
- Loading branch information
Showing
105 changed files
with
1,661 additions
and
761 deletions.
There are no files selected for viewing
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
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); | ||
} |
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
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
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
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; | ||
}); | ||
} | ||
} |
Oops, something went wrong.