兼容二进制打包

This commit is contained in:
COOL 2025-01-14 19:46:28 +08:00
parent da2bab9d71
commit b5b448689f
5 changed files with 11 additions and 8 deletions

View File

@ -50,3 +50,4 @@ export * from './module/menu';
export * from './interface';
export * from './util/func';
export * from './constant/global';
export * from './util/location';

View File

@ -32,7 +32,7 @@ export class CoolModuleConfig {
async init() {
const modules = [];
// 模块路径
const moduleBasePath = `${location.getRootPath()}/modules/`;
const moduleBasePath = `${location.getRunPath()}/modules/`;
if (!fs.existsSync(moduleBasePath)) {
return;
@ -49,7 +49,6 @@ export class CoolModuleConfig {
const configPath = fs.existsSync(`${modulePath}/config.ts`)
? `${modulePath}/config.ts`
: `${modulePath}/config.js`;
console.log('configPath', configPath);
if (fs.existsSync(configPath)) {
const moduleConfig: ModuleConfig = require(configPath).default({
app: this.app,

View File

@ -112,7 +112,7 @@ export class CoolModuleImport {
*/
checkFileExist(module: string) {
const importLockPath = path.join(
`${location.getRootPath()}`,
`${location.getRunPath()}`,
'..',
'lock',
'db'
@ -136,7 +136,7 @@ export class CoolModuleImport {
// 计算耗时
const startTime = new Date().getTime();
// 模块路径
const modulePath = `${location.getRootPath()}/modules/${module}`;
const modulePath = `${location.getRunPath()}/modules/${module}`;
// 数据路径
const dataPath = `${modulePath}/db.json`;
// 判断文件是否存在

View File

@ -87,7 +87,7 @@ export class CoolModuleMenu {
*/
async importMenu(module: string, metadatas, lockPath?: string) {
// 模块路径
const modulePath = `${location.getRootPath()}/modules/${module}`;
const modulePath = `${location.getRunPath()}/modules/${module}`;
// json 路径
const menuPath = `${modulePath}/menu.json`;
// 导入
@ -139,7 +139,7 @@ export class CoolModuleMenu {
*/
checkFileExist(module: string) {
const importLockPath = path.join(
`${location.getRootPath()}`,
`${location.getRunPath()}`,
'..',
'lock',
'menu'

View File

@ -1,10 +1,13 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import * as fs from 'fs';
import * as path from 'path';
/**
* Location
*/
class LocationUtil {
@Provide()
@Scope(ScopeEnum.Singleton)
export class LocationUtil {
private locationCache = new Map<string, any>();
/**
@ -56,7 +59,7 @@ class LocationUtil {
* 使
* @returns
*/
getRootPath(): string {
getRunPath(): string {
const err = new Error();
const callerfile = err.stack.split('\n')[2].match(/\(([^)]+)\)/)[1];
const dirPath = path.dirname(callerfile);