1010 */
1111
1212import { mkdir , unlink } from 'node:fs/promises' ;
13+ import { join } from 'node:path' ;
1314import { rimraf } from 'rimraf' ;
1415import getManifest from './browser-config/get-manifest.js' ;
1516import {
@@ -18,12 +19,13 @@ import {
1819 extension ,
1920 getDistPath ,
2021 getVersion ,
22+ scriptRoot ,
2123} from './config.mjs' ;
2224import amo from './pack-utils/amo.mjs' ;
2325import cws from './pack-utils/cws.mjs' ;
2426import edge from './pack-utils/edge.mjs' ;
2527import xpi from './pack-utils/xpi.mjs' ;
26- import { copyDir , outputJSON } from './utils.mjs' ;
28+ import { copyDir , outputJSON , readJSON } from './utils.mjs' ;
2729import { createZip } from './zip.mjs' ;
2830
2931const packUtils = {
@@ -36,8 +38,8 @@ const packUtils = {
3638/**
3739 * 打包一个平台的产物
3840 * @param {* } name
39- * @param {* } browserConfig 对应browser.config.json中的配置
40- * @param {* } extensionConfig 对应extension.json中的配置
41+ * @param {* } browserConfig 对应browser.config.json中的单项配置
42+ * @param {* } extensionConfig 对应extension.json中的单项配置
4143 * @returns
4244 */
4345async function prepareOnePlatform ( name , extensionConfig ) {
@@ -62,15 +64,15 @@ async function prepareOnePlatform(name, extensionConfig) {
6264 } ) ,
6365 ) ;
6466 // 打包成zip
65- console . log ( `zip ${ thisPack } -> ${ zipPath } ` ) ;
67+ console . log ( `[ ${ name } ] zip ${ thisPack } -> ${ zipPath } ` ) ;
6668 await createZip ( thisPack , zipPath ) ;
6769 } catch ( e ) {
68- console . error ( `Prepare ${ name } error` ) ;
70+ console . error ( `[ ${ name } ] prepare error` ) ;
6971 console . error ( e ) ;
7072 }
7173 return { dirName, thisPack, zipPath } ;
7274}
73- async function packOnePlatform ( name , prepare , extensionConfig ) {
75+ async function packOnePlatform ( name , prepare , browserConfig , extensionConfig ) {
7476 const { thisPack, zipPath } = prepare ;
7577 if ( typeof packUtils [ name ] === 'undefined' ) {
7678 console . error ( `pack-utils for ${ name } not found` ) ;
@@ -82,11 +84,12 @@ async function packOnePlatform(name, prepare, extensionConfig) {
8284 sourcePath : thisPack ,
8385 zipPath,
8486 releasePath : _path . release ,
87+ browserConfig,
8588 extensionConfig,
8689 } ) ;
87- console . log ( `Pack ${ name } success: ${ res } ` ) ;
90+ console . log ( `[ ${ name } ] pack success: ${ res } ` ) ;
8891 } catch ( e ) {
89- console . error ( `Pack ${ name } error` ) ;
92+ console . error ( `[ ${ name } ] pack error` ) ;
9093 console . error ( e ) ;
9194 }
9295 try {
@@ -118,13 +121,18 @@ async function main() {
118121 ) ;
119122 }
120123
124+ const browserConfig = await readJSON (
125+ join ( scriptRoot , 'browser-config/browser.config.json' ) ,
126+ ) ;
127+
121128 const queue = [ ] ;
122129
123130 for ( const name of platform ) {
124131 const platformConfig = extension [ name ] ;
125132 for ( const item of platformConfig ) {
133+ const browser = browserConfig [ item . browser ] ;
126134 const prepare = await prepareOnePlatform ( name , item ) ;
127- queue . push ( packOnePlatform ( name , { ...prepare } , item ) ) ;
135+ queue . push ( packOnePlatform ( name , { ...prepare } , browser , item ) ) ;
128136 }
129137 }
130138
0 commit comments