@@ -32,6 +32,7 @@ const headlampPluginPkg = require('../package.json');
32
32
const PluginManager = require ( '../plugin-management/plugin-management' ) . PluginManager ;
33
33
const { table } = require ( 'table' ) ;
34
34
const tar = require ( 'tar' ) ;
35
+ const MultiPluginManager = require ( '../plugin-management/multi-plugin-management' ) ;
35
36
36
37
// ES imports
37
38
const viteCopyPluginPromise = import ( 'vite-plugin-static-copy' ) ;
@@ -1420,14 +1421,19 @@ yargs(process.argv.slice(2))
1420
1421
}
1421
1422
)
1422
1423
. command (
1423
- 'install < URL> ' ,
1424
- 'Install a plugin from the Artiface Hub URL' ,
1424
+ 'install [ URL] ' ,
1425
+ 'Install plugin(s) from a configuration file or a plugin artifact Hub URL' ,
1425
1426
yargs => {
1426
- yargs
1427
+ return yargs
1427
1428
. positional ( 'URL' , {
1428
1429
describe : 'URL of the plugin to install' ,
1429
1430
type : 'string' ,
1430
1431
} )
1432
+ . option ( 'config' , {
1433
+ alias : 'c' ,
1434
+ describe : 'Path to plugin configuration file' ,
1435
+ type : 'string' ,
1436
+ } )
1431
1437
. option ( 'folderName' , {
1432
1438
describe : 'Name of the folder to install the plugin into' ,
1433
1439
type : 'string' ,
@@ -1440,22 +1446,66 @@ yargs(process.argv.slice(2))
1440
1446
alias : 'q' ,
1441
1447
describe : 'Do not print logs' ,
1442
1448
type : 'boolean' ,
1449
+ } )
1450
+ . check ( argv => {
1451
+ if ( ! argv . URL && ! argv . config ) {
1452
+ throw new Error ( 'Either URL or --config must be specified' ) ;
1453
+ }
1454
+ if ( argv . URL && argv . config ) {
1455
+ throw new Error ( 'Cannot specify both URL and --config' ) ;
1456
+ }
1457
+ return true ;
1443
1458
} ) ;
1444
1459
} ,
1445
1460
async argv => {
1446
- const { URL , folderName, headlampVersion, quiet } = argv ;
1447
- const progressCallback = quiet
1448
- ? null
1449
- : data => {
1450
- if ( data . type === 'error' || data . type === 'success' ) {
1451
- console . error ( data . type , ':' , data . message ) ;
1452
- }
1453
- } ; // Use console.log for logs if not in quiet mode
1454
1461
try {
1455
- await PluginManager . install ( URL , folderName , headlampVersion , progressCallback ) ;
1456
- } catch ( e ) {
1457
- console . error ( e . message ) ;
1458
- process . exit ( 1 ) ; // Exit with error status
1462
+ const { URL , config, folderName, headlampVersion, quiet } = argv ;
1463
+ const progressCallback = quiet
1464
+ ? ( ) => { }
1465
+ : data => {
1466
+ const { type = 'info' , message, raise = true } = data ;
1467
+ if ( config && ! URL ) {
1468
+ // bulk installation
1469
+ let prefix = '' ;
1470
+ if ( data . current || data . total || data . plugin ) {
1471
+ prefix = `${ data . current } of ${ data . total } (${ data . plugin } ): ` ;
1472
+ }
1473
+ if ( type === 'info' || type === 'success' ) {
1474
+ console . log ( `${ prefix } ${ type } : ${ message } ` ) ;
1475
+ } else if ( type === 'error' && raise ) {
1476
+ throw new Error ( message ) ;
1477
+ } else {
1478
+ console . error ( `${ prefix } ${ type } : ${ message } ` ) ;
1479
+ }
1480
+ } else {
1481
+ if ( type === 'error' || type === 'success' ) {
1482
+ console . error ( `${ type } : ${ message } ` ) ;
1483
+ }
1484
+ }
1485
+ } ;
1486
+ if ( URL ) {
1487
+ // Single plugin installation
1488
+ try {
1489
+ await PluginManager . install ( URL , folderName , headlampVersion , progressCallback ) ;
1490
+ } catch ( e ) {
1491
+ console . error ( e . message ) ;
1492
+ process . exit ( 1 ) ; // Exit with error status
1493
+ }
1494
+ } else if ( config ) {
1495
+ const installer = new MultiPluginManager ( folderName , headlampVersion , progressCallback ) ;
1496
+ // Bulk installation from config
1497
+ const result = await installer . installFromConfig ( config ) ;
1498
+ // Exit with error if any plugins failed to install
1499
+ if ( result . failed > 0 ) {
1500
+ process . exit ( 1 ) ;
1501
+ }
1502
+ }
1503
+ } catch ( error ) {
1504
+ console . error ( 'Installation failed' , {
1505
+ error : error . message ,
1506
+ stack : error . stack ,
1507
+ } ) ;
1508
+ process . exit ( 1 ) ;
1459
1509
}
1460
1510
}
1461
1511
)
0 commit comments