1+ const { execSync } = require ( 'child_process' ) ;
2+ const path = require ( 'path' ) ;
3+ const fs = require ( 'fs' ) ;
4+ const GetPluginName = ( pluginDir ) => {
5+ const jsonPath = path . join ( pluginDir , 'plugin.json' ) ;
6+ try {
7+ if ( fs . existsSync ( jsonPath ) ) {
8+ const pluginJson = JSON . parse ( fs . readFileSync ( jsonPath ) ) ;
9+ return pluginJson . name ;
10+ }
11+ }
12+ catch ( error ) {
13+ return null ;
14+ }
15+ }
16+ const ParsePlugin = ( pluginsDir , submodule ) => {
17+ const submodulePath = path . join ( pluginsDir , submodule ) ;
18+ const pluginName = execSync ( `git -C ${ submodulePath } rev-list --max-parents=0 HEAD` , { encoding : 'utf-8' } ) . trim ( ) ;
19+ if ( fs . existsSync ( path . join ( submodulePath , '.git' ) ) ) {
20+ try {
21+ return { id : pluginName , commitId : execSync ( `git -C ${ submodulePath } rev-parse HEAD` , { encoding : 'utf-8' } ) . trim ( ) } ;
22+ }
23+ catch ( error ) {
24+ return { id : pluginName , commitId : null } ;
25+ }
26+ }
27+ else {
28+ return { id : pluginName , commitId : null } ;
29+ }
30+ }
31+ const pluginsDir = path . resolve ( process . cwd ( ) , 'plugins' ) ;
32+ let pluginIds = [ ] ;
33+ if ( fs . existsSync ( pluginsDir ) ) {
34+ fs . readdirSync ( pluginsDir ) . forEach ( submodule => { pluginIds . push ( ParsePlugin ( pluginsDir , submodule ) ) ; } ) ;
35+ }
36+ // write JSON to metadata.json
37+ fs . writeFileSync ( path . resolve ( process . cwd ( ) , 'metadata.json' ) , JSON . stringify ( pluginIds , null , 4 ) ) ;
0 commit comments