Compare commits
2 Commits
cacc53a184
...
ae60273782
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae60273782 | ||
|
|
fb6f2bbc02 |
18
config/.env.example
Normal file
18
config/.env.example
Normal file
@@ -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
|
||||
19
config/app.json
Normal file
19
config/app.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
7
config/development.json
Normal file
7
config/development.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"logLevel": "debug",
|
||||
"browser": {
|
||||
"headless": false,
|
||||
"slowMo": 100
|
||||
}
|
||||
}
|
||||
103
src/main/config/app.config.ts
Normal file
103
src/main/config/app.config.ts
Normal file
@@ -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<AppConfig> = {};
|
||||
if (fs.existsSync(envConfigPath)) {
|
||||
envConfig = JSON.parse(fs.readFileSync(envConfigPath, 'utf-8'));
|
||||
}
|
||||
|
||||
// Load environment variables
|
||||
const envVars: Partial<AppConfig> = 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<AppConfig> {
|
||||
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 || '',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
46
src/main/models/config.types.ts
Normal file
46
src/main/models/config.types.ts
Normal file
@@ -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;
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [{ "path": "./tsconfig.node.json" }, { "path": "./tsconfig.web.json" }]
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "tests"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user