From 3288b64dbfb1504ba8224fc1bc2c84533784201e Mon Sep 17 00:00:00 2001 From: xion Date: Fri, 22 Nov 2024 22:26:48 +0800 Subject: [PATCH] fix: remove path fro dev, use progress.resolve() replace --- config/app-schema.json | 10 ++++++---- package.json | 8 ++++++-- src/config.ts | 14 +------------- src/pkgs.ts | 9 ++------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/config/app-schema.json b/config/app-schema.json index 925e4cc..ab2d0ec 100644 --- a/config/app-schema.json +++ b/config/app-schema.json @@ -6,10 +6,11 @@ "type": { "type": "string", "enum": [ - "inline-app", - "micro-app" + "system-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": { "type": "boolean", @@ -36,7 +37,8 @@ "required": [ "host", "path" - ] + ], + "$comment": "远程服务的地址和路径" }, "micro": { "type": "object", diff --git a/package.json b/package.json index 8c4a699..7244162 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,16 @@ { - "name": "@kevisual/user-config", - "version": "1.0.1", + "name": "@kevisual/use-config", + "version": "1.0.2", "types": "dist/config.d.ts", "scripts": { "build": "npm run clean && rollup -c", "watch": " rollup -c -w", "clean": "rimraf dist" }, + + "publishConfig": { + "access": "public" + }, "files": [ "dist", "src", diff --git a/src/config.ts b/src/config.ts index 415bd39..8c6af23 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,10 +1,6 @@ import JSON5 from 'json5'; import fs from 'fs'; import path from 'path'; -import { fileURLToPath } from 'url'; - -const __filename = fileURLToPath(import.meta.url); // 当前模块的文件路径 -const __dirname = path.dirname(__filename); // 当前模块的目录路径 // 配置类型 export type Config = { @@ -51,11 +47,7 @@ export const fileIsExist = (path: string) => { } }; export const getDirname = () => { - const isDev = getNODE_ENV() === 'development'; - if (isDev) { - return path.resolve(); - } - return __dirname; + return path.resolve(); }; export const getConfigFile = (fileName = 'app.config.json5') => { const dirname = getDirname(); @@ -133,7 +125,3 @@ export const deleteContext = (key: string): any => { } return _context; }; - -export const getNODE_ENV = (): string => { - return process?.env?.NODE_ENV || 'production'; -}; diff --git a/src/pkgs.ts b/src/pkgs.ts index 585a023..0995807 100644 --- a/src/pkgs.ts +++ b/src/pkgs.ts @@ -1,12 +1,7 @@ -import path from 'path'; import fs from 'fs'; import type { App } from './read-app-schema.ts'; -import { fileURLToPath } from 'url'; import { getConfigFile } from './config.ts'; -const __filename = fileURLToPath(import.meta.url); // 当前模块的文件路径 -const __dirname = path.dirname(__filename); // 当前模块的目录路径 - export const getPkgs = () => { const configFile = getConfigFile(); if (!configFile) { @@ -17,7 +12,7 @@ export const getPkgs = () => { return config; }; -export const getApps = (): App => { +export const getApp = (): App => { const config = getPkgs(); - return config.apps || {}; + return config.app || {}; };