diff --git a/config/.env.example b/config/.env.example new file mode 100644 index 0000000..077c3d5 --- /dev/null +++ b/config/.env.example @@ -0,0 +1,18 @@ +# SQL Server +SQL_SERVER_SERVER=192.168.110.114 +SQL_SERVER_DATABASE=CompanyDB +SQL_SERVER_USERNAME=peng +SQL_SERVER_PASSWORD=your_password_here +SQL_SERVER_DRIVER=ODBC Driver 18 for SQL Server +SQL_SERVER_TRUST_CERT=yes + +# MySQL +MYSQL_HOST=localhost +MYSQL_PORT=3306 +MYSQL_DATABASE=erp_db +MYSQL_USERNAME=root +MYSQL_PASSWORD=your_password_here + +# ERP Credentials (optional, can also be entered in UI) +ERP_USERNAME=BLDpengqiangqiang +ERP_PASSWORD=your_password_here diff --git a/config/app.json b/config/app.json new file mode 100644 index 0000000..5ad2388 --- /dev/null +++ b/config/app.json @@ -0,0 +1,19 @@ +{ + "appName": "ERPAuto", + "version": "1.0.0", + "logLevel": "info", + "browser": { + "headless": false, + "slowMo": 50, + "timeout": 30000 + }, + "erp": { + "baseUrl": "https://68.11.34.30:8082", + "ignoreHttpsErrors": true + }, + "paths": { + "tempDir": "./data/temp", + "outputDir": "./data/output", + "reportDir": "./data/reports" + } +} diff --git a/config/development.json b/config/development.json new file mode 100644 index 0000000..e42335c --- /dev/null +++ b/config/development.json @@ -0,0 +1,7 @@ +{ + "logLevel": "debug", + "browser": { + "headless": false, + "slowMo": 100 + } +} diff --git a/src/main/config/app.config.ts b/src/main/config/app.config.ts new file mode 100644 index 0000000..957bdd5 --- /dev/null +++ b/src/main/config/app.config.ts @@ -0,0 +1,103 @@ +import fs from 'fs'; +import path from 'path'; +import { AppConfig } from '../models/config.types'; + +export class ConfigManager { + private static instance: AppConfig | null = null; + + static load(): AppConfig { + if (this.instance) { + return this.instance; + } + + // Load default config + const defaultConfig = this.getDefaultConfig(); + + // Load environment-specific config + const env = process.env.NODE_ENV || 'development'; + const envConfigPath = path.join(__dirname, `../../../config/${env}.json`); + + let envConfig: Partial = {}; + if (fs.existsSync(envConfigPath)) { + envConfig = JSON.parse(fs.readFileSync(envConfigPath, 'utf-8')); + } + + // Load environment variables + const envVars: Partial = this.loadFromEnv(); + + this.instance = { + ...defaultConfig, + ...envConfig, + ...envVars, + }; + + return this.instance; + } + + private static getDefaultConfig(): AppConfig { + const appConfigPath = path.join(__dirname, '../../../config/app.json'); + if (fs.existsSync(appConfigPath)) { + return JSON.parse(fs.readFileSync(appConfigPath, 'utf-8')); + } + + // Fallback defaults + return { + appName: 'ERPAuto', + version: '1.0.0', + logLevel: 'info', + browser: { + headless: false, + slowMo: 50, + timeout: 30000, + }, + databases: { + sqlServer: { + server: '192.168.110.114', + database: 'CompanyDB', + username: 'peng', + password: '', + driver: 'ODBC Driver 18 for SQL Server', + trustServerCertificate: 'yes', + }, + mysql: { + host: 'localhost', + port: 3306, + database: 'erp_db', + username: 'root', + password: '', + }, + }, + erp: { + baseUrl: 'https://68.11.34.30:8082', + ignoreHttpsErrors: true, + }, + paths: { + tempDir: './data/temp', + outputDir: './data/output', + reportDir: './data/reports', + }, + }; + } + + private static loadFromEnv(): Partial { + return { + databases: { + sqlServer: { + server: process.env.SQL_SERVER_SERVER || '', + database: process.env.SQL_SERVER_DATABASE || '', + username: process.env.SQL_SERVER_USERNAME || '', + password: process.env.SQL_SERVER_PASSWORD || '', + driver: process.env.SQL_SERVER_DRIVER || '', + trustServerCertificate: process.env.SQL_SERVER_TRUST_CERT || 'yes', + }, + mysql: { + host: process.env.MYSQL_HOST || 'localhost', + port: parseInt(process.env.MYSQL_PORT || '3306'), + database: process.env.MYSQL_DATABASE || '', + username: process.env.MYSQL_USERNAME || '', + password: process.env.MYSQL_PASSWORD || '', + }, + }, + }; + } +} diff --git a/src/main/models/config.types.ts b/src/main/models/config.types.ts new file mode 100644 index 0000000..c3635ee --- /dev/null +++ b/src/main/models/config.types.ts @@ -0,0 +1,46 @@ +export interface SQLServerConfig { + server: string; + database: string; + username: string; + password: string; + driver: string; + trustServerCertificate?: string; +} + +export interface MySQLConfig { + host: string; + port: number; + database: string; + username: string; + password: string; +} + +export interface BrowserConfig { + headless: boolean; + slowMo: number; + timeout: number; +} + +export interface ERPConfig { + baseUrl: string; + ignoreHttpsErrors: boolean; +} + +export interface PathConfig { + tempDir: string; + outputDir: string; + reportDir: string; +} + +export interface AppConfig { + appName: string; + version: string; + logLevel: 'debug' | 'info' | 'warn' | 'error'; + browser: BrowserConfig; + databases: { + sqlServer: SQLServerConfig; + mysql: MySQLConfig; + }; + erp: ERPConfig; + paths: PathConfig; +}