@10yun/open-sdk 0.3.124 → 0.3.125

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.
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs';
2
- import { parseRouteItem } from './router.js';
2
+ import { parseRouteItem } from '../common/router.js';
3
3
  var nameOnlyArr = {};
4
4
  // 解析数据转菜单
5
5
  function parseDataToMenu(appFlag, oldData) {
@@ -94,7 +94,6 @@ function parseDataToMenu(appFlag, oldData) {
94
94
  }
95
95
  return newData;
96
96
  }
97
-
98
97
  /**
99
98
  * 获取 rbac权限配置
100
99
  * @param {*} menuArr 菜单组
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 使用正则表达式进行过滤
3
+ * 过滤除了 https:// 和 http:// 以外的 // 和 ///
4
+ */
5
+ export function parseDomainUrl(str) {
6
+ str = str.replace(/\/(undefined\/)+/g, '/');
7
+ str = str.replace(/([^:]\/)\/+/g, '$1');
8
+ return str;
9
+ }
@@ -0,0 +1,124 @@
1
+ import path from 'path';
2
+ import { buildRbac } from './build-rbac.js';
3
+ import { parseDomainUrl } from './common.js';
4
+ /**
5
+ * 通用
6
+ */
7
+ export function shiyunReleaseCommon(ENV_ARR_VITE, ENV_ARR_CICD, ENV_MODE, params) {
8
+ // 根据当前工作目录中的 `mode` 加载 .env 文件
9
+ const PROCESS_CWD = process.cwd();
10
+ const BASENAME_SIGN = path.basename(PROCESS_CWD);
11
+ const { CICD_BUILD_DOMAIN_SCHEME, CICD_BUILD_DOMAIN_ALONE, CICD_BUILD_VERS_FULL, CICD_BUILD_VERS_CODE } = ENV_ARR_CICD;
12
+ const { VITE_SY_PRODUCT_PORT, VITE_SY_PRODUCT_SIGN } = ENV_ARR_VITE;
13
+ const LAST_BUILD_SIGN = VITE_SY_PRODUCT_SIGN || BASENAME_SIGN;
14
+
15
+ let LAST_BUILD_DOMAIN = '';
16
+ /**
17
+ * 非独立[子应用情况]
18
+ */
19
+ if (CICD_BUILD_DOMAIN_ALONE == 'on') {
20
+ LAST_BUILD_DOMAIN = CICD_BUILD_DOMAIN_SCHEME;
21
+ } else {
22
+ LAST_BUILD_DOMAIN = `${CICD_BUILD_DOMAIN_SCHEME}/${LAST_BUILD_SIGN}/${CICD_BUILD_VERS_FULL}/`;
23
+ }
24
+ let basePath = '/';
25
+ if (ENV_MODE === 'production') {
26
+ basePath = parseDomainUrl(`${LAST_BUILD_DOMAIN}/`);
27
+ buildRbac(params.menu_arr, PROCESS_CWD, {
28
+ RBAC_BASE_SIGN: LAST_BUILD_SIGN
29
+ });
30
+ }
31
+ return {
32
+ name: 'vite-plugin-shiyun-release-common',
33
+ // apply: 'build', // 'build' 或 'serve' ,在什么情况下使用
34
+ config: (config, { mode, command }) => {
35
+ return {
36
+ base: basePath,
37
+ server: {
38
+ port: VITE_SY_PRODUCT_PORT
39
+ },
40
+ esbuild: {
41
+ drop: ['console', 'debugger']
42
+ },
43
+ optimizeDeps: {
44
+ esbuildOptions: {
45
+ target: 'esnext'
46
+ },
47
+ // 确保 open-sdk 包在依赖优化中
48
+ // include: ['@10yun/open-sdk']
49
+ exclude: ['@10yun/open-sdk/uncompiled']
50
+ /**
51
+ * TODO
52
+ * 确保 open-sdk 包不在依赖优化中,不然造成修改 【项目@/下的相关文件】,vite无法及时热更新响应
53
+ * 添加下列 exclude 会爆 dayjs 问题
54
+ */
55
+ // exclude: ['@10yun/open-sdk']
56
+ },
57
+ build: {
58
+ // target: ['chrome89', 'edge89', 'firefox89', 'safari15', 'chrome87', 'edge88', 'es2020', 'firefox78', 'safari14'],
59
+ target: 'esnext',
60
+ sourcemap: false,
61
+ chunkSizeWarningLimit: 2000
62
+ },
63
+ output: {
64
+ // 把子应用打包成 umd 库格式
65
+ // library: `${子应用名}-[name]`,
66
+ // libraryTarget: 'umd',
67
+ // jsonpFunction: `webpackJsonp_${子应用名}`
68
+ library: `${LAST_BUILD_SIGN}-[name]`,
69
+ libraryTarget: 'umd',
70
+ jsonpFunction: `webpackJsonp_${LAST_BUILD_SIGN}`
71
+ }
72
+ };
73
+ },
74
+ configResolved(config) {
75
+ // console.log('---111---');
76
+ // console.log('configResolved', config.base, config.mode, config.command, config.esbuild);
77
+ // config.base = 'asdad';
78
+ // isProduction = config.command === 'build' || config.isProduction;
79
+ // base = config.base;
80
+ },
81
+ configureServer(server) {
82
+ // 在开发服务器配置时可以执行的逻辑
83
+ // console.log('开发的时候', server);
84
+ },
85
+ transformIndexHtml(html) {
86
+ if (ENV_MODE === 'development') {
87
+ // 删除带 mode="pro" 的标签
88
+ // html = html.replace(/<(script)\b[^>]*?mode="pro"[^>]*>[\s\S]*?<\/script>/gi, '');
89
+ html = html.replace(/<script\b[^>]*?mode="pro"[^>]*>[\s\S]*?<\/script>/gi, '');
90
+ html = html.replace(/<(link|script)\b[^>]*?mode="pro"[^>]*>/gi, '');
91
+ }
92
+ if (ENV_MODE === 'production') {
93
+ // 删除带 mode="dev" 的标签
94
+ if (CICD_BUILD_DOMAIN_ALONE !== 'on') {
95
+ // html = html.replace(/<(script)\b[^>]*?mode="dev"[^>]*>[\s\S]*?<\/script>/gi, '');
96
+ html = html.replace(/<script\b[^>]*?mode="dev"[^>]*>[\s\S]*?<\/script>/gi, '');
97
+ html = html.replace(/<(link|script)\b[^>]*?mode="dev"[^>]*>/gi, '');
98
+ }
99
+ }
100
+ /**
101
+ * 新增十云相关信息
102
+ */
103
+ const copyrightInfo = 'saas软件,软件开发,软件制定,公众号,小程序,app,十云,十云科技,福州十云,ctocode,10yun.com';
104
+ let shiyunInfo = `<meta name="description" content="${copyrightInfo}" />\n`;
105
+ shiyunInfo += `<meta name="keywords" content="${copyrightInfo}" />\n`;
106
+ shiyunInfo += `<meta name="author" content="十云_ctocode_技术支持_https://www.10yun.com" />\n`;
107
+ if (CICD_BUILD_VERS_FULL) {
108
+ shiyunInfo += `<meta name="version" content="${CICD_BUILD_VERS_FULL}_${CICD_BUILD_VERS_CODE}" />\n`;
109
+ }
110
+ // 将meta标签插入到head标签内(</head>闭合标签之前)
111
+ html = html.replace('</head>', `\n${shiyunInfo}\n</head>`);
112
+ // 删除空行
113
+ html = html.replace(/\n\s*\n/g, '\n');
114
+ return html;
115
+ }
116
+ // transform(code, id) {
117
+ // // console.log('transform');
118
+ // if (id.endsWith('.example')) {
119
+ // // 对特定文件进行转换逻辑
120
+ // return code + '\n// This is an example plugin transformation';
121
+ // }
122
+ // }
123
+ };
124
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 使用 plugins: [shiyunInjectHtml({ key: 'value' })]
3
+ * @param {*} data
4
+ * @returns
5
+ */
6
+ export function shiyunInjectHtml(data) {
7
+ return {
8
+ name: 'vite-plugin-shiyun-inject-html',
9
+ transformIndexHtml(html) {
10
+ Object.keys(data).forEach((key) => {
11
+ html = html.replace(`<!--%${key}%-->`, data[key]);
12
+ });
13
+ return html;
14
+ }
15
+ };
16
+ }
package/common/rbac.js CHANGED
@@ -1,7 +1,15 @@
1
1
  import { StorageObj } from '../index.js';
2
2
  const envArr = import.meta.env;
3
3
  const currSign = envArr.VITE_SY_PRODUCT_SIGN;
4
- import { isValidString } from './common.js';
4
+ /**
5
+ * 判断是否为有效字符串:
6
+ * - 类型必须是 string
7
+ * - 不能是空字符串或全是空格
8
+ * - 不能是 'undefined' 这个字符串
9
+ */
10
+ export function isValidString(str) {
11
+ return typeof str === 'string' && str.trim() !== '' && str !== 'undefined';
12
+ }
5
13
  /**
6
14
  * 权限检查方法
7
15
  * @param {String|Array} value
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("./index-NK8pC8CF.cjs"),c={},s={class:"cloud-404-wrap"};function d(r,o){return e.openBlock(),e.createElementBlock("div",s,[...o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-404-box"},[e.createElementVNode("div",{class:"cloud-404-code"},"404"),e.createElementVNode("div",{class:"cloud-404-message"},"Not Found")],-1)])])}const n=t._export_sfc(c,[["render",d]]);exports.default=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("./index-cXIUdiY2.cjs"),c={},s={class:"cloud-404-wrap"};function d(r,o){return e.openBlock(),e.createElementBlock("div",s,[...o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-404-box"},[e.createElementVNode("div",{class:"cloud-404-code"},"404"),e.createElementVNode("div",{class:"cloud-404-message"},"Not Found")],-1)])])}const n=t._export_sfc(c,[["render",d]]);exports.default=n;
@@ -1,5 +1,5 @@
1
1
  import { createElementBlock as c, openBlock as s, createElementVNode as o } from "vue";
2
- import { _ as t } from "./index-BVWiD6lA.js";
2
+ import { _ as t } from "./index-DmigSfXx.js";
3
3
  const d = {}, r = { class: "cloud-404-wrap" };
4
4
  function l(n, e) {
5
5
  return s(), c("div", r, [...e[0] || (e[0] = [
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("./index-NK8pC8CF.cjs"),c={},t={class:"cloud-none-wrap",style:{"background-color":"none"}};function r(s,o){return e.openBlock(),e.createElementBlock("div",t,[...o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-none-box"},[e.createElementVNode("div",{class:"cloud-none-code"},"不建议,子应用单独运行~"),e.createElementVNode("div",{class:"cloud-none-message"},"Not Alone")],-1)])])}const l=n._export_sfc(c,[["render",r]]);exports.default=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("./index-cXIUdiY2.cjs"),c={},t={class:"cloud-none-wrap",style:{"background-color":"none"}};function r(s,o){return e.openBlock(),e.createElementBlock("div",t,[...o[0]||(o[0]=[e.createElementVNode("div",{class:"cloud-none-box"},[e.createElementVNode("div",{class:"cloud-none-code"},"不建议,子应用单独运行~"),e.createElementVNode("div",{class:"cloud-none-message"},"Not Alone")],-1)])])}const l=n._export_sfc(c,[["render",r]]);exports.default=l;
@@ -1,5 +1,5 @@
1
1
  import { createElementBlock as n, openBlock as c, createElementVNode as o } from "vue";
2
- import { _ as s } from "./index-BVWiD6lA.js";
2
+ import { _ as s } from "./index-DmigSfXx.js";
3
3
  const r = {}, t = {
4
4
  class: "cloud-none-wrap",
5
5
  style: { "background-color": "none" }