@tachybase/module-web 1.6.0 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,182 @@
1
+ /*!
2
+ * express
3
+ * Copyright(c) 2009-2013 TJ Holowaychuk
4
+ * Copyright(c) 2013 Roman Shtylman
5
+ * Copyright(c) 2014-2015 Douglas Christopher Wilson
6
+ * MIT Licensed
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ /**
12
+ * Module dependencies.
13
+ * @private
14
+ */
15
+
16
+ var debug = require('debug')('express:view');
17
+ var path = require('path');
18
+ var fs = require('fs');
19
+
20
+ /**
21
+ * Module variables.
22
+ * @private
23
+ */
24
+
25
+ var dirname = path.dirname;
26
+ var basename = path.basename;
27
+ var extname = path.extname;
28
+ var join = path.join;
29
+ var resolve = path.resolve;
30
+
31
+ /**
32
+ * Module exports.
33
+ * @public
34
+ */
35
+
36
+ module.exports = View;
37
+
38
+ /**
39
+ * Initialize a new `View` with the given `name`.
40
+ *
41
+ * Options:
42
+ *
43
+ * - `defaultEngine` the default template engine name
44
+ * - `engines` template engine require() cache
45
+ * - `root` root path for view lookup
46
+ *
47
+ * @param {string} name
48
+ * @param {object} options
49
+ * @public
50
+ */
51
+
52
+ function View(name, options) {
53
+ var opts = options || {};
54
+
55
+ this.defaultEngine = opts.defaultEngine;
56
+ this.ext = extname(name);
57
+ this.name = name;
58
+ this.root = opts.root;
59
+
60
+ if (!this.ext && !this.defaultEngine) {
61
+ throw new Error('No default engine was specified and no extension was provided.');
62
+ }
63
+
64
+ var fileName = name;
65
+
66
+ if (!this.ext) {
67
+ // get extension from default engine name
68
+ this.ext = this.defaultEngine[0] !== '.'
69
+ ? '.' + this.defaultEngine
70
+ : this.defaultEngine;
71
+
72
+ fileName += this.ext;
73
+ }
74
+
75
+ if (!opts.engines[this.ext]) {
76
+ // load engine
77
+ var mod = this.ext.slice(1)
78
+ debug('require "%s"', mod)
79
+
80
+ // default engine export
81
+ var fn = require(mod).__express
82
+
83
+ if (typeof fn !== 'function') {
84
+ throw new Error('Module "' + mod + '" does not provide a view engine.')
85
+ }
86
+
87
+ opts.engines[this.ext] = fn
88
+ }
89
+
90
+ // store loaded engine
91
+ this.engine = opts.engines[this.ext];
92
+
93
+ // lookup path
94
+ this.path = this.lookup(fileName);
95
+ }
96
+
97
+ /**
98
+ * Lookup view by the given `name`
99
+ *
100
+ * @param {string} name
101
+ * @private
102
+ */
103
+
104
+ View.prototype.lookup = function lookup(name) {
105
+ var path;
106
+ var roots = [].concat(this.root);
107
+
108
+ debug('lookup "%s"', name);
109
+
110
+ for (var i = 0; i < roots.length && !path; i++) {
111
+ var root = roots[i];
112
+
113
+ // resolve the path
114
+ var loc = resolve(root, name);
115
+ var dir = dirname(loc);
116
+ var file = basename(loc);
117
+
118
+ // resolve the file
119
+ path = this.resolve(dir, file);
120
+ }
121
+
122
+ return path;
123
+ };
124
+
125
+ /**
126
+ * Render with the given options.
127
+ *
128
+ * @param {object} options
129
+ * @param {function} callback
130
+ * @private
131
+ */
132
+
133
+ View.prototype.render = function render(options, callback) {
134
+ debug('render "%s"', this.path);
135
+ this.engine(this.path, options, callback);
136
+ };
137
+
138
+ /**
139
+ * Resolve the file within the given directory.
140
+ *
141
+ * @param {string} dir
142
+ * @param {string} file
143
+ * @private
144
+ */
145
+
146
+ View.prototype.resolve = function resolve(dir, file) {
147
+ var ext = this.ext;
148
+
149
+ // <path>.<ext>
150
+ var path = join(dir, file);
151
+ var stat = tryStat(path);
152
+
153
+ if (stat && stat.isFile()) {
154
+ return path;
155
+ }
156
+
157
+ // <path>/index.<ext>
158
+ path = join(dir, basename(file, ext), 'index' + ext);
159
+ stat = tryStat(path);
160
+
161
+ if (stat && stat.isFile()) {
162
+ return path;
163
+ }
164
+ };
165
+
166
+ /**
167
+ * Return a stat, maybe.
168
+ *
169
+ * @param {string} path
170
+ * @return {fs.Stats}
171
+ * @private
172
+ */
173
+
174
+ function tryStat(path) {
175
+ debug('stat "%s"', path);
176
+
177
+ try {
178
+ return fs.statSync(path);
179
+ } catch (e) {
180
+ return undefined;
181
+ }
182
+ }
@@ -0,0 +1 @@
1
+ {"name":"express","description":"Fast, unopinionated, minimalist web framework","version":"4.21.2","author":"TJ Holowaychuk <tj@vision-media.ca>","contributors":["Aaron Heckmann <aaron.heckmann+github@gmail.com>","Ciaran Jessup <ciaranj@gmail.com>","Douglas Christopher Wilson <doug@somethingdoug.com>","Guillermo Rauch <rauchg@gmail.com>","Jonathan Ong <me@jongleberry.com>","Roman Shtylman <shtylman+expressjs@gmail.com>","Young Jae Sim <hanul@hanul.me>"],"license":"MIT","repository":"expressjs/express","homepage":"http://expressjs.com/","funding":{"type":"opencollective","url":"https://opencollective.com/express"},"keywords":["express","framework","sinatra","web","http","rest","restful","router","app","api"],"dependencies":{"accepts":"~1.3.8","array-flatten":"1.1.1","body-parser":"1.20.3","content-disposition":"0.5.4","content-type":"~1.0.4","cookie":"0.7.1","cookie-signature":"1.0.6","debug":"2.6.9","depd":"2.0.0","encodeurl":"~2.0.0","escape-html":"~1.0.3","etag":"~1.8.1","finalhandler":"1.3.1","fresh":"0.5.2","http-errors":"2.0.0","merge-descriptors":"1.0.3","methods":"~1.1.2","on-finished":"2.4.1","parseurl":"~1.3.3","path-to-regexp":"0.1.12","proxy-addr":"~2.0.7","qs":"6.13.0","range-parser":"~1.2.1","safe-buffer":"5.2.1","send":"0.19.0","serve-static":"1.16.2","setprototypeof":"1.2.0","statuses":"2.0.1","type-is":"~1.6.18","utils-merge":"1.0.1","vary":"~1.1.2"},"devDependencies":{"after":"0.8.2","connect-redis":"3.4.2","cookie-parser":"1.4.6","cookie-session":"2.0.0","ejs":"3.1.9","eslint":"8.47.0","express-session":"1.17.2","hbs":"4.2.0","marked":"0.7.0","method-override":"3.0.0","mocha":"10.2.0","morgan":"1.10.0","nyc":"15.1.0","pbkdf2-password":"1.2.1","supertest":"6.3.0","vhost":"~3.0.2"},"engines":{"node":">= 0.10.0"},"files":["LICENSE","History.md","Readme.md","index.js","lib/"],"scripts":{"lint":"eslint .","test":"mocha --require test/support/env --reporter spec --bail --check-leaks test/ test/acceptance/","test-ci":"nyc --exclude examples --exclude test --exclude benchmarks --reporter=lcovonly --reporter=text npm test","test-cov":"nyc --exclude examples --exclude test --exclude benchmarks --reporter=html --reporter=text npm test","test-tap":"mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/"},"_lastModified":"2025-12-26T04:42:09.148Z"}
File without changes
@@ -0,0 +1,6 @@
1
+ import { Plugin } from '@tego/server';
2
+ /**
3
+ * 注册插件静态文件服务
4
+ * 提供 /static/plugins/ 路径的静态文件服务
5
+ */
6
+ export declare function registerPluginStaticFiles(plugin: Plugin): void;
@@ -0,0 +1,161 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var plugin_static_files_exports = {};
29
+ __export(plugin_static_files_exports, {
30
+ registerPluginStaticFiles: () => registerPluginStaticFiles
31
+ });
32
+ module.exports = __toCommonJS(plugin_static_files_exports);
33
+ var import_node_fs = require("node:fs");
34
+ var import_node_path = require("node:path");
35
+ var import_server = require("@tego/server");
36
+ var import_express = __toESM(require("express"));
37
+ function registerPluginStaticFiles(plugin) {
38
+ const callback = (0, import_express.default)();
39
+ const prefix = "/static/plugins";
40
+ const getPluginBasePath = () => {
41
+ const nodeModulesPaths = [
42
+ (0, import_node_path.join)(process.cwd(), "node_modules", "@tachybase"),
43
+ (0, import_node_path.join)(__dirname, "../../../../node_modules/@tachybase"),
44
+ (0, import_node_path.join)(__dirname, "../../../node_modules/@tachybase"),
45
+ // 尝试从编译后的文件位置推断
46
+ (0, import_node_path.join)(__dirname, "../../../../../node_modules/@tachybase")
47
+ ];
48
+ for (const nodeModulesPath of nodeModulesPaths) {
49
+ if ((0, import_node_fs.existsSync)(nodeModulesPath)) {
50
+ try {
51
+ const files = require("node:fs").readdirSync(nodeModulesPath);
52
+ const hasPlugins = files.some((file) => file.startsWith("plugin-"));
53
+ if (hasPlugins) {
54
+ return nodeModulesPath;
55
+ }
56
+ } catch (e) {
57
+ }
58
+ }
59
+ }
60
+ try {
61
+ const testPluginPath = require.resolve("@tachybase/plugin-otp/package.json");
62
+ const pluginDir = (0, import_node_path.dirname)(testPluginPath);
63
+ const tachybaseDir = (0, import_node_path.dirname)(pluginDir);
64
+ if ((0, import_node_fs.existsSync)(tachybaseDir)) {
65
+ return tachybaseDir;
66
+ }
67
+ } catch (e) {
68
+ }
69
+ const packagesPaths = [
70
+ (0, import_node_path.join)(process.cwd(), "packages"),
71
+ (0, import_node_path.join)(__dirname, "../../../../packages"),
72
+ (0, import_node_path.join)(__dirname, "../../../packages")
73
+ ];
74
+ for (const packagesPath of packagesPaths) {
75
+ if ((0, import_node_fs.existsSync)(packagesPath)) {
76
+ try {
77
+ const files = require("node:fs").readdirSync(packagesPath);
78
+ const hasPlugins = files.some((file) => file.startsWith("plugin-"));
79
+ if (hasPlugins) {
80
+ return packagesPath;
81
+ }
82
+ } catch (e) {
83
+ }
84
+ }
85
+ }
86
+ if (process.env.TEGO_RUNTIME_HOME) {
87
+ const runtimePluginsPath = (0, import_node_path.join)(process.env.TEGO_RUNTIME_HOME, "node_modules", "@tachybase");
88
+ if ((0, import_node_fs.existsSync)(runtimePluginsPath)) {
89
+ return runtimePluginsPath;
90
+ }
91
+ }
92
+ return null;
93
+ };
94
+ const findPluginFile = (pluginName, relativePath) => {
95
+ const cleanPluginName = pluginName.replace(/^@tachybase\//, "");
96
+ const possibleBasePaths = [
97
+ (0, import_node_path.join)(process.cwd(), "node_modules", "@tachybase", cleanPluginName),
98
+ (0, import_node_path.join)(process.cwd(), "packages", cleanPluginName),
99
+ (0, import_node_path.join)(__dirname, "../../../../node_modules/@tachybase", cleanPluginName),
100
+ (0, import_node_path.join)(__dirname, "../../../../packages", cleanPluginName),
101
+ (0, import_node_path.join)(__dirname, "../../../node_modules/@tachybase", cleanPluginName),
102
+ (0, import_node_path.join)(__dirname, "../../../packages", cleanPluginName)
103
+ ];
104
+ if (process.env.TEGO_RUNTIME_HOME) {
105
+ possibleBasePaths.push((0, import_node_path.join)(process.env.TEGO_RUNTIME_HOME, "node_modules", "@tachybase", cleanPluginName));
106
+ }
107
+ for (const basePath of possibleBasePaths) {
108
+ const filePath = (0, import_node_path.join)(basePath, relativePath);
109
+ if ((0, import_node_fs.existsSync)(filePath) && (0, import_node_fs.statSync)(filePath).isFile()) {
110
+ return filePath;
111
+ }
112
+ }
113
+ return null;
114
+ };
115
+ const pluginBasePath = getPluginBasePath();
116
+ if (pluginBasePath) {
117
+ const isPackagesPath = pluginBasePath.includes("packages");
118
+ callback.use((req, res, next) => {
119
+ const match = req.path.match(/^\/static\/plugins\/@tachybase\/([^/]+)\/(.+)$/);
120
+ if (!match) {
121
+ return next();
122
+ }
123
+ const [, pluginName, relativePath] = match;
124
+ let filePath = null;
125
+ if (isPackagesPath) {
126
+ filePath = (0, import_node_path.join)(pluginBasePath, pluginName, relativePath);
127
+ if (!(0, import_node_fs.existsSync)(filePath) || !(0, import_node_fs.statSync)(filePath).isFile()) {
128
+ filePath = null;
129
+ }
130
+ } else {
131
+ filePath = (0, import_node_path.join)(pluginBasePath, pluginName, relativePath);
132
+ if (!(0, import_node_fs.existsSync)(filePath) || !(0, import_node_fs.statSync)(filePath).isFile()) {
133
+ filePath = null;
134
+ }
135
+ }
136
+ if (!filePath) {
137
+ filePath = findPluginFile(pluginName, relativePath);
138
+ }
139
+ if (filePath) {
140
+ res.setHeader("Access-Control-Allow-Origin", "*");
141
+ res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS");
142
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Origin, X-Requested-With");
143
+ res.sendFile(filePath);
144
+ } else {
145
+ res.status(404).send(`Plugin file not found: ${pluginName}/${relativePath}`);
146
+ }
147
+ });
148
+ import_server.Gateway.getInstance().registerHandler({
149
+ name: "plugin-static-files",
150
+ prefix,
151
+ callback
152
+ });
153
+ plugin.app.logger.info(`[ModuleWeb] Registered plugin static files service at ${prefix} from ${pluginBasePath}`);
154
+ } else {
155
+ plugin.app.logger.warn("[ModuleWeb] Plugin static files directory not found, skipping registration");
156
+ }
157
+ }
158
+ // Annotate the CommonJS export names for ESM import in node:
159
+ 0 && (module.exports = {
160
+ registerPluginStaticFiles
161
+ });
@@ -27,6 +27,7 @@ var import_server = require("@tego/server");
27
27
  var import_antd = require("./antd");
28
28
  var import_cron = require("./cron");
29
29
  var import_cronstrue = require("./cronstrue");
30
+ var import_plugin_static_files = require("./plugin-static-files");
30
31
  async function getLang(ctx) {
31
32
  const SystemSetting = ctx.db.getRepository("systemSettings");
32
33
  const systemSetting = await SystemSetting.findOne();
@@ -132,6 +133,7 @@ class ModuleWeb extends import_server.Plugin {
132
133
  });
133
134
  const dialect = this.app.db.sequelize.getDialect();
134
135
  const appVersion = readAppVersionFromPackageJson();
136
+ (0, import_plugin_static_files.registerPluginStaticFiles)(this);
135
137
  this.app.resourcer.define({
136
138
  name: "app",
137
139
  actions: {
@@ -150,18 +152,18 @@ class ModuleWeb extends import_server.Plugin {
150
152
  dialect
151
153
  },
152
154
  version: {
153
- core: await ctx.app.version.get(),
155
+ core: await ctx.tego.version.get(),
154
156
  app: appVersion
155
157
  },
156
158
  lang,
157
- name: ctx.app.name,
159
+ name: ctx.tego.name,
158
160
  theme: ((_a = currentUser == null ? void 0 : currentUser.systemSettings) == null ? void 0 : _a.theme) || ((_b = systemSetting == null ? void 0 : systemSetting.options) == null ? void 0 : _b.theme) || "default"
159
161
  };
160
162
  await next();
161
163
  },
162
164
  async getLang(ctx, next) {
163
165
  const lang = await getLang(ctx);
164
- const app = ctx.app;
166
+ const app = ctx.tego;
165
167
  const eTag = await app.localeManager.getETag(lang);
166
168
  const resources = await app.localeManager.get(lang);
167
169
  const requestETag = ctx.get("If-None-Match");
@@ -183,11 +185,11 @@ class ModuleWeb extends import_server.Plugin {
183
185
  await next();
184
186
  },
185
187
  async restart(ctx, next) {
186
- ctx.app.runAsCLI(["restart"], { from: "user" });
188
+ ctx.tego.runAsCLI(["restart"], { from: "user" });
187
189
  await next();
188
190
  },
189
191
  async refresh(ctx, next) {
190
- ctx.app.runCommand("refresh");
192
+ ctx.tego.runCommand("refresh");
191
193
  await next();
192
194
  }
193
195
  }
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@tachybase/module-web",
3
3
  "displayName": "WEB client",
4
- "version": "1.6.0",
4
+ "version": "1.6.3",
5
5
  "description": "Provides a client interface for the TachyBase server",
6
6
  "keywords": [
7
7
  "System management"
8
8
  ],
9
9
  "license": "Apache-2.0",
10
10
  "main": "./dist/server/index.js",
11
- "dependencies": {},
12
11
  "devDependencies": {
13
- "@ant-design/icons": "^5.6.1",
14
- "@tachybase/schema": "1.3.52",
15
- "@tachybase/test": "1.3.52",
16
- "@tego/client": "1.3.52",
17
- "@tego/server": "1.3.52",
12
+ "@ant-design/icons": "^6.1.0",
13
+ "@tachybase/schema": "1.6.1",
14
+ "@tachybase/test": "1.6.1",
15
+ "@tego/client": "1.6.1",
16
+ "@tego/server": "1.6.1",
17
+ "@types/express": "5.0.2",
18
18
  "@types/react": "18.3.23",
19
19
  "@types/react-dom": "18.3.7",
20
20
  "ahooks": "^3.9.0",
@@ -23,6 +23,7 @@
23
23
  "antd-mobile-icons": "^0.3.0",
24
24
  "cronstrue": "^3.2.0",
25
25
  "dayjs": "1.11.13",
26
+ "express": "4.21.2",
26
27
  "koa-send": "^5.0.1",
27
28
  "koa-static": "^5.0.0",
28
29
  "lodash": "4.17.21",
@@ -30,7 +31,7 @@
30
31
  "react-dom": "18.3.1",
31
32
  "react-i18next": "16.2.1",
32
33
  "react-router-dom": "6.28.1",
33
- "@tachybase/client": "1.6.0"
34
+ "@tachybase/client": "1.6.3"
34
35
  },
35
36
  "description.zh-CN": "为 TachyBase 服务端提供客户端界面",
36
37
  "displayName.zh-CN": "WEB 客户端",