mirror of
https://github.com/cool-team-official/cool-admin-midway-packages.git
synced 2026-02-18 07:43: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 './interface';
|
||||||
export * from './util/func';
|
export * from './util/func';
|
||||||
export * from './constant/global';
|
export * from './constant/global';
|
||||||
|
export * from './util/location';
|
||||||
|
|||||||
@ -32,7 +32,7 @@ export class CoolModuleConfig {
|
|||||||
async init() {
|
async init() {
|
||||||
const modules = [];
|
const modules = [];
|
||||||
// 模块路径
|
// 模块路径
|
||||||
const moduleBasePath = `${location.getRootPath()}/modules/`;
|
const moduleBasePath = `${location.getRunPath()}/modules/`;
|
||||||
|
|
||||||
if (!fs.existsSync(moduleBasePath)) {
|
if (!fs.existsSync(moduleBasePath)) {
|
||||||
return;
|
return;
|
||||||
@ -49,7 +49,6 @@ export class CoolModuleConfig {
|
|||||||
const configPath = fs.existsSync(`${modulePath}/config.ts`)
|
const configPath = fs.existsSync(`${modulePath}/config.ts`)
|
||||||
? `${modulePath}/config.ts`
|
? `${modulePath}/config.ts`
|
||||||
: `${modulePath}/config.js`;
|
: `${modulePath}/config.js`;
|
||||||
console.log('configPath', configPath);
|
|
||||||
if (fs.existsSync(configPath)) {
|
if (fs.existsSync(configPath)) {
|
||||||
const moduleConfig: ModuleConfig = require(configPath).default({
|
const moduleConfig: ModuleConfig = require(configPath).default({
|
||||||
app: this.app,
|
app: this.app,
|
||||||
|
|||||||
@ -112,7 +112,7 @@ export class CoolModuleImport {
|
|||||||
*/
|
*/
|
||||||
checkFileExist(module: string) {
|
checkFileExist(module: string) {
|
||||||
const importLockPath = path.join(
|
const importLockPath = path.join(
|
||||||
`${location.getRootPath()}`,
|
`${location.getRunPath()}`,
|
||||||
'..',
|
'..',
|
||||||
'lock',
|
'lock',
|
||||||
'db'
|
'db'
|
||||||
@ -136,7 +136,7 @@ export class CoolModuleImport {
|
|||||||
// 计算耗时
|
// 计算耗时
|
||||||
const startTime = new Date().getTime();
|
const startTime = new Date().getTime();
|
||||||
// 模块路径
|
// 模块路径
|
||||||
const modulePath = `${location.getRootPath()}/modules/${module}`;
|
const modulePath = `${location.getRunPath()}/modules/${module}`;
|
||||||
// 数据路径
|
// 数据路径
|
||||||
const dataPath = `${modulePath}/db.json`;
|
const dataPath = `${modulePath}/db.json`;
|
||||||
// 判断文件是否存在
|
// 判断文件是否存在
|
||||||
|
|||||||
@ -87,7 +87,7 @@ export class CoolModuleMenu {
|
|||||||
*/
|
*/
|
||||||
async importMenu(module: string, metadatas, lockPath?: string) {
|
async importMenu(module: string, metadatas, lockPath?: string) {
|
||||||
// 模块路径
|
// 模块路径
|
||||||
const modulePath = `${location.getRootPath()}/modules/${module}`;
|
const modulePath = `${location.getRunPath()}/modules/${module}`;
|
||||||
// json 路径
|
// json 路径
|
||||||
const menuPath = `${modulePath}/menu.json`;
|
const menuPath = `${modulePath}/menu.json`;
|
||||||
// 导入
|
// 导入
|
||||||
@ -139,7 +139,7 @@ export class CoolModuleMenu {
|
|||||||
*/
|
*/
|
||||||
checkFileExist(module: string) {
|
checkFileExist(module: string) {
|
||||||
const importLockPath = path.join(
|
const importLockPath = path.join(
|
||||||
`${location.getRootPath()}`,
|
`${location.getRunPath()}`,
|
||||||
'..',
|
'..',
|
||||||
'lock',
|
'lock',
|
||||||
'menu'
|
'menu'
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
|
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Location 工具类
|
* Location 工具类
|
||||||
*/
|
*/
|
||||||
class LocationUtil {
|
@Provide()
|
||||||
|
@Scope(ScopeEnum.Singleton)
|
||||||
|
export class LocationUtil {
|
||||||
private locationCache = new Map<string, any>();
|
private locationCache = new Map<string, any>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +59,7 @@ class LocationUtil {
|
|||||||
* 获取使用此包的项目的真实根目录路径
|
* 获取使用此包的项目的真实根目录路径
|
||||||
* @returns 项目根目录的绝对路径
|
* @returns 项目根目录的绝对路径
|
||||||
*/
|
*/
|
||||||
getRootPath(): string {
|
getRunPath(): string {
|
||||||
const err = new Error();
|
const err = new Error();
|
||||||
const callerfile = err.stack.split('\n')[2].match(/\(([^)]+)\)/)[1];
|
const callerfile = err.stack.split('\n')[2].match(/\(([^)]+)\)/)[1];
|
||||||
const dirPath = path.dirname(callerfile);
|
const dirPath = path.dirname(callerfile);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user