@@ -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 ) ;
0 commit comments