Skip to content

Commit 78beb78

Browse files
committed
refactor(oss-licenses):重构开源许可证页面
- 更新组件引用,添加 t-icon 和 t-notice-bar 组件 - 修改仓库链接显示方式,使用 t-notice-bar 替代 t-link - 添加自定义样式,优化 repo-link 样式 - 重构 OSSLicensesBuilder.js,支持多目录依赖扫描 - 新增 OSSLicensesBuilderConfig.json5 配置文件
1 parent c4d502f commit 78beb78

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

source/OSSLicensesBuilder.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const shell = require('shelljs');
2222
const fs = require('fs');
2323
const path = require('path');
2424
const uglifyJS = require('uglify-js');
25+
const JSON5 = require('json5');
2526

2627
function normalizeLineEndings(content) {
2728
return content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
@@ -97,13 +98,14 @@ function main() {
9798
console.error('请先安装 license-checker-rseidelsohn: yarn add license-checker-rseidelsohn');
9899
process.exit(1);
99100
}
100-
const customPath = path.join(__dirname, 'pages/utils/OSSLicenseBuildFormat.json');
101-
if (!fs.existsSync(customPath)) {
102-
console.error(`找不到自定义配置文件: ${customPath}`);
101+
const configPath = path.join(__dirname, 'OSSLicensesBuilderConfig.json5');
102+
if (!fs.existsSync(configPath)) {
103+
console.error(`找不到配置文件: ${configPath}`);
103104
process.exit(1);
104105
}
105106
try {
106-
buildLicenses('OSSLicensesDist', customPath);
107+
const configs = JSON5.parse(fs.readFileSync(configPath, 'utf8'));
108+
for (const config of configs) if (config["startPath"] === undefined) buildLicenses(config["outputFile"], config["customPath"]); else buildLicenses(config["outputFile"], config["customPath"], config["startPath"]);
107109
} catch (error) {
108110
console.error(`构建失败: ${error.message}`);
109111
process.exit(1);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* 如需生成多个 npm 依赖目录的开放源代码许可信息,请在此列表下方添加更多对象
3+
* `outputFile`: 生成的目录名
4+
* `customPath`: 自定义 license-checker-rseidelsohn 生成格式的 JSON 文件路径
5+
* `startPath`: 可选,指定扫描的 npm 依赖目录
6+
**/
7+
[
8+
{
9+
outputFile: "OSSLicensesDist",
10+
customPath: "pages/utils/OSSLicenseBuildFormat.json"
11+
}
12+
// 示例新增:
13+
/*,{
14+
outputFile: "OSSLicensesDist",
15+
customPath: "subpackage/OSSLicenseBuildFormat.json",
16+
startPath: "subpackage/"
17+
}*/
18+
]

source/pages/oss-licenses/oss-licenses.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
"component": true,
33
"styleIsolation": "apply-shared",
44
"usingComponents": {
5+
"t-icon": "tdesign-miniprogram/icon/icon",
56
"t-link": "tdesign-miniprogram/link/link",
67
"t-message": "tdesign-miniprogram/message/message",
78
"t-navbar": "tdesign-miniprogram/navbar/navbar",
9+
"t-notice-bar": "tdesign-miniprogram/notice-bar/notice-bar",
810
"t-tag": "tdesign-miniprogram/tag/tag"
911
}
1012
}

source/pages/oss-licenses/oss-licenses.wxml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ See the Mulan PubL v2 for more details.
2828
<scroll-view class="overflow-y-auto block" enhanced scroll-x scroll-y style="height:{{heightRecycle+'px'}};"
2929
type="list">
3030
<view class="p-32rpx">
31-
<t-link bind:tap="copyRepo" class="mb-32rpx" content="{{repoLink}}" hover
32-
prefixIcon="{{repoType==='GitHub'?'logo-github':(repoType==='GitLab'?'logo-gitlab':'git-repository')}}"
33-
size="large" theme="primary" wx:if="{{repoLink !== ''}}"/>
31+
<t-notice-bar bind:tap="copyRepo" class="repo-link mb-32rpx rounded-18rpx" content="{{repoLink}}"
32+
prefixIcon="{{false}}" visible="{{true}}" wx:if="{{repoLink !== ''}}">
33+
<view slot="prefix-icon">
34+
<t-icon name="{{repoType==='GitHub'?'logo-github':(repoType==='GitLab'?'logo-gitlab':'git-repository')}}"></t-icon>
35+
</view>
36+
</t-notice-bar>
3437

3538
<text class="break-words whitespace-pre-wrap;" user-select>{{licenseBody}}</text>
3639
</view>

source/pages/oss-licenses/oss-licenses.wxss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@
1212
See the Mulan PubL v2 for more details.
1313
*/
1414

15+
.repo-link {
16+
border: 1rpx solid #0052d9;
17+
}
18+
19+
@media (prefers-color-scheme: dark) {
20+
.repo-link {
21+
border: 1rpx solid #4582e6;
22+
}
23+
}
24+

0 commit comments

Comments
 (0)