mirror of
https://github.com/cool-team-official/cool-admin-midway-packages.git
synced 2025-12-11 05:42:49 +00:00
兼容二进制打包
This commit is contained in:
parent
da2bab9d71
commit
b5b448689f
@ -50,3 +50,4 @@ export * from './module/menu';
|
||||
export * from './interface';
|
||||
export * from './util/func';
|
||||
export * from './constant/global';
|
||||
export * from './util/location';
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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`;
|
||||
// 判断文件是否存在
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user