fix: mkdir first
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import { Logger, MiddlewareConsumer, Module, NestModule } from '@nestjs/common'
|
||||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'
|
||||
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'
|
||||
import cluster from 'cluster'
|
||||
import { mkdirSync } from 'fs'
|
||||
import { CLUSTER } from './app.config'
|
||||
import { AppController } from './app.controller'
|
||||
import { AllExceptionsFilter } from './common/filters/any-exception.filter'
|
||||
import { RolesGuard } from './common/guard/roles.guard'
|
||||
@@ -12,12 +9,6 @@ import { CountingInterceptor } from './common/interceptors/counting.interceptor'
|
||||
import { JSONSerializeInterceptor } from './common/interceptors/json-serialize.interceptor'
|
||||
import { ResponseInterceptor } from './common/interceptors/response.interceptor'
|
||||
import { AttachHeaderTokenMiddleware } from './common/middlewares/attach-auth.middleware'
|
||||
import {
|
||||
DATA_DIR,
|
||||
LOG_DIR,
|
||||
TEMP_DIR,
|
||||
USER_ASSET_DIR,
|
||||
} from './constants/path.constant'
|
||||
import { AggregateModule } from './modules/aggregate/aggregate.module'
|
||||
import { AnalyzeModule } from './modules/analyze/analyze.module'
|
||||
import { AuthModule } from './modules/auth/auth.module'
|
||||
@@ -51,22 +42,6 @@ import { GatewayModule } from './processors/gateway/gateway.module'
|
||||
import { HelperModule } from './processors/helper/helper.module'
|
||||
import { LoggerModule } from './processors/logger/logger.module'
|
||||
|
||||
// FIXME
|
||||
function mkdirs() {
|
||||
mkdirSync(DATA_DIR, { recursive: true })
|
||||
Logger.log(chalk.blue('数据目录已经建好: ' + DATA_DIR))
|
||||
mkdirSync(TEMP_DIR, { recursive: true })
|
||||
Logger.log(chalk.blue('临时目录已经建好: ' + TEMP_DIR))
|
||||
mkdirSync(LOG_DIR, { recursive: true })
|
||||
Logger.log(chalk.blue('日志目录已经建好: ' + LOG_DIR))
|
||||
mkdirSync(USER_ASSET_DIR, { recursive: true })
|
||||
Logger.log(chalk.blue('资源目录已经建好: ' + USER_ASSET_DIR))
|
||||
}
|
||||
|
||||
if (!CLUSTER.enable || cluster.isPrimary) {
|
||||
mkdirs()
|
||||
}
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
DatabaseModule,
|
||||
|
||||
@@ -1,17 +1,48 @@
|
||||
import { Logger } from '@nestjs/common'
|
||||
import cluster from 'cluster'
|
||||
import { mkdirSync } from 'fs'
|
||||
import 'zx/globals'
|
||||
import { CLUSTER } from '~/app.config'
|
||||
import {
|
||||
DATA_DIR,
|
||||
LOG_DIR,
|
||||
TEMP_DIR,
|
||||
USER_ASSET_DIR,
|
||||
} from '~/constants/path.constant'
|
||||
import { consola } from './consola.global'
|
||||
import './dayjs.global'
|
||||
import { isDev } from './env.global'
|
||||
|
||||
$.verbose = isDev
|
||||
|
||||
console.debug = (...rest) => {
|
||||
if (isDev) {
|
||||
consola.log.call(console, ...rest)
|
||||
// 建立目录
|
||||
function mkdirs() {
|
||||
if (!CLUSTER.enable || cluster.isPrimary) {
|
||||
mkdirSync(DATA_DIR, { recursive: true })
|
||||
Logger.log(chalk.blue('数据目录已经建好: ' + DATA_DIR))
|
||||
mkdirSync(TEMP_DIR, { recursive: true })
|
||||
Logger.log(chalk.blue('临时目录已经建好: ' + TEMP_DIR))
|
||||
mkdirSync(LOG_DIR, { recursive: true })
|
||||
Logger.log(chalk.blue('日志目录已经建好: ' + LOG_DIR))
|
||||
mkdirSync(USER_ASSET_DIR, { recursive: true })
|
||||
Logger.log(chalk.blue('资源目录已经建好: ' + USER_ASSET_DIR))
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(globalThis, {
|
||||
isDev: isDev,
|
||||
consola,
|
||||
})
|
||||
function registerGlobal() {
|
||||
$.verbose = isDev
|
||||
|
||||
console.debug = (...rest) => {
|
||||
if (isDev) {
|
||||
consola.log.call(console, ...rest)
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(globalThis, {
|
||||
isDev: isDev,
|
||||
consola,
|
||||
})
|
||||
}
|
||||
|
||||
export function register() {
|
||||
mkdirs()
|
||||
registerGlobal()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// register global
|
||||
import './global/index.global'
|
||||
import { register } from './global/index.global'
|
||||
|
||||
async function main() {
|
||||
register()
|
||||
const [{ bootstrap }, { CLUSTER }, { Cluster }] = await Promise.all([
|
||||
import('./bootstrap'),
|
||||
import('./app.config'),
|
||||
|
||||
Reference in New Issue
Block a user