Skip to content

Commit a04e7ea

Browse files
committed
feat(OSSLicensesBuilder):增加自定义输出格式和路径
- 在 buildLicenses函数中添加 customFormat 参数,用于指定输出许可证信息的格式 - 将 customPath 参数的用途改为指定生成产物的目标目录 - 更新 OSSLicensesBuilderConfig.json5 中的配置项,增加 customFormat 和 customPath 字段 - 修改代码逻辑以适应新的参数结构,确保按指定格式和路径生成许可证信息
1 parent cb69fba commit a04e7ea

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

source/OSSLicensesBuilder.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@ function runCommand(command, args) {
6060
* 执行完成后,会删除 JSON 文件,仅保留 JS 文件
6161
*
6262
* @param {string} outputFile - 输出文件的名称,不包含文件扩展名
63+
* @param {string} customFormat 指定输出许可证信息格式,必填
6364
* @param {string} customPath - 指定依赖项的自定义路径
6465
* @param {string} [startPath=''] - 可选参数,指定从哪个路径开始查找依赖项,默认为当前目录
6566
*/
66-
function buildLicenses(outputFile, customPath, startPath = '') {
67-
const outputDir = path.join(__dirname, 'pages/utils');
67+
function buildLicenses(outputFile, customFormat, customPath, startPath = '') {
68+
const outputDir = path.join(__dirname, customPath);
6869
shell.mkdir('-p', outputDir);
6970
const jsonFile = path.join(outputDir, `${outputFile}.json`);
7071
const jsFile = path.join(outputDir, `${outputFile}.js`);
7172
try {
72-
const output = runCommand('license-checker-rseidelsohn', [startPath, '--customPath', customPath, '--json']);
73+
const output = runCommand('license-checker-rseidelsohn', [startPath, '--customPath', customFormat, '--json']);
7374
const jsonData = JSON.parse(output);
7475
if (Object.keys(jsonData).length === 0) throw new Error('生成的许可证数据为空');
7576
writeFileCrossPlatform(jsonFile, output);
@@ -102,7 +103,7 @@ function main() {
102103
}
103104
try {
104105
const configs = JSON5.parse(fs.readFileSync(configPath, 'utf8'));
105-
for (const config of configs) if (config["startPath"] === undefined) buildLicenses(config["outputFile"], config["customPath"]); else buildLicenses(config["outputFile"], config["customPath"], config["startPath"]);
106+
for (const config of configs) if (config["startPath"] === undefined) buildLicenses(config["outputFile"], config["customFormat"], config["customPath"]); else buildLicenses(config["outputFile"], config["customFormat"], config["customPath"], config["startPath"]);
106107
} catch (error) {
107108
console.error(`构建失败: ${error.message}`);
108109
process.exit(1);
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
/**
22
* 如需生成多个 npm 依赖目录的开放源代码许可信息,请在此列表下方添加更多对象
3-
* `outputFile`: 生成的目录名
4-
* `customPath`: 自定义 license-checker-rseidelsohn 生成格式的 JSON 文件路径
3+
* `outputFile`: 生成的文件名,无需添加 `.js` 后缀
4+
* `customFormat`: 自定义 license-checker-rseidelsohn 生成格式的 JSON 文件路径
5+
* `customPath`: 生成产物目标目录
56
* `startPath`: 可选,指定扫描的 npm 依赖目录
67
**/
78
[
89
{
910
outputFile: "OSSLicensesDist",
10-
customPath: "pages/utils/OSSLicensesBuildFormat.json"
11+
customFormat: "pages/utils/OSSLicensesBuildFormat.json",
12+
customPath: "pages/utils/"
1113
}
1214
// 示例新增:
1315
/*,{
1416
outputFile: "OSSLicensesDist",
15-
customPath: "subpackage/OSSLicensesBuildFormat.json",
17+
customFormat: "pages/utils/OSSLicensesBuildFormat.json",
18+
customPath: "subpackage/utils/",
1619
startPath: "subpackage/"
1720
}*/
1821
]

0 commit comments

Comments
 (0)