fix: remove path fro dev, use progress.resolve() replace

This commit is contained in:
熊潇 2024-11-22 22:26:48 +08:00
parent 9e1881d06e
commit 3288b64dbf
4 changed files with 15 additions and 26 deletions

View File

@ -6,10 +6,11 @@
"type": { "type": {
"type": "string", "type": "string",
"enum": [ "enum": [
"inline-app", "system-app",
"micro-app" "micro-app",
"gateway-app"
], ],
"$comment": "Type must be either 'inline-app' or 'micro-app'" "$comment": "Type must be either 'system-app' or 'micro-app' or 'gateway-app'."
}, },
"single": { "single": {
"type": "boolean", "type": "boolean",
@ -36,7 +37,8 @@
"required": [ "required": [
"host", "host",
"path" "path"
] ],
"$comment": "远程服务的地址和路径"
}, },
"micro": { "micro": {
"type": "object", "type": "object",

View File

@ -1,12 +1,16 @@
{ {
"name": "@kevisual/user-config", "name": "@kevisual/use-config",
"version": "1.0.1", "version": "1.0.2",
"types": "dist/config.d.ts", "types": "dist/config.d.ts",
"scripts": { "scripts": {
"build": "npm run clean && rollup -c", "build": "npm run clean && rollup -c",
"watch": " rollup -c -w", "watch": " rollup -c -w",
"clean": "rimraf dist" "clean": "rimraf dist"
}, },
"publishConfig": {
"access": "public"
},
"files": [ "files": [
"dist", "dist",
"src", "src",

View File

@ -1,10 +1,6 @@
import JSON5 from 'json5'; import JSON5 from 'json5';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url); // 当前模块的文件路径
const __dirname = path.dirname(__filename); // 当前模块的目录路径
// 配置类型 // 配置类型
export type Config = { export type Config = {
@ -51,11 +47,7 @@ export const fileIsExist = (path: string) => {
} }
}; };
export const getDirname = () => { export const getDirname = () => {
const isDev = getNODE_ENV() === 'development';
if (isDev) {
return path.resolve(); return path.resolve();
}
return __dirname;
}; };
export const getConfigFile = (fileName = 'app.config.json5') => { export const getConfigFile = (fileName = 'app.config.json5') => {
const dirname = getDirname(); const dirname = getDirname();
@ -133,7 +125,3 @@ export const deleteContext = (key: string): any => {
} }
return _context; return _context;
}; };
export const getNODE_ENV = (): string => {
return process?.env?.NODE_ENV || 'production';
};

View File

@ -1,12 +1,7 @@
import path from 'path';
import fs from 'fs'; import fs from 'fs';
import type { App } from './read-app-schema.ts'; import type { App } from './read-app-schema.ts';
import { fileURLToPath } from 'url';
import { getConfigFile } from './config.ts'; import { getConfigFile } from './config.ts';
const __filename = fileURLToPath(import.meta.url); // 当前模块的文件路径
const __dirname = path.dirname(__filename); // 当前模块的目录路径
export const getPkgs = () => { export const getPkgs = () => {
const configFile = getConfigFile(); const configFile = getConfigFile();
if (!configFile) { if (!configFile) {
@ -17,7 +12,7 @@ export const getPkgs = () => {
return config; return config;
}; };
export const getApps = (): App => { export const getApp = (): App => {
const config = getPkgs(); const config = getPkgs();
return config.apps || {}; return config.app || {};
}; };